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 {
161 : Preheader(L->getLoopPreheader()), Header(L->getHeader()),
162 ExitingBlock(L->getExitingBlock()), ExitBlock(L->getExitBlock()),
163 Latch(L->getLoopLatch()), L(L), Valid(
true),
164 GuardBranch(L->getLoopGuardBranch()), PP(PP), AbleToPeel(
canPeel(L)),
165 Peeled(
false), DT(DT), PDT(PDT), ORE(ORE) {
172 if (BB->hasAddressTaken()) {
175 reportInvalidCandidate(
"AddressTakenBB",
176 "Basic block has address taken");
185 "Loop may throw an exception");
188 if (
I.isVolatile()) {
190 ++ContainsVolatileAccess;
192 "Loop contains a volatile access");
200 ++ContainsAtomicAccess;
202 "Loop contains an atomic access");
205 if (
I.mayWriteToMemory())
206 MemWrites.push_back(&
I);
207 if (
I.mayReadFromMemory())
208 MemReads.push_back(&
I);
215 return Preheader && ExitingBlock && ExitBlock && Latch &&
L &&
222 assert(!
L->isInvalid() &&
"Loop is invalid!");
223 assert(Preheader ==
L->getLoopPreheader() &&
"Preheader is out of sync");
224 assert(Header ==
L->getHeader() &&
"Header is out of sync");
225 assert(ExitingBlock ==
L->getExitingBlock() &&
226 "Exiting Blocks is out of sync");
227 assert(ExitBlock ==
L->getExitBlock() &&
"Exit block is out of sync");
228 assert(Latch ==
L->getLoopLatch() &&
"Latch is out of sync");
244 void updateAfterPeeling() {
245 Preheader =
L->getLoopPreheader();
246 Header =
L->getHeader();
247 ExitingBlock =
L->getExitingBlock();
248 ExitBlock =
L->getExitBlock();
249 Latch =
L->getLoopLatch();
261 assert(GuardBranch &&
"Only valid on guarded loops.");
269#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
271 dbgs() <<
"\tGuardBranch: ";
273 dbgs() << *GuardBranch;
277 << (GuardBranch ? GuardBranch->
getName() :
"nullptr") <<
"\n"
278 <<
"\tPreheader: " << (Preheader ? Preheader->
getName() :
"nullptr")
280 <<
"\tHeader: " << (Header ? Header->getName() :
"nullptr") <<
"\n"
282 << (ExitingBlock ? ExitingBlock->
getName() :
"nullptr") <<
"\n"
283 <<
"\tExitBB: " << (ExitBlock ? ExitBlock->
getName() :
"nullptr")
285 <<
"\tLatch: " << (Latch ? Latch->
getName() :
"nullptr") <<
"\n"
287 << (getEntryBlock() ? getEntryBlock()->getName() :
"nullptr")
298 assert(Header &&
"Header should be guaranteed to exist!");
299 ++InvalidLoopStructure;
306 <<
" trip count not computable!\n");
309 "Loop has unknown trip count");
312 if (!
L->isLoopSimplifyForm()) {
314 <<
" is not in simplified form!\n");
317 "Loop is not in simplified form");
320 if (!
L->isRotatedForm()) {
349 L->getStartLoc(),
L->getHeader())
350 <<
"Loop is not a candidate for fusion");
353 L->getStartLoc(),
L->getHeader())
354 <<
"[" <<
L->getHeader()->getParent()->getName() <<
"]: "
355 <<
"Loop is not a candidate for fusion: " << RemarkMsg);
371 dbgs() <<
"****************************\n";
372 for (
const Loop *L : LV)
374 dbgs() <<
"****************************\n";
379 OS << FC.Preheader->getName();
388 for (
const FusionCandidate &FC : CandList)
396 dbgs() <<
"Fusion Candidates: \n";
397 for (
const auto &CandidateList : FusionCandidates) {
398 dbgs() <<
"*** Fusion Candidate List ***\n";
399 dbgs() << CandidateList;
400 dbgs() <<
"****************************\n";
427 if (!L->isLoopSimplifyForm() || !L->isRotatedForm())
430 BasicBlock *Preheader = L->getLoopPreheader();
431 BasicBlock *ExitBlock = L->getUniqueExitBlock();
443 BasicBlock *SkipBB = GuardBI->getSuccessor(0) == Preheader
444 ? GuardBI->getSuccessor(1)
445 : GuardBI->getSuccessor(0);
446 if (SkipBB == Preheader)
457 if (!MergeBB || MergeBB == SkipBB || MergeBB == GuardBB ||
468 <<
" of loop " << L->getHeader()->getName() <<
"\n");
471 GuardBI->replaceSuccessorWith(SkipBB, MergeBB);
493struct LoopDepthTree {
494 using LoopsOnLevelTy = SmallVector<LoopVector, 4>;
498 LoopDepthTree(LoopInfo &LI) : Depth(1) {
505 bool isRemovedLoop(
const Loop *L)
const {
return RemovedLoops.count(L); }
509 void removeLoop(
const Loop *L) { RemovedLoops.insert(L); }
513 LoopsOnLevelTy LoopsOnNextLevel;
517 if (!isRemovedLoop(L) &&
L->begin() !=
L->end())
518 LoopsOnNextLevel.emplace_back(
LoopVector(
L->begin(),
L->end()));
520 LoopsOnLevel = LoopsOnNextLevel;
521 RemovedLoops.clear();
525 bool empty()
const {
return size() == 0; }
526 size_t size()
const {
return LoopsOnLevel.size() - RemovedLoops.size(); }
527 unsigned getDepth()
const {
return Depth; }
529 iterator
begin() {
return LoopsOnLevel.begin(); }
530 iterator
end() {
return LoopsOnLevel.end(); }
531 const_iterator
begin()
const {
return LoopsOnLevel.begin(); }
532 const_iterator
end()
const {
return LoopsOnLevel.end(); }
537 SmallPtrSet<const Loop *, 8> RemovedLoops;
543 LoopsOnLevelTy LoopsOnLevel;
548 const ScalarOptions &Opts;
561 PostDominatorTree &PDT;
562 OptimizationRemarkEmitter &ORE;
564 const TargetTransformInfo &TTI;
567 LoopFuser(
const ScalarOptions &Opts, LoopInfo &LI, DominatorTree &DT,
568 DependenceInfo &DI, AAResults &AA, ScalarEvolution &SE,
569 PostDominatorTree &PDT, OptimizationRemarkEmitter &ORE,
570 AssumptionCache &AC,
const TargetTransformInfo &TTI)
571 : Opts(Opts), LDT(LI), DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Lazy),
572 LI(LI), DT(DT), DI(DI), AA(AA), SE(SE), PDT(PDT), ORE(ORE), AC(AC),
580 if (Opts.loop_fusion_verbose_debug) {
585 LLVM_DEBUG(
dbgs() <<
"Performing Loop Fusion on function " <<
F.getName()
589 while (!LDT.empty()) {
590 LLVM_DEBUG(
dbgs() <<
"Got " << LDT.size() <<
" loop sets for depth "
591 << LDT.getDepth() <<
"\n";);
594 assert(LV.size() > 0 &&
"Empty loop set was build!");
601 if (Opts.loop_fusion_verbose_debug) {
603 dbgs() <<
" Visit loop set (#" << LV.size() <<
"):\n";
609 collectFusionCandidates(LV);
614 FusionCandidates.clear();
640 void collectFusionCandidates(
const LoopVector &LV) {
644 FusionCandidate CurrCand(L, DT, &PDT, ORE, PP);
645 if (!CurrCand.isEligibleForFusion(SE))
653 bool FoundAdjacent =
false;
654 for (
auto &CurrCandList : FusionCandidates) {
655 if (isStrictlyAdjacent(CurrCandList.back(), CurrCand)) {
656 CurrCandList.push_back(CurrCand);
657 FoundAdjacent =
true;
658 NumFusionCandidates++;
660 if (Opts.loop_fusion_verbose_debug)
662 <<
" to existing candidate list\n");
667 if (!FoundAdjacent) {
670 if (Opts.loop_fusion_verbose_debug)
674 NewCandList.push_back(CurrCand);
675 FusionCandidates.push_back(NewCandList);
681 bool isBeneficialFusion(
unsigned ReusedValueCount)
const {
682 if (Opts.loop_fusion_disable_cost_model)
684 return ReusedValueCount >= Opts.loop_fusion_min_reused_values;
692 std::optional<int64_t>
693 calculateTripCountDiff(
const FusionCandidate &FC0,
694 const FusionCandidate &FC1)
const {
695 const SCEV *TripCount0 = SE.getBackedgeTakenCount(FC0.L);
697 UncomputableTripCount++;
698 LLVM_DEBUG(
dbgs() <<
"Trip count of first loop could not be computed!");
702 const SCEV *TripCount1 = SE.getBackedgeTakenCount(FC1.L);
704 UncomputableTripCount++;
705 LLVM_DEBUG(
dbgs() <<
"Trip count of second loop could not be computed!");
710 << *TripCount1 <<
" are "
711 << (TripCount0 == TripCount1 ?
"identical" :
"different")
714 if (TripCount0 == TripCount1)
718 "determining the difference between trip counts\n");
725 static_cast<int64_t
>(SE.getSmallConstantTripCount(FC0.L));
727 static_cast<int64_t
>(SE.getSmallConstantTripCount(FC1.L));
731 if (TC0 == 0 || TC1 == 0) {
732 LLVM_DEBUG(
dbgs() <<
"Loop(s) do not have a single exit point or do not "
733 "have a constant number of iterations. Peeling "
734 "is not benefical\n");
741 void peelFusionCandidate(FusionCandidate &FC0,
const FusionCandidate &FC1,
742 unsigned PeelCount) {
743 assert(FC0.AbleToPeel &&
"Should be able to peel loop");
746 <<
" iterations of the first loop. \n");
752 peelLoop(FC0.L, PeelCount,
false, &LI, &SE, DT, &AC,
758 auto TCDiff = calculateTripCountDiff(FC0, FC1);
760 assert(TCDiff && *TCDiff == 0 &&
761 "Loops should have identical trip counts after peeling");
767 PDT.recalculate(*FC0.Preheader->
getParent());
769 FC0.updateAfterPeeling();
783 SmallVector<Instruction *, 8> WorkList;
785 if (Pred != FC0.ExitBlock) {
788 DominatorTree::UpdateType(DominatorTree::Delete, Pred, BB));
793 for (Instruction *CurrentBranch : WorkList) {
794 BasicBlock *Succ = CurrentBranch->getSuccessor(0);
796 Succ = CurrentBranch->getSuccessor(1);
800 DTU.applyUpdates(TreeUpdates);
805 <<
" iterations from the first loop.\n"
806 "Both Loops have the same number of iterations now.\n");
816 bool fuseCandidates() {
819 for (
auto &CandidateList : FusionCandidates) {
820 if (CandidateList.size() < 2)
824 << CandidateList <<
"\n");
826 for (
auto It = CandidateList.begin(), NextIt = std::next(It);
827 NextIt != CandidateList.end(); It = NextIt, NextIt = std::next(It)) {
829 const FusionCandidate &FC0 = *It;
830 const FusionCandidate &FC1 = *NextIt;
832 assert(!LDT.isRemovedLoop(FC0.L) &&
833 "Should not have removed loops in CandidateList!");
834 assert(!LDT.isRemovedLoop(FC1.L) &&
835 "Should not have removed loops in CandidateList!");
837 LLVM_DEBUG(
dbgs() <<
"Attempting to fuse candidate \n"; FC0.dump();
838 dbgs() <<
" with\n"; FC1.dump();
dbgs() <<
"\n");
843 std::optional<int64_t> TCDifference = calculateTripCountDiff(FC0, FC1);
848 bool WillPeel = FC0.AbleToPeel && TCDifference && *TCDifference > 0 &&
849 *TCDifference <= static_cast<int64_t>(
850 Opts.loop_fusion_peel_max_count);
852 if (!WillPeel && (!TCDifference || *TCDifference != 0)) {
853 LLVM_DEBUG(
dbgs() <<
"Fusion candidates do not have identical trip "
854 "counts and peeling is not supported for this "
855 "case. Not fusing.\n");
857 reportLoopFusion<OptimizationRemarkMissed>(
858 FC0, FC1,
"NonEqualTripCount",
859 "Loop trip counts are not the same");
863 if ((!FC0.GuardBranch && FC1.GuardBranch) ||
864 (FC0.GuardBranch && !FC1.GuardBranch)) {
866 "another one is not. Not fusing.\n");
867 ++OnlySecondCandidateIsGuarded;
868 reportLoopFusion<OptimizationRemarkMissed>(
869 FC0, FC1,
"OnlySecondCandidateIsGuarded",
870 "The second candidate is guarded while the first one is not");
880 if (FC0.GuardBranch && FC1.GuardBranch &&
881 !haveIdenticalGuards(FC0, FC1)) {
883 "guards. Not Fusing.\n");
884 ++NonIdenticalGuards;
885 reportLoopFusion<OptimizationRemarkMissed>(
886 FC0, FC1,
"NonIdenticalGuards",
887 "Candidates have different guards");
891 if (FC0.GuardBranch) {
892 assert(FC1.GuardBranch &&
"Expecting valid FC1 guard branch");
898 "instructions in exit block. Not fusing.\n");
900 reportLoopFusion<OptimizationRemarkMissed>(
901 FC0, FC1,
"NonEmptyExitBlock",
902 "Candidate has a non-empty exit block with "
903 "instructions that cannot be moved");
909 *FC0.GuardBranch->
getParent()->getTerminator(), DT, &PDT,
912 "instructions in guard block. Not fusing.\n");
913 ++NonEmptyGuardBlock;
914 reportLoopFusion<OptimizationRemarkMissed>(
915 FC0, FC1,
"NonEmptyGuardBlock",
916 "Candidate has a non-empty guard block with "
917 "instructions that cannot be moved");
924 ReusedValueSet ReusedValues;
925 if (!dependencesAllowFusion(FC0, FC1, &ReusedValues)) {
926 LLVM_DEBUG(
dbgs() <<
"Memory dependencies do not allow fusion!\n");
927 ++InvalidDependencies;
928 reportLoopFusion<OptimizationRemarkMissed>(
929 FC0, FC1,
"InvalidDependencies",
"Dependencies prevent fusion");
936 SmallVector<Instruction *, 4> SafeToHoist;
937 SmallVector<Instruction *, 4> SafeToSink;
941 if (!isEmptyPreheader(FC1)) {
947 if (!collectMovablePreheaderInsts(FC0, FC1, SafeToHoist,
950 "Fusion Candidate Pre-header.\n"
953 reportLoopFusion<OptimizationRemarkMissed>(
954 FC0, FC1,
"NonEmptyPreheader",
955 "Loop has a non-empty preheader with instructions that "
961 unsigned ReusedValueCount = ReusedValues.size();
962 bool BeneficialToFuse = isBeneficialFusion(ReusedValueCount);
964 << (BeneficialToFuse ?
"" :
"un") <<
"profitable!\n");
965 if (!BeneficialToFuse) {
967 reportFusionInsufficientReuse(FC0, FC1, ReusedValueCount);
976 movePreheaderInsts(FC0, FC1, SafeToHoist, SafeToSink);
978 LLVM_DEBUG(
dbgs() <<
"\tFusion is performed: " << FC0 <<
" and " << FC1
981 FusionCandidate FC0Copy = FC0;
984 bool Peel = TCDifference && *TCDifference > 0;
986 peelFusionCandidate(FC0Copy, FC1, *TCDifference);
993 reportLoopFusion<OptimizationRemark>((Peel ? FC0Copy : FC0), FC1,
994 "FuseCounter",
"Loops fused");
996 FusionCandidate FusedCand(performFusion((Peel ? FC0Copy : FC0), FC1),
997 DT, &PDT, ORE, FC0Copy.PP);
999 assert(FusedCand.isEligibleForFusion(SE) &&
1000 "Fused candidate should be eligible for fusion!");
1003 LDT.removeLoop(FC1.L);
1006 It = CandidateList.erase(It);
1007 It = CandidateList.erase(It);
1008 It = CandidateList.insert(It, FusedCand);
1013 LLVM_DEBUG(
dbgs() <<
"Candidate List (after fusion): " << CandidateList
1027 bool canHoistInst(Instruction &
I,
1028 const SmallVector<Instruction *, 4> &SafeToHoist,
1029 const SmallVector<Instruction *, 4> &NotHoisting,
1030 const FusionCandidate &FC0)
const {
1032 assert(FC0PreheaderTarget &&
1033 "Expected single successor for loop preheader.");
1035 for (Use &
Op :
I.operands()) {
1040 if (!(OpHoisted || DT.dominates(OpInst, FC0PreheaderTarget))) {
1052 if (!
I.mayReadOrWriteMemory())
1055 LLVM_DEBUG(
dbgs() <<
"Checking if this mem inst can be hoisted.\n");
1056 for (Instruction *NotHoistedInst : NotHoisting) {
1057 if (
auto D = DI.depends(&
I, NotHoistedInst)) {
1060 if (
D->isFlow() ||
D->isAnti() ||
D->isOutput()) {
1062 "preheader that is not being hoisted.\n");
1068 for (Instruction *ReadInst : FC0.MemReads) {
1069 if (
auto D = DI.depends(ReadInst, &
I)) {
1072 LLVM_DEBUG(
dbgs() <<
"Inst depends on a read instruction in FC0.\n");
1078 for (Instruction *WriteInst : FC0.MemWrites) {
1079 if (
auto D = DI.depends(WriteInst, &
I)) {
1081 if (
D->isFlow() ||
D->isOutput()) {
1082 LLVM_DEBUG(
dbgs() <<
"Inst depends on a write instruction in FC0.\n");
1093 bool canSinkInst(Instruction &
I,
const FusionCandidate &FC1)
const {
1094 for (User *U :
I.users()) {
1107 if (!
I.mayReadOrWriteMemory())
1110 for (Instruction *ReadInst : FC1.MemReads) {
1111 if (
auto D = DI.depends(&
I, ReadInst)) {
1114 LLVM_DEBUG(
dbgs() <<
"Inst depends on a read instruction in FC1.\n");
1120 for (Instruction *WriteInst : FC1.MemWrites) {
1121 if (
auto D = DI.depends(&
I, WriteInst)) {
1123 if (
D->isOutput() ||
D->isAnti()) {
1124 LLVM_DEBUG(
dbgs() <<
"Inst depends on a write instruction in FC1.\n");
1135 bool collectMovablePreheaderInsts(
1136 const FusionCandidate &FC0,
const FusionCandidate &FC1,
1137 SmallVector<Instruction *, 4> &SafeToHoist,
1138 SmallVector<Instruction *, 4> &SafeToSink)
const {
1142 SmallVector<Instruction *, 4> NotHoisting;
1144 for (Instruction &
I : *FC1Preheader) {
1146 if (&
I == FC1Preheader->getTerminator())
1152 if (
I.mayThrow() || !
I.willReturn()) {
1153 LLVM_DEBUG(
dbgs() <<
"Inst: " <<
I <<
" may throw or won't return.\n");
1159 if (
I.isAtomic() ||
I.isVolatile()) {
1161 dbgs() <<
"\tInstruction is volatile or atomic. Cannot move it.\n");
1165 if (canHoistInst(
I, SafeToHoist, NotHoisting, FC0)) {
1172 if (canSinkInst(
I, FC1)) {
1182 dbgs() <<
"All preheader instructions could be sunk or hoisted!\n");
1186 using AffineLoadKey = std::tuple<const SCEV *, const SCEV *>;
1188 std::optional<AffineLoadKey> getAffineLoadKey(
const FusionCandidate &FC,
1192 return std::nullopt;
1196 if (!AR || AR->getLoop() !=
FC.L || !AR->isAffine())
1197 return std::nullopt;
1199 return AffineLoadKey{AR->getStart(), AR->getStepRecurrence(SE)};
1204 bool isKnownBefore(
const Instruction *
A,
const Instruction *
B,
1205 const Loop *L)
const {
1206 return LI.getLoopFor(
A->getParent()) ==
L &&
1207 LI.getLoopFor(
B->getParent()) ==
L && DT.dominates(
A,
B);
1212 bool hasInterveningWrite(BatchAAResults &BAA,
const LoadInst &Load0,
1213 const LoadInst &Load1,
const FusionCandidate &FC0,
1214 const FusionCandidate &FC1)
const {
1222 for (Instruction *
Write : FC0.MemWrites)
1223 if (!isKnownBefore(
Write, &Load0, FC0.L) && MayModify(
Write))
1225 for (Instruction *
Write : FC1.MemWrites)
1226 if (!isKnownBefore(&Load1,
Write, FC1.L) && MayModify(
Write))
1235 void collectReadReadReuse(
const FusionCandidate &FC0,
1236 const FusionCandidate &FC1,
1237 ReusedValueSet &ReusedValues) {
1238 if (ReusedValues.size() >= Opts.loop_fusion_min_reused_values)
1241 BatchAAResults BAA(AA);
1242 SmallDenseMap<AffineLoadKey, Instruction *, 8> LoadAccesses0;
1243 for (Instruction *ReadL0 : FC0.MemReads) {
1244 std::optional<AffineLoadKey>
Key = getAffineLoadKey(FC0, *ReadL0);
1251 for (Instruction *ReadL1 : FC1.MemReads) {
1252 std::optional<AffineLoadKey>
Key = getAffineLoadKey(FC1, *ReadL1);
1262 if (hasInterveningWrite(BAA, *Load0, *Load1, FC0, FC1))
1265 ReusedValues.insert(MatchingLoad);
1267 << *MatchingLoad <<
"\n");
1268 if (ReusedValues.size() >= Opts.loop_fusion_min_reused_values)
1275 bool dependencesAllowFusion(
const FusionCandidate &FC0,
1276 const FusionCandidate &FC1, Instruction &I0,
1278 ReusedValueSet *ReusedValues =
nullptr) {
1280 if (Opts.loop_fusion_verbose_debug) {
1281 LLVM_DEBUG(
dbgs() <<
"Check dep: " << I0 <<
" vs " << I1 <<
"\n");
1284 auto DepResult = DI.depends(&I0, &I1);
1292 if (S0->getValueOperand() ==
S1->getValueOperand())
1296 if (Opts.loop_fusion_verbose_debug) {
1298 dbgs() <<
" [#l: " << DepResult->getLevels() <<
"][Ordered: "
1299 << (DepResult->isOrdered() ?
"true" :
"false")
1301 LLVM_DEBUG(
dbgs() <<
"DepResult Levels: " << DepResult->getLevels()
1305 unsigned Levels = DepResult->getLevels();
1306 unsigned SameSDLevels = DepResult->getSameSDLevels();
1310 if (CurLoopLevel > Levels + SameSDLevels)
1314 for (
unsigned Level = 1;
Level <= std::min(CurLoopLevel - 1, Levels);
1316 unsigned Direction = DepResult->getDirection(Level,
false);
1322 LLVM_DEBUG(
dbgs() <<
"Safe to fuse due to non-equal acceses in the "
1329 assert(CurLoopLevel > Levels &&
"Fusion candidates are not separated");
1331 unsigned CurDir = DepResult->getDirection(CurLoopLevel,
true);
1333 if (ReusedValues && !DepResult->isConfused() && DepResult->isFlow() &&
1335 ReusedValues->insert(&I0);
1339 if (DepResult->isScalar(CurLoopLevel,
true)) {
1340 if (DepResult->isInput() || DepResult->isOutput()) {
1342 << (DepResult->isInput() ?
"input" :
"output")
1343 <<
" dependency\n");
1356 LLVM_DEBUG(
dbgs() <<
"Safe to fuse same-iteration scalar dependence\n");
1361 dbgs() <<
"Not safe to fuse due to a scalar flow dependency\n");
1373 LLVM_DEBUG(
dbgs() <<
"Safe to fuse with no backward loop-carried "
1379 if (DepResult->getNextPredecessor() || DepResult->getNextSuccessor())
1380 LLVM_DEBUG(
dbgs() <<
"TODO: Implement pred/succ dependence handling!\n");
1386 bool dependencesAllowFusion(
const FusionCandidate &FC0,
1387 const FusionCandidate &FC1,
1388 ReusedValueSet *ReusedValues) {
1389 LLVM_DEBUG(
dbgs() <<
"Check if " << FC0 <<
" can be fused with " << FC1
1392 assert(DT.dominates(FC0.getEntryBlock(), FC1.getEntryBlock()));
1396 for (BasicBlock *BB : FC1.L->
blocks())
1397 for (Instruction &
I : *BB)
1398 for (
auto &
Op :
I.operands())
1404 for (Instruction *WriteL0 : FC0.MemWrites) {
1405 for (Instruction *WriteL1 : FC1.MemWrites)
1406 if (!dependencesAllowFusion(FC0, FC1, *WriteL0, *WriteL1)) {
1409 for (Instruction *ReadL1 : FC1.MemReads)
1410 if (!dependencesAllowFusion(FC0, FC1, *WriteL0, *ReadL1,
1418 for (Instruction *ReadL0 : FC0.MemReads)
1419 for (Instruction *WriteL1 : FC1.MemWrites)
1420 if (!dependencesAllowFusion(FC0, FC1, *ReadL0, *WriteL1)) {
1424 if (ReusedValues && !Opts.loop_fusion_disable_cost_model)
1425 collectReadReadReuse(FC0, FC1, *ReusedValues);
1442 bool isStrictlyAdjacent(
const FusionCandidate &FC0,
1443 const FusionCandidate &FC1)
const {
1445 if (FC0.GuardBranch)
1446 return DT.dominates(FC0.getEntryBlock(), FC1.getEntryBlock()) &&
1448 return FC0.ExitBlock == FC1.getEntryBlock();
1451 bool isEmptyPreheader(
const FusionCandidate &FC)
const {
1452 return FC.Preheader->size() == 1;
1457 void movePreheaderInsts(
const FusionCandidate &FC0,
1458 const FusionCandidate &FC1,
1459 SmallVector<Instruction *, 4> &HoistInsts,
1460 SmallVector<Instruction *, 4> &SinkInsts)
const {
1463 "Attempting to sink and hoist preheader instructions, but not all "
1464 "the preheader instructions are accounted for.");
1466 NumHoistedInsts += HoistInsts.
size();
1467 NumSunkInsts += SinkInsts.
size();
1469 LLVM_DEBUG(
if (Opts.loop_fusion_verbose_debug) {
1470 if (!HoistInsts.empty())
1471 dbgs() <<
"Hoisting: \n";
1472 for (Instruction *I : HoistInsts)
1473 dbgs() << *I <<
"\n";
1474 if (!SinkInsts.empty())
1475 dbgs() <<
"Sinking: \n";
1476 for (Instruction *I : SinkInsts)
1477 dbgs() << *I <<
"\n";
1480 for (Instruction *
I : HoistInsts) {
1481 assert(
I->getParent() == FC1.Preheader);
1482 I->moveBefore(*FC0.Preheader,
1486 for (Instruction *
I :
reverse(SinkInsts)) {
1487 assert(
I->getParent() == FC1.Preheader);
1495 "Expected the sunk PHI node to have 1 incoming value.");
1496 I->replaceAllUsesWith(
I->getOperand(0));
1497 I->eraseFromParent();
1515 bool haveIdenticalGuards(
const FusionCandidate &FC0,
1516 const FusionCandidate &FC1)
const {
1517 assert(FC0.GuardBranch && FC1.GuardBranch &&
1518 "Expecting FC0 and FC1 to be guarded loops.");
1522 if ((!FC0CmpInst || !FC1CmpInst) &&
1526 if (FC0CmpInst && FC1CmpInst && !FC0CmpInst->isIdenticalTo(FC1CmpInst))
1533 return (FC1.GuardBranch->
getSuccessor(0) == FC1.Preheader);
1534 return (FC1.GuardBranch->
getSuccessor(1) == FC1.Preheader);
1539 void simplifyLatchBranch(
const FusionCandidate &FC)
const {
1541 if (FCLatchBranch) {
1543 "Expecting the two successors of FCLatchBranch to be the same");
1544 UncondBrInst *NewBranch =
1552 void mergeLatch(
const FusionCandidate &FC0,
const FusionCandidate &FC1) {
1564 void rewireFusedHeaderPHIsAndLatches(
1565 const FusionCandidate &FC0,
const FusionCandidate &FC1,
1566 const SmallVectorImpl<PHINode *> &OriginalFC0PHIs,
1567 SmallVectorImpl<DominatorTree::UpdateType> &TreeUpdates) {
1570 if (SE.isSCEVable(
PHI->getType()))
1571 SE.forgetValue(
PHI);
1572 if (
PHI->hasNUsesOrMore(1))
1575 PHI->eraseFromParent();
1583 for (PHINode *LCPHI : OriginalFC0PHIs) {
1584 int L1LatchBBIdx = LCPHI->getBasicBlockIndex(FC1.Latch);
1585 assert(L1LatchBBIdx >= 0 &&
1586 "Expected loop carried value to be rewired at this point!");
1588 Value *LCV = LCPHI->getIncomingValue(L1LatchBBIdx);
1590 PHINode *L1HeaderPHI =
1597 LCPHI->setIncomingValue(L1LatchBBIdx, L1HeaderPHI);
1606 simplifyLatchBranch(FC0);
1610 if (FC0.Latch != FC0.ExitingBlock)
1612 DominatorTree::Insert, FC0.Latch, FC1.Header));
1614 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Delete,
1615 FC0.Latch, FC0.Header));
1616 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Insert,
1617 FC1.Latch, FC0.Header));
1618 TreeUpdates.
emplace_back(DominatorTree::UpdateType(DominatorTree::Delete,
1619 FC1.Latch, FC1.Header));
1625 Loop *finalizeFusedLoop(
const FusionCandidate &FC0,
1626 const FusionCandidate &FC1) {
1631 SE.forgetLoop(FC1.L);
1632 SE.forgetLoop(FC0.L);
1635 SmallVector<BasicBlock *, 8> Blocks(FC1.L->
blocks());
1636 for (BasicBlock *BB : Blocks) {
1639 if (LI.getLoopFor(BB) != FC1.L)
1641 LI.changeLoopFor(BB, FC0.L);
1644 const auto &ChildLoopIt = FC1.L->
begin();
1645 Loop *ChildLoop = *ChildLoopIt;
1656 SE.forgetBlockAndLoopDispositions();
1660 mergeLatch(FC0, FC1);
1664 assert(DT.verify(DominatorTree::VerificationLevel::Fast));
1704 Loop *performFusion(
const FusionCandidate &FC0,
const FusionCandidate &FC1) {
1705 assert(FC0.isValid() && FC1.isValid() &&
1706 "Expecting valid fusion candidates");
1709 dbgs() <<
"Fusion Candidate 1: \n"; FC1.dump(););
1718 if (FC0.GuardBranch)
1719 return fuseGuardedLoops(FC0, FC1);
1736 if (FC0.ExitingBlock != FC0.Latch)
1737 for (PHINode &
PHI : FC0.Header->
phis())
1768 DominatorTree::Delete, FC0.ExitingBlock, FC1.Preheader));
1770 DominatorTree::Insert, FC0.ExitingBlock, FC1.Header));
1773 DominatorTree::Delete, FC0.ExitBlock, FC1.Preheader));
1779 DominatorTree::Delete, FC0.ExitingBlock, FC0.ExitBlock));
1782 DominatorTree::Insert, FC0.ExitingBlock, FC1.Header));
1783 new UnreachableInst(FC0.ExitBlock->
getContext(), FC0.ExitBlock);
1789 new UnreachableInst(FC1.Preheader->
getContext(), FC1.Preheader);
1791 DominatorTree::Delete, FC1.Preheader, FC1.Header));
1793 rewireFusedHeaderPHIsAndLatches(FC0, FC1, OriginalFC0PHIs, TreeUpdates);
1796 DTU.applyUpdates(TreeUpdates);
1798 LI.removeBlock(FC1.Preheader);
1799 DTU.deleteBB(FC1.Preheader);
1801 LI.removeBlock(FC0.ExitBlock);
1802 DTU.deleteBB(FC0.ExitBlock);
1807 return finalizeFusedLoop(FC0, FC1);
1822 template <
typename RemarkKind>
1823 void reportLoopFusion(
const FusionCandidate &FC0,
const FusionCandidate &FC1,
1824 StringRef RemarkName, StringRef RemarkMsg) {
1825 assert(FC0.Preheader && FC1.Preheader &&
1826 "Expecting valid fusion candidates");
1827 using namespace ore;
1831 <<
"]: " <<
NV(
"Cand1", StringRef(FC0.Preheader->
getName())) <<
" and "
1832 <<
NV(
"Cand2", StringRef(FC1.Preheader->
getName())) <<
": "
1836 void reportFusionInsufficientReuse(
const FusionCandidate &FC0,
1837 const FusionCandidate &FC1,
1838 unsigned ReusedValueCount) {
1839 assert(ReusedValueCount < Opts.loop_fusion_min_reused_values &&
1840 "Expected insufficient reuse");
1842 using namespace ore;
1843 ORE.emit(OptimizationRemarkMissed(
DEBUG_TYPE,
"InsufficientReuse",
1846 <<
"]: " <<
NV(
"Cand1", StringRef(FC0.Preheader->
getName()))
1847 <<
" and " <<
NV(
"Cand2", StringRef(FC1.Preheader->
getName()))
1848 <<
": found " <<
NV(
"ReusedValueCount", ReusedValueCount)
1849 <<
" cross-loop reused values; configured minimum is "
1850 <<
NV(
"MinimumReusedValues",
1851 unsigned(Opts.loop_fusion_min_reused_values)));
1869 Loop *fuseGuardedLoops(
const FusionCandidate &FC0,
1870 const FusionCandidate &FC1) {
1871 assert(FC0.GuardBranch && FC1.GuardBranch &&
"Expecting guarded loops");
1875 BasicBlock *FC0NonLoopBlock = FC0.getNonLoopBlock();
1876 BasicBlock *FC1NonLoopBlock = FC1.getNonLoopBlock();
1884 (FC0.Peeled ? *FC0ExitBlockSuccessor : *FC0.ExitBlock), *FC1.ExitBlock,
1891 assert(FC0NonLoopBlock == FC1GuardBlock &&
"Loops are not adjacent");
1906 BasicBlock *BBToUpdate = FC0.Peeled ? FC0ExitBlockSuccessor : FC0.ExitBlock;
1911 new UnreachableInst(FC1GuardBlock->
getContext(), FC1GuardBlock);
1914 DominatorTree::Delete, FC1GuardBlock, FC1.Preheader));
1916 DominatorTree::Delete, FC1GuardBlock, FC1NonLoopBlock));
1918 DominatorTree::Delete, FC0GuardBlock, FC1GuardBlock));
1920 DominatorTree::Insert, FC0GuardBlock, FC1NonLoopBlock));
1924 DominatorTree::Delete, FC0.ExitBlock, FC0ExitBlockSuccessor));
1927 DominatorTree::Delete, FC0ExitBlockSuccessor, FC1GuardBlock));
1929 new UnreachableInst(FC0ExitBlockSuccessor->
getContext(),
1930 FC0ExitBlockSuccessor);
1934 "Expecting guard block to have no predecessors");
1936 "Expecting guard block to have no successors");
1951 if (FC0.ExitingBlock != FC0.Latch)
1952 for (PHINode &
PHI : FC0.Header->
phis())
1955 assert(OriginalFC0PHIs.
empty() &&
"Expecting OriginalFC0PHIs to be empty!");
1978 DominatorTree::Delete, FC0.ExitingBlock, FC0.ExitBlock));
1980 DominatorTree::Insert, FC0.ExitingBlock, FC1.Header));
1991 new UnreachableInst(FC0.ExitBlock->
getContext(), FC0.ExitBlock);
1997 new UnreachableInst(FC1.Preheader->
getContext(), FC1.Preheader);
1999 DominatorTree::Delete, FC1.Preheader, FC1.Header));
2001 rewireFusedHeaderPHIsAndLatches(FC0, FC1, OriginalFC0PHIs, TreeUpdates);
2010 DTU.applyUpdates(TreeUpdates);
2012 LI.removeBlock(FC1GuardBlock);
2013 LI.removeBlock(FC1.Preheader);
2014 LI.removeBlock(FC0.ExitBlock);
2016 LI.removeBlock(FC0ExitBlockSuccessor);
2017 DTU.deleteBB(FC0ExitBlockSuccessor);
2019 DTU.deleteBB(FC1GuardBlock);
2020 DTU.deleteBB(FC1.Preheader);
2021 DTU.deleteBB(FC0.ExitBlock);
2024 return finalizeFusedLoop(FC0, FC1);
2045 for (
auto &L : LI) {
2049 for (
Loop *L : LI.getLoopsInPreorder()) {
2056 LoopFuser LF(ScalarOptions::Global, 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 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 * 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.
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.
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.
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.
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 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)
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)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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.