diff options
author | Kazu Hirata <kazu@google.com> | 2022-09-25 23:21:40 -0700 |
---|---|---|
committer | Kazu Hirata <kazu@google.com> | 2022-09-25 23:21:40 -0700 |
commit | e2398a4d7cfc0415c63cc13792bda80045c7c803 (patch) | |
tree | c6d99d71ce8627c28bcd8b039c32d93379eb8957 /llvm/lib/Analysis/InlineCost.cpp | |
parent | 06b1e5fdc32db61b59ad9ca605137d2a369e562e (diff) | |
download | llvm-e2398a4d7cfc0415c63cc13792bda80045c7c803.zip llvm-e2398a4d7cfc0415c63cc13792bda80045c7c803.tar.gz llvm-e2398a4d7cfc0415c63cc13792bda80045c7c803.tar.bz2 |
[Analysis] Introduce getStaticBonusApplied (NFC)
InlineCostCallAnalyzer encourages inlining of the last call to the
static function by subtracting LastCallToStaticBonus from Cost.
This patch introduces getStaticBonusApplied to make available the
amount of LastCallToStaticBonus applied.
The intent is to allow the module inliner to determine whether
inlining a given call site is expected to reduce the caller size with
an expression like:
IC.getCost() + IC.getStaticBonusApplied() < 0
This patch does not add a use of getStaticBonus yet.
Differential Revision: https://reviews.llvm.org/D134373
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index e193cee..e17b908 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -549,6 +549,9 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { /// for speculative "expected profit" of the inlining decision. int Threshold = 0; + /// The amount of StaticBonus applied. + int StaticBonusApplied = 0; + /// Attempt to evaluate indirect calls to boost its inline cost. const bool BoostIndirectCalls; @@ -1058,6 +1061,7 @@ public: virtual ~InlineCostCallAnalyzer() = default; int getThreshold() const { return Threshold; } int getCost() const { return Cost; } + int getStaticBonusApplied() const { return StaticBonusApplied; } Optional<CostBenefitPair> getCostBenefitPair() { return CostBenefit; } bool wasDecidedByCostBenefit() const { return DecidedByCostBenefit; } bool wasDecidedByCostThreshold() const { return DecidedByCostThreshold; } @@ -1922,8 +1926,10 @@ void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) { // If there is only one call of the function, and it has internal linkage, // the cost of inlining it drops dramatically. It may seem odd to update // Cost in updateThreshold, but the bonus depends on the logic in this method. - if (isSoleCallToLocalFunction(Call, F)) + if (isSoleCallToLocalFunction(Call, F)) { Cost -= LastCallToStaticBonus; + StaticBonusApplied = LastCallToStaticBonus; + } } bool CallAnalyzer::visitCmpInst(CmpInst &I) { @@ -2970,7 +2976,8 @@ InlineCost llvm::getInlineCost( } if (CA.wasDecidedByCostThreshold()) - return InlineCost::get(CA.getCost(), CA.getThreshold()); + return InlineCost::get(CA.getCost(), CA.getThreshold(), + CA.getStaticBonusApplied()); // No details on how the decision was made, simply return always or never. return ShouldInline.isSuccess() |