Title: [162969] branches/jsCStack/Source/_javascript_Core
Revision
162969
Author
fpi...@apple.com
Date
2014-01-28 15:22:56 -0800 (Tue, 28 Jan 2014)

Log Message

FTL should support ArrayPush
https://bugs.webkit.org/show_bug.cgi?id=127748

Reviewed by Oliver Hunt.

* ftl/FTLAbstractHeapRepository.h:
(JSC::FTL::AbstractHeapRepository::forArrayType):
* ftl/FTLCapabilities.cpp:
(JSC::FTL::canCompile):
* ftl/FTLIntrinsicRepository.h:
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::compileNode):
(JSC::FTL::LowerDFGToLLVM::compileArrayPush):
* tests/stress/array-push-contiguous.js: Added.
(foo):
* tests/stress/array-push-double.js: Added.
(foo):

Modified Paths

Added Paths

Diff

Modified: branches/jsCStack/Source/_javascript_Core/ChangeLog (162968 => 162969)


--- branches/jsCStack/Source/_javascript_Core/ChangeLog	2014-01-28 23:12:19 UTC (rev 162968)
+++ branches/jsCStack/Source/_javascript_Core/ChangeLog	2014-01-28 23:22:56 UTC (rev 162969)
@@ -1,3 +1,23 @@
+2014-01-27  Filip Pizlo  <fpi...@apple.com>
+
+        FTL should support ArrayPush
+        https://bugs.webkit.org/show_bug.cgi?id=127748
+
+        Reviewed by Oliver Hunt.
+
+        * ftl/FTLAbstractHeapRepository.h:
+        (JSC::FTL::AbstractHeapRepository::forArrayType):
+        * ftl/FTLCapabilities.cpp:
+        (JSC::FTL::canCompile):
+        * ftl/FTLIntrinsicRepository.h:
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::LowerDFGToLLVM::compileNode):
+        (JSC::FTL::LowerDFGToLLVM::compileArrayPush):
+        * tests/stress/array-push-contiguous.js: Added.
+        (foo):
+        * tests/stress/array-push-double.js: Added.
+        (foo):
+
 2014-01-28  Filip Pizlo  <fpi...@apple.com>
 
         Arity fixup clobbers callee-saves, causing FTL->FTL arity fixed-up calls to corrupt state

Modified: branches/jsCStack/Source/_javascript_Core/ftl/FTLAbstractHeapRepository.h (162968 => 162969)


--- branches/jsCStack/Source/_javascript_Core/ftl/FTLAbstractHeapRepository.h	2014-01-28 23:12:19 UTC (rev 162968)
+++ branches/jsCStack/Source/_javascript_Core/ftl/FTLAbstractHeapRepository.h	2014-01-28 23:22:56 UTC (rev 162969)
@@ -30,6 +30,7 @@
 
 #if ENABLE(FTL_JIT)
 
+#include "DFGArrayMode.h"
 #include "FTLAbstractHeap.h"
 #include "IndexingType.h"
 
@@ -136,6 +137,24 @@
             return 0;
         }
     }
+    
+    IndexedAbstractHeap& forArrayType(DFG::Array::Type type)
+    {
+        switch (type) {
+        case DFG::Array::Int32:
+            return indexedInt32Properties;
+        case DFG::Array::Double:
+            return indexedDoubleProperties;
+        case DFG::Array::Contiguous:
+            return indexedContiguousProperties;
+        case DFG::Array::ArrayStorage:
+        case DFG::Array::SlowPutArrayStorage:
+            return indexedArrayStorageProperties;
+        default:
+            RELEASE_ASSERT_NOT_REACHED();
+            return indexedInt32Properties;
+        }
+    }
 
 private:
     friend class AbstractHeap;

Modified: branches/jsCStack/Source/_javascript_Core/ftl/FTLCapabilities.cpp (162968 => 162969)


--- branches/jsCStack/Source/_javascript_Core/ftl/FTLCapabilities.cpp	2014-01-28 23:12:19 UTC (rev 162968)
+++ branches/jsCStack/Source/_javascript_Core/ftl/FTLCapabilities.cpp	2014-01-28 23:22:56 UTC (rev 162969)
@@ -201,6 +201,16 @@
             return CannotCompile;
         }
         break;
+    case ArrayPush:
+        switch (node->arrayMode().type()) {
+        case Array::Int32:
+        case Array::Contiguous:
+        case Array::Double:
+            break;
+        default:
+            return CannotCompile;
+        }
+        break;
     case CompareEq:
         if (node->isBinaryUseKind(Int32Use))
             break;

Modified: branches/jsCStack/Source/_javascript_Core/ftl/FTLIntrinsicRepository.h (162968 => 162969)


