14 #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONEXPANDER_H
15 #define LLVM_ANALYSIS_SCALAREVOLUTIONEXPANDER_H
25 class TargetTransformInfo;
48 std::set<AssertingVH<Value> > InsertedValues;
49 std::set<AssertingVH<Value> > InsertedPostIncValues;
63 const Loop *IVIncInsertLoop;
70 std::set<AssertingVH<PHINode> > ChainedPhis;
87 const char *DebugType;
96 : SE(se), DL(DL), IVName(name), IVIncInsertLoop(nullptr),
97 IVIncInsertPos(nullptr), CanonicalMode(
true), LSRMode(
false),
112 InsertedExpressions.clear();
113 InsertedValues.clear();
114 InsertedPostIncValues.clear();
122 return isHighCostExpansionHelper(Expr, L, Processed);
151 assert(!CanonicalMode &&
152 "IV increment positions are not supported in CanonicalMode");
154 IVIncInsertPos = Pos;
160 assert(!CanonicalMode &&
161 "Post-inc expansion is not supported in CanonicalMode");
167 PostIncLoops.
clear();
171 InsertedPostIncValues.clear();
191 return InsertedValues.count(I) || InsertedPostIncValues.count(I);
200 bool isHighCostExpansionHelper(
const SCEV *S, Loop *L,
201 SmallPtrSetImpl<const SCEV *> &Processed);
211 Value *ReuseOrCreateCast(Value *V,
Type *Ty,
217 Value *InsertNoopCastOfTo(Value *V,
Type *Ty);
221 Value *expandAddToGEP(
const SCEV *
const *op_begin,
222 const SCEV *
const *op_end,
225 Value *expand(
const SCEV *S);
234 const Loop *getRelevantLoop(
const SCEV *);
236 Value *visitConstant(
const SCEVConstant *S) {
237 return S->getValue();
240 Value *visitTruncateExpr(
const SCEVTruncateExpr *S);
242 Value *visitZeroExtendExpr(
const SCEVZeroExtendExpr *S);
244 Value *visitSignExtendExpr(
const SCEVSignExtendExpr *S);
246 Value *visitAddExpr(
const SCEVAddExpr *S);
248 Value *visitMulExpr(
const SCEVMulExpr *S);
250 Value *visitUDivExpr(
const SCEVUDivExpr *S);
252 Value *visitAddRecExpr(
const SCEVAddRecExpr *S);
254 Value *visitSMaxExpr(
const SCEVSMaxExpr *S);
256 Value *visitUMaxExpr(
const SCEVUMaxExpr *S);
258 Value *visitUnknown(
const SCEVUnknown *S) {
259 return S->getValue();
262 void rememberInstruction(Value *
I);
264 bool isNormalAddRecExprPHI(PHINode *PN, Instruction *IncV,
const Loop *L);
266 bool isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV,
const Loop *L);
268 Value *expandAddRecExprLiterally(
const SCEVAddRecExpr *);
269 PHINode *getAddRecExprPHILiterally(
const SCEVAddRecExpr *Normalized,
275 Value *expandIVInc(PHINode *PN, Value *StepV,
const Loop *L,
276 Type *ExpandTy,
Type *IntTy,
bool useSubtract);
A parsed version of the target data layout string in and methods for querying it. ...
bool hoistIVInc(Instruction *IncV, Instruction *InsertPos)
Utility for hoisting an IV increment.
LLVMContext & getContext() const
ScalarEvolution - This class is the main scalar evolution driver.
void setDebugType(const char *s)
void clearPostInc()
Disable all post-inc expansion.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void ClearInsertionPoint()
Clear the insertion point: created instructions will not be inserted into a block.
TargetFolder - Create constants with target dependent folding.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
void clearInsertPoint()
Clear the current insertion point.
void clear()
Erase the contents of the InsertedExpressions map so that users trying to expand the same expression ...
SCEVVisitor - This class defines a simple visitor class that may be used for various SCEV analysis pu...
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Value handle that tracks a Value across RAUW.
bool isHighCostExpansion(const SCEV *Expr, Loop *L)
Return true for expressions that may incur non-trivial cost to evaluate at runtime.
Value * expandCodeFor(const SCEV *SH, Type *Ty, Instruction *I)
Insert code to directly compute the specified SCEV expression into the program.
SCEVExpander(ScalarEvolution &se, const DataLayout &DL, const char *name)
Construct a SCEVExpander in "canonical" mode.
void setChainedPhi(PHINode *PN)
unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT, SmallVectorImpl< WeakVH > &DeadInsts, const TargetTransformInfo *TTI=nullptr)
replace congruent phis with their most canonical representative.
PHINode * getOrInsertCanonicalInductionVariable(const Loop *L, Type *Ty)
This method returns the canonical induction variable of the specified type for the specified loop (in...
void setIVIncInsertPos(const Loop *L, Instruction *Pos)
Set the current IV increment loop and position.
This class uses information about analyze scalars to rewrite expressions in canonical form...
SCEV - This class represents an analyzed expression in the program.
Instruction * getIVIncOperand(Instruction *IncV, Instruction *InsertPos, bool allowScale)
Return the induction variable increment's IV operand.
LLVM Value Representation.
bool isInsertedInstruction(Instruction *I) const
Return true if the specified instruction was inserted by the code rewriter.
void disableCanonicalMode()
Disable the behavior of expanding expressions in canonical form rather than in a more literal form...
void setPostInc(const PostIncLoopSet &L)
Enable post-inc expansion for addrecs referring to the given loops.
bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE)
Return true if the given expression is safe to expand in the sense that all materialized values are s...
InstListType::iterator iterator
Instruction iterators...