53#define DEBUG_TYPE "loop-utils"
68 "Must start with an empty predecessors list!");
73 bool IsDedicatedExit =
true;
75 if (L->contains(PredBB)) {
82 IsDedicatedExit =
false;
85 assert(!InLoopPredecessors.
empty() &&
"Must have *some* loop predecessor!");
92 BB, InLoopPredecessors,
".loopexit", DT, LI, MSSAU, PreserveLCSSA);
96 dbgs() <<
"WARNING: Can't create a dedicated exit block for loop: "
99 LLVM_DEBUG(
dbgs() <<
"LoopSimplify: Creating dedicated exit block "
100 << NewExitBB->getName() <<
"\n");
107 for (
auto *BB : L->blocks())
110 if (L->contains(SuccBB))
114 if (!Visited.
insert(SuccBB).second)
117 Changed |= RewriteExit(SuccBB);
127 for (
auto *
Block : L->getBlocks())
130 for (
auto &Inst : *
Block) {
131 auto Users = Inst.users();
134 return !L->contains(
Use->getParent());
221 for (
unsigned i = 1, ie = LoopID->
getNumOperands(); i < ie; ++i) {
224 if (
Node->getNumOperands() == 2) {
250std::optional<ElementCount>
252 std::optional<int> Width =
257 TheLoop,
"llvm.loop.vectorize.scalable.enable");
266 const char *InheritOptionsExceptPrefix,
bool AlwaysNew) {
275 bool InheritAllAttrs = !InheritOptionsExceptPrefix;
276 bool InheritSomeAttrs =
277 InheritOptionsExceptPrefix && InheritOptionsExceptPrefix[0] !=
'\0';
282 if (InheritAllAttrs || InheritSomeAttrs) {
286 auto InheritThisAttribute = [InheritSomeAttrs,
287 InheritOptionsExceptPrefix](
MDNode *
Op) {
288 if (!InheritSomeAttrs)
292 if (
Op->getNumOperands() == 0)
300 return !AttrName.
starts_with(InheritOptionsExceptPrefix);
303 if (InheritThisAttribute(
Op))
313 bool HasAnyFollowup =
false;
314 for (
StringRef OptionName : FollowupOptions) {
319 HasAnyFollowup =
true;
328 if (!AlwaysNew && !HasAnyFollowup)
342 return FollowupLoopID;
357 std::optional<int>
Count =
378 std::optional<int>
Count =
393 std::optional<bool>
Enable =
399 std::optional<ElementCount> VectorizeWidth =
401 std::optional<int> InterleaveCount =
406 if (
Enable ==
true && VectorizeWidth && VectorizeWidth->isScalar() &&
407 InterleaveCount == 1)
416 if ((VectorizeWidth && VectorizeWidth->isScalar()) && InterleaveCount == 1)
419 if ((VectorizeWidth && VectorizeWidth->isVector()) || InterleaveCount > 1)
452 const Loop *CurLoop) {
461 AddRegionToWorklist(
N);
463 for (
size_t I = 0;
I < Worklist.
size();
I++) {
465 AddRegionToWorklist(Child);
473 assert(LatchIdx != -1 &&
"LatchBlock is not a case in this PHINode");
477 if (U !=
Cond && U != IncV)
return false;
480 if (U !=
Cond && U != PN)
return false;
487 assert((!DT || L->isLCSSAForm(*DT)) &&
"Expected LCSSA!");
488 auto *Preheader = L->getLoopPreheader();
489 assert(Preheader &&
"Preheader should exist!");
491 std::unique_ptr<MemorySSAUpdater> MSSAU;
493 MSSAU = std::make_unique<MemorySSAUpdater>(MSSA);
511 "Preheader must end with a side-effect-free terminator");
513 "Preheader must have a single successor");
541 auto *ExitBlock = L->getUniqueExitBlock();
544 assert(ExitBlock &&
"Should have a unique exit block!");
545 assert(L->hasDedicatedExits() &&
"Loop should have dedicated exits!");
547 Builder.CreateCondBr(Builder.getFalse(), L->getHeader(), ExitBlock);
553 for (
PHINode &
P : ExitBlock->phis()) {
558 P.setIncomingBlock(PredIndex, Preheader);
562 P.removeIncomingValueIf([](
unsigned Idx) {
return Idx != 0; },
565 assert((
P.getNumIncomingValues() == 1 &&
566 P.getIncomingBlock(PredIndex) == Preheader) &&
567 "Should have exactly one value and that's from the preheader!");
581 Builder.SetInsertPoint(Preheader->getTerminator());
582 Builder.CreateBr(ExitBlock);
584 Preheader->getTerminator()->eraseFromParent();
586 assert(L->hasNoExitBlocks() &&
587 "Loop should have either zero or one exit blocks.");
589 Builder.SetInsertPoint(OldTerm);
590 Builder.CreateUnreachable();
591 Preheader->getTerminator()->eraseFromParent();
601 MSSAU->removeBlocks(DeadBlockSet);
620 for (
auto *
Block : L->blocks())
625 if (L->contains(Usr->getParent()))
631 "Unexpected user in reachable block");
641 DVR.getDebugLoc().get());
645 DVR.removeFromParent();
658 ExitBlock->getFirstInsertionPt();
659 assert(InsertDbgValueBefore != ExitBlock->end() &&
660 "There should be a non-PHI instruction in exit block, else these "
661 "instructions will have no parent.");
668 ExitBlock->insertDbgRecordBefore(DVR, InsertDbgValueBefore);
673 for (
auto *
Block : L->blocks())
674 Block->dropAllReferences();
685 BB->eraseFromParent();
698 if (
Loop *ParentLoop = L->getParentLoop()) {
700 assert(
I != ParentLoop->end() &&
"Couldn't find loop");
701 ParentLoop->removeChildLoop(
I);
704 assert(
I != LI->
end() &&
"Couldn't find loop");
713 auto *Latch = L->getLoopLatch();
714 assert(Latch &&
"multiple latches not yet supported");
715 auto *Header = L->getHeader();
716 Loop *OutermostLoop = L->getOutermostLoop();
721 std::unique_ptr<MemorySSAUpdater> MSSAU;
723 MSSAU = std::make_unique<MemorySSAUpdater>(MSSA);
729 if (!BI->isConditional()) {
738 if (L->isLoopExiting(Latch)) {
743 const unsigned ExitIdx = L->contains(BI->getSuccessor(0)) ? 1 : 0;
744 BasicBlock *ExitBB = BI->getSuccessor(ExitIdx);
747 Header->removePredecessor(Latch,
true);
750 auto *NewBI = Builder.CreateBr(ExitBB);
753 NewBI->copyMetadata(*BI, {LLVMContext::MD_dbg,
754 LLVMContext::MD_annotation});
756 BI->eraseFromParent();
767 auto *BackedgeBB =
SplitEdge(Latch, Header, &DT, &LI, MSSAU.get());
771 true, &DTU, MSSAU.get());
783 if (OutermostLoop != L)
797 if (!LatchBR || LatchBR->
getNumSuccessors() != 2 || !L->isLoopExiting(Latch))
802 "At least one edge out of the latch must go to the header");
826 OrigExitWeight = ExitWeight;
833 if (ExitCount >= std::numeric_limits<unsigned>::max())
834 return std::numeric_limits<unsigned>::max();
837 return ExitCount + 1;
840std::optional<unsigned>
842 unsigned *EstimatedLoopInvocationWeight) {
849 if (std::optional<uint64_t> EstTripCount =
851 if (EstimatedLoopInvocationWeight)
852 *EstimatedLoopInvocationWeight = ExitWeight;
853 return *EstTripCount;
860 unsigned EstimatedloopInvocationWeight) {
869 unsigned LatchExitWeight = 0;
870 unsigned BackedgeTakenWeight = 0;
872 if (EstimatedTripCount > 0) {
873 LatchExitWeight = EstimatedloopInvocationWeight;
874 BackedgeTakenWeight = (EstimatedTripCount - 1) * LatchExitWeight;
879 std::swap(BackedgeTakenWeight, LatchExitWeight);
885 LLVMContext::MD_prof,
899 const SCEV *InnerLoopBECountSC = SE.
getExitCount(InnerLoop, InnerLoopLatch);
920 return Intrinsic::vector_reduce_add;
922 return Intrinsic::vector_reduce_mul;
924 return Intrinsic::vector_reduce_and;
926 return Intrinsic::vector_reduce_or;
928 return Intrinsic::vector_reduce_xor;
931 return Intrinsic::vector_reduce_fadd;
933 return Intrinsic::vector_reduce_fmul;
935 return Intrinsic::vector_reduce_smax;
937 return Intrinsic::vector_reduce_smin;
939 return Intrinsic::vector_reduce_umax;
941 return Intrinsic::vector_reduce_umin;
944 return Intrinsic::vector_reduce_fmax;
947 return Intrinsic::vector_reduce_fmin;
949 return Intrinsic::vector_reduce_fmaximum;
951 return Intrinsic::vector_reduce_fminimum;
953 return Intrinsic::vector_reduce_fmax;
955 return Intrinsic::vector_reduce_fmin;
963 case Intrinsic::umin:
964 return Intrinsic::vector_reduce_umin;
965 case Intrinsic::umax:
966 return Intrinsic::vector_reduce_umax;
967 case Intrinsic::smin:
968 return Intrinsic::vector_reduce_smin;
969 case Intrinsic::smax:
970 return Intrinsic::vector_reduce_smax;
977 case Intrinsic::vector_reduce_fadd:
978 return Instruction::FAdd;
979 case Intrinsic::vector_reduce_fmul:
980 return Instruction::FMul;
981 case Intrinsic::vector_reduce_add:
982 return Instruction::Add;
983 case Intrinsic::vector_reduce_mul:
984 return Instruction::Mul;
985 case Intrinsic::vector_reduce_and:
986 return Instruction::And;
987 case Intrinsic::vector_reduce_or:
988 return Instruction::Or;
989 case Intrinsic::vector_reduce_xor:
990 return Instruction::Xor;
991 case Intrinsic::vector_reduce_smax:
992 case Intrinsic::vector_reduce_smin:
993 case Intrinsic::vector_reduce_umax:
994 case Intrinsic::vector_reduce_umin:
995 return Instruction::ICmp;
996 case Intrinsic::vector_reduce_fmax:
997 case Intrinsic::vector_reduce_fmin:
998 return Instruction::FCmp;
1009 case Instruction::Add:
1010 return Intrinsic::vector_reduce_add;
1011 case Instruction::Mul:
1012 return Intrinsic::vector_reduce_mul;
1013 case Instruction::And:
1014 return Intrinsic::vector_reduce_and;
1015 case Instruction::Or:
1016 return Intrinsic::vector_reduce_or;
1017 case Instruction::Xor:
1018 return Intrinsic::vector_reduce_xor;
1027 case Intrinsic::vector_reduce_umin:
1028 return Intrinsic::umin;
1029 case Intrinsic::vector_reduce_umax:
1030 return Intrinsic::umax;
1031 case Intrinsic::vector_reduce_smin:
1032 return Intrinsic::smin;
1033 case Intrinsic::vector_reduce_smax:
1034 return Intrinsic::smax;
1035 case Intrinsic::vector_reduce_fmin:
1036 return Intrinsic::minnum;
1037 case Intrinsic::vector_reduce_fmax:
1038 return Intrinsic::maxnum;
1039 case Intrinsic::vector_reduce_fminimum:
1040 return Intrinsic::minimum;
1041 case Intrinsic::vector_reduce_fmaximum:
1042 return Intrinsic::maximum;
1051 return Intrinsic::umin;
1053 return Intrinsic::umax;
1055 return Intrinsic::smin;
1057 return Intrinsic::smax;
1060 return Intrinsic::minnum;
1063 return Intrinsic::maxnum;
1065 return Intrinsic::minimum;
1067 return Intrinsic::maximum;
1069 return Intrinsic::minimumnum;
1071 return Intrinsic::maximumnum;
1077 case Intrinsic::vector_reduce_smax:
1079 case Intrinsic::vector_reduce_smin:
1081 case Intrinsic::vector_reduce_umax:
1083 case Intrinsic::vector_reduce_umin:
1085 case Intrinsic::vector_reduce_fmax:
1087 case Intrinsic::vector_reduce_fmin:
1119 if (Ty->isIntOrIntVectorTy() ||
1124 return Builder.CreateIntrinsic(Ty, Id, {
Left,
Right},
nullptr,
1128 Value *Cmp = Builder.CreateCmp(Pred,
Left,
Right,
"rdx.minmax.cmp");
1140 Value *Result = Acc;
1141 for (
unsigned ExtractIdx = 0; ExtractIdx != VF; ++ExtractIdx) {
1143 Builder.CreateExtractElement(Src, Builder.getInt32(ExtractIdx));
1145 if (
Op != Instruction::ICmp &&
Op != Instruction::FCmp) {
1168 "Reduction emission only supported for pow2 vectors!");
1176 auto BuildShuffledOp = [&Builder, &
Op,
1178 Value *&TmpVec) ->
void {
1179 Value *Shuf = Builder.CreateShuffleVector(TmpVec, ShuffleMask,
"rdx.shuf");
1180 if (
Op != Instruction::ICmp &&
Op != Instruction::FCmp) {
1190 Value *TmpVec = Src;
1193 for (
unsigned stride = 1; stride < VF; stride <<= 1) {
1196 for (
unsigned j = 0; j < VF; j += stride << 1) {
1197 ShuffleMask[j] = j + stride;
1199 BuildShuffledOp(ShuffleMask, TmpVec);
1203 for (
unsigned i = VF; i != 1; i >>= 1) {
1205 for (
unsigned j = 0; j != i / 2; ++j)
1206 ShuffleMask[j] = i / 2 + j;
1209 std::fill(&ShuffleMask[i / 2], ShuffleMask.end(), -1);
1210 BuildShuffledOp(ShuffleMask, TmpVec);
1214 return Builder.CreateExtractElement(TmpVec, Builder.getInt32(0));
1219 Value *NewVal =
nullptr;
1224 for (
auto *U : OrigPhi->
users()) {
1228 assert(
SI &&
"One user of the original phi should be a select");
1230 if (
SI->getTrueValue() == OrigPhi)
1231 NewVal =
SI->getFalseValue();
1233 assert(
SI->getFalseValue() == OrigPhi &&
1234 "At least one input to the select should be the original Phi");
1235 NewVal =
SI->getTrueValue();
1240 Src->getType()->isVectorTy() ? Builder.CreateOrReduce(Src) : Src;
1244 return Builder.CreateSelect(
AnyOf, NewVal, InitVal,
"rdx.select");
1253 ? (IsMaxRdx ? Builder.CreateIntMaxReduce(Src, IsSigned)
1254 : Builder.CreateIntMinReduce(Src, IsSigned))
1260 return Builder.CreateSelect(Cmp, MaxRdx, Start,
"rdx.select");
1265 bool Negative =
false;
1269 case Intrinsic::vector_reduce_add:
1270 case Intrinsic::vector_reduce_mul:
1271 case Intrinsic::vector_reduce_or:
1272 case Intrinsic::vector_reduce_xor:
1273 case Intrinsic::vector_reduce_and:
1274 case Intrinsic::vector_reduce_fadd:
1275 case Intrinsic::vector_reduce_fmul: {
1278 Flags.noSignedZeros());
1280 case Intrinsic::vector_reduce_umax:
1281 case Intrinsic::vector_reduce_umin:
1282 case Intrinsic::vector_reduce_smin:
1283 case Intrinsic::vector_reduce_smax: {
1287 case Intrinsic::vector_reduce_fmax:
1288 case Intrinsic::vector_reduce_fmaximum:
1291 case Intrinsic::vector_reduce_fmin:
1292 case Intrinsic::vector_reduce_fminimum: {
1293 bool PropagatesNaN = RdxID == Intrinsic::vector_reduce_fminimum ||
1294 RdxID == Intrinsic::vector_reduce_fmaximum;
1296 return (!Flags.noNaNs() && !PropagatesNaN)
1308 "nnan, nsz is expected to be set for FP min/max reduction.");
1316 auto getIdentity = [&]() {
1318 Builder.getFastMathFlags());
1343 return Builder.CreateFAddReduce(getIdentity(), Src);
1345 return Builder.CreateFMulReduce(getIdentity(), Src);
1355 "AnyOf and FindIV reductions are not supported.");
1359 "No VPIntrinsic for this reduction");
1362 Value *
Ops[] = {Iden, Src, Mask, EVL};
1363 return Builder.CreateIntrinsic(EltTy, VPID,
Ops);
1369 "Unexpected reduction kind");
1370 assert(Src->getType()->isVectorTy() &&
"Expected a vector type");
1371 assert(!Start->getType()->isVectorTy() &&
"Expected a scalar type");
1373 return B.CreateFAddReduce(Start, Src);
1380 "Unexpected reduction kind");
1381 assert(Src->getType()->isVectorTy() &&
"Expected a vector type");
1382 assert(!Start->getType()->isVectorTy() &&
"Expected a scalar type");
1387 "No VPIntrinsic for this reduction");
1389 Value *
Ops[] = {Start, Src, Mask, EVL};
1390 return Builder.CreateIntrinsic(EltTy, VPID,
Ops);
1394 bool IncludeWrapFlags) {
1402 const unsigned Opcode = Intersection->getOpcode();
1403 VecOp->copyIRFlags(Intersection, IncludeWrapFlags);
1404 for (
auto *V : VL) {
1408 if (OpValue ==
nullptr || Opcode == Instr->getOpcode())
1409 VecOp->andIRFlags(V);
1473 while (!WorkList.
empty()) {
1476 if (!L->contains(Curr))
1482 for (
const auto *U : Curr->
users()) {
1484 if (Visited.
insert(UI).second)
1510 BasicBlock *Preheader = L->getLoopPreheader();
1520 L->getExitingBlocks(ExitingBlocks);
1522 L->getUniqueExitBlocks(ExitBlocks);
1523 if (ExitBlocks.
size() != 1 || ExitingBlocks.
size() != 1)
1535 for (
const RewritePhi &Phi : RewritePhiSet) {
1536 unsigned i = Phi.Ith;
1537 if (Phi.PN ==
P && (Phi.PN)->getIncomingValue(i) ==
Incoming) {
1545 if (!L->hasLoopInvariantOperands(
I))
1551 for (
auto *BB : L->blocks())
1553 return I.mayHaveSideEffects();
1567 if (!L->getLoopPreheader())
1569 if (Phi->getParent() != L->getHeader())
1581 assert(L->isRecursivelyLCSSAForm(*DT, *LI) &&
1582 "Indvars did not preserve LCSSA!");
1585 L->getUniqueExitBlocks(ExitBlocks);
1609 for (
unsigned i = 0; i != NumPreds; ++i) {
1622 if (!L->contains(Inst))
1639 if (!isa<PHINode>(U) && !isa<BinaryOperator>(U))
1641 BinaryOperator *B = dyn_cast<BinaryOperator>(U);
1642 if (B && B != ID.getInductionBinOp())
1654 PHINode *Phi = dyn_cast<PHINode>(U);
1655 if (Phi != PN && !checkIsIndPhi(Phi, L, SE, ID))
1660 if (
B !=
ID.getInductionBinOp())
1674 !Rewriter.isSafeToExpand(ExitValue)) {
1683 if (AddRec->getLoop() == L)
1684 ExitValue = AddRec->evaluateAtIteration(ExitCount, *SE);
1687 !Rewriter.isSafeToExpand(ExitValue))
1701 bool HighCost = Rewriter.isHighCostExpansion(
1713 &*Inst->
getParent()->getFirstInsertionPt() : Inst;
1714 RewritePhiSet.
emplace_back(PN, i, ExitValue, InsertPt, HighCost);
1725 int NumReplaced = 0;
1728 for (
const RewritePhi &Phi : RewritePhiSet) {
1735 !LoopCanBeDel && Phi.HighCost)
1738 Value *ExitVal = Rewriter.expandCodeFor(
1739 Phi.ExpansionSCEV, Phi.PN->getType(), Phi.ExpansionPoint);
1741 LLVM_DEBUG(
dbgs() <<
"rewriteLoopExitValues: AfterLoopVal = " << *ExitVal
1743 <<
" LoopVal = " << *(Phi.ExpansionPoint) <<
"\n");
1750 if (
auto *EVL = LI->
getLoopFor(ExitInsn->getParent()))
1752 assert(EVL->contains(L) &&
"LCSSA breach detected!");
1780 Rewriter.clearInsertPoint();
1788 assert(UF > 0 &&
"Zero unrolled factor is not supported");
1789 assert(UnrolledLoop != RemainderLoop &&
1790 "Unrolled and Remainder loops are expected to distinct");
1793 unsigned OrigLoopInvocationWeight = 0;
1794 std::optional<unsigned> OrigAverageTripCount =
1796 if (!OrigAverageTripCount)
1800 unsigned UnrolledAverageTripCount = *OrigAverageTripCount / UF;
1802 unsigned RemainderAverageTripCount = *OrigAverageTripCount % UF;
1805 OrigLoopInvocationWeight);
1807 OrigLoopInvocationWeight);
1813template <
typename RangeT>
1823 assert(PreOrderLoops.
empty() &&
"Must start with an empty preorder walk.");
1825 "Must start with an empty preorder walk worklist.");
1829 PreOrderWorklist.
append(L->begin(), L->end());
1831 }
while (!PreOrderWorklist.
empty());
1833 Worklist.
insert(std::move(PreOrderLoops));
1834 PreOrderLoops.
clear();
1838template <
typename RangeT>
1861 PL->addChildLoop(&New);
1898 Value *Start =
nullptr, *End =
nullptr;
1918 const SCEV *Recur = LowAR->getStepRecurrence(SE);
1919 if (Recur == HighAR->getStepRecurrence(SE) &&
1920 HighAR->getLoop() == OuterLoop && LowAR->getLoop() == OuterLoop) {
1925 const SCEV *NewHigh =
1928 LLVM_DEBUG(
dbgs() <<
"LAA: Expanded RT check for range to include "
1929 "outer loop in order to permit hoisting\n");
1939 << *Stride <<
'\n');
1946 Start = Exp.expandCodeFor(
Low, PtrArithTy,
Loc);
1947 End = Exp.expandCodeFor(
High, PtrArithTy,
Loc);
1950 Start = Builder.CreateFreeze(Start, Start->getName() +
".fr");
1951 End = Builder.CreateFreeze(End, End->getName() +
".fr");
1954 Stride ? Exp.expandCodeFor(Stride, Stride->getType(),
Loc) :
nullptr;
1956 return {Start, End, StrideVal};
1968 transform(PointerChecks, std::back_inserter(ChecksWithBounds),
1974 return std::make_pair(
First, Second);
1977 return ChecksWithBounds;
1986 auto ExpandedChecks =
1993 Value *MemoryRuntimeCheck =
nullptr;
1995 for (
const auto &[
A,
B] : ExpandedChecks) {
1999 assert((
A.Start->getType()->getPointerAddressSpace() ==
2000 B.End->getType()->getPointerAddressSpace()) &&
2001 (
B.Start->getType()->getPointerAddressSpace() ==
2002 A.End->getType()->getPointerAddressSpace()) &&
2003 "Trying to bounds check pointers with different address spaces");
2015 Value *IsConflict = ChkBuilder.
CreateAnd(Cmp0, Cmp1,
"found.conflict");
2016 if (
A.StrideToCheck) {
2018 A.StrideToCheck, ConstantInt::get(
A.StrideToCheck->getType(), 0),
2020 IsConflict = ChkBuilder.
CreateOr(IsConflict, IsNegativeStride);
2022 if (
B.StrideToCheck) {
2024 B.StrideToCheck, ConstantInt::get(
B.StrideToCheck->getType(), 0),
2026 IsConflict = ChkBuilder.
CreateOr(IsConflict, IsNegativeStride);
2028 if (MemoryRuntimeCheck) {
2030 ChkBuilder.
CreateOr(MemoryRuntimeCheck, IsConflict,
"conflict.rdx");
2032 MemoryRuntimeCheck = IsConflict;
2035 Exp.eraseDeadInstructions(MemoryRuntimeCheck);
2036 return MemoryRuntimeCheck;
2047 Value *MemoryRuntimeCheck =
nullptr;
2049 auto &SE = *Expander.
getSE();
2053 for (
const auto &[SrcStart, SinkStart, AccessSize, NeedsFreeze] : Checks) {
2054 Type *Ty = SinkStart->getType();
2056 auto *VFTimesICTimesSize =
2057 ChkBuilder.
CreateMul(GetVF(ChkBuilder, Ty->getScalarSizeInBits()),
2058 ConstantInt::get(Ty, IC * AccessSize));
2064 Value *IsConflict = SeenCompares.
lookup({Diff, VFTimesICTimesSize});
2069 ChkBuilder.
CreateICmpULT(Diff, VFTimesICTimesSize,
"diff.check");
2070 SeenCompares.
insert({{Diff, VFTimesICTimesSize}, IsConflict});
2074 if (MemoryRuntimeCheck) {
2076 ChkBuilder.
CreateOr(MemoryRuntimeCheck, IsConflict,
"conflict.rdx");
2078 MemoryRuntimeCheck = IsConflict;
2082 return MemoryRuntimeCheck;
2085std::optional<IVConditionInfo>
2089 if (!TI || !TI->isConditional())
2104 WorkList.
append(CondI->op_begin(), CondI->op_end());
2108 while (!WorkList.
empty()) {
2110 if (!
I || !L.contains(
I))
2119 if (LI->isVolatile() || LI->isAtomic())
2126 AccessesToCheck.
push_back(MemUse->getDefiningAccess());
2134 WorkList.
append(
I->op_begin(),
I->op_end());
2137 if (InstToDuplicate.
empty())
2141 L.getExitingBlocks(ExitingBlocks);
2142 auto HasNoClobbersOnPath =
2143 [&L, &
AA, &AccessedLocs, &ExitingBlocks, &InstToDuplicate,
2146 -> std::optional<IVConditionInfo> {
2158 while (!WorkList.
empty()) {
2160 if (!L.contains(Current))
2162 const auto &SeenIns = Seen.
insert(Current);
2163 if (!SeenIns.second)
2166 Info.PathIsNoop &=
all_of(
2167 *Current, [](
Instruction &
I) {
return !
I.mayHaveSideEffects(); });
2173 if (Seen.
size() < 2)
2181 while (!AccessesToCheck.
empty()) {
2183 auto SeenI = SeenAccesses.
insert(Current);
2200 AA.getModRefInfo(CurrentDef->getMemoryInst(),
Loc));
2205 for (
Use &U : Current->
uses())
2216 if (Info.PathIsNoop) {
2217 for (
auto *Exiting : ExitingBlocks) {
2221 if (L.contains(Succ))
2224 Info.PathIsNoop &= Succ->phis().empty() &&
2225 (!Info.ExitForPath || Info.ExitForPath == Succ);
2226 if (!Info.PathIsNoop)
2228 assert((!Info.ExitForPath || Info.ExitForPath == Succ) &&
2229 "cannot have multiple exit blocks");
2230 Info.ExitForPath = Succ;
2234 if (!Info.ExitForPath)
2235 Info.PathIsNoop =
false;
2237 Info.InstToDuplicate = InstToDuplicate;
2243 if (TI->getSuccessor(0) == TI->getSuccessor(1))
2246 if (
auto Info = HasNoClobbersOnPath(TI->getSuccessor(0), L.getHeader(),
2251 if (
auto Info = HasNoClobbersOnPath(TI->getSuccessor(1), L.getHeader(),
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Register Bank Select
This is the interface for LLVM's primary stateless and local alias analysis.
bbsections Prepares for basic block by splitting functions into clusters of basic blocks
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXPORT_TEMPLATE
This file defines the DenseSet and SmallDenseSet classes.
This is the interface for a simple mod/ref and alias analysis over globals.
static const HTTPClientCleanup Cleanup
Module.h This file contains the declarations for the Module class.
iv Induction Variable Users
static cl::opt< ReplaceExitVal > ReplaceExitValue("replexitval", cl::Hidden, cl::init(OnlyCheapRepl), cl::desc("Choose the strategy to replace exit value in IndVarSimplify"), cl::values(clEnumValN(NeverRepl, "never", "never replace exit value"), clEnumValN(OnlyCheapRepl, "cheap", "only replace exit value when the cost is cheap"), clEnumValN(UnusedIndVarInLoop, "unusedindvarinloop", "only replace exit value when it is an unused " "induction variable in the loop and has cheap replacement cost"), clEnumValN(NoHardUse, "noharduse", "only replace exit values when loop def likely dead"), clEnumValN(AlwaysRepl, "always", "always replace exit value whenever possible")))
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static cl::opt< bool, true > HoistRuntimeChecks("hoist-runtime-checks", cl::Hidden, cl::desc("Hoist inner loop runtime memory checks to outer loop if possible"), cl::location(VectorizerParams::HoistRuntimeChecks), cl::init(true))
static bool hasHardUserWithinLoop(const Loop *L, const Instruction *I)
static const char * LLVMLoopDisableLICM
static PointerBounds expandBounds(const RuntimeCheckingPtrGroup *CG, Loop *TheLoop, Instruction *Loc, SCEVExpander &Exp, bool HoistRuntimeChecks)
Expand code for the lower and upper bound of the pointer group CG in TheLoop.
static bool canLoopBeDeleted(Loop *L, SmallVector< RewritePhi, 8 > &RewritePhiSet)
static const char * LLVMLoopDisableNonforced
static MDNode * createStringMetadata(Loop *TheLoop, StringRef Name, unsigned V)
Create MDNode for input string.
static BranchInst * getExpectedExitLoopLatchBranch(Loop *L)
Checks if L has an exiting latch branch.
static bool checkIsIndPhi(PHINode *Phi, Loop *L, ScalarEvolution *SE, InductionDescriptor &ID)
Checks if it is safe to call InductionDescriptor::isInductionPHI for Phi, and returns true if this Ph...
static std::optional< unsigned > getEstimatedTripCount(BranchInst *ExitingBranch, Loop *L, uint64_t &OrigExitWeight)
Return the estimated trip count for any exiting branch which dominates the loop latch.
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
#define INITIALIZE_PASS_DEPENDENCY(depName)
This file provides a priority worklist.
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
This is the interface for a SCEV-based alias analysis.
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
This file implements a set that has insertion order iteration characteristics.
static cl::opt< unsigned > MSSAThreshold("simple-loop-unswitch-memoryssa-threshold", cl::desc("Max number of memory uses to explore during " "partial unswitching analysis"), cl::init(100), cl::Hidden)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Class for arbitrary precision integers.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Represent the analysis usage information of a pass.
LLVM_ABI AnalysisUsage & addRequiredID(const void *ID)
AnalysisUsage & addPreservedID(const void *ID)
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Legacy wrapper pass to provide the BasicAAResult object.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
InstListType::iterator iterator
Instruction iterators...
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Conditional or Unconditional Branch instruction.
unsigned getNumSuccessors() const
BasicBlock * getSuccessor(unsigned i) const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ ICMP_ULT
unsigned less than
@ ICMP_SGE
signed greater or equal
static LLVM_ABI Constant * getIntrinsicIdentity(Intrinsic::ID, Type *Ty)
static LLVM_ABI Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
static LLVM_ABI Constant * getInfinity(Type *Ty, bool Negative=false)
static LLVM_ABI Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
This is the shared class of boolean and integer constants.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
Record of a variable value-assignment, aka a non instruction representation of the dbg....
Identifies a unique instance of a variable.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
iterator_range< iterator > children()
static constexpr UpdateKind Delete
static constexpr UpdateKind Insert
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Legacy analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Convenience struct for specifying and reasoning about fast-math flags.
bool noSignedZeros() const
void applyUpdates(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
Legacy wrapper pass to provide the GlobalsAAResult object.
Common base class shared among various IRBuilders.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateFreeze(Value *V, const Twine &Name="")
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
A struct for saving information about induction variables.
static LLVM_ABI bool isInductionPHI(PHINode *Phi, const Loop *L, ScalarEvolution *SE, InductionDescriptor &D, const SCEV *Expr=nullptr, SmallVectorImpl< Instruction * > *CastsToIgnore=nullptr)
Returns true if Phi is an induction in the loop L.
InstSimplifyFolder - Use InstructionSimplify to fold operations to existing values.
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
This is an important class for using LLVM in a threaded context.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
BlockT * getHeader() const
std::vector< Loop * >::const_iterator iterator
LoopT * getParentLoop() const
Return the parent loop if it exists or nullptr for top level loops.
void addTopLevelLoop(LoopT *New)
This adds the specified loop to the collection of top-level loops.
void removeBlock(BlockT *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
LoopT * AllocateLoop(ArgsTy &&...Args)
LoopT * removeLoop(iterator I)
This removes the specified top-level loop from this loop info object.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
void destroy(LoopT *L)
Destroy a loop that has been removed from the LoopInfo nest.
The legacy pass manager's analysis pass to compute loop information.
bool replacementPreservesLCSSAForm(Instruction *From, Value *To)
Returns true if replacing From with To everywhere is guaranteed to preserve LCSSA form.
LLVM_ABI void erase(Loop *L)
Update LoopInfo after removing the last backedge from a loop.
Represents a single loop in the control flow graph.
void setLoopID(MDNode *LoopID) const
Set the llvm.loop loop id metadata for this loop.
MDNode * getLoopID() const
Return the llvm.loop loop id metadata node for this loop if it is present.
LLVM_ABI MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
LLVM_ABI void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
const MDOperand & getOperand(unsigned I) const
ArrayRef< MDOperand > operands() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
LLVMContext & getContext() const
Tracking metadata reference owned by Metadata.
LLVM_ABI StringRef getString() const
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
BasicBlock * getBlock() const
Representation for a specific memory location.
static LLVM_ABI MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
Legacy analysis pass which computes MemorySSA.
Encapsulates MemorySSA, including all data associated with memory accesses.
LLVM_ABI void verifyMemorySSA(VerificationLevel=VerificationLevel::Fast) const
Verify that MemorySSA is self consistent (IE definitions dominate all uses, uses appear in the right ...
MemoryUseOrDef * getMemoryAccess(const Instruction *I) const
Given a memory Mod/Ref'ing instruction, get the MemorySSA access associated with it.
void setIncomingValue(unsigned i, Value *V)
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
bool insert(const T &X)
Insert a new element into the PriorityWorklist.
static bool isSignedRecurrenceKind(RecurKind Kind)
Returns true if recurrece kind is a signed redux kind.
static bool isAnyOfRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is of the form select(cmp(),x,y) where one of (x,...
static bool isFindLastIVRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is of the form select(cmp(),x,y) where one of (x,...
static bool isFindIVRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is of the form select(cmp(),x,y) where one of (x,...
static bool isMinMaxRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is any min/max kind.
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Legacy wrapper pass to provide the SCEVAAResult object.
This class uses information about analyze scalars to rewrite expressions in canonical form.
ScalarEvolution * getSE()
LLVM_ABI Value * expandCodeFor(const SCEV *SH, Type *Ty, BasicBlock::iterator I)
Insert code to directly compute the specified SCEV expression into the program.
void eraseDeadInstructions(Value *Root)
Remove inserted instructions that are dead, e.g.
This class represents an analyzed expression in the program.
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
The main scalar evolution driver.
LLVM_ABI bool isKnownNonNegative(const SCEV *S)
Test if the given expression is known to be non-negative.
LLVM_ABI bool isLoopEntryGuardedByCond(const Loop *L, CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
Test whether entry to the loop is protected by a conditional between LHS and RHS.
LLVM_ABI const SCEV * getSCEVAtScope(const SCEV *S, const Loop *L)
Return a SCEV expression for the specified value at the specified scope in the program.
const SCEV * getZero(Type *Ty)
Return a SCEV for the constant 0 of a specific type.
LLVM_ABI const SCEV * getConstant(ConstantInt *V)
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
LLVM_ABI void forgetLoop(const Loop *L)
This method should be called by the client when it has changed a loop in a way that may effect Scalar...
LLVM_ABI bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
LLVM_ABI LoopDisposition getLoopDisposition(const SCEV *S, const Loop *L)
Return the "disposition" of the given SCEV with respect to the given loop.
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
LLVM_ABI void forgetValue(Value *V)
This method should be called by the client when it has changed a value in a way that may effect its v...
LLVM_ABI void forgetBlockAndLoopDispositions(Value *V=nullptr)
Called when the client has changed the disposition of values in a loop or block.
LoopDisposition
An enum describing the relationship between a SCEV and a loop.
@ LoopInvariant
The SCEV is loop-invariant.
LLVM_ABI bool isAvailableAtLoopEntry(const SCEV *S, const Loop *L)
Determine if the SCEV can be evaluated at loop's entry.
LLVM_ABI const SCEV * getExitCount(const Loop *L, const BasicBlock *ExitingBlock, ExitCountKind Kind=Exact)
Return the number of times the backedge executes before the given exit would be taken; if not exactly...
LLVM_ABI const SCEV * applyLoopGuards(const SCEV *Expr, const Loop *L)
Try to apply information from loop guards for L to Expr.
This class represents the LLVM 'select' instruction.
Implements a dense probed hash-table based set with some number of buckets stored inline.
A version of PriorityWorklist that selects small size optimized data structures for the vector and ma...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Provides information about what library functions are available for the current target.
Value handle that tracks a Value across RAUW.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
A Use represents the edge between a Value definition and its users.
static LLVM_ABI Intrinsic::ID getForIntrinsic(Intrinsic::ID Id)
The llvm.vp.
static LLVM_ABI bool isVPReduction(Intrinsic::ID ID)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< use_iterator > uses()
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
std::pair< iterator, bool > insert(const ValueT &V)
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Abstract Attribute helper functions.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
LLVM_ABI Value * createSimpleReduction(IRBuilderBase &B, Value *Src, RecurKind RdxKind)
Create a reduction of the given vector.
LLVM_ABI std::optional< ElementCount > getOptionalElementCountLoopAttribute(const Loop *TheLoop)
Find a combination of metadata ("llvm.loop.vectorize.width" and "llvm.loop.vectorize....
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
LLVM_ABI Value * addRuntimeChecks(Instruction *Loc, Loop *TheLoop, const SmallVectorImpl< RuntimePointerCheck > &PointerChecks, SCEVExpander &Expander, bool HoistRuntimeChecks=false)
Add code that checks at runtime if the accessed arrays in PointerChecks overlap.
LLVM_ABI Value * createFindLastIVReduction(IRBuilderBase &B, Value *Src, RecurKind RdxKind, Value *Start, Value *Sentinel)
Create a reduction of the given vector Src for a reduction of the kind RecurKind::FindLastIV.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI std::optional< unsigned > getLoopEstimatedTripCount(Loop *L, unsigned *EstimatedLoopInvocationWeight=nullptr)
Returns a loop's estimated trip count based on branch weight metadata.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Intrinsic::ID getMinMaxReductionIntrinsicOp(Intrinsic::ID RdxID)
Returns the min/max intrinsic used when expanding a min/max reduction.
LLVM_ABI bool getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name)
Returns true if Name is applied to TheLoop and enabled.
std::pair< const RuntimeCheckingPtrGroup *, const RuntimeCheckingPtrGroup * > RuntimePointerCheck
A memcheck which made up of a pair of grouped pointers.
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
LLVM_ABI bool isKnownNonPositiveInLoop(const SCEV *S, const Loop *L, ScalarEvolution &SE)
Returns true if we can prove that S is defined and always non-positive in loop L.
LLVM_ABI std::optional< bool > getOptionalBoolLoopAttribute(const Loop *TheLoop, StringRef Name)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void appendReversedLoopsToWorklist(RangeT &&, SmallPriorityWorklist< Loop *, 4 > &)
Utility that implements appending of loops onto a worklist given a range.
auto successors(const MachineBasicBlock *BB)
LLVM_ABI void initializeLoopPassPass(PassRegistry &)
Manually defined generic "LoopPass" dependency initialization.
constexpr from_range_t from_range
LLVM_ABI bool formLCSSARecursively(Loop &L, const DominatorTree &DT, const LoopInfo *LI, ScalarEvolution *SE)
Put a loop nest into LCSSA form.
LLVM_ABI Value * getReductionIdentity(Intrinsic::ID RdxID, Type *Ty, FastMathFlags FMF)
Given information about an @llvm.vector.reduce.
LLVM_ABI std::optional< MDNode * > makeFollowupLoopID(MDNode *OrigLoopID, ArrayRef< StringRef > FollowupAttrs, const char *InheritOptionsAttrsPrefix="", bool AlwaysNew=false)
Create a new loop identifier for a loop created from a loop transformation.
LLVM_ABI unsigned getArithmeticReductionInstruction(Intrinsic::ID RdxID)
Returns the arithmetic instruction opcode used when expanding a reduction.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI char & LoopSimplifyID
LLVM_ABI Value * createMinMaxOp(IRBuilderBase &Builder, RecurKind RK, Value *Left, Value *Right)
Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
LLVM_ABI SmallVector< BasicBlock *, 16 > collectChildrenInLoop(DominatorTree *DT, DomTreeNode *N, const Loop *CurLoop)
Does a BFS from a given node to all of its children inside a given loop.
LLVM_ABI void addStringMetadataToLoop(Loop *TheLoop, const char *MDString, unsigned V=0)
Set input string into loop metadata by keeping other values intact.
LLVM_ABI bool cannotBeMaxInLoop(const SCEV *S, const Loop *L, ScalarEvolution &SE, bool Signed)
Returns true if S is defined and never is equal to signed/unsigned max.
DomTreeNodeBase< BasicBlock > DomTreeNode
constexpr T divideNearest(U Numerator, V Denominator)
Returns (Numerator / Denominator) rounded by round-half-up.
LLVM_ABI TransformationMode hasVectorizeTransformation(const Loop *L)
auto dyn_cast_or_null(const Y &Val)
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
LLVM_ABI SmallVector< Instruction *, 8 > findDefsUsedOutsideOfLoop(Loop *L)
Returns the instructions that use values defined in the loop.
auto reverse(ContainerTy &&C)
LLVM_ABI constexpr Intrinsic::ID getReductionIntrinsicID(RecurKind RK)
Returns the llvm.vector.reduce intrinsic that corresponds to the recurrence kind.
LLVM_ABI bool isMustProgress(const Loop *L)
Return true if this loop can be assumed to make progress.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
bool isModSet(const ModRefInfo MRI)
LLVM_ABI TransformationMode hasUnrollAndJamTransformation(const Loop *L)
LLVM_ABI void deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE, LoopInfo *LI, MemorySSA *MSSA=nullptr)
This function deletes dead loops.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI bool hasDisableAllTransformsHint(const Loop *L)
Look for the loop attribute that disables all transformation heuristic.
LLVM_TEMPLATE_ABI void appendLoopsToWorklist(RangeT &&, SmallPriorityWorklist< Loop *, 4 > &)
Utility that implements appending of loops onto a worklist given a range.
LLVM_ABI cl::opt< unsigned > SCEVCheapExpansionBudget
FunctionAddr VTableAddr Count
LLVM_ABI Value * getShuffleReduction(IRBuilderBase &Builder, Value *Src, unsigned Op, TargetTransformInfo::ReductionShuffle RS, RecurKind MinMaxKind=RecurKind::None)
Generates a vector reduction using shufflevectors to reduce the value.
LLVM_ABI TransformationMode hasUnrollTransformation(const Loop *L)
LLVM_ABI TransformationMode hasDistributeTransformation(const Loop *L)
LLVM_ABI void breakLoopBackedge(Loop *L, DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI, MemorySSA *MSSA)
Remove the backedge of the specified loop.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass's AnalysisUsage.
LLVM_ABI void propagateIRFlags(Value *I, ArrayRef< Value * > VL, Value *OpValue=nullptr, bool IncludeWrapFlags=true)
Get the intersection (logical and) of all of the potential IR flags of each scalar operation (VL) tha...
LLVM_ABI bool isKnownPositiveInLoop(const SCEV *S, const Loop *L, ScalarEvolution &SE)
Returns true if we can prove that S is defined and always positive in loop L.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
LLVM_ABI unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
LLVM_ABI std::optional< int > getOptionalIntLoopAttribute(const Loop *TheLoop, StringRef Name)
Find named metadata for a loop with an integer value.
LLVM_ABI BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
LLVM_ABI CmpInst::Predicate getMinMaxReductionPredicate(RecurKind RK)
Returns the comparison predicate used when expanding a min/max reduction.
LLVM_ABI TransformationMode hasLICMVersioningTransformation(const Loop *L)
LLVM_ABI bool VerifyMemorySSA
Enables verification of MemorySSA.
TransformationMode
The mode sets how eager a transformation should be applied.
@ TM_Unspecified
The pass can use heuristics to determine whether a transformation should be applied.
@ TM_SuppressedByUser
The transformation must not be applied.
@ TM_ForcedByUser
The transformation was directed by the user, e.g.
@ TM_Disable
The transformation should not be applied.
@ TM_Enable
The transformation should be applied without considering a cost model.
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
LLVM_ABI bool hasDisableLICMTransformsHint(const Loop *L)
Look for the loop attribute that disables the LICM transformation heuristics.
template LLVM_TEMPLATE_ABI void appendLoopsToWorklist< Loop & >(Loop &L, SmallPriorityWorklist< Loop *, 4 > &Worklist)
LLVM_ABI Intrinsic::ID getReductionForBinop(Instruction::BinaryOps Opc)
Returns the reduction intrinsic id corresponding to the binary operation.
RecurKind
These are the kinds of recurrences that we support.
@ UMin
Unsigned integer min implemented in terms of select(cmp()).
@ FMinimumNum
FP min with llvm.minimumnum semantics.
@ Or
Bitwise or logical OR of integers.
@ FMinimum
FP min with llvm.minimum semantics.
@ FMaxNum
FP max with llvm.maxnum semantics including NaNs.
@ Mul
Product of integers.
@ AnyOf
AnyOf reduction with select(cmp(),x,y) where one of (x,y) is loop invariant, and both x and y are int...
@ Xor
Bitwise or logical XOR of integers.
@ FMax
FP max implemented in terms of select(cmp()).
@ FMaximum
FP max with llvm.maximum semantics.
@ FMulAdd
Sum of float products with llvm.fmuladd(a * b + sum).
@ SMax
Signed integer max implemented in terms of select(cmp()).
@ And
Bitwise or logical AND of integers.
@ SMin
Signed integer min implemented in terms of select(cmp()).
@ FMin
FP min implemented in terms of select(cmp()).
@ FMinNum
FP min with llvm.minnum semantics including NaNs.
@ Sub
Subtraction of integers.
@ AddChainWithSubs
A chain of adds and subs.
@ FMaximumNum
FP max with llvm.maximumnum semantics.
@ UMax
Unsigned integer max implemented in terms of select(cmp()).
LLVM_ABI bool setLoopEstimatedTripCount(Loop *L, unsigned EstimatedTripCount, unsigned EstimatedLoopInvocationWeight)
Set a loop's branch weight metadata to reflect that loop has EstimatedTripCount iterations and Estima...
LLVM_ABI Value * getRecurrenceIdentity(RecurKind K, Type *Tp, FastMathFlags FMF)
Given information about an recurrence kind, return the identity for the @llvm.vector....
LLVM_ABI void setProfileInfoAfterUnrolling(Loop *OrigLoop, Loop *UnrolledLoop, Loop *RemainderLoop, uint64_t UF)
Set weights for UnrolledLoop and RemainderLoop based on weights for OrigLoop and the following distri...
LLVM_ABI bool formDedicatedExitBlocks(Loop *L, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
Ensure that all exit blocks of the loop are dedicated exits.
DWARFExpression::Operation Op
LLVM_ABI bool isKnownNegativeInLoop(const SCEV *S, const Loop *L, ScalarEvolution &SE)
Returns true if we can prove that S is defined and always negative in loop L.
constexpr unsigned BitWidth
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
LLVM_ABI bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
LLVM_ABI bool hasIterationCountInvariantInParent(Loop *L, ScalarEvolution &SE)
Check inner loop (L) backedge count is known to be invariant on all iterations of its outer loop.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool isAlmostDeadIV(PHINode *IV, BasicBlock *LatchBlock, Value *Cond)
Return true if the induction variable IV in a Loop whose latch is LatchBlock would become dead if the...
auto predecessors(const MachineBasicBlock *BB)
LLVM_ABI int rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI, ScalarEvolution *SE, const TargetTransformInfo *TTI, SCEVExpander &Rewriter, DominatorTree *DT, ReplaceExitVal ReplaceExitValue, SmallVector< WeakTrackingVH, 16 > &DeadInsts)
If the final value of any expressions that are recurrent in the loop can be computed,...
LLVM_ABI Value * createOrderedReduction(IRBuilderBase &B, RecurKind RdxKind, Value *Src, Value *Start)
Create an ordered reduction intrinsic using the given recurrence kind RdxKind.
LLVM_ABI Value * addDiffRuntimeChecks(Instruction *Loc, ArrayRef< PointerDiffInfo > Checks, SCEVExpander &Expander, function_ref< Value *(IRBuilderBase &, unsigned)> GetVF, unsigned IC)
LLVM_ABI RecurKind getMinMaxReductionRecurKind(Intrinsic::ID RdxID)
Returns the recurence kind used when expanding a min/max reduction.
LLVM_ABI BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the edge connecting the specified blocks, and return the newly created basic block between From...
LLVM_ABI std::optional< IVConditionInfo > hasPartialIVCondition(const Loop &L, unsigned MSSAThreshold, const MemorySSA &MSSA, AAResults &AA)
Check if the loop header has a conditional branch that is not loop-invariant, because it involves loa...
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
LLVM_ABI Value * createAnyOfReduction(IRBuilderBase &B, Value *Src, Value *InitVal, PHINode *OrigPhi)
Create a reduction of the given vector Src for a reduction of kind RecurKind::AnyOf.
LLVM_ABI bool cannotBeMinInLoop(const SCEV *S, const Loop *L, ScalarEvolution &SE, bool Signed)
Returns true if S is defined and never is equal to signed/unsigned min.
LLVM_ABI bool isKnownNonNegativeInLoop(const SCEV *S, const Loop *L, ScalarEvolution &SE)
Returns true if we can prove that S is defined and always non-negative in loop L.
LLVM_ABI Value * getOrderedReduction(IRBuilderBase &Builder, Value *Acc, Value *Src, unsigned Op, RecurKind MinMaxKind=RecurKind::None)
Generates an ordered vector reduction using extracts to reduce the value.
LLVM_ABI MDNode * findOptionMDForLoopID(MDNode *LoopID, StringRef Name)
Find and return the loop attribute node for the attribute Name in LoopID.
LLVM_ABI Intrinsic::ID getMinMaxReductionIntrinsicID(Intrinsic::ID IID)
Returns the llvm.vector.reduce min/max intrinsic that corresponds to the intrinsic op.
LLVM_ABI Loop * cloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM, LoopInfo *LI, LPPassManager *LPM)
Recursively clone the specified loop and all of its children, mapping the blocks with the specified m...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
IR Values for the lower and upper bounds of a pointer evolution.
TrackingVH< Value > Start
RewritePhi(PHINode *P, unsigned I, const SCEV *Val, Instruction *ExpansionPt, bool H)
const SCEV * ExpansionSCEV
Instruction * ExpansionPoint
Struct to hold information about a partially invariant condition.
Incoming for lane maks phi as machine instruction, incoming register Reg and incoming block Block are...
unsigned AddressSpace
Address space of the involved pointers.
bool NeedsFreeze
Whether the pointer needs to be frozen after expansion, e.g.
const SCEV * High
The SCEV expression which represents the upper bound of all the pointers in this group.
const SCEV * Low
The SCEV expression which represents the lower bound of all the pointers in this group.