Chromium Code Reviews| 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/compiler/code-generator.h" | 5 #include "src/compiler/code-generator.h" |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/compiler/code-generator-impl.h" | 8 #include "src/compiler/code-generator-impl.h" |
| 9 #include "src/compiler/gap-resolver.h" | 9 #include "src/compiler/gap-resolver.h" |
| 10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 __ PrepareCallCFunction(1); \ | 619 __ PrepareCallCFunction(1); \ |
| 620 __ CallCFunction(ExternalReference::ieee754_##name##_function(isolate()), \ | 620 __ CallCFunction(ExternalReference::ieee754_##name##_function(isolate()), \ |
| 621 1); \ | 621 1); \ |
| 622 } while (false) | 622 } while (false) |
| 623 | 623 |
| 624 void CodeGenerator::AssembleDeconstructFrame() { | 624 void CodeGenerator::AssembleDeconstructFrame() { |
| 625 __ movq(rsp, rbp); | 625 __ movq(rsp, rbp); |
| 626 __ popq(rbp); | 626 __ popq(rbp); |
| 627 } | 627 } |
| 628 | 628 |
| 629 void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { | 629 void CodeGenerator::AssemblePrepareTailCall() { |
| 630 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); | |
| 631 if (sp_slot_delta > 0) { | |
| 632 __ addq(rsp, Immediate(sp_slot_delta * kPointerSize)); | |
| 633 } | |
| 634 frame_access_state()->SetFrameAccessToDefault(); | |
| 635 } | |
| 636 | |
| 637 | |
| 638 void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) { | |
| 639 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); | |
| 640 if (sp_slot_delta < 0) { | |
| 641 __ subq(rsp, Immediate(-sp_slot_delta * kPointerSize)); | |
| 642 frame_access_state()->IncreaseSPDelta(-sp_slot_delta); | |
| 643 } | |
| 644 if (frame_access_state()->has_frame()) { | 630 if (frame_access_state()->has_frame()) { |
| 645 __ movq(rbp, MemOperand(rbp, 0)); | 631 __ movq(rbp, MemOperand(rbp, 0)); |
| 646 } | 632 } |
| 647 frame_access_state()->SetFrameAccessToSP(); | 633 frame_access_state()->SetFrameAccessToSP(); |
| 648 } | 634 } |
| 649 | 635 |
| 650 void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg, | 636 void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg, |
| 651 Register scratch1, | 637 Register scratch1, |
| 652 Register scratch2, | 638 Register scratch2, |
| 653 Register scratch3) { | 639 Register scratch3) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 665 __ SmiToInteger32( | 651 __ SmiToInteger32( |
| 666 caller_args_count_reg, | 652 caller_args_count_reg, |
| 667 Operand(rbp, ArgumentsAdaptorFrameConstants::kLengthOffset)); | 653 Operand(rbp, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 668 | 654 |
| 669 ParameterCount callee_args_count(args_reg); | 655 ParameterCount callee_args_count(args_reg); |
| 670 __ PrepareForTailCall(callee_args_count, caller_args_count_reg, scratch2, | 656 __ PrepareForTailCall(callee_args_count, caller_args_count_reg, scratch2, |
| 671 scratch3, ReturnAddressState::kOnStack); | 657 scratch3, ReturnAddressState::kOnStack); |
| 672 __ bind(&done); | 658 __ bind(&done); |
| 673 } | 659 } |
| 674 | 660 |
| 661 namespace { | |
| 662 void AdjustStackPointerForGap(MacroAssembler* masm, FrameAccessState* state, | |
| 663 int new_slot_above_sp, | |
| 664 bool allow_shrinkage = true) { | |
| 665 int current_sp_offset = state->GetSPToFPSlotCount() + | |
| 666 StandardFrameConstants::kFixedSlotCountAboveFp; | |
| 667 int stack_slot_delta = new_slot_above_sp - current_sp_offset; | |
| 668 if (stack_slot_delta > 0) { | |
| 669 masm->subq(rsp, Immediate(stack_slot_delta * kPointerSize)); | |
| 670 state->IncreaseSPDelta(stack_slot_delta); | |
| 671 } else if (allow_shrinkage && stack_slot_delta < 0) { | |
| 672 masm->addq(rsp, Immediate(-stack_slot_delta * kPointerSize)); | |
| 673 state->IncreaseSPDelta(stack_slot_delta); | |
| 674 } | |
| 675 } | |
| 676 } // namespace | |
| 677 | |
| 678 void CodeGenerator::AssemblePreGaps(Instruction* instr) { | |
| 679 int first_unused_stack_slot; | |
| 680 if (!GetSlotAboveSPAfterGap(instr, &first_unused_stack_slot)) return; | |
| 681 | |
| 682 GapResolver::PushTypeFlags flags = GapResolver::kImmediatePush; | |
|
Benedikt Meurer
2016/06/30 07:57:06
Nit: Merge these two lines.
danno
2016/07/01 07:31:56
Done.
| |
| 683 flags |= GapResolver::kScalarPush; | |
| 684 ZoneVector<MoveOperands*> pushes(zone()); | |
| 685 resolver()->GetPushCompatibleMoves(zone(), instr, flags, &pushes); | |
| 686 | |
| 687 if (pushes.size() > 0 && | |
|
Benedikt Meurer
2016/06/30 07:57:06
Nit: !pushes.empty()
danno
2016/07/01 07:31:56
Done.
| |
| 688 (LocationOperand::cast(pushes.back()->destination()).index() + 1 == | |
| 689 first_unused_stack_slot)) { | |
| 690 X64OperandConverter g(this, instr); | |
| 691 for (auto move : pushes) { | |
| 692 LocationOperand destination_location( | |
| 693 LocationOperand::cast(move->destination())); | |
| 694 InstructionOperand source(move->source()); | |
| 695 AdjustStackPointerForGap(masm(), frame_access_state(), | |
| 696 destination_location.index()); | |
| 697 if (source.IsStackSlot()) { | |
| 698 LocationOperand source_location(LocationOperand::cast(source)); | |
| 699 __ Push(g.SlotToOperand(source_location.index())); | |
| 700 frame_access_state()->IncreaseSPDelta(1); | |
| 701 move->Eliminate(); | |
| 702 } else if (source.IsRegister()) { | |
| 703 LocationOperand source_location(LocationOperand::cast(source)); | |
| 704 __ Push(source_location.GetRegister()); | |
| 705 frame_access_state()->IncreaseSPDelta(1); | |
| 706 move->Eliminate(); | |
| 707 } else if (source.IsImmediate()) { | |
| 708 __ Push(Immediate(ImmediateOperand::cast(source).inline_value())); | |
| 709 frame_access_state()->IncreaseSPDelta(1); | |
| 710 move->Eliminate(); | |
| 711 } else { | |
| 712 // Pushes of non-scalar data types is not supported. | |
| 713 UNIMPLEMENTED(); | |
| 714 } | |
| 715 } | |
| 716 } | |
| 717 AdjustStackPointerForGap(masm(), frame_access_state(), | |
| 718 first_unused_stack_slot, false); | |
| 719 } | |
| 720 | |
| 721 void CodeGenerator::AssemblePostGaps(Instruction* instr) { | |
| 722 int first_unused_stack_slot; | |
| 723 if (!GetSlotAboveSPAfterGap(instr, &first_unused_stack_slot)) return; | |
| 724 AdjustStackPointerForGap(masm(), frame_access_state(), | |
| 725 first_unused_stack_slot); | |
| 726 } | |
| 727 | |
| 675 // Assembles an instruction after register allocation, producing machine code. | 728 // Assembles an instruction after register allocation, producing machine code. |
| 676 CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( | 729 CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
| 677 Instruction* instr) { | 730 Instruction* instr) { |
| 678 X64OperandConverter i(this, instr); | 731 X64OperandConverter i(this, instr); |
| 679 InstructionCode opcode = instr->opcode(); | 732 InstructionCode opcode = instr->opcode(); |
| 680 ArchOpcode arch_opcode = ArchOpcodeField::decode(opcode); | 733 ArchOpcode arch_opcode = ArchOpcodeField::decode(opcode); |
| 681 switch (arch_opcode) { | 734 switch (arch_opcode) { |
| 682 case kArchCallCodeObject: { | 735 case kArchCallCodeObject: { |
| 683 EnsureSpaceForLazyDeopt(); | 736 EnsureSpaceForLazyDeopt(); |
| 684 if (HasImmediateInput(instr, 0)) { | 737 if (HasImmediateInput(instr, 0)) { |
| 685 Handle<Code> code = Handle<Code>::cast(i.InputHeapObject(0)); | 738 Handle<Code> code = Handle<Code>::cast(i.InputHeapObject(0)); |
| 686 __ Call(code, RelocInfo::CODE_TARGET); | 739 __ Call(code, RelocInfo::CODE_TARGET); |
| 687 } else { | 740 } else { |
| 688 Register reg = i.InputRegister(0); | 741 Register reg = i.InputRegister(0); |
| 689 __ addp(reg, Immediate(Code::kHeaderSize - kHeapObjectTag)); | 742 __ addp(reg, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 690 __ call(reg); | 743 __ call(reg); |
| 691 } | 744 } |
| 692 RecordCallPosition(instr); | 745 RecordCallPosition(instr); |
| 693 frame_access_state()->ClearSPDelta(); | 746 frame_access_state()->ClearSPDelta(); |
| 694 break; | 747 break; |
| 695 } | 748 } |
| 696 case kArchTailCallCodeObjectFromJSFunction: | 749 case kArchTailCallCodeObjectFromJSFunction: |
| 697 case kArchTailCallCodeObject: { | 750 case kArchTailCallCodeObject: { |
| 698 int stack_param_delta = i.InputInt32(instr->InputCount() - 1); | |
| 699 AssembleDeconstructActivationRecord(stack_param_delta); | |
| 700 if (arch_opcode == kArchTailCallCodeObjectFromJSFunction) { | 751 if (arch_opcode == kArchTailCallCodeObjectFromJSFunction) { |
| 701 AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, | 752 AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, |
| 702 i.TempRegister(0), i.TempRegister(1), | 753 i.TempRegister(0), i.TempRegister(1), |
| 703 i.TempRegister(2)); | 754 i.TempRegister(2)); |
| 704 } | 755 } |
| 705 if (HasImmediateInput(instr, 0)) { | 756 if (HasImmediateInput(instr, 0)) { |
| 706 Handle<Code> code = Handle<Code>::cast(i.InputHeapObject(0)); | 757 Handle<Code> code = Handle<Code>::cast(i.InputHeapObject(0)); |
| 707 __ jmp(code, RelocInfo::CODE_TARGET); | 758 __ jmp(code, RelocInfo::CODE_TARGET); |
| 708 } else { | 759 } else { |
| 709 Register reg = i.InputRegister(0); | 760 Register reg = i.InputRegister(0); |
| 710 __ addp(reg, Immediate(Code::kHeaderSize - kHeapObjectTag)); | 761 __ addp(reg, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 711 __ jmp(reg); | 762 __ jmp(reg); |
| 712 } | 763 } |
| 713 frame_access_state()->ClearSPDelta(); | 764 frame_access_state()->ClearSPDelta(); |
| 765 frame_access_state()->SetFrameAccessToDefault(); | |
| 714 break; | 766 break; |
| 715 } | 767 } |
| 716 case kArchTailCallAddress: { | 768 case kArchTailCallAddress: { |
| 717 int stack_param_delta = i.InputInt32(instr->InputCount() - 1); | |
| 718 AssembleDeconstructActivationRecord(stack_param_delta); | |
| 719 CHECK(!HasImmediateInput(instr, 0)); | 769 CHECK(!HasImmediateInput(instr, 0)); |
| 720 Register reg = i.InputRegister(0); | 770 Register reg = i.InputRegister(0); |
| 721 __ jmp(reg); | 771 __ jmp(reg); |
| 722 frame_access_state()->ClearSPDelta(); | 772 frame_access_state()->ClearSPDelta(); |
| 773 frame_access_state()->SetFrameAccessToDefault(); | |
| 723 break; | 774 break; |
| 724 } | 775 } |
| 725 case kArchCallJSFunction: { | 776 case kArchCallJSFunction: { |
| 726 EnsureSpaceForLazyDeopt(); | 777 EnsureSpaceForLazyDeopt(); |
| 727 Register func = i.InputRegister(0); | 778 Register func = i.InputRegister(0); |
| 728 if (FLAG_debug_code) { | 779 if (FLAG_debug_code) { |
| 729 // Check the function's context matches the context argument. | 780 // Check the function's context matches the context argument. |
| 730 __ cmpp(rsi, FieldOperand(func, JSFunction::kContextOffset)); | 781 __ cmpp(rsi, FieldOperand(func, JSFunction::kContextOffset)); |
| 731 __ Assert(equal, kWrongFunctionContext); | 782 __ Assert(equal, kWrongFunctionContext); |
| 732 } | 783 } |
| 733 __ Call(FieldOperand(func, JSFunction::kCodeEntryOffset)); | 784 __ Call(FieldOperand(func, JSFunction::kCodeEntryOffset)); |
| 734 frame_access_state()->ClearSPDelta(); | 785 frame_access_state()->ClearSPDelta(); |
| 735 RecordCallPosition(instr); | 786 RecordCallPosition(instr); |
| 736 break; | 787 break; |
| 737 } | 788 } |
| 738 case kArchTailCallJSFunctionFromJSFunction: | 789 case kArchTailCallJSFunctionFromJSFunction: |
| 739 case kArchTailCallJSFunction: { | 790 case kArchTailCallJSFunction: { |
| 740 Register func = i.InputRegister(0); | 791 Register func = i.InputRegister(0); |
| 741 if (FLAG_debug_code) { | 792 if (FLAG_debug_code) { |
| 742 // Check the function's context matches the context argument. | 793 // Check the function's context matches the context argument. |
| 743 __ cmpp(rsi, FieldOperand(func, JSFunction::kContextOffset)); | 794 __ cmpp(rsi, FieldOperand(func, JSFunction::kContextOffset)); |
| 744 __ Assert(equal, kWrongFunctionContext); | 795 __ Assert(equal, kWrongFunctionContext); |
| 745 } | 796 } |
| 746 int stack_param_delta = i.InputInt32(instr->InputCount() - 1); | |
| 747 AssembleDeconstructActivationRecord(stack_param_delta); | |
| 748 if (arch_opcode == kArchTailCallJSFunctionFromJSFunction) { | 797 if (arch_opcode == kArchTailCallJSFunctionFromJSFunction) { |
| 749 AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, | 798 AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, |
| 750 i.TempRegister(0), i.TempRegister(1), | 799 i.TempRegister(0), i.TempRegister(1), |
| 751 i.TempRegister(2)); | 800 i.TempRegister(2)); |
| 752 } | 801 } |
| 753 __ jmp(FieldOperand(func, JSFunction::kCodeEntryOffset)); | 802 __ jmp(FieldOperand(func, JSFunction::kCodeEntryOffset)); |
| 754 frame_access_state()->ClearSPDelta(); | 803 frame_access_state()->ClearSPDelta(); |
| 804 frame_access_state()->SetFrameAccessToDefault(); | |
| 755 break; | 805 break; |
| 756 } | 806 } |
| 757 case kArchPrepareCallCFunction: { | 807 case kArchPrepareCallCFunction: { |
| 758 // Frame alignment requires using FP-relative frame addressing. | 808 // Frame alignment requires using FP-relative frame addressing. |
| 759 frame_access_state()->SetFrameAccessToFP(); | 809 frame_access_state()->SetFrameAccessToFP(); |
| 760 int const num_parameters = MiscField::decode(instr->opcode()); | 810 int const num_parameters = MiscField::decode(instr->opcode()); |
| 761 __ PrepareCallCFunction(num_parameters); | 811 __ PrepareCallCFunction(num_parameters); |
| 762 break; | 812 break; |
| 763 } | 813 } |
| 764 case kArchPrepareTailCall: | 814 case kArchPrepareTailCall: |
| 765 AssemblePrepareTailCall(i.InputInt32(instr->InputCount() - 1)); | 815 AssemblePrepareTailCall(); |
| 766 break; | 816 break; |
| 767 case kArchCallCFunction: { | 817 case kArchCallCFunction: { |
| 768 int const num_parameters = MiscField::decode(instr->opcode()); | 818 int const num_parameters = MiscField::decode(instr->opcode()); |
| 769 if (HasImmediateInput(instr, 0)) { | 819 if (HasImmediateInput(instr, 0)) { |
| 770 ExternalReference ref = i.InputExternalReference(0); | 820 ExternalReference ref = i.InputExternalReference(0); |
| 771 __ CallCFunction(ref, num_parameters); | 821 __ CallCFunction(ref, num_parameters); |
| 772 } else { | 822 } else { |
| 773 Register func = i.InputRegister(0); | 823 Register func = i.InputRegister(0); |
| 774 __ CallCFunction(func, num_parameters); | 824 __ CallCFunction(func, num_parameters); |
| 775 } | 825 } |
| (...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2394 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | 2444 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
| 2395 __ Nop(padding_size); | 2445 __ Nop(padding_size); |
| 2396 } | 2446 } |
| 2397 } | 2447 } |
| 2398 | 2448 |
| 2399 #undef __ | 2449 #undef __ |
| 2400 | 2450 |
| 2401 } // namespace compiler | 2451 } // namespace compiler |
| 2402 } // namespace internal | 2452 } // namespace internal |
| 2403 } // namespace v8 | 2453 } // namespace v8 |
| OLD | NEW |