[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
This commit is contained in:
Chandler Carruth 2015-01-13 11:31:43 +00:00
parent 92602ea18e
commit 0ef3c5a377
2 changed files with 37 additions and 45 deletions

View File

@ -243,13 +243,11 @@ public:
private: private:
// Pull in the concept type and model template specialized for modules. // Pull in the concept type and model template specialized for modules.
typedef detail::PassConcept<IRUnitT, AnalysisManager<IRUnitT>> PassConcept; typedef detail::PassConcept<IRUnitT> PassConcept;
template <typename PassT> template <typename PassT>
struct PassModel struct PassModel : detail::PassModel<IRUnitT, PassT> {
: detail::PassModel<IRUnitT, AnalysisManager<IRUnitT>, PassT> {
PassModel(PassT Pass) PassModel(PassT Pass)
: detail::PassModel<IRUnitT, AnalysisManager<IRUnitT>, PassT>( : detail::PassModel<IRUnitT, PassT>(std::move(Pass)) {}
std::move(Pass)) {}
}; };
PassManager(const PassManager &) LLVM_DELETED_FUNCTION; PassManager(const PassManager &) LLVM_DELETED_FUNCTION;
@ -295,7 +293,7 @@ template <typename DerivedT, typename IRUnitT> class AnalysisManagerBase {
protected: protected:
typedef detail::AnalysisResultConcept<IRUnitT> ResultConceptT; typedef detail::AnalysisResultConcept<IRUnitT> ResultConceptT;
typedef detail::AnalysisPassConcept<IRUnitT, DerivedT> PassConceptT; typedef detail::AnalysisPassConcept<IRUnitT> PassConceptT;
// FIXME: Provide template aliases for the models when we're using C++11 in // FIXME: Provide template aliases for the models when we're using C++11 in
// a mode supporting them. // a mode supporting them.
@ -354,7 +352,7 @@ public:
template <typename PassT> void registerPass(PassT Pass) { template <typename PassT> void registerPass(PassT Pass) {
assert(!AnalysisPasses.count(PassT::ID()) && assert(!AnalysisPasses.count(PassT::ID()) &&
"Registered the same analysis pass twice!"); "Registered the same analysis pass twice!");
typedef detail::AnalysisPassModel<IRUnitT, DerivedT, PassT> PassModelT; typedef detail::AnalysisPassModel<IRUnitT, PassT> PassModelT;
AnalysisPasses[PassT::ID()].reset(new PassModelT(std::move(Pass))); AnalysisPasses[PassT::ID()].reset(new PassModelT(std::move(Pass)));
} }
@ -823,8 +821,8 @@ template <typename AnalysisT> struct RequireAnalysisPass {
/// provided they satisfy the basic API requirements. When this pass is /// provided they satisfy the basic API requirements. When this pass is
/// created, these methods can be instantiated to satisfy whatever the /// created, these methods can be instantiated to satisfy whatever the
/// context requires. /// context requires.
template <typename IRUnitT, typename AnalysisManagerT> template <typename IRUnitT>
PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT *AM) { PreservedAnalyses run(IRUnitT &Arg, AnalysisManager<IRUnitT> *AM) {
if (AM) if (AM)
(void)AM->template getResult<AnalysisT>(Arg); (void)AM->template getResult<AnalysisT>(Arg);
@ -846,8 +844,8 @@ template <typename AnalysisT> struct InvalidateAnalysisPass {
/// provided they satisfy the basic API requirements. When this pass is /// provided they satisfy the basic API requirements. When this pass is
/// created, these methods can be instantiated to satisfy whatever the /// created, these methods can be instantiated to satisfy whatever the
/// context requires. /// context requires.
template <typename IRUnitT, typename AnalysisManagerT> template <typename IRUnitT>
PreservedAnalyses run(IRUnitT &Arg, AnalysisManagerT *AM) { PreservedAnalyses run(IRUnitT &Arg, AnalysisManager<IRUnitT> *AM) {
if (AM) if (AM)
// We have to directly invalidate the analysis result as we can't // We have to directly invalidate the analysis result as we can't
// enumerate all other analyses and use the preserved set to control it. // enumerate all other analyses and use the preserved set to control it.

View File

@ -22,8 +22,7 @@
namespace llvm { namespace llvm {
class Function; template <typename IRUnitT> class AnalysisManager;
class Module;
class PreservedAnalyses; class PreservedAnalyses;
/// \brief Implementation details of the pass manager interfaces. /// \brief Implementation details of the pass manager interfaces.
@ -31,7 +30,7 @@ namespace detail {
/// \brief Template for the abstract base class used to dispatch /// \brief Template for the abstract base class used to dispatch
/// polymorphically over pass objects. /// polymorphically over pass objects.
template <typename IRUnitT, typename AnalysisManagerT> struct PassConcept { template <typename IRUnitT> struct PassConcept {
// Boiler plate necessary for the container of derived classes. // Boiler plate necessary for the container of derived classes.
virtual ~PassConcept() {} virtual ~PassConcept() {}
@ -40,23 +39,22 @@ template <typename IRUnitT, typename AnalysisManagerT> struct PassConcept {
/// Note that actual pass object can omit the analysis manager argument if /// 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 /// desired. Also that the analysis manager may be null if there is no
/// analysis manager in the pass pipeline. /// analysis manager in the pass pipeline.
virtual PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT *AM) = 0; virtual PreservedAnalyses run(IRUnitT &IR, AnalysisManager<IRUnitT> *AM) = 0;
/// \brief Polymorphic method to access the name of a pass. /// \brief Polymorphic method to access the name of a pass.
virtual StringRef name() = 0; virtual StringRef name() = 0;
}; };
/// \brief SFINAE metafunction for computing whether \c PassT has a run method /// \brief SFINAE metafunction for computing whether \c PassT has a run method
/// accepting an \c AnalysisManagerT. /// accepting an \c AnalysisManager<IRUnitT>.
template <typename IRUnitT, typename AnalysisManagerT, typename PassT, template <typename IRUnitT, typename PassT, typename ResultT>
typename ResultT>
class PassRunAcceptsAnalysisManager { class PassRunAcceptsAnalysisManager {
typedef char SmallType; typedef char SmallType;
struct BigType { struct BigType {
char a, b; char a, b;
}; };
template <typename T, ResultT (T::*)(IRUnitT &, AnalysisManagerT *)> template <typename T, ResultT (T::*)(IRUnitT &, AnalysisManager<IRUnitT> *)>
struct Checker; struct Checker;
template <typename T> static SmallType f(Checker<T, &T::run> *); template <typename T> static SmallType f(Checker<T, &T::run> *);
@ -70,19 +68,19 @@ public:
/// ///
/// Can be instantiated for any object which provides a \c run method accepting /// 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 /// an \c IRUnitT. It requires the pass to be a copyable object. When the
/// \c run method also accepts an \c AnalysisManagerT*, we pass it along. /// \c run method also accepts an \c AnalysisManager<IRUnitT>*, we pass it
template <typename IRUnitT, typename AnalysisManagerT, typename PassT, /// along.
template <typename IRUnitT, typename PassT,
typename PreservedAnalysesT = PreservedAnalyses, typename PreservedAnalysesT = PreservedAnalyses,
bool AcceptsAnalysisManager = PassRunAcceptsAnalysisManager< bool AcceptsAnalysisManager = PassRunAcceptsAnalysisManager<
IRUnitT, AnalysisManagerT, PassT, PreservedAnalysesT>::Value> IRUnitT, PassT, PreservedAnalysesT>::Value>
struct PassModel; struct PassModel;
/// \brief Specialization of \c PassModel for passes that accept an analyis /// \brief Specialization of \c PassModel for passes that accept an analyis
/// manager. /// manager.
template <typename IRUnitT, typename AnalysisManagerT, typename PassT, template <typename IRUnitT, typename PassT, typename PreservedAnalysesT>
typename PreservedAnalysesT> struct PassModel<IRUnitT, PassT, PreservedAnalysesT, true>
struct PassModel<IRUnitT, AnalysisManagerT, PassT, PreservedAnalysesT, true> : PassConcept<IRUnitT> {
: PassConcept<IRUnitT, AnalysisManagerT> {
explicit PassModel(PassT Pass) : Pass(std::move(Pass)) {} explicit PassModel(PassT Pass) : Pass(std::move(Pass)) {}
// We have to explicitly define all the special member functions because MSVC // We have to explicitly define all the special member functions because MSVC
// refuses to generate them. // refuses to generate them.
@ -97,7 +95,7 @@ struct PassModel<IRUnitT, AnalysisManagerT, PassT, PreservedAnalysesT, true>
return *this; return *this;
} }
PreservedAnalysesT run(IRUnitT &IR, AnalysisManagerT *AM) override { PreservedAnalysesT run(IRUnitT &IR, AnalysisManager<IRUnitT> *AM) override {
return Pass.run(IR, AM); return Pass.run(IR, AM);
} }
StringRef name() override { return PassT::name(); } StringRef name() override { return PassT::name(); }
@ -106,10 +104,9 @@ struct PassModel<IRUnitT, AnalysisManagerT, PassT, PreservedAnalysesT, true>
/// \brief Specialization of \c PassModel for passes that accept an analyis /// \brief Specialization of \c PassModel for passes that accept an analyis
/// manager. /// manager.
template <typename IRUnitT, typename AnalysisManagerT, typename PassT, template <typename IRUnitT, typename PassT, typename PreservedAnalysesT>
typename PreservedAnalysesT> struct PassModel<IRUnitT, PassT, PreservedAnalysesT, false>
struct PassModel<IRUnitT, AnalysisManagerT, PassT, PreservedAnalysesT, false> : PassConcept<IRUnitT> {
: PassConcept<IRUnitT, AnalysisManagerT> {
explicit PassModel(PassT Pass) : Pass(std::move(Pass)) {} explicit PassModel(PassT Pass) : Pass(std::move(Pass)) {}
// We have to explicitly define all the special member functions because MSVC // We have to explicitly define all the special member functions because MSVC
// refuses to generate them. // refuses to generate them.
@ -124,7 +121,7 @@ struct PassModel<IRUnitT, AnalysisManagerT, PassT, PreservedAnalysesT, false>
return *this; return *this;
} }
PreservedAnalysesT run(IRUnitT &IR, AnalysisManagerT *AM) override { PreservedAnalysesT run(IRUnitT &IR, AnalysisManager<IRUnitT> *AM) override {
return Pass.run(IR); return Pass.run(IR);
} }
StringRef name() override { return PassT::name(); } StringRef name() override { return PassT::name(); }
@ -247,15 +244,14 @@ struct AnalysisResultModel<IRUnitT, PassT, ResultT, PreservedAnalysesT, true>
/// ///
/// This concept is parameterized over the IR unit that it can run over and /// This concept is parameterized over the IR unit that it can run over and
/// produce an analysis result. /// produce an analysis result.
template <typename IRUnitT, typename AnalysisManagerT> template <typename IRUnitT> struct AnalysisPassConcept {
struct AnalysisPassConcept {
virtual ~AnalysisPassConcept() {} virtual ~AnalysisPassConcept() {}
/// \brief Method to run this analysis over a unit of IR. /// \brief Method to run this analysis over a unit of IR.
/// \returns A unique_ptr to the analysis result object to be queried by /// \returns A unique_ptr to the analysis result object to be queried by
/// users. /// users.
virtual std::unique_ptr<AnalysisResultConcept<IRUnitT>> virtual std::unique_ptr<AnalysisResultConcept<IRUnitT>>
run(IRUnitT &IR, AnalysisManagerT *AM) = 0; run(IRUnitT &IR, AnalysisManager<IRUnitT> *AM) = 0;
/// \brief Polymorphic method to access the name of a pass. /// \brief Polymorphic method to access the name of a pass.
virtual StringRef name() = 0; virtual StringRef name() = 0;
@ -266,16 +262,15 @@ struct AnalysisPassConcept {
/// Can wrap any type which implements a suitable \c run method. The method /// 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 /// must accept the IRUnitT as an argument and produce an object which can be
/// wrapped in a \c AnalysisResultModel. /// wrapped in a \c AnalysisResultModel.
template <typename IRUnitT, typename AnalysisManagerT, typename PassT, template <typename IRUnitT, typename PassT,
bool AcceptsAnalysisManager = PassRunAcceptsAnalysisManager< bool AcceptsAnalysisManager = PassRunAcceptsAnalysisManager<
IRUnitT, AnalysisManagerT, PassT, typename PassT::Result>::Value> IRUnitT, PassT, typename PassT::Result>::Value>
struct AnalysisPassModel; struct AnalysisPassModel;
/// \brief Specialization of \c AnalysisPassModel which passes an /// \brief Specialization of \c AnalysisPassModel which passes an
/// \c AnalysisManager to PassT's run method. /// \c AnalysisManager to PassT's run method.
template <typename IRUnitT, typename AnalysisManagerT, typename PassT> template <typename IRUnitT, typename PassT>
struct AnalysisPassModel<IRUnitT, AnalysisManagerT, PassT, true> struct AnalysisPassModel<IRUnitT, PassT, true> : AnalysisPassConcept<IRUnitT> {
: AnalysisPassConcept<IRUnitT, AnalysisManagerT> {
explicit AnalysisPassModel(PassT Pass) : Pass(std::move(Pass)) {} explicit AnalysisPassModel(PassT Pass) : Pass(std::move(Pass)) {}
// We have to explicitly define all the special member functions because MSVC // We have to explicitly define all the special member functions because MSVC
// refuses to generate them. // refuses to generate them.
@ -298,7 +293,7 @@ struct AnalysisPassModel<IRUnitT, AnalysisManagerT, PassT, true>
/// ///
/// The return is wrapped in an \c AnalysisResultModel. /// The return is wrapped in an \c AnalysisResultModel.
std::unique_ptr<AnalysisResultConcept<IRUnitT>> std::unique_ptr<AnalysisResultConcept<IRUnitT>>
run(IRUnitT &IR, AnalysisManagerT *AM) override { run(IRUnitT &IR, AnalysisManager<IRUnitT> *AM) override {
return make_unique<ResultModelT>(Pass.run(IR, AM)); return make_unique<ResultModelT>(Pass.run(IR, AM));
} }
@ -312,9 +307,8 @@ struct AnalysisPassModel<IRUnitT, AnalysisManagerT, PassT, true>
/// \brief Specialization of \c AnalysisPassModel which does not pass an /// \brief Specialization of \c AnalysisPassModel which does not pass an
/// \c AnalysisManager to PassT's run method. /// \c AnalysisManager to PassT's run method.
template <typename IRUnitT, typename AnalysisManagerT, typename PassT> template <typename IRUnitT, typename PassT>
struct AnalysisPassModel<IRUnitT, AnalysisManagerT, PassT, false> struct AnalysisPassModel<IRUnitT, PassT, false> : AnalysisPassConcept<IRUnitT> {
: AnalysisPassConcept<IRUnitT, AnalysisManagerT> {
explicit AnalysisPassModel(PassT Pass) : Pass(std::move(Pass)) {} explicit AnalysisPassModel(PassT Pass) : Pass(std::move(Pass)) {}
// We have to explicitly define all the special member functions because MSVC // We have to explicitly define all the special member functions because MSVC
// refuses to generate them. // refuses to generate them.
@ -337,7 +331,7 @@ struct AnalysisPassModel<IRUnitT, AnalysisManagerT, PassT, false>
/// ///
/// The return is wrapped in an \c AnalysisResultModel. /// The return is wrapped in an \c AnalysisResultModel.
std::unique_ptr<AnalysisResultConcept<IRUnitT>> std::unique_ptr<AnalysisResultConcept<IRUnitT>>
run(IRUnitT &IR, AnalysisManagerT *) override { run(IRUnitT &IR, AnalysisManager<IRUnitT> *) override {
return make_unique<ResultModelT>(Pass.run(IR)); return make_unique<ResultModelT>(Pass.run(IR));
} }