[llvm-commits] [llvm] r112743 - /llvm/trunk/lib/CodeGen/RegAllocLinearScan.cpp

Jim Grosbach grosbach at apple.com
Wed Sep 1 14:34:41 PDT 2010


Author: grosbach
Date: Wed Sep  1 16:34:41 2010
New Revision: 112743

URL: http://llvm.org/viewvc/llvm-project?rev=112743&view=rev
Log:
cleanup per feedback. use a helper function for getting the first non-reserved
physical register in a register class. Make sure to assert if the register
class is empty.

Modified:
    llvm/trunk/lib/CodeGen/RegAllocLinearScan.cpp

Modified: llvm/trunk/lib/CodeGen/RegAllocLinearScan.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocLinearScan.cpp?rev=112743&r1=112742&r2=112743&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegAllocLinearScan.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegAllocLinearScan.cpp Wed Sep  1 16:34:41 2010
@@ -336,6 +336,17 @@
                             SmallVector<unsigned, 256> &inactiveCounts,
                             bool SkipDGRegs);
 
+    /// getFirstNonReservedPhysReg - return the first non-reserved physical
+    /// register in the register class.
+    unsigned getFirstNonReservedPhysReg(const TargetRegisterClass *RC) {
+        TargetRegisterClass::iterator aoe = RC->allocation_order_end(*mf_);
+        TargetRegisterClass::iterator i = RC->allocation_order_begin(*mf_);
+        while (i != aoe && reservedRegs_.test(*i))
+          ++i;
+        assert(i != aoe && "All registers reserved?!");
+        return *i;
+      }
+
     void ComputeRelatedRegClasses();
 
     template <typename ItTy>
@@ -951,14 +962,8 @@
   const TargetRegisterClass *RC = mri_->getRegClass(cur->reg);
   if (cur->empty()) {
     unsigned physReg = vrm_->getRegAllocPref(cur->reg);
-    if (!physReg) {
-      TargetRegisterClass::iterator aoe = RC->allocation_order_end(*mf_);
-      TargetRegisterClass::iterator i = RC->allocation_order_begin(*mf_);
-      while (reservedRegs_.test(*i) && i != aoe)
-        ++i;
-      assert(i != aoe && "All registers reserved?!");
-      physReg = *i;
-    }
+    if (!physReg)
+      physReg = getFirstNonReservedPhysReg(RC);
     DEBUG(dbgs() <<  tri_->getName(physReg) << '\n');
     // Note the register is not really in use.
     vrm_->assignVirt2Phys(cur->reg, physReg);
@@ -1168,15 +1173,7 @@
   minWeight = RegsWeights[0].second;
   if (minWeight == HUGE_VALF) {
     // All registers must have inf weight. Just grab one!
-    if (BestPhysReg == 0) {
-      TargetRegisterClass::iterator aoe = RC->allocation_order_end(*mf_);
-      TargetRegisterClass::iterator i = RC->allocation_order_begin(*mf_);
-      while (reservedRegs_.test(*i) && i != aoe)
-        ++i;
-      assert(i != aoe && "All registers reserved?!");
-      minReg = *i;
-    } else
-      minReg = BestPhysReg;
+    minReg = BestPhysReg ? BestPhysReg : getFirstNonReservedPhysReg(RC);
     if (cur->weight == HUGE_VALF ||
         li_->getApproximateInstructionCount(*cur) == 0) {
       // Spill a physical register around defs and uses.





More information about the llvm-commits mailing list