mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
Revert [Inliner] Attribute callsites with inline remarks
llvm-svn: 340619
This commit is contained in:
parent
43c40e97d4
commit
d9c443e857
@ -113,14 +113,6 @@ static cl::opt<InlinerFunctionImportStatsOpts> InlinerFunctionImportStats(
|
|||||||
"printing of statistics for each inlined function")),
|
"printing of statistics for each inlined function")),
|
||||||
cl::Hidden, cl::desc("Enable inliner stats for imported functions"));
|
cl::Hidden, cl::desc("Enable inliner stats for imported functions"));
|
||||||
|
|
||||||
/// Flag to add inline messages as callsite attributes 'inline-remark'.
|
|
||||||
static cl::opt<bool>
|
|
||||||
InlineRemarkAttribute("inline-remark-attribute", cl::init(false),
|
|
||||||
cl::Hidden,
|
|
||||||
cl::desc("Enable adding inline-remark attribute to"
|
|
||||||
" callsites processed by inliner but decided"
|
|
||||||
" to be not inlined"));
|
|
||||||
|
|
||||||
LegacyInlinerBase::LegacyInlinerBase(char &ID) : CallGraphSCCPass(ID) {}
|
LegacyInlinerBase::LegacyInlinerBase(char &ID) : CallGraphSCCPass(ID) {}
|
||||||
|
|
||||||
LegacyInlinerBase::LegacyInlinerBase(char &ID, bool InsertLifetime)
|
LegacyInlinerBase::LegacyInlinerBase(char &ID, bool InsertLifetime)
|
||||||
@ -272,7 +264,7 @@ static void mergeInlinedArrayAllocas(
|
|||||||
/// available from other functions inlined into the caller. If we are able to
|
/// available from other functions inlined into the caller. If we are able to
|
||||||
/// inline this call site we attempt to reuse already available allocas or add
|
/// inline this call site we attempt to reuse already available allocas or add
|
||||||
/// any new allocas to the set if not possible.
|
/// any new allocas to the set if not possible.
|
||||||
static InlineResult InlineCallIfPossible(
|
static bool InlineCallIfPossible(
|
||||||
CallSite CS, InlineFunctionInfo &IFI,
|
CallSite CS, InlineFunctionInfo &IFI,
|
||||||
InlinedArrayAllocasTy &InlinedArrayAllocas, int InlineHistory,
|
InlinedArrayAllocasTy &InlinedArrayAllocas, int InlineHistory,
|
||||||
bool InsertLifetime, function_ref<AAResults &(Function &)> &AARGetter,
|
bool InsertLifetime, function_ref<AAResults &(Function &)> &AARGetter,
|
||||||
@ -398,11 +390,13 @@ RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
|
|||||||
return R;
|
return R;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
static std::string inlineCostStr(const InlineCost &IC) {
|
static std::string inlineCostStr(const InlineCost &IC) {
|
||||||
std::stringstream Remark;
|
std::stringstream Remark;
|
||||||
Remark << IC;
|
Remark << IC;
|
||||||
return Remark.str();
|
return Remark.str();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Return the cost only if the inliner should attempt to inline at the given
|
/// Return the cost only if the inliner should attempt to inline at the given
|
||||||
/// CallSite. If we return the cost, we will emit an optimisation remark later
|
/// CallSite. If we return the cost, we will emit an optimisation remark later
|
||||||
@ -508,14 +502,6 @@ static void emit_inlined_into(OptimizationRemarkEmitter &ORE, DebugLoc &DLoc,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setInlineRemark(CallSite &CS, StringRef message) {
|
|
||||||
if (!InlineRemarkAttribute)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Attribute attr = Attribute::get(CS->getContext(), "inline-remark", message);
|
|
||||||
CS.addAttribute(AttributeList::FunctionIndex, attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
|
inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
|
||||||
std::function<AssumptionCache &(Function &)> GetAssumptionCache,
|
std::function<AssumptionCache &(Function &)> GetAssumptionCache,
|
||||||
@ -565,7 +551,6 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
|
|||||||
if (Callee->isDeclaration()) {
|
if (Callee->isDeclaration()) {
|
||||||
using namespace ore;
|
using namespace ore;
|
||||||
|
|
||||||
setInlineRemark(CS, "unavailable definition");
|
|
||||||
ORE.emit([&]() {
|
ORE.emit([&]() {
|
||||||
return OptimizationRemarkMissed(DEBUG_TYPE, "NoDefinition", &I)
|
return OptimizationRemarkMissed(DEBUG_TYPE, "NoDefinition", &I)
|
||||||
<< NV("Callee", Callee) << " will not be inlined into "
|
<< NV("Callee", Callee) << " will not be inlined into "
|
||||||
@ -629,10 +614,8 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
|
|||||||
// infinitely inline.
|
// infinitely inline.
|
||||||
InlineHistoryID = CallSites[CSi].second;
|
InlineHistoryID = CallSites[CSi].second;
|
||||||
if (InlineHistoryID != -1 &&
|
if (InlineHistoryID != -1 &&
|
||||||
InlineHistoryIncludes(Callee, InlineHistoryID, InlineHistory)) {
|
InlineHistoryIncludes(Callee, InlineHistoryID, InlineHistory))
|
||||||
setInlineRemark(CS, "recursive");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME for new PM: because of the old PM we currently generate ORE and
|
// FIXME for new PM: because of the old PM we currently generate ORE and
|
||||||
@ -643,15 +626,7 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
|
|||||||
Optional<InlineCost> OIC = shouldInline(CS, GetInlineCost, ORE);
|
Optional<InlineCost> OIC = shouldInline(CS, GetInlineCost, ORE);
|
||||||
// If the policy determines that we should inline this function,
|
// If the policy determines that we should inline this function,
|
||||||
// delete the call instead.
|
// delete the call instead.
|
||||||
if (!OIC.hasValue()) {
|
if (!OIC || !*OIC) {
|
||||||
setInlineRemark(CS, "deferred");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!OIC.getValue()) {
|
|
||||||
// shouldInline() call returned a negative inline cost that explains
|
|
||||||
// why this callsite should not be inlined.
|
|
||||||
setInlineRemark(CS, inlineCostStr(*OIC));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -662,7 +637,6 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
|
|||||||
if (IsTriviallyDead) {
|
if (IsTriviallyDead) {
|
||||||
LLVM_DEBUG(dbgs() << " -> Deleting dead call: " << *Instr << "\n");
|
LLVM_DEBUG(dbgs() << " -> Deleting dead call: " << *Instr << "\n");
|
||||||
// Update the call graph by deleting the edge from Callee to Caller.
|
// Update the call graph by deleting the edge from Callee to Caller.
|
||||||
setInlineRemark(CS, "trivially dead");
|
|
||||||
CG[Caller]->removeCallEdgeFor(CS);
|
CG[Caller]->removeCallEdgeFor(CS);
|
||||||
Instr->eraseFromParent();
|
Instr->eraseFromParent();
|
||||||
++NumCallsDeleted;
|
++NumCallsDeleted;
|
||||||
@ -678,7 +652,6 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
|
|||||||
CS, InlineInfo, InlinedArrayAllocas, InlineHistoryID,
|
CS, InlineInfo, InlinedArrayAllocas, InlineHistoryID,
|
||||||
InsertLifetime, AARGetter, ImportedFunctionsStats);
|
InsertLifetime, AARGetter, ImportedFunctionsStats);
|
||||||
if (!IR) {
|
if (!IR) {
|
||||||
setInlineRemark(CS, std::string(IR) + "; " + inlineCostStr(*OIC));
|
|
||||||
ORE.emit([&]() {
|
ORE.emit([&]() {
|
||||||
return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc,
|
return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc,
|
||||||
Block)
|
Block)
|
||||||
@ -921,7 +894,6 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
|
|||||||
Calls.push_back({CS, -1});
|
Calls.push_back({CS, -1});
|
||||||
else if (!isa<IntrinsicInst>(I)) {
|
else if (!isa<IntrinsicInst>(I)) {
|
||||||
using namespace ore;
|
using namespace ore;
|
||||||
setInlineRemark(CS, "unavailable definition");
|
|
||||||
ORE.emit([&]() {
|
ORE.emit([&]() {
|
||||||
return OptimizationRemarkMissed(DEBUG_TYPE, "NoDefinition", &I)
|
return OptimizationRemarkMissed(DEBUG_TYPE, "NoDefinition", &I)
|
||||||
<< NV("Callee", Callee) << " will not be inlined into "
|
<< NV("Callee", Callee) << " will not be inlined into "
|
||||||
@ -965,10 +937,8 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
|
|||||||
LazyCallGraph::Node &N = *CG.lookup(F);
|
LazyCallGraph::Node &N = *CG.lookup(F);
|
||||||
if (CG.lookupSCC(N) != C)
|
if (CG.lookupSCC(N) != C)
|
||||||
continue;
|
continue;
|
||||||
if (F.hasFnAttribute(Attribute::OptimizeNone)) {
|
if (F.hasFnAttribute(Attribute::OptimizeNone))
|
||||||
setInlineRemark(Calls[i].first, "optnone attribute");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
LLVM_DEBUG(dbgs() << "Inlining calls in: " << F.getName() << "\n");
|
LLVM_DEBUG(dbgs() << "Inlining calls in: " << F.getName() << "\n");
|
||||||
|
|
||||||
@ -1012,10 +982,8 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
|
|||||||
Function &Callee = *CS.getCalledFunction();
|
Function &Callee = *CS.getCalledFunction();
|
||||||
|
|
||||||
if (InlineHistoryID != -1 &&
|
if (InlineHistoryID != -1 &&
|
||||||
InlineHistoryIncludes(&Callee, InlineHistoryID, InlineHistory)) {
|
InlineHistoryIncludes(&Callee, InlineHistoryID, InlineHistory))
|
||||||
setInlineRemark(CS, "recursive");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
// Check if this inlining may repeat breaking an SCC apart that has
|
// Check if this inlining may repeat breaking an SCC apart that has
|
||||||
// already been split once before. In that case, inlining here may
|
// already been split once before. In that case, inlining here may
|
||||||
@ -1027,23 +995,13 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
|
|||||||
LLVM_DEBUG(dbgs() << "Skipping inlining internal SCC edge from a node "
|
LLVM_DEBUG(dbgs() << "Skipping inlining internal SCC edge from a node "
|
||||||
"previously split out of this SCC by inlining: "
|
"previously split out of this SCC by inlining: "
|
||||||
<< F.getName() << " -> " << Callee.getName() << "\n");
|
<< F.getName() << " -> " << Callee.getName() << "\n");
|
||||||
setInlineRemark(CS, "recursive SCC split");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<InlineCost> OIC = shouldInline(CS, GetInlineCost, ORE);
|
Optional<InlineCost> OIC = shouldInline(CS, GetInlineCost, ORE);
|
||||||
// Check whether we want to inline this callsite.
|
// Check whether we want to inline this callsite.
|
||||||
if (!OIC.hasValue()) {
|
if (!OIC || !*OIC)
|
||||||
setInlineRemark(CS, "deferred");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!OIC.getValue()) {
|
|
||||||
// shouldInline() call returned a negative inline cost that explains
|
|
||||||
// why this callsite should not be inlined.
|
|
||||||
setInlineRemark(CS, inlineCostStr(*OIC));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup the data structure used to plumb customization into the
|
// Setup the data structure used to plumb customization into the
|
||||||
// `InlineFunction` routine.
|
// `InlineFunction` routine.
|
||||||
@ -1060,7 +1018,6 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
|
|||||||
|
|
||||||
InlineResult IR = InlineFunction(CS, IFI);
|
InlineResult IR = InlineFunction(CS, IFI);
|
||||||
if (!IR) {
|
if (!IR) {
|
||||||
setInlineRemark(CS, std::string(IR) + "; " + inlineCostStr(*OIC));
|
|
||||||
ORE.emit([&]() {
|
ORE.emit([&]() {
|
||||||
return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
|
return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
|
||||||
<< NV("Callee", &Callee) << " will not be inlined into "
|
<< NV("Callee", &Callee) << " will not be inlined into "
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
; RUN: opt < %s -inline -inline-remark-attribute --inline-threshold=-2 -S | FileCheck %s
|
|
||||||
|
|
||||||
; Test that the inliner adds inline remark attributes to non-inlined callsites.
|
|
||||||
|
|
||||||
define void @foo() {
|
|
||||||
call void @bar(i1 true)
|
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
define void @bar(i1 %p) {
|
|
||||||
br i1 %p, label %bb1, label %bb2
|
|
||||||
|
|
||||||
bb1:
|
|
||||||
call void @foo()
|
|
||||||
ret void
|
|
||||||
|
|
||||||
bb2:
|
|
||||||
call void @bar(i1 true)
|
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
;; Test 1 - Add different inline remarks to similar callsites.
|
|
||||||
define void @test1() {
|
|
||||||
; CHECK-LABEL: @test1
|
|
||||||
; CHECK-NEXT: call void @bar(i1 true) [[ATTR1:#[0-9]+]]
|
|
||||||
; CHECK-NEXT: call void @bar(i1 false) [[ATTR2:#[0-9]+]]
|
|
||||||
call void @bar(i1 true)
|
|
||||||
call void @bar(i1 false)
|
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
define void @noop() {
|
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
;; Test 2 - Printed InlineResult messages are followed by InlineCost.
|
|
||||||
define void @test2(i8*) {
|
|
||||||
; CHECK-LABEL: @test2
|
|
||||||
; CHECK-NEXT: call void @noop() [[ATTR3:#[0-9]+]] [ "CUSTOM_OPERAND_BUNDLE"() ]
|
|
||||||
; CHECK-NEXT: ret void
|
|
||||||
call void @noop() ; extepected to be inlined
|
|
||||||
call void @noop() [ "CUSTOM_OPERAND_BUNDLE"() ] ; cannot be inlined because of unsupported operand bundle
|
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
; CHECK: attributes [[ATTR1]] = { "inline-remark"="(cost=-5, threshold=-6)" }
|
|
||||||
; CHECK: attributes [[ATTR2]] = { "inline-remark"="(cost=never): recursive" }
|
|
||||||
; CHECK: attributes [[ATTR3]] = { "inline-remark"="unsupported operand bundle; (cost={{.*}}, threshold={{.*}})" }
|
|
||||||
; RUN: opt < %s -inline -inline-remark-attribute --inline-threshold=-2 -S | FileCheck %s
|
|
||||||
|
|
||||||
; Test that the inliner adds inline remark attributes to non-inlined callsites.
|
|
||||||
|
|
||||||
define void @foo() {
|
|
||||||
call void @bar(i1 true)
|
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
define void @bar(i1 %p) {
|
|
||||||
br i1 %p, label %bb1, label %bb2
|
|
||||||
|
|
||||||
bb1:
|
|
||||||
call void @foo()
|
|
||||||
ret void
|
|
||||||
|
|
||||||
bb2:
|
|
||||||
call void @bar(i1 true)
|
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
;; Test 1 - Add different inline remarks to similar callsites.
|
|
||||||
define void @test1() {
|
|
||||||
; CHECK-LABEL: @test1
|
|
||||||
; CHECK-NEXT: call void @bar(i1 true) [[ATTR1:#[0-9]+]]
|
|
||||||
; CHECK-NEXT: call void @bar(i1 false) [[ATTR2:#[0-9]+]]
|
|
||||||
call void @bar(i1 true)
|
|
||||||
call void @bar(i1 false)
|
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
define void @noop() {
|
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
;; Test 2 - Printed InlineResult messages are followed by InlineCost.
|
|
||||||
define void @test2(i8*) {
|
|
||||||
; CHECK-LABEL: @test2
|
|
||||||
; CHECK-NEXT: call void @noop() [[ATTR3:#[0-9]+]] [ "CUSTOM_OPERAND_BUNDLE"() ]
|
|
||||||
; CHECK-NEXT: ret void
|
|
||||||
call void @noop() ; extepected to be inlined
|
|
||||||
call void @noop() [ "CUSTOM_OPERAND_BUNDLE"() ] ; cannot be inlined because of unsupported operand bundle
|
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
; CHECK: attributes [[ATTR1]] = { "inline-remark"="(cost=-5, threshold=-6)" }
|
|
||||||
; CHECK: attributes [[ATTR2]] = { "inline-remark"="(cost=never): recursive" }
|
|
||||||
; CHECK: attributes [[ATTR3]] = { "inline-remark"="unsupported operand bundle; (cost={{.*}}, threshold={{.*}})" }
|
|
Loading…
x
Reference in New Issue
Block a user