#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"
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.
/// 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.
///
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
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,
/// 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