<!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>[149941] branches/dfgFourthTier/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/149941">149941</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2013-05-11 14:07:51 -0700 (Sat, 11 May 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>fourthTier: FTL should support Jump and ForceOSRExit
https://bugs.webkit.org/show_bug.cgi?id=115942

Reviewed by Oliver Hunt.
        
Added two obvious nodes: Jump and ForceOSRExit. We already had everything we needed
to support them.
        
Adding these increases our coverage a fair bit, and revealed a bug: LLVM's full
instruction selector currently appears to mishandle doubles in constant pools (or
just constant pools in general) with the small code model in the MCJIT. But switching
to FastISel &quot;fixes&quot; it. That's what this patch does, for now. This will probably
actually be permanent; the FastISel does pretty much everything we would ever want,
at least in the foreseeable future.

* ftl/FTLCapabilities.cpp:
(JSC::FTL::canCompile):
(FTL):
* ftl/FTLCompile.cpp:
(JSC::FTL::compile):
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::compileBlock):
(JSC::FTL::LowerDFGToLLVM::compileNode):
(JSC::FTL::LowerDFGToLLVM::compileJSConstant):
(LowerDFGToLLVM):
(JSC::FTL::LowerDFGToLLVM::compileJump):
(JSC::FTL::LowerDFGToLLVM::compileReturn):
(JSC::FTL::LowerDFGToLLVM::compileForceOSRExit):
* runtime/Options.h:
(JSC):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesdfgFourthTierSourceJavaScriptCoreChangeLog">branches/dfgFourthTier/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchesdfgFourthTierSourceJavaScriptCoreftlFTLCapabilitiescpp">branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLCapabilities.cpp</a></li>
<li><a href="#branchesdfgFourthTierSourceJavaScriptCoreftlFTLCompilecpp">branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLCompile.cpp</a></li>
<li><a href="#branchesdfgFourthTierSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp">branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp</a></li>
<li><a href="#branchesdfgFourthTierSourceJavaScriptCoreruntimeOptionsh">branches/dfgFourthTier/Source/JavaScriptCore/runtime/Options.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesdfgFourthTierSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/dfgFourthTier/Source/JavaScriptCore/ChangeLog (149940 => 149941)</h4>
<pre class="diff"><span>
<span class="info">--- branches/dfgFourthTier/Source/JavaScriptCore/ChangeLog        2013-05-11 20:57:29 UTC (rev 149940)
+++ branches/dfgFourthTier/Source/JavaScriptCore/ChangeLog        2013-05-11 21:07:51 UTC (rev 149941)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2013-05-11  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        fourthTier: FTL should support Jump and ForceOSRExit
+        https://bugs.webkit.org/show_bug.cgi?id=115942
+
+        Reviewed by Oliver Hunt.
+        
+        Added two obvious nodes: Jump and ForceOSRExit. We already had everything we needed
+        to support them.
+        
+        Adding these increases our coverage a fair bit, and revealed a bug: LLVM's full
+        instruction selector currently appears to mishandle doubles in constant pools (or
+        just constant pools in general) with the small code model in the MCJIT. But switching
+        to FastISel &quot;fixes&quot; it. That's what this patch does, for now. This will probably
+        actually be permanent; the FastISel does pretty much everything we would ever want,
+        at least in the foreseeable future.
+
+        * ftl/FTLCapabilities.cpp:
+        (JSC::FTL::canCompile):
+        (FTL):
+        * ftl/FTLCompile.cpp:
+        (JSC::FTL::compile):
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::LowerDFGToLLVM::compileBlock):
+        (JSC::FTL::LowerDFGToLLVM::compileNode):
+        (JSC::FTL::LowerDFGToLLVM::compileJSConstant):
+        (LowerDFGToLLVM):
+        (JSC::FTL::LowerDFGToLLVM::compileJump):
+        (JSC::FTL::LowerDFGToLLVM::compileReturn):
+        (JSC::FTL::LowerDFGToLLVM::compileForceOSRExit):
+        * runtime/Options.h:
+        (JSC):
+
</ins><span class="cx"> 2013-05-10  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         fourthTier: FTL should support CompareStrictEqConstant
</span></span></pre></div>
<a id="branchesdfgFourthTierSourceJavaScriptCoreftlFTLCapabilitiescpp"></a>
<div class="modfile"><h4>Modified: branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLCapabilities.cpp (149940 => 149941)</h4>
<pre class="diff"><span>
<span class="info">--- branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLCapabilities.cpp        2013-05-11 20:57:29 UTC (rev 149940)
+++ branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLCapabilities.cpp        2013-05-11 21:07:51 UTC (rev 149941)
</span><span class="lines">@@ -32,6 +32,108 @@
</span><span class="cx"> 
</span><span class="cx"> using namespace DFG;
</span><span class="cx"> 
</span><ins>+inline bool canCompile(Node* node)
+{
+    switch (node-&gt;op()) {
+    case JSConstant:
+    case WeakJSConstant:
+    case GetLocal:
+    case SetLocal:
+    case MovHintAndCheck:
+    case MovHint:
+    case ZombieHint:
+    case Phantom:
+    case Flush:
+    case PhantomLocal:
+    case SetArgument:
+    case Return:
+    case BitAnd:
+    case BitOr:
+    case BitXor:
+    case BitRShift:
+    case BitLShift:
+    case BitURShift:
+    case CheckStructure:
+    case StructureTransitionWatchpoint:
+    case PutStructure:
+    case PhantomPutStructure:
+    case GetButterfly:
+    case GetByOffset:
+    case PutByOffset:
+    case GetGlobalVar:
+    case PutGlobalVar:
+    case ValueAdd:
+    case ArithAdd:
+    case ArithSub:
+    case ArithMul:
+    case ArithNegate:
+    case UInt32ToNumber:
+    case Int32ToDouble:
+    case CompareEqConstant:
+    case CompareStrictEqConstant:
+    case Jump:
+    case ForceOSRExit:
+        // These are OK.
+        break;
+    case GetArrayLength:
+        switch (node-&gt;arrayMode().type()) {
+        case Array::Int32:
+        case Array::Double:
+        case Array::Contiguous:
+            break;
+        default:
+            return false;
+        }
+        break;
+    case GetByVal:
+        switch (node-&gt;arrayMode().type()) {
+        case Array::ForceExit:
+            return true;
+        case Array::Int32:
+        case Array::Double:
+        case Array::Contiguous:
+            break;
+        default:
+            return false;
+        }
+        switch (node-&gt;arrayMode().speculation()) {
+        case Array::SaneChain:
+        case Array::InBounds:
+            break;
+        default:
+            return false;
+        }
+        break;
+    case CompareEq:
+    case CompareStrictEq:
+        if (node-&gt;isBinaryUseKind(Int32Use))
+            break;
+        if (node-&gt;isBinaryUseKind(NumberUse))
+            break;
+        if (node-&gt;isBinaryUseKind(ObjectUse))
+            break;
+        return false;
+    case CompareLess:
+    case CompareLessEq:
+    case CompareGreater:
+    case CompareGreaterEq:
+        if (node-&gt;isBinaryUseKind(Int32Use))
+            break;
+        if (node-&gt;isBinaryUseKind(NumberUse))
+            break;
+        return false;
+    case Branch:
+    case LogicalNot:
+        if (node-&gt;child1().useKind() == BooleanUse)
+            break;
+        return false;
+    default:
+        // Don't know how to handle anything else.
+        return false;
+    }
+    return true;
+}
+
</ins><span class="cx"> bool canCompile(Graph&amp; graph)
</span><span class="cx"> {
</span><span class="cx">     for (BlockIndex blockIndex = graph.m_blocks.size(); blockIndex--;) {
</span><span class="lines">@@ -65,99 +167,8 @@
</span><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx">             
</span><del>-            switch (node-&gt;op()) {
-            case JSConstant:
-            case WeakJSConstant:
-            case GetLocal:
-            case SetLocal:
-            case MovHintAndCheck:
-            case MovHint:
-            case ZombieHint:
-            case Phantom:
-            case Flush:
-            case PhantomLocal:
-            case SetArgument:
-            case Return:
-            case BitAnd:
-            case BitOr:
-            case BitXor:
-            case BitRShift:
-            case BitLShift:
-            case BitURShift:
-            case CheckStructure:
-            case StructureTransitionWatchpoint:
-            case PutStructure:
-            case PhantomPutStructure:
-            case GetButterfly:
-            case GetByOffset:
-            case PutByOffset:
-            case GetGlobalVar:
-            case PutGlobalVar:
-            case ValueAdd:
-            case ArithAdd:
-            case ArithSub:
-            case ArithMul:
-            case ArithNegate:
-            case UInt32ToNumber:
-            case Int32ToDouble:
-            case CompareEqConstant:
-            case CompareStrictEqConstant:
-                // These are OK.
-                break;
-            case GetArrayLength:
-                switch (node-&gt;arrayMode().type()) {
-                case Array::Int32:
-                case Array::Double:
-                case Array::Contiguous:
-                    break;
-                default:
-                    return false;
-                }
-                break;
-            case GetByVal:
-                switch (node-&gt;arrayMode().type()) {
-                case Array::Int32:
-                case Array::Double:
-                case Array::Contiguous:
-                    break;
-                default:
-                    return false;
-                }
-                switch (node-&gt;arrayMode().speculation()) {
-                case Array::SaneChain:
-                case Array::InBounds:
-                    break;
-                default:
-                    return false;
-                }
-                break;
-            case CompareEq:
-            case CompareStrictEq:
-                if (node-&gt;isBinaryUseKind(Int32Use))
-                    break;
-                if (node-&gt;isBinaryUseKind(NumberUse))
-                    break;
-                if (node-&gt;isBinaryUseKind(ObjectUse))
-                    break;
</del><ins>+            if (!canCompile(node))
</ins><span class="cx">                 return false;
</span><del>-            case CompareLess:
-            case CompareLessEq:
-            case CompareGreater:
-            case CompareGreaterEq:
-                if (node-&gt;isBinaryUseKind(Int32Use))
-                    break;
-                if (node-&gt;isBinaryUseKind(NumberUse))
-                    break;
-                return false;
-            case Branch:
-            case LogicalNot:
-                if (node-&gt;child1().useKind() == BooleanUse)
-                    break;
-                return false;
-            default:
-                // Don't know how to handle anything else.
-                return false;
-            }
</del><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     
</span></span></pre></div>
<a id="branchesdfgFourthTierSourceJavaScriptCoreftlFTLCompilecpp"></a>
<div class="modfile"><h4>Modified: branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLCompile.cpp (149940 => 149941)</h4>
<pre class="diff"><span>
<span class="info">--- branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLCompile.cpp        2013-05-11 20:57:29 UTC (rev 149940)
+++ branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLCompile.cpp        2013-05-11 21:07:51 UTC (rev 149941)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx">     options.OptLevel = Options::llvmOptimizationLevel();
</span><span class="cx">     options.NoFramePointerElim = true;
</span><span class="cx">     options.CodeModel = LLVMCodeModelSmall;
</span><ins>+    options.EnableFastISel = Options::enableLLVMFastISel();
</ins><span class="cx">     
</span><span class="cx">     if (LLVMCreateMCJITCompilerForModule(&amp;state.engine, state.module, &amp;options, sizeof(options), &amp;error)) {
</span><span class="cx">         dataLog(&quot;FATAL: Could not create LLVM execution engine: &quot;, error, &quot;\n&quot;);
</span></span></pre></div>
<a id="branchesdfgFourthTierSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp"></a>
<div class="modfile"><h4>Modified: branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp (149940 => 149941)</h4>
<pre class="diff"><span>
<span class="info">--- branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2013-05-11 20:57:29 UTC (rev 149940)
+++ branches/dfgFourthTier/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2013-05-11 21:07:51 UTC (rev 149941)
</span><span class="lines">@@ -243,12 +243,19 @@
</span><span class="cx">         m_state.reset();
</span><span class="cx">         m_state.beginBasicBlock(m_highBlock);
</span><span class="cx">         
</span><del>-        for (m_nodeIndex = 0; m_nodeIndex &lt; m_highBlock-&gt;size(); ++m_nodeIndex)
-            compileNode(m_nodeIndex);
</del><ins>+        for (m_nodeIndex = 0; m_nodeIndex &lt; m_highBlock-&gt;size(); ++m_nodeIndex) {
+            if (!compileNode(m_nodeIndex))
+                break;
+        }
</ins><span class="cx">     }
</span><span class="cx">     
</span><del>-    void compileNode(unsigned nodeIndex)
</del><ins>+    bool compileNode(unsigned nodeIndex)
</ins><span class="cx">     {
</span><ins>+        if (!m_state.isValid()) {
+            m_out.unreachable();
+            return false;
+        }
+        
</ins><span class="cx">         m_node = m_highBlock-&gt;at(nodeIndex);
</span><span class="cx">         m_codeOrigin = m_node-&gt;codeOrigin;
</span><span class="cx">         
</span><span class="lines">@@ -288,9 +295,6 @@
</span><span class="cx">         case PhantomLocal:
</span><span class="cx">         case SetArgument:
</span><span class="cx">             break;
</span><del>-        case Return:
-            compileReturn();
-            break;
</del><span class="cx">         case ArithAdd:
</span><span class="cx">         case ValueAdd:
</span><span class="cx">             compileAdd();
</span><span class="lines">@@ -388,9 +392,18 @@
</span><span class="cx">         case LogicalNot:
</span><span class="cx">             compileLogicalNot();
</span><span class="cx">             break;
</span><ins>+        case Jump:
+            compileJump();
+            break;
</ins><span class="cx">         case Branch:
</span><span class="cx">             compileBranch();
</span><span class="cx">             break;
</span><ins>+        case Return:
+            compileReturn();
+            break;
+        case ForceOSRExit:
+            compileForceOSRExit();
+            break;
</ins><span class="cx">         default:
</span><span class="cx">             RELEASE_ASSERT_NOT_REACHED();
</span><span class="cx">             break;
</span><span class="lines">@@ -404,11 +417,17 @@
</span><span class="cx">         
</span><span class="cx">         if (shouldExecuteEffects)
</span><span class="cx">             m_state.executeEffects(nodeIndex);
</span><ins>+        
+        return true;
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     void compileJSConstant()
</span><span class="cx">     {
</span><del>-        m_jsValueValues.add(m_node, m_out.constInt64(JSValue::encode(m_graph.valueOfJSConstant(m_node))));
</del><ins>+        JSValue value = m_graph.valueOfJSConstant(m_node);
+        if (value.isDouble())
+            m_doubleValues.add(m_node, m_out.constDouble(value.asDouble()));
+        else
+            m_jsValueValues.add(m_node, m_out.constInt64(JSValue::encode(value)));
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     void compileWeakJSConstant()
</span><span class="lines">@@ -555,13 +574,6 @@
</span><span class="cx">         DFG_NODE_DO_TO_CHILDREN(m_graph, m_node, speculate);
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    void compileReturn()
-    {
-        // FIXME: have a real epilogue when we switch to using our calling convention.
-        // https://bugs.webkit.org/show_bug.cgi?id=113621
-        m_out.ret(lowJSValue(m_node-&gt;child1()));
-    }
-    
</del><span class="cx">     void compileAdd()
</span><span class="cx">     {
</span><span class="cx">         switch (m_node-&gt;binaryUseKind()) {
</span><span class="lines">@@ -1123,6 +1135,11 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+    void compileJump()
+    {
+        m_out.jump(m_blocks.get(m_graph.m_blocks[m_node-&gt;takenBlockIndex()].get()));
+    }
+    
</ins><span class="cx">     void compileBranch()
</span><span class="cx">     {
</span><span class="cx">         switch (m_node-&gt;child1().useKind()) {
</span><span class="lines">@@ -1140,6 +1157,18 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+    void compileReturn()
+    {
+        // FIXME: have a real epilogue when we switch to using our calling convention.
+        // https://bugs.webkit.org/show_bug.cgi?id=113621
+        m_out.ret(lowJSValue(m_node-&gt;child1()));
+    }
+    
+    void compileForceOSRExit()
+    {
+        terminate(InadequateCoverage);
+    }
+    
</ins><span class="cx">     enum EqualNullOrUndefinedMode { EqualNull, EqualUndefined, EqualNullOrUndefined };
</span><span class="cx">     void equalNullOrUndefined(Edge edge, EqualNullOrUndefinedMode mode)
</span><span class="cx">     {
</span></span></pre></div>
<a id="branchesdfgFourthTierSourceJavaScriptCoreruntimeOptionsh"></a>
<div class="modfile"><h4>Modified: branches/dfgFourthTier/Source/JavaScriptCore/runtime/Options.h (149940 => 149941)</h4>
<pre class="diff"><span>
<span class="info">--- branches/dfgFourthTier/Source/JavaScriptCore/runtime/Options.h        2013-05-11 20:57:29 UTC (rev 149940)
+++ branches/dfgFourthTier/Source/JavaScriptCore/runtime/Options.h        2013-05-11 21:07:51 UTC (rev 149941)
</span><span class="lines">@@ -85,6 +85,7 @@
</span><span class="cx">     v(bool, useExperimentalFTL, false) \
</span><span class="cx">     v(bool, useFTLTBAA, true) \
</span><span class="cx">     v(bool, enableLLVMLICM, true) \
</span><ins>+    v(bool, enableLLVMFastISel, true) \
</ins><span class="cx">     v(unsigned, llvmOptimizationLevel, 2) \
</span><span class="cx">     \
</span><span class="cx">     v(bool, enableProfiler, false) \
</span></span></pre>
</div>
</div>

</body>
</html>