14 #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONEXPANDER_H
15 #define LLVM_ANALYSIS_SCALAREVOLUTIONEXPANDER_H
27 class TargetTransformInfo;
65 const Loop *IVIncInsertLoop;
92 class SCEVInsertPointGuard {
99 SCEVInsertPointGuard(
const SCEVInsertPointGuard &) =
delete;
100 SCEVInsertPointGuard &operator=(
const SCEVInsertPointGuard &) =
delete;
109 ~SCEVInsertPointGuard() {
116 Builder.SetCurrentDebugLocation(DbgLoc);
128 const char *DebugType;
137 : SE(se), DL(DL), IVName(name), IVIncInsertLoop(nullptr),
138 IVIncInsertPos(nullptr), CanonicalMode(
true), LSRMode(
false),
158 InsertedExpressions.clear();
159 InsertedValues.clear();
160 InsertedPostIncValues.clear();
173 return isHighCostExpansionHelper(Expr, L, At, Processed);
232 "IV increment positions are not supported in CanonicalMode");
234 IVIncInsertPos = Pos;
241 "Post-inc expansion is not supported in CanonicalMode");
247 PostIncLoops.
clear();
251 InsertedPostIncValues.clear();
279 return InsertedValues.count(I) || InsertedPostIncValues.count(I);
307 bool isHighCostExpansionHelper(
const SCEV *S, Loop *
L,
308 const Instruction *At,
309 SmallPtrSetImpl<const SCEV *> &Processed);
318 Value *ReuseOrCreateCast(Value *V,
Type *Ty,
324 Value *InsertNoopCastOfTo(Value *V,
Type *Ty);
328 Value *expandAddToGEP(
const SCEV *
const *op_begin,
329 const SCEV *
const *op_end,
330 PointerType *PTy,
Type *Ty, Value *V);
333 ScalarEvolution::ValueOffsetPair
334 FindValueInExprValueMap(
const SCEV *S,
const Instruction *InsertPt);
336 Value *
expand(
const SCEV *S);
339 const Loop *getRelevantLoop(
const SCEV *);
341 Value *visitConstant(
const SCEVConstant *S) {
342 return S->getValue();
345 Value *visitTruncateExpr(
const SCEVTruncateExpr *S);
347 Value *visitZeroExtendExpr(
const SCEVZeroExtendExpr *S);
349 Value *visitSignExtendExpr(
const SCEVSignExtendExpr *S);
351 Value *visitAddExpr(
const SCEVAddExpr *S);
353 Value *visitMulExpr(
const SCEVMulExpr *S);
355 Value *visitUDivExpr(
const SCEVUDivExpr *S);
357 Value *visitAddRecExpr(
const SCEVAddRecExpr *S);
359 Value *visitSMaxExpr(
const SCEVSMaxExpr *S);
361 Value *visitUMaxExpr(
const SCEVUMaxExpr *S);
363 Value *visitUnknown(
const SCEVUnknown *S) {
364 return S->getValue();
367 void rememberInstruction(Value *
I);
369 bool isNormalAddRecExprPHI(PHINode *PN, Instruction *IncV,
const Loop *
L);
371 bool isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV,
const Loop *
L);
373 Value *expandAddRecExprLiterally(
const SCEVAddRecExpr *);
374 PHINode *getAddRecExprPHILiterally(
const SCEVAddRecExpr *Normalized,
380 Value *expandIVInc(PHINode *PN, Value *StepV,
const Loop *
L,
381 Type *ExpandTy,
Type *IntTy,
bool useSubtract);
383 void hoistBeforePos(DominatorTree *DT, Instruction *InstToHoist,
384 Instruction *Pos, PHINode *LoopPhi);
386 void fixupInsertPoints(Instruction *
I);
Common base class shared among various IRBuilders.
void push_back(const T &Elt)
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.
BasicBlock::iterator GetInsertPoint() const
Value * getExactExistingExpansion(const SCEV *S, const Instruction *At, Loop *L)
Try to find existing LLVM IR value for S available at the point At.
LLVMContext & getContext() const
Implements a dense probed hash-table based set.
The main scalar evolution driver.
bool isHighCostExpansion(const SCEV *Expr, Loop *L, const Instruction *At=nullptr)
Return true for expressions that may incur non-trivial cost to evaluate at runtime.
Optional< ScalarEvolution::ValueOffsetPair > getRelatedExistingExpansion(const SCEV *S, const Instruction *At, Loop *L)
Try to find the ValueOffsetPair for S.
void setDebugType(const char *s)
Value * expandWrapPredicate(const SCEVWrapPredicate *P, Instruction *Loc)
A specialized variant of expandCodeForPredicate, handling the case when we are expanding code for a S...
Value * expandCodeForPredicate(const SCEVPredicate *Pred, Instruction *Loc)
Generates a code sequence that evaluates this predicate.
void clearPostInc()
Disable all post-inc expansion.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Value * generateOverflowCheck(const SCEVAddRecExpr *AR, Instruction *Loc, bool Signed)
Generates code that evaluates if the AR expression will overflow.
LLVM_NODISCARD bool empty() const
This node represents a polynomial recurrence on the trip count of the specified loop.
void ClearInsertionPoint()
Clear the insertion point: created instructions will not be inserted into a block.
Function Alias Analysis false
TargetFolder - Create constants with target dependent folding.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
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 ...
This class defines a simple visitor class that may be used for various SCEV analysis purposes...
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.
void setInsertPoint(Instruction *IP)
Set the current insertion point.
Value handle that tracks a Value across RAUW.
Value * expandCodeFor(const SCEV *SH, Type *Ty, Instruction *I)
Insert code to directly compute the specified SCEV expression into the program.
static Expected< BitVector > expand(StringRef S, StringRef Original)
SCEVExpander(ScalarEvolution &se, const DataLayout &DL, const char *name)
Construct a SCEVExpander in "canonical" mode.
This class represents an assumption made using SCEV expressions which can be checked at run-time...
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.
Iterator for intrusive lists based on ilist_node.
InsertPoint - A saved insertion point.
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.
BasicBlock * GetInsertBlock() const
Value handle that asserts if the Value is deleted.
const DebugLoc & getCurrentDebugLocation() const
Get location information used by debugging information.
Value * expandUnionPredicate(const SCEVUnionPredicate *Pred, Instruction *Loc)
A specialized variant of expandCodeForPredicate, handling the case when we are expanding code for a S...
This class uses information about analyze scalars to rewrite expressions in canonical form...
This class represents an analyzed expression in the program.
Represents a single loop in the control flow graph.
Instruction * getIVIncOperand(Instruction *IncV, Instruction *InsertPos, bool allowScale)
Return the induction variable increment's IV operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents a composition of other SCEV predicates, and is the class that most clients will...
Value * expandEqualPredicate(const SCEVEqualPredicate *Pred, Instruction *Loc)
A specialized variant of expandCodeForPredicate, handling the case when we are expanding code for a S...
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...
This class represents an assumption made on an AddRec expression.
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...
This class represents an assumption that two SCEV expressions are equal, and this can be checked at r...
InstListType::iterator iterator
Instruction iterators...