@@ -34,7 +34,8 @@ bool AlwaysInlineImpl(
34
34
Module &M, bool InsertLifetime, ProfileSummaryInfo &PSI,
35
35
function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
36
36
function_ref<AAResults &(Function &)> GetAAR,
37
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI) {
37
+ function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
38
+ function_ref<BlockFrequencyInfo *(Function &)> GetCachedBFI) {
38
39
SmallSetVector<CallBase *, 16 > Calls;
39
40
bool Changed = false ;
40
41
SmallVector<Function *, 16 > InlinedComdatFunctions;
@@ -61,9 +62,11 @@ bool AlwaysInlineImpl(
61
62
DebugLoc DLoc = CB->getDebugLoc ();
62
63
BasicBlock *Block = CB->getParent ();
63
64
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 );
67
70
68
71
InlineResult Res = InlineFunction (*CB, IFI, /* MergeAttributes=*/ true ,
69
72
&GetAAR (F), InsertLifetime);
@@ -133,9 +136,12 @@ struct AlwaysInlinerLegacyPass : public ModulePass {
133
136
auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
134
137
return getAnalysis<AssumptionCacheTracker>().getAssumptionCache (F);
135
138
};
139
+ auto GetCachedBFI = [](Function &) -> BlockFrequencyInfo * {
140
+ return nullptr ;
141
+ };
136
142
137
143
return AlwaysInlineImpl (M, InsertLifetime, PSI, GetAssumptionCache, GetAAR,
138
- /* GetBFI*/ nullptr );
144
+ /* GetBFI= */ nullptr , GetCachedBFI );
139
145
}
140
146
141
147
static char ID; // Pass identification, replacement for typeid
@@ -172,13 +178,16 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
172
178
auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {
173
179
return FAM.getResult <BlockFrequencyAnalysis>(F);
174
180
};
181
+ auto GetCachedBFI = [&](Function &F) -> BlockFrequencyInfo * {
182
+ return FAM.getCachedResult <BlockFrequencyAnalysis>(F);
183
+ };
175
184
auto GetAAR = [&](Function &F) -> AAResults & {
176
185
return FAM.getResult <AAManager>(F);
177
186
};
178
187
auto &PSI = MAM.getResult <ProfileSummaryAnalysis>(M);
179
188
180
189
bool Changed = AlwaysInlineImpl (M, InsertLifetime, PSI, GetAssumptionCache,
181
- GetAAR, GetBFI);
190
+ GetAAR, GetBFI, GetCachedBFI );
182
191
183
192
return Changed ? PreservedAnalyses::none () : PreservedAnalyses::all ();
184
193
}
0 commit comments