--- branches/jsCStack/Source/_javascript_Core/ftl/FTLIntrinsicRepository.h	2014-01-28 23:12:19 UTC (rev 162968)
+++ branches/jsCStack/Source/_javascript_Core/ftl/FTLIntrinsicRepository.h	2014-01-28 23:22:56 UTC (rev 162969)
@@ -63,6 +63,8 @@
     macro(I_JITOperation_EJss, functionType(intPtr, intPtr, intPtr)) \
     macro(J_JITOperation_E, functionType(int64, intPtr)) \
     macro(J_JITOperation_EAZ, functionType(int64, intPtr, intPtr, int32)) \
+    macro(J_JITOperation_EDA, functionType(int64, intPtr, doubleType, intPtr)) \
+    macro(J_JITOperation_EJA, functionType(int64, intPtr, int64, intPtr)) \
     macro(J_JITOperation_EJJ, functionType(int64, intPtr, int64, int64)) \
     macro(J_JITOperation_EJssZ, functionType(int64, intPtr, intPtr, int32)) \
     macro(J_JITOperation_ESsiJI, functionType(int64, intPtr, intPtr, int64, intPtr)) \

Modified: branches/jsCStack/Source/_javascript_Core/ftl/FTLLowerDFGToLLVM.cpp (162968 => 162969)


--- branches/jsCStack/Source/_javascript_Core/ftl/FTLLowerDFGToLLVM.cpp	2014-01-28 23:12:19 UTC (rev 162968)
+++ branches/jsCStack/Source/_javascript_Core/ftl/FTLLowerDFGToLLVM.cpp	2014-01-28 23:22:56 UTC (rev 162969)
@@ -416,6 +416,9 @@
         case PutByValDirect:
             compilePutByVal();
             break;
+        case ArrayPush:
+            compileArrayPush();
+            break;
         case NewObject:
             compileNewObject();
             break;
@@ -2181,6 +2184,102 @@
         }
     }
     
