53#define DEBUG_TYPE "loop-interchange"
55STATISTIC(LoopsInterchanged,
"Number of loops interchanged");
59 cl::desc(
"Interchange if you gain more than this number"));
65 "Maximum number of load-store instructions that should be handled "
66 "in the dependency matrix. Higher value may lead to more interchanges "
67 "at the cost of compile-time"));
81using CharMatrix = std::vector<std::vector<char>>;
96 cl::desc(
"Minimum depth of loop nest considered for the transform"));
101 cl::desc(
"Maximum depth of loop nest considered for the transform"));
107 cl::desc(
"List of profitability heuristics to be used. They are applied in "
110 RuleTy::PerInstrOrderCost,
111 RuleTy::ForVectorization}),
113 "Prioritize loop cache cost"),
114 clEnumValN(RuleTy::PerInstrOrderCost,
"instorder",
115 "Prioritize the IVs order of each instruction"),
116 clEnumValN(RuleTy::ForVectorization,
"vectorize",
117 "Prioritize vectorization"),
119 "Ignore profitability, force interchange (does not "
120 "work with other options)")));
125 for (RuleTy Rule : Rules) {
126 if (!Set.insert(Rule).second)
128 if (Rule == RuleTy::Ignore)
135 for (
auto &Row : DepMatrix) {
148 assert(Src->getParent() == Dst->getParent() && Src != Dst &&
149 "Expected Src and Dst to be different instructions in the same BB");
151 bool FoundSrc =
false;
171 ValueVector MemInstr;
182 MemInstr.push_back(&
I);
186 MemInstr.push_back(&
I);
192 <<
" Loads and Stores to analyze\n");
198 L->getStartLoc(), L->getHeader())
199 <<
"Number of loads/stores exceeded, the supported maximum "
200 "can be increased with option "
201 "-loop-interchange-maxmeminstr-count.";
205 ValueVector::iterator
I, IE, J, JE;
211 for (
I = MemInstr.begin(), IE = MemInstr.end();
I != IE; ++
I) {
212 for (J =
I, JE = MemInstr.end(); J != JE; ++J) {
213 std::vector<char> Dep;
220 if (
auto D = DI->
depends(Src, Dst)) {
221 assert(
D->isOrdered() &&
"Expected an output, flow or anti dep.");
224 if (
D->normalize(SE))
227 D->isFlow() ?
"flow" :
D->isAnti() ?
"anti" :
"output";
228 dbgs() <<
"Found " << DepType
229 <<
" dependency between Src and Dst\n"
230 <<
" Src:" << *Src <<
"\n Dst:" << *Dst <<
'\n');
231 unsigned Levels =
D->getLevels();
233 for (
unsigned II = 1;
II <= Levels; ++
II) {
240 unsigned Dir =
D->getDirection(
II);
254 if (
D->isConfused()) {
255 assert(Dep.empty() &&
"Expected empty dependency vector");
256 Dep.assign(Level,
'*');
259 while (Dep.size() != Level) {
265 if (
all_of(Dep, [](
char C) {
return C ==
'*'; })) {
268 L->getStartLoc(), L->getHeader())
269 <<
"All loops have dependencies in all directions.";
275 bool IsKnownForward =
true;
276 if (Src->getParent() != Dst->getParent()) {
280 IsKnownForward =
false;
286 "Unexpected instructions");
291 bool IsReversed =
D->getSrc() != Src;
293 IsKnownForward =
false;
309 DepMatrix.push_back(Dep);
316 DepMatrix[Ite->second].back() =
'*';
328 for (
auto &Row : DepMatrix)
337static std::optional<bool>
350 unsigned InnerLoopId,
351 unsigned OuterLoopId) {
352 unsigned NumRows = DepMatrix.size();
353 std::vector<char> Cur;
355 for (
unsigned Row = 0; Row < NumRows; ++Row) {
358 Cur = DepMatrix[Row];
371 std::swap(Cur[InnerLoopId], Cur[OuterLoopId]);
380 << L.getHeader()->getParent()->getName() <<
" Loop: %"
381 << L.getHeader()->getName() <<
'\n');
382 assert(LoopList.empty() &&
"LoopList should initially be empty!");
383 Loop *CurrentLoop = &L;
384 const std::vector<Loop *> *Vec = &CurrentLoop->
getSubLoops();
385 while (!Vec->empty()) {
389 if (Vec->size() != 1) {
394 LoopList.push_back(CurrentLoop);
395 CurrentLoop = Vec->front();
398 LoopList.push_back(CurrentLoop);
403 unsigned LoopNestDepth = LoopList.
size();
405 LLVM_DEBUG(
dbgs() <<
"Unsupported depth of loop nest " << LoopNestDepth
413 <<
"Unsupported depth of loop nest, the supported range is ["
424 for (
Loop *L : LoopList) {
430 if (L->getNumBackEdges() != 1) {
434 if (!L->getExitingBlock()) {
445class LoopInterchangeLegality {
447 LoopInterchangeLegality(Loop *Outer, Loop *Inner, ScalarEvolution *SE,
448 OptimizationRemarkEmitter *ORE)
449 : OuterLoop(
Outer), InnerLoop(Inner), SE(SE), ORE(ORE) {}
452 bool canInterchangeLoops(
unsigned InnerLoopId,
unsigned OuterLoopId,
453 CharMatrix &DepMatrix);
457 bool findInductions(Loop *L, SmallVectorImpl<PHINode *> &Inductions);
461 bool isLoopStructureUnderstood();
463 bool currentLimitations();
465 const SmallPtrSetImpl<PHINode *> &getOuterInnerReductions()
const {
466 return OuterInnerReductions;
470 return InnerLoopInductions;
474 return HasNoWrapReductions;
478 bool tightlyNested(Loop *Outer, Loop *Inner);
479 bool containsUnsafeInstructions(BasicBlock *BB);
485 bool findInductionAndReductions(Loop *L,
495 OptimizationRemarkEmitter *ORE;
499 SmallPtrSet<PHINode *, 4> OuterInnerReductions;
507 SmallVector<Instruction *, 4> HasNoWrapReductions;
513class CacheCostManager {
515 LoopStandardAnalysisResults *AR;
520 std::optional<std::unique_ptr<CacheCost>> CC;
524 DenseMap<const Loop *, unsigned> CostMap;
526 void computeIfUnitinialized();
529 CacheCostManager(Loop *OutermostLoop, LoopStandardAnalysisResults *AR,
531 : OutermostLoop(OutermostLoop), AR(AR), DI(DI) {}
532 CacheCost *getCacheCost();
533 const DenseMap<const Loop *, unsigned> &getCostMap();
538class LoopInterchangeProfitability {
540 LoopInterchangeProfitability(Loop *Outer, Loop *Inner, ScalarEvolution *SE,
541 OptimizationRemarkEmitter *ORE)
542 : OuterLoop(
Outer), InnerLoop(Inner), SE(SE), ORE(ORE) {}
545 bool isProfitable(
const Loop *InnerLoop,
const Loop *OuterLoop,
546 unsigned InnerLoopId,
unsigned OuterLoopId,
547 CharMatrix &DepMatrix, CacheCostManager &CCM);
550 int getInstrOrderCost();
551 std::optional<bool> isProfitablePerLoopCacheAnalysis(
552 const DenseMap<const Loop *, unsigned> &CostMap, CacheCost *CC);
553 std::optional<bool> isProfitablePerInstrOrderCost();
554 std::optional<bool> isProfitableForVectorization(
unsigned InnerLoopId,
555 unsigned OuterLoopId,
556 CharMatrix &DepMatrix);
564 OptimizationRemarkEmitter *ORE;
568class LoopInterchangeTransform {
570 LoopInterchangeTransform(Loop *Outer, Loop *Inner, ScalarEvolution *SE,
571 LoopInfo *LI, DominatorTree *DT,
572 const LoopInterchangeLegality &LIL)
573 : OuterLoop(
Outer), InnerLoop(Inner), SE(SE), LI(LI), DT(DT), LIL(LIL) {}
577 void restructureLoops(Loop *NewInner, Loop *NewOuter,
578 BasicBlock *OrigInnerPreHeader,
579 BasicBlock *OrigOuterPreHeader);
580 void removeChildLoop(Loop *OuterLoop, Loop *InnerLoop);
583 bool adjustLoopLinks();
584 bool adjustLoopBranches();
595 const LoopInterchangeLegality &LIL;
598struct LoopInterchange {
599 ScalarEvolution *SE =
nullptr;
600 LoopInfo *LI =
nullptr;
601 DependenceInfo *DI =
nullptr;
602 DominatorTree *DT =
nullptr;
603 LoopStandardAnalysisResults *AR =
nullptr;
606 OptimizationRemarkEmitter *ORE;
608 LoopInterchange(ScalarEvolution *SE, LoopInfo *LI, DependenceInfo *DI,
609 DominatorTree *DT, LoopStandardAnalysisResults *AR,
610 OptimizationRemarkEmitter *ORE)
611 : SE(SE), LI(LI), DI(DI), DT(DT), AR(AR), ORE(ORE) {}
614 if (
L->getParentLoop())
616 SmallVector<Loop *, 8> LoopList;
618 return processLoopList(LoopList);
621 bool run(LoopNest &LN) {
622 SmallVector<Loop *, 8> LoopList(LN.
getLoops());
623 for (
unsigned I = 1;
I < LoopList.size(); ++
I)
624 if (LoopList[
I]->getParentLoop() != LoopList[
I - 1])
626 return processLoopList(LoopList);
632 return LoopList.
size() - 1;
635 bool processLoopList(SmallVectorImpl<Loop *> &LoopList) {
640 "Unsupported depth of loop nest.");
642 unsigned LoopNestDepth = LoopList.
size();
644 LLVM_DEBUG(
dbgs() <<
"Processing LoopList of size = " << LoopNestDepth
647 CharMatrix DependencyMatrix;
648 Loop *OuterMostLoop = *(LoopList.
begin());
650 OuterMostLoop, DI, SE, ORE)) {
665 unsigned SelecLoopId = selectLoopForInterchange(LoopList);
666 CacheCostManager CCM(LoopList[0], AR, DI);
671 for (
unsigned j = SelecLoopId;
j > 0;
j--) {
672 bool ChangedPerIter =
false;
673 for (
unsigned i = SelecLoopId; i > SelecLoopId -
j; i--) {
675 processLoop(LoopList, i, i - 1, DependencyMatrix, CCM);
676 ChangedPerIter |= Interchanged;
687 bool processLoop(SmallVectorImpl<Loop *> &LoopList,
unsigned InnerLoopId,
688 unsigned OuterLoopId,
689 std::vector<std::vector<char>> &DependencyMatrix,
690 CacheCostManager &CCM) {
691 Loop *OuterLoop = LoopList[OuterLoopId];
692 Loop *InnerLoop = LoopList[InnerLoopId];
694 <<
" and OuterLoopId = " << OuterLoopId <<
"\n");
695 LoopInterchangeLegality LIL(OuterLoop, InnerLoop, SE, ORE);
696 if (!LIL.canInterchangeLoops(InnerLoopId, OuterLoopId, DependencyMatrix)) {
697 LLVM_DEBUG(
dbgs() <<
"Not interchanging loops. Cannot prove legality.\n");
701 LoopInterchangeProfitability LIP(OuterLoop, InnerLoop, SE, ORE);
702 if (!LIP.isProfitable(InnerLoop, OuterLoop, InnerLoopId, OuterLoopId,
703 DependencyMatrix, CCM)) {
709 return OptimizationRemark(
DEBUG_TYPE,
"Interchanged",
712 <<
"Loop interchanged with enclosing loop.";
715 LoopInterchangeTransform LIT(OuterLoop, InnerLoop, SE, LI, DT, LIL);
716 LIT.transform(LIL.getHasNoWrapReductions());
723 std::swap(LoopList[OuterLoopId], LoopList[InnerLoopId]);
736bool LoopInterchangeLegality::containsUnsafeInstructions(
BasicBlock *BB) {
737 return any_of(*BB, [](
const Instruction &
I) {
738 return I.mayHaveSideEffects() ||
I.mayReadFromMemory();
742bool LoopInterchangeLegality::tightlyNested(Loop *OuterLoop, Loop *InnerLoop) {
752 BranchInst *OuterLoopHeaderBI =
754 if (!OuterLoopHeaderBI)
757 for (BasicBlock *Succ :
successors(OuterLoopHeaderBI))
758 if (Succ != InnerLoopPreHeader && Succ != InnerLoop->
getHeader() &&
759 Succ != OuterLoopLatch)
762 LLVM_DEBUG(
dbgs() <<
"Checking instructions in Loop header and Loop latch\n");
765 if (containsUnsafeInstructions(OuterLoopHeader) ||
766 containsUnsafeInstructions(OuterLoopLatch))
772 if (InnerLoopPreHeader != OuterLoopHeader &&
773 containsUnsafeInstructions(InnerLoopPreHeader))
781 if (&SuccInner != OuterLoopLatch) {
783 <<
" does not lead to the outer loop latch.\n";);
789 if (containsUnsafeInstructions(InnerLoopExit))
797bool LoopInterchangeLegality::isLoopStructureUnderstood() {
799 for (PHINode *InnerInduction : InnerLoopInductions) {
800 unsigned Num = InnerInduction->getNumOperands();
801 for (
unsigned i = 0; i < Num; ++i) {
802 Value *Val = InnerInduction->getOperand(i);
812 if (InnerInduction->getIncomingBlock(IncomBlockIndx) ==
813 InnerLoopPreheader &&
827 BranchInst *InnerLoopLatchBI =
831 if (CmpInst *InnerLoopCmp =
833 Value *Op0 = InnerLoopCmp->getOperand(0);
834 Value *Op1 = InnerLoopCmp->getOperand(1);
845 std::function<bool(
Value *)> IsPathToInnerIndVar;
846 IsPathToInnerIndVar = [
this, &IsPathToInnerIndVar](
const Value *
V) ->
bool {
855 return IsPathToInnerIndVar(
I->getOperand(0));
857 return IsPathToInnerIndVar(
I->getOperand(0)) &&
858 IsPathToInnerIndVar(
I->getOperand(1));
864 if (IsPathToInnerIndVar(Op0) && IsPathToInnerIndVar(Op1))
872 }
else if (IsPathToInnerIndVar(Op1) && !
isa<Constant>(Op1)) {
895 if (
PHI->getNumIncomingValues() != 1)
910 if (
PHI->getNumIncomingValues() == 1)
962 assert(
I->getOpcode() == OpCode &&
963 "Expected the instruction to be the reduction operation");
968 if (
I->hasNoSignedWrap() ||
I->hasNoUnsignedWrap())
985bool LoopInterchangeLegality::findInductionAndReductions(
987 if (!
L->getLoopLatch() || !
L->getLoopPredecessor())
989 for (PHINode &
PHI :
L->getHeader()->phis()) {
990 InductionDescriptor
ID;
997 if (!OuterInnerReductions.count(&
PHI)) {
999 "across the outer loop.\n");
1003 assert(
PHI.getNumIncomingValues() == 2 &&
1004 "Phis in loop header should have exactly 2 incoming values");
1008 PHINode *InnerRedPhi =
1014 <<
"Failed to recognize PHI as an induction or reduction.\n");
1017 OuterInnerReductions.insert(&
PHI);
1018 OuterInnerReductions.insert(InnerRedPhi);
1027bool LoopInterchangeLegality::currentLimitations() {
1037 dbgs() <<
"Loops where the latch is not the exiting block are not"
1038 <<
" supported currently.\n");
1040 return OptimizationRemarkMissed(
DEBUG_TYPE,
"ExitingNotLatch",
1043 <<
"Loops where the latch is not the exiting block cannot be"
1044 " interchange currently.";
1050 if (!findInductionAndReductions(OuterLoop, Inductions, InnerLoop)) {
1052 dbgs() <<
"Only outer loops with induction or reduction PHI nodes "
1053 <<
"are supported currently.\n");
1055 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UnsupportedPHIOuter",
1058 <<
"Only outer loops with induction or reduction PHI nodes can be"
1059 " interchanged currently.";
1068 Loop *CurLevelLoop = OuterLoop;
1071 CurLevelLoop = CurLevelLoop->
getSubLoops().front();
1072 if (!findInductionAndReductions(CurLevelLoop, Inductions,
nullptr)) {
1074 dbgs() <<
"Only inner loops with induction or reduction PHI nodes "
1075 <<
"are supported currently.\n");
1077 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UnsupportedPHIInner",
1080 <<
"Only inner loops with induction or reduction PHI nodes can be"
1081 " interchange currently.";
1088 if (!isLoopStructureUnderstood()) {
1091 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UnsupportedStructureInner",
1094 <<
"Inner loop structure not understood currently.";
1102bool LoopInterchangeLegality::findInductions(
1103 Loop *L, SmallVectorImpl<PHINode *> &Inductions) {
1104 for (PHINode &
PHI :
L->getHeader()->phis()) {
1105 InductionDescriptor
ID;
1109 return !Inductions.
empty();
1121 if (
PHI.getNumIncomingValues() > 1)
1124 PHINode *PN = dyn_cast<PHINode>(U);
1126 (!Reductions.count(PN) && OuterL->contains(PN->getParent()));
1191 for (
auto *U :
PHI.users()) {
1200bool LoopInterchangeLegality::canInterchangeLoops(
unsigned InnerLoopId,
1201 unsigned OuterLoopId,
1202 CharMatrix &DepMatrix) {
1204 LLVM_DEBUG(
dbgs() <<
"Failed interchange InnerLoopId = " << InnerLoopId
1205 <<
" and OuterLoopId = " << OuterLoopId
1206 <<
" due to dependence\n");
1208 return OptimizationRemarkMissed(
DEBUG_TYPE,
"Dependence",
1211 <<
"Cannot interchange loops due to dependences.";
1216 for (
auto *BB : OuterLoop->
blocks())
1220 if (CI->onlyWritesMemory())
1223 dbgs() <<
"Loops with call instructions cannot be interchanged "
1226 return OptimizationRemarkMissed(
DEBUG_TYPE,
"CallInst",
1229 <<
"Cannot interchange loops due to call instruction.";
1235 if (!findInductions(InnerLoop, InnerLoopInductions)) {
1236 LLVM_DEBUG(
dbgs() <<
"Could not find inner loop induction variables.\n");
1241 LLVM_DEBUG(
dbgs() <<
"Found unsupported PHI nodes in inner loop latch.\n");
1243 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UnsupportedInnerLatchPHI",
1246 <<
"Cannot interchange loops because unsupported PHI nodes found "
1247 "in inner loop latch.";
1254 if (currentLimitations()) {
1255 LLVM_DEBUG(
dbgs() <<
"Not legal because of current transform limitation\n");
1260 if (!tightlyNested(OuterLoop, InnerLoop)) {
1263 return OptimizationRemarkMissed(
DEBUG_TYPE,
"NotTightlyNested",
1266 <<
"Cannot interchange loops because they are not tightly "
1273 OuterInnerReductions)) {
1274 LLVM_DEBUG(
dbgs() <<
"Found unsupported PHI nodes in inner loop exit.\n");
1276 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UnsupportedExitPHI",
1279 <<
"Found unsupported PHI node in loop exit.";
1285 LLVM_DEBUG(
dbgs() <<
"Found unsupported PHI nodes in outer loop exit.\n");
1287 return OptimizationRemarkMissed(
DEBUG_TYPE,
"UnsupportedExitPHI",
1290 <<
"Found unsupported PHI node in loop exit.";
1298void CacheCostManager::computeIfUnitinialized() {
1313 for (
const auto &[Idx,
Cost] :
enumerate((*CC)->getLoopCosts()))
1314 CostMap[
Cost.first] = Idx;
1317CacheCost *CacheCostManager::getCacheCost() {
1318 computeIfUnitinialized();
1322const DenseMap<const Loop *, unsigned> &CacheCostManager::getCostMap() {
1323 computeIfUnitinialized();
1327int LoopInterchangeProfitability::getInstrOrderCost() {
1328 unsigned GoodOrder, BadOrder;
1329 BadOrder = GoodOrder = 0;
1330 for (BasicBlock *BB : InnerLoop->
blocks()) {
1331 for (Instruction &Ins : *BB) {
1333 bool FoundInnerInduction =
false;
1334 bool FoundOuterInduction =
false;
1340 const SCEV *OperandVal = SE->
getSCEV(
Op);
1350 if (AR->
getLoop() == InnerLoop) {
1353 FoundInnerInduction =
true;
1354 if (FoundOuterInduction) {
1364 if (AR->
getLoop() == OuterLoop) {
1367 FoundOuterInduction =
true;
1368 if (FoundInnerInduction) {
1377 return GoodOrder - BadOrder;
1381LoopInterchangeProfitability::isProfitablePerLoopCacheAnalysis(
1382 const DenseMap<const Loop *, unsigned> &CostMap, CacheCost *CC) {
1386 auto InnerLoopIt = CostMap.
find(InnerLoop);
1387 if (InnerLoopIt == CostMap.
end())
1388 return std::nullopt;
1389 auto OuterLoopIt = CostMap.
find(OuterLoop);
1390 if (OuterLoopIt == CostMap.
end())
1391 return std::nullopt;
1394 return std::nullopt;
1395 unsigned InnerIndex = InnerLoopIt->second;
1396 unsigned OuterIndex = OuterLoopIt->second;
1398 <<
", OuterIndex = " << OuterIndex <<
"\n");
1399 assert(InnerIndex != OuterIndex &&
"CostMap should assign unique "
1400 "numbers to each loop");
1401 return std::optional<bool>(InnerIndex < OuterIndex);
1405LoopInterchangeProfitability::isProfitablePerInstrOrderCost() {
1409 int Cost = getInstrOrderCost();
1412 return std::optional<bool>(
true);
1414 return std::nullopt;
1419 for (
const auto &Dep : DepMatrix) {
1420 char Dir = Dep[LoopId];
1421 char DepType = Dep.back();
1422 assert((DepType ==
'<' || DepType ==
'*') &&
1423 "Unexpected element in dependency vector");
1426 if (Dir ==
'=' || Dir ==
'I')
1432 if (Dir ==
'<' && DepType ==
'<')
1441std::optional<bool> LoopInterchangeProfitability::isProfitableForVectorization(
1442 unsigned InnerLoopId,
unsigned OuterLoopId, CharMatrix &DepMatrix) {
1458 return std::nullopt;
1461bool LoopInterchangeProfitability::isProfitable(
1462 const Loop *InnerLoop,
const Loop *OuterLoop,
unsigned InnerLoopId,
1463 unsigned OuterLoopId, CharMatrix &DepMatrix, CacheCostManager &CCM) {
1469 "Duplicate rules and option 'ignore' are not allowed");
1479 std::optional<bool> shouldInterchange;
1482 case RuleTy::PerLoopCacheAnalysis: {
1483 CacheCost *CC = CCM.getCacheCost();
1484 const DenseMap<const Loop *, unsigned> &CostMap = CCM.getCostMap();
1485 shouldInterchange = isProfitablePerLoopCacheAnalysis(CostMap, CC);
1488 case RuleTy::PerInstrOrderCost:
1489 shouldInterchange = isProfitablePerInstrOrderCost();
1491 case RuleTy::ForVectorization:
1493 isProfitableForVectorization(InnerLoopId, OuterLoopId, DepMatrix);
1495 case RuleTy::Ignore:
1502 if (shouldInterchange.has_value())
1506 if (!shouldInterchange.has_value()) {
1508 return OptimizationRemarkMissed(
DEBUG_TYPE,
"InterchangeNotProfitable",
1511 <<
"Insufficient information to calculate the cost of loop for "
1515 }
else if (!shouldInterchange.value()) {
1517 return OptimizationRemarkMissed(
DEBUG_TYPE,
"InterchangeNotProfitable",
1520 <<
"Interchanging loops is not considered to improve cache "
1521 "locality nor vectorization.";
1528void LoopInterchangeTransform::removeChildLoop(Loop *OuterLoop,
1530 for (Loop *L : *OuterLoop)
1531 if (L == InnerLoop) {
1532 OuterLoop->removeChildLoop(L);
1561void LoopInterchangeTransform::restructureLoops(
1562 Loop *NewInner, Loop *NewOuter, BasicBlock *OrigInnerPreHeader,
1563 BasicBlock *OrigOuterPreHeader) {
1564 Loop *OuterLoopParent = OuterLoop->getParentLoop();
1571 if (OuterLoopParent) {
1573 removeChildLoop(OuterLoopParent, NewInner);
1574 removeChildLoop(NewInner, NewOuter);
1577 removeChildLoop(NewInner, NewOuter);
1585 SmallVector<BasicBlock *, 8> OrigInnerBBs(NewOuter->
blocks());
1589 for (BasicBlock *BB : NewInner->
blocks())
1597 for (BasicBlock *BB : OrigInnerBBs) {
1602 if (BB == OuterHeader || BB == OuterLatch)
1617bool LoopInterchangeTransform::transform(
1619 bool Transformed =
false;
1624 auto &InductionPHIs = LIL.getInnerLoopInductions();
1625 if (InductionPHIs.empty()) {
1626 LLVM_DEBUG(
dbgs() <<
"Failed to find the point to split loop latch \n");
1630 SmallVector<Instruction *, 8> InnerIndexVarList;
1631 for (PHINode *CurInductionPHI : InductionPHIs) {
1632 if (CurInductionPHI->getIncomingBlock(0) == InnerLoopPreHeader)
1648 SmallSetVector<Instruction *, 4> WorkList;
1650 auto MoveInstructions = [&i, &WorkList,
this, &InductionPHIs, NewLatch]() {
1651 for (; i < WorkList.
size(); i++) {
1657 "Moving instructions with side-effects may change behavior of "
1668 for (
Value *
Op : WorkList[i]->operands()) {
1686 for (Instruction *InnerIndexVar : InnerIndexVarList)
1705 BasicBlock *OuterLoopHeader = OuterLoop->getHeader();
1706 if (InnerLoopPreHeader != OuterLoopHeader) {
1707 for (Instruction &
I :
1709 std::prev(InnerLoopPreHeader->
end()))))
1713 Transformed |= adjustLoopLinks();
1721 for (Instruction *
Reduction : DropNoWrapInsts) {
1745 I->removeFromParent();
1760 std::vector<DominatorTree::UpdateType> &DTUpdates,
1761 bool MustUpdateOnce =
true) {
1763 "BI must jump to OldBB exactly once.");
1772 DTUpdates.push_back(
1773 {DominatorTree::UpdateKind::Insert, BI->
getParent(), NewBB});
1774 DTUpdates.push_back(
1775 {DominatorTree::UpdateKind::Delete, BI->
getParent(), OldBB});
1794 assert(
P.getNumIncomingValues() == 1 &&
1795 "Only loops with a single exit are supported!");
1804 if (IncIInnerMost->getParent() != InnerLatch &&
1805 IncIInnerMost->
getParent() != InnerHeader)
1809 [OuterHeader, OuterExit, IncI, InnerHeader](
User *U) {
1810 return (cast<PHINode>(U)->getParent() == OuterHeader &&
1811 IncI->getParent() == InnerHeader) ||
1812 cast<PHINode>(U)->getParent() == OuterExit;
1814 "Can only replace phis iff the uses are in the loop nest exit or "
1815 "the incoming value is defined in the inner header (it will "
1816 "dominate all loop blocks after interchanging)");
1817 P.replaceAllUsesWith(IncI);
1818 P.eraseFromParent();
1846 if (
P.getNumIncomingValues() != 1)
1860 if (Pred == OuterLatch)
1865 P.setIncomingValue(0, NewPhi);
1875bool LoopInterchangeTransform::adjustLoopBranches() {
1877 std::vector<DominatorTree::UpdateType> DTUpdates;
1879 BasicBlock *OuterLoopPreHeader = OuterLoop->getLoopPreheader();
1882 assert(OuterLoopPreHeader != OuterLoop->getHeader() &&
1883 InnerLoopPreHeader != InnerLoop->
getHeader() && OuterLoopPreHeader &&
1884 InnerLoopPreHeader &&
"Guaranteed by loop-simplify form");
1891 OuterLoopPreHeader =
1893 if (InnerLoopPreHeader == OuterLoop->getHeader())
1894 InnerLoopPreHeader =
1899 BasicBlock *OuterLoopHeader = OuterLoop->getHeader();
1901 BasicBlock *OuterLoopLatch = OuterLoop->getLoopLatch();
1908 BranchInst *OuterLoopLatchBI =
1910 BranchInst *InnerLoopLatchBI =
1912 BranchInst *OuterLoopHeaderBI =
1914 BranchInst *InnerLoopHeaderBI =
1917 if (!OuterLoopPredecessor || !InnerLoopLatchPredecessor ||
1918 !OuterLoopLatchBI || !InnerLoopLatchBI || !OuterLoopHeaderBI ||
1922 BranchInst *InnerLoopLatchPredecessorBI =
1924 BranchInst *OuterLoopPredecessorBI =
1927 if (!OuterLoopPredecessorBI || !InnerLoopLatchPredecessorBI)
1930 if (!InnerLoopHeaderSuccessor)
1938 InnerLoopPreHeader, DTUpdates,
false);
1948 InnerLoopHeaderSuccessor, DTUpdates,
1956 OuterLoopPreHeader, DTUpdates);
1959 if (InnerLoopLatchBI->
getSuccessor(0) == InnerLoopHeader)
1960 InnerLoopLatchSuccessor = InnerLoopLatchBI->
getSuccessor(1);
1962 InnerLoopLatchSuccessor = InnerLoopLatchBI->
getSuccessor(0);
1965 InnerLoopLatchSuccessor, DTUpdates);
1967 if (OuterLoopLatchBI->
getSuccessor(0) == OuterLoopHeader)
1968 OuterLoopLatchSuccessor = OuterLoopLatchBI->
getSuccessor(1);
1970 OuterLoopLatchSuccessor = OuterLoopLatchBI->
getSuccessor(0);
1973 OuterLoopLatchSuccessor, DTUpdates);
1974 updateSuccessor(OuterLoopLatchBI, OuterLoopLatchSuccessor, InnerLoopLatch,
1978 restructureLoops(OuterLoop, InnerLoop, InnerLoopPreHeader,
1979 OuterLoopPreHeader);
1981 moveLCSSAPhis(InnerLoopLatchSuccessor, InnerLoopHeader, InnerLoopLatch,
1982 OuterLoopHeader, OuterLoopLatch, InnerLoop->
getExitBlock(),
1988 auto &OuterInnerReductions = LIL.getOuterInnerReductions();
1991 for (PHINode &
PHI : InnerLoopHeader->
phis())
1992 if (OuterInnerReductions.contains(&
PHI))
1995 for (PHINode &
PHI : OuterLoopHeader->
phis())
1996 if (OuterInnerReductions.contains(&
PHI))
2002 for (PHINode *
PHI : OuterLoopPHIs) {
2005 assert(OuterInnerReductions.count(
PHI) &&
"Expected a reduction PHI node");
2007 for (PHINode *
PHI : InnerLoopPHIs) {
2010 assert(OuterInnerReductions.count(
PHI) &&
"Expected a reduction PHI node");
2023 SmallVector<Instruction *, 4> MayNeedLCSSAPhis;
2024 for (Instruction &
I :
2032bool LoopInterchangeTransform::adjustLoopLinks() {
2034 bool Changed = adjustLoopBranches();
2039 BasicBlock *OuterLoopPreHeader = OuterLoop->getLoopPreheader();
2064 LLVM_DEBUG(
dbgs() <<
"Not valid loop candidate for interchange\n");
2072 <<
"Computed dependence info, invoking the transform.";
2076 if (!LoopInterchange(&AR.
SE, &AR.
LI, &DI, &AR.
DT, &AR, &ORE).run(LN))
2078 U.markLoopNestChanged(
true);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
ReachingDefInfo InstSet InstSet & Ignore
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
static void moveBBContents(BasicBlock &SourceBB, BasicBlock &TargetBB)
Move the contents of SourceBB to before the last instruction of TargetBB.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
This file defines the interface for the loop cache analysis.
Loop::LoopBounds::Direction Direction
static cl::opt< unsigned int > MaxMemInstrCount("loop-interchange-max-meminstr-count", cl::init(64), cl::Hidden, cl::desc("Maximum number of load-store instructions that should be handled " "in the dependency matrix. Higher value may lead to more interchanges " "at the cost of compile-time"))
static cl::opt< int > LoopInterchangeCostThreshold("loop-interchange-threshold", cl::init(0), cl::Hidden, cl::desc("Interchange if you gain more than this number"))
static PHINode * findInnerReductionPhi(Loop *L, Value *V, SmallVectorImpl< Instruction * > &HasNoWrapInsts)
static cl::opt< unsigned int > MinLoopNestDepth("loop-interchange-min-loop-nest-depth", cl::init(2), cl::Hidden, cl::desc("Minimum depth of loop nest considered for the transform"))
static bool isComputableLoopNest(ScalarEvolution *SE, ArrayRef< Loop * > LoopList)
static bool areOuterLoopExitPHIsSupported(Loop *OuterLoop, Loop *InnerLoop)
static void interChangeDependencies(CharMatrix &DepMatrix, unsigned FromIndx, unsigned ToIndx)
static void moveLCSSAPhis(BasicBlock *InnerExit, BasicBlock *InnerHeader, BasicBlock *InnerLatch, BasicBlock *OuterHeader, BasicBlock *OuterLatch, BasicBlock *OuterExit, Loop *InnerLoop, LoopInfo *LI)
static void printDepMatrix(CharMatrix &DepMatrix)
static void swapBBContents(BasicBlock *BB1, BasicBlock *BB2)
Swap instructions between BB1 and BB2 but keep terminators intact.
static cl::opt< unsigned int > MaxLoopNestDepth("loop-interchange-max-loop-nest-depth", cl::init(10), cl::Hidden, cl::desc("Maximum depth of loop nest considered for the transform"))
static bool hasSupportedLoopDepth(ArrayRef< Loop * > LoopList, OptimizationRemarkEmitter &ORE)
static bool inThisOrder(const Instruction *Src, const Instruction *Dst)
Return true if Src appears before Dst in the same basic block.
static bool areInnerLoopLatchPHIsSupported(Loop *OuterLoop, Loop *InnerLoop)
static bool canVectorize(const CharMatrix &DepMatrix, unsigned LoopId)
Return true if we can vectorize the loop specified by LoopId.
static bool isLegalToInterChangeLoops(CharMatrix &DepMatrix, unsigned InnerLoopId, unsigned OuterLoopId)
static bool areInnerLoopExitPHIsSupported(Loop *InnerL, Loop *OuterL, SmallPtrSetImpl< PHINode * > &Reductions)
static Value * followLCSSA(Value *SV)
static void populateWorklist(Loop &L, LoopVector &LoopList)
static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level, Loop *L, DependenceInfo *DI, ScalarEvolution *SE, OptimizationRemarkEmitter *ORE)
static void updateSuccessor(BranchInst *BI, BasicBlock *OldBB, BasicBlock *NewBB, std::vector< DominatorTree::UpdateType > &DTUpdates, bool MustUpdateOnce=true)
static std::optional< bool > isLexicographicallyPositive(ArrayRef< char > DV, unsigned Begin, unsigned End)
static cl::list< RuleTy > Profitabilities("loop-interchange-profitabilities", cl::ZeroOrMore, cl::MiscFlags::CommaSeparated, cl::Hidden, cl::desc("List of profitability heuristics to be used. They are applied in " "the given order"), cl::list_init< RuleTy >({RuleTy::PerLoopCacheAnalysis, RuleTy::PerInstrOrderCost, RuleTy::ForVectorization}), cl::values(clEnumValN(RuleTy::PerLoopCacheAnalysis, "cache", "Prioritize loop cache cost"), clEnumValN(RuleTy::PerInstrOrderCost, "instorder", "Prioritize the IVs order of each instruction"), clEnumValN(RuleTy::ForVectorization, "vectorize", "Prioritize vectorization"), clEnumValN(RuleTy::Ignore, "ignore", "Ignore profitability, force interchange (does not " "work with other options)")))
static bool noDuplicateRulesAndIgnore(ArrayRef< RuleTy > Rules)
This file defines the interface for the loop nest analysis.
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
loop Loop Strength Reduction
uint64_t IntrinsicInst * II
This file defines the SmallSet class.
This file defines the SmallVector class.
static bool isProfitable(const StableFunctionMap::StableFunctionEntries &SFS)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & front() const
front - Get the first element.
size_t size() const
size - Get the array size.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI iterator_range< filter_iterator< BasicBlock::const_iterator, std::function< bool(const Instruction &)> > > instructionsWithoutDebug(bool SkipPseudoOp=true) const
Return a const iterator range over the instructions in the block, skipping any debug instructions.
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
LLVM_ABI const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
LLVM_ABI void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old.
LLVM_ABI const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
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...
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
Conditional or Unconditional Branch instruction.
iterator_range< succ_op_iterator > successors()
bool isConditional() const
BasicBlock * getSuccessor(unsigned i) const
Value * getCondition() const
static std::unique_ptr< CacheCost > getCacheCost(Loop &Root, LoopStandardAnalysisResults &AR, DependenceInfo &DI, std::optional< unsigned > TRT=std::nullopt)
Create a CacheCost for the loop nest rooted by Root.
CacheCostTy getLoopCost(const Loop &L) const
Return the estimated cost of loop L if the given loop is part of the loop nest associated with this o...
iterator find(const_arg_type_t< KeyT > Val)
DependenceInfo - This class is the main dependence-analysis driver.
LLVM_ABI std::unique_ptr< Dependence > depends(Instruction *Src, Instruction *Dst, bool UnderRuntimeAssumptions=false)
depends - Tests for a dependence between the Src and Dst instructions.
void applyUpdates(ArrayRef< UpdateType > Updates)
Inform the dominator tree about a sequence of CFG edge insertions and deletions and perform a batch u...
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.
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
LLVM_ABI bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
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.
bool isInnermost() const
Return true if the loop does not contain any (natural) loops.
void removeBlockFromLoop(BlockT *BB)
This removes the specified basic block from the current loop, updating the Blocks as appropriate.
const std::vector< LoopT * > & getSubLoops() const
Return the loops contained entirely within this loop.
BlockT * getHeader() const
iterator_range< block_iterator > blocks() const
void addChildLoop(LoopT *NewChild)
Add the specified loop to be a child of this loop.
void addBlockEntry(BlockT *BB)
This adds a basic block directly to the basic block list.
BlockT * getExitBlock() const
If getExitBlocks would return exactly one block, return that block.
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
BlockT * getExitingBlock() const
If getExitingBlocks would return exactly one block, return that block.
BlockT * getUniqueExitBlock() const
If getUniqueExitBlocks would return exactly one block, return that block.
LoopT * removeChildLoop(iterator I)
This removes the specified child from being a subloop of this loop.
void changeTopLevelLoop(LoopT *OldLoop, LoopT *NewLoop)
Replace the specified loop in the top-level loops list with the indicated loop.
void changeLoopFor(BlockT *BB, LoopT *L)
Change the top-level loop that contains BB to the specified loop.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
This class represents a loop nest and can be used to query its properties.
static const BasicBlock & skipEmptyBlockUntil(const BasicBlock *From, const BasicBlock *End, bool CheckUniquePred=false)
Recursivelly traverse all empty 'single successor' basic blocks of From (if there are any).
ArrayRef< Loop * > getLoops() const
Get the loops in the nest.
Function * getParent() const
Return the function to which the loop-nest belongs.
Loop & getOutermostLoop() const
Return the outermost loop in the loop nest.
Represents a single loop in the control flow graph.
DebugLoc getStartLoc() const
Return the debug location of the start of this loop.
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
op_range incoming_values()
void setIncomingBlock(unsigned i, BasicBlock *BB)
void setIncomingValue(unsigned i, Value *V)
static unsigned getIncomingValueNumForOperand(unsigned i)
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Instruction * getExactFPMathInst() const
Returns 1st non-reassociative FP instruction in the PHI node's use-chain.
unsigned getOpcode() const
static LLVM_ABI bool isReductionPHI(PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes, DemandedBits *DB=nullptr, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr, ScalarEvolution *SE=nullptr)
Returns true if Phi is a reduction in TheLoop.
LLVM_ABI SmallVector< Instruction *, 4 > getReductionOpChain(PHINode *Phi, Loop *L) const
Attempts to find a chain of operations from Phi to LoopExitInst that can be treated as a set of reduc...
RecurKind getRecurrenceKind() const
const Loop * getLoop() const
This class represents an analyzed expression in the program.
The main scalar evolution driver.
LLVM_ABI const SCEV * getBackedgeTakenCount(const Loop *L, ExitCountKind Kind=Exact)
If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCould...
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 bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
size_type size() const
Determine the number of elements in the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
iterator_range< user_iterator > users()
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
@ BasicBlock
Various leaf nodes.
list_initializer< Ty > list_init(ArrayRef< Ty > Vals)
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
LLVM_ABI BasicBlock * InsertPreheaderForLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
InsertPreheaderForLoop - Once we discover that a loop doesn't have a preheader, this method is called...
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
LLVM_ABI bool formLCSSARecursively(Loop &L, const DominatorTree &DT, const LoopInfo *LI, ScalarEvolution *SE)
Put a loop nest into LCSSA form.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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...
auto map_range(ContainerTy &&C, FuncTy F)
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
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 raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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...
auto drop_end(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the last N elements excluded.
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.
@ 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()).
@ FMaximumNum
FP max with llvm.maximumnum semantics.
@ UMax
Unsigned integer max implemented in terms of select(cmp()).
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI bool formLCSSAForInstructions(SmallVectorImpl< Instruction * > &Worklist, const DominatorTree &DT, const LoopInfo &LI, ScalarEvolution *SE, SmallVectorImpl< PHINode * > *PHIsToRemove=nullptr, SmallVectorImpl< PHINode * > *InsertedPHIs=nullptr)
Ensures LCSSA form for every instruction from the Worklist in the scope of innermost containing loop.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
LLVM_ABI PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
auto predecessors(const MachineBasicBlock *BB)
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Incoming for lane maks phi as machine instruction, incoming register Reg and incoming block Block are...
PreservedAnalyses run(LoopNest &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...