diff options
Diffstat (limited to 'include/llvm/IR/PassManagerInternal.h')
-rw-r--r-- | include/llvm/IR/PassManagerInternal.h | 123 |
1 files changed, 12 insertions, 111 deletions
diff --git a/include/llvm/IR/PassManagerInternal.h b/include/llvm/IR/PassManagerInternal.h index 92de10bcd75b2..4351b5888283d 100644 --- a/include/llvm/IR/PassManagerInternal.h +++ b/include/llvm/IR/PassManagerInternal.h @@ -18,8 +18,8 @@ #ifndef LLVM_IR_PASSMANAGERINTERNAL_H #define LLVM_IR_PASSMANAGERINTERNAL_H -#include "llvm/ADT/StringRef.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" namespace llvm { @@ -40,48 +40,20 @@ template <typename IRUnitT> struct PassConcept { /// Note that actual pass object can omit the analysis manager argument if /// desired. Also that the analysis manager may be null if there is no /// analysis manager in the pass pipeline. - virtual PreservedAnalyses run(IRUnitT &IR, AnalysisManager<IRUnitT> *AM) = 0; + virtual PreservedAnalyses run(IRUnitT &IR, AnalysisManager<IRUnitT> &AM) = 0; /// \brief Polymorphic method to access the name of a pass. virtual StringRef name() = 0; }; -/// \brief SFINAE metafunction for computing whether \c PassT has a run method -/// accepting an \c AnalysisManager<IRUnitT>. -template <typename IRUnitT, typename PassT, typename ResultT> -class PassRunAcceptsAnalysisManager { - typedef char SmallType; - struct BigType { - char a, b; - }; - - template <typename T, ResultT (T::*)(IRUnitT &, AnalysisManager<IRUnitT> *)> - struct Checker; - - template <typename T> static SmallType f(Checker<T, &T::run> *); - template <typename T> static BigType f(...); - -public: - enum { Value = sizeof(f<PassT>(nullptr)) == sizeof(SmallType) }; -}; - /// \brief A template wrapper used to implement the polymorphic API. /// /// Can be instantiated for any object which provides a \c run method accepting -/// an \c IRUnitT. It requires the pass to be a copyable object. When the -/// \c run method also accepts an \c AnalysisManager<IRUnitT>*, we pass it -/// along. +/// an \c IRUnitT& and an \c AnalysisManager<IRUnit>&. It requires the pass to +/// be a copyable object. When the template <typename IRUnitT, typename PassT, - typename PreservedAnalysesT = PreservedAnalyses, - bool AcceptsAnalysisManager = PassRunAcceptsAnalysisManager< - IRUnitT, PassT, PreservedAnalysesT>::Value> -struct PassModel; - -/// \brief Specialization of \c PassModel for passes that accept an analyis -/// manager. -template <typename IRUnitT, typename PassT, typename PreservedAnalysesT> -struct PassModel<IRUnitT, PassT, PreservedAnalysesT, true> - : PassConcept<IRUnitT> { + typename PreservedAnalysesT = PreservedAnalyses> +struct PassModel : PassConcept<IRUnitT> { explicit PassModel(PassT Pass) : Pass(std::move(Pass)) {} // We have to explicitly define all the special member functions because MSVC // refuses to generate them. @@ -96,39 +68,13 @@ struct PassModel<IRUnitT, PassT, PreservedAnalysesT, true> return *this; } - PreservedAnalysesT run(IRUnitT &IR, AnalysisManager<IRUnitT> *AM) override { + PreservedAnalysesT run(IRUnitT &IR, AnalysisManager<IRUnitT> &AM) override { return Pass.run(IR, AM); } StringRef name() override { return PassT::name(); } PassT Pass; }; -/// \brief Specialization of \c PassModel for passes that accept an analyis -/// manager. -template <typename IRUnitT, typename PassT, typename PreservedAnalysesT> -struct PassModel<IRUnitT, PassT, PreservedAnalysesT, false> - : PassConcept<IRUnitT> { - explicit PassModel(PassT Pass) : Pass(std::move(Pass)) {} - // We have to explicitly define all the special member functions because MSVC - // refuses to generate them. - PassModel(const PassModel &Arg) : Pass(Arg.Pass) {} - PassModel(PassModel &&Arg) : Pass(std::move(Arg.Pass)) {} - friend void swap(PassModel &LHS, PassModel &RHS) { - using std::swap; - swap(LHS.Pass, RHS.Pass); - } - PassModel &operator=(PassModel RHS) { - swap(*this, RHS); - return *this; - } - - PreservedAnalysesT run(IRUnitT &IR, AnalysisManager<IRUnitT> *AM) override { - return Pass.run(IR); - } - StringRef name() override { return PassT::name(); } - PassT Pass; -}; - /// \brief Abstract concept of an analysis result. /// /// This concept is parameterized over the IR unit that this result pertains @@ -252,7 +198,7 @@ template <typename IRUnitT> struct AnalysisPassConcept { /// \returns A unique_ptr to the analysis result object to be queried by /// users. virtual std::unique_ptr<AnalysisResultConcept<IRUnitT>> - run(IRUnitT &IR, AnalysisManager<IRUnitT> *AM) = 0; + run(IRUnitT &IR, AnalysisManager<IRUnitT> &AM) = 0; /// \brief Polymorphic method to access the name of a pass. virtual StringRef name() = 0; @@ -261,17 +207,10 @@ template <typename IRUnitT> struct AnalysisPassConcept { /// \brief Wrapper to model the analysis pass concept. /// /// Can wrap any type which implements a suitable \c run method. The method -/// must accept the IRUnitT as an argument and produce an object which can be -/// wrapped in a \c AnalysisResultModel. -template <typename IRUnitT, typename PassT, - bool AcceptsAnalysisManager = PassRunAcceptsAnalysisManager< - IRUnitT, PassT, typename PassT::Result>::Value> -struct AnalysisPassModel; - -/// \brief Specialization of \c AnalysisPassModel which passes an -/// \c AnalysisManager to PassT's run method. +/// must accept an \c IRUnitT& and an \c AnalysisManager<IRUnitT>& as arguments +/// and produce an object which can be wrapped in a \c AnalysisResultModel. template <typename IRUnitT, typename PassT> -struct AnalysisPassModel<IRUnitT, PassT, true> : AnalysisPassConcept<IRUnitT> { +struct AnalysisPassModel : AnalysisPassConcept<IRUnitT> { explicit AnalysisPassModel(PassT Pass) : Pass(std::move(Pass)) {} // We have to explicitly define all the special member functions because MSVC // refuses to generate them. @@ -294,7 +233,7 @@ struct AnalysisPassModel<IRUnitT, PassT, true> : AnalysisPassConcept<IRUnitT> { /// /// The return is wrapped in an \c AnalysisResultModel. std::unique_ptr<AnalysisResultConcept<IRUnitT>> - run(IRUnitT &IR, AnalysisManager<IRUnitT> *AM) override { + run(IRUnitT &IR, AnalysisManager<IRUnitT> &AM) override { return make_unique<ResultModelT>(Pass.run(IR, AM)); } @@ -306,44 +245,6 @@ struct AnalysisPassModel<IRUnitT, PassT, true> : AnalysisPassConcept<IRUnitT> { PassT Pass; }; -/// \brief Specialization of \c AnalysisPassModel which does not pass an -/// \c AnalysisManager to PassT's run method. -template <typename IRUnitT, typename PassT> -struct AnalysisPassModel<IRUnitT, PassT, false> : AnalysisPassConcept<IRUnitT> { - explicit AnalysisPassModel(PassT Pass) : Pass(std::move(Pass)) {} - // We have to explicitly define all the special member functions because MSVC - // refuses to generate them. - AnalysisPassModel(const AnalysisPassModel &Arg) : Pass(Arg.Pass) {} - AnalysisPassModel(AnalysisPassModel &&Arg) : Pass(std::move(Arg.Pass)) {} - friend void swap(AnalysisPassModel &LHS, AnalysisPassModel &RHS) { - using std::swap; - swap(LHS.Pass, RHS.Pass); - } - AnalysisPassModel &operator=(AnalysisPassModel RHS) { - swap(*this, RHS); - return *this; - } - - // FIXME: Replace PassT::Result with type traits when we use C++11. - typedef AnalysisResultModel<IRUnitT, PassT, typename PassT::Result> - ResultModelT; - - /// \brief The model delegates to the \c PassT::run method. - /// - /// The return is wrapped in an \c AnalysisResultModel. - std::unique_ptr<AnalysisResultConcept<IRUnitT>> - run(IRUnitT &IR, AnalysisManager<IRUnitT> *) override { - return make_unique<ResultModelT>(Pass.run(IR)); - } - - /// \brief The model delegates to a static \c PassT::name method. - /// - /// The returned string ref must point to constant immutable data! - StringRef name() override { return PassT::name(); } - - PassT Pass; -}; - } // End namespace detail } |