llvm.org GIT mirror llvm / 18e9a2b
[PM] Rename the CRTP mixin base classes for the new pass manager to clarify their purpose. Firstly, call them "...Mixin" types so it is clear that there is no type hierarchy being formed here. Secondly, use the term 'Info' to clarify that they aren't adding any interesting *semantics* to the passes or analyses, just exposing APIs used by the management layer to get information about the pass or analysis. Thanks to Manuel for helping pin down the naming confusion here and come up with effective names to address it. In case you already have some out-of-tree stuff, the following should be roughly what you want to update: perl -pi -e 's/\b(Pass|Analysis)Base\b/\1InfoMixin/g' git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263217 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 3 years ago
38 changed file(s) with 114 addition(s) and 100 deletion(s). Raw diff Collapse all Expand all
837837 /// This manager effectively wraps the AnalysisManager for registering alias
838838 /// analyses. When you register your alias analysis with this manager, it will
839839 /// ensure the analysis itself is registered with its AnalysisManager.
840 class AAManager : public AnalysisBase {
840 class AAManager : public AnalysisInfoMixin {
841841 public:
842842 typedef AAResults Result;
843843
873873 }
874874
875875 private:
876 friend AnalysisBase;
876 friend AnalysisInfoMixin;
877877 static char PassID;
878878
879879 SmallVector &AM,
3030 namespace llvm {
3131 class AAResults;
3232
33 class AAEvaluator : public PassBase {
33 class AAEvaluator : public PassInfoMixin {
3434 int64_t FunctionCount;
3535 int64_t NoAliasCount, MayAliasCount, PartialAliasCount, MustAliasCount;
3636 int64_t NoModRefCount, ModCount, RefCount, ModRefCount;
9292 ///
9393 /// This analysis is intended for use with the new pass manager and will vend
9494 /// assumption caches for a given function.
95 class AssumptionAnalysis : public AnalysisBase {
96 friend AnalysisBase;
95 class AssumptionAnalysis : public AnalysisInfoMixin {
96 friend AnalysisInfoMixin;
9797 static char PassID;
9898
9999 public:
109109 };
110110
111111 /// \brief Printer pass for the \c AssumptionAnalysis results.
112 class AssumptionPrinterPass : public PassBase {
112 class AssumptionPrinterPass : public PassInfoMixin {
113113 raw_ostream &OS;
114114
115115 public:
179179 };
180180
181181 /// Analysis pass providing a never-invalidated alias analysis result.
182 class BasicAA : public AnalysisBase {
183 friend AnalysisBase;
182 class BasicAA : public AnalysisInfoMixin {
183 friend AnalysisInfoMixin;
184184 static char PassID;
185185
186186 public:
108108 ///
109109 /// FIXME: We really should refactor CFL to use the analysis more heavily, and
110110 /// in particular to leverage invalidation to trigger re-computation of sets.
111 class CFLAA : public AnalysisBase {
112 friend AnalysisBase;
111 class CFLAA : public AnalysisInfoMixin {
112 friend AnalysisInfoMixin;
113113 static char PassID;
114114
115115 public:
6464 /// within this run safely.
6565 template
6666 class ModuleToPostOrderCGSCCPassAdaptor
67 : public PassBase> {
67 : public PassInfoMixin> {
6868 public:
6969 explicit ModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT Pass)
7070 : Pass(std::move(Pass)) {}
158158 /// within this run safely.
159159 template
160160 class CGSCCToFunctionPassAdaptor
161 : public PassBase> {
161 : public PassInfoMixin> {
162162 public:
163163 explicit CGSCCToFunctionPassAdaptor(FunctionPassT Pass)
164164 : Pass(std::move(Pass)) {}
294294 /// This class implements the concept of an analysis pass used by the \c
295295 /// ModuleAnalysisManager to run an analysis over a module and cache the
296296 /// resulting data.
297 class CallGraphAnalysis : public AnalysisBase {
298 friend AnalysisBase;
297 class CallGraphAnalysis : public AnalysisInfoMixin {
298 friend AnalysisInfoMixin;
299299 static char PassID;
300300
301301 public:
309309 };
310310
311311 /// \brief Printer pass for the \c CallGraphAnalysis results.
312 class CallGraphPrinterPass : public PassBase {
312 class CallGraphPrinterPass : public PassInfoMixin {
313313 raw_ostream &OS;
314314
315315 public:
168168
169169 /// \brief Analysis pass which computes a \c DominanceFrontier.
170170 class DominanceFrontierAnalysis
171 : public AnalysisBase {
172 friend AnalysisBase;
171 : public AnalysisInfoMixin {
172 friend AnalysisInfoMixin;
173173 static char PassID;
174174
175175 public:
182182
183183 /// \brief Printer pass for the \c DominanceFrontier.
184184 class DominanceFrontierPrinterPass
185 : public PassBase {
185 : public PassInfoMixin {
186186 raw_ostream &OS;
187187
188188 public:
117117 };
118118
119119 /// Analysis pass providing a never-invalidated alias analysis result.
120 class GlobalsAA : public AnalysisBase {
121 friend AnalysisBase;
120 class GlobalsAA : public AnalysisInfoMixin {
121 friend AnalysisInfoMixin;
122122 static char PassID;
123123
124124 public:
894894 };
895895
896896 /// An analysis pass which computes the call graph for a module.
897 class LazyCallGraphAnalysis : public AnalysisBase {
898 friend AnalysisBase;
897 class LazyCallGraphAnalysis : public AnalysisInfoMixin {
898 friend AnalysisInfoMixin;
899899 static char PassID;
900900
901901 public:
912912 /// A pass which prints the call graph to a \c raw_ostream.
913913 ///
914914 /// This is primarily useful for testing the analysis.
915 class LazyCallGraphPrinterPass : public PassBase {
915 class LazyCallGraphPrinterPass
916 : public PassInfoMixin {
916917 raw_ostream &OS;
917918
918919 public:
786786 };
787787
788788 /// \brief Analysis pass that exposes the \c LoopInfo for a function.
789 class LoopAnalysis : public AnalysisBase {
790 friend AnalysisBase;
789 class LoopAnalysis : public AnalysisInfoMixin {
790 friend AnalysisInfoMixin;
791791 static char PassID;
792792
793793 public:
797797 };
798798
799799 /// \brief Printer pass for the \c LoopAnalysis results.
800 class LoopPrinterPass : public PassBase {
800 class LoopPrinterPass : public PassInfoMixin {
801801 raw_ostream &OS;
802802
803803 public:
832832 };
833833
834834 /// \brief Pass for printing a loop's contents as LLVM's text IR assembly.
835 class PrintLoopPass : public PassBase {
835 class PrintLoopPass : public PassInfoMixin {
836836 raw_ostream &OS;
837837 std::string Banner;
838838
5656 /// LoopAnalysisManager to be used within this run safely.
5757 template
5858 class FunctionToLoopPassAdaptor
59 : public PassBase> {
59 : public PassInfoMixin> {
6060 public:
6161 explicit FunctionToLoopPassAdaptor(LoopPassT Pass)
6262 : Pass(std::move(Pass)) {}
470470 ///
471471 /// This is essentially a no-op because the results are computed entirely
472472 /// lazily.
473 class MemoryDependenceAnalysis : public AnalysisBase {
474 friend AnalysisBase;
473 class MemoryDependenceAnalysis
474 : public AnalysisInfoMixin {
475 friend AnalysisInfoMixin;
475476 static char PassID;
476477
477478 public:
6060 };
6161
6262 /// Analysis pass providing a never-invalidated alias analysis result.
63 class ObjCARCAA : public AnalysisBase {
64 friend AnalysisBase;
63 class ObjCARCAA : public AnalysisInfoMixin {
64 friend AnalysisInfoMixin;
6565 static char PassID;
6666
6767 public:
3737
3838 /// \brief Analysis pass which computes a \c PostDominatorTree.
3939 class PostDominatorTreeAnalysis
40 : public AnalysisBase {
41 friend AnalysisBase;
40 : public AnalysisInfoMixin {
41 friend AnalysisInfoMixin;
4242 static char PassID;
4343
4444 public:
5252
5353 /// \brief Printer pass for the \c PostDominatorTree.
5454 class PostDominatorTreePrinterPass
55 : public PassBase {
55 : public PassInfoMixin {
5656 raw_ostream &OS;
5757
5858 public:
922922 };
923923
924924 /// \brief Analysis pass that exposes the \c RegionInfo for a function.
925 class RegionInfoAnalysis : public AnalysisBase {
926 friend AnalysisBase;
925 class RegionInfoAnalysis : public AnalysisInfoMixin {
926 friend AnalysisInfoMixin;
927927 static char PassID;
928928
929929 public:
933933 };
934934
935935 /// \brief Printer pass for the \c RegionInfo.
936 class RegionInfoPrinterPass : public PassBase {
936 class RegionInfoPrinterPass : public PassInfoMixin {
937937 raw_ostream &OS;
938938
939939 public:
942942 };
943943
944944 /// \brief Verifier pass for the \c RegionInfo.
945 struct RegionInfoVerifierPass : PassBase {
945 struct RegionInfoVerifierPass : PassInfoMixin {
946946 PreservedAnalyses run(Function &F, AnalysisManager *AM);
947947 };
948948
14291429 };
14301430
14311431 /// \brief Analysis pass that exposes the \c ScalarEvolution for a function.
1432 class ScalarEvolutionAnalysis : public AnalysisBase {
1433 friend AnalysisBase;
1432 class ScalarEvolutionAnalysis
1433 : public AnalysisInfoMixin {
1434 friend AnalysisInfoMixin;
14341435 static char PassID;
14351436
14361437 public:
14411442
14421443 /// \brief Printer pass for the \c ScalarEvolutionAnalysis results.
14431444 class ScalarEvolutionPrinterPass
1444 : public PassBase {
1445 : public PassInfoMixin {
14451446 raw_ostream &OS;
14461447
14471448 public:
3737 };
3838
3939 /// Analysis pass providing a never-invalidated alias analysis result.
40 class SCEVAA : public AnalysisBase {
41 friend AnalysisBase;
40 class SCEVAA : public AnalysisInfoMixin {
41 friend AnalysisInfoMixin;
4242 static char PassID;
4343
4444 public:
4646 };
4747
4848 /// Analysis pass providing a never-invalidated alias analysis result.
49 class ScopedNoAliasAA : public AnalysisBase {
50 friend AnalysisBase;
49 class ScopedNoAliasAA : public AnalysisInfoMixin {
50 friend AnalysisInfoMixin;
5151 static char PassID;
5252
5353 public:
261261 ///
262262 /// Note that this pass's result cannot be invalidated, it is immutable for the
263263 /// life of the module.
264 class TargetLibraryAnalysis : public AnalysisBase {
264 class TargetLibraryAnalysis : public AnalysisInfoMixin {
265265 public:
266266 typedef TargetLibraryInfo Result;
267267
291291 TargetLibraryInfo run(Function &F);
292292
293293 private:
294 friend AnalysisBase;
294 friend AnalysisInfoMixin;
295295 static char PassID;
296296
297297 Optional PresetInfoImpl;
888888 /// is done in a subtarget specific way and LLVM supports compiling different
889889 /// functions targeting different subtargets in order to support runtime
890890 /// dispatch according to the observed subtarget.
891 class TargetIRAnalysis : public AnalysisBase {
891 class TargetIRAnalysis : public AnalysisInfoMixin {
892892 public:
893893 typedef TargetTransformInfo Result;
894894
921921 Result run(const Function &F);
922922
923923 private:
924 friend AnalysisBase;
924 friend AnalysisInfoMixin;
925925 static char PassID;
926926
927927 /// \brief The callback used to produce a result.
4747 };
4848
4949 /// Analysis pass providing a never-invalidated alias analysis result.
50 class TypeBasedAA : public AnalysisBase {
51 friend AnalysisBase;
50 class TypeBasedAA : public AnalysisInfoMixin {
51 friend AnalysisInfoMixin;
5252 static char PassID;
5353
5454 public:
181181 };
182182
183183 /// \brief Analysis pass which computes a \c DominatorTree.
184 class DominatorTreeAnalysis : public AnalysisBase {
185 friend AnalysisBase;
184 class DominatorTreeAnalysis : public AnalysisInfoMixin {
185 friend AnalysisInfoMixin;
186186 static char PassID;
187187
188188 public:
194194 };
195195
196196 /// \brief Printer pass for the \c DominatorTree.
197 class DominatorTreePrinterPass : public PassBase {
197 class DominatorTreePrinterPass
198 : public PassInfoMixin {
198199 raw_ostream &OS;
199200
200201 public:
203204 };
204205
205206 /// \brief Verifier pass for the \c DominatorTree.
206 struct DominatorTreeVerifierPass : PassBase {
207 struct DominatorTreeVerifierPass : PassInfoMixin {
207208 PreservedAnalyses run(Function &F, AnalysisManager *AM);
208209 };
209210
166166 // Forward declare the analysis manager template.
167167 template class AnalysisManager;
168168
169 /// A CRTP mix-in base class to help define types that are valid passes.
169 /// A CRTP mix-in to automatically provide informational APIs needed for
170 /// passes.
170171 ///
171172 /// This provides some boiler plate for types that are passes.
172 template struct PassBase {
173 template struct PassInfoMixin {
173174 /// Returns the name of the derived pass type.
174175 static StringRef name() {
175176 StringRef Name = getTypeName();
179180 }
180181 };
181182
182 /// A CRTP mix-in base class to help define types that are valid analyses.
183 ///
184 /// This provides some boiler plate for types that are analysis passes.
185 template struct AnalysisBase : PassBase {
183 /// A CRTP mix-in to automatically provide informational APIs needed for
184 /// analysis passes.
185 ///
186 /// This provides some boiler plate for types that are analysis passes. It
187 /// automatically mixes in \c PassInfoMixin and adds informational APIs
188 /// specifically used for analyses.
189 template
190 struct AnalysisInfoMixin : PassInfoMixin {
186191 /// Returns an opaque, unique ID for this pass type.
187192 ///
188193 /// Note that this requires the derived type provide a static member whose
211216 /// manager's invalidation routine with the PreservedAnalyses of each pass it
212217 /// runs.
213218 template
214 class PassManager : public PassBase> {
219 class PassManager : public PassInfoMixin> {
215220 public:
216221 /// \brief Construct a pass manager.
217222 ///
662667 /// provides.
663668 template
664669 class InnerAnalysisManagerProxy
665 : public AnalysisBase<
670 : public AnalysisInfoMixin<
666671 InnerAnalysisManagerProxy> {
667672 public:
668673 class Result {
745750 Result run(IRUnitT &IR) { return Result(*AM); }
746751
747752 private:
748 friend AnalysisBase>;
753 friend AnalysisInfoMixin<
754 InnerAnalysisManagerProxy>;
749755 static char PassID;
750756
751757 AnalysisManagerT *AM;
774780 /// returned PreservedAnalysis set.
775781 template
776782 class OuterAnalysisManagerProxy
777 : public AnalysisBase<
783 : public AnalysisInfoMixin<
778784 OuterAnalysisManagerProxy> {
779785 public:
780786 /// \brief Result proxy object for \c OuterAnalysisManagerProxy.
817823 Result run(IRUnitT &) { return Result(*AM); }
818824
819825 private:
820 friend AnalysisBase>;
826 friend AnalysisInfoMixin<
827 OuterAnalysisManagerProxy>;
821828 static char PassID;
822829
823830 const AnalysisManagerT *AM;
856863 /// violate this principle.
857864 template
858865 class ModuleToFunctionPassAdaptor
859 : public PassBase> {
866 : public PassInfoMixin> {
860867 public:
861868 explicit ModuleToFunctionPassAdaptor(FunctionPassT Pass)
862869 : Pass(std::move(Pass)) {}
928935 /// This is a no-op pass which simply forces a specific analysis pass's result
929936 /// to be available when it is run.
930937 template
931 struct RequireAnalysisPass : PassBase> {
938 struct RequireAnalysisPass : PassInfoMixin> {
932939 /// \brief Run this pass over some unit of IR.
933940 ///
934941 /// This pass can be run over any unit of IR and use any analysis manager
950957 /// This is a no-op pass which simply forces a specific analysis result to be
951958 /// invalidated when it is run.
952959 template
953 struct InvalidateAnalysisPass : PassBase> {
960 struct InvalidateAnalysisPass
961 : PassInfoMixin> {
954962 /// \brief Run this pass over some unit of IR.
955963 ///
956964 /// This pass can be run over any unit of IR and use any analysis manager
972980 ///
973981 /// As a consequence fo not preserving any analyses, this pass will force all
974982 /// analysis passes to be re-run to produce fresh results if any are needed.
975 struct InvalidateAllAnalysesPass : PassBase {
983 struct InvalidateAllAnalysesPass : PassInfoMixin {
976984 /// \brief Run this pass over some unit of IR.
977985 template PreservedAnalyses run(IRUnitT &Arg) {
978986 return PreservedAnalyses::none();
5959 /// nothing to do with \c VerifierPass.
6060 FunctionPass *createVerifierPass(bool FatalErrors = true);
6161
62 class VerifierPass : public PassBase {
62 class VerifierPass : public PassInfoMixin {
6363 bool FatalErrors;
6464
6565 public:
2020
2121 /// Pass which forces specific function attributes into the IR, primarily as
2222 /// a debugging tool.
23 struct ForceFunctionAttrsPass : PassBase {
23 struct ForceFunctionAttrsPass : PassInfoMixin {
2424 PreservedAnalyses run(Module &M);
2525 };
2626
2828 /// access memory, or only read memory, and give them the readnone/readonly
2929 /// attribute. It also discovers function arguments that are not captured by
3030 /// the function and marks them with the nocapture attribute.
31 struct PostOrderFunctionAttrsPass : PassBase {
31 struct PostOrderFunctionAttrsPass : PassInfoMixin {
3232 PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager *AM);
3333 };
3434
2222
2323 /// A pass which infers function attributes from the names and signatures of
2424 /// function declarations in a module.
25 struct InferFunctionAttrsPass : PassBase {
25 struct InferFunctionAttrsPass : PassInfoMixin {
2626 PreservedAnalyses run(Module &M, AnalysisManager *AM);
2727 };
2828
2222 namespace llvm {
2323
2424 /// Pass to remove unused function declarations.
25 struct StripDeadPrototypesPass : PassBase {
25 struct StripDeadPrototypesPass : PassInfoMixin {
2626 PreservedAnalyses run(Module &M);
2727 };
2828
2323
2424 namespace llvm {
2525
26 class InstCombinePass : public PassBase {
26 class InstCombinePass : public PassInfoMixin {
2727 InstCombineWorklist Worklist;
2828 bool ExpensiveCombines;
2929
2727 /// instructions are dead until proven otherwise. This allows it to eliminate
2828 /// dead computations that other DCE passes do not catch, particularly involving
2929 /// loop computations.
30 struct ADCEPass : PassBase {
30 struct ADCEPass : PassInfoMixin {
3131 PreservedAnalyses run(Function &F);
3232 };
3333 }
2525 /// canonicalize things as it goes. It is intended to be fast and catch obvious
2626 /// cases so that instcombine and other passes are more effective. It is
2727 /// expected that a later pass of GVN will catch the interesting/hard cases.
28 struct EarlyCSEPass : PassBase {
28 struct EarlyCSEPass : PassInfoMixin {
2929 /// \brief Run the pass over the function.
3030 PreservedAnalyses run(Function &F, AnalysisManager *AM);
3131 };
4141 ///
4242 /// FIXME: We should have a good summary of the GVN algorithm implemented by
4343 /// this particular pass here.
44 class GVN : public PassBase {
44 class GVN : public PassInfoMixin {
4545 public:
4646
4747 /// \brief Run the pass over the function.
2020
2121 namespace llvm {
2222
23 struct LowerExpectIntrinsicPass : PassBase {
23 struct LowerExpectIntrinsicPass : PassInfoMixin {
2424 /// \brief Run the pass over the function.
2525 ///
2626 /// This will lower all of th expect intrinsic calls in this function into
5050 /// onto insert and extract operations on a vector value, and convert them to
5151 /// this form. By doing so, it will enable promotion of vector aggregates to
5252 /// SSA vector values.
53 class SROA : public PassBase {
53 class SROA : public PassInfoMixin {
5454 LLVMContext *C;
5555 DominatorTree *DT;
5656 AssumptionCache *AC;
2424 /// This pass iteratively simplifies the entire CFG of a function, removing
2525 /// unnecessary control flows and bringing it into the canonical form expected
2626 /// by the rest of the mid-level optimizer.
27 class SimplifyCFGPass : public PassBase {
27 class SimplifyCFGPass : public PassInfoMixin {
2828 int BonusInstThreshold;
2929
3030 public:
6969 };
7070
7171 /// \brief No-op module analysis.
72 class NoOpModuleAnalysis : public AnalysisBase {
73 friend AnalysisBase;
72 class NoOpModuleAnalysis : public AnalysisInfoMixin {
73 friend AnalysisInfoMixin;
7474 static char PassID;
7575
7676 public:
8888 };
8989
9090 /// \brief No-op CGSCC analysis.
91 class NoOpCGSCCAnalysis : public AnalysisBase {
92 friend AnalysisBase;
91 class NoOpCGSCCAnalysis : public AnalysisInfoMixin {
92 friend AnalysisInfoMixin;
9393 static char PassID;
9494
9595 public:
105105 };
106106
107107 /// \brief No-op function analysis.
108 class NoOpFunctionAnalysis : public AnalysisBase {
109 friend AnalysisBase;
108 class NoOpFunctionAnalysis : public AnalysisInfoMixin {
109 friend AnalysisInfoMixin;
110110 static char PassID;
111111
112112 public:
122122 };
123123
124124 /// \brief No-op loop analysis.
125 class NoOpLoopAnalysis : public AnalysisBase {
126 friend AnalysisBase;
125 class NoOpLoopAnalysis : public AnalysisInfoMixin {
126 friend AnalysisInfoMixin;
127127 static char PassID;
128128
129129 public:
1818
1919 namespace {
2020
21 class TestFunctionAnalysis : public AnalysisBase {
21 class TestFunctionAnalysis : public AnalysisInfoMixin {
2222 public:
2323 struct Result {
2424 Result(int Count) : InstructionCount(Count) {}
3939 }
4040
4141 private:
42 friend AnalysisBase;
42 friend AnalysisInfoMixin;
4343 static char PassID;
4444
4545 int &Runs;
4747
4848 char TestFunctionAnalysis::PassID;
4949
50 class TestModuleAnalysis : public AnalysisBase {
50 class TestModuleAnalysis : public AnalysisInfoMixin {
5151 public:
5252 struct Result {
5353 Result(int Count) : FunctionCount(Count) {}
6565 }
6666
6767 private:
68 friend AnalysisBase;
68 friend AnalysisInfoMixin;
6969 static char PassID;
7070
7171 int &Runs;
7373
7474 char TestModuleAnalysis::PassID;
7575
76 struct TestModulePass : PassBase {
76 struct TestModulePass : PassInfoMixin {
7777 TestModulePass(int &RunCount) : RunCount(RunCount) {}
7878
7979 PreservedAnalyses run(Module &M) {
8484 int &RunCount;
8585 };
8686
87 struct TestPreservingModulePass : PassBase {
87 struct TestPreservingModulePass : PassInfoMixin {
8888 PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); }
8989 };
9090
91 struct TestMinPreservingModulePass : PassBase {
91 struct TestMinPreservingModulePass
92 : PassInfoMixin {
9293 PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) {
9394 PreservedAnalyses PA;
9495
100101 }
101102 };
102103
103 struct TestFunctionPass : PassBase {
104 struct TestFunctionPass : PassInfoMixin {
104105 TestFunctionPass(int &RunCount, int &AnalyzedInstrCount,
105106 int &AnalyzedFunctionCount,
106107 bool OnlyUseCachedResults = false)
139140
140141 // A test function pass that invalidates all function analyses for a function
141142 // with a specific name.
142 struct TestInvalidationFunctionPass : PassBase {
143 struct TestInvalidationFunctionPass
144 : PassInfoMixin {
143145 TestInvalidationFunctionPass(StringRef FunctionName) : Name(FunctionName) {}
144146
145147 PreservedAnalyses run(Function &F) {