1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[InlineCost] Make cost-benefit decision explicit

With cost-benefit analysis for inlining, we bypass the cost-threshold by returning inline result from call analyzer early.

However the cost and threshold are still available from call analyzer, and when cost is actually higher than threshold, we incorrect set the reason.

The change makes the decision from cost-benefit analysis explicit. It's mostly NFC, except that it allows the priority-based sample loader inliner used by CSSPGO to use cost-benefit heuristic.

Differential Revision: https://reviews.llvm.org/D99302
This commit is contained in:
Wenlei He 2021-03-24 14:33:45 -07:00
parent 4cf653e83d
commit 4391957539
2 changed files with 17 additions and 3 deletions

View File

@ -489,6 +489,9 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
// sense that it's not weighted by profile counts at all.
int ColdSize = 0;
// Whether inlining is decided by cost-benefit analysis.
bool DecidedByCostBenefit = false;
bool SingleBB = true;
unsigned SROACostSavings = 0;
@ -832,6 +835,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
Threshold -= VectorBonus / 2;
if (auto Result = costBenefitAnalysis()) {
DecidedByCostBenefit = true;
if (Result.getValue())
return InlineResult::success();
else
@ -933,6 +937,7 @@ public:
virtual ~InlineCostCallAnalyzer() {}
int getThreshold() { return Threshold; }
int getCost() { return Cost; }
bool wasDecidedByCostBenefit() { return DecidedByCostBenefit; }
};
} // namespace
@ -2616,6 +2621,16 @@ InlineCost llvm::getInlineCost(
LLVM_DEBUG(CA.dump());
// Always make cost benefit based decision explicit.
// We use always/never here since threshold is not meaningful,
// as it's not what drives cost-benefit analysis.
if (CA.wasDecidedByCostBenefit()) {
if (ShouldInline.isSuccess())
return InlineCost::getAlways("benefit over cost");
else
return InlineCost::getNever("cost over benefit");
}
// Check if there was a reason to force inlining or no inlining.
if (!ShouldInline.isSuccess() && CA.getCost() < CA.getThreshold())
return InlineCost::getNever(ShouldInline.getFailureReason());

View File

@ -10,14 +10,14 @@
; RUN: FileCheck %s -check-prefix=YAML-MISS < %t.yaml
;; test 'auto' threshold
; RUN: opt < %s --disable-output --enable-new-pm \
; RUN: opt < %s --disable-output --enable-new-pm --inline-enable-cost-benefit-analysis=0 \
; RUN: --passes='module(print-profile-summary,cgscc(inline))' \
; RUN: --pass-remarks-output=%t.hot.yaml --pass-remarks-filter='inline' \
; RUN: --pass-remarks-with-hotness --pass-remarks-hotness-threshold=auto 2>&1 | FileCheck %s
; RUN: FileCheck %s -check-prefix=YAML-PASS < %t.hot.yaml
; RUN: not FileCheck %s -check-prefix=YAML-MISS < %t.hot.yaml
; RUN: opt < %s --disable-output --enable-new-pm \
; RUN: opt < %s --disable-output --enable-new-pm --inline-enable-cost-benefit-analysis=0 \
; RUN: --passes='module(print-profile-summary,cgscc(inline))' \
; RUN: --pass-remarks=inline --pass-remarks-missed=inline --pass-remarks-analysis=inline \
; RUN: --pass-remarks-with-hotness --pass-remarks-hotness-threshold=auto 2>&1 | FileCheck %s -check-prefix=CHECK-RPASS
@ -82,4 +82,3 @@ entry:
!12 = !{i32 10000, i64 100, i32 1}
!13 = !{i32 999000, i64 100, i32 1}
!14 = !{i32 999999, i64 1, i32 2}