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/lib/Passes/PassBuilder.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/lib/Passes/PassBuilder.cpp')
-rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 93daad7eca0..a6a4cb62647 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -61,17 +61,12 @@ struct NoOpModulePass { }; /// \brief No-op module analysis. -struct NoOpModuleAnalysis { +struct NoOpModuleAnalysis : AnalysisBase<NoOpModuleAnalysis> { struct Result {}; Result run(Module &) { return Result(); } static StringRef name() { return "NoOpModuleAnalysis"; } - static void *ID() { return (void *)&PassID; } -private: - static char PassID; }; -char NoOpModuleAnalysis::PassID; - /// \brief No-op CGSCC pass which does nothing. struct NoOpCGSCCPass { PreservedAnalyses run(LazyCallGraph::SCC &C) { @@ -81,17 +76,12 @@ struct NoOpCGSCCPass { }; /// \brief No-op CGSCC analysis. -struct NoOpCGSCCAnalysis { +struct NoOpCGSCCAnalysis : AnalysisBase<NoOpCGSCCAnalysis> { struct Result {}; Result run(LazyCallGraph::SCC &) { return Result(); } static StringRef name() { return "NoOpCGSCCAnalysis"; } - static void *ID() { return (void *)&PassID; } -private: - static char PassID; }; -char NoOpCGSCCAnalysis::PassID; - /// \brief No-op function pass which does nothing. struct NoOpFunctionPass { PreservedAnalyses run(Function &F) { return PreservedAnalyses::all(); } @@ -99,17 +89,12 @@ struct NoOpFunctionPass { }; /// \brief No-op function analysis. -struct NoOpFunctionAnalysis { +struct NoOpFunctionAnalysis : AnalysisBase<NoOpFunctionAnalysis> { struct Result {}; Result run(Function &) { return Result(); } static StringRef name() { return "NoOpFunctionAnalysis"; } - static void *ID() { return (void *)&PassID; } -private: - static char PassID; }; -char NoOpFunctionAnalysis::PassID; - /// \brief No-op loop pass which does nothing. struct NoOpLoopPass { PreservedAnalyses run(Loop &L) { return PreservedAnalyses::all(); } @@ -117,17 +102,12 @@ struct NoOpLoopPass { }; /// \brief No-op loop analysis. -struct NoOpLoopAnalysis { +struct NoOpLoopAnalysis : AnalysisBase<NoOpLoopAnalysis> { struct Result {}; Result run(Loop &) { return Result(); } static StringRef name() { return "NoOpLoopAnalysis"; } - static void *ID() { return (void *)&PassID; } -private: - static char PassID; }; -char NoOpLoopAnalysis::PassID; - } // End anonymous namespace. void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) { |