[PM] Port ScalarEvolution to the new pass manager.
[oota-llvm.git] / include / llvm / Analysis / ScalarEvolution.h
index 57f23f07769e5901077a1f6f2f75a7a69f3c9290..537198e7107d9f4c0db9d17357c2098e0e931675 100644 (file)
@@ -27,6 +27,7 @@
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/PassManager.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Allocator.h"
@@ -170,11 +171,10 @@ namespace llvm {
     static bool classof(const SCEV *S);
   };
 
-  /// ScalarEvolution - This class is the main scalar evolution driver.  Because
-  /// client code (intentionally) can't do much with the SCEV objects directly,
-  /// they must ask this class for services.
-  ///
-  class ScalarEvolution : public FunctionPass {
+  /// The main scalar evolution driver. Because client code (intentionally)
+  /// can't do much with the SCEV objects directly, they must ask this class
+  /// for services.
+  class ScalarEvolution {
   public:
     /// LoopDisposition - An enum describing the relationship between a
     /// SCEV and a loop.
@@ -224,26 +224,26 @@ namespace llvm {
 
     /// F - The function we are analyzing.
     ///
-    Function *F;
-
-    /// The tracker for @llvm.assume intrinsics in this function.
-    AssumptionCache *AC;
-
-    /// LI - The loop information for the function we are currently analyzing.
-    ///
-    LoopInfo *LI;
+    Function &F;
 
     /// TLI - The target library information for the target we are targeting.
     ///
-    TargetLibraryInfo *TLI;
+    TargetLibraryInfo &TLI;
+
+    /// The tracker for @llvm.assume intrinsics in this function.
+    AssumptionCache ∾
 
     /// DT - The dominator tree.
     ///
-    DominatorTree *DT;
+    DominatorTree &DT;
+
+    /// LI - The loop information for the function we are currently analyzing.
+    ///
+    LoopInfo &LI;
 
     /// CouldNotCompute - This SCEV is used to represent unknown trip
     /// counts and things.
-    SCEVCouldNotCompute CouldNotCompute;
+    std::unique_ptr<SCEVCouldNotCompute> CouldNotCompute;
 
     /// ValueExprMapType - The typedef for ValueExprMap.
     ///
@@ -604,10 +604,12 @@ namespace llvm {
     SCEV::NoWrapFlags getNoWrapFlagsFromUB(const Value *V);
 
   public:
-    static char ID; // Pass identification, replacement for typeid
-    ScalarEvolution();
+    ScalarEvolution(Function &F, TargetLibraryInfo &TLI, AssumptionCache &AC,
+                    DominatorTree &DT, LoopInfo &LI);
+    ~ScalarEvolution();
+    ScalarEvolution(ScalarEvolution &&Arg);
 
-    LLVMContext &getContext() const { return F->getContext(); }
+    LLVMContext &getContext() const { return F.getContext(); }
 
     /// isSCEVable - Test if values of the given type are analyzable within
     /// the SCEV framework. This primarily includes integer types, and it
@@ -984,11 +986,8 @@ namespace llvm {
                              SmallVectorImpl<const SCEV *> &Sizes,
                              const SCEV *ElementSize) const;
 
-    bool runOnFunction(Function &F) override;
-    void releaseMemory() override;
-    void getAnalysisUsage(AnalysisUsage &AU) const override;
-    void print(raw_ostream &OS, const Module* = nullptr) const override;
-    void verifyAnalysis() const override;
+    void print(raw_ostream &OS) const;
+    void verify() const;
 
     /// Collect parametric terms occurring in step expressions.
     void collectParametricTerms(const SCEV *Expr,
@@ -1097,6 +1096,51 @@ namespace llvm {
     /// to locate them all and call their destructors.
     SCEVUnknown *FirstUnknown;
   };
+
+  /// \brief Analysis pass that exposes the \c ScalarEvolution for a function.
+  class ScalarEvolutionAnalysis {
+    static char PassID;
+
+  public:
+    typedef ScalarEvolution Result;
+
+    /// \brief Opaque, unique identifier for this analysis pass.
+    static void *ID() { return (void *)&PassID; }
+
+    /// \brief Provide a name for the analysis for debugging and logging.
+    static StringRef name() { return "ScalarEvolutionAnalysis"; }
+
+    ScalarEvolution run(Function &F, AnalysisManager<Function> *AM);
+  };
+
+  /// \brief Printer pass for the \c ScalarEvolutionAnalysis results.
+  class ScalarEvolutionPrinterPass {
+    raw_ostream &OS;
+
+  public:
+    explicit ScalarEvolutionPrinterPass(raw_ostream &OS) : OS(OS) {}
+    PreservedAnalyses run(Function &F, AnalysisManager<Function> *AM);
+
+    static StringRef name() { return "ScalarEvolutionPrinterPass"; }
+  };
+
+  class ScalarEvolutionWrapperPass : public FunctionPass {
+    std::unique_ptr<ScalarEvolution> SE;
+
+  public:
+    static char ID;
+
+    ScalarEvolutionWrapperPass();
+
+    ScalarEvolution &getSE() { return *SE; }
+    const ScalarEvolution &getSE() const { return *SE; }
+
+    bool runOnFunction(Function &F) override;
+    void releaseMemory() override;
+    void getAnalysisUsage(AnalysisUsage &AU) const override;
+    void print(raw_ostream &OS, const Module * = nullptr) const override;
+    void verifyAnalysis() const override;
+  };
 }
 
 #endif