[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.

llvm-svn: 273973
This commit is contained in:
Chandler Carruth 2016-06-28 00:38:42 +00:00
parent 7de0cf3cf7
commit 6c138ce31c

View File

@ -208,53 +208,48 @@ struct TestFunctionPass {
int &RunCount; int &RunCount;
}; };
std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) { std::unique_ptr<Module> parseIR(const char *IR) {
// We just use a static context here. This is never called from multiple
// threads so it is harmless no matter how it is implemented. We just need
// the context to outlive the module which it does.
static LLVMContext C;
SMDiagnostic Err; SMDiagnostic Err;
return parseAssemblyString(IR, Err, C); return parseAssemblyString(IR, Err, C);
} }
class CGSCCPassManagerTest : public ::testing::Test { TEST(CGSCCPassManagerTest, Basic) {
protected: auto M = parseIR("define void @f() {\n"
LLVMContext Context; "entry:\n"
std::unique_ptr<Module> M; " call void @g()\n"
" call void @h1()\n"
public: " ret void\n"
CGSCCPassManagerTest() "}\n"
: M(parseIR(Context, "define void @f() {\n" "define void @g() {\n"
"entry:\n" "entry:\n"
" call void @g()\n" " call void @g()\n"
" call void @h1()\n" " call void @x()\n"
" ret void\n" " ret void\n"
"}\n" "}\n"
"define void @g() {\n" "define void @h1() {\n"
"entry:\n" "entry:\n"
" call void @g()\n" " call void @h2()\n"
" call void @x()\n" " ret void\n"
" ret void\n" "}\n"
"}\n" "define void @h2() {\n"
"define void @h1() {\n" "entry:\n"
"entry:\n" " call void @h3()\n"
" call void @h2()\n" " call void @x()\n"
" ret void\n" " ret void\n"
"}\n" "}\n"
"define void @h2() {\n" "define void @h3() {\n"
"entry:\n" "entry:\n"
" call void @h3()\n" " call void @h1()\n"
" call void @x()\n" " ret void\n"
" ret void\n" "}\n"
"}\n" "define void @x() {\n"
"define void @h3() {\n" "entry:\n"
"entry:\n" " ret void\n"
" call void @h1()\n" "}\n");
" ret void\n"
"}\n"
"define void @x() {\n"
"entry:\n"
" ret void\n"
"}\n")) {}
};
TEST_F(CGSCCPassManagerTest, Basic) {
FunctionAnalysisManager FAM(/*DebugLogging*/ true); FunctionAnalysisManager FAM(/*DebugLogging*/ true);
int FunctionAnalysisRuns = 0; int FunctionAnalysisRuns = 0;
FAM.registerPass([&] { return TestFunctionAnalysis(FunctionAnalysisRuns); }); FAM.registerPass([&] { return TestFunctionAnalysis(FunctionAnalysisRuns); });