[PATCH] D94427: [NFC][InstructionCost] Use InstructionCost in lib/Transforms/IPO/IROutliner.cpp

David Sherwood via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 11 09:16:01 PST 2021


david-arm created this revision.
david-arm added reviewers: sdesmalen, CarolineConcatto, ctetreau.
Herald added a subscriber: hiraditya.
david-arm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In places where we call a TTI.getXXCost() function I have changed
the code to use InstructionCost instead of unsigned. This is in
preparation for later on when we will change the TTI interfaces
to return InstructionCost.

See this patch for the introduction of the type: https://reviews.llvm.org/D91174
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2020-November/146408.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94427

Files:
  llvm/lib/Transforms/IPO/IROutliner.cpp


Index: llvm/lib/Transforms/IPO/IROutliner.cpp
===================================================================
--- llvm/lib/Transforms/IPO/IROutliner.cpp
+++ llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -1292,7 +1292,7 @@
 }
 
 unsigned IROutliner::findCostOutputReloads(OutlinableGroup &CurrentGroup) {
-  unsigned OverallCost = 0;
+  InstructionCost OverallCost = 0;
   for (OutlinableRegion *Region : CurrentGroup.Regions) {
     TargetTransformInfo &TTI = getTTI(*Region->StartBB->getParent());
 
@@ -1301,7 +1301,7 @@
       Optional<Value *> OV = Region->Candidate->fromGVN(OutputGVN);
       assert(OV.hasValue() && "Could not find value for GVN?");
       Value *V = OV.getValue();
-      unsigned LoadCost =
+      InstructionCost LoadCost =
           TTI.getMemoryOpCost(Instruction::Load, V->getType(), Align(1), 0,
                               TargetTransformInfo::TCK_CodeSize);
 
@@ -1312,7 +1312,8 @@
     }
   }
 
-  return OverallCost;
+  assert(OverallCost.isValid() && "Invalid cost found");
+  return *OverallCost.getValue();
 }
 
 /// Find the extra instructions needed to handle any output values for the
@@ -1326,7 +1327,7 @@
 static unsigned findCostForOutputBlocks(Module &M,
                                         OutlinableGroup &CurrentGroup,
                                         TargetTransformInfo &TTI) {
-  unsigned OutputCost = 0;
+  InstructionCost OutputCost = 0;
 
   for (const ArrayRef<unsigned> &OutputUse :
        CurrentGroup.OutputGVNCombinations) {
@@ -1335,7 +1336,7 @@
       Optional<Value *> OV = Candidate.fromGVN(GVN);
       assert(OV.hasValue() && "Could not find value for GVN?");
       Value *V = OV.getValue();
-      unsigned StoreCost =
+      InstructionCost StoreCost =
           TTI.getMemoryOpCost(Instruction::Load, V->getType(), Align(1), 0,
                               TargetTransformInfo::TCK_CodeSize);
 
@@ -1348,7 +1349,7 @@
       OutputCost += StoreCost;
     }
 
-    unsigned BranchCost =
+    InstructionCost BranchCost =
         TTI.getCFInstrCost(Instruction::Br, TargetTransformInfo::TCK_CodeSize);
     LLVM_DEBUG(dbgs() << "Adding " << BranchCost << " to the current cost for"
                       << " a branch instruction\n");
@@ -1358,15 +1359,15 @@
   // If there is more than one output scheme, we must have a comparison and
   // branch for each different item in the switch statement.
   if (CurrentGroup.OutputGVNCombinations.size() > 1) {
-    unsigned ComparisonCost = TTI.getCmpSelInstrCost(
+    InstructionCost ComparisonCost = TTI.getCmpSelInstrCost(
         Instruction::ICmp, Type::getInt32Ty(M.getContext()),
         Type::getInt32Ty(M.getContext()), CmpInst::BAD_ICMP_PREDICATE,
         TargetTransformInfo::TCK_CodeSize);
-    unsigned BranchCost =
+    InstructionCost BranchCost =
         TTI.getCFInstrCost(Instruction::Br, TargetTransformInfo::TCK_CodeSize);
 
     unsigned DifferentBlocks = CurrentGroup.OutputGVNCombinations.size();
-    unsigned TotalCost = ComparisonCost * BranchCost * DifferentBlocks;
+    InstructionCost TotalCost = ComparisonCost * BranchCost * DifferentBlocks;
 
     LLVM_DEBUG(dbgs() << "Adding: " << TotalCost
                       << " instructions for each switch case for each different"
@@ -1374,7 +1375,8 @@
     OutputCost += TotalCost;
   }
 
-  return OutputCost;
+  assert(OutputCost.isValid() && "Invalid cost found");
+  return *OutputCost.getValue();
 }
 
 void IROutliner::findCostBenefit(Module &M, OutlinableGroup &CurrentGroup) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94427.315828.patch
Type: text/x-patch
Size: 3500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210111/88b1babd/attachment.bin>


More information about the llvm-commits mailing list