-
Notifications
You must be signed in to change notification settings - Fork 14.4k
AlwaysInliner: Factor out some code in preparation for a future change. #145614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
AlwaysInliner: Factor out some code in preparation for a future change. #145614
Conversation
Created using spr 1.3.5
@llvm/pr-subscribers-llvm-transforms Author: Amara Emerson (aemerson) ChangesFull diff: https://github.com/llvm/llvm-project/pull/145614.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
index 921fe8c18aa72..8de1467ea47ec 100644
--- a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
+++ b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -30,6 +30,43 @@ using namespace llvm;
namespace {
+bool canInlineCallBase(CallBase *CB) {
+ return CB->hasFnAttr(Attribute::AlwaysInline) &&
+ !CB->getAttributes().hasFnAttr(Attribute::NoInline);
+}
+
+ bool attemptInlineFunction(
+ Function &F, CallBase *CB, bool InsertLifetime,
+ function_ref<AAResults &(Function &)> &GetAAR,
+ function_ref<AssumptionCache &(Function &)> &GetAssumptionCache,
+ ProfileSummaryInfo &PSI) {
+ Function *Caller = CB->getCaller();
+ OptimizationRemarkEmitter ORE(Caller);
+ DebugLoc DLoc = CB->getDebugLoc();
+ BasicBlock *Block = CB->getParent();
+
+ InlineFunctionInfo IFI(GetAssumptionCache, &PSI, nullptr, nullptr);
+ InlineResult Res = InlineFunction(*CB, IFI, /*MergeAttributes=*/true,
+ &GetAAR(F), InsertLifetime);
+ if (!Res.isSuccess()) {
+ ORE.emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
+ << "'" << ore::NV("Callee", &F) << "' is not inlined into '"
+ << ore::NV("Caller", Caller)
+ << "': " << ore::NV("Reason", Res.getFailureReason());
+ });
+ return false;
+ }
+
+ emitInlinedIntoBasedOnCost(ORE, DLoc, Block, F, *Caller,
+ InlineCost::getAlways("always inline attribute"),
+ /*ForProfileContext=*/false, DEBUG_TYPE);
+
+ return true;
+ }
+/// This function inlines all functions that are marked with the always_inline
+/// attribute. It also removes the inlined functions if they are dead after the
+/// inlining process.
bool AlwaysInlineImpl(
Module &M, bool InsertLifetime, ProfileSummaryInfo &PSI,
FunctionAnalysisManager *FAM,
@@ -50,36 +87,13 @@ bool AlwaysInlineImpl(
for (User *U : F.users())
if (auto *CB = dyn_cast<CallBase>(U))
- if (CB->getCalledFunction() == &F &&
- CB->hasFnAttr(Attribute::AlwaysInline) &&
- !CB->getAttributes().hasFnAttr(Attribute::NoInline))
+ if (CB->getCalledFunction() == &F && canInlineCallBase(CB))
Calls.insert(CB);
for (CallBase *CB : Calls) {
Function *Caller = CB->getCaller();
- OptimizationRemarkEmitter ORE(Caller);
- DebugLoc DLoc = CB->getDebugLoc();
- BasicBlock *Block = CB->getParent();
-
- InlineFunctionInfo IFI(GetAssumptionCache, &PSI, nullptr, nullptr);
- InlineResult Res = InlineFunction(*CB, IFI, /*MergeAttributes=*/true,
- &GetAAR(F), InsertLifetime);
- if (!Res.isSuccess()) {
- ORE.emit([&]() {
- return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
- << "'" << ore::NV("Callee", &F) << "' is not inlined into '"
- << ore::NV("Caller", Caller)
- << "': " << ore::NV("Reason", Res.getFailureReason());
- });
- continue;
- }
-
- emitInlinedIntoBasedOnCost(
- ORE, DLoc, Block, F, *Caller,
- InlineCost::getAlways("always inline attribute"),
- /*ForProfileContext=*/false, DEBUG_TYPE);
-
- Changed = true;
+ Changed |= attemptInlineFunction(F, CB, InsertLifetime, GetAAR,
+ GetAssumptionCache, PSI);
if (FAM)
FAM->invalidate(*Caller, PreservedAnalyses::none());
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Created using spr 1.3.6
@@ -30,6 +30,44 @@ using namespace llvm; | |||
|
|||
namespace { | |||
|
|||
bool canInlineCallBase(CallBase *CB) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool canInlineCallBase(CallBase *CB) { | |
static bool canInlineCallBase(CallBase *CB) { |
Could you also add a brief doc-comment?
!CB->getAttributes().hasFnAttr(Attribute::NoInline); | ||
} | ||
|
||
bool attemptInlineFunction( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool attemptInlineFunction( | |
static bool attemptInlineFunction( |
Could you also add a brief doc-comment?
Created using spr 1.3.6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
No description provided.