OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 1704 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
1705 Comment cmnt(masm_, "[ ArrayLiteral"); | 1705 Comment cmnt(masm_, "[ ArrayLiteral"); |
1706 | 1706 |
1707 ZoneList<Expression*>* subexprs = expr->values(); | 1707 ZoneList<Expression*>* subexprs = expr->values(); |
1708 int length = subexprs->length(); | 1708 int length = subexprs->length(); |
1709 | 1709 |
1710 Handle<FixedArray> constant_elements = expr->constant_elements(); | 1710 Handle<FixedArray> constant_elements = expr->constant_elements(); |
1711 ASSERT_EQ(2, constant_elements->length()); | 1711 ASSERT_EQ(2, constant_elements->length()); |
1712 ElementsKind constant_elements_kind = | 1712 ElementsKind constant_elements_kind = |
1713 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); | 1713 static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
1714 bool has_fast_elements = constant_elements_kind == FAST_ELEMENTS; | 1714 bool has_fast_elements = |
| 1715 IsFastObjectElementsKind(constant_elements_kind); |
1715 Handle<FixedArrayBase> constant_elements_values( | 1716 Handle<FixedArrayBase> constant_elements_values( |
1716 FixedArrayBase::cast(constant_elements->get(1))); | 1717 FixedArrayBase::cast(constant_elements->get(1))); |
1717 | 1718 |
1718 __ mov(a0, result_register()); | 1719 __ mov(a0, result_register()); |
1719 __ lw(a3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 1720 __ lw(a3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
1720 __ lw(a3, FieldMemOperand(a3, JSFunction::kLiteralsOffset)); | 1721 __ lw(a3, FieldMemOperand(a3, JSFunction::kLiteralsOffset)); |
1721 __ li(a2, Operand(Smi::FromInt(expr->literal_index()))); | 1722 __ li(a2, Operand(Smi::FromInt(expr->literal_index()))); |
1722 __ li(a1, Operand(constant_elements)); | 1723 __ li(a1, Operand(constant_elements)); |
1723 __ Push(a3, a2, a1); | 1724 __ Push(a3, a2, a1); |
1724 if (has_fast_elements && constant_elements_values->map() == | 1725 if (has_fast_elements && constant_elements_values->map() == |
1725 isolate()->heap()->fixed_cow_array_map()) { | 1726 isolate()->heap()->fixed_cow_array_map()) { |
1726 FastCloneShallowArrayStub stub( | 1727 FastCloneShallowArrayStub stub( |
1727 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); | 1728 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
1728 __ CallStub(&stub); | 1729 __ CallStub(&stub); |
1729 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), | 1730 __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), |
1730 1, a1, a2); | 1731 1, a1, a2); |
1731 } else if (expr->depth() > 1) { | 1732 } else if (expr->depth() > 1) { |
1732 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); | 1733 __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
1733 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 1734 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
1734 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); | 1735 __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
1735 } else { | 1736 } else { |
1736 ASSERT(constant_elements_kind == FAST_ELEMENTS || | 1737 ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || |
1737 constant_elements_kind == FAST_SMI_ONLY_ELEMENTS || | |
1738 FLAG_smi_only_arrays); | 1738 FLAG_smi_only_arrays); |
1739 FastCloneShallowArrayStub::Mode mode = has_fast_elements | 1739 FastCloneShallowArrayStub::Mode mode = has_fast_elements |
1740 ? FastCloneShallowArrayStub::CLONE_ELEMENTS | 1740 ? FastCloneShallowArrayStub::CLONE_ELEMENTS |
1741 : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; | 1741 : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
1742 FastCloneShallowArrayStub stub(mode, length); | 1742 FastCloneShallowArrayStub stub(mode, length); |
1743 __ CallStub(&stub); | 1743 __ CallStub(&stub); |
1744 } | 1744 } |
1745 | 1745 |
1746 bool result_saved = false; // Is the result saved to the stack? | 1746 bool result_saved = false; // Is the result saved to the stack? |
1747 | 1747 |
1748 // Emit code to evaluate all the non-constant subexpressions and to store | 1748 // Emit code to evaluate all the non-constant subexpressions and to store |
1749 // them into the newly cloned array. | 1749 // them into the newly cloned array. |
1750 for (int i = 0; i < length; i++) { | 1750 for (int i = 0; i < length; i++) { |
1751 Expression* subexpr = subexprs->at(i); | 1751 Expression* subexpr = subexprs->at(i); |
1752 // If the subexpression is a literal or a simple materialized literal it | 1752 // If the subexpression is a literal or a simple materialized literal it |
1753 // is already set in the cloned array. | 1753 // is already set in the cloned array. |
1754 if (subexpr->AsLiteral() != NULL || | 1754 if (subexpr->AsLiteral() != NULL || |
1755 CompileTimeValue::IsCompileTimeValue(subexpr)) { | 1755 CompileTimeValue::IsCompileTimeValue(subexpr)) { |
1756 continue; | 1756 continue; |
1757 } | 1757 } |
1758 | 1758 |
1759 if (!result_saved) { | 1759 if (!result_saved) { |
1760 __ push(v0); | 1760 __ push(v0); |
1761 result_saved = true; | 1761 result_saved = true; |
1762 } | 1762 } |
1763 | 1763 |
1764 VisitForAccumulatorValue(subexpr); | 1764 VisitForAccumulatorValue(subexpr); |
1765 | 1765 |
1766 if (constant_elements_kind == FAST_ELEMENTS) { | 1766 if (IsFastObjectElementsKind(constant_elements_kind)) { |
1767 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1767 int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
1768 __ lw(t2, MemOperand(sp)); // Copy of array literal. | 1768 __ lw(t2, MemOperand(sp)); // Copy of array literal. |
1769 __ lw(a1, FieldMemOperand(t2, JSObject::kElementsOffset)); | 1769 __ lw(a1, FieldMemOperand(t2, JSObject::kElementsOffset)); |
1770 __ sw(result_register(), FieldMemOperand(a1, offset)); | 1770 __ sw(result_register(), FieldMemOperand(a1, offset)); |
1771 // Update the write barrier for the array store. | 1771 // Update the write barrier for the array store. |
1772 __ RecordWriteField(a1, offset, result_register(), a2, | 1772 __ RecordWriteField(a1, offset, result_register(), a2, |
1773 kRAHasBeenSaved, kDontSaveFPRegs, | 1773 kRAHasBeenSaved, kDontSaveFPRegs, |
1774 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK); | 1774 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK); |
1775 } else { | 1775 } else { |
1776 __ lw(a1, MemOperand(sp)); // Copy of array literal. | 1776 __ lw(a1, MemOperand(sp)); // Copy of array literal. |
(...skipping 2893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4670 *context_length = 0; | 4670 *context_length = 0; |
4671 return previous_; | 4671 return previous_; |
4672 } | 4672 } |
4673 | 4673 |
4674 | 4674 |
4675 #undef __ | 4675 #undef __ |
4676 | 4676 |
4677 } } // namespace v8::internal | 4677 } } // namespace v8::internal |
4678 | 4678 |
4679 #endif // V8_TARGET_ARCH_MIPS | 4679 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |