Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/x64/full-codegen-x64.cc

Issue 1125183008: [es6] Spread in array literals (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cleanup Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/typing.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #if V8_TARGET_ARCH_X64 7 #if V8_TARGET_ARCH_X64
8 8
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 __ CallStub(&stub); 1840 __ CallStub(&stub);
1841 } 1841 }
1842 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); 1842 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
1843 1843
1844 bool result_saved = false; // Is the result saved to the stack? 1844 bool result_saved = false; // Is the result saved to the stack?
1845 ZoneList<Expression*>* subexprs = expr->values(); 1845 ZoneList<Expression*>* subexprs = expr->values();
1846 int length = subexprs->length(); 1846 int length = subexprs->length();
1847 1847
1848 // Emit code to evaluate all the non-constant subexpressions and to store 1848 // Emit code to evaluate all the non-constant subexpressions and to store
1849 // them into the newly cloned array. 1849 // them into the newly cloned array.
1850 for (int i = 0; i < length; i++) { 1850 int array_index = 0;
1851 Expression* subexpr = subexprs->at(i); 1851 for (; array_index < length; array_index++) {
1852 Expression* subexpr = subexprs->at(array_index);
1853 if (subexpr->IsSpread()) break;
1854
1852 // If the subexpression is a literal or a simple materialized literal it 1855 // If the subexpression is a literal or a simple materialized literal it
1853 // is already set in the cloned array. 1856 // is already set in the cloned array.
1854 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; 1857 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
1855 1858
1856 if (!result_saved) { 1859 if (!result_saved) {
1857 __ Push(rax); // array literal 1860 __ Push(rax); // array literal
1858 __ Push(Smi::FromInt(expr->literal_index())); 1861 __ Push(Smi::FromInt(expr->literal_index()));
1859 result_saved = true; 1862 result_saved = true;
1860 } 1863 }
1861 VisitForAccumulatorValue(subexpr); 1864 VisitForAccumulatorValue(subexpr);
1862 1865
1863 if (has_constant_fast_elements) { 1866 if (has_constant_fast_elements) {
1864 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they 1867 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they
1865 // cannot transition and don't need to call the runtime stub. 1868 // cannot transition and don't need to call the runtime stub.
1866 int offset = FixedArray::kHeaderSize + (i * kPointerSize); 1869 int offset = FixedArray::kHeaderSize + (array_index * kPointerSize);
1867 __ movp(rbx, Operand(rsp, kPointerSize)); // Copy of array literal. 1870 __ movp(rbx, Operand(rsp, kPointerSize)); // Copy of array literal.
1868 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset)); 1871 __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
1869 // Store the subexpression value in the array's elements. 1872 // Store the subexpression value in the array's elements.
1870 __ movp(FieldOperand(rbx, offset), result_register()); 1873 __ movp(FieldOperand(rbx, offset), result_register());
1871 // Update the write barrier for the array store. 1874 // Update the write barrier for the array store.
1872 __ RecordWriteField(rbx, offset, result_register(), rcx, 1875 __ RecordWriteField(rbx, offset, result_register(), rcx,
1873 kDontSaveFPRegs, 1876 kDontSaveFPRegs,
1874 EMIT_REMEMBERED_SET, 1877 EMIT_REMEMBERED_SET,
1875 INLINE_SMI_CHECK); 1878 INLINE_SMI_CHECK);
1876 } else { 1879 } else {
1877 // Store the subexpression value in the array's elements. 1880 // Store the subexpression value in the array's elements.
1878 __ Move(rcx, Smi::FromInt(i)); 1881 __ Move(rcx, Smi::FromInt(array_index));
1879 StoreArrayLiteralElementStub stub(isolate()); 1882 StoreArrayLiteralElementStub stub(isolate());
1880 __ CallStub(&stub); 1883 __ CallStub(&stub);
1881 } 1884 }
1882 1885
1883 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); 1886 PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS);
1887 }
1888
1889 // In case the array literal contains spread expressions it has two parts. The
1890 // first part is the "static" array which has a literal index is handled
1891 // above. The second part is the part after the first spread expression
1892 // (inclusive) and these elements gets appended to the array. Note that the
1893 // number elements an iterable produces is unknown ahead of time.
1894 if (array_index < length && result_saved) {
1895 __ Drop(1); // literal index
1896 __ Pop(rax);
1897 result_saved = false;
1898 }
1899 for (; array_index < length; array_index++) {
1900 Expression* subexpr = subexprs->at(array_index);
1901
1902 __ Push(rax);
1903 if (subexpr->IsSpread()) {
1904 VisitForStackValue(subexpr->AsSpread()->expression());
1905 __ InvokeBuiltin(Builtins::CONCAT_ITERABLE_TO_ARRAY, CALL_FUNCTION);
1906 } else {
1907 VisitForStackValue(subexpr);
1908 __ CallRuntime(Runtime::kAppendElement, 2);
1909 }
1910
1911 PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS);
1884 } 1912 }
1885 1913
1886 if (result_saved) { 1914 if (result_saved) {
1887 __ addp(rsp, Immediate(kPointerSize)); // literal index 1915 __ Drop(1); // literal index
1888 context()->PlugTOS(); 1916 context()->PlugTOS();
1889 } else { 1917 } else {
1890 context()->Plug(rax); 1918 context()->Plug(rax);
1891 } 1919 }
1892 } 1920 }
1893 1921
1894 1922
1895 void FullCodeGenerator::VisitAssignment(Assignment* expr) { 1923 void FullCodeGenerator::VisitAssignment(Assignment* expr) {
1896 DCHECK(expr->target()->IsValidReferenceExpression()); 1924 DCHECK(expr->target()->IsValidReferenceExpression());
1897 1925
(...skipping 3469 matching lines...) Expand 10 before | Expand all | Expand 10 after
5367 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 5395 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
5368 Assembler::target_address_at(call_target_address, 5396 Assembler::target_address_at(call_target_address,
5369 unoptimized_code)); 5397 unoptimized_code));
5370 return OSR_AFTER_STACK_CHECK; 5398 return OSR_AFTER_STACK_CHECK;
5371 } 5399 }
5372 5400
5373 5401
5374 } } // namespace v8::internal 5402 } } // namespace v8::internal
5375 5403
5376 #endif // V8_TARGET_ARCH_X64 5404 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/typing.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698