diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2016-02-26 11:44:45 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2016-02-26 11:44:45 +0000 |
commit | 3a6343555180817fe1f533a60e66b0e4db465e46 (patch) | |
tree | b5c40db2a6e046ae4d71a83a06a4f591233ba90f /llvm/unittests/IR/PassManagerTest.cpp | |
parent | 6456376fe94dcf4df5f2b946c1806fe579f9e414 (diff) | |
download | bcm5719-llvm-3a6343555180817fe1f533a60e66b0e4db465e46.tar.gz bcm5719-llvm-3a6343555180817fe1f533a60e66b0e4db465e46.zip |
[PM] Introduce CRTP mixin base classes to help define passes and
analyses in the new pass manager.
These just handle really basic stuff: turning a type name into a string
statically that is nice to print in logs, and getting a static unique ID
for each analysis.
Sadly, the format of passes in anonymous namespaces makes using their
names in tests really annoying so I've customized the names of the no-op
passes to keep tests sane to read.
This is the first of a few simplifying refactorings for the new pass
manager that should reduce boilerplate and confusion.
llvm-svn: 262004
Diffstat (limited to 'llvm/unittests/IR/PassManagerTest.cpp')
-rw-r--r-- | llvm/unittests/IR/PassManagerTest.cpp | 43 |
1 files changed, 7 insertions, 36 deletions
diff --git a/llvm/unittests/IR/PassManagerTest.cpp b/llvm/unittests/IR/PassManagerTest.cpp index 37939768aaf..857b5283c41 100644 --- a/llvm/unittests/IR/PassManagerTest.cpp +++ b/llvm/unittests/IR/PassManagerTest.cpp @@ -19,19 +19,13 @@ using namespace llvm; namespace { -class TestFunctionAnalysis { +class TestFunctionAnalysis : public AnalysisBase<TestFunctionAnalysis> { public: struct Result { Result(int Count) : InstructionCount(Count) {} int InstructionCount; }; - /// \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. @@ -46,25 +40,16 @@ public: } private: - /// \brief Private static data to provide unique ID. - static char PassID; - int &Runs; }; -char TestFunctionAnalysis::PassID; - -class TestModuleAnalysis { +class TestModuleAnalysis : public AnalysisBase<TestModuleAnalysis> { public: struct Result { Result(int Count) : FunctionCount(Count) {} int FunctionCount; }; - static void *ID() { return (void *)&PassID; } - - static StringRef name() { return "TestModuleAnalysis"; } - TestModuleAnalysis(int &Runs) : Runs(Runs) {} Result run(Module &M, ModuleAnalysisManager *AM) { @@ -76,14 +61,10 @@ public: } private: - static char PassID; - int &Runs; }; -char TestModuleAnalysis::PassID; - -struct TestModulePass { +struct TestModulePass : PassBase<TestModulePass> { TestModulePass(int &RunCount) : RunCount(RunCount) {} PreservedAnalyses run(Module &M) { @@ -91,18 +72,14 @@ struct TestModulePass { return PreservedAnalyses::none(); } - static StringRef name() { return "TestModulePass"; } - int &RunCount; }; -struct TestPreservingModulePass { +struct TestPreservingModulePass : PassBase<TestPreservingModulePass> { PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); } - - static StringRef name() { return "TestPreservingModulePass"; } }; -struct TestMinPreservingModulePass { +struct TestMinPreservingModulePass : PassBase<TestMinPreservingModulePass> { PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) { PreservedAnalyses PA; @@ -112,11 +89,9 @@ struct TestMinPreservingModulePass { PA.preserve<FunctionAnalysisManagerModuleProxy>(); return PA; } - - static StringRef name() { return "TestMinPreservingModulePass"; } }; -struct TestFunctionPass { +struct TestFunctionPass : PassBase<TestFunctionPass> { TestFunctionPass(int &RunCount, int &AnalyzedInstrCount, int &AnalyzedFunctionCount, bool OnlyUseCachedResults = false) @@ -147,8 +122,6 @@ struct TestFunctionPass { return PreservedAnalyses::all(); } - static StringRef name() { return "TestFunctionPass"; } - int &RunCount; int &AnalyzedInstrCount; int &AnalyzedFunctionCount; @@ -157,7 +130,7 @@ struct TestFunctionPass { // A test function pass that invalidates all function analyses for a function // with a specific name. -struct TestInvalidationFunctionPass { +struct TestInvalidationFunctionPass : PassBase<TestInvalidationFunctionPass> { TestInvalidationFunctionPass(StringRef FunctionName) : Name(FunctionName) {} PreservedAnalyses run(Function &F) { @@ -165,8 +138,6 @@ struct TestInvalidationFunctionPass { : PreservedAnalyses::all(); } - static StringRef name() { return "TestInvalidationFunctionPass"; } - StringRef Name; }; |