Title: [134182] trunk/Source/_javascript_Core
Revision
134182
Author
[email protected]
Date
2012-11-11 18:08:06 -0800 (Sun, 11 Nov 2012)

Log Message

DFG register allocation should be greedy rather than round-robin
https://bugs.webkit.org/show_bug.cgi?id=101870

Reviewed by Geoffrey Garen.

This simplifies the code, reduces some code duplication, and shows some slight
performance improvements in a few places, likely due to the fact that lower-numered
registers also typically have smaller encodings.

* dfg/DFGRegisterBank.h:
(JSC::DFG::RegisterBank::RegisterBank):
(JSC::DFG::RegisterBank::tryAllocate):
(JSC::DFG::RegisterBank::allocate):
(JSC::DFG::RegisterBank::allocateInternal):
(RegisterBank):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (134181 => 134182)


--- trunk/Source/_javascript_Core/ChangeLog	2012-11-12 01:41:50 UTC (rev 134181)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-11-12 02:08:06 UTC (rev 134182)
@@ -1,3 +1,21 @@
+2012-11-11  Filip Pizlo  <[email protected]>
+
+        DFG register allocation should be greedy rather than round-robin
+        https://bugs.webkit.org/show_bug.cgi?id=101870
+
+        Reviewed by Geoffrey Garen.
+
+        This simplifies the code, reduces some code duplication, and shows some slight
+        performance improvements in a few places, likely due to the fact that lower-numered
+        registers also typically have smaller encodings.
+
+        * dfg/DFGRegisterBank.h:
+        (JSC::DFG::RegisterBank::RegisterBank):
+        (JSC::DFG::RegisterBank::tryAllocate):
+        (JSC::DFG::RegisterBank::allocate):
+        (JSC::DFG::RegisterBank::allocateInternal):
+        (RegisterBank):
+
 2012-11-11  Kenichi Ishibashi  <[email protected]>
 
         WTFString::utf8() should have a mode of conversion to use replacement character

Modified: trunk/Source/_javascript_Core/dfg/DFGRegisterBank.h (134181 => 134182)


--- trunk/Source/_javascript_Core/dfg/DFGRegisterBank.h	2012-11-12 01:41:50 UTC (rev 134181)
+++ trunk/Source/_javascript_Core/dfg/DFGRegisterBank.h	2012-11-12 02:08:06 UTC (rev 134182)
@@ -75,7 +75,6 @@
 
 public:
     RegisterBank()
-        : m_lastAllocated(NUM_REGS - 1)
     {
     }
 
@@ -86,15 +85,10 @@
     {
         VirtualRegister ignored;
         
-        for (uint32_t i = m_lastAllocated + 1; i < NUM_REGS; ++i) {
+        for (uint32_t i = 0; i < NUM_REGS; ++i) {
             if (!m_data[i].lockCount && m_data[i].name == InvalidVirtualRegister)
                 return allocateInternal(i, ignored);
         }
-        // Loop over the remaining entries.
-        for (uint32_t i = 0; i <= m_lastAllocated; ++i) {
-            if (!m_data[i].lockCount && m_data[i].name == InvalidVirtualRegister)
-                return allocateInternal(i, ignored);
-        }
         
         return (RegID)-1;
     }
@@ -115,9 +109,6 @@
         uint32_t currentLowest = NUM_REGS;
         SpillHint currentSpillOrder = SpillHintInvalid;
 
-        // Scan through all register, starting at the last allocated & looping around.
-        ASSERT(m_lastAllocated < NUM_REGS);
-
         // This loop is broken into two halves, looping from the last allocated
         // register (the register returned last time this method was called) to
         // the maximum register value, then from 0 to the last allocated.
@@ -125,7 +116,7 @@
         // thrash, and minimize time spent scanning locked registers in allocation.
         // If a unlocked and unnamed register is found return it immediately.
         // Otherwise, find the first unlocked register with the lowest spillOrder.
-        for (uint32_t i = m_lastAllocated + 1; i < NUM_REGS; ++i) {
+        for (uint32_t i = 0 ; i < NUM_REGS; ++i) {
             // (1) If the current register is locked, it is not a candidate.
             if (m_data[i].lockCount)
                 continue;
@@ -140,18 +131,6 @@
                 currentLowest = i;
             }
         }
-        // Loop over the remaining entries.
-        for (uint32_t i = 0; i <= m_lastAllocated; ++i) {
-            if (m_data[i].lockCount)
-                continue;
-            SpillHint spillOrder = m_data[i].spillOrder;
-            if (spillOrder == SpillHintInvalid)
-                return allocateInternal(i, spillMe);
-            if (spillOrder < currentSpillOrder) {
-                currentSpillOrder = spillOrder;
-                currentLowest = i;
-            }
-        }
 
         // Deadlock check - this could only occur is all registers are locked!
         ASSERT(currentLowest != NUM_REGS && currentSpillOrder != SpillHintInvalid);
@@ -354,7 +333,6 @@
         // Mark the register as locked (with a lock count of 1).
         m_data[i].lockCount = 1;
 
-        m_lastAllocated = i;
         return BankInfo::toRegister(i);
     }
 
@@ -378,8 +356,6 @@
 
     // Holds the current status of all registers.
     MapEntry m_data[NUM_REGS];
-    // Used to to implement a simple round-robin like allocation scheme.
-    uint32_t m_lastAllocated;
 };
 
 } } // namespace JSC::DFG
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to