llvm.org GIT mirror llvm / 5dcd187
[PM] Sink the module parsing from the fixture to the test as subsequent tests will want different IR. Wanted this when writing tests for the proposed CG update stuff, and this is an easily separable piece. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273973 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 4 years ago
1 changed file(s) with 38 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
207207 int &RunCount;
208208 };
209209
210 std::unique_ptr parseIR(LLVMContext &C, const char *IR) {
210 std::unique_ptr parseIR(const char *IR) {
211 // We just use a static context here. This is never called from multiple
212 // threads so it is harmless no matter how it is implemented. We just need
213 // the context to outlive the module which it does.
214 static LLVMContext C;
211215 SMDiagnostic Err;
212216 return parseAssemblyString(IR, Err, C);
213217 }
214218
215 class CGSCCPassManagerTest : public ::testing::Test {
216 protected:
217 LLVMContext Context;
218 std::unique_ptr M;
219
220 public:
221 CGSCCPassManagerTest()
222 : M(parseIR(Context, "define void @f() {\n"
223 "entry:\n"
224 " call void @g()\n"
225 " call void @h1()\n"
226 " ret void\n"
227 "}\n"
228 "define void @g() {\n"
229 "entry:\n"
230 " call void @g()\n"
231 " call void @x()\n"
232 " ret void\n"
233 "}\n"
234 "define void @h1() {\n"
235 "entry:\n"
236 " call void @h2()\n"
237 " ret void\n"
238 "}\n"
239 "define void @h2() {\n"
240 "entry:\n"
241 " call void @h3()\n"
242 " call void @x()\n"
243 " ret void\n"
244 "}\n"
245 "define void @h3() {\n"
246 "entry:\n"
247 " call void @h1()\n"
248 " ret void\n"
249 "}\n"
250 "define void @x() {\n"
251 "entry:\n"
252 " ret void\n"
253 "}\n")) {}
254 };
255
256 TEST_F(CGSCCPassManagerTest, Basic) {
219 TEST(CGSCCPassManagerTest, Basic) {
220 auto M = parseIR("define void @f() {\n"
221 "entry:\n"
222 " call void @g()\n"
223 " call void @h1()\n"
224 " ret void\n"
225 "}\n"
226 "define void @g() {\n"
227 "entry:\n"
228 " call void @g()\n"
229 " call void @x()\n"
230 " ret void\n"
231 "}\n"
232 "define void @h1() {\n"
233 "entry:\n"
234 " call void @h2()\n"
235 " ret void\n"
236 "}\n"
237 "define void @h2() {\n"
238 "entry:\n"
239 " call void @h3()\n"
240 " call void @x()\n"
241 " ret void\n"
242 "}\n"
243 "define void @h3() {\n"
244 "entry:\n"
245 " call void @h1()\n"
246 " ret void\n"
247 "}\n"
248 "define void @x() {\n"
249 "entry:\n"
250 " ret void\n"
251 "}\n");
257252 FunctionAnalysisManager FAM(/*DebugLogging*/ true);
258253 int FunctionAnalysisRuns = 0;
259254 FAM.registerPass([&] { return TestFunctionAnalysis(FunctionAnalysisRuns); });