Skip to content

Commit 7537740

Browse files
authored
Merge pull request #20589 from gottesmm/pr-37958925c26b34b09c8e6638f5f45e8763af2110
[inliner] Treat inline_always as meaning truly inline_always even in …
2 parents 0898e01 + 6decec6 commit 7537740

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,10 @@ addToBBCounts(llvm::DenseMap<SILBasicBlock *, uint64_t> &BBToWeightMap,
652652
}
653653
}
654654

655+
static bool isInlineAlwaysCallSite(SILFunction *Callee) {
656+
return Callee->getInlineStrategy() == AlwaysInline || Callee->isTransparent();
657+
}
658+
655659
static void
656660
calculateBBWeights(SILFunction *Caller, DominanceInfo *DT,
657661
llvm::DenseMap<SILBasicBlock *, uint64_t> &BBToWeightMap) {
@@ -787,6 +791,23 @@ void SILPerformanceInliner::collectAppliesToInline(
787791

788792
auto *Callee = getEligibleFunction(AI, WhatToInline);
789793
if (Callee) {
794+
// Check if we have an always_inline or transparent function. If we do,
795+
// just add it to our final Applies list and continue.
796+
if (isInlineAlwaysCallSite(Callee)) {
797+
NumCallerBlocks += Callee->size();
798+
Applies.push_back(AI);
799+
continue;
800+
}
801+
802+
// Next make sure that we do not have more blocks than our overall
803+
// caller block limit at this point. In such a case, we continue. This
804+
// will ensure that any further non inline always functions are skipped,
805+
// but we /do/ inline any inline_always functions remaining.
806+
if (NumCallerBlocks > OverallCallerBlockLimit)
807+
continue;
808+
809+
// Otherwise, calculate our block weights and determine if we want to
810+
// inline this.
790811
if (!BlockWeight.isValid())
791812
BlockWeight = SPA->getWeight(block, Weight(0, 0));
792813

@@ -798,8 +819,6 @@ void SILPerformanceInliner::collectAppliesToInline(
798819
InitialCandidates.push_back(AI);
799820
}
800821
}
801-
if (NumCallerBlocks > OverallCallerBlockLimit)
802-
break;
803822

804823
domOrder.pushChildrenIf(block, [&] (SILBasicBlock *child) {
805824
if (CBI.isSlowPath(block, child)) {

0 commit comments

Comments
 (0)