71#define DEBUG_TYPE "loop-fusion"
74STATISTIC(NumFusionCandidates,
"Number of candidates for loop fusion");
75STATISTIC(InvalidPreheader,
"Loop has invalid preheader");
77STATISTIC(InvalidExitingBlock,
"Loop has invalid exiting blocks");
78STATISTIC(InvalidExitBlock,
"Loop has invalid exit block");
81STATISTIC(AddressTakenBB,
"Basic block has address taken");
82STATISTIC(MayThrowException,
"Loop may throw an exception");
83STATISTIC(ContainsVolatileAccess,
"Loop contains a volatile access");
84STATISTIC(NotSimplifiedForm,
"Loop is not in simplified form");
85STATISTIC(InvalidDependencies,
"Dependencies prevent fusion");
86STATISTIC(UnknownTripCount,
"Loop has unknown trip count");
87STATISTIC(UncomputableTripCount,
"SCEV cannot compute trip count of loop");
88STATISTIC(NonEqualTripCount,
"Loop trip counts are not the same");
91 "Loop has a non-empty preheader with instructions that cannot be moved");
92STATISTIC(FusionNotBeneficial,
"Fusion is not beneficial");
93STATISTIC(NonIdenticalGuards,
"Candidates have different guards");
94STATISTIC(NonEmptyExitBlock,
"Candidate has a non-empty exit block with "
95 "instructions that cannot be moved");
96STATISTIC(NonEmptyGuardBlock,
"Candidate has a non-empty guard block with "
97 "instructions that cannot be moved");
100 "The second candidate is guarded while the first one is not");
101STATISTIC(NumHoistedInsts,
"Number of hoisted preheader instructions.");
102STATISTIC(NumSunkInsts,
"Number of hoisted preheader instructions.");
112 "loop-fusion-dependence-analysis",
113 cl::desc(
"Which dependence analysis should loop fusion use?"),
115 "Use the scalar evolution interface"),
117 "Use the dependence analysis interface"),
119 "Use all available analyses")),
124 cl::desc(
"Max number of iterations to be peeled from a loop, such that "
125 "fusion can take place"));
130 cl::desc(
"Enable verbose debugging for Loop Fusion"),
145struct FusionCandidate {
184 : Preheader(L->getLoopPreheader()), Header(L->getHeader()),
185 ExitingBlock(L->getExitingBlock()), ExitBlock(L->getExitBlock()),
186 Latch(L->getLoopLatch()), L(L), Valid(
true),
187 GuardBranch(L->getLoopGuardBranch()), PP(PP), AbleToPeel(
canPeel(L)),
188 Peeled(
false), DT(DT), PDT(PDT), ORE(ORE) {
195 if (BB->hasAddressTaken()) {
197 reportInvalidCandidate(AddressTakenBB);
208 if (
SI->isVolatile()) {
215 if (LI->isVolatile()) {
221 if (
I.mayWriteToMemory())
222 MemWrites.push_back(&
I);
223 if (
I.mayReadFromMemory())
224 MemReads.push_back(&
I);
231 return Preheader && Header && ExitingBlock && ExitBlock && Latch &&
L &&
238 assert(!
L->isInvalid() &&
"Loop is invalid!");
239 assert(Preheader ==
L->getLoopPreheader() &&
"Preheader is out of sync");
240 assert(Header ==
L->getHeader() &&
"Header is out of sync");
241 assert(ExitingBlock ==
L->getExitingBlock() &&
242 "Exiting Blocks is out of sync");
243 assert(ExitBlock ==
L->getExitBlock() &&
"Exit block is out of sync");
244 assert(Latch ==
L->getLoopLatch() &&
"Latch is out of sync");
261 void updateAfterPeeling() {
262 Preheader =
L->getLoopPreheader();
263 Header =
L->getHeader();
264 ExitingBlock =
L->getExitingBlock();
265 ExitBlock =
L->getExitBlock();
266 Latch =
L->getLoopLatch();
278 assert(GuardBranch &&
"Only valid on guarded loops.");
280 "Expecting guard to be a conditional branch.");
288#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
290 dbgs() <<
"\tGuardBranch: ";
292 dbgs() << *GuardBranch;
296 << (GuardBranch ? GuardBranch->
getName() :
"nullptr") <<
"\n"
297 <<
"\tPreheader: " << (Preheader ? Preheader->
getName() :
"nullptr")
299 <<
"\tHeader: " << (Header ? Header->getName() :
"nullptr") <<
"\n"
301 << (ExitingBlock ? ExitingBlock->
getName() :
"nullptr") <<
"\n"
302 <<
"\tExitBB: " << (ExitBlock ? ExitBlock->
getName() :
"nullptr")
304 <<
"\tLatch: " << (Latch ? Latch->
getName() :
"nullptr") <<
"\n"
306 << (getEntryBlock() ? getEntryBlock()->getName() :
"nullptr")
322 ++InvalidExitingBlock;
336 <<
" trip count not computable!\n");
340 if (!
L->isLoopSimplifyForm()) {
342 <<
" is not in simplified form!\n");
346 if (!
L->isRotatedForm()) {
369 assert(L && Preheader &&
"Fusion candidate not initialized properly!");
373 L->getStartLoc(), Preheader)
375 <<
"Loop is not a candidate for fusion: " << Stat.getDesc());
392 dbgs() <<
"****************************\n";
393 for (
const Loop *L : LV)
395 dbgs() <<
"****************************\n";
400 OS << FC.Preheader->getName();
409 for (
const FusionCandidate &FC : CandList)
417 dbgs() <<
"Fusion Candidates: \n";
418 for (
const auto &CandidateList : FusionCandidates) {
419 dbgs() <<
"*** Fusion Candidate List ***\n";
420 dbgs() << CandidateList;
421 dbgs() <<
"****************************\n";
434struct LoopDepthTree {
435 using LoopsOnLevelTy = SmallVector<LoopVector, 4>;
439 LoopDepthTree(LoopInfo &LI) : Depth(1) {
446 bool isRemovedLoop(
const Loop *L)
const {
return RemovedLoops.count(L); }
450 void removeLoop(
const Loop *L) { RemovedLoops.insert(L); }
454 LoopsOnLevelTy LoopsOnNextLevel;
458 if (!isRemovedLoop(L) &&
L->begin() !=
L->end())
459 LoopsOnNextLevel.emplace_back(
LoopVector(
L->begin(),
L->end()));
461 LoopsOnLevel = LoopsOnNextLevel;
462 RemovedLoops.clear();
466 bool empty()
const {
return size() == 0; }
467 size_t size()
const {
return LoopsOnLevel.size() - RemovedLoops.size(); }
468 unsigned getDepth()
const {
return Depth; }
470 iterator
begin() {
return LoopsOnLevel.begin(); }
471 iterator
end() {
return LoopsOnLevel.end(); }
472 const_iterator
begin()
const {
return LoopsOnLevel.begin(); }
473 const_iterator
end()
const {
return LoopsOnLevel.end(); }
478 SmallPtrSet<const Loop *, 8> RemovedLoops;
484 LoopsOnLevelTy LoopsOnLevel;
499 PostDominatorTree &PDT;
500 OptimizationRemarkEmitter &ORE;
502 const TargetTransformInfo &TTI;
505 LoopFuser(LoopInfo &LI, DominatorTree &DT, DependenceInfo &DI,
506 ScalarEvolution &SE, PostDominatorTree &PDT,
507 OptimizationRemarkEmitter &ORE,
const DataLayout &
DL,
508 AssumptionCache &AC,
const TargetTransformInfo &TTI)
509 : LDT(LI), DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Lazy), LI(LI),
510 DT(DT), DI(DI), SE(SE), PDT(PDT), ORE(ORE), AC(AC), TTI(TTI) {}
515 bool fuseLoops(Function &
F) {
522 LLVM_DEBUG(
dbgs() <<
"Performing Loop Fusion on function " <<
F.getName()
526 while (!LDT.empty()) {
527 LLVM_DEBUG(
dbgs() <<
"Got " << LDT.size() <<
" loop sets for depth "
528 << LDT.getDepth() <<
"\n";);
531 assert(LV.size() > 0 &&
"Empty loop set was build!");
540 dbgs() <<
" Visit loop set (#" << LV.size() <<
"):\n";
546 collectFusionCandidates(LV);
558 FusionCandidates.clear();
579 void collectFusionCandidates(
const LoopVector &LV) {
583 FusionCandidate CurrCand(L, DT, &PDT, ORE, PP);
584 if (!CurrCand.isEligibleForFusion(SE))
592 bool FoundAdjacent =
false;
593 for (
auto &CurrCandList : FusionCandidates) {
594 if (isStrictlyAdjacent(CurrCand, CurrCandList.front())) {
595 CurrCandList.push_front(CurrCand);
596 FoundAdjacent =
true;
600 <<
" to existing candidate list\n");
603 }
else if (isStrictlyAdjacent(CurrCandList.back(), CurrCand)) {
604 CurrCandList.push_back(CurrCand);
605 FoundAdjacent =
true;
609 <<
" to existing candidate list\n");
614 if (!FoundAdjacent) {
621 NewCandList.push_back(CurrCand);
622 FusionCandidates.push_back(NewCandList);
624 NumFusionCandidates++;
633 bool isBeneficialFusion(
const FusionCandidate &FC0,
634 const FusionCandidate &FC1) {
646 std::pair<bool, std::optional<unsigned>>
647 haveIdenticalTripCounts(
const FusionCandidate &FC0,
648 const FusionCandidate &FC1)
const {
649 const SCEV *TripCount0 = SE.getBackedgeTakenCount(FC0.L);
651 UncomputableTripCount++;
652 LLVM_DEBUG(
dbgs() <<
"Trip count of first loop could not be computed!");
653 return {
false, std::nullopt};
656 const SCEV *TripCount1 = SE.getBackedgeTakenCount(FC1.L);
658 UncomputableTripCount++;
659 LLVM_DEBUG(
dbgs() <<
"Trip count of second loop could not be computed!");
660 return {
false, std::nullopt};
664 << *TripCount1 <<
" are "
665 << (TripCount0 == TripCount1 ?
"identical" :
"different")
668 if (TripCount0 == TripCount1)
672 "determining the difference between trip counts\n");
676 const unsigned TC0 = SE.getSmallConstantTripCount(FC0.L);
677 const unsigned TC1 = SE.getSmallConstantTripCount(FC1.L);
681 if (TC0 == 0 || TC1 == 0) {
682 LLVM_DEBUG(
dbgs() <<
"Loop(s) do not have a single exit point or do not "
683 "have a constant number of iterations. Peeling "
684 "is not benefical\n");
685 return {
false, std::nullopt};
688 std::optional<unsigned> Difference;
689 int Diff = TC0 - TC1;
695 dbgs() <<
"Difference is less than 0. FC1 (second loop) has more "
696 "iterations than the first one. Currently not supported\n");
699 LLVM_DEBUG(
dbgs() <<
"Difference in loop trip count is: " << Difference
702 return {
false, Difference};
705 void peelFusionCandidate(FusionCandidate &FC0,
const FusionCandidate &FC1,
706 unsigned PeelCount) {
707 assert(FC0.AbleToPeel &&
"Should be able to peel loop");
710 <<
" iterations of the first loop. \n");
714 peelLoop(FC0.L, PeelCount,
false, &LI, &SE, DT, &AC,
true, VMap);
719 auto IdenticalTripCount = haveIdenticalTripCounts(FC0, FC1);
721 assert(IdenticalTripCount.first && *IdenticalTripCount.second == 0 &&
722 "Loops should have identical trip counts after peeling");
728 PDT.recalculate(*FC0.Preheader->
getParent());
730 FC0.updateAfterPeeling();
744 SmallVector<Instruction *, 8> WorkList;
746 if (Pred != FC0.ExitBlock) {
749 DominatorTree::UpdateType(DominatorTree::Delete, Pred, BB));
754 for (Instruction *CurrentBranch : WorkList) {
755 BasicBlock *Succ = CurrentBranch->getSuccessor(0);
757 Succ = CurrentBranch->getSuccessor(1);
761 DTU.applyUpdates(TreeUpdates);
766 <<
" iterations from the first loop.\n"
767 "Both Loops have the same number of iterations now.\n");
778 bool fuseCandidates() {
781 for (
auto &CandidateList : FusionCandidates) {
782 if (CandidateList.size() < 2)
786 << CandidateList <<
"\n");
788 for (
auto It = CandidateList.begin(), NextIt = std::next(It);
789 NextIt != CandidateList.end(); It = NextIt, NextIt = std::next(It)) {
794 assert(!LDT.isRemovedLoop(FC0.L) &&
795 "Should not have removed loops in CandidateList!");
796 assert(!LDT.isRemovedLoop(FC1.L) &&
797 "Should not have removed loops in CandidateList!");
799 LLVM_DEBUG(
dbgs() <<
"Attempting to fuse candidate \n"; FC0.dump();
800 dbgs() <<
" with\n"; FC1.dump();
dbgs() <<
"\n");
810 std::pair<bool, std::optional<unsigned>> IdenticalTripCountRes =
811 haveIdenticalTripCounts(FC0, FC1);
812 bool SameTripCount = IdenticalTripCountRes.first;
813 std::optional<unsigned> TCDifference = IdenticalTripCountRes.second;
817 if (FC0.AbleToPeel && !SameTripCount && TCDifference) {
820 <<
"Difference in loop trip counts: " << *TCDifference
821 <<
" is greater than maximum peel count specificed: "
826 SameTripCount =
true;
830 if (!SameTripCount) {
831 LLVM_DEBUG(
dbgs() <<
"Fusion candidates do not have identical trip "
832 "counts. Not fusing.\n");
833 reportLoopFusion<OptimizationRemarkMissed>(FC0, FC1,
838 if ((!FC0.GuardBranch && FC1.GuardBranch) ||
839 (FC0.GuardBranch && !FC1.GuardBranch)) {
841 "another one is not. Not fusing.\n");
842 reportLoopFusion<OptimizationRemarkMissed>(
843 FC0, FC1, OnlySecondCandidateIsGuarded);
849 if (FC0.GuardBranch && FC1.GuardBranch &&
850 !haveIdenticalGuards(FC0, FC1) && !TCDifference) {
852 "guards. Not Fusing.\n");
853 reportLoopFusion<OptimizationRemarkMissed>(FC0, FC1,
858 if (FC0.GuardBranch) {
859 assert(FC1.GuardBranch &&
"Expecting valid FC1 guard branch");
865 "instructions in exit block. Not fusing.\n");
866 reportLoopFusion<OptimizationRemarkMissed>(FC0, FC1,
873 *FC0.GuardBranch->
getParent()->getTerminator(), DT, &PDT,
876 "instructions in guard block. Not fusing.\n");
877 reportLoopFusion<OptimizationRemarkMissed>(FC0, FC1,
885 if (!dependencesAllowFusion(FC0, FC1)) {
886 LLVM_DEBUG(
dbgs() <<
"Memory dependencies do not allow fusion!\n");
887 reportLoopFusion<OptimizationRemarkMissed>(FC0, FC1,
888 InvalidDependencies);
895 SmallVector<Instruction *, 4> SafeToHoist;
896 SmallVector<Instruction *, 4> SafeToSink;
900 if (!isEmptyPreheader(FC1)) {
906 if (!collectMovablePreheaderInsts(FC0, FC1, SafeToHoist,
909 "Fusion Candidate Pre-header.\n"
911 reportLoopFusion<OptimizationRemarkMissed>(FC0, FC1,
917 bool BeneficialToFuse = isBeneficialFusion(FC0, FC1);
919 << (BeneficialToFuse ?
"" :
"un") <<
"profitable!\n");
920 if (!BeneficialToFuse) {
921 reportLoopFusion<OptimizationRemarkMissed>(FC0, FC1,
922 FusionNotBeneficial);
930 movePreheaderInsts(FC0, FC1, SafeToHoist, SafeToSink);
932 LLVM_DEBUG(
dbgs() <<
"\tFusion is performed: " << FC0 <<
" and " << FC1
935 FusionCandidate FC0Copy = FC0;
938 bool Peel = TCDifference && *TCDifference > 0;
940 peelFusionCandidate(FC0Copy, FC1, *TCDifference);
946 reportLoopFusion<OptimizationRemark>((Peel ? FC0Copy : FC0), FC1,
949 FusionCandidate FusedCand(performFusion((Peel ? FC0Copy : FC0), FC1),
950 DT, &PDT, ORE, FC0Copy.PP);
952 assert(FusedCand.isEligibleForFusion(SE) &&
953 "Fused candidate should be eligible for fusion!");
956 LDT.removeLoop(FC1.L);
959 It = CandidateList.erase(It);
960 It = CandidateList.erase(It);
961 It = CandidateList.insert(It, FusedCand);
966 LLVM_DEBUG(
dbgs() <<
"Candidate List (after fusion): " << CandidateList
980 bool canHoistInst(Instruction &
I,
981 const SmallVector<Instruction *, 4> &SafeToHoist,
982 const SmallVector<Instruction *, 4> &NotHoisting,
983 const FusionCandidate &FC0)
const {
985 assert(FC0PreheaderTarget &&
986 "Expected single successor for loop preheader.");
988 for (Use &
Op :
I.operands()) {
993 if (!(OpHoisted || DT.dominates(OpInst, FC0PreheaderTarget))) {
1005 if (!
I.mayReadOrWriteMemory())
1008 LLVM_DEBUG(
dbgs() <<
"Checking if this mem inst can be hoisted.\n");
1009 for (Instruction *NotHoistedInst : NotHoisting) {
1010 if (
auto D = DI.depends(&
I, NotHoistedInst)) {
1013 if (
D->isFlow() ||
D->isAnti() ||
D->isOutput()) {
1015 "preheader that is not being hoisted.\n");
1021 for (Instruction *ReadInst : FC0.MemReads) {
1022 if (
auto D = DI.depends(ReadInst, &
I)) {
1025 LLVM_DEBUG(
dbgs() <<
"Inst depends on a read instruction in FC0.\n");
1031 for (Instruction *WriteInst : FC0.MemWrites) {
1032 if (
auto D = DI.depends(WriteInst, &
I)) {
1034 if (
D->isFlow() ||
D->isOutput()) {
1035 LLVM_DEBUG(
dbgs() <<
"Inst depends on a write instruction in FC0.\n");
1046 bool canSinkInst(Instruction &
I,
const FusionCandidate &FC1)
const {
1047 for (User *U :
I.users()) {
1060 if (!
I.mayReadOrWriteMemory())
1063 for (Instruction *ReadInst : FC1.MemReads) {
1064 if (
auto D = DI.depends(&
I, ReadInst)) {
1067 LLVM_DEBUG(
dbgs() <<
"Inst depends on a read instruction in FC1.\n");
1073 for (Instruction *WriteInst : FC1.MemWrites) {
1074 if (
auto D = DI.depends(&
I, WriteInst)) {
1076 if (
D->isOutput() ||
D->isAnti()) {
1077 LLVM_DEBUG(
dbgs() <<
"Inst depends on a write instruction in FC1.\n");
1092 const FusionCandidate &FC0,
1093 const FusionCandidate &FC1)
const {
1094 for (Instruction *Inst : SafeToSink) {
1099 for (
unsigned I = 0;
I <
Phi->getNumIncomingValues();
I++) {
1100 if (
Phi->getIncomingBlock(
I) != FC0.Latch)
1102 assert(FC1.Latch &&
"FC1 latch is not set");
1103 Phi->setIncomingBlock(
I, FC1.Latch);
1110 bool collectMovablePreheaderInsts(
1111 const FusionCandidate &FC0,
const FusionCandidate &FC1,
1112 SmallVector<Instruction *, 4> &SafeToHoist,
1113 SmallVector<Instruction *, 4> &SafeToSink)
const {
1117 SmallVector<Instruction *, 4> NotHoisting;
1119 for (Instruction &
I : *FC1Preheader) {
1121 if (&
I == FC1Preheader->getTerminator())
1127 if (
I.mayThrow() || !
I.willReturn()) {
1128 LLVM_DEBUG(
dbgs() <<
"Inst: " <<
I <<
" may throw or won't return.\n");
1134 if (
I.isAtomic() ||
I.isVolatile()) {
1136 dbgs() <<
"\tInstruction is volatile or atomic. Cannot move it.\n");
1140 if (canHoistInst(
I, SafeToHoist, NotHoisting, FC0)) {
1147 if (canSinkInst(
I, FC1)) {
1157 dbgs() <<
"All preheader instructions could be sunk or hoisted!\n");
1162 class AddRecLoopReplacer :
public SCEVRewriteVisitor<AddRecLoopReplacer> {
1164 AddRecLoopReplacer(ScalarEvolution &SE,
const Loop &OldL,
const Loop &NewL,
1166 : SCEVRewriteVisitor(SE), Valid(
true), UseMax(UseMax), OldL(OldL),
1169 const SCEV *visitAddRecExpr(
const SCEVAddRecExpr *Expr) {
1170 const Loop *ExprL = Expr->
getLoop();
1172 if (ExprL == &OldL) {
1177 if (OldL.contains(ExprL)) {
1179 if (!UseMax || !Pos || !Expr->
isAffine()) {
1191 bool wasValidSCEV()
const {
return Valid; }
1195 const Loop &OldL, &NewL;
1200 bool accessDiffIsPositive(
const Loop &L0,
const Loop &L1, Instruction &I0,
1201 Instruction &I1,
bool EqualIsInvalid) {
1207 const SCEV *SCEVPtr0 = SE.getSCEVAtScope(Ptr0, &L0);
1208 const SCEV *SCEVPtr1 = SE.getSCEVAtScope(Ptr1, &L1);
1211 LLVM_DEBUG(
dbgs() <<
" Access function check: " << *SCEVPtr0 <<
" vs "
1212 << *SCEVPtr1 <<
"\n");
1214 AddRecLoopReplacer
Rewriter(SE, L0, L1);
1215 SCEVPtr0 =
Rewriter.visit(SCEVPtr0);
1218 LLVM_DEBUG(
dbgs() <<
" Access function after rewrite: " << *SCEVPtr0
1219 <<
" [Valid: " <<
Rewriter.wasValidSCEV() <<
"]\n");
1229 auto HasNonLinearDominanceRelation = [&](
const SCEV *S) {
1239 ICmpInst::Predicate Pred =
1240 EqualIsInvalid ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_SGE;
1241 bool IsAlwaysGE = SE.isKnownPredicate(Pred, SCEVPtr0, SCEVPtr1);
1245 << (IsAlwaysGE ?
" >= " :
" may < ") << *SCEVPtr1
1254 bool dependencesAllowFusion(
const FusionCandidate &FC0,
1255 const FusionCandidate &FC1, Instruction &I0,
1256 Instruction &I1,
bool AnyDep,
1260 LLVM_DEBUG(
dbgs() <<
"Check dep: " << I0 <<
" vs " << I1 <<
" : "
1261 << DepChoice <<
"\n");
1264 switch (DepChoice) {
1266 return accessDiffIsPositive(*FC0.L, *FC1.L, I0, I1, AnyDep);
1268 auto DepResult = DI.depends(&I0, &I1);
1274 dbgs() <<
" [#l: " << DepResult->getLevels() <<
"][Ordered: "
1275 << (DepResult->isOrdered() ?
"true" :
"false")
1277 LLVM_DEBUG(
dbgs() <<
"DepResult Levels: " << DepResult->getLevels()
1281 unsigned Levels = DepResult->getLevels();
1282 unsigned SameSDLevels = DepResult->getSameSDLevels();
1286 if (CurLoopLevel > Levels + SameSDLevels)
1290 for (
unsigned Level = 1;
Level <= std::min(CurLoopLevel - 1, Levels);
1292 unsigned Direction = DepResult->getDirection(Level,
false);
1298 LLVM_DEBUG(
dbgs() <<
"Safe to fuse due to non-equal acceses in the "
1305 assert(CurLoopLevel > Levels &&
"Fusion candidates are not separated");
1307 unsigned CurDir = DepResult->getDirection(CurLoopLevel,
true);
1317 LLVM_DEBUG(
dbgs() <<
"Safe to fuse with no backward loop-carried "
1323 if (DepResult->getNextPredecessor() || DepResult->getNextSuccessor())
1325 dbgs() <<
"TODO: Implement pred/succ dependence handling!\n");
1332 return dependencesAllowFusion(FC0, FC1, I0, I1, AnyDep,
1334 dependencesAllowFusion(FC0, FC1, I0, I1, AnyDep,
1342 bool dependencesAllowFusion(
const FusionCandidate &FC0,
1343 const FusionCandidate &FC1) {
1344 LLVM_DEBUG(
dbgs() <<
"Check if " << FC0 <<
" can be fused with " << FC1
1347 assert(DT.dominates(FC0.getEntryBlock(), FC1.getEntryBlock()));
1349 for (Instruction *WriteL0 : FC0.MemWrites) {
1350 for (Instruction *WriteL1 : FC1.MemWrites)
1351 if (!dependencesAllowFusion(FC0, FC1, *WriteL0, *WriteL1,
1354 InvalidDependencies++;
1357 for (Instruction *ReadL1 : FC1.MemReads)
1358 if (!dependencesAllowFusion(FC0, FC1, *WriteL0, *ReadL1,
1361 InvalidDependencies++;
1366 for (Instruction *WriteL1 : FC1.MemWrites) {
1367 for (Instruction *WriteL0 : FC0.MemWrites)
1368 if (!dependencesAllowFusion(FC0, FC1, *WriteL0, *WriteL1,
1371 InvalidDependencies++;
1374 for (Instruction *ReadL0 : FC0.MemReads)
1375 if (!dependencesAllowFusion(FC0, FC1, *ReadL0, *WriteL1,
1378 InvalidDependencies++;
1385 for (BasicBlock *BB : FC1.L->
blocks())
1386 for (Instruction &
I : *BB)
1387 for (
auto &
Op :
I.operands())
1390 InvalidDependencies++;
1408 bool isStrictlyAdjacent(
const FusionCandidate &FC0,
1409 const FusionCandidate &FC1)
const {
1411 if (FC0.GuardBranch)
1412 return DT.dominates(FC0.getEntryBlock(), FC1.getEntryBlock()) &&
1413 FC0.getNonLoopBlock() == FC1.getEntryBlock();
1415 return FC0.ExitBlock == FC1.getEntryBlock();
1418 bool isEmptyPreheader(
const FusionCandidate &FC)
const {
1419 return FC.Preheader->size() == 1;
1424 void movePreheaderInsts(
const FusionCandidate &FC0,
1425 const FusionCandidate &FC1,
1426 SmallVector<Instruction *, 4> &HoistInsts,
1427 SmallVector<Instruction *, 4> &SinkInsts)
const {
1430 "Attempting to sink and hoist preheader instructions, but not all "
1431 "the preheader instructions are accounted for.");
1433 NumHoistedInsts += HoistInsts.
size();
1434 NumSunkInsts += SinkInsts.
size();
1437 if (!HoistInsts.
empty())
1438 dbgs() <<
"Hoisting: \n";
1439 for (Instruction *
I : HoistInsts)
1440 dbgs() << *
I <<
"\n";
1441 if (!SinkInsts.
empty())
1442 dbgs() <<
"Sinking: \n";
1443 for (Instruction *
I : SinkInsts)
1444 dbgs() << *
I <<
"\n";
1447 for (Instruction *
I : HoistInsts) {
1448 assert(
I->getParent() == FC1.Preheader);
1449 I->moveBefore(*FC0.Preheader,
1453 for (Instruction *
I :
reverse(SinkInsts)) {
1454 assert(
I->getParent() == FC1.Preheader);
1459 fixPHINodes(SinkInsts, FC0, FC1);
1474 bool haveIdenticalGuards(
const FusionCandidate &FC0,
1475 const FusionCandidate &FC1)
const {
1476 assert(FC0.GuardBranch && FC1.GuardBranch &&
1477 "Expecting FC0 and FC1 to be guarded loops.");
1479 if (
auto FC0CmpInst =
1481 if (
auto FC1CmpInst =
1483 if (!FC0CmpInst->isIdenticalTo(FC1CmpInst))
1490 return (FC1.GuardBranch->
getSuccessor(0) == FC1.Preheader);
1492 return (FC1.GuardBranch->
getSuccessor(1) == FC1.Preheader);
1497 void simplifyLatchBranch(
const FusionCandidate &FC)
const {
1499 if (FCLatchBranch) {
1502 "Expecting the two successors of FCLatchBranch to be the same");
1503 BranchInst *NewBranch =
1511 void mergeLatch(
const FusionCandidate &FC0,
const FusionCandidate &FC1) {
1548 Loop *performFusion(
const FusionCandidate &FC0,
const FusionCandidate &FC1) {
1549 assert(FC0.isValid() && FC1.isValid() &&
1550 "Expecting valid fusion candidates");
1553 dbgs() <<
"Fusion Candidate 1: \n"; FC1.dump(););
1562 if (FC0.GuardBranch)
1563 return fuseGuardedLoops(FC0, FC1);
1580 if (FC0.ExitingBlock != FC0.Latch)
1581 for (PHINode &
PHI : FC0.Header->
phis())
1612 DominatorTree::Delete, FC0.ExitingBlock, FC1.Preheader));
1614 DominatorTree::Insert, FC0.ExitingBlock, FC1.Header));
1617 DominatorTree::Delete, FC0.ExitBlock, FC1.Preheader));
1623 DominatorTree::Delete, FC0.ExitingBlock, FC0.ExitBlock));
1626 DominatorTree::Insert, FC0.ExitingBlock, FC1.Header));
1627 new UnreachableInst(FC0.ExitBlock->
getContext(), FC0.ExitBlock);
1633 new UnreachableInst(FC1.Preheader->
getContext(), FC1.Preheader);
1635 DominatorTree::Delete, FC1.Preheader, FC1.Header));
1639 if (SE.isSCEVable(
PHI->getType()))
1640 SE.forgetValue(
PHI);
1641 if (
PHI->hasNUsesOrMore(1))
1644 PHI->eraseFromParent();
1652 for (PHINode *LCPHI : OriginalFC0PHIs) {
1653 int L1LatchBBIdx = LCPHI->getBasicBlockIndex(FC1.Latch);
1654 assert(L1LatchBBIdx >= 0 &&
1655 "Expected loop carried value to be rewired at this point!");
1657 Value *LCV = LCPHI->getIncomingValue(L1LatchBBIdx);
1659 PHINode *L1HeaderPHI =
1666 LCPHI->setIncomingValue(L1LatchBBIdx, L1HeaderPHI);
1675 simplifyLatchBranch(FC0);
1679 if (FC0.Latch != FC0.ExitingBlock)
1681 DominatorTree::Insert, FC0.Latch, FC1.Header));
1683 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Delete,
1684 FC0.Latch, FC0.Header));
1685 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Insert,
1686 FC1.Latch, FC0.Header));
1687 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Delete,
1688 FC1.Latch, FC1.Header));
1691 DTU.applyUpdates(TreeUpdates);
1693 LI.removeBlock(FC1.Preheader);
1694 DTU.deleteBB(FC1.Preheader);
1696 LI.removeBlock(FC0.ExitBlock);
1697 DTU.deleteBB(FC0.ExitBlock);
1706 SE.forgetLoop(FC1.L);
1707 SE.forgetLoop(FC0.L);
1711 mergeLatch(FC0, FC1);
1716 SE.forgetBlockAndLoopDispositions();
1719 SmallVector<BasicBlock *, 8> Blocks(FC1.L->
blocks());
1720 for (BasicBlock *BB : Blocks) {
1723 if (LI.getLoopFor(BB) != FC1.L)
1725 LI.changeLoopFor(BB, FC0.L);
1728 const auto &ChildLoopIt = FC1.L->
begin();
1729 Loop *ChildLoop = *ChildLoopIt;
1739 assert(DT.verify(DominatorTree::VerificationLevel::Fast));
1762 template <
typename RemarkKind>
1763 void reportLoopFusion(
const FusionCandidate &FC0,
const FusionCandidate &FC1,
1765 assert(FC0.Preheader && FC1.Preheader &&
1766 "Expecting valid fusion candidates");
1767 using namespace ore;
1768#if LLVM_ENABLE_STATS
1773 <<
"]: " <<
NV(
"Cand1", StringRef(FC0.Preheader->
getName()))
1774 <<
" and " <<
NV(
"Cand2", StringRef(FC1.Preheader->
getName()))
1775 <<
": " << Stat.getDesc());
1794 Loop *fuseGuardedLoops(
const FusionCandidate &FC0,
1795 const FusionCandidate &FC1) {
1796 assert(FC0.GuardBranch && FC1.GuardBranch &&
"Expecting guarded loops");
1800 BasicBlock *FC0NonLoopBlock = FC0.getNonLoopBlock();
1801 BasicBlock *FC1NonLoopBlock = FC1.getNonLoopBlock();
1809 (FC0.Peeled ? *FC0ExitBlockSuccessor : *FC0.ExitBlock), *FC1.ExitBlock,
1816 assert(FC0NonLoopBlock == FC1GuardBlock &&
"Loops are not adjacent");
1831 BasicBlock *BBToUpdate = FC0.Peeled ? FC0ExitBlockSuccessor : FC0.ExitBlock;
1836 new UnreachableInst(FC1GuardBlock->
getContext(), FC1GuardBlock);
1839 DominatorTree::Delete, FC1GuardBlock, FC1.Preheader));
1841 DominatorTree::Delete, FC1GuardBlock, FC1NonLoopBlock));
1843 DominatorTree::Delete, FC0GuardBlock, FC1GuardBlock));
1845 DominatorTree::Insert, FC0GuardBlock, FC1NonLoopBlock));
1850 DominatorTree::Delete, FC0ExitBlockSuccessor, FC1GuardBlock));
1852 new UnreachableInst(FC0ExitBlockSuccessor->
getContext(),
1853 FC0ExitBlockSuccessor);
1857 "Expecting guard block to have no predecessors");
1859 "Expecting guard block to have no successors");
1874 if (FC0.ExitingBlock != FC0.Latch)
1875 for (PHINode &
PHI : FC0.Header->
phis())
1878 assert(OriginalFC0PHIs.
empty() &&
"Expecting OriginalFC0PHIs to be empty!");
1901 DominatorTree::Delete, FC0.ExitingBlock, FC0.ExitBlock));
1903 DominatorTree::Insert, FC0.ExitingBlock, FC1.Header));
1914 new UnreachableInst(FC0.ExitBlock->
getContext(), FC0.ExitBlock);
1920 new UnreachableInst(FC1.Preheader->
getContext(), FC1.Preheader);
1922 DominatorTree::Delete, FC1.Preheader, FC1.Header));
1926 if (SE.isSCEVable(
PHI->getType()))
1927 SE.forgetValue(
PHI);
1928 if (
PHI->hasNUsesOrMore(1))
1931 PHI->eraseFromParent();
1939 for (PHINode *LCPHI : OriginalFC0PHIs) {
1940 int L1LatchBBIdx = LCPHI->getBasicBlockIndex(FC1.Latch);
1941 assert(L1LatchBBIdx >= 0 &&
1942 "Expected loop carried value to be rewired at this point!");
1944 Value *LCV = LCPHI->getIncomingValue(L1LatchBBIdx);
1946 PHINode *L1HeaderPHI =
1953 LCPHI->setIncomingValue(L1LatchBBIdx, L1HeaderPHI);
1964 simplifyLatchBranch(FC0);
1968 if (FC0.Latch != FC0.ExitingBlock)
1970 DominatorTree::Insert, FC0.Latch, FC1.Header));
1972 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Delete,
1973 FC0.Latch, FC0.Header));
1974 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Insert,
1975 FC1.Latch, FC0.Header));
1976 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Delete,
1977 FC1.Latch, FC1.Header));
1986 DTU.applyUpdates(TreeUpdates);
1988 LI.removeBlock(FC1GuardBlock);
1989 LI.removeBlock(FC1.Preheader);
1990 LI.removeBlock(FC0.ExitBlock);
1992 LI.removeBlock(FC0ExitBlockSuccessor);
1993 DTU.deleteBB(FC0ExitBlockSuccessor);
1995 DTU.deleteBB(FC1GuardBlock);
1996 DTU.deleteBB(FC1.Preheader);
1997 DTU.deleteBB(FC0.ExitBlock);
2004 SE.forgetLoop(FC1.L);
2005 SE.forgetLoop(FC0.L);
2009 mergeLatch(FC0, FC1);
2014 SE.forgetBlockAndLoopDispositions();
2017 SmallVector<BasicBlock *, 8> Blocks(FC1.L->
blocks());
2018 for (BasicBlock *BB : Blocks) {
2021 if (LI.getLoopFor(BB) != FC1.L)
2023 LI.changeLoopFor(BB, FC0.L);
2026 const auto &ChildLoopIt = FC1.L->
begin();
2027 Loop *ChildLoop = *ChildLoopIt;
2037 assert(DT.verify(DominatorTree::VerificationLevel::Fast));
2065 for (
auto &L : LI) {
2072 LoopFuser LF(LI, DT, DI, SE, PDT, ORE,
DL, AC,
TTI);
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static bool reportInvalidCandidate(const Instruction &I, llvm::Statistic &Stat)
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static void printFusionCandidates(const FusionCandidateCollection &FusionCandidates)
static cl::opt< FusionDependenceAnalysisChoice > FusionDependenceAnalysis("loop-fusion-dependence-analysis", cl::desc("Which dependence analysis should loop fusion use?"), cl::values(clEnumValN(FUSION_DEPENDENCE_ANALYSIS_SCEV, "scev", "Use the scalar evolution interface"), clEnumValN(FUSION_DEPENDENCE_ANALYSIS_DA, "da", "Use the dependence analysis interface"), clEnumValN(FUSION_DEPENDENCE_ANALYSIS_ALL, "all", "Use all available analyses")), cl::Hidden, cl::init(FUSION_DEPENDENCE_ANALYSIS_ALL))
std::list< FusionCandidate > FusionCandidateList
SmallVector< FusionCandidateList, 4 > FusionCandidateCollection
static void printLoopVector(const LoopVector &LV)
SmallVector< Loop *, 4 > LoopVector
FusionDependenceAnalysisChoice
@ FUSION_DEPENDENCE_ANALYSIS_DA
@ FUSION_DEPENDENCE_ANALYSIS_ALL
@ FUSION_DEPENDENCE_ANALYSIS_SCEV
static cl::opt< bool > VerboseFusionDebugging("loop-fusion-verbose-debug", cl::desc("Enable verbose debugging for Loop Fusion"), cl::Hidden, cl::init(false))
static cl::opt< unsigned > FusionPeelMaxCount("loop-fusion-peel-max-count", cl::init(0), cl::Hidden, cl::desc("Max number of iterations to be peeled from a loop, such that " "fusion can take place"))
This file implements the Loop Fusion pass.
Loop::LoopBounds::Direction Direction
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
void visit(MachineFunction &MF, MachineBasicBlock &Start, std::function< void(MachineBasicBlock *)> op)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Virtual Register Rewriter
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
A function analysis which provides an AssumptionCache.
LLVM Basic Block Representation.
LLVM_ABI void replaceSuccessorsPhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block's successors to refer to basic block New instead of basic bl...
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
LLVM_ABI const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
const Instruction & front() const
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 * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
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.
bool isConditional() const
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
BasicBlock * getSuccessor(unsigned i) const
Value * getCondition() const
A parsed version of the target data layout string in and methods for querying it.
AnalysisPass to compute dependence information in a function.
Analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Analysis pass that exposes the LoopInfo for a function.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
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.
BlockT * getHeader() const
unsigned getLoopDepth() const
Return the nesting level of this loop.
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.
LoopT * removeChildLoop(iterator I)
This removes the specified child from being a subloop of this loop.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
reverse_iterator rend() const
reverse_iterator rbegin() const
Represents a single loop in the control flow graph.
DebugLoc getStartLoc() const
Return the debug location of the start of this loop.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Analysis pass which computes a PostDominatorTree.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
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.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
const SCEV * getStart() const
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values.
const Loop * getLoop() const
NoWrapFlags getNoWrapFlags(NoWrapFlags Mask=NoWrapMask) const
ArrayRef< const SCEV * > operands() const
Analysis pass that exposes the ScalarEvolution for a function.
The main scalar evolution driver.
LLVM_ABI bool isKnownPositive(const SCEV *S)
Test if the given expression is known to be positive.
LLVM_ABI const SCEV * getAddRecExpr(const SCEV *Start, const SCEV *Step, const Loop *L, SCEV::NoWrapFlags Flags)
Get an add recurrence expression for the specified loop.
LLVM_ABI bool hasLoopInvariantBackedgeTakenCount(const Loop *L)
Return true if the specified loop has an analyzable loop-invariant backedge-taken count.
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetTransformInfo.
LLVM_ABI bool replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
const ParentTy * getParent() const
self_iterator getIterator()
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ BasicBlock
Various leaf nodes.
@ Valid
The data is already valid.
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)
Add a small namespace to avoid name clashes with the classes used in the streaming interface.
DiagnosticInfoOptimizationBase::Argument NV
NodeAddr< DefNode * > Def
NodeAddr< PhiNode * > Phi
LLVM_ABI iterator begin() const
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, AssumptionCache *AC, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
Simplify each loop in a loop nest recursively.
LLVM_ABI void ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI, Instruction *I)
Replace the instruction specified by BI with the instruction specified by I.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
FunctionAddr VTableAddr Value
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
bool succ_empty(const Instruction *I)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
const Value * getLoadStorePointerOperand(const Value *V)
A helper function that returns the pointer operand of a load or store instruction.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
bool canPeel(const Loop *L)
LLVM_ABI void moveInstructionsToTheEnd(BasicBlock &FromBB, BasicBlock &ToBB, DominatorTree &DT, const PostDominatorTree &PDT, DependenceInfo &DI)
Move instructions, in an order-preserving manner, from FromBB to the end of ToBB when proven safe.
auto reverse(ContainerTy &&C)
TargetTransformInfo::PeelingPreferences gatherPeelingPreferences(Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI, std::optional< bool > UserAllowPeeling, std::optional< bool > UserAllowProfileBasedPeeling, bool UnrollingSpecficValues=false)
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...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI void moveInstructionsToTheBeginning(BasicBlock &FromBB, BasicBlock &ToBB, DominatorTree &DT, const PostDominatorTree &PDT, DependenceInfo &DI)
Move instructions, in an order-preserving manner, from FromBB to the beginning of ToBB when proven sa...
LLVM_ABI bool MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, MemoryDependenceResults *MemDep=nullptr, bool PredecessorWithTwoSuccessors=false, DominatorTree *DT=nullptr)
Attempts to merge a block into its predecessor, if possible.
LLVM_ABI void printLoop(const Loop &L, raw_ostream &OS, const std::string &Banner="")
Function to print a loop's contents as LLVM's text IR assembly.
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
ArrayRef(const T &OneElt) -> ArrayRef< T >
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool pred_empty(const BasicBlock *BB)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint, DominatorTree &DT, const PostDominatorTree *PDT=nullptr, DependenceInfo *DI=nullptr, bool CheckForEntireBlock=false)
Return true if I can be safely moved before InsertPoint.
bool peelLoop(Loop *L, unsigned PeelCount, bool PeelLast, LoopInfo *LI, ScalarEvolution *SE, DominatorTree &DT, AssumptionCache *AC, bool PreserveLCSSA, ValueToValueMapTy &VMap)
VMap is the value-map that maps instructions from the original loop to instructions in the last peele...
bool SCEVExprContains(const SCEV *Root, PredTy Pred)
Return true if any node in Root satisfies the predicate Pred.