Be a little more conservative about emitting table-based switches
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Jan 2013 05:43:47 +0000 (05:43 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Jan 2013 05:43:47 +0000 (05:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108292

Reviewed by Filip Pizlo.

Profiling shows we're using op_switch in cases where it's a regression.

* bytecompiler/NodesCodegen.cpp:
(JSC):
(JSC::length):
(JSC::CaseBlockNode::tryTableSwitch):
(JSC::CaseBlockNode::emitBytecodeForBlock):
* parser/Nodes.h:
(CaseBlockNode):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@141222 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
Source/JavaScriptCore/parser/Nodes.h

index 5b504fc..08982ed 100644 (file)
@@ -1,3 +1,20 @@
+2013-01-29  Geoffrey Garen  <ggaren@apple.com>
+
+        Be a little more conservative about emitting table-based switches
+        https://bugs.webkit.org/show_bug.cgi?id=108292
+
+        Reviewed by Filip Pizlo.
+
+        Profiling shows we're using op_switch in cases where it's a regression.
+
+        * bytecompiler/NodesCodegen.cpp:
+        (JSC):
+        (JSC::length):
+        (JSC::CaseBlockNode::tryTableSwitch):
+        (JSC::CaseBlockNode::emitBytecodeForBlock):
+        * parser/Nodes.h:
+        (CaseBlockNode):
+
 2013-01-29  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r140983.
index ae4a570..4e745e1 100644 (file)
@@ -1851,9 +1851,22 @@ static void processClauseList(ClauseListNode* list, Vector<ExpressionNode*, 8>&
         break;        
     }
 }
-    
-SwitchInfo::SwitchType CaseBlockNode::tryOptimizedSwitch(Vector<ExpressionNode*, 8>& literalVector, int32_t& min_num, int32_t& max_num)
+
+static inline size_t length(ClauseListNode* list1, ClauseListNode* list2)
 {
+    size_t length = 0;
+    for (ClauseListNode* node = list1; node; node = node->getNext())
+        ++length;
+    for (ClauseListNode* node = list2; node; node = node->getNext())
+        ++length;
+    return length;
+}
+
+SwitchInfo::SwitchType CaseBlockNode::tryTableSwitch(Vector<ExpressionNode*, 8>& literalVector, int32_t& min_num, int32_t& max_num)
+{
+    if (length(m_list1, m_list2) < s_tableSwitchMinimum)
+        return SwitchInfo::SwitchNone;
+
     SwitchKind typeForTable = SwitchUnset;
     bool singleCharacterSwitch = true;
     
@@ -1888,7 +1901,7 @@ RegisterID* CaseBlockNode::emitBytecodeForBlock(BytecodeGenerator& generator, Re
     Vector<ExpressionNode*, 8> literalVector;
     int32_t min_num = std::numeric_limits<int32_t>::max();
     int32_t max_num = std::numeric_limits<int32_t>::min();
-    SwitchInfo::SwitchType switchType = tryOptimizedSwitch(literalVector, min_num, max_num);
+    SwitchInfo::SwitchType switchType = tryTableSwitch(literalVector, min_num, max_num);
 
     if (switchType != SwitchInfo::SwitchNone) {
         // Prepare the various labels
index 5296e23..05f662e 100644 (file)
@@ -1509,7 +1509,8 @@ namespace JSC {
         RegisterID* emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* destination);
 
     private:
-        SwitchInfo::SwitchType tryOptimizedSwitch(Vector<ExpressionNode*, 8>& literalVector, int32_t& min_num, int32_t& max_num);
+        SwitchInfo::SwitchType tryTableSwitch(Vector<ExpressionNode*, 8>& literalVector, int32_t& min_num, int32_t& max_num);
+        static const size_t s_tableSwitchMinimum = 10;
         ClauseListNode* m_list1;
         CaseClauseNode* m_defaultClause;
         ClauseListNode* m_list2;