- /// \brief Abstract concept of an analysis result.
- ///
- /// This concept is parameterized over the IR unit that this result pertains
- /// to.
- template <typename IRUnitT> struct AnalysisResultConcept {
- virtual ~AnalysisResultConcept() {}
- virtual AnalysisResultConcept *clone() = 0;
-
- /// \brief Method to try and mark a result as invalid.
- ///
- /// When the outer \c AnalysisManager detects a change in some underlying
- /// unit of the IR, it will call this method on all of the results cached.
- ///
- /// \returns true if the result should indeed be invalidated (the default).
- virtual bool invalidate(IRUnitT *IR) = 0;
- };
-
- /// \brief Wrapper to model the analysis result concept.
- ///
- /// Can wrap any type which implements a suitable invalidate member and model
- /// the AnalysisResultConcept for the AnalysisManager.
- template <typename IRUnitT, typename ResultT>
- struct AnalysisResultModel : AnalysisResultConcept<IRUnitT> {
- AnalysisResultModel(ResultT Result) : Result(llvm_move(Result)) {}
- virtual AnalysisResultModel *clone() {
- return new AnalysisResultModel(Result);
- }
-
- /// \brief The model delegates to the \c ResultT method.
- virtual bool invalidate(IRUnitT *IR) { return Result.invalidate(IR); }
-
- ResultT Result;
- };
-
- /// \brief Abstract concept of an analysis pass.
- ///
- /// This concept is parameterized over the IR unit that it can run over and
- /// produce an analysis result.
- template <typename IRUnitT> struct AnalysisPassConcept {
- virtual ~AnalysisPassConcept() {}
- virtual AnalysisPassConcept *clone() = 0;
-
- /// \brief Method to run this analysis over a unit of IR.
- /// \returns The analysis result object to be queried by users, the caller
- /// takes ownership.
- virtual AnalysisResultConcept<IRUnitT> *run(IRUnitT *IR) = 0;
- };
-
- /// \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 PassT>
- struct AnalysisPassModel : AnalysisPassConcept<typename PassT::IRUnitT> {
- AnalysisPassModel(PassT Pass) : Pass(llvm_move(Pass)) {}
- virtual AnalysisPassModel *clone() { return new AnalysisPassModel(Pass); }
-
- // FIXME: Replace PassT::IRUnitT with type traits when we use C++11.
- typedef typename PassT::IRUnitT IRUnitT;
-
- // FIXME: Replace PassT::Result with type traits when we use C++11.
- typedef AnalysisResultModel<IRUnitT, typename PassT::Result> ResultModelT;
-
- /// \brief The model delegates to the \c PassT::run method.
- ///
- /// The return is wrapped in an \c AnalysisResultModel.
- virtual ResultModelT *run(IRUnitT *IR) {
- return new ResultModelT(Pass.run(IR));
- }
-
- PassT Pass;
- };
-
-