diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 |
| commit | 044eb2f6afba375a914ac9d8024f8f5142bb912e (patch) | |
| tree | 1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /include/llvm/Analysis/ScalarEvolutionExpressions.h | |
| parent | eb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff) | |
Notes
Diffstat (limited to 'include/llvm/Analysis/ScalarEvolutionExpressions.h')
| -rw-r--r-- | include/llvm/Analysis/ScalarEvolutionExpressions.h | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/include/llvm/Analysis/ScalarEvolutionExpressions.h b/include/llvm/Analysis/ScalarEvolutionExpressions.h index 56ddb5028d6d..acf83455cdcd 100644 --- a/include/llvm/Analysis/ScalarEvolutionExpressions.h +++ b/include/llvm/Analysis/ScalarEvolutionExpressions.h @@ -14,15 +14,27 @@ #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H #define LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Analysis/ScalarEvolution.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/Value.h" +#include "llvm/IR/ValueHandle.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" +#include <cassert> +#include <cstddef> namespace llvm { - class ConstantInt; - class ConstantRange; - class DominatorTree; + +class APInt; +class Constant; +class ConstantRange; +class Loop; +class Type; enum SCEVTypes { // These should be ordered in terms of increasing complexity to make the @@ -37,8 +49,10 @@ namespace llvm { friend class ScalarEvolution; ConstantInt *V; + SCEVConstant(const FoldingSetNodeIDRef ID, ConstantInt *v) : SCEV(ID, scConstant), V(v) {} + public: ConstantInt *getValue() const { return V; } const APInt &getAPInt() const { return getValue()->getValue(); } @@ -117,7 +131,6 @@ namespace llvm { } }; - /// This node is a base class providing common functionality for /// n'ary operators. class SCEVNAryExpr : public SCEV { @@ -135,13 +148,15 @@ namespace llvm { public: size_t getNumOperands() const { return NumOperands; } + const SCEV *getOperand(unsigned i) const { assert(i < NumOperands && "Operand index out of range!"); return Operands[i]; } - typedef const SCEV *const *op_iterator; - typedef iterator_range<op_iterator> op_range; + using op_iterator = const SCEV *const *; + using op_range = iterator_range<op_iterator>; + op_iterator op_begin() const { return Operands; } op_iterator op_end() const { return Operands + NumOperands; } op_range operands() const { @@ -198,15 +213,13 @@ namespace llvm { } }; - /// This node represents an addition of some number of SCEVs. class SCEVAddExpr : public SCEVCommutativeExpr { friend class ScalarEvolution; SCEVAddExpr(const FoldingSetNodeIDRef ID, const SCEV *const *O, size_t N) - : SCEVCommutativeExpr(ID, scAddExpr, O, N) { - } + : SCEVCommutativeExpr(ID, scAddExpr, O, N) {} public: Type *getType() const { @@ -222,15 +235,13 @@ namespace llvm { } }; - /// This node represents multiplication of some number of SCEVs. class SCEVMulExpr : public SCEVCommutativeExpr { friend class ScalarEvolution; SCEVMulExpr(const FoldingSetNodeIDRef ID, const SCEV *const *O, size_t N) - : SCEVCommutativeExpr(ID, scMulExpr, O, N) { - } + : SCEVCommutativeExpr(ID, scMulExpr, O, N) {} public: /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -239,13 +250,13 @@ namespace llvm { } }; - /// This class represents a binary unsigned division operation. class SCEVUDivExpr : public SCEV { friend class ScalarEvolution; const SCEV *LHS; const SCEV *RHS; + SCEVUDivExpr(const FoldingSetNodeIDRef ID, const SCEV *lhs, const SCEV *rhs) : SCEV(ID, scUDivExpr), LHS(lhs), RHS(rhs) {} @@ -268,7 +279,6 @@ namespace llvm { } }; - /// This node represents a polynomial recurrence on the trip count /// of the specified loop. This is the primary focus of the /// ScalarEvolution framework; all the other SCEV subclasses are @@ -368,7 +378,6 @@ namespace llvm { } }; - /// This class represents an unsigned maximum selection. class SCEVUMaxExpr : public SCEVCommutativeExpr { friend class ScalarEvolution; @@ -393,10 +402,6 @@ namespace llvm { class SCEVUnknown final : public SCEV, private CallbackVH { friend class ScalarEvolution; - // Implement CallbackVH. - void deleted() override; - void allUsesReplacedWith(Value *New) override; - /// The parent ScalarEvolution value. This is used to update the /// parent's maps when the value associated with a SCEVUnknown is /// deleted or RAUW'd. @@ -410,6 +415,10 @@ namespace llvm { ScalarEvolution *se, SCEVUnknown *next) : SCEV(ID, scUnknown), CallbackVH(V), SE(se), Next(next) {} + // Implement CallbackVH. + void deleted() override; + void allUsesReplacedWith(Value *New) override; + public: Value *getValue() const { return getValPtr(); } @@ -490,6 +499,7 @@ namespace llvm { if (Visited.insert(S).second && Visitor.follow(S)) Worklist.push_back(S); } + public: SCEVTraversal(SV& V): Visitor(V) {} @@ -682,7 +692,7 @@ namespace llvm { } }; - typedef DenseMap<const Value*, Value*> ValueToValueMap; + using ValueToValueMap = DenseMap<const Value *, Value *>; /// The SCEVParameterRewriter takes a scalar evolution expression and updates /// the SCEVUnknown components following the Map (Value -> Value). @@ -714,26 +724,26 @@ namespace llvm { bool InterpretConsts; }; - typedef DenseMap<const Loop*, const SCEV*> LoopToScevMapT; + using LoopToScevMapT = DenseMap<const Loop *, const SCEV *>; /// The SCEVLoopAddRecRewriter takes a scalar evolution expression and applies /// the Map (Loop -> SCEV) to all AddRecExprs. class SCEVLoopAddRecRewriter : public SCEVRewriteVisitor<SCEVLoopAddRecRewriter> { public: + SCEVLoopAddRecRewriter(ScalarEvolution &SE, LoopToScevMapT &M) + : SCEVRewriteVisitor(SE), Map(M) {} + static const SCEV *rewrite(const SCEV *Scev, LoopToScevMapT &Map, ScalarEvolution &SE) { SCEVLoopAddRecRewriter Rewriter(SE, Map); return Rewriter.visit(Scev); } - SCEVLoopAddRecRewriter(ScalarEvolution &SE, LoopToScevMapT &M) - : SCEVRewriteVisitor(SE), Map(M) {} - const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) { SmallVector<const SCEV *, 2> Operands; - for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) - Operands.push_back(visit(Expr->getOperand(i))); + for (const SCEV *Op : Expr->operands()) + Operands.push_back(visit(Op)); const Loop *L = Expr->getLoop(); const SCEV *Res = SE.getAddRecExpr(Operands, L, Expr->getNoWrapFlags()); @@ -748,6 +758,7 @@ namespace llvm { private: LoopToScevMapT ⤅ }; -} -#endif +} // end namespace llvm + +#endif // LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H |
