<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[183525] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/183525">183525</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2015-04-28 20:34:43 -0700 (Tue, 28 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>FTL should fully support Switch (it currently lacks the SwitchString variant)
https://bugs.webkit.org/show_bug.cgi?id=144348

Reviewed by Benjamin Poulain.
        
This adds SwitchString support to the FTL. This is already tested by switch microbenchmarks
in LayoutTests/js/regress.

* dfg/DFGCommon.cpp:
(JSC::DFG::stringLessThan):
* dfg/DFGCommon.h:
* dfg/DFGOperations.cpp:
* dfg/DFGOperations.h:
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::StringSwitchCase::operator&lt;): Deleted.
* dfg/DFGSpeculativeJIT.h:
(JSC::DFG::SpeculativeJIT::StringSwitchCase::operator&lt;):
* ftl/FTLCapabilities.cpp:
(JSC::FTL::canCompile):
* ftl/FTLIntrinsicRepository.h:
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::compileSwitch):
(JSC::FTL::LowerDFGToLLVM::switchString):
(JSC::FTL::LowerDFGToLLVM::StringSwitchCase::StringSwitchCase):
(JSC::FTL::LowerDFGToLLVM::StringSwitchCase::operator&lt;):
(JSC::FTL::LowerDFGToLLVM::CharacterCase::CharacterCase):
(JSC::FTL::LowerDFGToLLVM::CharacterCase::operator&lt;):
(JSC::FTL::LowerDFGToLLVM::switchStringRecurse):
(JSC::FTL::LowerDFGToLLVM::switchStringSlow):
(JSC::FTL::LowerDFGToLLVM::appendOSRExit):
* ftl/FTLOutput.cpp:
(JSC::FTL::Output::check):
* ftl/FTLOutput.h:
* ftl/FTLWeight.h:
(JSC::FTL::Weight::inverse):
* jit/JITOperations.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGCommoncpp">trunk/Source/JavaScriptCore/dfg/DFGCommon.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGCommonh">trunk/Source/JavaScriptCore/dfg/DFGCommon.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGOperationscpp">trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGOperationsh">trunk/Source/JavaScriptCore/dfg/DFGOperations.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGSpeculativeJITcpp">trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGSpeculativeJITh">trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLCapabilitiescpp">trunk/Source/JavaScriptCore/ftl/FTLCapabilities.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLIntrinsicRepositoryh">trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp">trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLOutputcpp">trunk/Source/JavaScriptCore/ftl/FTLOutput.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLOutputh">trunk/Source/JavaScriptCore/ftl/FTLOutput.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLWeighth">trunk/Source/JavaScriptCore/ftl/FTLWeight.h</a></li>
<li><a href="#trunkSourceJavaScriptCorejitJITOperationsh">trunk/Source/JavaScriptCore/jit/JITOperations.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2015-04-28  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        FTL should fully support Switch (it currently lacks the SwitchString variant)
+        https://bugs.webkit.org/show_bug.cgi?id=144348
+
+        Reviewed by Benjamin Poulain.
+        
+        This adds SwitchString support to the FTL. This is already tested by switch microbenchmarks
+        in LayoutTests/js/regress.
+
+        * dfg/DFGCommon.cpp:
+        (JSC::DFG::stringLessThan):
+        * dfg/DFGCommon.h:
+        * dfg/DFGOperations.cpp:
+        * dfg/DFGOperations.h:
+        * dfg/DFGSpeculativeJIT.cpp:
+        (JSC::DFG::SpeculativeJIT::StringSwitchCase::operator&lt;): Deleted.
+        * dfg/DFGSpeculativeJIT.h:
+        (JSC::DFG::SpeculativeJIT::StringSwitchCase::operator&lt;):
+        * ftl/FTLCapabilities.cpp:
+        (JSC::FTL::canCompile):
+        * ftl/FTLIntrinsicRepository.h:
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::LowerDFGToLLVM::compileSwitch):
+        (JSC::FTL::LowerDFGToLLVM::switchString):
+        (JSC::FTL::LowerDFGToLLVM::StringSwitchCase::StringSwitchCase):
+        (JSC::FTL::LowerDFGToLLVM::StringSwitchCase::operator&lt;):
+        (JSC::FTL::LowerDFGToLLVM::CharacterCase::CharacterCase):
+        (JSC::FTL::LowerDFGToLLVM::CharacterCase::operator&lt;):
+        (JSC::FTL::LowerDFGToLLVM::switchStringRecurse):
+        (JSC::FTL::LowerDFGToLLVM::switchStringSlow):
+        (JSC::FTL::LowerDFGToLLVM::appendOSRExit):
+        * ftl/FTLOutput.cpp:
+        (JSC::FTL::Output::check):
+        * ftl/FTLOutput.h:
+        * ftl/FTLWeight.h:
+        (JSC::FTL::Weight::inverse):
+        * jit/JITOperations.h:
+
</ins><span class="cx"> 2015-04-28  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Fully replace ENABLE_LLINT_C_LOOP with ENABLE_JIT
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGCommoncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGCommon.cpp (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGCommon.cpp        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/dfg/DFGCommon.cpp        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -46,6 +46,17 @@
</span><span class="cx">     return crashLock.isLocked();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool stringLessThan(StringImpl&amp; a, StringImpl&amp; b)
+{
+    unsigned minLength = std::min(a.length(), b.length());
+    for (unsigned i = 0; i &lt; minLength; ++i) {
+        if (a[i] == b[i])
+            continue;
+        return a[i] &lt; b[i];
+    }
+    return a.length() &lt; b.length();
+}
+
</ins><span class="cx"> } } // namespace JSC::DFG
</span><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGCommonh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGCommon.h (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGCommon.h        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/dfg/DFGCommon.h        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -297,6 +297,10 @@
</span><span class="cx">     unsigned index;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+// A less-than operator for strings that is useful for generating string switches. Sorts by &lt;
+// relation on characters. Ensures that if a is a prefix of b, then a &lt; b.
+bool stringLessThan(StringImpl&amp; a, StringImpl&amp; b);
+
</ins><span class="cx"> } } // namespace JSC::DFG
</span><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGOperationscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -1077,6 +1077,14 @@
</span><span class="cx">     return static_cast&lt;char*&gt;(exec-&gt;codeBlock()-&gt;stringSwitchJumpTable(tableIndex).ctiForValue(string-&gt;value(exec).impl()).executableAddress());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+int32_t JIT_OPERATION operationSwitchStringAndGetBranchOffset(ExecState* exec, size_t tableIndex, JSString* string)
+{
+    VM&amp; vm = exec-&gt;vm();
+    NativeCallFrameTracer tracer(&amp;vm, exec);
+
+    return exec-&gt;codeBlock()-&gt;stringSwitchJumpTable(tableIndex).offsetForValue(string-&gt;value(exec).impl(), std::numeric_limits&lt;int32_t&gt;::min());
+}
+
</ins><span class="cx"> void JIT_OPERATION operationNotifyWrite(ExecState* exec, WatchpointSet* set)
</span><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGOperationsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGOperations.h (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGOperations.h        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/dfg/DFGOperations.h        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -127,6 +127,7 @@
</span><span class="cx"> JSCell* JIT_OPERATION operationMakeRope3(ExecState*, JSString*, JSString*, JSString*);
</span><span class="cx"> char* JIT_OPERATION operationFindSwitchImmTargetForDouble(ExecState*, EncodedJSValue, size_t tableIndex);
</span><span class="cx"> char* JIT_OPERATION operationSwitchString(ExecState*, size_t tableIndex, JSString*);
</span><ins>+int32_t JIT_OPERATION operationSwitchStringAndGetBranchOffset(ExecState*, size_t tableIndex, JSString*);
</ins><span class="cx"> void JIT_OPERATION operationNotifyWrite(ExecState*, WatchpointSet*);
</span><span class="cx"> void JIT_OPERATION operationThrowStackOverflowForVarargs(ExecState*) WTF_INTERNAL;
</span><span class="cx"> int32_t JIT_OPERATION operationSizeOfVarargs(ExecState*, EncodedJSValue arguments, int32_t firstVarArgOffset);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGSpeculativeJITcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -5634,18 +5634,6 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool SpeculativeJIT::StringSwitchCase::operator&lt;(
-    const SpeculativeJIT::StringSwitchCase&amp; other) const
-{
-    unsigned minLength = std::min(string-&gt;length(), other.string-&gt;length());
-    for (unsigned i = 0; i &lt; minLength; ++i) {
-        if (string-&gt;at(i) == other.string-&gt;at(i))
-            continue;
-        return string-&gt;at(i) &lt; other.string-&gt;at(i);
-    }
-    return string-&gt;length() &lt; other.string-&gt;length();
-}
-
</del><span class="cx"> namespace {
</span><span class="cx"> 
</span><span class="cx"> struct CharacterCase {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGSpeculativeJITh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -2115,7 +2115,10 @@
</span><span class="cx">         {
</span><span class="cx">         }
</span><span class="cx">         
</span><del>-        bool operator&lt;(const StringSwitchCase&amp; other) const;
</del><ins>+        bool operator&lt;(const StringSwitchCase&amp; other) const
+        {
+            return stringLessThan(*string, *other.string);
+        }
</ins><span class="cx">         
</span><span class="cx">         StringImpl* string;
</span><span class="cx">         BasicBlock* target;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLCapabilitiescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLCapabilities.cpp (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLCapabilities.cpp        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/ftl/FTLCapabilities.cpp        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -188,6 +188,7 @@
</span><span class="cx">     case PhantomClonedArguments:
</span><span class="cx">     case GetMyArgumentByVal:
</span><span class="cx">     case ForwardVarargs:
</span><ins>+    case Switch:
</ins><span class="cx">         // These are OK.
</span><span class="cx">         break;
</span><span class="cx">     case Identity:
</span><span class="lines">@@ -350,16 +351,6 @@
</span><span class="cx">         if (node-&gt;isBinaryUseKind(UntypedUse))
</span><span class="cx">             break;
</span><span class="cx">         return CannotCompile;
</span><del>-    case Switch:
-        switch (node-&gt;switchData()-&gt;kind) {
-        case SwitchImm:
-        case SwitchChar:
-        case SwitchCell:
-            break;
-        default:
-            return CannotCompile;
-        }
-        break;
</del><span class="cx">     default:
</span><span class="cx">         // Don't know how to handle anything else.
</span><span class="cx">         return CannotCompile;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLIntrinsicRepositoryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -112,7 +112,8 @@
</span><span class="cx">     macro(V_JITOperation_Z, functionType(voidType, int32)) \
</span><span class="cx">     macro(Z_JITOperation_D, functionType(int32, doubleType)) \
</span><span class="cx">     macro(Z_JITOperation_EC, functionType(int32, intPtr, intPtr)) \
</span><del>-    macro(Z_JITOperation_EJZ, functionType(int32, intPtr, int64, int32))
</del><ins>+    macro(Z_JITOperation_EJZ, functionType(int32, intPtr, int64, int32)) \
+    macro(Z_JITOperation_ESJss, functionType(int32, intPtr, intPtr, int64)) \
</ins><span class="cx">     
</span><span class="cx"> class IntrinsicRepository : public CommonValues {
</span><span class="cx"> public:
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -4439,7 +4439,54 @@
</span><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         case SwitchString: {
</span><del>-            DFG_CRASH(m_graph, m_node, &quot;Unimplemented&quot;);
</del><ins>+            switch (m_node-&gt;child1().useKind()) {
+            case StringIdentUse: {
+                LValue stringImpl = lowStringIdent(m_node-&gt;child1());
+                
+                Vector&lt;SwitchCase&gt; cases;
+                for (unsigned i = 0; i &lt; data-&gt;cases.size(); ++i) {
+                    LValue value = m_out.constIntPtr(data-&gt;cases[i].value.stringImpl());
+                    LBasicBlock block = lowBlock(data-&gt;cases[i].target.block);
+                    Weight weight = Weight(data-&gt;cases[i].target.count);
+                    cases.append(SwitchCase(value, block, weight));
+                }
+                
+                m_out.switchInstruction(
+                    stringImpl, cases, lowBlock(data-&gt;fallThrough.block),
+                    Weight(data-&gt;fallThrough.count));
+                return;
+            }
+                
+            case StringUse: {
+                switchString(data, lowString(m_node-&gt;child1()));
+                return;
+            }
+                
+            case UntypedUse: {
+                LValue value = lowJSValue(m_node-&gt;child1());
+                
+                LBasicBlock isCellBlock = FTL_NEW_BLOCK(m_out, (&quot;Switch/SwitchString Untyped cell case&quot;));
+                LBasicBlock isStringBlock = FTL_NEW_BLOCK(m_out, (&quot;Switch/SwitchString Untyped string case&quot;));
+                
+                m_out.branch(
+                    isCell(value), unsure(isCellBlock), unsure(lowBlock(data-&gt;fallThrough.block)));
+                
+                LBasicBlock lastNext = m_out.appendTo(isCellBlock, isStringBlock);
+                
+                m_out.branch(
+                    isString(value),
+                    unsure(isStringBlock), unsure(lowBlock(data-&gt;fallThrough.block)));
+                
+                m_out.appendTo(isStringBlock, lastNext);
+                
+                switchString(data, value);
+                return;
+            }
+                
+            default:
+                DFG_CRASH(m_graph, m_node, &quot;Bad use kind&quot;);
+                return;
+            }
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">             
</span><span class="lines">@@ -6039,6 +6086,260 @@
</span><span class="cx">             lowBlock(data-&gt;fallThrough.block), Weight(data-&gt;fallThrough.count));
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+    void switchString(SwitchData* data, LValue string)
+    {
+        bool canDoBinarySwitch = true;
+        unsigned totalLength = 0;
+        
+        for (DFG::SwitchCase myCase : data-&gt;cases) {
+            StringImpl* string = myCase.value.stringImpl();
+            if (!string-&gt;is8Bit()) {
+                canDoBinarySwitch = false;
+                break;
+            }
+            if (string-&gt;length() &gt; Options::maximumBinaryStringSwitchCaseLength()) {
+                canDoBinarySwitch = false;
+                break;
+            }
+            totalLength += string-&gt;length();
+        }
+        
+        if (!canDoBinarySwitch || totalLength &gt; Options::maximumBinaryStringSwitchTotalLength()) {
+            switchStringSlow(data, string);
+            return;
+        }
+        
+        LValue stringImpl = m_out.loadPtr(string, m_heaps.JSString_value);
+        LValue length = m_out.load32(string, m_heaps.JSString_length);
+        
+        LBasicBlock hasImplBlock = FTL_NEW_BLOCK(m_out, (&quot;Switch/SwitchString has impl case&quot;));
+        LBasicBlock is8BitBlock = FTL_NEW_BLOCK(m_out, (&quot;Switch/SwitchString is 8 bit case&quot;));
+        LBasicBlock slowBlock = FTL_NEW_BLOCK(m_out, (&quot;Switch/SwitchString slow case&quot;));
+        
+        m_out.branch(m_out.isNull(stringImpl), unsure(slowBlock), unsure(hasImplBlock));
+        
+        LBasicBlock lastNext = m_out.appendTo(hasImplBlock, is8BitBlock);
+        
+        m_out.branch(
+            m_out.testIsZero32(
+                m_out.load32(stringImpl, m_heaps.StringImpl_hashAndFlags),
+                m_out.constInt32(StringImpl::flagIs8Bit())),
+            unsure(slowBlock), unsure(is8BitBlock));
+        
+        m_out.appendTo(is8BitBlock, slowBlock);
+        
+        LValue buffer = m_out.loadPtr(stringImpl, m_heaps.StringImpl_data);
+        
+        // FIXME: We should propagate branch weight data to the cases of this switch.
+        // https://bugs.webkit.org/show_bug.cgi?id=144368
+        
+        Vector&lt;StringSwitchCase&gt; cases;
+        for (DFG::SwitchCase myCase : data-&gt;cases)
+            cases.append(StringSwitchCase(myCase.value.stringImpl(), lowBlock(myCase.target.block)));
+        std::sort(cases.begin(), cases.end());
+        switchStringRecurse(data, buffer, length, cases, 0, 0, cases.size(), 0, false);
+
+        m_out.appendTo(slowBlock, lastNext);
+        switchStringSlow(data, string);
+    }
+    
+    // The code for string switching is based closely on the same code in the DFG backend. While it
+    // would be nice to reduce the amount of similar-looking code, it seems like this is one of
+    // those algorithms where factoring out the common bits would result in more code than just
+    // duplicating.
+    
+    struct StringSwitchCase {
+        StringSwitchCase() { }
+        
+        StringSwitchCase(StringImpl* string, LBasicBlock target)
+            : string(string)
+            , target(target)
+        {
+        }
+
+        bool operator&lt;(const StringSwitchCase&amp; other) const
+        {
+            return stringLessThan(*string, *other.string);
+        }
+        
+        StringImpl* string;
+        LBasicBlock target;
+    };
+    
+    struct CharacterCase {
+        CharacterCase()
+            : character(0)
+            , begin(0)
+            , end(0)
+        {
+        }
+        
+        CharacterCase(LChar character, unsigned begin, unsigned end)
+            : character(character)
+            , begin(begin)
+            , end(end)
+        {
+        }
+        
+        bool operator&lt;(const CharacterCase&amp; other) const
+        {
+            return character &lt; other.character;
+        }
+        
+        LChar character;
+        unsigned begin;
+        unsigned end;
+    };
+    
+    void switchStringRecurse(
+        SwitchData* data, LValue buffer, LValue length, const Vector&lt;StringSwitchCase&gt;&amp; cases,
+        unsigned numChecked, unsigned begin, unsigned end, unsigned alreadyCheckedLength,
+        unsigned checkedExactLength)
+    {
+        LBasicBlock fallThrough = lowBlock(data-&gt;fallThrough.block);
+        
+        if (begin == end) {
+            m_out.jump(fallThrough);
+            return;
+        }
+        
+        unsigned minLength = cases[begin].string-&gt;length();
+        unsigned commonChars = minLength;
+        bool allLengthsEqual = true;
+        for (unsigned i = begin + 1; i &lt; end; ++i) {
+            unsigned myCommonChars = numChecked;
+            unsigned limit = std::min(cases[begin].string-&gt;length(), cases[i].string-&gt;length());
+            for (unsigned j = numChecked; j &lt; limit; ++j) {
+                if (cases[begin].string-&gt;at(j) != cases[i].string-&gt;at(j))
+                    break;
+                myCommonChars++;
+            }
+            commonChars = std::min(commonChars, myCommonChars);
+            if (minLength != cases[i].string-&gt;length())
+                allLengthsEqual = false;
+            minLength = std::min(minLength, cases[i].string-&gt;length());
+        }
+        
+        if (checkedExactLength) {
+            DFG_ASSERT(m_graph, m_node, alreadyCheckedLength == minLength);
+            DFG_ASSERT(m_graph, m_node, allLengthsEqual);
+        }
+        
+        DFG_ASSERT(m_graph, m_node, minLength &gt;= commonChars);
+        
+        if (!allLengthsEqual &amp;&amp; alreadyCheckedLength &lt; minLength)
+            m_out.check(m_out.below(length, m_out.constInt32(minLength)), unsure(fallThrough));
+        if (allLengthsEqual &amp;&amp; (alreadyCheckedLength &lt; minLength || !checkedExactLength))
+            m_out.check(m_out.notEqual(length, m_out.constInt32(minLength)), unsure(fallThrough));
+        
+        for (unsigned i = numChecked; i &lt; commonChars; ++i) {
+            m_out.check(
+                m_out.notEqual(
+                    m_out.load8(buffer, m_heaps.characters8[i]),
+                    m_out.constInt8(cases[begin].string-&gt;at(i))),
+                unsure(fallThrough));
+        }
+        
+        if (minLength == commonChars) {
+            // This is the case where one of the cases is a prefix of all of the other cases.
+            // We've already checked that the input string is a prefix of all of the cases,
+            // so we just check length to jump to that case.
+            
+            DFG_ASSERT(m_graph, m_node, cases[begin].string-&gt;length() == commonChars);
+            for (unsigned i = begin + 1; i &lt; end; ++i)
+                DFG_ASSERT(m_graph, m_node, cases[i].string-&gt;length() &gt; commonChars);
+            
+            if (allLengthsEqual) {
+                DFG_ASSERT(m_graph, m_node, end == begin + 1);
+                m_out.jump(cases[begin].target);
+                return;
+            }
+            
+            m_out.check(
+                m_out.equal(length, m_out.constInt32(commonChars)),
+                unsure(cases[begin].target));
+            
+            // We've checked if the length is &gt;= minLength, and then we checked if the length is
+            // == commonChars. We get to this point if it is &gt;= minLength but not == commonChars.
+            // Hence we know that it now must be &gt; minLength, i.e. that it's &gt;= minLength + 1.
+            switchStringRecurse(
+                data, buffer, length, cases, commonChars, begin + 1, end, minLength + 1, false);
+            return;
+        }
+        
+        // At this point we know that the string is longer than commonChars, and we've only verified
+        // commonChars. Use a binary switch on the next unchecked character, i.e.
+        // string[commonChars].
+        
+        DFG_ASSERT(m_graph, m_node, end &gt;= begin + 2);
+        
+        LValue uncheckedChar = m_out.load8(buffer, m_heaps.characters8[commonChars]);
+        
+        Vector&lt;CharacterCase&gt; characterCases;
+        CharacterCase currentCase(cases[begin].string-&gt;at(commonChars), begin, begin + 1);
+        for (unsigned i = begin + 1; i &lt; end; ++i) {
+            LChar currentChar = cases[i].string-&gt;at(commonChars);
+            if (currentChar != currentCase.character) {
+                currentCase.end = i;
+                characterCases.append(currentCase);
+                currentCase = CharacterCase(currentChar, i, i + 1);
+            } else
+                currentCase.end = i + 1;
+        }
+        characterCases.append(currentCase);
+        
+        Vector&lt;LBasicBlock&gt; characterBlocks;
+        for (CharacterCase&amp; myCase : characterCases)
+            characterBlocks.append(FTL_NEW_BLOCK(m_out, (&quot;Switch/SwitchString case for &quot;, myCase.character, &quot; at index &quot;, commonChars)));
+        
+        Vector&lt;SwitchCase&gt; switchCases;
+        for (unsigned i = 0; i &lt; characterCases.size(); ++i) {
+            switchCases.append(SwitchCase(
+                m_out.constInt8(characterCases[i].character), characterBlocks[i], Weight()));
+        }
+        m_out.switchInstruction(uncheckedChar, switchCases, fallThrough, Weight());
+        
+        LBasicBlock lastNext = m_out.m_nextBlock;
+        characterBlocks.append(lastNext); // Makes it convenient to set nextBlock.
+        for (unsigned i = 0; i &lt; characterCases.size(); ++i) {
+            m_out.appendTo(characterBlocks[i], characterBlocks[i + 1]);
+            switchStringRecurse(
+                data, buffer, length, cases, commonChars + 1,
+                characterCases[i].begin, characterCases[i].end, minLength, allLengthsEqual);
+        }
+        
+        DFG_ASSERT(m_graph, m_node, m_out.m_nextBlock == lastNext);
+    }
+    
+    void switchStringSlow(SwitchData* data, LValue string)
+    {
+        // FIXME: We ought to be able to use computed gotos here. We would save the labels of the
+        // blocks we want to jump to, and then request their addresses after compilation completes.
+        // https://bugs.webkit.org/show_bug.cgi?id=144369
+        
+        LValue branchOffset = vmCall(
+            m_out.operation(operationSwitchStringAndGetBranchOffset),
+            m_callFrame, m_out.constIntPtr(data-&gt;switchTableIndex), string);
+        
+        StringJumpTable&amp; table = codeBlock()-&gt;stringSwitchJumpTable(data-&gt;switchTableIndex);
+        
+        Vector&lt;SwitchCase&gt; cases;
+        for (unsigned i = 0; i &lt; data-&gt;cases.size(); ++i) {
+            DFG::SwitchCase myCase = data-&gt;cases[i];
+            StringJumpTable::StringOffsetTable::iterator iter =
+                table.offsetTable.find(myCase.value.stringImpl());
+            DFG_ASSERT(m_graph, m_node, iter != table.offsetTable.end());
+            
+            cases.append(SwitchCase(
+                m_out.constInt32(iter-&gt;value.branchOffset),
+                lowBlock(myCase.target.block), Weight(myCase.target.count)));
+        }
+        
+        m_out.switchInstruction(
+            branchOffset, cases, lowBlock(data-&gt;fallThrough.block),
+            Weight(data-&gt;fallThrough.count));
+    }
+    
</ins><span class="cx">     LValue doubleToInt32(LValue doubleValue, double low, double high, bool isSigned = true)
</span><span class="cx">     {
</span><span class="cx">         LBasicBlock greatEnough = FTL_NEW_BLOCK(m_out, (&quot;doubleToInt32 greatEnough&quot;));
</span><span class="lines">@@ -7173,8 +7474,8 @@
</span><span class="cx">         
</span><span class="cx">         OSRExit&amp; exit = m_ftlState.jitCode-&gt;osrExit.last();
</span><span class="cx"> 
</span><del>-        LBasicBlock lastNext = 0;
-        LBasicBlock continuation = 0;
</del><ins>+        LBasicBlock lastNext = nullptr;
+        LBasicBlock continuation = nullptr;
</ins><span class="cx">         
</span><span class="cx">         LBasicBlock failCase = FTL_NEW_BLOCK(m_out, (&quot;OSR exit failCase for &quot;, m_node));
</span><span class="cx">         continuation = FTL_NEW_BLOCK(m_out, (&quot;OSR exit continuation for &quot;, m_node));
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLOutputcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLOutput.cpp (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLOutput.cpp        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/ftl/FTLOutput.cpp        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -138,6 +138,18 @@
</span><span class="cx">             constInt32(notTakenWeight.scaleToTotal(total))));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Output::check(LValue condition, WeightedTarget taken, Weight notTakenWeight)
+{
+    LBasicBlock continuation = FTL_NEW_BLOCK(*this, (&quot;Output::check continuation&quot;));
+    branch(condition, taken, WeightedTarget(continuation, notTakenWeight));
+    appendTo(continuation);
+}
+
+void Output::check(LValue condition, WeightedTarget taken)
+{
+    check(condition, taken, taken.weight().inverse());
+}
+
</ins><span class="cx"> } } // namespace JSC::FTL
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(FTL_JIT)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLOutputh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLOutput.h (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLOutput.h        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/ftl/FTLOutput.h        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -384,7 +384,14 @@
</span><span class="cx">     {
</span><span class="cx">         branch(condition, taken.target(), taken.weight(), notTaken.target(), notTaken.weight());
</span><span class="cx">     }
</span><ins>+
+    // Branches to an already-created handler if true, &quot;falls through&quot; if false. Fall-through is
+    // simulated by creating a continuation for you.
+    void check(LValue condition, WeightedTarget taken, Weight notTakenWeight);
</ins><span class="cx">     
</span><ins>+    // Same as check(), but uses Weight::inverse() to compute the notTakenWeight.
+    void check(LValue condition, WeightedTarget taken);
+    
</ins><span class="cx">     template&lt;typename VectorType&gt;
</span><span class="cx">     void switchInstruction(LValue value, const VectorType&amp; cases, LBasicBlock fallThrough, Weight fallThroughWeight)
</span><span class="cx">     {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLWeighth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLWeight.h (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLWeight.h        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/ftl/FTLWeight.h        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -62,6 +62,16 @@
</span><span class="cx">         return static_cast&lt;unsigned&gt;(result);
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+    // Inverse weight for a two-target branch.
+    Weight inverse() const
+    {
+        if (!isSet())
+            return Weight();
+        if (value())
+            return Weight(0);
+        return Weight(1);
+    }
+    
</ins><span class="cx"> private:
</span><span class="cx">     float m_value;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitJITOperationsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/JITOperations.h (183524 => 183525)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/JITOperations.h        2015-04-29 02:26:07 UTC (rev 183524)
+++ trunk/Source/JavaScriptCore/jit/JITOperations.h        2015-04-29 03:34:43 UTC (rev 183525)
</span><span class="lines">@@ -157,6 +157,7 @@
</span><span class="cx"> typedef int32_t JIT_OPERATION (*Z_JITOperation_D)(double);
</span><span class="cx"> typedef int32_t JIT_OPERATION (*Z_JITOperation_E)(ExecState*);
</span><span class="cx"> typedef int32_t JIT_OPERATION (*Z_JITOperation_EC)(ExecState*, JSCell*);
</span><ins>+typedef int32_t JIT_OPERATION (*Z_JITOperation_ESJss)(ExecState*, size_t, JSString*);
</ins><span class="cx"> typedef int32_t JIT_OPERATION (*Z_JITOperation_EJZ)(ExecState*, EncodedJSValue, int32_t);
</span><span class="cx"> typedef int32_t JIT_OPERATION (*Z_JITOperation_EJZZ)(ExecState*, EncodedJSValue, int32_t, int32_t);
</span><span class="cx"> typedef size_t JIT_OPERATION (*S_JITOperation_ECC)(ExecState*, JSCell*, JSCell*);
</span></span></pre>
</div>
</div>

</body>
</html>