[llvm] r270245 - [RegBankSelect] Take advantage of a potential best cost information in

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Fri May 20 11:00:46 PDT 2016


Author: qcolombet
Date: Fri May 20 13:00:46 2016
New Revision: 270245

URL: http://llvm.org/viewvc/llvm-project?rev=270245&view=rev
Log:
[RegBankSelect] Take advantage of a potential best cost information in
computeMapping.

Computing the cost of a mapping takes some time.
Since in Fast mode, the cost is irrelevant, just spare some cycles by not
computing it.
In Greedy mode, we need to choose the best cost, that means that when
the local cost gets more expensive than the best cost, we can stop
computing the repairing and cost for the current mapping.

Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/RegBankSelect.h
    llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/RegBankSelect.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/RegBankSelect.h?rev=270245&r1=270244&r2=270245&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegBankSelect.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegBankSelect.h Fri May 20 13:00:46 2016
@@ -533,10 +533,15 @@ private:
   /// Compute the cost of mapping \p MI with \p InstrMapping and
   /// compute the repairing placement for such mapping in \p
   /// RepairPts.
+  /// \p BestCost is used to specify when the cost becomes too high
+  /// and thus it is not worth computing the RepairPts.  Moreover if
+  /// \p BestCost == nullptr, the mapping cost is actually not
+  /// computed.
   MappingCost
   computeMapping(MachineInstr &MI,
                  const RegisterBankInfo::InstructionMapping &InstrMapping,
-                 SmallVectorImpl<RepairingPlacement> &RepairPts);
+                 SmallVectorImpl<RepairingPlacement> &RepairPts,
+                 const MappingCost *BestCost = nullptr);
 
   /// When \p RepairPt involves splitting to repair \p MO for the
   /// given \p ValMapping, try to change the way we repair such that

Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp?rev=270245&r1=270244&r2=270245&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp Fri May 20 13:00:46 2016
@@ -291,7 +291,9 @@ void RegBankSelect::tryAvoidingSplit(
 
 RegBankSelect::MappingCost RegBankSelect::computeMapping(
     MachineInstr &MI, const RegisterBankInfo::InstructionMapping &InstrMapping,
-    SmallVectorImpl<RepairingPlacement> &RepairPts) {
+    SmallVectorImpl<RepairingPlacement> &RepairPts,
+    const RegBankSelect::MappingCost *BestCost) {
+  assert((MBFI || !BestCost) && "Costs comparison require MBFI");
 
   // If mapped with InstrMapping, MI will have the recorded cost.
   MappingCost Cost(MBFI ? MBFI->getBlockFreq(MI.getParent()) : 1);
@@ -300,6 +302,9 @@ RegBankSelect::MappingCost RegBankSelect
   DEBUG(dbgs() << "Evaluating mapping cost for: " << MI);
   DEBUG(dbgs() << "With: " << InstrMapping << '\n');
   RepairPts.clear();
+  if (BestCost && Cost > *BestCost)
+    return Cost;
+
   // Moreover, to realize this mapping, the register bank of each operand must
   // match this mapping. In other words, we may need to locally reassign the
   // register banks. Account for that repairing cost as well.
@@ -356,10 +361,14 @@ RegBankSelect::MappingCost RegBankSelect
       return MappingCost::ImpossibleCost();
 
     // Account for the split cost and repair cost.
-    // Unless the cost is already saturated.
-    if (Saturated)
+    // Unless the cost is already saturated or we do not care about the cost.
+    if (!BestCost || Saturated)
       continue;
 
+    // To get accurate information we need MBFI and MBPI.
+    // Thus, if we end up here this information should be here.
+    assert(MBFI && MBPI && "Cost computation requires MBFI and MBPI");
+
     // Sums up the repairing cost of at each insertion point.
     // TODO: Get the actual repairing cost.
     uint64_t RepairCost = 1;
@@ -393,6 +402,12 @@ RegBankSelect::MappingCost RegBankSelect
         else
           Saturated = Cost.addNonLocalCost(PtCost);
       }
+
+      // Stop looking into what it takes to repair, this is already
+      // too expensive.
+      if (BestCost && Cost > *BestCost)
+        return Cost;
+
       // No need to accumulate more cost information.
       // We need to still gather the repairing information though.
       if (Saturated)




More information about the llvm-commits mailing list