llvm.org GIT mirror llvm / 0ef3c5a
[PM] Remove the 'AnalysisManagerT' type parameter from numerous layers of templates in the new pass manager. The analysis manager is now itself just a template predicated on the IR unit. This makes lots of the templates really trivial and more clear: they are all parameterized on a single type, the IR unit's type. Everything else is a function of that. To me, this is a really nice cleanup of the APIs and removes a layer of 'magic' and 'indirection' that really wasn't there and just got in the way of understanding what is going on here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225784 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 5 years ago
2 changed file(s) with 37 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
242242
243243 private:
244244 // Pull in the concept type and model template specialized for modules.
245 typedef detail::PassConcept, AnalysisManager> PassConcept;
245 typedef detail::PassConcept> PassConcept;
246246 template
247 struct PassModel
248 : detail::PassModel, PassT> {
247 struct PassModel : detail::PassModel, PassT> {
249248 PassModel(PassT Pass)
250 : detail::PassModel, PassT>(
251 std::move(Pass)) {}
249 : detail::PassModel(std::move(Pass)) {}
252250 };
253251
254252 PassManager(const PassManager &) LLVM_DELETED_FUNCTION;
294292
295293 protected:
296294 typedef detail::AnalysisResultConcept ResultConceptT;
297 typedef detail::AnalysisPassConcept, DerivedT> PassConceptT;
295 typedef detail::AnalysisPassConcept> PassConceptT;
298296
299297 // FIXME: Provide template aliases for the models when we're using C++11 in
300298 // a mode supporting them.
353351 template void registerPass(PassT Pass) {
354352 assert(!AnalysisPasses.count(PassT::ID()) &&
355353 "Registered the same analysis pass twice!");
356 typedef detail::AnalysisPassModelDerivedT, PassT> PassModelT;
354 typedef detail::AnalysisPassModelPassT> PassModelT;
357355 AnalysisPasses[PassT::ID()].reset(new PassModelT(std::move(Pass)));
358356 }
359357
822820 /// provided they satisfy the basic API requirements. When this pass is
823821 /// created, these methods can be instantiated to satisfy whatever the
824822 /// context requires.
825 template
826 PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT *AM) {
823 template
824 PreservedAnalyses run(IRUnitT &Arg, AnalysisManager *AM) {
827825 if (AM)
828826 (void)AM->template getResult(Arg);
829827
845843 /// provided they satisfy the basic API requirements. When this pass is
846844 /// created, these methods can be instantiated to satisfy whatever the
847845 /// context requires.
848 template
849 PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT *AM) {
846 template
847 PreservedAnalyses run(IRUnitT &Arg, AnalysisManager *AM) {
850848 if (AM)
851849 // We have to directly invalidate the analysis result as we can't
852850 // enumerate all other analyses and use the preserved set to control it.
2121
2222 namespace llvm {
2323
24 class Function;
25 class Module;
24 template class AnalysisManager;
2625 class PreservedAnalyses;
2726
2827 /// \brief Implementation details of the pass manager interfaces.
3029
3130 /// \brief Template for the abstract base class used to dispatch
3231 /// polymorphically over pass objects.
33 template , typename AnalysisManagerT> struct PassConcept {
32 template > struct PassConcept {
3433 // Boiler plate necessary for the container of derived classes.
3534 virtual ~PassConcept() {}
3635
3938 /// Note that actual pass object can omit the analysis manager argument if
4039 /// desired. Also that the analysis manager may be null if there is no
4140 /// analysis manager in the pass pipeline.
42 virtual PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT *AM) = 0;
41 virtual PreservedAnalyses run(IRUnitT &IR, AnalysisManager *AM) = 0;
4342
4443 /// \brief Polymorphic method to access the name of a pass.
4544 virtual StringRef name() = 0;
4645 };
4746
4847 /// \brief SFINAE metafunction for computing whether \c PassT has a run method
49 /// accepting an \c AnalysisManagerT.
50 template
51 typename ResultT>
48 /// accepting an \c AnalysisManager.
49 template
5250 class PassRunAcceptsAnalysisManager {
5351 typedef char SmallType;
5452 struct BigType {
5553 char a, b;
5654 };
5755
58 template T *)>
56 template *)>
5957 struct Checker;
6058
6159 template static SmallType f(Checker *);
6967 ///
7068 /// Can be instantiated for any object which provides a \c run method accepting
7169 /// an \c IRUnitT. It requires the pass to be a copyable object. When the
72 /// \c run method also accepts an \c AnalysisManagerT*, we pass it along.
73 template
70 /// \c run method also accepts an \c AnalysisManager*, we pass it
71 /// along.
72 template
7473 typename PreservedAnalysesT = PreservedAnalyses,
7574 bool AcceptsAnalysisManager = PassRunAcceptsAnalysisManager<
76 IRUnitT, AnalysisManagerT, PassT, PreservedAnalysesT>::Value>
75 IRUnitT, PassT, PreservedAnalysesT>::Value>
7776 struct PassModel;
7877
7978 /// \brief Specialization of \c PassModel for passes that accept an analyis
8079 /// manager.
81 template
82 typename PreservedAnalysesT>
83 struct PassModel
84 : PassConcept {
80 template
81 struct PassModel
82 : PassConcept {
8583 explicit PassModel(PassT Pass) : Pass(std::move(Pass)) {}
8684 // We have to explicitly define all the special member functions because MSVC
8785 // refuses to generate them.
9694 return *this;
9795 }
9896
99 PreservedAnalysesT run(IRUnitT &IR, AnalysisManagerT *AM) override {
97 PreservedAnalysesT run(IRUnitT &IR, AnalysisManager *AM) override {
10098 return Pass.run(IR, AM);
10199 }
102100 StringRef name() override { return PassT::name(); }
105103
106104 /// \brief Specialization of \c PassModel for passes that accept an analyis
107105 /// manager.
108 template
109 typename PreservedAnalysesT>
110 struct PassModel
111 : PassConcept {
106 template
107 struct PassModel
108 : PassConcept {
112109 explicit PassModel(PassT Pass) : Pass(std::move(Pass)) {}
113110 // We have to explicitly define all the special member functions because MSVC
114111 // refuses to generate them.
123120 return *this;
124121 }
125122
126 PreservedAnalysesT run(IRUnitT &IR, AnalysisManagerT *AM) override {
123 PreservedAnalysesT run(IRUnitT &IR, AnalysisManager *AM) override {
127124 return Pass.run(IR);
128125 }
129126 StringRef name() override { return PassT::name(); }
246243 ///
247244 /// This concept is parameterized over the IR unit that it can run over and
248245 /// produce an analysis result.
249 template
250 struct AnalysisPassConcept {
246 template struct AnalysisPassConcept {
251247 virtual ~AnalysisPassConcept() {}
252248
253249 /// \brief Method to run this analysis over a unit of IR.
254250 /// \returns A unique_ptr to the analysis result object to be queried by
255251 /// users.
256252 virtual std::unique_ptr>
257 run(IRUnitT &IR, AnalysisManagerT *AM) = 0;
253 run(IRUnitT &IR, AnalysisManager *AM) = 0;
258254
259255 /// \brief Polymorphic method to access the name of a pass.
260256 virtual StringRef name() = 0;
265261 /// Can wrap any type which implements a suitable \c run method. The method
266262 /// must accept the IRUnitT as an argument and produce an object which can be
267263 /// wrapped in a \c AnalysisResultModel.
268 template AnalysisManagerT, typename PassT,
264 template PassT,
269265 bool AcceptsAnalysisManager = PassRunAcceptsAnalysisManager<
270 IRUnitT, AnalysisManagerT, PassT, typename PassT::Result>::Value>
266 IRUnitT, PassT, typename PassT::Result>::Value>
271267 struct AnalysisPassModel;
272268
273269 /// \brief Specialization of \c AnalysisPassModel which passes an
274270 /// \c AnalysisManager to PassT's run method.
275 template
276 struct AnalysisPassModel
277 : AnalysisPassConcept {
271 template
272 struct AnalysisPassModel : AnalysisPassConcept {
278273 explicit AnalysisPassModel(PassT Pass) : Pass(std::move(Pass)) {}
279274 // We have to explicitly define all the special member functions because MSVC
280275 // refuses to generate them.
297292 ///
298293 /// The return is wrapped in an \c AnalysisResultModel.
299294 std::unique_ptr>
300 run(IRUnitT &IR, AnalysisManagerT *AM) override {
295 run(IRUnitT &IR, AnalysisManager *AM) override {
301296 return make_unique(Pass.run(IR, AM));
302297 }
303298
311306
312307 /// \brief Specialization of \c AnalysisPassModel which does not pass an
313308 /// \c AnalysisManager to PassT's run method.
314 template
315 struct AnalysisPassModel
316 : AnalysisPassConcept {
309 template
310 struct AnalysisPassModel : AnalysisPassConcept {
317311 explicit AnalysisPassModel(PassT Pass) : Pass(std::move(Pass)) {}
318312 // We have to explicitly define all the special member functions because MSVC
319313 // refuses to generate them.
336330 ///
337331 /// The return is wrapped in an \c AnalysisResultModel.
338332 std::unique_ptr>
339 run(IRUnitT &IR, AnalysisManagerT *) override {
333 run(IRUnitT &IR, AnalysisManager *) override {
340334 return make_unique(Pass.run(IR));
341335 }
342336