OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 4531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4542 DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister())); | 4542 DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister())); |
4543 DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister())); | 4543 DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister())); |
4544 | 4544 |
4545 Handle<Code> ic = CodeFactory::KeyedStoreICInOptimizedCode( | 4545 Handle<Code> ic = CodeFactory::KeyedStoreICInOptimizedCode( |
4546 isolate(), instr->language_mode(), | 4546 isolate(), instr->language_mode(), |
4547 instr->hydrogen()->initialization_state()).code(); | 4547 instr->hydrogen()->initialization_state()).code(); |
4548 CallCode(ic, RelocInfo::CODE_TARGET, instr); | 4548 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
4549 } | 4549 } |
4550 | 4550 |
4551 | 4551 |
| 4552 void LCodeGen::DoMaybeGrowElements(LMaybeGrowElements* instr) { |
| 4553 class DeferredMaybeGrowElements final : public LDeferredCode { |
| 4554 public: |
| 4555 DeferredMaybeGrowElements(LCodeGen* codegen, LMaybeGrowElements* instr) |
| 4556 : LDeferredCode(codegen), instr_(instr) {} |
| 4557 void Generate() override { codegen()->DoDeferredMaybeGrowElements(instr_); } |
| 4558 LInstruction* instr() override { return instr_; } |
| 4559 |
| 4560 private: |
| 4561 LMaybeGrowElements* instr_; |
| 4562 }; |
| 4563 |
| 4564 Register result = rax; |
| 4565 DeferredMaybeGrowElements* deferred = |
| 4566 new (zone()) DeferredMaybeGrowElements(this, instr); |
| 4567 LOperand* key = instr->key(); |
| 4568 LOperand* current_capacity = instr->current_capacity(); |
| 4569 |
| 4570 DCHECK(instr->hydrogen()->key()->representation().IsInteger32()); |
| 4571 DCHECK(instr->hydrogen()->current_capacity()->representation().IsInteger32()); |
| 4572 DCHECK(key->IsConstantOperand() || key->IsRegister()); |
| 4573 DCHECK(current_capacity->IsConstantOperand() || |
| 4574 current_capacity->IsRegister()); |
| 4575 |
| 4576 if (key->IsConstantOperand() && current_capacity->IsConstantOperand()) { |
| 4577 int32_t constant_key = ToInteger32(LConstantOperand::cast(key)); |
| 4578 int32_t constant_capacity = |
| 4579 ToInteger32(LConstantOperand::cast(current_capacity)); |
| 4580 if (constant_key >= constant_capacity) { |
| 4581 // Deferred case. |
| 4582 __ jmp(deferred->entry()); |
| 4583 } |
| 4584 } else if (key->IsConstantOperand()) { |
| 4585 int32_t constant_key = ToInteger32(LConstantOperand::cast(key)); |
| 4586 __ cmpl(ToRegister(current_capacity), Immediate(constant_key)); |
| 4587 __ j(less_equal, deferred->entry()); |
| 4588 } else if (current_capacity->IsConstantOperand()) { |
| 4589 int32_t constant_capacity = |
| 4590 ToInteger32(LConstantOperand::cast(current_capacity)); |
| 4591 __ cmpl(ToRegister(key), Immediate(constant_capacity)); |
| 4592 __ j(greater_equal, deferred->entry()); |
| 4593 } else { |
| 4594 __ cmpl(ToRegister(key), ToRegister(current_capacity)); |
| 4595 __ j(greater_equal, deferred->entry()); |
| 4596 } |
| 4597 |
| 4598 if (instr->elements()->IsRegister()) { |
| 4599 __ movp(result, ToRegister(instr->elements())); |
| 4600 } else { |
| 4601 __ movp(result, ToOperand(instr->elements())); |
| 4602 } |
| 4603 |
| 4604 __ bind(deferred->exit()); |
| 4605 } |
| 4606 |
| 4607 |
| 4608 void LCodeGen::DoDeferredMaybeGrowElements(LMaybeGrowElements* instr) { |
| 4609 // TODO(3095996): Get rid of this. For now, we need to make the |
| 4610 // result register contain a valid pointer because it is already |
| 4611 // contained in the register pointer map. |
| 4612 Register result = rax; |
| 4613 __ Move(result, Smi::FromInt(0)); |
| 4614 |
| 4615 // We have to call a stub. |
| 4616 { |
| 4617 PushSafepointRegistersScope scope(this); |
| 4618 if (instr->object()->IsConstantOperand()) { |
| 4619 LConstantOperand* constant_object = |
| 4620 LConstantOperand::cast(instr->object()); |
| 4621 if (IsSmiConstant(constant_object)) { |
| 4622 Smi* immediate = ToSmi(constant_object); |
| 4623 __ Move(result, immediate); |
| 4624 } else { |
| 4625 Handle<Object> handle_value = ToHandle(constant_object); |
| 4626 __ Move(result, handle_value); |
| 4627 } |
| 4628 } else if (instr->object()->IsRegister()) { |
| 4629 __ Move(result, ToRegister(instr->object())); |
| 4630 } else { |
| 4631 __ movp(result, ToOperand(instr->object())); |
| 4632 } |
| 4633 |
| 4634 LOperand* key = instr->key(); |
| 4635 if (key->IsConstantOperand()) { |
| 4636 __ Move(rbx, ToSmi(LConstantOperand::cast(key))); |
| 4637 } else { |
| 4638 __ Move(rbx, ToRegister(key)); |
| 4639 __ Integer32ToSmi(rbx, rbx); |
| 4640 } |
| 4641 |
| 4642 GrowArrayElementsStub stub(isolate(), instr->hydrogen()->is_js_array(), |
| 4643 instr->hydrogen()->kind()); |
| 4644 __ CallStub(&stub); |
| 4645 RecordSafepointWithLazyDeopt(instr, RECORD_SAFEPOINT_WITH_REGISTERS, 0); |
| 4646 __ StoreToSafepointRegisterSlot(result, result); |
| 4647 } |
| 4648 |
| 4649 // Deopt on smi, which means the elements array changed to dictionary mode. |
| 4650 Condition is_smi = __ CheckSmi(result); |
| 4651 DeoptimizeIf(is_smi, instr, Deoptimizer::kSmi); |
| 4652 } |
| 4653 |
| 4654 |
4552 void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { | 4655 void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
4553 Register object_reg = ToRegister(instr->object()); | 4656 Register object_reg = ToRegister(instr->object()); |
4554 | 4657 |
4555 Handle<Map> from_map = instr->original_map(); | 4658 Handle<Map> from_map = instr->original_map(); |
4556 Handle<Map> to_map = instr->transitioned_map(); | 4659 Handle<Map> to_map = instr->transitioned_map(); |
4557 ElementsKind from_kind = instr->from_kind(); | 4660 ElementsKind from_kind = instr->from_kind(); |
4558 ElementsKind to_kind = instr->to_kind(); | 4661 ElementsKind to_kind = instr->to_kind(); |
4559 | 4662 |
4560 Label not_applicable; | 4663 Label not_applicable; |
4561 __ Cmp(FieldOperand(object_reg, HeapObject::kMapOffset), from_map); | 4664 __ Cmp(FieldOperand(object_reg, HeapObject::kMapOffset), from_map); |
(...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5953 CallRuntime(Runtime::kPushBlockContext, 2, instr); | 6056 CallRuntime(Runtime::kPushBlockContext, 2, instr); |
5954 RecordSafepoint(Safepoint::kNoLazyDeopt); | 6057 RecordSafepoint(Safepoint::kNoLazyDeopt); |
5955 } | 6058 } |
5956 | 6059 |
5957 | 6060 |
5958 #undef __ | 6061 #undef __ |
5959 | 6062 |
5960 } } // namespace v8::internal | 6063 } } // namespace v8::internal |
5961 | 6064 |
5962 #endif // V8_TARGET_ARCH_X64 | 6065 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |