From 3a6343555180817fe1f533a60e66b0e4db465e46 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 26 Feb 2016 11:44:45 +0000 Subject: [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 --- llvm/unittests/IR/PassManagerTest.cpp | 43 ++++++----------------------------- 1 file changed, 7 insertions(+), 36 deletions(-) (limited to 'llvm/unittests/IR/PassManagerTest.cpp') 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 { 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 { 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(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 { PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); } - - static StringRef name() { return "TestPreservingModulePass"; } }; -struct TestMinPreservingModulePass { +struct TestMinPreservingModulePass : PassBase { PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) { PreservedAnalyses PA; @@ -112,11 +89,9 @@ struct TestMinPreservingModulePass { PA.preserve(); return PA; } - - static StringRef name() { return "TestMinPreservingModulePass"; } }; -struct TestFunctionPass { +struct TestFunctionPass : PassBase { 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(StringRef FunctionName) : Name(FunctionName) {} PreservedAnalyses run(Function &F) { @@ -165,8 +138,6 @@ struct TestInvalidationFunctionPass { : PreservedAnalyses::all(); } - static StringRef name() { return "TestInvalidationFunctionPass"; } - StringRef Name; }; -- cgit v1.2.3