36 using namespace llvm::PatternMatch;
38 #define DEBUG_TYPE "loop-utils"
43 if (!Set.
count(dyn_cast<Instruction>(*
Use)))
57 case RK_IntegerMinMax:
64 return (Kind != RK_NoRecurrence) && !isIntegerRecurrenceKind(Kind);
87 const APInt *M =
nullptr;
93 int32_t
Bits = (*M + 1).exactLogBase2();
110 bool FoundOneOperand =
false;
116 while (!Worklist.
empty()) {
123 if (!J || J == Start)
127 if (Visited.
count(J)) {
136 bool IsSExtInst = isa<SExtInst>(J);
137 if (!Cast || !Cast->
hasOneUse() || !(isa<ZExtInst>(J) || IsSExtInst))
143 if (SrcSize > DstSize)
147 if (FoundOneOperand) {
148 if (IsSigned != IsSExtInst)
151 FoundOneOperand =
true;
152 IsSigned = IsSExtInst;
158 if (SrcSize == DstSize)
166 Loop *TheLoop,
bool HasFunNoNaNAttr,
185 bool FoundReduxOp =
false;
191 bool FoundStartPHI =
false;
196 unsigned NumCmpSelectPatternInst = 0;
203 bool IsSigned =
false;
214 if (!isFloatingPointRecurrenceKind(Kind))
217 if (!isIntegerRecurrenceKind(Kind))
219 if (isArithmeticRecurrenceKind(Kind))
220 Start = lookThroughAnd(Phi, RecurrenceType, VisitedInsts, CastInsts);
224 VisitedInsts.
insert(Start);
241 while (!Worklist.
empty()) {
251 bool IsAPhi = isa<PHINode>(Cur);
259 if (!Cur->
isCommutative() && !IsAPhi && !isa<SelectInst>(Cur) &&
260 !isa<ICmpInst>(Cur) && !isa<FCmpInst>(Cur) &&
268 ReduxDesc = isRecurrenceInstr(Cur, Kind, ReduxDesc, HasFunNoNaNAttr);
274 if (!IsAPhi && Kind != RK_IntegerMinMax && Kind != RK_FloatMinMax &&
275 hasMultipleUsesOf(Cur, VisitedInsts))
279 if (IsAPhi && Cur != Phi && !areAllUsesIn(Cur, VisitedInsts))
282 if (Kind == RK_IntegerMinMax &&
283 (isa<ICmpInst>(Cur) || isa<SelectInst>(Cur)))
284 ++NumCmpSelectPatternInst;
285 if (Kind == RK_FloatMinMax && (isa<FCmpInst>(Cur) || isa<SelectInst>(Cur)))
286 ++NumCmpSelectPatternInst;
289 FoundReduxOp |= !IsAPhi && Cur != Start;
304 if (ExitInstruction == Cur)
311 if (ExitInstruction !=
nullptr || Cur == Phi)
320 ExitInstruction = Cur;
327 InstDesc IgnoredVal(
false,
nullptr);
328 if (VisitedInsts.
insert(UI).second) {
329 if (isa<PHINode>(UI))
333 }
else if (!isa<PHINode>(UI) &&
334 ((!isa<FCmpInst>(UI) && !isa<ICmpInst>(UI) &&
335 !isa<SelectInst>(UI)) ||
336 !isMinMaxSelectCmpPattern(UI, IgnoredVal).isRecurrence()))
341 FoundStartPHI =
true;
349 if ((Kind == RK_IntegerMinMax || Kind == RK_FloatMinMax) &&
350 NumCmpSelectPatternInst != 2)
353 if (!FoundStartPHI || !FoundReduxOp || !ExitInstruction)
360 if (!getSourceExtensionKind(Start, ExitInstruction, RecurrenceType,
361 IsSigned, VisitedInsts, CastInsts))
384 assert((isa<ICmpInst>(I) || isa<FCmpInst>(I) || isa<SelectInst>(I)) &&
385 "Expect a select instruction");
391 if ((Cmp = dyn_cast<ICmpInst>(I)) || (Cmp = dyn_cast<FCmpInst>(I))) {
398 if (!(Select = dyn_cast<SelectInst>(I)))
400 if (!(Cmp = dyn_cast<ICmpInst>(I->
getOperand(0))) &&
411 return InstDesc(Select, MRK_UIntMin);
413 return InstDesc(Select, MRK_UIntMax);
415 return InstDesc(Select, MRK_SIntMax);
417 return InstDesc(Select, MRK_SIntMin);
419 return InstDesc(Select, MRK_FloatMin);
421 return InstDesc(Select, MRK_FloatMax);
423 return InstDesc(Select, MRK_FloatMin);
425 return InstDesc(Select, MRK_FloatMax);
432 InstDesc &Prev,
bool HasFunNoNaNAttr) {
441 case Instruction::PHI:
443 case Instruction::Sub:
445 return InstDesc(Kind == RK_IntegerAdd, I);
446 case Instruction::Mul:
447 return InstDesc(Kind == RK_IntegerMult, I);
448 case Instruction::And:
449 return InstDesc(Kind == RK_IntegerAnd, I);
450 case Instruction::Or:
451 return InstDesc(Kind == RK_IntegerOr, I);
452 case Instruction::Xor:
453 return InstDesc(Kind == RK_IntegerXor, I);
454 case Instruction::FMul:
455 return InstDesc(Kind == RK_FloatMult, I, UAI);
456 case Instruction::FSub:
457 case Instruction::FAdd:
458 return InstDesc(Kind == RK_FloatAdd, I, UAI);
459 case Instruction::FCmp:
460 case Instruction::ICmp:
462 if (Kind != RK_IntegerMinMax &&
463 (!HasFunNoNaNAttr || Kind != RK_FloatMinMax))
465 return isMinMaxSelectCmpPattern(I, Prev);
471 unsigned NumUses = 0;
474 if (Insts.
count(dyn_cast<Instruction>(*
Use)))
487 bool HasFunNoNaNAttr =
490 if (AddReductionVar(Phi, RK_IntegerAdd, TheLoop, HasFunNoNaNAttr, RedDes)) {
491 DEBUG(
dbgs() <<
"Found an ADD reduction PHI." << *Phi <<
"\n");
494 if (AddReductionVar(Phi, RK_IntegerMult, TheLoop, HasFunNoNaNAttr, RedDes)) {
495 DEBUG(
dbgs() <<
"Found a MUL reduction PHI." << *Phi <<
"\n");
498 if (AddReductionVar(Phi, RK_IntegerOr, TheLoop, HasFunNoNaNAttr, RedDes)) {
499 DEBUG(
dbgs() <<
"Found an OR reduction PHI." << *Phi <<
"\n");
502 if (AddReductionVar(Phi, RK_IntegerAnd, TheLoop, HasFunNoNaNAttr, RedDes)) {
503 DEBUG(
dbgs() <<
"Found an AND reduction PHI." << *Phi <<
"\n");
506 if (AddReductionVar(Phi, RK_IntegerXor, TheLoop, HasFunNoNaNAttr, RedDes)) {
507 DEBUG(
dbgs() <<
"Found a XOR reduction PHI." << *Phi <<
"\n");
510 if (AddReductionVar(Phi, RK_IntegerMinMax, TheLoop, HasFunNoNaNAttr,
512 DEBUG(
dbgs() <<
"Found a MINMAX reduction PHI." << *Phi <<
"\n");
515 if (AddReductionVar(Phi, RK_FloatMult, TheLoop, HasFunNoNaNAttr, RedDes)) {
516 DEBUG(
dbgs() <<
"Found an FMult reduction PHI." << *Phi <<
"\n");
519 if (AddReductionVar(Phi, RK_FloatAdd, TheLoop, HasFunNoNaNAttr, RedDes)) {
520 DEBUG(
dbgs() <<
"Found an FAdd reduction PHI." << *Phi <<
"\n");
523 if (AddReductionVar(Phi, RK_FloatMinMax, TheLoop, HasFunNoNaNAttr, RedDes)) {
524 DEBUG(
dbgs() <<
"Found an float MINMAX reduction PHI." << *Phi <<
"\n");
544 if (!Preheader || !Latch)
555 if (!Previous || !TheLoop->
contains(Previous) || isa<PHINode>(Previous) ||
556 SinkAfter.
count(Previous))
566 if (
I->isCast() && (
I->getParent() == Phi->
getParent()) &&
I->hasOneUse() &&
568 SinkAfter[
I] = Previous;
574 if (
auto *
I = dyn_cast<Instruction>(U)) {
615 return Instruction::Mul;
617 return Instruction::Or;
619 return Instruction::And;
621 return Instruction::Xor;
623 return Instruction::FMul;
625 return Instruction::FAdd;
626 case RK_IntegerMinMax:
627 return Instruction::ICmp;
629 return Instruction::FCmp;
670 if (RK == MRK_FloatMin || RK == MRK_FloatMax)
671 Cmp = Builder.
CreateFCmp(P, Left, Right,
"rdx.minmax.cmp");
673 Cmp = Builder.
CreateICmp(P, Left, Right,
"rdx.minmax.cmp");
681 : StartValue(Start), IK(K), Step(Step), InductionBinOp(BOp) {
682 assert(IK != IK_NoInduction &&
"Not an induction");
686 assert(StartValue &&
"StartValue is null");
687 assert((IK != IK_PtrInduction || StartValue->getType()->isPointerTy()) &&
688 "StartValue is not a pointer for pointer induction");
689 assert((IK != IK_IntInduction || StartValue->getType()->isIntegerTy()) &&
690 "StartValue is not an integer for integer induction");
693 assert((!getConstIntStepValue() || !getConstIntStepValue()->
isZero()) &&
694 "Step value is zero");
696 assert((IK != IK_PtrInduction || getConstIntStepValue()) &&
697 "Step value should be constant for pointer induction");
699 "StepValue is not an integer");
702 "StepValue is not FP for FpInduction");
703 assert((IK != IK_FpInduction || (InductionBinOp &&
704 (InductionBinOp->getOpcode() == Instruction::FAdd ||
705 InductionBinOp->getOpcode() == Instruction::FSub))) &&
706 "Binary opcode should be specified for FP induction");
717 if (isa<SCEVConstant>(Step))
728 "Index type does not match StepValue type");
732 "Index type does not match StartValue type");
753 assert(isa<SCEVConstant>(Step) &&
754 "Expected constant step for pointer induction");
757 return B.
CreateGEP(
nullptr, StartValue, Index);
762 (InductionBinOp->
getOpcode() == Instruction::FAdd ||
763 InductionBinOp->
getOpcode() == Instruction::FSub) &&
764 "Original bin op should be defined for FP induction");
766 Value *StepValue = cast<SCEVUnknown>(Step)->getValue();
773 if (isa<Instruction>(MulExp))
775 cast<Instruction>(MulExp)->setFastMathFlags(Flags);
778 MulExp,
"induction");
779 if (isa<Instruction>(BOp))
780 cast<Instruction>(BOp)->setFastMathFlags(Flags);
804 Value *BEValue =
nullptr, *StartValue =
nullptr;
810 "Unexpected Phi node in the loop");
819 Value *Addend =
nullptr;
820 if (BOp->
getOpcode() == Instruction::FAdd) {
825 }
else if (BOp->
getOpcode() == Instruction::FSub)
833 if (
auto *
I = dyn_cast<Instruction>(Addend))
868 DEBUG(
dbgs() <<
"LV: PHI is not a poly recurrence.\n");
885 const SCEV *PhiScev = Expr ? Expr : SE->
getSCEV(Phi);
889 DEBUG(
dbgs() <<
"LV: PHI is not a poly recurrence.\n");
893 if (AR->
getLoop() != TheLoop) {
896 DEBUG(
dbgs() <<
"LV: PHI is a recurrence with respect to an outer loop.\n");
923 if (!PointerElementType->
isSized())
941 bool PreserveLCSSA) {
942 bool Changed =
false;
949 "Must start with an empty predecessors list!");
954 bool IsDedicatedExit =
true;
957 if (isa<IndirectBrInst>(PredBB->getTerminator()))
963 IsDedicatedExit =
false;
966 assert(!InLoopPredecessors.
empty() &&
"Must have *some* loop predecessor!");
973 BB, InLoopPredecessors,
".loopexit", DT, LI, PreserveLCSSA);
976 DEBUG(
dbgs() <<
"WARNING: Can't create a dedicated exit block for loop: "
979 DEBUG(
dbgs() <<
"LoopSimplify: Creating dedicated exit block "
980 << NewExitBB->getName() <<
"\n");
987 for (
auto *BB : L->
blocks())
994 if (!Visited.
insert(SuccBB).second)
997 Changed |= RewriteExit(SuccBB);
1010 for (
auto &Inst : *Block) {
1011 auto Users = Inst.users();
1013 auto *
Use = cast<Instruction>(U);
1151 if (ExitBlocks.empty())
1173 "At least one edge out of the latch must go to the header");
1178 uint64_t TrueVal, FalseVal;
1182 if (!TrueVal || !FalseVal)
1188 return (TrueVal + (FalseVal / 2)) / FalseVal;
1190 return (FalseVal + (TrueVal / 2)) / TrueVal;
1195 if (isa<FPMathOperator>(V)) {
1198 cast<Instruction>(V)->setFastMathFlags(Flags);
1213 "Reduction emission only supported for pow2 vectors!");
1214 Value *TmpVec = Src;
1216 for (
unsigned i = VF; i != 1; i >>= 1) {
1218 for (
unsigned j = 0; j != i / 2; ++j)
1219 ShuffleMask[j] = Builder.
getInt32(i / 2 + j);
1222 std::fill(&ShuffleMask[i / 2], ShuffleMask.
end(),
1229 if (Op != Instruction::ICmp && Op != Instruction::FCmp) {
1232 TmpVec, Shuf,
"bin.rdx"));
1239 if (!RedOps.
empty())
1252 assert(isa<VectorType>(Src->
getType()) &&
"Type must be a vector");
1255 std::function<Value*()> BuildFunc;
1257 RD::MinMaxRecurrenceKind MinMaxKind = RD::MRK_Invalid;
1266 case Instruction::Mul:
1269 case Instruction::And:
1272 case Instruction::Or:
1275 case Instruction::Xor:
1278 case Instruction::FAdd:
1281 cast<CallInst>(Rdx)->setFastMathFlags(FMFUnsafe);
1285 case Instruction::FMul:
1288 cast<CallInst>(Rdx)->setFastMathFlags(FMFUnsafe);
1292 case Instruction::ICmp:
1294 MinMaxKind = Flags.
IsSigned ? RD::MRK_SIntMax : RD::MRK_UIntMax;
1299 MinMaxKind = Flags.
IsSigned ? RD::MRK_SIntMin : RD::MRK_UIntMin;
1305 case Instruction::FCmp:
1307 MinMaxKind = RD::MRK_FloatMax;
1310 MinMaxKind = RD::MRK_FloatMin;
1331 Flags.
NoNaN = NoNaN;
1332 auto getSimpleRdx = [&](
unsigned Opc) {
1337 return getSimpleRdx(Instruction::FAdd);
1339 return getSimpleRdx(Instruction::FMul);
1343 return getSimpleRdx(Instruction::Mul);
1345 return getSimpleRdx(Instruction::And);
1347 return getSimpleRdx(Instruction::Or);
1349 return getSimpleRdx(Instruction::Xor);
1367 return getSimpleRdx(Instruction::ICmp);
1372 return getSimpleRdx(Instruction::FCmp);
1383 auto *Intersection = (OpValue ==
nullptr) ? dyn_cast<Instruction>(VL[0])
1387 const unsigned Opcode = Intersection->
getOpcode();
1388 VecOp->copyIRFlags(Intersection);
1389 for (
auto *V : VL) {
1393 if (OpValue ==
nullptr || Opcode == Instr->getOpcode())
Legacy wrapper pass to provide the GlobalsAAResult object.
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
Bitwise or logical XOR of numbers.
static bool isArithmeticRecurrenceKind(RecurrenceKind Kind)
Returns true if the recurrence kind is an arithmetic kind.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
BasicBlock::iterator GetInsertPoint() const
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
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.
InductionDescriptor()=default
Default constructor - creates an invalid induction.
const SCEV * getConstant(ConstantInt *V)
This is the interface for a simple mod/ref and alias analysis over globals.
Min/max implemented in terms of select(cmp()).
unsigned getNumOperands() const
Return number of MDNode operands.
The main scalar evolution driver.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
int getConsecutiveDirection() const
Get the consecutive direction.
A global registry used in conjunction with static constructors to make pluggable components (like tar...
static bool isReductionPHI(PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes)
Returns true if Phi is a reduction in TheLoop.
0 1 0 0 True if ordered and less than
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
LLVM_NODISCARD detail::scope_exit< typename std::decay< Callable >::type > make_scope_exit(Callable &&F)
bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
const Function * getParent() const
Return the enclosing method, or null if none.
MinMaxRecurrenceKind getMinMaxRecurrenceKind()
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an 'unordered' floating point maximum function.
iv Induction Variable Users
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'...
const std::vector< BlockT * > & getBlocks() const
Get a list of the basic blocks which make up this loop.
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
BlockT * getHeader() const
static Instruction * lookThroughAnd(PHINode *Phi, Type *&RT, SmallPtrSetImpl< Instruction * > &Visited, SmallPtrSetImpl< Instruction * > &CI)
Determines if Phi may have been type-promoted.
Type * getPointerElementType() const
static bool isFirstOrderRecurrence(PHINode *Phi, Loop *TheLoop, DenseMap< Instruction *, Instruction * > &SinkAfter, DominatorTree *DT)
Returns true if Phi is a first-order recurrence.
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
bool match(Val *V, const Pattern &P)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
This is the interface for a SCEV-based alias analysis.
void initializeLoopPassPass(PassRegistry &)
Manually defined generic "LoopPass" dependency initialization.
This class represents the LLVM 'select' instruction.
This is the base class for all instructions that perform data casts.
CallInst * CreateFAddReduce(Value *Acc, Value *Src)
Create a vector fadd reduction intrinsic of the source vector.
A Use represents the edge between a Value definition and its users.
Value * createSimpleTargetReduction(IRBuilder<> &B, const TargetTransformInfo *TTI, unsigned Opcode, Value *Src, TargetTransformInfo::ReductionFlags Flags=TargetTransformInfo::ReductionFlags(), ArrayRef< Value * > RedOps=ArrayRef< Value * >())
Create a target reduction of the given vector.
static Constant * get(ArrayRef< Constant * > V)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
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).
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
ConstantInt * getConstIntStepValue() const
SmallVector< Instruction *, 8 > findDefsUsedOutsideOfLoop(Loop *L)
Returns the instructions that use values defined in the loop.
Type * getVectorElementType() const
LLVM_NODISCARD bool empty() const
void getExitBlocks(SmallVectorImpl< BlockT * > &ExitBlocks) const
Return all of the successor blocks of this loop.
CallInst * CreateFPMinReduce(Value *Src, bool NoNaN=false)
Create a vector float min reduction intrinsic of the source vector.
Value * transform(IRBuilder<> &B, Value *Index, ScalarEvolution *SE, const DataLayout &DL) const
Compute the transformed value of Index at offset StartValue using step StepValue. ...
This node represents a polynomial recurrence on the trip count of the specified loop.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
This instruction compares its operands according to the predicate given to the constructor.
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction...
BasicBlock * getSuccessor(unsigned i) const
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
bool hasUnsafeAlgebra() const
Determine whether the unsafe-algebra flag is set.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
static bool areAllUsesIn(Instruction *I, SmallPtrSetImpl< Instruction * > &Set)
Returns true if all uses of the instruction I is within the Set.
const SCEV * getMulExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical multiply expression, or something simpler if possible.
const SCEVAddRecExpr * getAsAddRec(Value *V)
Attempts to produce an AddRecExpr for V by adding additional SCEV predicates.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void propagateIRFlags(Value *I, ArrayRef< Value * > VL, Value *OpValue=nullptr)
Get the intersection (logical and) of all of the potential IR flags of each scalar operation (VL) tha...
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
AnalysisUsage & addPreservedID(const void *ID)
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Not an induction variable.
This POD struct holds information about a potential recurrence operation.
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.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
iterator_range< block_iterator > blocks() const
Pointer induction var. Step = C / sizeof(elem).
const SCEV * getSCEV(Value *V)
Returns the SCEV expression of V, in the context of the current SCEV predicate.
CallInst * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
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.
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Integer induction variable. Step = C.
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
Type * getType() const
Return the LLVM type of this SCEV expression.
Conditional or Unconditional Branch instruction.
Min/max implemented in terms of select(cmp()).
This is an important base class in LLVM.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal) const
Retrieve the raw weight values of a conditional branch or select.
MDNode * getLoopID() const
Return the llvm.loop loop id metadata node for this loop if it is present.
Represent the analysis usage information of a pass.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
Instruction * getUnsafeAlgebraInst()
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Value * expandCodeFor(const SCEV *SH, Type *Ty, Instruction *I)
Insert code to directly compute the specified SCEV expression into the program.
BlockT * getExitingBlock() const
If getExitingBlocks would return exactly one block, return that block.
Value * getOperand(unsigned i) const
bool isCommutative() const
Return true if the instruction is commutative:
Optional< unsigned > getLoopEstimatedTripCount(Loop *L)
Get a loop's estimated trip count based on branch weight metadata.
Type * getSrcTy() const
Return the source type, as a convenience.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
bool empty() const
empty - Check if the array is empty.
bool isPointerTy() const
True if this is an instance of PointerType.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
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.
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
0 0 1 0 True if ordered and greater than
BinaryOps getOpcode() const
StringRef getString() const
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
const MDOperand & getOperand(unsigned I) const
MinMaxRecurrenceKind getMinMaxKind()
CallInst * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
Legacy wrapper pass to provide the SCEVAAResult object.
This is the shared class of boolean and integer constants.
A struct for saving information about induction variables.
Bitwise or logical OR of numbers.
CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
AnalysisUsage & addRequiredID(const void *ID)
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
static bool isFloatingPointRecurrenceKind(RecurrenceKind Kind)
Returns true if the recurrence kind is a floating point kind.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
LLVM_NODISCARD T pop_back_val()
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
pred_range predecessors(BasicBlock *BB)
ConstantInt * getValue() const
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
CallInst * CreateFMulReduce(Value *Acc, Value *Src)
Create a vector fmul reduction intrinsic of the source vector.
Value * createTargetReduction(IRBuilder<> &B, const TargetTransformInfo *TTI, RecurrenceDescriptor &Desc, Value *Src, bool NoNaN=false)
Create a generic target reduction using a recurrence descriptor Desc The target is queried to determi...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static Constant * getRecurrenceIdentity(RecurrenceKind K, Type *Tp)
Returns identity corresponding to the RecurrenceKind.
Value * CreateGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Class for arbitrary precision integers.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
bool isIntegerTy() const
True if this is an instance of IntegerType.
iterator_range< user_iterator > users()
unsigned getVectorNumElements() const
static Value * createMinMaxOp(IRBuilder<> &Builder, MinMaxRecurrenceKind RK, Value *Left, Value *Right)
Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
This class uses information about analyze scalars to rewrite expressions in canonical form...
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
static std::vector< std::string > Flags
CallInst * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
CallInst * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
Captures loop safety information.
This class represents an analyzed expression in the program.
unsigned getNumSuccessors() const
static bool isIntegerRecurrenceKind(RecurrenceKind Kind)
Returns true if the recurrence kind is an integer kind.
Floating point induction variable.
Represents a single loop in the control flow graph.
ScalarEvolution * getSE() const
Returns the ScalarEvolution analysis used.
bool hasOneUse() const
Return true if there is exactly one user of this value.
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass's AnalysisUsage.
CallInst * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const Loop * getLoop() const
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
StringRef getValueAsString() const
Return the attribute's value as a string.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
succ_range successors(BasicBlock *BB)
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
void setFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
bool formDedicatedExitBlocks(Loop *L, DominatorTree *DT, LoopInfo *LI, bool PreserveLCSSA)
Ensure that all exit blocks of the loop are dedicated exits.
const SCEV * getUnknown(Value *V)
The legacy pass manager's analysis pass to compute loop information.
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
This is the interface for LLVM's primary stateless and local alias analysis.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Value * getShuffleReduction(IRBuilder<> &Builder, Value *Src, unsigned Op, RecurrenceDescriptor::MinMaxRecurrenceKind MinMaxKind=RecurrenceDescriptor::MRK_Invalid, ArrayRef< Value * > RedOps=ArrayRef< Value * >())
Generates a vector reduction using shufflevectors to reduce the value.
Legacy analysis pass which computes a DominatorTree.
const SCEV * getAddExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
CallInst * CreateFPMaxReduce(Value *Src, bool NoNaN=false)
Create a vector float max reduction intrinsic of the source vector.
Value * CreateFMul(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
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 Value * addFastMathFlag(Value *V)
Adds a 'fast' flag to floating point operations.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
const BasicBlock * getParent() const
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.
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
RecurrenceKind
This enum represents the kinds of recurrences that we support.
This class represents a constant integer value.
Legacy wrapper pass to provide the BasicAAResult object.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.