14 #ifndef LLVM_TRANSFORMS_UTILS_LOOPUTILS_H
15 #define LLVM_TRANSFORMS_UTILS_LOOPUTILS_H
25 class AliasSetTracker;
26 class AssumptionCache;
32 class OptimizationRemarkEmitter;
34 class PredicatedScalarEvolution;
35 class PredIteratorCache;
36 class ScalarEvolution;
38 class TargetLibraryInfo;
93 MinMaxKind(
MRK_Invalid), UnsafeAlgebraInst(nullptr),
94 RecurrenceType(nullptr), IsSigned(
false) {}
99 : StartValue(Start), LoopExitInstr(Exit), Kind(K), MinMaxKind(MK),
100 UnsafeAlgebraInst(UAI), RecurrenceType(RT), IsSigned(Signed) {
109 : IsRecurrence(IsRecur), PatternLastInst(I), MinMaxKind(
MRK_Invalid),
110 UnsafeAlgebraInst(UAI) {}
113 : IsRecurrence(
true), PatternLastInst(I), MinMaxKind(K),
114 UnsafeAlgebraInst(UAI) {}
144 InstDesc &Prev,
bool HasFunNoNaNAttr);
172 bool HasFunNoNaNAttr,
225 Type *RT,
bool &IsSigned,
253 Type *RecurrenceType;
275 InductionBinOp(nullptr) {}
304 const SCEV *Expr =
nullptr);
326 return InductionBinOp &&
333 if (!InductionBinOp ||
336 return InductionBinOp;
341 return InductionBinOp ? InductionBinOp->
getOpcode() :
342 Instruction::BinaryOpsEnd;
375 DominatorTree &DT, LoopInfo &LI);
388 bool formLCSSA(Loop &
L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution *SE);
400 ScalarEvolution *SE);
411 TargetLibraryInfo *, Loop *, AliasSetTracker *,
412 LoopSafetyInfo *, OptimizationRemarkEmitter *ORE);
423 TargetLibraryInfo *, Loop *, AliasSetTracker *,
424 LoopSafetyInfo *, OptimizationRemarkEmitter *ORE);
435 SmallVectorImpl<Instruction *> &,
436 PredIteratorCache &, LoopInfo *,
437 DominatorTree *,
const TargetLibraryInfo *,
438 Loop *, AliasSetTracker *, LoopSafetyInfo *,
439 OptimizationRemarkEmitter *);
451 const LoopSafetyInfo *SafetyInfo);
488 Loop *CurLoop, AliasSetTracker *CurAST,
489 LoopSafetyInfo *SafetyInfo,
490 OptimizationRemarkEmitter *ORE =
nullptr);
Bitwise or logical XOR of numbers.
static bool isArithmeticRecurrenceKind(RecurrenceKind Kind)
Returns true if the recurrence kind is an arithmetic kind.
A parsed version of the target data layout string in and methods for querying it. ...
static bool isFPInductionPHI(PHINode *Phi, const Loop *L, ScalarEvolution *SE, InductionDescriptor &D)
Returns true if Phi is a floating point induction in the loop L.
Instruction * getPatternInst()
Instruction * getUnsafeAlgebraInst()
Returns first unsafe algebra instruction in the PHI node's use-chain.
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
aarch64 AArch64 CCMP Pass
Min/max implemented in terms of select(cmp()).
InstDesc(bool IsRecur, Instruction *I, Instruction *UAI=nullptr)
The main scalar evolution driver.
int getConsecutiveDirection() const
Get the consecutive direction.
static bool isReductionPHI(PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes)
Returns true if Phi is a reduction in TheLoop.
BasicBlock * InsertPreheaderForLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, bool PreserveLCSSA)
InsertPreheaderForLoop - Once we discover that a loop doesn't have a preheader, this method is called...
MinMaxRecurrenceKind getMinMaxRecurrenceKind()
static InstDesc isRecurrenceInstr(Instruction *I, RecurrenceKind Kind, InstDesc &Prev, bool HasFunNoNaNAttr)
Returns a struct describing if the instruction 'I' can be a recurrence variable of type 'Kind'...
static Instruction * lookThroughAnd(PHINode *Phi, Type *&RT, SmallPtrSetImpl< Instruction * > &Visited, SmallPtrSetImpl< Instruction * > &CI)
Determines if Phi may have been type-promoted.
DenseMap< BasicBlock *, ColorVector > BlockColors
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool formLCSSARecursively(Loop &L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution *SE)
Put a loop nest into LCSSA form.
bool isSigned()
Returns true if all source operands of the recurrence are SExtInsts.
bool hasUnsafeAlgebra()
Returns true if the recurrence has unsafe algebra which requires a relaxed floating-point model...
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static InstDesc isMinMaxSelectCmpPattern(Instruction *I, InstDesc &Prev)
Returns a struct describing if the instruction if the instruction is a Select(ICmp(X, Y), X, Y) instruction pattern corresponding to a min(X, Y) or max(X, Y).
ConstantInt * getConstIntStepValue() const
SmallVector< Instruction *, 8 > findDefsUsedOutsideOfLoop(Loop *L)
Returns the instructions that use values defined in the loop.
void computeLoopSafetyInfo(LoopSafetyInfo *, Loop *)
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
Value * transform(IRBuilder<> &B, Value *Index, ScalarEvolution *SE, const DataLayout &DL) const
Compute the transformed value of Index at offset StartValue using step StepValue. ...
Function Alias Analysis false
static bool areAllUsesIn(Instruction *I, SmallPtrSetImpl< Instruction * > &Set)
Returns true if all uses of the instruction I is within the Set.
Not an induction variable.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
This POD struct holds information about a potential recurrence operation.
void addStringMetadataToLoop(Loop *TheLoop, const char *MDString, unsigned V=0)
Set input string into loop metadata by keeping other values intact.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Bitwise or logical AND of numbers.
static bool hasMultipleUsesOf(Instruction *I, SmallPtrSetImpl< Instruction * > &Insts)
Returns true if instruction I has multiple uses in Insts.
Pointer induction var. Step = C / sizeof(elem).
static bool AddReductionVar(PHINode *Phi, RecurrenceKind Kind, Loop *TheLoop, bool HasFunNoNaNAttr, RecurrenceDescriptor &RedDes)
Returns true if Phi is a reduction of type Kind and adds it to the RecurrenceDescriptor.
Integer induction variable. Step = C.
The instances of the Type class are immutable: once they are created, they are never changed...
Min/max implemented in terms of select(cmp()).
Value handle that tracks a Value across RAUW.
This is an important base class in LLVM.
Instruction * getUnsafeAlgebraInst()
Returns induction operator that does not have "fast-math" property and requires FP unsafe mode...
InstDesc(Instruction *I, MinMaxRecurrenceKind K, Instruction *UAI=nullptr)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Instruction * getUnsafeAlgebraInst()
Instruction::BinaryOps getInductionOpcode() const
Returns binary opcode of the induction operator.
static bool isFirstOrderRecurrence(PHINode *Phi, Loop *TheLoop, DominatorTree *DT)
Returns true if Phi is a first-order recurrence.
Optional< unsigned > getLoopEstimatedTripCount(Loop *L)
Get a loop's estimated trip count based on branch weight metadata.
bool promoteLoopAccessesToScalars(AliasSet &, SmallVectorImpl< BasicBlock * > &, SmallVectorImpl< Instruction * > &, PredIteratorCache &, LoopInfo *, DominatorTree *, const TargetLibraryInfo *, Loop *, AliasSetTracker *, LoopSafetyInfo *, OptimizationRemarkEmitter *)
Try to promote memory values to scalars by sinking stores out of the loop and moving loads to before ...
RecurrenceKind getRecurrenceKind()
Optional< const MDOperand * > findStringMetadataForLoop(Loop *TheLoop, StringRef Name)
Find string metadata for loop.
static unsigned getRecurrenceBinOp(RecurrenceKind Kind)
Returns the opcode of binary operation corresponding to the RecurrenceKind.
Value * getStartValue() const
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
bool formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution *SE)
Put loop into LCSSA form.
BinaryOps getOpcode() const
MinMaxRecurrenceKind getMinMaxKind()
This is the shared class of boolean and integer constants.
A struct for saving information about induction variables.
Bitwise or logical OR of numbers.
bool formLCSSAForInstructions(SmallVectorImpl< Instruction * > &Worklist, DominatorTree &DT, LoopInfo &LI)
Ensures LCSSA form for every instruction from the Worklist in the scope of innermost containing loop...
static bool getSourceExtensionKind(Instruction *Start, Instruction *Exit, Type *RT, bool &IsSigned, SmallPtrSetImpl< Instruction * > &Visited, SmallPtrSetImpl< Instruction * > &CI)
Returns true if all the source operands of a recurrence are either SExtInsts or ZExtInsts.
static bool isFloatingPointRecurrenceKind(RecurrenceKind Kind)
Returns true if the recurrence kind is a floating point kind.
InductionKind getKind() const
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
RecurrenceDescriptor(Value *Start, Instruction *Exit, RecurrenceKind K, MinMaxRecurrenceKind MK, Instruction *UAI, Type *RT, bool Signed, SmallPtrSetImpl< Instruction * > &CI)
bool hoistRegion(DomTreeNode *, AliasAnalysis *, LoopInfo *, DominatorTree *, TargetLibraryInfo *, Loop *, AliasSetTracker *, LoopSafetyInfo *, OptimizationRemarkEmitter *ORE)
Walk the specified region of the CFG (defined by all blocks dominated by the specified block...
DomTreeNodeBase< BasicBlock > DomTreeNode
static Constant * getRecurrenceIdentity(RecurrenceKind K, Type *Tp)
Returns identity corresponding to the RecurrenceKind.
bool sinkRegion(DomTreeNode *, AliasAnalysis *, LoopInfo *, DominatorTree *, TargetLibraryInfo *, Loop *, AliasSetTracker *, LoopSafetyInfo *, OptimizationRemarkEmitter *ORE)
Walk the specified region of the CFG (defined by all blocks dominated by the specified block...
static Value * createMinMaxOp(IRBuilder<> &Builder, MinMaxRecurrenceKind RK, Value *Left, Value *Right)
Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
bool hasUnsafeAlgebra()
Returns true if the induction type is FP and the binary operator does not have the "fast-math" proper...
Captures loop safety information.
This class represents an analyzed expression in the program.
static bool isIntegerRecurrenceKind(RecurrenceKind Kind)
Returns true if the recurrence kind is an integer kind.
Floating point induction variable.
Instruction * getLoopExitInstr()
Represents a single loop in the control flow graph.
void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass's AnalysisUsage.
const SCEV * getStep() const
InductionDescriptor()
Default constructor - creates an invalid induction.
SmallPtrSet< Instruction *, 8 > & getCastInsts()
Returns a reference to the instructions used for type-promoting the recurrence.
LLVM Value Representation.
TrackingVH< Value > getRecurrenceStartValue()
bool canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT, Loop *CurLoop, AliasSetTracker *CurAST, LoopSafetyInfo *SafetyInfo, OptimizationRemarkEmitter *ORE=nullptr)
Returns true if the hoister and sinker can handle this instruction.
InductionKind
This enum represents the kinds of inductions that we support.
bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo)
Returns true if the instruction in a loop is guaranteed to execute at least once. ...
static bool isInductionPHI(PHINode *Phi, const Loop *L, ScalarEvolution *SE, InductionDescriptor &D, const SCEV *Expr=nullptr)
Returns true if Phi is an induction in the loop L.
RecurrenceKind
This enum represents the kinds of recurrences that we support.
Type * getRecurrenceType()
Returns the type of the recurrence.