From 3a6343555180817fe1f533a60e66b0e4db465e46 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 26 Feb 2016 11:44:45 +0000 Subject: [PATCH] [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/include/llvm/Analysis/AliasAnalysis.h | 10 +-- .../llvm/Analysis/AliasAnalysisEvaluator.h | 2 +- llvm/include/llvm/Analysis/AssumptionCache.h | 13 +--- .../llvm/Analysis/BasicAliasAnalysis.h | 12 +--- llvm/include/llvm/Analysis/CFLAliasAnalysis.h | 12 +--- llvm/include/llvm/Analysis/CGSCCPassManager.h | 48 ++++--------- llvm/include/llvm/Analysis/CallGraph.h | 8 +-- .../include/llvm/Analysis/DominanceFrontier.h | 17 +---- llvm/include/llvm/Analysis/GlobalsModRef.h | 12 +--- llvm/include/llvm/Analysis/LazyCallGraph.h | 14 +--- llvm/include/llvm/Analysis/LoopInfo.h | 18 +---- llvm/include/llvm/Analysis/LoopPassManager.h | 24 ++----- .../llvm/Analysis/ObjCARCAliasAnalysis.h | 12 +--- llvm/include/llvm/Analysis/PostDominators.h | 17 +---- llvm/include/llvm/Analysis/RegionInfo.h | 19 +----- llvm/include/llvm/Analysis/ScalarEvolution.h | 16 +---- .../Analysis/ScalarEvolutionAliasAnalysis.h | 12 +--- llvm/include/llvm/Analysis/ScopedNoAliasAA.h | 12 +--- .../include/llvm/Analysis/TargetLibraryInfo.h | 12 +--- .../llvm/Analysis/TargetTransformInfo.h | 12 +--- .../llvm/Analysis/TypeBasedAliasAnalysis.h | 12 +--- llvm/include/llvm/IR/Dominators.h | 20 +----- llvm/include/llvm/IR/PassManager.h | 68 +++++++++++-------- llvm/include/llvm/IR/Verifier.h | 6 +- .../llvm/Transforms/IPO/ForceFunctionAttrs.h | 4 +- .../llvm/Transforms/IPO/FunctionAttrs.h | 5 +- .../llvm/Transforms/IPO/InferFunctionAttrs.h | 4 +- .../llvm/Transforms/IPO/StripDeadPrototypes.h | 4 +- .../llvm/Transforms/InstCombine/InstCombine.h | 2 +- llvm/include/llvm/Transforms/Scalar/ADCE.h | 4 +- .../include/llvm/Transforms/Scalar/EarlyCSE.h | 5 +- .../Transforms/Scalar/LowerExpectIntrinsic.h | 5 +- llvm/include/llvm/Transforms/Scalar/SROA.h | 4 +- .../llvm/Transforms/Scalar/SimplifyCFG.h | 4 +- llvm/lib/Analysis/AliasAnalysis.cpp | 3 - llvm/lib/Analysis/AssumptionCache.cpp | 2 - llvm/lib/Analysis/BasicAliasAnalysis.cpp | 2 - llvm/lib/Analysis/CFLAliasAnalysis.cpp | 2 - llvm/lib/Analysis/CGSCCPassManager.cpp | 8 --- llvm/lib/Analysis/CallGraph.cpp | 2 - llvm/lib/Analysis/DominanceFrontier.cpp | 2 - llvm/lib/Analysis/GlobalsModRef.cpp | 2 - llvm/lib/Analysis/LazyCallGraph.cpp | 2 - llvm/lib/Analysis/LoopInfo.cpp | 2 - llvm/lib/Analysis/LoopPassManager.cpp | 4 -- llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp | 2 - llvm/lib/Analysis/PostDominators.cpp | 2 - llvm/lib/Analysis/RegionInfo.cpp | 2 - llvm/lib/Analysis/ScalarEvolution.cpp | 2 - .../Analysis/ScalarEvolutionAliasAnalysis.cpp | 2 - llvm/lib/Analysis/ScopedNoAliasAA.cpp | 2 - llvm/lib/Analysis/TargetLibraryInfo.cpp | 2 - llvm/lib/Analysis/TargetTransformInfo.cpp | 2 - llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp | 2 - llvm/lib/IR/Dominators.cpp | 2 - llvm/lib/IR/PassManager.cpp | 4 -- llvm/lib/Passes/PassBuilder.cpp | 28 ++------ llvm/test/Other/new-pass-manager.ll | 2 +- llvm/unittests/IR/PassManagerTest.cpp | 43 ++---------- 59 files changed, 123 insertions(+), 454 deletions(-) diff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h index 775d994dcd04..8422e010e450 100644 --- a/llvm/include/llvm/Analysis/AliasAnalysis.h +++ b/llvm/include/llvm/Analysis/AliasAnalysis.h @@ -979,16 +979,10 @@ bool isIdentifiedFunctionLocal(const Value *V); /// This manager effectively wraps the AnalysisManager for registering alias /// analyses. When you register your alias analysis with this manager, it will /// ensure the analysis itself is registered with its AnalysisManager. -class AAManager { +class AAManager : public AnalysisBase { public: typedef AAResults Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - - /// \brief Provide access to a name for this pass. - static StringRef name() { return "AAManager"; } - // This type hase value semantics. We have to spell these out because MSVC // won't synthesize them. AAManager() {} @@ -1018,8 +1012,6 @@ public: } private: - static char PassID; - SmallVector &AM, AAResults &AAResults), 4> FunctionResultGetters; diff --git a/llvm/include/llvm/Analysis/AliasAnalysisEvaluator.h b/llvm/include/llvm/Analysis/AliasAnalysisEvaluator.h index 5275dcab1c62..b32bf577c836 100644 --- a/llvm/include/llvm/Analysis/AliasAnalysisEvaluator.h +++ b/llvm/include/llvm/Analysis/AliasAnalysisEvaluator.h @@ -26,7 +26,7 @@ namespace llvm { class AAResults; -class AAEvaluator { +class AAEvaluator : public PassBase { int64_t FunctionCount; int64_t NoAliasCount, MayAliasCount, PartialAliasCount, MustAliasCount; int64_t NoModRefCount, ModCount, RefCount, ModRefCount; diff --git a/llvm/include/llvm/Analysis/AssumptionCache.h b/llvm/include/llvm/Analysis/AssumptionCache.h index e299bd10902b..79d2bc966e4c 100644 --- a/llvm/include/llvm/Analysis/AssumptionCache.h +++ b/llvm/include/llvm/Analysis/AssumptionCache.h @@ -93,18 +93,9 @@ public: /// /// This analysis is intended for use with the new pass manager and will vend /// assumption caches for a given function. -class AssumptionAnalysis { - static char PassID; - -public: +struct AssumptionAnalysis : AnalysisBase { typedef AssumptionCache Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - - /// \brief Provide a name for the analysis for debugging and logging. - static StringRef name() { return "AssumptionAnalysis"; } - AssumptionAnalysis() {} AssumptionAnalysis(const AssumptionAnalysis &Arg) {} AssumptionAnalysis(AssumptionAnalysis &&Arg) {} @@ -115,7 +106,7 @@ public: }; /// \brief Printer pass for the \c AssumptionAnalysis results. -class AssumptionPrinterPass { +class AssumptionPrinterPass : public PassBase { raw_ostream &OS; public: diff --git a/llvm/include/llvm/Analysis/BasicAliasAnalysis.h b/llvm/include/llvm/Analysis/BasicAliasAnalysis.h index c57dde96cacd..ee769ecd983b 100644 --- a/llvm/include/llvm/Analysis/BasicAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/BasicAliasAnalysis.h @@ -178,20 +178,10 @@ private: }; /// Analysis pass providing a never-invalidated alias analysis result. -class BasicAA { -public: +struct BasicAA : AnalysisBase { typedef BasicAAResult Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "BasicAA"; } - BasicAAResult run(Function &F, AnalysisManager *AM); - -private: - static char PassID; }; /// Legacy wrapper pass to provide the BasicAAResult object. diff --git a/llvm/include/llvm/Analysis/CFLAliasAnalysis.h b/llvm/include/llvm/Analysis/CFLAliasAnalysis.h index 0f9d994e8fe5..d966e0c93ff0 100644 --- a/llvm/include/llvm/Analysis/CFLAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/CFLAliasAnalysis.h @@ -109,20 +109,10 @@ private: /// /// FIXME: We really should refactor CFL to use the analysis more heavily, and /// in particular to leverage invalidation to trigger re-computation of sets. -class CFLAA { -public: +struct CFLAA : AnalysisBase { typedef CFLAAResult Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - CFLAAResult run(Function &F, AnalysisManager *AM); - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "CFLAA"; } - -private: - static char PassID; }; /// Legacy wrapper pass to provide the CFLAAResult object. diff --git a/llvm/include/llvm/Analysis/CGSCCPassManager.h b/llvm/include/llvm/Analysis/CGSCCPassManager.h index 7d01ebb9a002..cede4b0d1173 100644 --- a/llvm/include/llvm/Analysis/CGSCCPassManager.h +++ b/llvm/include/llvm/Analysis/CGSCCPassManager.h @@ -52,7 +52,8 @@ typedef AnalysisManager CGSCCAnalysisManager; /// /// Note that the proxy's result is a move-only object and represents ownership /// of the validity of the analyses in the \c CGSCCAnalysisManager it provides. -class CGSCCAnalysisManagerModuleProxy { +class CGSCCAnalysisManagerModuleProxy + : public AnalysisBase { public: class Result { public: @@ -92,10 +93,6 @@ public: CGSCCAnalysisManager *CGAM; }; - static void *ID() { return (void *)&PassID; } - - static StringRef name() { return "CGSCCAnalysisManagerModuleProxy"; } - explicit CGSCCAnalysisManagerModuleProxy(CGSCCAnalysisManager &CGAM) : CGAM(&CGAM) {} // We have to explicitly define all the special member functions because MSVC @@ -122,8 +119,6 @@ public: Result run(Module &M); private: - static char PassID; - CGSCCAnalysisManager *CGAM; }; @@ -139,7 +134,8 @@ private: /// This proxy *doesn't* manage the invalidation in any way. That is handled by /// the recursive return path of each layer of the pass manager and the /// returned PreservedAnalysis set. -class ModuleAnalysisManagerCGSCCProxy { +class ModuleAnalysisManagerCGSCCProxy + : public AnalysisBase { public: /// \brief Result proxy object for \c ModuleAnalysisManagerCGSCCProxy. class Result { @@ -163,10 +159,6 @@ public: const ModuleAnalysisManager *MAM; }; - static void *ID() { return (void *)&PassID; } - - static StringRef name() { return "ModuleAnalysisManagerCGSCCProxy"; } - ModuleAnalysisManagerCGSCCProxy(const ModuleAnalysisManager &MAM) : MAM(&MAM) {} // We have to explicitly define all the special member functions because MSVC @@ -187,8 +179,6 @@ public: Result run(LazyCallGraph::SCC &) { return Result(*MAM); } private: - static char PassID; - const ModuleAnalysisManager *MAM; }; @@ -201,7 +191,9 @@ private: /// \c CGSCCAnalysisManagerModuleProxy analysis prior to running the CGSCC /// pass over the module to enable a \c FunctionAnalysisManager to be used /// within this run safely. -template class ModuleToPostOrderCGSCCPassAdaptor { +template +class ModuleToPostOrderCGSCCPassAdaptor + : public PassBase> { public: explicit ModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT Pass) : Pass(std::move(Pass)) {} @@ -262,8 +254,6 @@ public: return PA; } - static StringRef name() { return "ModuleToPostOrderCGSCCPassAdaptor"; } - private: CGSCCPassT Pass; }; @@ -288,7 +278,8 @@ createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT Pass) { /// Note that the proxy's result is a move-only object and represents ownership /// of the validity of the analyses in the \c FunctionAnalysisManager it /// provides. -class FunctionAnalysisManagerCGSCCProxy { +class FunctionAnalysisManagerCGSCCProxy + : public AnalysisBase { public: class Result { public: @@ -328,10 +319,6 @@ public: FunctionAnalysisManager *FAM; }; - static void *ID() { return (void *)&PassID; } - - static StringRef name() { return "FunctionAnalysisManagerCGSCCProxy"; } - explicit FunctionAnalysisManagerCGSCCProxy(FunctionAnalysisManager &FAM) : FAM(&FAM) {} // We have to explicitly define all the special member functions because MSVC @@ -359,8 +346,6 @@ public: Result run(LazyCallGraph::SCC &C); private: - static char PassID; - FunctionAnalysisManager *FAM; }; @@ -376,7 +361,8 @@ private: /// This proxy *doesn't* manage the invalidation in any way. That is handled by /// the recursive return path of each layer of the pass manager and the /// returned PreservedAnalysis set. -class CGSCCAnalysisManagerFunctionProxy { +class CGSCCAnalysisManagerFunctionProxy + : public AnalysisBase { public: /// \brief Result proxy object for \c CGSCCAnalysisManagerFunctionProxy. class Result { @@ -400,10 +386,6 @@ public: const CGSCCAnalysisManager *CGAM; }; - static void *ID() { return (void *)&PassID; } - - static StringRef name() { return "CGSCCAnalysisManagerFunctionProxy"; } - CGSCCAnalysisManagerFunctionProxy(const CGSCCAnalysisManager &CGAM) : CGAM(&CGAM) {} // We have to explicitly define all the special member functions because MSVC @@ -425,8 +407,6 @@ public: Result run(Function &) { return Result(*CGAM); } private: - static char PassID; - const CGSCCAnalysisManager *CGAM; }; @@ -438,7 +418,9 @@ private: /// \c FunctionAnalysisManagerCGSCCProxy analysis prior to running the function /// pass over the SCC to enable a \c FunctionAnalysisManager to be used /// within this run safely. -template class CGSCCToFunctionPassAdaptor { +template +class CGSCCToFunctionPassAdaptor + : public PassBase> { public: explicit CGSCCToFunctionPassAdaptor(FunctionPassT Pass) : Pass(std::move(Pass)) {} @@ -492,8 +474,6 @@ public: return PA; } - static StringRef name() { return "CGSCCToFunctionPassAdaptor"; } - private: FunctionPassT Pass; }; diff --git a/llvm/include/llvm/Analysis/CallGraph.h b/llvm/include/llvm/Analysis/CallGraph.h index 5562e9b9465f..5f3299131210 100644 --- a/llvm/include/llvm/Analysis/CallGraph.h +++ b/llvm/include/llvm/Analysis/CallGraph.h @@ -57,6 +57,7 @@ #include "llvm/IR/CallSite.h" #include "llvm/IR/Function.h" #include "llvm/IR/Intrinsics.h" +#include "llvm/IR/PassManager.h" #include "llvm/IR/ValueHandle.h" #include "llvm/Pass.h" #include @@ -294,20 +295,15 @@ private: /// This class implements the concept of an analysis pass used by the \c /// ModuleAnalysisManager to run an analysis over a module and cache the /// resulting data. -class CallGraphAnalysis { +struct CallGraphAnalysis : AnalysisBase { public: /// \brief A formulaic typedef to inform clients of the result type. typedef CallGraph Result; - static void *ID() { return (void *)&PassID; } - /// \brief Compute the \c CallGraph for the module \c M. /// /// The real work here is done in the \c CallGraph constructor. CallGraph run(Module *M) { return CallGraph(*M); } - -private: - static char PassID; }; /// \brief The \c ModulePass which wraps up a \c CallGraph and the logic to diff --git a/llvm/include/llvm/Analysis/DominanceFrontier.h b/llvm/include/llvm/Analysis/DominanceFrontier.h index 5f8805dedb25..62f9f0eab182 100644 --- a/llvm/include/llvm/Analysis/DominanceFrontier.h +++ b/llvm/include/llvm/Analysis/DominanceFrontier.h @@ -168,33 +168,22 @@ extern template class DominanceFrontierBase; extern template class ForwardDominanceFrontierBase; /// \brief Analysis pass which computes a \c DominanceFrontier. -class DominanceFrontierAnalysis { -public: +struct DominanceFrontierAnalysis : AnalysisBase { /// \brief Provide the result typedef for this analysis pass. typedef DominanceFrontier Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - /// \brief Run the analysis pass over a function and produce a dominator tree. DominanceFrontier run(Function &F, AnalysisManager *AM); - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "DominanceFrontierAnalysis"; } - -private: - static char PassID; }; /// \brief Printer pass for the \c DominanceFrontier. -class DominanceFrontierPrinterPass { +class DominanceFrontierPrinterPass + : public PassBase { raw_ostream &OS; public: explicit DominanceFrontierPrinterPass(raw_ostream &OS); PreservedAnalyses run(Function &F, AnalysisManager *AM); - - static StringRef name() { return "DominanceFrontierAnalysis"; } }; } // End llvm namespace diff --git a/llvm/include/llvm/Analysis/GlobalsModRef.h b/llvm/include/llvm/Analysis/GlobalsModRef.h index bcd102e7ded2..f2e7424181f8 100644 --- a/llvm/include/llvm/Analysis/GlobalsModRef.h +++ b/llvm/include/llvm/Analysis/GlobalsModRef.h @@ -116,20 +116,10 @@ private: }; /// Analysis pass providing a never-invalidated alias analysis result. -class GlobalsAA { -public: +struct GlobalsAA : AnalysisBase { typedef GlobalsAAResult Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - GlobalsAAResult run(Module &M, AnalysisManager *AM); - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "GlobalsAA"; } - -private: - static char PassID; }; /// Legacy wrapper pass to provide the GlobalsAAResult object. diff --git a/llvm/include/llvm/Analysis/LazyCallGraph.h b/llvm/include/llvm/Analysis/LazyCallGraph.h index 743b9890b3d7..0c0524605787 100644 --- a/llvm/include/llvm/Analysis/LazyCallGraph.h +++ b/llvm/include/llvm/Analysis/LazyCallGraph.h @@ -895,37 +895,27 @@ template <> struct GraphTraits { }; /// An analysis pass which computes the call graph for a module. -class LazyCallGraphAnalysis { -public: +struct LazyCallGraphAnalysis : AnalysisBase { /// Inform generic clients of the result type. typedef LazyCallGraph Result; - static void *ID() { return (void *)&PassID; } - - static StringRef name() { return "Lazy CallGraph Analysis"; } - /// Compute the \c LazyCallGraph for the module \c M. /// /// This just builds the set of entry points to the call graph. The rest is /// built lazily as it is walked. LazyCallGraph run(Module &M) { return LazyCallGraph(M); } - -private: - static char PassID; }; /// A pass which prints the call graph to a \c raw_ostream. /// /// This is primarily useful for testing the analysis. -class LazyCallGraphPrinterPass { +class LazyCallGraphPrinterPass : public PassBase { raw_ostream &OS; public: explicit LazyCallGraphPrinterPass(raw_ostream &OS); PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM); - - static StringRef name() { return "LazyCallGraphPrinterPass"; } }; } diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h index c37936fe20aa..55bafd261852 100644 --- a/llvm/include/llvm/Analysis/LoopInfo.h +++ b/llvm/include/llvm/Analysis/LoopInfo.h @@ -787,30 +787,19 @@ template <> struct GraphTraits { }; /// \brief Analysis pass that exposes the \c LoopInfo for a function. -class LoopAnalysis { - static char PassID; - -public: +struct LoopAnalysis : AnalysisBase { typedef LoopInfo Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - - /// \brief Provide a name for the analysis for debugging and logging. - static StringRef name() { return "LoopAnalysis"; } - LoopInfo run(Function &F, AnalysisManager *AM); }; /// \brief Printer pass for the \c LoopAnalysis results. -class LoopPrinterPass { +class LoopPrinterPass : public PassBase { raw_ostream &OS; public: explicit LoopPrinterPass(raw_ostream &OS) : OS(OS) {} PreservedAnalyses run(Function &F, AnalysisManager *AM); - - static StringRef name() { return "LoopPrinterPass"; } }; /// \brief The legacy pass manager's analysis pass to compute loop information. @@ -840,7 +829,7 @@ public: }; /// \brief Pass for printing a loop's contents as LLVM's text IR assembly. -class PrintLoopPass { +class PrintLoopPass : public PassBase { raw_ostream &OS; std::string Banner; @@ -849,7 +838,6 @@ public: PrintLoopPass(raw_ostream &OS, const std::string &Banner = ""); PreservedAnalyses run(Loop &L); - static StringRef name() { return "PrintLoopPass"; } }; } // End llvm namespace diff --git a/llvm/include/llvm/Analysis/LoopPassManager.h b/llvm/include/llvm/Analysis/LoopPassManager.h index da740ce5f19e..9fd4c7bd1414 100644 --- a/llvm/include/llvm/Analysis/LoopPassManager.h +++ b/llvm/include/llvm/Analysis/LoopPassManager.h @@ -44,7 +44,8 @@ typedef AnalysisManager LoopAnalysisManager; /// never use a loop analysis manager from within (transitively) a function /// pass manager unless your parent function pass has received a proxy result /// object for it. -class LoopAnalysisManagerFunctionProxy { +class LoopAnalysisManagerFunctionProxy + : public AnalysisBase { public: class Result { public: @@ -77,10 +78,6 @@ public: LoopAnalysisManager *LAM; }; - static void *ID() { return (void *)&PassID; } - - static StringRef name() { return "LoopAnalysisManagerFunctionProxy"; } - explicit LoopAnalysisManagerFunctionProxy(LoopAnalysisManager &LAM) : LAM(&LAM) {} // We have to explicitly define all the special member functions because MSVC @@ -107,8 +104,6 @@ public: Result run(Function &F); private: - static char PassID; - LoopAnalysisManager *LAM; }; @@ -124,7 +119,8 @@ private: /// This proxy *doesn't* manage the invalidation in any way. That is handled by /// the recursive return path of each layer of the pass manager and the /// returned PreservedAnalysis set. -class FunctionAnalysisManagerLoopProxy { +class FunctionAnalysisManagerLoopProxy + : public AnalysisBase { public: /// \brief Result proxy object for \c FunctionAnalysisManagerLoopProxy. class Result { @@ -148,10 +144,6 @@ public: const FunctionAnalysisManager *FAM; }; - static void *ID() { return (void *)&PassID; } - - static StringRef name() { return "FunctionAnalysisManagerLoopProxy"; } - FunctionAnalysisManagerLoopProxy(const FunctionAnalysisManager &FAM) : FAM(&FAM) {} // We have to explicitly define all the special member functions because MSVC @@ -172,8 +164,6 @@ public: Result run(Loop &) { return Result(*FAM); } private: - static char PassID; - const FunctionAnalysisManager *FAM; }; @@ -184,7 +174,9 @@ private: /// FunctionAnalysisManager it will run the \c LoopAnalysisManagerFunctionProxy /// analysis prior to running the loop passes over the function to enable a \c /// LoopAnalysisManager to be used within this run safely. -template class FunctionToLoopPassAdaptor { +template +class FunctionToLoopPassAdaptor + : public PassBase> { public: explicit FunctionToLoopPassAdaptor(LoopPassT Pass) : Pass(std::move(Pass)) {} @@ -250,8 +242,6 @@ public: return PA; } - static StringRef name() { return "FunctionToLoopPassAdaptor"; } - private: LoopPassT Pass; }; diff --git a/llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h b/llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h index ac01154bac6c..61b80435d404 100644 --- a/llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h @@ -63,20 +63,10 @@ public: }; /// Analysis pass providing a never-invalidated alias analysis result. -class ObjCARCAA { -public: +struct ObjCARCAA : AnalysisBase { typedef ObjCARCAAResult Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - ObjCARCAAResult run(Function &F, AnalysisManager *AM); - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "ObjCARCAA"; } - -private: - static char PassID; }; /// Legacy wrapper pass to provide the ObjCARCAAResult object. diff --git a/llvm/include/llvm/Analysis/PostDominators.h b/llvm/include/llvm/Analysis/PostDominators.h index 403d85af1379..8800d4ffd46c 100644 --- a/llvm/include/llvm/Analysis/PostDominators.h +++ b/llvm/include/llvm/Analysis/PostDominators.h @@ -37,34 +37,23 @@ struct PostDominatorTree : public DominatorTreeBase { }; /// \brief Analysis pass which computes a \c PostDominatorTree. -class PostDominatorTreeAnalysis { -public: +struct PostDominatorTreeAnalysis : AnalysisBase { /// \brief Provide the result typedef for this analysis pass. typedef PostDominatorTree Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - /// \brief Run the analysis pass over a function and produce a post dominator /// tree. PostDominatorTree run(Function &F); - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "PostDominatorTreeAnalysis"; } - -private: - static char PassID; }; /// \brief Printer pass for the \c PostDominatorTree. -class PostDominatorTreePrinterPass { +class PostDominatorTreePrinterPass + : public PassBase { raw_ostream &OS; public: explicit PostDominatorTreePrinterPass(raw_ostream &OS); PreservedAnalyses run(Function &F, AnalysisManager *AM); - - static StringRef name() { return "PostDominatorTreePrinterPass"; } }; struct PostDominatorTreeWrapperPass : public FunctionPass { diff --git a/llvm/include/llvm/Analysis/RegionInfo.h b/llvm/include/llvm/Analysis/RegionInfo.h index 72ef070473c8..69e00375de9d 100644 --- a/llvm/include/llvm/Analysis/RegionInfo.h +++ b/llvm/include/llvm/Analysis/RegionInfo.h @@ -923,37 +923,24 @@ public: }; /// \brief Analysis pass that exposes the \c RegionInfo for a function. -class RegionInfoAnalysis { - static char PassID; - -public: +struct RegionInfoAnalysis : AnalysisBase { typedef RegionInfo Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - - /// \brief Provide a name for the analysis for debugging and logging. - static StringRef name() { return "RegionInfoAnalysis"; } - RegionInfo run(Function &F, AnalysisManager *AM); }; /// \brief Printer pass for the \c RegionInfo. -class RegionInfoPrinterPass { +class RegionInfoPrinterPass : public PassBase { raw_ostream &OS; public: explicit RegionInfoPrinterPass(raw_ostream &OS); PreservedAnalyses run(Function &F, AnalysisManager *AM); - - static StringRef name() { return "RegionInfoPrinterPass"; } }; /// \brief Verifier pass for the \c RegionInfo. -struct RegionInfoVerifierPass { +struct RegionInfoVerifierPass : PassBase { PreservedAnalyses run(Function &F, AnalysisManager *AM); - - static StringRef name() { return "RegionInfoVerifierPass"; } }; template <> diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index 620f3cdd8ca0..8487c9695315 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1415,30 +1415,20 @@ namespace llvm { }; /// \brief Analysis pass that exposes the \c ScalarEvolution for a function. - class ScalarEvolutionAnalysis { - static char PassID; - - public: + struct ScalarEvolutionAnalysis : AnalysisBase { typedef ScalarEvolution Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - - /// \brief Provide a name for the analysis for debugging and logging. - static StringRef name() { return "ScalarEvolutionAnalysis"; } - ScalarEvolution run(Function &F, AnalysisManager *AM); }; /// \brief Printer pass for the \c ScalarEvolutionAnalysis results. - class ScalarEvolutionPrinterPass { + class ScalarEvolutionPrinterPass + : public PassBase { raw_ostream &OS; public: explicit ScalarEvolutionPrinterPass(raw_ostream &OS) : OS(OS) {} PreservedAnalyses run(Function &F, AnalysisManager *AM); - - static StringRef name() { return "ScalarEvolutionPrinterPass"; } }; class ScalarEvolutionWrapperPass : public FunctionPass { diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionAliasAnalysis.h b/llvm/include/llvm/Analysis/ScalarEvolutionAliasAnalysis.h index 7bbbf5562047..d3a83b6ac989 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolutionAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/ScalarEvolutionAliasAnalysis.h @@ -39,20 +39,10 @@ private: }; /// Analysis pass providing a never-invalidated alias analysis result. -class SCEVAA { -public: +struct SCEVAA : AnalysisBase { typedef SCEVAAResult Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - SCEVAAResult run(Function &F, AnalysisManager *AM); - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "SCEVAA"; } - -private: - static char PassID; }; /// Legacy wrapper pass to provide the SCEVAAResult object. diff --git a/llvm/include/llvm/Analysis/ScopedNoAliasAA.h b/llvm/include/llvm/Analysis/ScopedNoAliasAA.h index 175561687157..d53d6269ede4 100644 --- a/llvm/include/llvm/Analysis/ScopedNoAliasAA.h +++ b/llvm/include/llvm/Analysis/ScopedNoAliasAA.h @@ -48,20 +48,10 @@ private: }; /// Analysis pass providing a never-invalidated alias analysis result. -class ScopedNoAliasAA { -public: +struct ScopedNoAliasAA : AnalysisBase { typedef ScopedNoAliasAAResult Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - ScopedNoAliasAAResult run(Function &F, AnalysisManager *AM); - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "ScopedNoAliasAA"; } - -private: - static char PassID; }; /// Legacy wrapper pass to provide the ScopedNoAliasAAResult object. diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.h b/llvm/include/llvm/Analysis/TargetLibraryInfo.h index 7becdf033dd2..6e0776fd17b4 100644 --- a/llvm/include/llvm/Analysis/TargetLibraryInfo.h +++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.h @@ -16,6 +16,7 @@ #include "llvm/ADT/Triple.h" #include "llvm/IR/Function.h" #include "llvm/IR/Module.h" +#include "llvm/IR/PassManager.h" #include "llvm/Pass.h" namespace llvm { @@ -27,7 +28,6 @@ struct VecDesc { const char *VectorFnName; unsigned VectorizationFactor; }; -class PreservedAnalyses; namespace LibFunc { enum Func { @@ -262,13 +262,10 @@ public: /// /// Note that this pass's result cannot be invalidated, it is immutable for the /// life of the module. -class TargetLibraryAnalysis { +class TargetLibraryAnalysis : public AnalysisBase { public: typedef TargetLibraryInfo Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - /// \brief Default construct the library analysis. /// /// This will use the module's triple to construct the library info for that @@ -294,12 +291,7 @@ public: TargetLibraryInfo run(Module &M); TargetLibraryInfo run(Function &F); - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "TargetLibraryAnalysis"; } - private: - static char PassID; - Optional PresetInfoImpl; StringMap> Impls; diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h index 312585304d01..7c97b4fd3b93 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfo.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -25,6 +25,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" +#include "llvm/IR/PassManager.h" #include "llvm/Pass.h" #include "llvm/Support/DataTypes.h" #include @@ -34,7 +35,6 @@ namespace llvm { class Function; class GlobalValue; class Loop; -class PreservedAnalyses; class Type; class User; class Value; @@ -889,16 +889,10 @@ TargetTransformInfo::TargetTransformInfo(T Impl) /// is done in a subtarget specific way and LLVM supports compiling different /// functions targeting different subtargets in order to support runtime /// dispatch according to the observed subtarget. -class TargetIRAnalysis { +class TargetIRAnalysis : public AnalysisBase { public: typedef TargetTransformInfo Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "TargetIRAnalysis"; } - /// \brief Default construct a target IR analysis. /// /// This will use the module's datalayout to construct a baseline @@ -928,8 +922,6 @@ public: Result run(const Function &F); private: - static char PassID; - /// \brief The callback used to produce a result. /// /// We use a completely opaque callback so that targets can provide whatever diff --git a/llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h b/llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h index 7b44ac73f1fa..39b809af26a6 100644 --- a/llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h @@ -49,20 +49,10 @@ private: }; /// Analysis pass providing a never-invalidated alias analysis result. -class TypeBasedAA { -public: +struct TypeBasedAA : AnalysisBase { typedef TypeBasedAAResult Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - TypeBasedAAResult run(Function &F, AnalysisManager *AM); - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "TypeBasedAA"; } - -private: - static char PassID; }; /// Legacy wrapper pass to provide the TypeBasedAAResult object. diff --git a/llvm/include/llvm/IR/Dominators.h b/llvm/include/llvm/IR/Dominators.h index 7a16ce939bda..dece1533accb 100644 --- a/llvm/include/llvm/IR/Dominators.h +++ b/llvm/include/llvm/IR/Dominators.h @@ -182,40 +182,26 @@ template <> struct GraphTraits }; /// \brief Analysis pass which computes a \c DominatorTree. -class DominatorTreeAnalysis { -public: +struct DominatorTreeAnalysis : AnalysisBase { /// \brief Provide the result typedef for this analysis pass. typedef DominatorTree Result; - /// \brief Opaque, unique identifier for this analysis pass. - static void *ID() { return (void *)&PassID; } - /// \brief Run the analysis pass over a function and produce a dominator tree. DominatorTree run(Function &F); - - /// \brief Provide access to a name for this pass for debugging purposes. - static StringRef name() { return "DominatorTreeAnalysis"; } - -private: - static char PassID; }; /// \brief Printer pass for the \c DominatorTree. -class DominatorTreePrinterPass { +class DominatorTreePrinterPass : public PassBase { raw_ostream &OS; public: explicit DominatorTreePrinterPass(raw_ostream &OS); PreservedAnalyses run(Function &F, AnalysisManager *AM); - - static StringRef name() { return "DominatorTreePrinterPass"; } }; /// \brief Verifier pass for the \c DominatorTree. -struct DominatorTreeVerifierPass { +struct DominatorTreeVerifierPass : PassBase { PreservedAnalyses run(Function &F, AnalysisManager *AM); - - static StringRef name() { return "DominatorTreeVerifierPass"; } }; /// \brief Legacy analysis pass which computes a \c DominatorTree. diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h index c18f539b92d5..68f74f8a616b 100644 --- a/llvm/include/llvm/IR/PassManager.h +++ b/llvm/include/llvm/IR/PassManager.h @@ -167,6 +167,33 @@ private: // Forward declare the analysis manager template. template class AnalysisManager; +/// A CRTP mix-in base class to help define types that are valid passes. +/// +/// This provides some boiler plate for types that are passes. +template struct PassBase { + /// Returns the name of the derived pass type. + static StringRef name() { + StringRef Name = getTypeName(); + if (Name.startswith("llvm::")) + Name = Name.drop_front(strlen("llvm::")); + return Name; + } +}; + +/// A CRTP mix-in base class to help define types that are valid analyses. +/// +/// This provides some boiler plate for types that are analysis passes. +template class AnalysisBase : public PassBase { + static char PassID; + +public: + /// Returns an opaque, unique ID for this pass type. + static void *ID() { return (void *)&PassID; } +}; + +/// Private static data to provide unique ID. +template char AnalysisBase::PassID; + /// \brief Manages a sequence of passes over units of IR. /// /// A pass manager contains a sequence of passes to run over units of IR. It is @@ -178,7 +205,8 @@ template class AnalysisManager; /// that analysis manager to each pass it runs, as well as calling the analysis /// manager's invalidation routine with the PreservedAnalyses of each pass it /// runs. -template class PassManager { +template +class PassManager : public PassBase> { public: /// \brief Construct a pass manager. /// @@ -623,14 +651,11 @@ typedef AnalysisManager FunctionAnalysisManager; /// Note that the proxy's result is a move-only object and represents ownership /// of the validity of the analyses in the \c FunctionAnalysisManager it /// provides. -class FunctionAnalysisManagerModuleProxy { +class FunctionAnalysisManagerModuleProxy + : public AnalysisBase { public: class Result; - static void *ID() { return (void *)&PassID; } - - static StringRef name() { return "FunctionAnalysisManagerModuleProxy"; } - explicit FunctionAnalysisManagerModuleProxy(FunctionAnalysisManager &FAM) : FAM(&FAM) {} // We have to explicitly define all the special member functions because MSVC @@ -658,8 +683,6 @@ public: Result run(Module &M); private: - static char PassID; - FunctionAnalysisManager *FAM; }; @@ -717,7 +740,8 @@ private: /// This proxy *doesn't* manage the invalidation in any way. That is handled by /// the recursive return path of each layer of the pass manager and the /// returned PreservedAnalysis set. -class ModuleAnalysisManagerFunctionProxy { +class ModuleAnalysisManagerFunctionProxy + : public AnalysisBase { public: /// \brief Result proxy object for \c ModuleAnalysisManagerFunctionProxy. class Result { @@ -741,10 +765,6 @@ public: const ModuleAnalysisManager *MAM; }; - static void *ID() { return (void *)&PassID; } - - static StringRef name() { return "ModuleAnalysisManagerFunctionProxy"; } - ModuleAnalysisManagerFunctionProxy(const ModuleAnalysisManager &MAM) : MAM(&MAM) {} // We have to explicitly define all the special member functions because MSVC @@ -766,8 +786,6 @@ public: Result run(Function &) { return Result(*MAM); } private: - static char PassID; - const ModuleAnalysisManager *MAM; }; @@ -793,7 +811,9 @@ private: /// module. /// FIXME: Make the above true for all of LLVM's actual passes, some still /// violate this principle. -template class ModuleToFunctionPassAdaptor { +template +class ModuleToFunctionPassAdaptor + : public PassBase> { public: explicit ModuleToFunctionPassAdaptor(FunctionPassT Pass) : Pass(std::move(Pass)) {} @@ -848,8 +868,6 @@ public: return PA; } - static StringRef name() { return "ModuleToFunctionPassAdaptor"; } - private: FunctionPassT Pass; }; @@ -866,7 +884,8 @@ createModuleToFunctionPassAdaptor(FunctionPassT Pass) { /// /// This is a no-op pass which simply forces a specific analysis pass's result /// to be available when it is run. -template struct RequireAnalysisPass { +template +struct RequireAnalysisPass : PassBase> { /// \brief Run this pass over some unit of IR. /// /// This pass can be run over any unit of IR and use any analysis manager @@ -880,8 +899,6 @@ template struct RequireAnalysisPass { return PreservedAnalyses::all(); } - - static StringRef name() { return "RequireAnalysisPass"; } }; /// \brief A template utility pass to force an analysis result to be @@ -889,7 +906,8 @@ template struct RequireAnalysisPass { /// /// This is a no-op pass which simply forces a specific analysis result to be /// invalidated when it is run. -template struct InvalidateAnalysisPass { +template +struct InvalidateAnalysisPass : PassBase> { /// \brief Run this pass over some unit of IR. /// /// This pass can be run over any unit of IR and use any analysis manager @@ -905,21 +923,17 @@ template struct InvalidateAnalysisPass { return PreservedAnalyses::all(); } - - static StringRef name() { return "InvalidateAnalysisPass"; } }; /// \brief A utility pass that does nothing but preserves no analyses. /// /// As a consequence fo not preserving any analyses, this pass will force all /// analysis passes to be re-run to produce fresh results if any are needed. -struct InvalidateAllAnalysesPass { +struct InvalidateAllAnalysesPass : PassBase { /// \brief Run this pass over some unit of IR. template PreservedAnalyses run(IRUnitT &Arg) { return PreservedAnalyses::none(); } - - static StringRef name() { return "InvalidateAllAnalysesPass"; } }; } diff --git a/llvm/include/llvm/IR/Verifier.h b/llvm/include/llvm/IR/Verifier.h index 89039d24195e..a0c75de116d5 100644 --- a/llvm/include/llvm/IR/Verifier.h +++ b/llvm/include/llvm/IR/Verifier.h @@ -22,6 +22,7 @@ #define LLVM_IR_VERIFIER_H #include "llvm/ADT/StringRef.h" +#include "llvm/IR/PassManager.h" #include namespace llvm { @@ -30,7 +31,6 @@ class Function; class FunctionPass; class ModulePass; class Module; -class PreservedAnalyses; class raw_ostream; /// \brief Check a function for errors, useful for use when debugging a @@ -60,7 +60,7 @@ bool verifyModule(const Module &M, raw_ostream *OS = nullptr); /// nothing to do with \c VerifierPass. FunctionPass *createVerifierPass(bool FatalErrors = true); -class VerifierPass { +class VerifierPass : public PassBase { bool FatalErrors; public: @@ -68,8 +68,6 @@ public: PreservedAnalyses run(Module &M); PreservedAnalyses run(Function &F); - - static StringRef name() { return "VerifierPass"; } }; } // End llvm namespace diff --git a/llvm/include/llvm/Transforms/IPO/ForceFunctionAttrs.h b/llvm/include/llvm/Transforms/IPO/ForceFunctionAttrs.h index 0ff4afe79b0c..cf15f4631869 100644 --- a/llvm/include/llvm/Transforms/IPO/ForceFunctionAttrs.h +++ b/llvm/include/llvm/Transforms/IPO/ForceFunctionAttrs.h @@ -21,9 +21,7 @@ namespace llvm { /// Pass which forces specific function attributes into the IR, primarily as /// a debugging tool. -class ForceFunctionAttrsPass { -public: - static StringRef name() { return "ForceFunctionAttrsPass"; } +struct ForceFunctionAttrsPass : PassBase { PreservedAnalyses run(Module &M); }; diff --git a/llvm/include/llvm/Transforms/IPO/FunctionAttrs.h b/llvm/include/llvm/Transforms/IPO/FunctionAttrs.h index ad3c603a36d7..d4a1c3d56c7e 100644 --- a/llvm/include/llvm/Transforms/IPO/FunctionAttrs.h +++ b/llvm/include/llvm/Transforms/IPO/FunctionAttrs.h @@ -29,10 +29,7 @@ namespace llvm { /// access memory, or only read memory, and give them the readnone/readonly /// attribute. It also discovers function arguments that are not captured by /// the function and marks them with the nocapture attribute. -class PostOrderFunctionAttrsPass { -public: - static StringRef name() { return "PostOrderFunctionAttrsPass"; } - +struct PostOrderFunctionAttrsPass : PassBase { PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager *AM); }; diff --git a/llvm/include/llvm/Transforms/IPO/InferFunctionAttrs.h b/llvm/include/llvm/Transforms/IPO/InferFunctionAttrs.h index 80afc02c62ae..ef69de8d5127 100644 --- a/llvm/include/llvm/Transforms/IPO/InferFunctionAttrs.h +++ b/llvm/include/llvm/Transforms/IPO/InferFunctionAttrs.h @@ -23,9 +23,7 @@ namespace llvm { /// A pass which infers function attributes from the names and signatures of /// function declarations in a module. -class InferFunctionAttrsPass { -public: - static StringRef name() { return "InferFunctionAttrsPass"; } +struct InferFunctionAttrsPass : PassBase { PreservedAnalyses run(Module &M, AnalysisManager *AM); }; diff --git a/llvm/include/llvm/Transforms/IPO/StripDeadPrototypes.h b/llvm/include/llvm/Transforms/IPO/StripDeadPrototypes.h index 9dddd12871c4..12cf00a8f083 100644 --- a/llvm/include/llvm/Transforms/IPO/StripDeadPrototypes.h +++ b/llvm/include/llvm/Transforms/IPO/StripDeadPrototypes.h @@ -23,9 +23,7 @@ namespace llvm { /// Pass to remove unused function declarations. -class StripDeadPrototypesPass { -public: - static StringRef name() { return "StripDeadPrototypesPass"; } +struct StripDeadPrototypesPass : PassBase { PreservedAnalyses run(Module &M); }; diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombine.h b/llvm/include/llvm/Transforms/InstCombine/InstCombine.h index f48ec13107bc..7936e0765722 100644 --- a/llvm/include/llvm/Transforms/InstCombine/InstCombine.h +++ b/llvm/include/llvm/Transforms/InstCombine/InstCombine.h @@ -24,7 +24,7 @@ namespace llvm { -class InstCombinePass { +class InstCombinePass : public PassBase { InstCombineWorklist Worklist; public: diff --git a/llvm/include/llvm/Transforms/Scalar/ADCE.h b/llvm/include/llvm/Transforms/Scalar/ADCE.h index f9bc7b77c14a..a28e93dfdf9a 100644 --- a/llvm/include/llvm/Transforms/Scalar/ADCE.h +++ b/llvm/include/llvm/Transforms/Scalar/ADCE.h @@ -28,9 +28,7 @@ namespace llvm { /// instructions are dead until proven otherwise. This allows it to eliminate /// dead computations that other DCE passes do not catch, particularly involving /// loop computations. -class ADCEPass { -public: - static StringRef name() { return "ADCEPass"; } +struct ADCEPass : PassBase { PreservedAnalyses run(Function &F); }; } diff --git a/llvm/include/llvm/Transforms/Scalar/EarlyCSE.h b/llvm/include/llvm/Transforms/Scalar/EarlyCSE.h index e3dd3c050df6..24b02c86aaf1 100644 --- a/llvm/include/llvm/Transforms/Scalar/EarlyCSE.h +++ b/llvm/include/llvm/Transforms/Scalar/EarlyCSE.h @@ -26,10 +26,7 @@ namespace llvm { /// canonicalize things as it goes. It is intended to be fast and catch obvious /// cases so that instcombine and other passes are more effective. It is /// expected that a later pass of GVN will catch the interesting/hard cases. -class EarlyCSEPass { -public: - static StringRef name() { return "EarlyCSEPass"; } - +struct EarlyCSEPass : PassBase { /// \brief Run the pass over the function. PreservedAnalyses run(Function &F, AnalysisManager *AM); }; diff --git a/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h b/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h index 40283203f3a3..c78ae310d3e3 100644 --- a/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h +++ b/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h @@ -21,10 +21,7 @@ namespace llvm { -class LowerExpectIntrinsicPass { -public: - static StringRef name() { return "LowerExpectIntrinsicPass"; } - +struct LowerExpectIntrinsicPass : PassBase { /// \brief Run the pass over the function. /// /// This will lower all of th expect intrinsic calls in this function into diff --git a/llvm/include/llvm/Transforms/Scalar/SROA.h b/llvm/include/llvm/Transforms/Scalar/SROA.h index 2c441ce538bb..c6fe735a2918 100644 --- a/llvm/include/llvm/Transforms/Scalar/SROA.h +++ b/llvm/include/llvm/Transforms/Scalar/SROA.h @@ -51,7 +51,7 @@ class SROALegacyPass; /// onto insert and extract operations on a vector value, and convert them to /// this form. By doing so, it will enable promotion of vector aggregates to /// SSA vector values. -class SROA { +class SROA : public PassBase { LLVMContext *C; DominatorTree *DT; AssumptionCache *AC; @@ -101,8 +101,6 @@ class SROA { public: SROA() : C(nullptr), DT(nullptr), AC(nullptr) {} - static StringRef name() { return "SROA"; } - /// \brief Run the pass over the function. PreservedAnalyses run(Function &F, AnalysisManager *AM); diff --git a/llvm/include/llvm/Transforms/Scalar/SimplifyCFG.h b/llvm/include/llvm/Transforms/Scalar/SimplifyCFG.h index ef28e0f78a4c..6a102c5b7d86 100644 --- a/llvm/include/llvm/Transforms/Scalar/SimplifyCFG.h +++ b/llvm/include/llvm/Transforms/Scalar/SimplifyCFG.h @@ -25,12 +25,10 @@ namespace llvm { /// This pass iteratively simplifies the entire CFG of a function, removing /// unnecessary control flows and bringing it into the canonical form expected /// by the rest of the mid-level optimizer. -class SimplifyCFGPass { +class SimplifyCFGPass : public PassBase { int BonusInstThreshold; public: - static StringRef name() { return "SimplifyCFGPass"; } - /// \brief Construct a pass with the default thresholds. SimplifyCFGPass(); diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp index 937841f206f2..a30aedc4060f 100644 --- a/llvm/lib/Analysis/AliasAnalysis.cpp +++ b/llvm/lib/Analysis/AliasAnalysis.cpp @@ -390,9 +390,6 @@ bool AAResults::canInstructionRangeModRef(const Instruction &I1, // Provide a definition for the root virtual destructor. AAResults::Concept::~Concept() {} -// Provide a definition for the static object used to identify passes. -char AAManager::PassID; - namespace { /// A wrapper pass for external alias analyses. This just squirrels away the /// callback used to run any analyses and register their results. diff --git a/llvm/lib/Analysis/AssumptionCache.cpp b/llvm/lib/Analysis/AssumptionCache.cpp index f468a43ef0b8..6af2dc12d066 100644 --- a/llvm/lib/Analysis/AssumptionCache.cpp +++ b/llvm/lib/Analysis/AssumptionCache.cpp @@ -74,8 +74,6 @@ void AssumptionCache::registerAssumption(CallInst *CI) { #endif } -char AssumptionAnalysis::PassID; - PreservedAnalyses AssumptionPrinterPass::run(Function &F, AnalysisManager *AM) { AssumptionCache &AC = AM->getResult(F); diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index 74aae76793cf..58aa670d3877 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -1586,8 +1586,6 @@ bool BasicAAResult::constantOffsetHeuristic( // BasicAliasAnalysis Pass //===----------------------------------------------------------------------===// -char BasicAA::PassID; - BasicAAResult BasicAA::run(Function &F, AnalysisManager *AM) { return BasicAAResult(F.getParent()->getDataLayout(), AM->getResult(F), diff --git a/llvm/lib/Analysis/CFLAliasAnalysis.cpp b/llvm/lib/Analysis/CFLAliasAnalysis.cpp index 969147621e88..9dc74e4eed4f 100644 --- a/llvm/lib/Analysis/CFLAliasAnalysis.cpp +++ b/llvm/lib/Analysis/CFLAliasAnalysis.cpp @@ -1093,8 +1093,6 @@ CFLAAResult CFLAA::run(Function &F, AnalysisManager *AM) { return CFLAAResult(AM->getResult(F)); } -char CFLAA::PassID; - char CFLAAWrapperPass::ID = 0; INITIALIZE_PASS_BEGIN(CFLAAWrapperPass, "cfl-aa", "CFL-Based Alias Analysis", false, true) diff --git a/llvm/lib/Analysis/CGSCCPassManager.cpp b/llvm/lib/Analysis/CGSCCPassManager.cpp index efffc8e4eba2..69c37f57528c 100644 --- a/llvm/lib/Analysis/CGSCCPassManager.cpp +++ b/llvm/lib/Analysis/CGSCCPassManager.cpp @@ -13,8 +13,6 @@ using namespace llvm; -char CGSCCAnalysisManagerModuleProxy::PassID; - CGSCCAnalysisManagerModuleProxy::Result CGSCCAnalysisManagerModuleProxy::run(Module &M) { assert(CGAM->empty() && "CGSCC analyses ran prior to the module proxy!"); @@ -44,10 +42,6 @@ bool CGSCCAnalysisManagerModuleProxy::Result::invalidate( return false; } -char ModuleAnalysisManagerCGSCCProxy::PassID; - -char FunctionAnalysisManagerCGSCCProxy::PassID; - FunctionAnalysisManagerCGSCCProxy::Result FunctionAnalysisManagerCGSCCProxy::run(LazyCallGraph::SCC &C) { return Result(*FAM); @@ -75,5 +69,3 @@ bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate( // Return false to indicate that this result is still a valid proxy. return false; } - -char CGSCCAnalysisManagerFunctionProxy::PassID; diff --git a/llvm/lib/Analysis/CallGraph.cpp b/llvm/lib/Analysis/CallGraph.cpp index 7cec962678e8..426684be58a6 100644 --- a/llvm/lib/Analysis/CallGraph.cpp +++ b/llvm/lib/Analysis/CallGraph.cpp @@ -263,8 +263,6 @@ void CallGraphNode::replaceCallEdge(CallSite CS, // Out-of-line definitions of CallGraphAnalysis class members. // -char CallGraphAnalysis::PassID; - //===----------------------------------------------------------------------===// // Implementations of the CallGraphWrapperPass class methods. // diff --git a/llvm/lib/Analysis/DominanceFrontier.cpp b/llvm/lib/Analysis/DominanceFrontier.cpp index ef7062da7759..00904a95ce7f 100644 --- a/llvm/lib/Analysis/DominanceFrontier.cpp +++ b/llvm/lib/Analysis/DominanceFrontier.cpp @@ -56,8 +56,6 @@ LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const { } #endif -char DominanceFrontierAnalysis::PassID; - DominanceFrontier DominanceFrontierAnalysis::run(Function &F, FunctionAnalysisManager *AM) { DominanceFrontier DF; diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp index 549b37451eb3..01ef5af4e9b1 100644 --- a/llvm/lib/Analysis/GlobalsModRef.cpp +++ b/llvm/lib/Analysis/GlobalsModRef.cpp @@ -940,8 +940,6 @@ GlobalsAAResult GlobalsAA::run(Module &M, AnalysisManager *AM) { AM->getResult(M)); } -char GlobalsAA::PassID; - char GlobalsAAWrapperPass::ID = 0; INITIALIZE_PASS_BEGIN(GlobalsAAWrapperPass, "globals-aa", "Globals Alias Analysis", false, true) diff --git a/llvm/lib/Analysis/LazyCallGraph.cpp b/llvm/lib/Analysis/LazyCallGraph.cpp index 5de90782a31a..88f5cd7dd9ff 100644 --- a/llvm/lib/Analysis/LazyCallGraph.cpp +++ b/llvm/lib/Analysis/LazyCallGraph.cpp @@ -1499,8 +1499,6 @@ LazyCallGraph::RefSCC *LazyCallGraph::getNextRefSCCInPostOrder() { } } -char LazyCallGraphAnalysis::PassID; - LazyCallGraphPrinterPass::LazyCallGraphPrinterPass(raw_ostream &OS) : OS(OS) {} static void printNode(raw_ostream &OS, LazyCallGraph::Node &N) { diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index 14ca91dc5e09..bcec24c822f3 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -641,8 +641,6 @@ void LoopInfo::markAsRemoved(Loop *Unloop) { } } -char LoopAnalysis::PassID; - LoopInfo LoopAnalysis::run(Function &F, AnalysisManager *AM) { // FIXME: Currently we create a LoopInfo from scratch for every function. // This may prove to be too wasteful due to deallocating and re-allocating diff --git a/llvm/lib/Analysis/LoopPassManager.cpp b/llvm/lib/Analysis/LoopPassManager.cpp index b1d1140d11bb..1d87e07b837c 100644 --- a/llvm/lib/Analysis/LoopPassManager.cpp +++ b/llvm/lib/Analysis/LoopPassManager.cpp @@ -11,8 +11,6 @@ using namespace llvm; -char LoopAnalysisManagerFunctionProxy::PassID; - LoopAnalysisManagerFunctionProxy::Result LoopAnalysisManagerFunctionProxy::run(Function &F) { // TODO: In FunctionAnalysisManagerModuleProxy we assert that the @@ -41,5 +39,3 @@ bool LoopAnalysisManagerFunctionProxy::Result::invalidate( // Return false to indicate that this result is still a valid proxy. return false; } - -char FunctionAnalysisManagerLoopProxy::PassID; diff --git a/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp b/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp index 25f660ffe221..31e46e384d2e 100644 --- a/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp +++ b/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp @@ -136,8 +136,6 @@ ObjCARCAAResult ObjCARCAA::run(Function &F, AnalysisManager *AM) { AM->getResult(F)); } -char ObjCARCAA::PassID; - char ObjCARCAAWrapperPass::ID = 0; INITIALIZE_PASS_BEGIN(ObjCARCAAWrapperPass, "objc-arc-aa", "ObjC-ARC-Based Alias Analysis", false, true) diff --git a/llvm/lib/Analysis/PostDominators.cpp b/llvm/lib/Analysis/PostDominators.cpp index b515108fafb2..d617a876b841 100644 --- a/llvm/lib/Analysis/PostDominators.cpp +++ b/llvm/lib/Analysis/PostDominators.cpp @@ -44,8 +44,6 @@ FunctionPass* llvm::createPostDomTree() { return new PostDominatorTreeWrapperPass(); } -char PostDominatorTreeAnalysis::PassID; - PostDominatorTree PostDominatorTreeAnalysis::run(Function &F) { PostDominatorTree PDT; PDT.recalculate(F); diff --git a/llvm/lib/Analysis/RegionInfo.cpp b/llvm/lib/Analysis/RegionInfo.cpp index 72b3217dc6f4..40501e6f7b65 100644 --- a/llvm/lib/Analysis/RegionInfo.cpp +++ b/llvm/lib/Analysis/RegionInfo.cpp @@ -185,8 +185,6 @@ namespace llvm { // RegionInfoAnalysis implementation // -char RegionInfoAnalysis::PassID; - RegionInfo RegionInfoAnalysis::run(Function &F, AnalysisManager *AM) { RegionInfo RI; auto *DT = &AM->getResult(F); diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index f1f57c6fbd62..2056306e1270 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -9554,8 +9554,6 @@ void ScalarEvolution::verify() const { // TODO: Verify more things. } -char ScalarEvolutionAnalysis::PassID; - ScalarEvolution ScalarEvolutionAnalysis::run(Function &F, AnalysisManager *AM) { return ScalarEvolution(F, AM->getResult(F), diff --git a/llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp b/llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp index 2e50c80c4e73..5d04d89f1d20 100644 --- a/llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionAliasAnalysis.cpp @@ -116,8 +116,6 @@ SCEVAAResult SCEVAA::run(Function &F, AnalysisManager *AM) { AM->getResult(F)); } -char SCEVAA::PassID; - char SCEVAAWrapperPass::ID = 0; INITIALIZE_PASS_BEGIN(SCEVAAWrapperPass, "scev-aa", "ScalarEvolution-based Alias Analysis", false, true) diff --git a/llvm/lib/Analysis/ScopedNoAliasAA.cpp b/llvm/lib/Analysis/ScopedNoAliasAA.cpp index bd4451420b69..4735ed8933b0 100644 --- a/llvm/lib/Analysis/ScopedNoAliasAA.cpp +++ b/llvm/lib/Analysis/ScopedNoAliasAA.cpp @@ -178,8 +178,6 @@ ScopedNoAliasAAResult ScopedNoAliasAA::run(Function &F, return ScopedNoAliasAAResult(AM->getResult(F)); } -char ScopedNoAliasAA::PassID; - char ScopedNoAliasAAWrapperPass::ID = 0; INITIALIZE_PASS_BEGIN(ScopedNoAliasAAWrapperPass, "scoped-noalias", "Scoped NoAlias Alias Analysis", false, true) diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp index 3bd54c47e609..950ee549f809 100644 --- a/llvm/lib/Analysis/TargetLibraryInfo.cpp +++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp @@ -636,8 +636,6 @@ TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass( initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); } -char TargetLibraryAnalysis::PassID; - // Register the basic pass. INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo", "Target Library Information", false, true) diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp index bd9578988348..a9e18e01caaf 100644 --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -377,8 +377,6 @@ TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F) { return TTICallback(F); } -char TargetIRAnalysis::PassID; - TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) { return Result(F.getParent()->getDataLayout()); } diff --git a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp index 9f923913ca27..1ef61e8e6db2 100644 --- a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp +++ b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp @@ -588,8 +588,6 @@ TypeBasedAAResult TypeBasedAA::run(Function &F, AnalysisManager *AM) { return TypeBasedAAResult(AM->getResult(F)); } -char TypeBasedAA::PassID; - char TypeBasedAAWrapperPass::ID = 0; INITIALIZE_PASS_BEGIN(TypeBasedAAWrapperPass, "tbaa", "Type-Based Alias Analysis", false, true) diff --git a/llvm/lib/IR/Dominators.cpp b/llvm/lib/IR/Dominators.cpp index b9d4fb7de881..c47091e29088 100644 --- a/llvm/lib/IR/Dominators.cpp +++ b/llvm/lib/IR/Dominators.cpp @@ -308,8 +308,6 @@ DominatorTree DominatorTreeAnalysis::run(Function &F) { return DT; } -char DominatorTreeAnalysis::PassID; - DominatorTreePrinterPass::DominatorTreePrinterPass(raw_ostream &OS) : OS(OS) {} PreservedAnalyses DominatorTreePrinterPass::run(Function &F, diff --git a/llvm/lib/IR/PassManager.cpp b/llvm/lib/IR/PassManager.cpp index f55db9c1e649..06491ae08a70 100644 --- a/llvm/lib/IR/PassManager.cpp +++ b/llvm/lib/IR/PassManager.cpp @@ -13,8 +13,6 @@ using namespace llvm; -char FunctionAnalysisManagerModuleProxy::PassID; - FunctionAnalysisManagerModuleProxy::Result FunctionAnalysisManagerModuleProxy::run(Module &M) { assert(FAM->empty() && "Function analyses ran prior to the module proxy!"); @@ -43,5 +41,3 @@ bool FunctionAnalysisManagerModuleProxy::Result::invalidate( // Return false to indicate that this result is still a valid proxy. return false; } - -char ModuleAnalysisManagerFunctionProxy::PassID; diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 93daad7eca09..a6a4cb626470 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 { 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 { 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 { 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 { 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) { diff --git a/llvm/test/Other/new-pass-manager.ll b/llvm/test/Other/new-pass-manager.ll index 0c16d59c8c08..f1a7ef68ff67 100644 --- a/llvm/test/Other/new-pass-manager.ll +++ b/llvm/test/Other/new-pass-manager.ll @@ -21,7 +21,7 @@ ; CHECK-CGSCC-PASS: Starting llvm::Module pass manager run ; CHECK-CGSCC-PASS-NEXT: Running pass: ModuleToPostOrderCGSCCPassAdaptor ; CHECK-CGSCC-PASS-NEXT: Running analysis: CGSCCAnalysisManagerModuleProxy -; CHECK-CGSCC-PASS-NEXT: Running analysis: Lazy CallGraph Analysis +; CHECK-CGSCC-PASS-NEXT: Running analysis: LazyCallGraphAnalysis ; CHECK-CGSCC-PASS-NEXT: Starting llvm::LazyCallGraph::SCC pass manager run ; CHECK-CGSCC-PASS-NEXT: Running pass: NoOpCGSCCPass ; CHECK-CGSCC-PASS-NEXT: Finished llvm::LazyCallGraph::SCC pass manager run diff --git a/llvm/unittests/IR/PassManagerTest.cpp b/llvm/unittests/IR/PassManagerTest.cpp index 37939768aaf8..857b5283c41b 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; };