OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
6 #include "src/compiler/code-generator.h" | 6 #include "src/compiler/code-generator.h" |
7 #include "src/compiler/code-generator-impl.h" | 7 #include "src/compiler/code-generator-impl.h" |
8 #include "src/compiler/gap-resolver.h" | 8 #include "src/compiler/gap-resolver.h" |
9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
10 #include "src/compiler/osr.h" | 10 #include "src/compiler/osr.h" |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 0, 1); \ | 506 0, 1); \ |
507 /* Move the result in the double result register. */ \ | 507 /* Move the result in the double result register. */ \ |
508 __ MovFromFloatResult(i.OutputDoubleRegister()); \ | 508 __ MovFromFloatResult(i.OutputDoubleRegister()); \ |
509 } while (0) | 509 } while (0) |
510 | 510 |
511 void CodeGenerator::AssembleDeconstructFrame() { | 511 void CodeGenerator::AssembleDeconstructFrame() { |
512 __ mov(sp, fp); | 512 __ mov(sp, fp); |
513 __ Pop(ra, fp); | 513 __ Pop(ra, fp); |
514 } | 514 } |
515 | 515 |
516 void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { | 516 void CodeGenerator::AssemblePrepareTailCall() { |
517 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); | |
518 if (sp_slot_delta > 0) { | |
519 __ addiu(sp, sp, sp_slot_delta * kPointerSize); | |
520 } | |
521 frame_access_state()->SetFrameAccessToDefault(); | |
522 } | |
523 | |
524 | |
525 void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) { | |
526 int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); | |
527 if (sp_slot_delta < 0) { | |
528 __ Subu(sp, sp, Operand(-sp_slot_delta * kPointerSize)); | |
529 frame_access_state()->IncreaseSPDelta(-sp_slot_delta); | |
530 } | |
531 if (frame_access_state()->has_frame()) { | 517 if (frame_access_state()->has_frame()) { |
532 __ lw(ra, MemOperand(fp, StandardFrameConstants::kCallerPCOffset)); | 518 __ lw(ra, MemOperand(fp, StandardFrameConstants::kCallerPCOffset)); |
533 __ lw(fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | 519 __ lw(fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
534 } | 520 } |
535 frame_access_state()->SetFrameAccessToSP(); | 521 frame_access_state()->SetFrameAccessToSP(); |
536 } | 522 } |
537 | 523 |
538 void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg, | 524 void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg, |
539 Register scratch1, | 525 Register scratch1, |
540 Register scratch2, | 526 Register scratch2, |
(...skipping 12 matching lines...) Expand all Loading... |
553 __ lw(caller_args_count_reg, | 539 __ lw(caller_args_count_reg, |
554 MemOperand(fp, ArgumentsAdaptorFrameConstants::kLengthOffset)); | 540 MemOperand(fp, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
555 __ SmiUntag(caller_args_count_reg); | 541 __ SmiUntag(caller_args_count_reg); |
556 | 542 |
557 ParameterCount callee_args_count(args_reg); | 543 ParameterCount callee_args_count(args_reg); |
558 __ PrepareForTailCall(callee_args_count, caller_args_count_reg, scratch2, | 544 __ PrepareForTailCall(callee_args_count, caller_args_count_reg, scratch2, |
559 scratch3); | 545 scratch3); |
560 __ bind(&done); | 546 __ bind(&done); |
561 } | 547 } |
562 | 548 |
| 549 namespace { |
| 550 |
| 551 void AdjustStackPointerForTailCall(MacroAssembler* masm, |
| 552 FrameAccessState* state, |
| 553 int new_slot_above_sp, |
| 554 bool allow_shrinkage = true) { |
| 555 int current_sp_offset = state->GetSPToFPSlotCount() + |
| 556 StandardFrameConstants::kFixedSlotCountAboveFp; |
| 557 int stack_slot_delta = new_slot_above_sp - current_sp_offset; |
| 558 if (stack_slot_delta > 0) { |
| 559 masm->Subu(sp, sp, stack_slot_delta * kPointerSize); |
| 560 state->IncreaseSPDelta(stack_slot_delta); |
| 561 } else if (allow_shrinkage && stack_slot_delta < 0) { |
| 562 masm->Addu(sp, sp, stack_slot_delta * kPointerSize); |
| 563 state->IncreaseSPDelta(stack_slot_delta); |
| 564 } |
| 565 } |
| 566 |
| 567 } // namespace |
| 568 |
| 569 void CodeGenerator::AssembleTailCallBeforeGap(Instruction* instr, |
| 570 int first_unused_stack_slot) { |
| 571 AdjustStackPointerForTailCall(masm(), frame_access_state(), |
| 572 first_unused_stack_slot, false); |
| 573 } |
| 574 |
| 575 void CodeGenerator::AssembleTailCallAfterGap(Instruction* instr, |
| 576 int first_unused_stack_slot) { |
| 577 AdjustStackPointerForTailCall(masm(), frame_access_state(), |
| 578 first_unused_stack_slot); |
| 579 } |
| 580 |
563 // Assembles an instruction after register allocation, producing machine code. | 581 // Assembles an instruction after register allocation, producing machine code. |
564 CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( | 582 CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
565 Instruction* instr) { | 583 Instruction* instr) { |
566 MipsOperandConverter i(this, instr); | 584 MipsOperandConverter i(this, instr); |
567 InstructionCode opcode = instr->opcode(); | 585 InstructionCode opcode = instr->opcode(); |
568 ArchOpcode arch_opcode = ArchOpcodeField::decode(opcode); | 586 ArchOpcode arch_opcode = ArchOpcodeField::decode(opcode); |
569 switch (arch_opcode) { | 587 switch (arch_opcode) { |
570 case kArchCallCodeObject: { | 588 case kArchCallCodeObject: { |
571 EnsureSpaceForLazyDeopt(); | 589 EnsureSpaceForLazyDeopt(); |
572 if (instr->InputAt(0)->IsImmediate()) { | 590 if (instr->InputAt(0)->IsImmediate()) { |
573 __ Call(Handle<Code>::cast(i.InputHeapObject(0)), | 591 __ Call(Handle<Code>::cast(i.InputHeapObject(0)), |
574 RelocInfo::CODE_TARGET); | 592 RelocInfo::CODE_TARGET); |
575 } else { | 593 } else { |
576 __ addiu(at, i.InputRegister(0), Code::kHeaderSize - kHeapObjectTag); | 594 __ addiu(at, i.InputRegister(0), Code::kHeaderSize - kHeapObjectTag); |
577 __ Call(at); | 595 __ Call(at); |
578 } | 596 } |
579 RecordCallPosition(instr); | 597 RecordCallPosition(instr); |
580 frame_access_state()->ClearSPDelta(); | 598 frame_access_state()->ClearSPDelta(); |
581 break; | 599 break; |
582 } | 600 } |
583 case kArchTailCallCodeObjectFromJSFunction: | 601 case kArchTailCallCodeObjectFromJSFunction: |
584 case kArchTailCallCodeObject: { | 602 case kArchTailCallCodeObject: { |
585 int stack_param_delta = i.InputInt32(instr->InputCount() - 1); | |
586 AssembleDeconstructActivationRecord(stack_param_delta); | |
587 if (arch_opcode == kArchTailCallCodeObjectFromJSFunction) { | 603 if (arch_opcode == kArchTailCallCodeObjectFromJSFunction) { |
588 AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, | 604 AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, |
589 i.TempRegister(0), i.TempRegister(1), | 605 i.TempRegister(0), i.TempRegister(1), |
590 i.TempRegister(2)); | 606 i.TempRegister(2)); |
591 } | 607 } |
592 if (instr->InputAt(0)->IsImmediate()) { | 608 if (instr->InputAt(0)->IsImmediate()) { |
593 __ Jump(Handle<Code>::cast(i.InputHeapObject(0)), | 609 __ Jump(Handle<Code>::cast(i.InputHeapObject(0)), |
594 RelocInfo::CODE_TARGET); | 610 RelocInfo::CODE_TARGET); |
595 } else { | 611 } else { |
596 __ addiu(at, i.InputRegister(0), Code::kHeaderSize - kHeapObjectTag); | 612 __ addiu(at, i.InputRegister(0), Code::kHeaderSize - kHeapObjectTag); |
597 __ Jump(at); | 613 __ Jump(at); |
598 } | 614 } |
599 frame_access_state()->ClearSPDelta(); | 615 frame_access_state()->ClearSPDelta(); |
| 616 frame_access_state()->SetFrameAccessToDefault(); |
600 break; | 617 break; |
601 } | 618 } |
602 case kArchTailCallAddress: { | 619 case kArchTailCallAddress: { |
603 int stack_param_delta = i.InputInt32(instr->InputCount() - 1); | |
604 AssembleDeconstructActivationRecord(stack_param_delta); | |
605 CHECK(!instr->InputAt(0)->IsImmediate()); | 620 CHECK(!instr->InputAt(0)->IsImmediate()); |
606 __ Jump(i.InputRegister(0)); | 621 __ Jump(i.InputRegister(0)); |
607 frame_access_state()->ClearSPDelta(); | 622 frame_access_state()->ClearSPDelta(); |
608 break; | 623 break; |
609 } | 624 } |
610 case kArchCallJSFunction: { | 625 case kArchCallJSFunction: { |
611 EnsureSpaceForLazyDeopt(); | 626 EnsureSpaceForLazyDeopt(); |
612 Register func = i.InputRegister(0); | 627 Register func = i.InputRegister(0); |
613 if (FLAG_debug_code) { | 628 if (FLAG_debug_code) { |
614 // Check the function's context matches the context argument. | 629 // Check the function's context matches the context argument. |
615 __ lw(kScratchReg, FieldMemOperand(func, JSFunction::kContextOffset)); | 630 __ lw(kScratchReg, FieldMemOperand(func, JSFunction::kContextOffset)); |
616 __ Assert(eq, kWrongFunctionContext, cp, Operand(kScratchReg)); | 631 __ Assert(eq, kWrongFunctionContext, cp, Operand(kScratchReg)); |
617 } | 632 } |
618 | 633 |
619 __ lw(at, FieldMemOperand(func, JSFunction::kCodeEntryOffset)); | 634 __ lw(at, FieldMemOperand(func, JSFunction::kCodeEntryOffset)); |
620 __ Call(at); | 635 __ Call(at); |
621 RecordCallPosition(instr); | 636 RecordCallPosition(instr); |
622 frame_access_state()->ClearSPDelta(); | 637 frame_access_state()->ClearSPDelta(); |
| 638 frame_access_state()->SetFrameAccessToDefault(); |
623 break; | 639 break; |
624 } | 640 } |
625 case kArchTailCallJSFunctionFromJSFunction: | 641 case kArchTailCallJSFunctionFromJSFunction: |
626 case kArchTailCallJSFunction: { | 642 case kArchTailCallJSFunction: { |
627 Register func = i.InputRegister(0); | 643 Register func = i.InputRegister(0); |
628 if (FLAG_debug_code) { | 644 if (FLAG_debug_code) { |
629 // Check the function's context matches the context argument. | 645 // Check the function's context matches the context argument. |
630 __ lw(kScratchReg, FieldMemOperand(func, JSFunction::kContextOffset)); | 646 __ lw(kScratchReg, FieldMemOperand(func, JSFunction::kContextOffset)); |
631 __ Assert(eq, kWrongFunctionContext, cp, Operand(kScratchReg)); | 647 __ Assert(eq, kWrongFunctionContext, cp, Operand(kScratchReg)); |
632 } | 648 } |
633 | 649 |
634 int stack_param_delta = i.InputInt32(instr->InputCount() - 1); | |
635 AssembleDeconstructActivationRecord(stack_param_delta); | |
636 if (arch_opcode == kArchTailCallJSFunctionFromJSFunction) { | 650 if (arch_opcode == kArchTailCallJSFunctionFromJSFunction) { |
637 AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, | 651 AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, |
638 i.TempRegister(0), i.TempRegister(1), | 652 i.TempRegister(0), i.TempRegister(1), |
639 i.TempRegister(2)); | 653 i.TempRegister(2)); |
640 } | 654 } |
641 __ lw(at, FieldMemOperand(func, JSFunction::kCodeEntryOffset)); | 655 __ lw(at, FieldMemOperand(func, JSFunction::kCodeEntryOffset)); |
642 __ Jump(at); | 656 __ Jump(at); |
643 frame_access_state()->ClearSPDelta(); | 657 frame_access_state()->ClearSPDelta(); |
| 658 frame_access_state()->SetFrameAccessToDefault(); |
644 break; | 659 break; |
645 } | 660 } |
646 case kArchPrepareCallCFunction: { | 661 case kArchPrepareCallCFunction: { |
647 int const num_parameters = MiscField::decode(instr->opcode()); | 662 int const num_parameters = MiscField::decode(instr->opcode()); |
648 __ PrepareCallCFunction(num_parameters, kScratchReg); | 663 __ PrepareCallCFunction(num_parameters, kScratchReg); |
649 // Frame alignment requires using FP-relative frame addressing. | 664 // Frame alignment requires using FP-relative frame addressing. |
650 frame_access_state()->SetFrameAccessToFP(); | 665 frame_access_state()->SetFrameAccessToFP(); |
651 break; | 666 break; |
652 } | 667 } |
653 case kArchPrepareTailCall: | 668 case kArchPrepareTailCall: |
654 AssemblePrepareTailCall(i.InputInt32(instr->InputCount() - 1)); | 669 AssemblePrepareTailCall(); |
655 break; | 670 break; |
656 case kArchCallCFunction: { | 671 case kArchCallCFunction: { |
657 int const num_parameters = MiscField::decode(instr->opcode()); | 672 int const num_parameters = MiscField::decode(instr->opcode()); |
658 if (instr->InputAt(0)->IsImmediate()) { | 673 if (instr->InputAt(0)->IsImmediate()) { |
659 ExternalReference ref = i.InputExternalReference(0); | 674 ExternalReference ref = i.InputExternalReference(0); |
660 __ CallCFunction(ref, num_parameters); | 675 __ CallCFunction(ref, num_parameters); |
661 } else { | 676 } else { |
662 Register func = i.InputRegister(0); | 677 Register func = i.InputRegister(0); |
663 __ CallCFunction(func, num_parameters); | 678 __ CallCFunction(func, num_parameters); |
664 } | 679 } |
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 padding_size -= v8::internal::Assembler::kInstrSize; | 2113 padding_size -= v8::internal::Assembler::kInstrSize; |
2099 } | 2114 } |
2100 } | 2115 } |
2101 } | 2116 } |
2102 | 2117 |
2103 #undef __ | 2118 #undef __ |
2104 | 2119 |
2105 } // namespace compiler | 2120 } // namespace compiler |
2106 } // namespace internal | 2121 } // namespace internal |
2107 } // namespace v8 | 2122 } // namespace v8 |
OLD | NEW |