]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - dfg/DFGScoreBoard.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGScoreBoard.h
index 8701fc7406d11d0c42fdfaa70ff2cbeb8d1074d1..c8795c8a448adda936873ce56a76ba4a065916f6 100644 (file)
@@ -43,18 +43,11 @@ namespace JSC { namespace DFG {
 // another node.
 class ScoreBoard {
 public:
-    ScoreBoard(const BitVector& usedVars)
-        : m_highWatermark(0)
+    ScoreBoard(unsigned nextMachineLocal)
+        : m_highWatermark(nextMachineLocal + 1)
     {
-        m_used.fill(0, usedVars.size());
-        m_free.reserveCapacity(usedVars.size());
-        for (size_t i = usedVars.size(); i-- > 0;) {
-            if (usedVars.get(i)) {
-                m_used[i] = max(); // This is mostly for debugging and sanity.
-                m_highWatermark = std::max(m_highWatermark, static_cast<unsigned>(i) + 1);
-            } else
-                m_free.append(i);
-        }
+        m_used.fill(max(), nextMachineLocal);
+        m_free.reserveCapacity(nextMachineLocal);
     }
 
     ~ScoreBoard()
@@ -62,21 +55,27 @@ public:
         assertClear();
     }
     
+    void sortFree()
+    {
+        std::sort(m_free.begin(), m_free.end());
+    }
+    
     void assertClear()
     {
-#if !ASSERT_DISABLED
+        if (ASSERT_DISABLED)
+            return;
+        
         // For every entry in the used list the use count of the virtual register should be zero, or max, due to it being a preserved local.
         for (size_t i = 0; i < m_used.size(); ++i)
-            ASSERT(!m_used[i] || m_used[i] == max());
+            RELEASE_ASSERT(!m_used[i] || m_used[i] == max());
         // For every entry in the free list, the use count should be zero.
         for (size_t i = 0; i < m_free.size(); ++i)
-            ASSERT(!m_used[m_free[i]]);
+            RELEASE_ASSERT(!m_used[m_free[i]]);
         // There must not be duplicates in the free list.
         for (size_t i = 0; i < m_free.size(); ++i) {
             for (size_t j = i + 1; j < m_free.size(); ++j)
-                ASSERT(m_free[i] != m_free[j]);
+                RELEASE_ASSERT(m_free[i] != m_free[j]);
         }
-#endif
     }
 
     VirtualRegister allocate()
@@ -89,39 +88,32 @@ public:
             // Use count must have hit zero for it to have been added to the free list!
             ASSERT(!m_used[index]);
             m_highWatermark = std::max(m_highWatermark, static_cast<unsigned>(index) + 1);
-            return (VirtualRegister)index;
+            return virtualRegisterForLocal(index);
         }
 
         // Allocate a new VirtualRegister, and add a corresponding entry to m_used.
         size_t next = m_used.size();
         m_used.append(0);
         m_highWatermark = std::max(m_highWatermark, static_cast<unsigned>(next) + 1);
-        return (VirtualRegister)next;
+        return virtualRegisterForLocal(next);
     }
 
-    // Increment the usecount for the VirtualRegsiter associated with 'child',
-    // if it reaches the node's refcount, free the VirtualRegsiter.
+    // Increment the usecount for the VirtualRegister associated with 'child',
+    // if it reaches the node's refcount, free the VirtualRegister.
     void use(Node* child)
     {
         if (!child)
             return;
 
         // Find the virtual register number for this child, increment its use count.
-        uint32_t index = child->virtualRegister();
+        uint32_t index = child->virtualRegister().toLocal();
         ASSERT(m_used[index] != max());
         if (child->refCount() == ++m_used[index]) {
-#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
-            dataLogF(" Freeing virtual register %u.", index);
-#endif
             // If the use count in the scoreboard reaches the use count for the node,
             // then this was its last use; the virtual register is now free.
             // Clear the use count & add to the free list.
             m_used[index] = 0;
             m_free.append(index);
-        } else {
-#if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE)
-            dataLogF(" Virtual register %u is at %u/%u uses.", index, m_used[index], child->refCount());
-#endif
         }
     }
     void use(Edge child)