[PATCH] D105362: [NFC] Code cleanups in InlineCost.cpp.

Jacob Hegna via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 2 11:17:18 PDT 2021


jacobhegna created this revision.
jacobhegna added a reviewer: mtrofin.
Herald added subscribers: haicheng, hiraditya, eraman.
jacobhegna requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

- annotate const functions with "const"
- replace INT_MAX with std::numeric_limits<int>::max()
- replace C-style casts with static_cast


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105362

Files:
  llvm/lib/Analysis/InlineCost.cpp


Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -461,7 +461,8 @@
 /// FIXME: if it is necessary to derive from InlineCostCallAnalyzer, note
 /// the FIXME in onLoweredCall, when instantiating an InlineCostCallAnalyzer
 class InlineCostCallAnalyzer final : public CallAnalyzer {
-  const int CostUpperBound = INT_MAX - InlineConstants::InstrCost - 1;
+  const int CostUpperBound =
+      std::numeric_limits<int>::max() - InlineConstants::InstrCost - 1;
   const bool ComputeFullInlineCost;
   int LoadEliminationCost = 0;
   /// Bonus to be applied when percentage of vector instructions in callee is
@@ -532,9 +533,11 @@
                                         BlockFrequencyInfo *CallerBFI);
 
   /// Handle a capped 'int' increment for Cost.
-  void addCost(int64_t Inc, int64_t UpperBound = INT_MAX) {
-    assert(UpperBound > 0 && UpperBound <= INT_MAX && "invalid upper bound");
-    Cost = (int)std::min(UpperBound, Cost + Inc);
+  void addCost(int64_t Inc,
+               int64_t UpperBound = std::numeric_limits<int>::max()) {
+    assert(UpperBound > 0 && UpperBound <= std::numeric_limits<int>::max() &&
+           "invalid upper bound");
+    Cost = std::min<int>(UpperBound, Cost + Inc);
   }
 
   void onDisableSROA(AllocaInst *Arg) override {
@@ -595,10 +598,11 @@
     // branch to destination.
     // Maximum valid cost increased in this function.
     if (JumpTableSize) {
-      int64_t JTCost = (int64_t)JumpTableSize * InlineConstants::InstrCost +
-                       4 * InlineConstants::InstrCost;
+      int64_t JTCost =
+          static_cast<int64_t>(JumpTableSize) * InlineConstants::InstrCost +
+          4 * InlineConstants::InstrCost;
 
-      addCost(JTCost, (int64_t)CostUpperBound);
+      addCost(JTCost, static_cast<int64_t>(CostUpperBound));
       return;
     }
 
@@ -613,7 +617,7 @@
     int64_t SwitchCost =
         ExpectedNumberOfCompare * 2 * InlineConstants::InstrCost;
 
-    addCost(SwitchCost, (int64_t)CostUpperBound);
+    addCost(SwitchCost, static_cast<int64_t>(CostUpperBound));
   }
   void onMissedSimplification() override {
     addCost(InlineConstants::InstrCost);
@@ -938,9 +942,9 @@
   }
 
   virtual ~InlineCostCallAnalyzer() {}
-  int getThreshold() { return Threshold; }
-  int getCost() { return Cost; }
-  bool wasDecidedByCostBenefit() { return DecidedByCostBenefit; }
+  int getThreshold() const { return Threshold; }
+  int getCost() const { return Cost; }
+  bool wasDecidedByCostBenefit() const { return DecidedByCostBenefit; }
 };
 
 class InlineCostFeaturesAnalyzer final : public CallAnalyzer {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105362.356229.patch
Type: text/x-patch
Size: 2714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210702/bbee05a2/attachment.bin>


More information about the llvm-commits mailing list