| OLD | NEW |
| 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 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
| 6 | 6 |
| 7 #include "src/full-codegen/full-codegen.h" | 7 #include "src/full-codegen/full-codegen.h" |
| 8 #include "src/ast/compile-time-value.h" | 8 #include "src/ast/compile-time-value.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
| (...skipping 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 __ CallStub(&stub); | 1529 __ CallStub(&stub); |
| 1530 } | 1530 } |
| 1531 PrepareForBailoutForId(expr->CreateLiteralId(), BailoutState::TOS_REGISTER); | 1531 PrepareForBailoutForId(expr->CreateLiteralId(), BailoutState::TOS_REGISTER); |
| 1532 | 1532 |
| 1533 bool result_saved = false; // Is the result saved to the stack? | 1533 bool result_saved = false; // Is the result saved to the stack? |
| 1534 ZoneList<Expression*>* subexprs = expr->values(); | 1534 ZoneList<Expression*>* subexprs = expr->values(); |
| 1535 int length = subexprs->length(); | 1535 int length = subexprs->length(); |
| 1536 | 1536 |
| 1537 // Emit code to evaluate all the non-constant subexpressions and to store | 1537 // Emit code to evaluate all the non-constant subexpressions and to store |
| 1538 // them into the newly cloned array. | 1538 // them into the newly cloned array. |
| 1539 int array_index = 0; | 1539 for (int array_index = 0; array_index < length; array_index++) { |
| 1540 for (; array_index < length; array_index++) { | |
| 1541 Expression* subexpr = subexprs->at(array_index); | 1540 Expression* subexpr = subexprs->at(array_index); |
| 1542 DCHECK(!subexpr->IsSpread()); | 1541 DCHECK(!subexpr->IsSpread()); |
| 1543 | 1542 |
| 1544 // If the subexpression is a literal or a simple materialized literal it | 1543 // If the subexpression is a literal or a simple materialized literal it |
| 1545 // is already set in the cloned array. | 1544 // is already set in the cloned array. |
| 1546 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; | 1545 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
| 1547 | 1546 |
| 1548 if (!result_saved) { | 1547 if (!result_saved) { |
| 1549 PushOperand(rax); // array literal | 1548 PushOperand(rax); // array literal |
| 1550 result_saved = true; | 1549 result_saved = true; |
| 1551 } | 1550 } |
| 1552 VisitForAccumulatorValue(subexpr); | 1551 VisitForAccumulatorValue(subexpr); |
| 1553 | 1552 |
| 1554 __ Move(StoreDescriptor::NameRegister(), Smi::FromInt(array_index)); | 1553 __ Move(StoreDescriptor::NameRegister(), Smi::FromInt(array_index)); |
| 1555 __ movp(StoreDescriptor::ReceiverRegister(), Operand(rsp, 0)); | 1554 __ movp(StoreDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
| 1556 EmitLoadStoreICSlot(expr->LiteralFeedbackSlot()); | 1555 EmitLoadStoreICSlot(expr->LiteralFeedbackSlot()); |
| 1557 CallKeyedStoreIC(); | 1556 CallKeyedStoreIC(); |
| 1558 | 1557 |
| 1559 PrepareForBailoutForId(expr->GetIdForElement(array_index), | 1558 PrepareForBailoutForId(expr->GetIdForElement(array_index), |
| 1560 BailoutState::NO_REGISTERS); | 1559 BailoutState::NO_REGISTERS); |
| 1561 } | 1560 } |
| 1562 | 1561 |
| 1563 // In case the array literal contains spread expressions it has two parts. The | |
| 1564 // first part is the "static" array which has a literal index is handled | |
| 1565 // above. The second part is the part after the first spread expression | |
| 1566 // (inclusive) and these elements gets appended to the array. Note that the | |
| 1567 // number elements an iterable produces is unknown ahead of time. | |
| 1568 if (array_index < length && result_saved) { | |
| 1569 PopOperand(rax); | |
| 1570 result_saved = false; | |
| 1571 } | |
| 1572 for (; array_index < length; array_index++) { | |
| 1573 Expression* subexpr = subexprs->at(array_index); | |
| 1574 | |
| 1575 PushOperand(rax); | |
| 1576 DCHECK(!subexpr->IsSpread()); | |
| 1577 VisitForStackValue(subexpr); | |
| 1578 CallRuntimeWithOperands(Runtime::kAppendElement); | |
| 1579 | |
| 1580 PrepareForBailoutForId(expr->GetIdForElement(array_index), | |
| 1581 BailoutState::NO_REGISTERS); | |
| 1582 } | |
| 1583 | |
| 1584 if (result_saved) { | 1562 if (result_saved) { |
| 1585 context()->PlugTOS(); | 1563 context()->PlugTOS(); |
| 1586 } else { | 1564 } else { |
| 1587 context()->Plug(rax); | 1565 context()->Plug(rax); |
| 1588 } | 1566 } |
| 1589 } | 1567 } |
| 1590 | 1568 |
| 1591 | 1569 |
| 1592 void FullCodeGenerator::VisitAssignment(Assignment* expr) { | 1570 void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1593 DCHECK(expr->target()->IsValidReferenceExpressionOrThis()); | 1571 DCHECK(expr->target()->IsValidReferenceExpressionOrThis()); |
| (...skipping 2023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3617 DCHECK_EQ( | 3595 DCHECK_EQ( |
| 3618 isolate->builtins()->OnStackReplacement()->entry(), | 3596 isolate->builtins()->OnStackReplacement()->entry(), |
| 3619 Assembler::target_address_at(call_target_address, unoptimized_code)); | 3597 Assembler::target_address_at(call_target_address, unoptimized_code)); |
| 3620 return ON_STACK_REPLACEMENT; | 3598 return ON_STACK_REPLACEMENT; |
| 3621 } | 3599 } |
| 3622 | 3600 |
| 3623 } // namespace internal | 3601 } // namespace internal |
| 3624 } // namespace v8 | 3602 } // namespace v8 |
| 3625 | 3603 |
| 3626 #endif // V8_TARGET_ARCH_X64 | 3604 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |