77#define DEBUG_TYPE "loop-fusion"
80STATISTIC(NumFusionCandidates,
"Number of candidates for loop fusion");
81STATISTIC(InvalidLoopStructure,
"Loop has invalid structure");
82STATISTIC(AddressTakenBB,
"Basic block has address taken");
83STATISTIC(MayThrowException,
"Loop may throw an exception");
84STATISTIC(ContainsVolatileAccess,
"Loop contains a volatile access");
85STATISTIC(ContainsAtomicAccess,
"Loop contains an atomic access");
86STATISTIC(NotSimplifiedForm,
"Loop is not in simplified form");
87STATISTIC(InvalidDependencies,
"Dependencies prevent fusion");
88STATISTIC(UnknownTripCount,
"Loop has unknown trip count");
89STATISTIC(UncomputableTripCount,
"SCEV cannot compute trip count of loop");
90STATISTIC(NonEqualTripCount,
"Loop trip counts are not the same");
93 "Loop has a non-empty preheader with instructions that cannot be moved");
95 "Fusion has insufficient cross-loop reused values");
96STATISTIC(NonIdenticalGuards,
"Candidates have different guards");
97STATISTIC(NonEmptyExitBlock,
"Candidate has a non-empty exit block with "
98 "instructions that cannot be moved");
99STATISTIC(NonEmptyGuardBlock,
"Candidate has a non-empty guard block with "
100 "instructions that cannot be moved");
103 "The second candidate is guarded while the first one is not");
104STATISTIC(NumHoistedInsts,
"Number of hoisted preheader instructions.");
105STATISTIC(NumSunkInsts,
"Number of sunk preheader instructions.");
122struct FusionCandidate {
160 : Preheader(L->getLoopPreheader()), Header(L->getHeader()),
161 ExitingBlock(L->getExitingBlock()), ExitBlock(L->getExitBlock()),
162 Latch(L->getLoopLatch()), L(L), Valid(
true),
163 GuardBranch(L->getLoopGuardBranch()), PP(PP), AbleToPeel(
canPeel(L)),
164 Peeled(
false), DT(DT), ORE(ORE) {
171 if (BB->hasAddressTaken()) {
174 reportInvalidCandidate(
"AddressTakenBB",
175 "Basic block has address taken");
184 "Loop may throw an exception");
187 if (
I.isVolatile()) {
189 ++ContainsVolatileAccess;
191 "Loop contains a volatile access");
199 ++ContainsAtomicAccess;
201 "Loop contains an atomic access");
204 if (
I.mayWriteToMemory())
205 MemWrites.push_back(&
I);
206 if (
I.mayReadFromMemory())
207 MemReads.push_back(&
I);
214 return Preheader && ExitingBlock && ExitBlock && Latch &&
L &&
221 assert(!
L->isInvalid() &&
"Loop is invalid!");
222 assert(Preheader ==
L->getLoopPreheader() &&
"Preheader is out of sync");
223 assert(Header ==
L->getHeader() &&
"Header is out of sync");
224 assert(ExitingBlock ==
L->getExitingBlock() &&
225 "Exiting Blocks is out of sync");
226 assert(ExitBlock ==
L->getExitBlock() &&
"Exit block is out of sync");
227 assert(Latch ==
L->getLoopLatch() &&
"Latch is out of sync");
243 void updateAfterPeeling() {
244 Preheader =
L->getLoopPreheader();
245 Header =
L->getHeader();
246 ExitingBlock =
L->getExitingBlock();
247 ExitBlock =
L->getExitBlock();
248 Latch =
L->getLoopLatch();
260 assert(GuardBranch &&
"Only valid on guarded loops.");
268#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
270 dbgs() <<
"\tGuardBranch: ";
272 dbgs() << *GuardBranch;
276 << (GuardBranch ? GuardBranch->
getName() :
"nullptr") <<
"\n"
277 <<
"\tPreheader: " << (Preheader ? Preheader->
getName() :
"nullptr")
279 <<
"\tHeader: " << (Header ? Header->getName() :
"nullptr") <<
"\n"
281 << (ExitingBlock ? ExitingBlock->
getName() :
"nullptr") <<
"\n"
282 <<
"\tExitBB: " << (ExitBlock ? ExitBlock->
getName() :
"nullptr")
284 <<
"\tLatch: " << (Latch ? Latch->
getName() :
"nullptr") <<
"\n"
286 << (getEntryBlock() ? getEntryBlock()->getName() :
"nullptr")
297 assert(Header &&
"Header should be guaranteed to exist!");
298 ++InvalidLoopStructure;
305 <<
" trip count not computable!\n");
308 "Loop has unknown trip count");
311 if (!
L->isLoopSimplifyForm()) {
313 <<
" is not in simplified form!\n");
316 "Loop is not in simplified form");
319 if (!
L->isRotatedForm()) {
348 L->getStartLoc(),
L->getHeader())
349 <<
"Loop is not a candidate for fusion");
352 L->getStartLoc(),
L->getHeader())
353 <<
"[" <<
L->getHeader()->getParent()->getName() <<
"]: "
354 <<
"Loop is not a candidate for fusion: " << RemarkMsg);
370 dbgs() <<
"****************************\n";
371 for (
const Loop *L : LV)
373 dbgs() <<
"****************************\n";
378 OS << FC.Preheader->getName();
387 for (
const FusionCandidate &FC : CandList)
395 dbgs() <<
"Fusion Candidates: \n";
396 for (
const auto &CandidateList : FusionCandidates) {
397 dbgs() <<
"*** Fusion Candidate List ***\n";
398 dbgs() << CandidateList;
399 dbgs() <<
"****************************\n";
426 if (!L->isLoopSimplifyForm() || !L->isRotatedForm())
429 BasicBlock *Preheader = L->getLoopPreheader();
430 BasicBlock *ExitBlock = L->getUniqueExitBlock();
442 BasicBlock *SkipBB = GuardBI->getSuccessor(0) == Preheader
443 ? GuardBI->getSuccessor(1)
444 : GuardBI->getSuccessor(0);
445 if (SkipBB == Preheader)
456 if (!MergeBB || MergeBB == SkipBB || MergeBB == GuardBB ||
467 <<
" of loop " << L->getHeader()->getName() <<
"\n");
470 GuardBI->replaceSuccessorWith(SkipBB, MergeBB);
492struct LoopDepthTree {
493 using LoopsOnLevelTy = SmallVector<LoopVector, 4>;
497 LoopDepthTree(LoopInfo &LI) : Depth(1) {
504 bool isRemovedLoop(
const Loop *L)
const {
return RemovedLoops.count(L); }
508 void removeLoop(
const Loop *L) { RemovedLoops.insert(L); }
512 LoopsOnLevelTy LoopsOnNextLevel;
516 if (!isRemovedLoop(L) &&
L->begin() !=
L->end())
517 LoopsOnNextLevel.emplace_back(
LoopVector(
L->begin(),
L->end()));
519 LoopsOnLevel = LoopsOnNextLevel;
520 RemovedLoops.clear();
524 bool empty()
const {
return size() == 0; }
525 size_t size()
const {
return LoopsOnLevel.size() - RemovedLoops.size(); }
526 unsigned getDepth()
const {
return Depth; }
528 iterator
begin() {
return LoopsOnLevel.begin(); }
529 iterator
end() {
return LoopsOnLevel.end(); }
530 const_iterator
begin()
const {
return LoopsOnLevel.begin(); }
531 const_iterator
end()
const {
return LoopsOnLevel.end(); }
536 SmallPtrSet<const Loop *, 8> RemovedLoops;
542 LoopsOnLevelTy LoopsOnLevel;
547 const ScalarOptions &Opts;
560 PostDominatorTree &PDT;
561 OptimizationRemarkEmitter &ORE;
563 const TargetTransformInfo &TTI;
566 LoopFuser(
const ScalarOptions &Opts, LoopInfo &LI, DominatorTree &DT,
567 DependenceInfo &DI, AAResults &AA, ScalarEvolution &SE,
568 PostDominatorTree &PDT, OptimizationRemarkEmitter &ORE,
569 AssumptionCache &AC,
const TargetTransformInfo &TTI)
570 : Opts(Opts), LDT(LI), DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Lazy),
571 LI(LI), DT(DT), DI(DI), AA(AA), SE(SE), PDT(PDT), ORE(ORE), AC(AC),
579 if (Opts.loop_fusion_verbose_debug) {
584 LLVM_DEBUG(
dbgs() <<
"Performing Loop Fusion on function " <<
F.getName()
588 while (!LDT.empty()) {
589 LLVM_DEBUG(
dbgs() <<
"Got " << LDT.size() <<
" loop sets for depth "
590 << LDT.getDepth() <<
"\n";);
593 assert(LV.size() > 0 &&
"Empty loop set was build!");
600 if (Opts.loop_fusion_verbose_debug) {
602 dbgs() <<
" Visit loop set (#" << LV.size() <<
"):\n";
608 collectFusionCandidates(LV);
613 FusionCandidates.clear();
639 void collectFusionCandidates(
const LoopVector &LV) {
643 FusionCandidate CurrCand(L, DT, ORE, PP);
644 if (!CurrCand.isEligibleForFusion(SE))
652 bool FoundAdjacent =
false;
653 for (
auto &CurrCandList : FusionCandidates) {
654 if (isStrictlyAdjacent(CurrCandList.back(), CurrCand)) {
655 CurrCandList.push_back(CurrCand);
656 FoundAdjacent =
true;
657 NumFusionCandidates++;
659 if (Opts.loop_fusion_verbose_debug)
661 <<
" to existing candidate list\n");
666 if (!FoundAdjacent) {
669 if (Opts.loop_fusion_verbose_debug)
673 NewCandList.push_back(CurrCand);
674 FusionCandidates.push_back(NewCandList);
680 bool isBeneficialFusion(
unsigned ReusedValueCount)
const {
681 if (Opts.loop_fusion_disable_cost_model)
683 return ReusedValueCount >= Opts.loop_fusion_min_reused_values;
691 std::optional<int64_t>
692 calculateTripCountDiff(
const FusionCandidate &FC0,
693 const FusionCandidate &FC1)
const {
694 const SCEV *TripCount0 = SE.getBackedgeTakenCount(FC0.L);
696 UncomputableTripCount++;
697 LLVM_DEBUG(
dbgs() <<
"Trip count of first loop could not be computed!");
701 const SCEV *TripCount1 = SE.getBackedgeTakenCount(FC1.L);
703 UncomputableTripCount++;
704 LLVM_DEBUG(
dbgs() <<
"Trip count of second loop could not be computed!");
709 << *TripCount1 <<
" are "
710 << (TripCount0 == TripCount1 ?
"identical" :
"different")
713 if (TripCount0 == TripCount1)
717 "determining the difference between trip counts\n");
724 static_cast<int64_t
>(SE.getSmallConstantTripCount(FC0.L));
726 static_cast<int64_t
>(SE.getSmallConstantTripCount(FC1.L));
730 if (TC0 == 0 || TC1 == 0) {
731 LLVM_DEBUG(
dbgs() <<
"Loop(s) do not have a single exit point or do not "
732 "have a constant number of iterations. Peeling "
733 "is not benefical\n");
740 void peelFusionCandidate(FusionCandidate &FC0,
const FusionCandidate &FC1,
741 unsigned PeelCount) {
742 assert(FC0.AbleToPeel &&
"Should be able to peel loop");
745 <<
" iterations of the first loop. \n");
751 peelLoop(FC0.L, PeelCount,
false, &LI, &SE, DT, &AC,
757 auto TCDiff = calculateTripCountDiff(FC0, FC1);
759 assert(TCDiff && *TCDiff == 0 &&
760 "Loops should have identical trip counts after peeling");
766 PDT.recalculate(*FC0.Preheader->
getParent());
768 FC0.updateAfterPeeling();
782 SmallVector<Instruction *, 8> WorkList;
784 if (
Pred != FC0.ExitBlock) {
787 DominatorTree::UpdateType(DominatorTree::Delete,
Pred, BB));
792 for (Instruction *CurrentBranch : WorkList) {
793 BasicBlock *Succ = CurrentBranch->getSuccessor(0);
795 Succ = CurrentBranch->getSuccessor(1);
799 DTU.applyUpdates(TreeUpdates);
804 <<
" iterations from the first loop.\n"
805 "Both Loops have the same number of iterations now.\n");
815 bool fuseCandidates() {
818 for (
auto &CandidateList : FusionCandidates) {
819 if (CandidateList.size() < 2)
823 << CandidateList <<
"\n");
825 for (
auto It = CandidateList.begin(), NextIt = std::next(It);
826 NextIt != CandidateList.end(); It = NextIt, NextIt = std::next(It)) {
828 const FusionCandidate &FC0 = *It;
829 const FusionCandidate &FC1 = *NextIt;
831 assert(!LDT.isRemovedLoop(FC0.L) &&
832 "Should not have removed loops in CandidateList!");
833 assert(!LDT.isRemovedLoop(FC1.L) &&
834 "Should not have removed loops in CandidateList!");
836 LLVM_DEBUG(
dbgs() <<
"Attempting to fuse candidate \n"; FC0.dump();
837 dbgs() <<
" with\n"; FC1.dump();
dbgs() <<
"\n");
842 std::optional<int64_t> TCDifference = calculateTripCountDiff(FC0, FC1);
847 bool WillPeel = FC0.AbleToPeel && TCDifference && *TCDifference > 0 &&
848 *TCDifference <= static_cast<int64_t>(
849 Opts.loop_fusion_peel_max_count);
851 if (!WillPeel && (!TCDifference || *TCDifference != 0)) {
852 LLVM_DEBUG(
dbgs() <<
"Fusion candidates do not have identical trip "
853 "counts and peeling is not supported for this "
854 "case. Not fusing.\n");
856 reportLoopFusion<OptimizationRemarkMissed>(
857 FC0, FC1,
"NonEqualTripCount",
858 "Loop trip counts are not the same");
862 if ((!FC0.GuardBranch && FC1.GuardBranch) ||
863 (FC0.GuardBranch && !FC1.GuardBranch)) {
865 "another one is not. Not fusing.\n");
866 ++OnlySecondCandidateIsGuarded;
867 reportLoopFusion<OptimizationRemarkMissed>(
868 FC0, FC1,
"OnlySecondCandidateIsGuarded",
869 "The second candidate is guarded while the first one is not");
879 if (FC0.GuardBranch && FC1.GuardBranch &&
880 !haveIdenticalGuards(FC0, FC1)) {
882 "guards. Not Fusing.\n");
883 ++NonIdenticalGuards;
884 reportLoopFusion<OptimizationRemarkMissed>(
885 FC0, FC1,
"NonIdenticalGuards",
886 "Candidates have different guards");
890 if (FC0.GuardBranch) {
891 assert(FC1.GuardBranch &&
"Expecting valid FC1 guard branch");
897 "instructions in exit block. Not fusing.\n");
899 reportLoopFusion<OptimizationRemarkMissed>(
900 FC0, FC1,
"NonEmptyExitBlock",
901 "Candidate has a non-empty exit block with "
902 "instructions that cannot be moved");
908 *FC0.GuardBranch->
getParent()->getTerminator(), DT, &PDT,
911 "instructions in guard block. Not fusing.\n");
912 ++NonEmptyGuardBlock;
913 reportLoopFusion<OptimizationRemarkMissed>(
914 FC0, FC1,
"NonEmptyGuardBlock",
915 "Candidate has a non-empty guard block with "
916 "instructions that cannot be moved");
923 ReusedValueSet ReusedValues;
924 if (!dependencesAllowFusion(FC0, FC1, &ReusedValues)) {
925 LLVM_DEBUG(
dbgs() <<
"Memory dependencies do not allow fusion!\n");
926 ++InvalidDependencies;
927 reportLoopFusion<OptimizationRemarkMissed>(
928 FC0, FC1,
"InvalidDependencies",
"Dependencies prevent fusion");
935 SmallVector<Instruction *, 4> SafeToHoist;
936 SmallVector<Instruction *, 4> SafeToSink;
940 if (!isEmptyPreheader(FC1)) {
946 if (!collectMovablePreheaderInsts(FC0, FC1, SafeToHoist,
949 "Fusion Candidate Pre-header.\n"
952 reportLoopFusion<OptimizationRemarkMissed>(
953 FC0, FC1,
"NonEmptyPreheader",
954 "Loop has a non-empty preheader with instructions that "
960 unsigned ReusedValueCount = ReusedValues.size();
961 bool BeneficialToFuse = isBeneficialFusion(ReusedValueCount);
963 << (BeneficialToFuse ?
"" :
"un") <<
"profitable!\n");
964 if (!BeneficialToFuse) {
966 reportFusionInsufficientReuse(FC0, FC1, ReusedValueCount);
975 movePreheaderInsts(FC0, FC1, SafeToHoist, SafeToSink);
977 LLVM_DEBUG(
dbgs() <<
"\tFusion is performed: " << FC0 <<
" and " << FC1
980 FusionCandidate FC0Copy = FC0;
983 bool Peel = TCDifference && *TCDifference > 0;
985 peelFusionCandidate(FC0Copy, FC1, *TCDifference);
992 reportLoopFusion<OptimizationRemark>((Peel ? FC0Copy : FC0), FC1,
993 "FuseCounter",
"Loops fused");
995 FusionCandidate FusedCand(performFusion((Peel ? FC0Copy : FC0), FC1),
996 DT, ORE, FC0Copy.PP);
998 assert(FusedCand.isEligibleForFusion(SE) &&
999 "Fused candidate should be eligible for fusion!");
1002 LDT.removeLoop(FC1.L);
1005 It = CandidateList.erase(It);
1006 It = CandidateList.erase(It);
1007 It = CandidateList.insert(It, FusedCand);
1012 LLVM_DEBUG(
dbgs() <<
"Candidate List (after fusion): " << CandidateList
1026 bool canHoistInst(Instruction &
I,
1027 const SmallVector<Instruction *, 4> &SafeToHoist,
1028 const SmallVector<Instruction *, 4> &NotHoisting,
1029 const FusionCandidate &FC0)
const {
1031 assert(FC0PreheaderTarget &&
1032 "Expected single successor for loop preheader.");
1034 for (Use &
Op :
I.operands()) {
1039 if (!(OpHoisted || DT.dominates(OpInst, FC0PreheaderTarget))) {
1051 if (!
I.mayReadOrWriteMemory())
1054 LLVM_DEBUG(
dbgs() <<
"Checking if this mem inst can be hoisted.\n");
1055 for (Instruction *NotHoistedInst : NotHoisting) {
1056 if (
auto D = DI.depends(&
I, NotHoistedInst)) {
1059 if (
D->isFlow() ||
D->isAnti() ||
D->isOutput()) {
1061 "preheader that is not being hoisted.\n");
1067 for (Instruction *ReadInst : FC0.MemReads) {
1068 if (
auto D = DI.depends(ReadInst, &
I)) {
1071 LLVM_DEBUG(
dbgs() <<
"Inst depends on a read instruction in FC0.\n");
1077 for (Instruction *WriteInst : FC0.MemWrites) {
1078 if (
auto D = DI.depends(WriteInst, &
I)) {
1080 if (
D->isFlow() ||
D->isOutput()) {
1081 LLVM_DEBUG(
dbgs() <<
"Inst depends on a write instruction in FC0.\n");
1092 bool canSinkInst(Instruction &
I,
const FusionCandidate &FC1)
const {
1093 for (Instruction *UI :
I.users()) {
1104 if (!
I.mayReadOrWriteMemory())
1107 for (Instruction *ReadInst : FC1.MemReads) {
1108 if (
auto D = DI.depends(&
I, ReadInst)) {
1111 LLVM_DEBUG(
dbgs() <<
"Inst depends on a read instruction in FC1.\n");
1117 for (Instruction *WriteInst : FC1.MemWrites) {
1118 if (
auto D = DI.depends(&
I, WriteInst)) {
1120 if (
D->isOutput() ||
D->isAnti()) {
1121 LLVM_DEBUG(
dbgs() <<
"Inst depends on a write instruction in FC1.\n");
1132 bool collectMovablePreheaderInsts(
1133 const FusionCandidate &FC0,
const FusionCandidate &FC1,
1134 SmallVector<Instruction *, 4> &SafeToHoist,
1135 SmallVector<Instruction *, 4> &SafeToSink)
const {
1139 SmallVector<Instruction *, 4> NotHoisting;
1141 for (Instruction &
I : *FC1Preheader) {
1143 if (&
I == FC1Preheader->getTerminator())
1149 if (
I.mayThrow() || !
I.willReturn()) {
1150 LLVM_DEBUG(
dbgs() <<
"Inst: " <<
I <<
" may throw or won't return.\n");
1156 if (
I.isAtomic() ||
I.isVolatile()) {
1158 dbgs() <<
"\tInstruction is volatile or atomic. Cannot move it.\n");
1162 if (canHoistInst(
I, SafeToHoist, NotHoisting, FC0)) {
1169 if (canSinkInst(
I, FC1)) {
1179 dbgs() <<
"All preheader instructions could be sunk or hoisted!\n");
1183 using AffineLoadKey = std::tuple<const SCEV *, const SCEV *>;
1185 std::optional<AffineLoadKey> getAffineLoadKey(
const FusionCandidate &FC,
1189 return std::nullopt;
1193 if (!AR || AR->getLoop() !=
FC.L || !AR->isAffine())
1194 return std::nullopt;
1196 return AffineLoadKey{AR->getStart(), AR->getStepRecurrence(SE)};
1201 bool isKnownBefore(
const Instruction *
A,
const Instruction *
B,
1202 const Loop *L)
const {
1203 return LI.getLoopFor(
A->getParent()) ==
L &&
1204 LI.getLoopFor(
B->getParent()) ==
L && DT.dominates(
A,
B);
1209 bool hasInterveningWrite(BatchAAResults &BAA,
const LoadInst &Load0,
1210 const LoadInst &Load1,
const FusionCandidate &FC0,
1211 const FusionCandidate &FC1)
const {
1219 for (Instruction *
Write : FC0.MemWrites)
1220 if (!isKnownBefore(
Write, &Load0, FC0.L) && MayModify(
Write))
1222 for (Instruction *
Write : FC1.MemWrites)
1223 if (!isKnownBefore(&Load1,
Write, FC1.L) && MayModify(
Write))
1232 void collectReadReadReuse(
const FusionCandidate &FC0,
1233 const FusionCandidate &FC1,
1234 ReusedValueSet &ReusedValues) {
1235 if (ReusedValues.size() >= Opts.loop_fusion_min_reused_values)
1238 BatchAAResults BAA(AA);
1239 SmallDenseMap<AffineLoadKey, Instruction *, 8> LoadAccesses0;
1240 for (Instruction *ReadL0 : FC0.MemReads) {
1241 std::optional<AffineLoadKey>
Key = getAffineLoadKey(FC0, *ReadL0);
1248 for (Instruction *ReadL1 : FC1.MemReads) {
1249 std::optional<AffineLoadKey>
Key = getAffineLoadKey(FC1, *ReadL1);
1259 if (hasInterveningWrite(BAA, *Load0, *Load1, FC0, FC1))
1262 ReusedValues.insert(MatchingLoad);
1264 << *MatchingLoad <<
"\n");
1265 if (ReusedValues.size() >= Opts.loop_fusion_min_reused_values)
1272 bool dependencesAllowFusion(
const FusionCandidate &FC0,
1273 const FusionCandidate &FC1, Instruction &I0,
1275 ReusedValueSet *ReusedValues =
nullptr) {
1277 if (Opts.loop_fusion_verbose_debug) {
1278 LLVM_DEBUG(
dbgs() <<
"Check dep: " << I0 <<
" vs " << I1 <<
"\n");
1281 auto DepResult = DI.depends(&I0, &I1);
1289 if (S0->getValueOperand() ==
S1->getValueOperand())
1293 if (Opts.loop_fusion_verbose_debug) {
1295 dbgs() <<
" [#l: " << DepResult->getLevels() <<
"][Ordered: "
1296 << (DepResult->isOrdered() ?
"true" :
"false")
1298 LLVM_DEBUG(
dbgs() <<
"DepResult Levels: " << DepResult->getLevels()
1302 unsigned Levels = DepResult->getLevels();
1303 unsigned SameSDLevels = DepResult->getSameSDLevels();
1307 if (CurLoopLevel > Levels + SameSDLevels)
1311 for (
unsigned Level = 1;
Level <= std::min(CurLoopLevel - 1, Levels);
1313 unsigned Direction = DepResult->getDirection(Level,
false);
1319 LLVM_DEBUG(
dbgs() <<
"Safe to fuse due to non-equal acceses in the "
1326 assert(CurLoopLevel > Levels &&
"Fusion candidates are not separated");
1328 unsigned CurDir = DepResult->getDirection(CurLoopLevel,
true);
1330 if (ReusedValues && !DepResult->isConfused() && DepResult->isFlow() &&
1332 ReusedValues->insert(&I0);
1336 if (DepResult->isScalar(CurLoopLevel,
true)) {
1337 if (DepResult->isInput() || DepResult->isOutput()) {
1339 << (DepResult->isInput() ?
"input" :
"output")
1340 <<
" dependency\n");
1353 LLVM_DEBUG(
dbgs() <<
"Safe to fuse same-iteration scalar dependence\n");
1358 dbgs() <<
"Not safe to fuse due to a scalar flow dependency\n");
1370 LLVM_DEBUG(
dbgs() <<
"Safe to fuse with no backward loop-carried "
1376 if (DepResult->getNextPredecessor() || DepResult->getNextSuccessor())
1377 LLVM_DEBUG(
dbgs() <<
"TODO: Implement pred/succ dependence handling!\n");
1383 bool dependencesAllowFusion(
const FusionCandidate &FC0,
1384 const FusionCandidate &FC1,
1385 ReusedValueSet *ReusedValues) {
1386 LLVM_DEBUG(
dbgs() <<
"Check if " << FC0 <<
" can be fused with " << FC1
1389 assert(DT.dominates(FC0.getEntryBlock(), FC1.getEntryBlock()));
1393 for (BasicBlock *BB : FC1.L->
blocks())
1394 for (Instruction &
I : *BB)
1395 for (
auto &
Op :
I.operands())
1401 for (Instruction *WriteL0 : FC0.MemWrites) {
1402 for (Instruction *WriteL1 : FC1.MemWrites)
1403 if (!dependencesAllowFusion(FC0, FC1, *WriteL0, *WriteL1)) {
1406 for (Instruction *ReadL1 : FC1.MemReads)
1407 if (!dependencesAllowFusion(FC0, FC1, *WriteL0, *ReadL1,
1415 for (Instruction *ReadL0 : FC0.MemReads)
1416 for (Instruction *WriteL1 : FC1.MemWrites)
1417 if (!dependencesAllowFusion(FC0, FC1, *ReadL0, *WriteL1)) {
1421 if (ReusedValues && !Opts.loop_fusion_disable_cost_model)
1422 collectReadReadReuse(FC0, FC1, *ReusedValues);
1439 bool isStrictlyAdjacent(
const FusionCandidate &FC0,
1440 const FusionCandidate &FC1)
const {
1442 if (FC0.GuardBranch)
1443 return DT.dominates(FC0.getEntryBlock(), FC1.getEntryBlock()) &&
1445 return FC0.ExitBlock == FC1.getEntryBlock();
1448 bool isEmptyPreheader(
const FusionCandidate &FC)
const {
1449 return FC.Preheader->size() == 1;
1454 void movePreheaderInsts(
const FusionCandidate &FC0,
1455 const FusionCandidate &FC1,
1456 SmallVector<Instruction *, 4> &HoistInsts,
1457 SmallVector<Instruction *, 4> &SinkInsts)
const {
1460 "Attempting to sink and hoist preheader instructions, but not all "
1461 "the preheader instructions are accounted for.");
1463 NumHoistedInsts += HoistInsts.
size();
1464 NumSunkInsts += SinkInsts.
size();
1466 LLVM_DEBUG(
if (Opts.loop_fusion_verbose_debug) {
1467 if (!HoistInsts.empty())
1468 dbgs() <<
"Hoisting: \n";
1469 for (Instruction *I : HoistInsts)
1470 dbgs() << *I <<
"\n";
1471 if (!SinkInsts.empty())
1472 dbgs() <<
"Sinking: \n";
1473 for (Instruction *I : SinkInsts)
1474 dbgs() << *I <<
"\n";
1477 for (Instruction *
I : HoistInsts) {
1478 assert(
I->getParent() == FC1.Preheader);
1479 I->moveBefore(*FC0.Preheader,
1483 for (Instruction *
I :
reverse(SinkInsts)) {
1484 assert(
I->getParent() == FC1.Preheader);
1492 "Expected the sunk PHI node to have 1 incoming value.");
1493 I->replaceAllUsesWith(
I->getOperand(0));
1494 I->eraseFromParent();
1501 for (User *U :
I->users()) {
1503 if (!PN || PN->getParent() != FC1.ExitBlock)
1509 assert(PN->getNumIncomingValues() == 1 &&
1510 PN->getIncomingValue(0) ==
I &&
1511 "Expected a single-input exit phi forwarding the sunk value");
1514 for (PHINode *PN : ExitPhis) {
1515 PN->replaceAllUsesWith(
I);
1516 PN->eraseFromParent();
1535 bool haveIdenticalGuards(
const FusionCandidate &FC0,
1536 const FusionCandidate &FC1)
const {
1537 assert(FC0.GuardBranch && FC1.GuardBranch &&
1538 "Expecting FC0 and FC1 to be guarded loops.");
1542 if ((!FC0CmpInst || !FC1CmpInst) &&
1546 if (FC0CmpInst && FC1CmpInst && !FC0CmpInst->isIdenticalTo(FC1CmpInst))
1553 return (FC1.GuardBranch->
getSuccessor(0) == FC1.Preheader);
1554 return (FC1.GuardBranch->
getSuccessor(1) == FC1.Preheader);
1559 void simplifyLatchBranch(
const FusionCandidate &FC)
const {
1561 if (FCLatchBranch) {
1563 "Expecting the two successors of FCLatchBranch to be the same");
1564 UncondBrInst *NewBranch =
1572 void mergeLatch(
const FusionCandidate &FC0,
const FusionCandidate &FC1) {
1584 void rewireFusedHeaderPHIsAndLatches(
1585 const FusionCandidate &FC0,
const FusionCandidate &FC1,
1586 const SmallVectorImpl<PHINode *> &OriginalFC0PHIs,
1587 SmallVectorImpl<DominatorTree::UpdateType> &TreeUpdates) {
1590 if (SE.isSCEVable(
PHI->getType()))
1591 SE.forgetValue(
PHI);
1592 if (
PHI->hasNUsesOrMore(1))
1595 PHI->eraseFromParent();
1603 for (PHINode *LCPHI : OriginalFC0PHIs) {
1604 int L1LatchBBIdx = LCPHI->getBasicBlockIndex(FC1.Latch);
1605 assert(L1LatchBBIdx >= 0 &&
1606 "Expected loop carried value to be rewired at this point!");
1608 Value *LCV = LCPHI->getIncomingValue(L1LatchBBIdx);
1610 PHINode *L1HeaderPHI =
1617 LCPHI->setIncomingValue(L1LatchBBIdx, L1HeaderPHI);
1626 simplifyLatchBranch(FC0);
1630 if (FC0.Latch != FC0.ExitingBlock)
1632 DominatorTree::Insert, FC0.Latch, FC1.Header));
1634 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Delete,
1635 FC0.Latch, FC0.Header));
1636 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Insert,
1637 FC1.Latch, FC0.Header));
1638 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Delete,
1639 FC1.Latch, FC1.Header));
1645 Loop *finalizeFusedLoop(
const FusionCandidate &FC0,
1646 const FusionCandidate &FC1) {
1651 SE.forgetLoop(FC1.L);
1652 SE.forgetLoop(FC0.L);
1655 SmallVector<BasicBlock *, 8> Blocks(FC1.L->
blocks());
1656 for (BasicBlock *BB : Blocks) {
1659 if (LI.getLoopFor(BB) != FC1.L)
1661 LI.changeLoopFor(BB, FC0.L);
1664 const auto &ChildLoopIt = FC1.L->
begin();
1665 Loop *ChildLoop = *ChildLoopIt;
1676 SE.forgetBlockAndLoopDispositions();
1680 mergeLatch(FC0, FC1);
1684 assert(DT.verify(DominatorTree::VerificationLevel::Fast));
1724 Loop *performFusion(
const FusionCandidate &FC0,
const FusionCandidate &FC1) {
1725 assert(FC0.isValid() && FC1.isValid() &&
1726 "Expecting valid fusion candidates");
1729 dbgs() <<
"Fusion Candidate 1: \n"; FC1.dump(););
1738 if (FC0.GuardBranch)
1739 return fuseGuardedLoops(FC0, FC1);
1756 if (FC0.ExitingBlock != FC0.Latch)
1757 for (PHINode &
PHI : FC0.Header->
phis())
1788 DominatorTree::Delete, FC0.ExitingBlock, FC1.Preheader));
1790 DominatorTree::Insert, FC0.ExitingBlock, FC1.Header));
1793 DominatorTree::Delete, FC0.ExitBlock, FC1.Preheader));
1799 DominatorTree::Delete, FC0.ExitingBlock, FC0.ExitBlock));
1802 DominatorTree::Insert, FC0.ExitingBlock, FC1.Header));
1803 new UnreachableInst(FC0.ExitBlock->
getContext(), FC0.ExitBlock);
1809 new UnreachableInst(FC1.Preheader->
getContext(), FC1.Preheader);
1811 DominatorTree::Delete, FC1.Preheader, FC1.Header));
1813 rewireFusedHeaderPHIsAndLatches(FC0, FC1, OriginalFC0PHIs, TreeUpdates);
1816 DTU.applyUpdates(TreeUpdates);
1818 LI.removeBlock(FC1.Preheader);
1819 DTU.deleteBB(FC1.Preheader);
1821 LI.removeBlock(FC0.ExitBlock);
1822 DTU.deleteBB(FC0.ExitBlock);
1827 return finalizeFusedLoop(FC0, FC1);
1842 template <
typename RemarkKind>
1843 void reportLoopFusion(
const FusionCandidate &FC0,
const FusionCandidate &FC1,
1844 StringRef RemarkName, StringRef RemarkMsg) {
1845 assert(FC0.Preheader && FC1.Preheader &&
1846 "Expecting valid fusion candidates");
1847 using namespace ore;
1851 <<
"]: " <<
NV(
"Cand1", StringRef(FC0.Preheader->
getName())) <<
" and "
1852 <<
NV(
"Cand2", StringRef(FC1.Preheader->
getName())) <<
": "
1856 void reportFusionInsufficientReuse(
const FusionCandidate &FC0,
1857 const FusionCandidate &FC1,
1858 unsigned ReusedValueCount) {
1859 assert(ReusedValueCount < Opts.loop_fusion_min_reused_values &&
1860 "Expected insufficient reuse");
1862 using namespace ore;
1863 ORE.emit(OptimizationRemarkMissed(
DEBUG_TYPE,
"InsufficientReuse",
1866 <<
"]: " <<
NV(
"Cand1", StringRef(FC0.Preheader->
getName()))
1867 <<
" and " <<
NV(
"Cand2", StringRef(FC1.Preheader->
getName()))
1868 <<
": found " <<
NV(
"ReusedValueCount", ReusedValueCount)
1869 <<
" cross-loop reused values; configured minimum is "
1870 <<
NV(
"MinimumReusedValues",
1871 unsigned(Opts.loop_fusion_min_reused_values)));
1889 Loop *fuseGuardedLoops(
const FusionCandidate &FC0,
1890 const FusionCandidate &FC1) {
1891 assert(FC0.GuardBranch && FC1.GuardBranch &&
"Expecting guarded loops");
1895 BasicBlock *FC0NonLoopBlock = FC0.getNonLoopBlock();
1896 BasicBlock *FC1NonLoopBlock = FC1.getNonLoopBlock();
1904 (FC0.Peeled ? *FC0ExitBlockSuccessor : *FC0.ExitBlock), *FC1.ExitBlock,
1911 assert(FC0NonLoopBlock == FC1GuardBlock &&
"Loops are not adjacent");
1926 BasicBlock *BBToUpdate = FC0.Peeled ? FC0ExitBlockSuccessor : FC0.ExitBlock;
1931 new UnreachableInst(FC1GuardBlock->
getContext(), FC1GuardBlock);
1934 DominatorTree::Delete, FC1GuardBlock, FC1.Preheader));
1936 DominatorTree::Delete, FC1GuardBlock, FC1NonLoopBlock));
1938 DominatorTree::Delete, FC0GuardBlock, FC1GuardBlock));
1940 DominatorTree::Insert, FC0GuardBlock, FC1NonLoopBlock));
1944 DominatorTree::Delete, FC0.ExitBlock, FC0ExitBlockSuccessor));
1947 DominatorTree::Delete, FC0ExitBlockSuccessor, FC1GuardBlock));
1949 new UnreachableInst(FC0ExitBlockSuccessor->
getContext(),
1950 FC0ExitBlockSuccessor);
1954 "Expecting guard block to have no predecessors");
1956 "Expecting guard block to have no successors");
1971 if (FC0.ExitingBlock != FC0.Latch)
1972 for (PHINode &
PHI : FC0.Header->
phis())
1975 assert(OriginalFC0PHIs.
empty() &&
"Expecting OriginalFC0PHIs to be empty!");
1998 DominatorTree::Delete, FC0.ExitingBlock, FC0.ExitBlock));
2000 DominatorTree::Insert, FC0.ExitingBlock, FC1.Header));
2011 new UnreachableInst(FC0.ExitBlock->
getContext(), FC0.ExitBlock);
2017 new UnreachableInst(FC1.Preheader->
getContext(), FC1.Preheader);
2019 DominatorTree::Delete, FC1.Preheader, FC1.Header));
2021 rewireFusedHeaderPHIsAndLatches(FC0, FC1, OriginalFC0PHIs, TreeUpdates);
2030 DTU.applyUpdates(TreeUpdates);
2032 LI.removeBlock(FC1GuardBlock);
2033 LI.removeBlock(FC1.Preheader);
2034 LI.removeBlock(FC0.ExitBlock);
2036 LI.removeBlock(FC0ExitBlockSuccessor);
2037 DTU.deleteBB(FC0ExitBlockSuccessor);
2039 DTU.deleteBB(FC1GuardBlock);
2040 DTU.deleteBB(FC1.Preheader);
2041 DTU.deleteBB(FC0.ExitBlock);
2044 return finalizeFusedLoop(FC0, FC1);
2065 for (
auto &L : LI) {
2069 for (
Loop *L : LI.getLoopsInPreorder()) {
2077 LoopFuser LF(Opts, LI, DT, DI,
AA, SE, PDT, ORE, AC,
TTI);
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static bool reportInvalidCandidate(const Instruction &I, llvm::Statistic &Stat)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines the DenseMap class.
static void printFusionCandidates(const FusionCandidateCollection &FusionCandidates)
std::list< FusionCandidate > FusionCandidateList
static bool simplifyLoopGuard(Loop *L, DomTreeUpdater &DTU, LoopInfo &LI, ScalarEvolution &SE)
Fold away an empty block on the "skip" edge of L's loop guard, if any.
SmallVector< FusionCandidateList, 4 > FusionCandidateCollection
static void printLoopVector(const LoopVector &LV)
SmallVector< Loop *, 4 > LoopVector
This file implements the Loop Fusion pass.
Loop::LoopBounds::Direction Direction
This file defines the interface for the loop nest analysis.
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
This file defines the SmallPtrSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A manager for alias analyses.
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.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
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 * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
LLVM_ABI const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrPseudoProbe() const
Returns an iterator to the first instruction in this block that is not a PHINode or a pseudo operatio...
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; assumes that the block is well-formed.
ModRefInfo getModRefInfo(const Instruction *I, const std::optional< MemoryLocation > &OptLoc)
Conditional Branch instruction.
Value * getCondition() const
BasicBlock * getSuccessor(unsigned i) const
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
AnalysisPass to compute dependence information in a function.
LLVM_ABI void deleteBB(BasicBlock *DelBB)
Delete DelBB.
Analysis pass which computes a DominatorTree.
static constexpr UpdateKind Delete
static constexpr UpdateKind Insert
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
void applyUpdates(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
void flush()
Apply all pending updates to available trees and flush all BasicBlocks awaiting deletion.
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 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.
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.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
reverse_iterator rend() const
void removeBlock(BlockT *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
bool isLoopHeader(const BlockT *BB) const
reverse_iterator rbegin() const
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).
Represents a single loop in the control flow graph.
LLVM_ABI DebugLoc getStartLoc() const
Return the debug location of the start of this loop.
static LLVM_ABI MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
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.
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.
Analysis pass that exposes the ScalarEvolution for a function.
The main scalar evolution driver.
LLVM_ABI bool hasLoopInvariantBackedgeTakenCount(const Loop *L)
Return true if the specified loop has an analyzable loop-invariant backedge-taken count.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
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.
Represent a constant reference to a string, i.e.
Analysis pass providing the TargetTransformInfo.
static UncondBrInst * Create(BasicBlock *Target, InsertPosition InsertBefore=nullptr)
This function has undefined behavior.
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.
Abstract Attribute helper functions.
@ BasicBlock
Various leaf nodes.
@ Valid
The data is already valid.
Add a small namespace to avoid name clashes with the classes used in the streaming interface.
DiagnosticInfoOptimizationBase::Argument NV
NodeAddr< DefNode * > Def
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI iterator begin() const
This is an optimization pass for GlobalISel generic memory operations.
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)
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.
@ Load
The value being inserted comes from a load (InsertElement only).
LLVM_ABI void moveInstructionsToTheEnd(BasicBlock &FromBB, BasicBlock &ToBB, DominatorTree &DT, const PostDominatorTree &PDT, DependenceInfo &DI, ScalarEvolution &SE)
Move instructions, in an order-preserving manner, from FromBB to the end of ToBB when proven safe.
LLVM_ABI void moveInstructionsToTheBeginning(BasicBlock &FromBB, BasicBlock &ToBB, DominatorTree &DT, const PostDominatorTree &PDT, DependenceInfo &DI, ScalarEvolution &SE)
Move instructions, in an order-preserving manner, from FromBB to the beginning of ToBB when proven sa...
LLVM_ABI bool canPeel(const Loop *L)
const ScalarOptions & getScalarOptions(const LLVMContext &C)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, AssumptionCache *AC, MemorySSAUpdater *MSSAU, bool PreserveLCSSA, const TargetTransformInfo *TTI=nullptr)
Simplify each loop in a loop nest recursively.
auto reverse(ContainerTy &&C)
LLVM_ABI TargetTransformInfo::PeelingPreferences gatherPeelingPreferences(Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI, std::optional< bool > UserAllowPeeling, std::optional< bool > UserAllowProfileBasedPeeling, bool UnrollingSpecficValues=false)
bool isModSet(const ModRefInfo MRI)
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_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI void 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...
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)
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
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.