@@ -32,10 +32,9 @@ namespace {
32
32
33
33
bool AlwaysInlineImpl (
34
34
Module &M, bool InsertLifetime, ProfileSummaryInfo &PSI,
35
+ FunctionAnalysisManager *FAM,
35
36
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) {
39
38
SmallSetVector<CallBase *, 16 > Calls;
40
39
bool Changed = false ;
41
40
SmallVector<Function *, 16 > InlinedComdatFunctions;
@@ -62,12 +61,7 @@ bool AlwaysInlineImpl(
62
61
DebugLoc DLoc = CB->getDebugLoc ();
63
62
BasicBlock *Block = CB->getParent ();
64
63
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 );
71
65
InlineResult Res = InlineFunction (*CB, IFI, /* MergeAttributes=*/ true ,
72
66
&GetAAR (F), InsertLifetime);
73
67
if (!Res.isSuccess ()) {
@@ -86,6 +80,8 @@ bool AlwaysInlineImpl(
86
80
/* ForProfileContext=*/ false , DEBUG_TYPE);
87
81
88
82
Changed = true ;
83
+ if (FAM)
84
+ FAM->invalidate (*Caller, PreservedAnalyses::none ());
89
85
}
90
86
91
87
F.removeDeadConstantUsers ();
@@ -95,6 +91,8 @@ bool AlwaysInlineImpl(
95
91
if (F.hasComdat ()) {
96
92
InlinedComdatFunctions.push_back (&F);
97
93
} else {
94
+ if (FAM)
95
+ FAM->clear (F, F.getName ());
98
96
M.getFunctionList ().erase (F);
99
97
Changed = true ;
100
98
}
@@ -107,6 +105,8 @@ bool AlwaysInlineImpl(
107
105
filterDeadComdatFunctions (InlinedComdatFunctions);
108
106
// The remaining functions are actually dead.
109
107
for (Function *F : InlinedComdatFunctions) {
108
+ if (FAM)
109
+ FAM->clear (*F, F->getName ());
110
110
M.getFunctionList ().erase (F);
111
111
Changed = true ;
112
112
}
@@ -136,12 +136,9 @@ struct AlwaysInlinerLegacyPass : public ModulePass {
136
136
auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
137
137
return getAnalysis<AssumptionCacheTracker>().getAssumptionCache (F);
138
138
};
139
- auto GetCachedBFI = [](Function &) -> BlockFrequencyInfo * {
140
- return nullptr ;
141
- };
142
139
143
- return AlwaysInlineImpl (M, InsertLifetime, PSI, GetAssumptionCache, GetAAR ,
144
- /* GetBFI= */ nullptr , GetCachedBFI );
140
+ return AlwaysInlineImpl (M, InsertLifetime, PSI, /* FAM= */ nullptr ,
141
+ GetAssumptionCache, GetAAR );
145
142
}
146
143
147
144
static char ID; // Pass identification, replacement for typeid
@@ -175,19 +172,18 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
175
172
auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
176
173
return FAM.getResult <AssumptionAnalysis>(F);
177
174
};
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
- };
184
175
auto GetAAR = [&](Function &F) -> AAResults & {
185
176
return FAM.getResult <AAManager>(F);
186
177
};
187
178
auto &PSI = MAM.getResult <ProfileSummaryAnalysis>(M);
188
179
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 ();
191
184
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;
193
189
}
0 commit comments