+    void compileArrayPush()
+    {
+        LValue base = lowCell(m_node->child1());
+        LValue storage = lowStorage(m_node->child3());
+        
+        switch (m_node->arrayMode().type()) {
+        case Array::Int32:
+        case Array::Contiguous:
+        case Array::Double: {
+            if (true) {
+                LValue value;
+                if (m_node->arrayMode().type() != Array::Double) {
+                    value = lowJSValue(m_node->child2(), ManualOperandSpeculation);
+                    if (m_node->arrayMode().type() == Array::Int32) {
+                        FTL_TYPE_CHECK(
+                            jsValueValue(value), m_node->child2(), SpecInt32, isNotInt32(value));
+                    }
+                } else {
+                    value = lowDouble(m_node->child2());
+                    FTL_TYPE_CHECK(
+                        doubleValue(value), m_node->child2(), SpecFullRealNumber,
+                        m_out.doubleNotEqualOrUnordered(value, value));
+                }
+                
+                LValue operation;
+                if (m_node->arrayMode().type() != Array::Double)
+                    operation = m_out.operation(operationArrayPush);
+                else
+                    operation = m_out.operation(operationArrayPushDouble);
+                setJSValue(vmCall(operation, m_callFrame, value, base));
+                return;
+            }
+            
+            LValue value;
+            LType refType;
+            
+            if (m_node->arrayMode().type() != Array::Double) {
+                value = lowJSValue(m_node->child2(), ManualOperandSpeculation);
+                if (m_node->arrayMode().type() == Array::Int32) {
+                    FTL_TYPE_CHECK(
+                        jsValueValue(value), m_node->child2(), SpecInt32, isNotInt32(value));
+                }
+                refType = m_out.ref64;
+            } else {
+                value = lowDouble(m_node->child2());
+                FTL_TYPE_CHECK(
+                    doubleValue(value), m_node->child2(), SpecFullRealNumber,
+                    m_out.doubleNotEqualOrUnordered(value, value));
+                refType = m_out.refDouble;
+            }
+            
+            IndexedAbstractHeap& heap = m_heaps.forArrayType(m_node->arrayMode().type());
+
+            LValue prevLength = m_out.load32(storage, m_heaps.Butterfly_publicLength);
+            
+            LBasicBlock fastPath = FTL_NEW_BLOCK(m_out, ("ArrayPush int32/contiguous fast path"));
+            LBasicBlock slowPath = FTL_NEW_BLOCK(m_out, ("ArrayPush int32/contiguous slow path"));
+            LBasicBlock continuation = FTL_NEW_BLOCK(m_out, ("ArrayPush int32/contiguous continuation"));
+            
+            m_out.branch(
+                m_out.aboveOrEqual(
+                    prevLength, m_out.load32(storage, m_heaps.Butterfly_vectorLength)),
+                slowPath, fastPath);
+            
+            LBasicBlock lastNext = m_out.appendTo(fastPath, slowPath);
+            m_out.store(
+                value,
+                m_out.baseIndex(heap, storage, m_out.zeroExt(prevLength, m_out.intPtr)),
+                refType);
+            LValue newLength = m_out.add(prevLength, m_out.int32One);
+            m_out.store32(newLength, storage, m_heaps.Butterfly_publicLength);
+            
+            ValueFromBlock fastResult = m_out.anchor(boxInt32(newLength));
+            m_out.jump(continuation);
+            
+            m_out.appendTo(slowPath, continuation);
+            LValue operation;
+            if (m_node->arrayMode().type() != Array::Double)
+                operation = m_out.operation(operationArrayPush);
+            else
+                operation = m_out.operation(operationArrayPushDouble);
+            ValueFromBlock slowResult = m_out.anchor(
+                vmCall(operation, m_callFrame, value, base));
+            m_out.jump(continuation);
+            
+            m_out.appendTo(continuation, lastNext);
+            setJSValue(m_out.phi(m_out.int64, fastResult, slowResult));
+            return;
+        }
+            
+        default:
+            RELEASE_ASSERT_NOT_REACHED();
+            return;
+        }
+    }
+    
     void compileNewObject()
     {
         Structure* structure = m_node->structure();

Added: branches/jsCStack/Source/_javascript_Core/tests/stress/array-push-contiguous.js (0 => 162969)


--- branches/jsCStack/Source/_javascript_Core/tests/stress/array-push-contiguous.js	                        (rev 0)
+++ branches/jsCStack/Source/_javascript_Core/tests/stress/array-push-contiguous.js	2014-01-28 23:22:56 UTC (rev 162969)
@@ -0,0 +1,18 @@
+function foo() {
+    var array = [];
+    var result = [];
+    for (var i = 0; i < 42; ++i)
+        result.push(array.push("hello"));
+    return [array, result];
+}
+
+noInline(foo);
+
+for (var i = 0; i < 100000; ++i) {
+    var result = foo();
+    if (result[0].toString() != "hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello,hello")
+        throw "Error: bad array: " + result[0];
+    if (result[1].toString() != "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42")
+        throw "Error: bad array: " + result[1];
+}
+

Added: branches/jsCStack/Source/_javascript_Core/tests/stress/array-push-double-then-nan.js (0 => 162969)


--- branches/jsCStack/Source/_javascript_Core/tests/stress/array-push-double-then-nan.js	                        (rev 0)
+++ branches/jsCStack/Source/_javascript_Core/tests/stress/array-push-double-then-nan.js	2014-01-28 23:22:56 UTC (rev 162969)
@@ -0,0 +1,23 @@
+function foo(x) {
+    var array = [];
+    var result = [];
+    for (var i = 0; i < 42; ++i)
+        result.push(array.push(x));
+    return [array, result];
+}
+
+noInline(foo);
+
+for (var i = 0; i < 100000; ++i) {
+    var result = foo(5.5);
+    if (result[0].toString() != "5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5")
+        throw "Error: bad array: " + result[0];
+    if (result[1].toString() != "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42")
+        throw "Error: bad array: " + result[1];
+}
+
+var result = foo(0/0);
+if (result[0].toString() != "NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN")
+    throw "Error: bad array: " + result[0];
+if (result[1].toString() != "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42")
+    throw "Error: bad array: " + result[1];

Added: branches/jsCStack/Source/_javascript_Core/tests/stress/array-push-double.js (0 => 162969)


--- branches/jsCStack/Source/_javascript_Core/tests/stress/array-push-double.js	                        (rev 0)
+++ branches/jsCStack/Source/_javascript_Core/tests/stress/array-push-double.js	2014-01-28 23:22:56 UTC (rev 162969)
@@ -0,0 +1,18 @@
+function foo() {
+    var array = [];
+    var result = [];
+    for (var i = 0; i < 42; ++i)
+        result.push(array.push(7.5 - i));
+    return [array, result];
+}
+
+noInline(foo);
+
+for (var i = 0; i < 100000; ++i) {
+    var result = foo();
+    if (result[0].toString() != "7.5,6.5,5.5,4.5,3.5,2.5,1.5,0.5,-0.5,-1.5,-2.5,-3.5,-4.5,-5.5,-6.5,-7.5,-8.5,-9.5,-10.5,-11.5,-12.5,-13.5,-14.5,-15.5,-16.5,-17.5,-18.5,-19.5,-20.5,-21.5,-22.5,-23.5,-24.5,-25.5,-26.5,-27.5,-28.5,-29.5,-30.5,-31.5,-32.5,-33.5")
+        throw "Error: bad array: " + result[0];
+    if (result[1].toString() != "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42")
+        throw "Error: bad array: " + result[1];
+}
+
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to