OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1533 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
1534 Comment cmnt(masm_, "[ ArrayLiteral"); | 1534 Comment cmnt(masm_, "[ ArrayLiteral"); |
1535 | 1535 |
1536 ZoneList<Expression*>* subexprs = expr->values(); | 1536 ZoneList<Expression*>* subexprs = expr->values(); |
1537 int length = subexprs->length(); | 1537 int length = subexprs->length(); |
1538 | 1538 |
1539 Handle<FixedArray> constant_elements = expr->constant_elements(); | 1539 Handle<FixedArray> constant_elements = expr->constant_elements(); |
1540 ASSERT_EQ(2, constant_elements->length()); | 1540 ASSERT_EQ(2, constant_elements->length()); |
1541 ElementsKind constant_elements_kind = | 1541 ElementsKind constant_elements_kind = |
1542 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | 1542 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
| 1543 bool has_fast_elements = constant_elements_kind == FAST_ELEMENTS; |
1543 Handle<FixedArrayBase> constant_elements_values( | 1544 Handle<FixedArrayBase> constant_elements_values( |
1544 FixedArrayBase::cast(constant_elements->get(1))); | 1545 FixedArrayBase::cast(constant_elements->get(1))); |
1545 | 1546 |
1546 __ mov(a0, result_register()); | 1547 __ mov(a0, result_register()); |
1547 __ lw(a3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 1548 __ lw(a3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
1548 __ lw(a3, FieldMemOperand(a3, JSFunction::kLiteralsOffset)); | 1549 __ lw(a3, FieldMemOperand(a3, JSFunction::kLiteralsOffset)); |
1549 __ li(a2, Operand(Smi::FromInt(expr->literal_index()))); | 1550 __ li(a2, Operand(Smi::FromInt(expr->literal_index()))); |
1550 __ li(a1, Operand(constant_elements)); | 1551 __ li(a1, Operand(constant_elements)); |
1551 __ Push(a3, a2, a1); | 1552 __ Push(a3, a2, a1); |
1552 if (constant_elements_values->map() == | 1553 if (has_fast_elements && constant_elements_values->map() == |
1553 isolate()->heap()->fixed_cow_array_map()) { | 1554 isolate()->heap()->fixed_cow_array_map()) { |
1554 FastCloneShallowArrayStub stub( | 1555 FastCloneShallowArrayStub stub( |
1555 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); | 1556 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
1556 __ CallStub(&stub); | 1557 __ CallStub(&stub); |
1557 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), | 1558 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), |
1558 1, a1, a2); | 1559 1, a1, a2); |
1559 } else if (expr->depth() > 1) { | 1560 } else if (expr->depth() > 1) { |
1560 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1561 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
1561 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1562 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
1562 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); | 1563 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
1563 } else { | 1564 } else { |
1564 ASSERT(constant_elements_kind == FAST_ELEMENTS || | 1565 ASSERT(constant_elements_kind == FAST_ELEMENTS || |
1565 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || | 1566 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || |
1566 FLAG_smi_only_arrays); | 1567 FLAG_smi_only_arrays); |
1567 FastCloneShallowArrayStub::Mode mode = | 1568 FastCloneShallowArrayStub::Mode mode = has_fast_elements |
1568 constant_elements_kind == FAST_DOUBLE_ELEMENTS | 1569 ? FastCloneShallowArrayStub::CLONE_ELEMENTS |
1569 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS | 1570 : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
1570 : FastCloneShallowArrayStub::CLONE_ELEMENTS; | |
1571 FastCloneShallowArrayStub stub(mode, length); | 1571 FastCloneShallowArrayStub stub(mode, length); |
1572 __ CallStub(&stub); | 1572 __ CallStub(&stub); |
1573 } | 1573 } |
1574 | 1574 |
1575 bool result_saved = false; // Is the result saved to the stack? | 1575 bool result_saved = false; // Is the result saved to the stack? |
1576 | 1576 |
1577 // Emit code to evaluate all the non-constant subexpressions and to store | 1577 // Emit code to evaluate all the non-constant subexpressions and to store |
1578 // them into the newly cloned array. | 1578 // them into the newly cloned array. |
1579 for (int i = 0; i < length; i++) { | 1579 for (int i = 0; i < length; i++) { |
1580 Expression* subexpr = subexprs->at(i); | 1580 Expression* subexpr = subexprs->at(i); |
1581 // If the subexpression is a literal or a simple materialized literal it | 1581 // If the subexpression is a literal or a simple materialized literal it |
1582 // is already set in the cloned array. | 1582 // is already set in the cloned array. |
1583 if (subexpr->AsLiteral() != NULL || | 1583 if (subexpr->AsLiteral() != NULL || |
1584 CompileTimeValue::IsCompileTimeValue(subexpr)) { | 1584 CompileTimeValue::IsCompileTimeValue(subexpr)) { |
1585 continue; | 1585 continue; |
1586 } | 1586 } |
1587 | 1587 |
1588 if (!result_saved) { | 1588 if (!result_saved) { |
1589 __ push(v0); | 1589 __ push(v0); |
1590 result_saved = true; | 1590 result_saved = true; |
1591 } | 1591 } |
| 1592 |
1592 VisitForAccumulatorValue(subexpr); | 1593 VisitForAccumulatorValue(subexpr); |
1593 | 1594 |
1594 __ lw(t6, MemOperand(sp)); // Copy of array literal. | 1595 if (constant_elements_kind == FAST_ELEMENTS) { |
1595 __ lw(a1, FieldMemOperand(t6, JSObject::kElementsOffset)); | 1596 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
1596 __ lw(a2, FieldMemOperand(t6, JSObject::kMapOffset)); | 1597 __ lw(t2, MemOperand(sp)); // Copy of array literal. |
1597 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1598 __ lw(a1, FieldMemOperand(t2, JSObject::kElementsOffset)); |
1598 | 1599 __ sw(result_register(), FieldMemOperand(a1, offset)); |
1599 Label element_done; | 1600 // Update the write barrier for the array store. |
1600 Label double_elements; | 1601 __ RecordWriteField(a1, offset, result_register(), a2, |
1601 Label smi_element; | 1602 kRAHasBeenSaved, kDontSaveFPRegs, |
1602 Label slow_elements; | 1603 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK); |
1603 Label fast_elements; | 1604 } else { |
1604 __ CheckFastElements(a2, a3, &double_elements); | 1605 __ lw(a1, MemOperand(sp)); // Copy of array literal. |
1605 | 1606 __ lw(a2, FieldMemOperand(a1, JSObject::kMapOffset)); |
1606 // FAST_SMI_ONLY_ELEMENTS or FAST_ELEMENTS | 1607 __ li(a3, Operand(Smi::FromInt(i))); |
1607 __ JumpIfSmi(result_register(), &smi_element); | 1608 __ li(t0, Operand(Smi::FromInt(expr->literal_index()))); |
1608 __ CheckFastSmiOnlyElements(a2, a3, &fast_elements); | 1609 __ mov(a0, result_register()); |
1609 | 1610 StoreArrayLiteralElementStub stub; |
1610 // Store into the array literal requires a elements transition. Call into | 1611 __ CallStub(&stub); |
1611 // the runtime. | 1612 } |
1612 __ bind(&slow_elements); | |
1613 __ push(t6); // Copy of array literal. | |
1614 __ li(a1, Operand(Smi::FromInt(i))); | |
1615 __ li(a2, Operand(Smi::FromInt(NONE))); // PropertyAttributes | |
1616 StrictModeFlag strict_mode_flag = (language_mode() == CLASSIC_MODE) | |
1617 ? kNonStrictMode : kStrictMode; | |
1618 __ li(a3, Operand(Smi::FromInt(strict_mode_flag))); // Strict mode. | |
1619 __ Push(a1, result_register(), a2, a3); | |
1620 __ CallRuntime(Runtime::kSetProperty, 5); | |
1621 __ Branch(&element_done); | |
1622 | |
1623 // Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS. | |
1624 __ bind(&double_elements); | |
1625 __ li(a3, Operand(Smi::FromInt(i))); | |
1626 __ StoreNumberToDoubleElements(result_register(), a3, t6, a1, t0, t1, t5, | |
1627 t3, &slow_elements); | |
1628 __ Branch(&element_done); | |
1629 | |
1630 // Array literal has ElementsKind of FAST_ELEMENTS and value is an object. | |
1631 __ bind(&fast_elements); | |
1632 __ sw(result_register(), FieldMemOperand(a1, offset)); | |
1633 // Update the write barrier for the array store. | |
1634 | |
1635 __ RecordWriteField( | |
1636 a1, offset, result_register(), a2, kRAHasBeenSaved, kDontSaveFPRegs, | |
1637 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); | |
1638 __ Branch(&element_done); | |
1639 | |
1640 // Array literal has ElementsKind of FAST_SMI_ONLY_ELEMENTS or | |
1641 // FAST_ELEMENTS, and value is Smi. | |
1642 __ bind(&smi_element); | |
1643 __ sw(result_register(), FieldMemOperand(a1, offset)); | |
1644 // Fall through | |
1645 | |
1646 __ bind(&element_done); | |
1647 | 1613 |
1648 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); | 1614 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
1649 } | 1615 } |
1650 | |
1651 if (result_saved) { | 1616 if (result_saved) { |
1652 context()->PlugTOS(); | 1617 context()->PlugTOS(); |
1653 } else { | 1618 } else { |
1654 context()->Plug(v0); | 1619 context()->Plug(v0); |
1655 } | 1620 } |
1656 } | 1621 } |
1657 | 1622 |
1658 | 1623 |
1659 void FullCodeGenerator::VisitAssignment(Assignment* expr) { | 1624 void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
1660 Comment cmnt(masm_, "[ Assignment"); | 1625 Comment cmnt(masm_, "[ Assignment"); |
(...skipping 2777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4438 *context_length = 0; | 4403 *context_length = 0; |
4439 return previous_; | 4404 return previous_; |
4440 } | 4405 } |
4441 | 4406 |
4442 | 4407 |
4443 #undef __ | 4408 #undef __ |
4444 | 4409 |
4445 } } // namespace v8::internal | 4410 } } // namespace v8::internal |
4446 | 4411 |
4447 #endif // V8_TARGET_ARCH_MIPS | 4412 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |