@@ -30,6 +30,43 @@ using namespace llvm;
3030
3131namespace {
3232
33+ bool canInlineCallBase (CallBase *CB) {
34+ return CB->hasFnAttr (Attribute::AlwaysInline) &&
35+ !CB->getAttributes ().hasFnAttr (Attribute::NoInline);
36+ }
37+
38+ bool attemptInlineFunction (
39+ Function &F, CallBase *CB, bool InsertLifetime,
40+ function_ref<AAResults &(Function &)> &GetAAR,
41+ function_ref<AssumptionCache &(Function &)> &GetAssumptionCache,
42+ ProfileSummaryInfo &PSI) {
43+ Function *Caller = CB->getCaller ();
44+ OptimizationRemarkEmitter ORE (Caller);
45+ DebugLoc DLoc = CB->getDebugLoc ();
46+ BasicBlock *Block = CB->getParent ();
47+
48+ InlineFunctionInfo IFI (GetAssumptionCache, &PSI, nullptr , nullptr );
49+ InlineResult Res = InlineFunction (*CB, IFI, /* MergeAttributes=*/ true ,
50+ &GetAAR (F), InsertLifetime);
51+ if (!Res.isSuccess ()) {
52+ ORE.emit ([&]() {
53+ return OptimizationRemarkMissed (DEBUG_TYPE, " NotInlined" , DLoc, Block)
54+ << " '" << ore::NV (" Callee" , &F) << " ' is not inlined into '"
55+ << ore::NV (" Caller" , Caller)
56+ << " ': " << ore::NV (" Reason" , Res.getFailureReason ());
57+ });
58+ return false ;
59+ }
60+
61+ emitInlinedIntoBasedOnCost (ORE, DLoc, Block, F, *Caller,
62+ InlineCost::getAlways (" always inline attribute" ),
63+ /* ForProfileContext=*/ false , DEBUG_TYPE);
64+
65+ return true ;
66+ }
67+ // / This function inlines all functions that are marked with the always_inline
68+ // / attribute. It also removes the inlined functions if they are dead after the
69+ // / inlining process.
3370bool AlwaysInlineImpl (
3471 Module &M, bool InsertLifetime, ProfileSummaryInfo &PSI,
3572 FunctionAnalysisManager *FAM,
@@ -50,36 +87,13 @@ bool AlwaysInlineImpl(
5087
5188 for (User *U : F.users ())
5289 if (auto *CB = dyn_cast<CallBase>(U))
53- if (CB->getCalledFunction () == &F &&
54- CB->hasFnAttr (Attribute::AlwaysInline) &&
55- !CB->getAttributes ().hasFnAttr (Attribute::NoInline))
90+ if (CB->getCalledFunction () == &F && canInlineCallBase (CB))
5691 Calls.insert (CB);
5792
5893 for (CallBase *CB : Calls) {
5994 Function *Caller = CB->getCaller ();
60- OptimizationRemarkEmitter ORE (Caller);
61- DebugLoc DLoc = CB->getDebugLoc ();
62- BasicBlock *Block = CB->getParent ();
63-
64- InlineFunctionInfo IFI (GetAssumptionCache, &PSI, nullptr , nullptr );
65- InlineResult Res = InlineFunction (*CB, IFI, /* MergeAttributes=*/ true ,
66- &GetAAR (F), InsertLifetime);
67- if (!Res.isSuccess ()) {
68- ORE.emit ([&]() {
69- return OptimizationRemarkMissed (DEBUG_TYPE, " NotInlined" , DLoc, Block)
70- << " '" << ore::NV (" Callee" , &F) << " ' is not inlined into '"
71- << ore::NV (" Caller" , Caller)
72- << " ': " << ore::NV (" Reason" , Res.getFailureReason ());
73- });
74- continue ;
75- }
76-
77- emitInlinedIntoBasedOnCost (
78- ORE, DLoc, Block, F, *Caller,
79- InlineCost::getAlways (" always inline attribute" ),
80- /* ForProfileContext=*/ false , DEBUG_TYPE);
81-
82- Changed = true ;
95+ Changed |= attemptInlineFunction (F, CB, InsertLifetime, GetAAR,
96+ GetAssumptionCache, PSI);
8397 if (FAM)
8498 FAM->invalidate (*Caller, PreservedAnalyses::none ());
8599 }
0 commit comments