Skip to content

Commit 274dcdc

Browse files
committed
avoid bfi calculation in alwaysinline
1 parent 5322415 commit 274dcdc

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

llvm/lib/Transforms/IPO/AlwaysInliner.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ bool AlwaysInlineImpl(
3434
Module &M, bool InsertLifetime, ProfileSummaryInfo &PSI,
3535
function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
3636
function_ref<AAResults &(Function &)> GetAAR,
37-
function_ref<BlockFrequencyInfo &(Function &)> GetBFI) {
37+
function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
38+
function_ref<BlockFrequencyInfo *(Function &)> GetCachedBFI) {
3839
SmallSetVector<CallBase *, 16> Calls;
3940
bool Changed = false;
4041
SmallVector<Function *, 16> InlinedComdatFunctions;
@@ -61,9 +62,11 @@ bool AlwaysInlineImpl(
6162
DebugLoc DLoc = CB->getDebugLoc();
6263
BasicBlock *Block = CB->getParent();
6364

64-
InlineFunctionInfo IFI(GetAssumptionCache, &PSI,
65-
GetBFI ? &GetBFI(*Caller) : nullptr,
66-
GetBFI ? &GetBFI(F) : nullptr);
65+
// Only update CallerBFI if already available. The CallerBFI update
66+
// requires CalleeBFI.
67+
BlockFrequencyInfo *CallerBFI = GetCachedBFI(*Caller);
68+
InlineFunctionInfo IFI(GetAssumptionCache, &PSI, CallerBFI,
69+
CallerBFI ? &GetBFI(F) : nullptr);
6770

6871
InlineResult Res = InlineFunction(*CB, IFI, /*MergeAttributes=*/true,
6972
&GetAAR(F), InsertLifetime);
@@ -133,9 +136,12 @@ struct AlwaysInlinerLegacyPass : public ModulePass {
133136
auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
134137
return getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
135138
};
139+
auto GetCachedBFI = [&](Function &) -> BlockFrequencyInfo * {
140+
return nullptr;
141+
};
136142

137143
return AlwaysInlineImpl(M, InsertLifetime, PSI, GetAssumptionCache, GetAAR,
138-
/*GetBFI*/ nullptr);
144+
/*GetBFI=*/nullptr, GetCachedBFI);
139145
}
140146

141147
static char ID; // Pass identification, replacement for typeid
@@ -172,13 +178,16 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
172178
auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {
173179
return FAM.getResult<BlockFrequencyAnalysis>(F);
174180
};
181+
auto GetCachedBFI = [&](Function &F) -> BlockFrequencyInfo * {
182+
return FAM.getCachedResult<BlockFrequencyAnalysis>(F);
183+
};
175184
auto GetAAR = [&](Function &F) -> AAResults & {
176185
return FAM.getResult<AAManager>(F);
177186
};
178187
auto &PSI = MAM.getResult<ProfileSummaryAnalysis>(M);
179188

180189
bool Changed = AlwaysInlineImpl(M, InsertLifetime, PSI, GetAssumptionCache,
181-
GetAAR, GetBFI);
190+
GetAAR, GetBFI, GetCachedBFI);
182191

183192
return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
184193
}

0 commit comments

Comments
 (0)