@@ -32,10 +32,9 @@ namespace {
3232
3333bool AlwaysInlineImpl (
3434 Module &M, bool InsertLifetime, ProfileSummaryInfo &PSI,
35+ FunctionAnalysisManager *FAM,
3536 function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
36- function_ref<AAResults &(Function &)> GetAAR,
37- function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
38- function_ref<BlockFrequencyInfo *(Function &)> GetCachedBFI) {
37+ function_ref<AAResults &(Function &)> GetAAR) {
3938 SmallSetVector<CallBase *, 16 > Calls;
4039 bool Changed = false ;
4140 SmallVector<Function *, 16 > InlinedComdatFunctions;
@@ -62,12 +61,7 @@ bool AlwaysInlineImpl(
6261 DebugLoc DLoc = CB->getDebugLoc ();
6362 BasicBlock *Block = CB->getParent ();
6463
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 );
70-
64+ InlineFunctionInfo IFI (GetAssumptionCache, &PSI, nullptr , nullptr );
7165 InlineResult Res = InlineFunction (*CB, IFI, /* MergeAttributes=*/ true ,
7266 &GetAAR (F), InsertLifetime);
7367 if (!Res.isSuccess ()) {
@@ -86,6 +80,8 @@ bool AlwaysInlineImpl(
8680 /* ForProfileContext=*/ false , DEBUG_TYPE);
8781
8882 Changed = true ;
83+ if (FAM)
84+ FAM->invalidate (*Caller, PreservedAnalyses::none ());
8985 }
9086
9187 F.removeDeadConstantUsers ();
@@ -95,6 +91,8 @@ bool AlwaysInlineImpl(
9591 if (F.hasComdat ()) {
9692 InlinedComdatFunctions.push_back (&F);
9793 } else {
94+ if (FAM)
95+ FAM->clear (F, F.getName ());
9896 M.getFunctionList ().erase (F);
9997 Changed = true ;
10098 }
@@ -107,6 +105,8 @@ bool AlwaysInlineImpl(
107105 filterDeadComdatFunctions (InlinedComdatFunctions);
108106 // The remaining functions are actually dead.
109107 for (Function *F : InlinedComdatFunctions) {
108+ if (FAM)
109+ FAM->clear (*F, F->getName ());
110110 M.getFunctionList ().erase (F);
111111 Changed = true ;
112112 }
@@ -136,12 +136,9 @@ struct AlwaysInlinerLegacyPass : public ModulePass {
136136 auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
137137 return getAnalysis<AssumptionCacheTracker>().getAssumptionCache (F);
138138 };
139- auto GetCachedBFI = [](Function &) -> BlockFrequencyInfo * {
140- return nullptr ;
141- };
142139
143- return AlwaysInlineImpl (M, InsertLifetime, PSI, GetAssumptionCache, GetAAR ,
144- /* GetBFI= */ nullptr , GetCachedBFI );
140+ return AlwaysInlineImpl (M, InsertLifetime, PSI, /* FAM= */ nullptr ,
141+ GetAssumptionCache, GetAAR );
145142 }
146143
147144 static char ID; // Pass identification, replacement for typeid
@@ -175,19 +172,18 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
175172 auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
176173 return FAM.getResult <AssumptionAnalysis>(F);
177174 };
178- auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {
179- return FAM.getResult <BlockFrequencyAnalysis>(F);
180- };
181- auto GetCachedBFI = [&](Function &F) -> BlockFrequencyInfo * {
182- return FAM.getCachedResult <BlockFrequencyAnalysis>(F);
183- };
184175 auto GetAAR = [&](Function &F) -> AAResults & {
185176 return FAM.getResult <AAManager>(F);
186177 };
187178 auto &PSI = MAM.getResult <ProfileSummaryAnalysis>(M);
188179
189- bool Changed = AlwaysInlineImpl (M, InsertLifetime, PSI, GetAssumptionCache,
190- GetAAR, GetBFI, GetCachedBFI);
180+ bool Changed = AlwaysInlineImpl (M, InsertLifetime, PSI, &FAM,
181+ GetAssumptionCache, GetAAR);
182+ if (!Changed)
183+ return PreservedAnalyses::all ();
191184
192- return Changed ? PreservedAnalyses::none () : PreservedAnalyses::all ();
185+ PreservedAnalyses PA;
186+ // We have already invalidated all analyses on modified functions.
187+ PA.preserveSet <AllAnalysesOn<Function>>();
188+ return PA;
193189}
0 commit comments