diff options
Diffstat (limited to 'unittests/IR/PassManagerTest.cpp')
-rw-r--r-- | unittests/IR/PassManagerTest.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/unittests/IR/PassManagerTest.cpp b/unittests/IR/PassManagerTest.cpp index d493156..41af0b0 100644 --- a/unittests/IR/PassManagerTest.cpp +++ b/unittests/IR/PassManagerTest.cpp @@ -29,13 +29,16 @@ public: /// \brief Returns an opaque, unique ID for this pass type. static void *ID() { return (void *)&PassID; } + /// \brief Returns the name of the analysis. + static StringRef name() { return "TestFunctionAnalysis"; } + TestFunctionAnalysis(int &Runs) : Runs(Runs) {} /// \brief Run the analysis pass over the function and return a result. - Result run(Function *F, FunctionAnalysisManager *AM) { + Result run(Function &F, FunctionAnalysisManager *AM) { ++Runs; int Count = 0; - for (Function::iterator BBI = F->begin(), BBE = F->end(); BBI != BBE; ++BBI) + for (Function::iterator BBI = F.begin(), BBE = F.end(); BBI != BBE; ++BBI) for (BasicBlock::iterator II = BBI->begin(), IE = BBI->end(); II != IE; ++II) ++Count; @@ -60,12 +63,14 @@ public: static void *ID() { return (void *)&PassID; } + static StringRef name() { return "TestModuleAnalysis"; } + TestModuleAnalysis(int &Runs) : Runs(Runs) {} - Result run(Module *M, ModuleAnalysisManager *AM) { + Result run(Module &M, ModuleAnalysisManager *AM) { ++Runs; int Count = 0; - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) ++Count; return Result(Count); } @@ -81,7 +86,7 @@ char TestModuleAnalysis::PassID; struct TestModulePass { TestModulePass(int &RunCount) : RunCount(RunCount) {} - PreservedAnalyses run(Module *M) { + PreservedAnalyses run(Module &M) { ++RunCount; return PreservedAnalyses::none(); } @@ -92,13 +97,13 @@ struct TestModulePass { }; struct TestPreservingModulePass { - PreservedAnalyses run(Module *M) { return PreservedAnalyses::all(); } + PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); } static StringRef name() { return "TestPreservingModulePass"; } }; struct TestMinPreservingModulePass { - PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM) { + PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) { PreservedAnalyses PA; // Force running an analysis. @@ -119,13 +124,13 @@ struct TestFunctionPass { AnalyzedFunctionCount(AnalyzedFunctionCount), OnlyUseCachedResults(OnlyUseCachedResults) {} - PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM) { + PreservedAnalyses run(Function &F, FunctionAnalysisManager *AM) { ++RunCount; const ModuleAnalysisManager &MAM = AM->getResult<ModuleAnalysisManagerFunctionProxy>(F).getManager(); if (TestModuleAnalysis::Result *TMA = - MAM.getCachedResult<TestModuleAnalysis>(F->getParent())) + MAM.getCachedResult<TestModuleAnalysis>(*F.getParent())) AnalyzedFunctionCount += TMA->FunctionCount; if (OnlyUseCachedResults) { @@ -155,9 +160,9 @@ struct TestFunctionPass { struct TestInvalidationFunctionPass { TestInvalidationFunctionPass(StringRef FunctionName) : Name(FunctionName) {} - PreservedAnalyses run(Function *F) { - return F->getName() == Name ? PreservedAnalyses::none() - : PreservedAnalyses::all(); + PreservedAnalyses run(Function &F) { + return F.getName() == Name ? PreservedAnalyses::none() + : PreservedAnalyses::all(); } static StringRef name() { return "TestInvalidationFunctionPass"; } @@ -165,10 +170,10 @@ struct TestInvalidationFunctionPass { StringRef Name; }; -Module *parseIR(const char *IR) { +std::unique_ptr<Module> parseIR(const char *IR) { LLVMContext &C = getGlobalContext(); SMDiagnostic Err; - return parseAssemblyString(IR, Err, C).release(); + return parseAssemblyString(IR, Err, C); } class PassManagerTest : public ::testing::Test { @@ -310,7 +315,7 @@ TEST_F(PassManagerTest, Basic) { MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); } - MPM.run(M.get(), &MAM); + MPM.run(*M, &MAM); // Validate module pass counters. EXPECT_EQ(1, ModulePassRunCount); |