summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/PassManagerTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2015-01-05 02:47:05 +0000
committerChandler Carruth <chandlerc@gmail.com>2015-01-05 02:47:05 +0000
commitd174ce4ad17b1965cefba7a7e5b97fe7235d7337 (patch)
tree7a6d6b16f4bc15a26b83b14e53d8d05dd4b8ee5f /llvm/unittests/IR/PassManagerTest.cpp
parent9c31db4f94e78027bece17ee18a154a48436e574 (diff)
downloadbcm5719-llvm-d174ce4ad17b1965cefba7a7e5b97fe7235d7337.tar.gz
bcm5719-llvm-d174ce4ad17b1965cefba7a7e5b97fe7235d7337.zip
[PM] Switch the new pass manager to use a reference-based API for IR
units. This was debated back and forth a bunch, but using references is now clearly cleaner. Of all the code written using pointers thus far, in only one place did it really make more sense to have a pointer. In most cases, this just removes immediate dereferencing from the code. I think it is much better to get errors on null IR units earlier, potentially at compile time, than to delay it. Most notably, the legacy pass manager uses references for its routines and so as more and more code works with both, the use of pointers was likely to become really annoying. I noticed this when I ported the domtree analysis over and wrote the entire thing with references only to have it fail to compile. =/ It seemed better to switch now than to delay. We can, of course, revisit this is we learn that references are really problematic in the API. llvm-svn: 225145
Diffstat (limited to 'llvm/unittests/IR/PassManagerTest.cpp')
-rw-r--r--llvm/unittests/IR/PassManagerTest.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/llvm/unittests/IR/PassManagerTest.cpp b/llvm/unittests/IR/PassManagerTest.cpp
index d493156a343..d641e36ac6a 100644
--- a/llvm/unittests/IR/PassManagerTest.cpp
+++ b/llvm/unittests/IR/PassManagerTest.cpp
@@ -32,10 +32,10 @@ public:
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;
@@ -62,10 +62,10 @@ public:
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 +81,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 +92,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 +119,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 +155,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 +165,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 +310,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);
OpenPOWER on IntegriCloud