[PATCH] D99302: [InlineCost] Make cost-benefit decision explicit

Wenlei He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 24 14:43:34 PDT 2021


wenlei created this revision.
wenlei added reviewers: hoy, wmi, davidxl, kazu.
Herald added subscribers: modimo, lxfind, haicheng, hiraditya, eraman.
wenlei requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99302

Files:
  llvm/lib/Analysis/InlineCost.cpp


Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -489,6 +489,9 @@
   // 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;
@@ -825,6 +828,7 @@
       Threshold -= VectorBonus / 2;
 
     if (auto Result = costBenefitAnalysis()) {
+      DecidedByCostBenefit = true;
       if (Result.getValue())
         return InlineResult::success();
       else
@@ -926,6 +930,7 @@
   virtual ~InlineCostCallAnalyzer() {}
   int getThreshold() { return Threshold; }
   int getCost() { return Cost; }
+  bool wasDecidedByCostBenefit() { return DecidedByCostBenefit; }
 };
 } // namespace
 
@@ -2610,6 +2615,8 @@
   LLVM_DEBUG(CA.dump());
 
   // Check if there was a reason to force inlining or no inlining.
+  if (ShouldInline.isSuccess() && CA.wasDecidedByCostBenefit())
+    return InlineCost::getAlways("benefit over cost");
   if (!ShouldInline.isSuccess() && CA.getCost() < CA.getThreshold())
     return InlineCost::getNever(ShouldInline.getFailureReason());
   if (ShouldInline.isSuccess() && CA.getCost() >= CA.getThreshold())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99302.333133.patch
Type: text/x-patch
Size: 1345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210324/4fb527cc/attachment.bin>


More information about the llvm-commits mailing list