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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 __ Subu(sp, sp, Operand(-sp_slot_delta * kPointerSize)); | 482 __ Subu(sp, sp, Operand(-sp_slot_delta * kPointerSize)); |
483 frame_access_state()->IncreaseSPDelta(-sp_slot_delta); | 483 frame_access_state()->IncreaseSPDelta(-sp_slot_delta); |
484 } | 484 } |
485 if (frame()->needs_frame()) { | 485 if (frame()->needs_frame()) { |
486 __ lw(ra, MemOperand(fp, StandardFrameConstants::kCallerPCOffset)); | 486 __ lw(ra, MemOperand(fp, StandardFrameConstants::kCallerPCOffset)); |
487 __ lw(fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); | 487 __ lw(fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
488 } | 488 } |
489 frame_access_state()->SetFrameAccessToSP(); | 489 frame_access_state()->SetFrameAccessToSP(); |
490 } | 490 } |
491 | 491 |
| 492 void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg, |
| 493 Register scratch1, |
| 494 Register scratch2, |
| 495 Register scratch3) { |
| 496 DCHECK(!AreAliased(args_reg, scratch1, scratch2, scratch3)); |
| 497 Label done; |
| 498 |
| 499 // Check if current frame is an arguments adaptor frame. |
| 500 __ lw(scratch1, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 501 __ Branch(&done, ne, scratch1, |
| 502 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 503 |
| 504 // Load arguments count from current arguments adaptor frame (note, it |
| 505 // does not include receiver). |
| 506 Register caller_args_count_reg = scratch1; |
| 507 __ lw(caller_args_count_reg, |
| 508 MemOperand(fp, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 509 __ SmiUntag(caller_args_count_reg); |
| 510 |
| 511 ParameterCount callee_args_count(args_reg); |
| 512 __ PrepareForTailCall(callee_args_count, caller_args_count_reg, scratch2, |
| 513 scratch3); |
| 514 __ bind(&done); |
| 515 } |
492 | 516 |
493 // Assembles an instruction after register allocation, producing machine code. | 517 // Assembles an instruction after register allocation, producing machine code. |
494 void CodeGenerator::AssembleArchInstruction(Instruction* instr) { | 518 void CodeGenerator::AssembleArchInstruction(Instruction* instr) { |
495 MipsOperandConverter i(this, instr); | 519 MipsOperandConverter i(this, instr); |
496 InstructionCode opcode = instr->opcode(); | 520 InstructionCode opcode = instr->opcode(); |
497 | 521 ArchOpcode arch_opcode = ArchOpcodeField::decode(opcode); |
498 switch (ArchOpcodeField::decode(opcode)) { | 522 switch (arch_opcode) { |
499 case kArchCallCodeObject: { | 523 case kArchCallCodeObject: { |
500 EnsureSpaceForLazyDeopt(); | 524 EnsureSpaceForLazyDeopt(); |
501 if (instr->InputAt(0)->IsImmediate()) { | 525 if (instr->InputAt(0)->IsImmediate()) { |
502 __ Call(Handle<Code>::cast(i.InputHeapObject(0)), | 526 __ Call(Handle<Code>::cast(i.InputHeapObject(0)), |
503 RelocInfo::CODE_TARGET); | 527 RelocInfo::CODE_TARGET); |
504 } else { | 528 } else { |
505 __ addiu(at, i.InputRegister(0), Code::kHeaderSize - kHeapObjectTag); | 529 __ addiu(at, i.InputRegister(0), Code::kHeaderSize - kHeapObjectTag); |
506 __ Call(at); | 530 __ Call(at); |
507 } | 531 } |
508 RecordCallPosition(instr); | 532 RecordCallPosition(instr); |
509 frame_access_state()->ClearSPDelta(); | 533 frame_access_state()->ClearSPDelta(); |
510 break; | 534 break; |
511 } | 535 } |
| 536 case kArchTailCallCodeObjectFromJSFunction: |
512 case kArchTailCallCodeObject: { | 537 case kArchTailCallCodeObject: { |
513 int stack_param_delta = i.InputInt32(instr->InputCount() - 1); | 538 int stack_param_delta = i.InputInt32(instr->InputCount() - 1); |
514 AssembleDeconstructActivationRecord(stack_param_delta); | 539 AssembleDeconstructActivationRecord(stack_param_delta); |
| 540 if (arch_opcode == kArchTailCallCodeObjectFromJSFunction) { |
| 541 AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, |
| 542 i.TempRegister(0), i.TempRegister(1), |
| 543 i.TempRegister(2)); |
| 544 } |
515 if (instr->InputAt(0)->IsImmediate()) { | 545 if (instr->InputAt(0)->IsImmediate()) { |
516 __ Jump(Handle<Code>::cast(i.InputHeapObject(0)), | 546 __ Jump(Handle<Code>::cast(i.InputHeapObject(0)), |
517 RelocInfo::CODE_TARGET); | 547 RelocInfo::CODE_TARGET); |
518 } else { | 548 } else { |
519 __ addiu(at, i.InputRegister(0), Code::kHeaderSize - kHeapObjectTag); | 549 __ addiu(at, i.InputRegister(0), Code::kHeaderSize - kHeapObjectTag); |
520 __ Jump(at); | 550 __ Jump(at); |
521 } | 551 } |
522 frame_access_state()->ClearSPDelta(); | 552 frame_access_state()->ClearSPDelta(); |
523 break; | 553 break; |
524 } | 554 } |
525 case kArchCallJSFunction: { | 555 case kArchCallJSFunction: { |
526 EnsureSpaceForLazyDeopt(); | 556 EnsureSpaceForLazyDeopt(); |
527 Register func = i.InputRegister(0); | 557 Register func = i.InputRegister(0); |
528 if (FLAG_debug_code) { | 558 if (FLAG_debug_code) { |
529 // Check the function's context matches the context argument. | 559 // Check the function's context matches the context argument. |
530 __ lw(kScratchReg, FieldMemOperand(func, JSFunction::kContextOffset)); | 560 __ lw(kScratchReg, FieldMemOperand(func, JSFunction::kContextOffset)); |
531 __ Assert(eq, kWrongFunctionContext, cp, Operand(kScratchReg)); | 561 __ Assert(eq, kWrongFunctionContext, cp, Operand(kScratchReg)); |
532 } | 562 } |
533 | 563 |
534 __ lw(at, FieldMemOperand(func, JSFunction::kCodeEntryOffset)); | 564 __ lw(at, FieldMemOperand(func, JSFunction::kCodeEntryOffset)); |
535 __ Call(at); | 565 __ Call(at); |
536 RecordCallPosition(instr); | 566 RecordCallPosition(instr); |
537 frame_access_state()->ClearSPDelta(); | 567 frame_access_state()->ClearSPDelta(); |
538 break; | 568 break; |
539 } | 569 } |
| 570 case kArchTailCallJSFunctionFromJSFunction: |
540 case kArchTailCallJSFunction: { | 571 case kArchTailCallJSFunction: { |
541 Register func = i.InputRegister(0); | 572 Register func = i.InputRegister(0); |
542 if (FLAG_debug_code) { | 573 if (FLAG_debug_code) { |
543 // Check the function's context matches the context argument. | 574 // Check the function's context matches the context argument. |
544 __ lw(kScratchReg, FieldMemOperand(func, JSFunction::kContextOffset)); | 575 __ lw(kScratchReg, FieldMemOperand(func, JSFunction::kContextOffset)); |
545 __ Assert(eq, kWrongFunctionContext, cp, Operand(kScratchReg)); | 576 __ Assert(eq, kWrongFunctionContext, cp, Operand(kScratchReg)); |
546 } | 577 } |
547 | 578 |
548 int stack_param_delta = i.InputInt32(instr->InputCount() - 1); | 579 int stack_param_delta = i.InputInt32(instr->InputCount() - 1); |
549 AssembleDeconstructActivationRecord(stack_param_delta); | 580 AssembleDeconstructActivationRecord(stack_param_delta); |
| 581 if (arch_opcode == kArchTailCallJSFunctionFromJSFunction) { |
| 582 AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister, |
| 583 i.TempRegister(0), i.TempRegister(1), |
| 584 i.TempRegister(2)); |
| 585 } |
550 __ lw(at, FieldMemOperand(func, JSFunction::kCodeEntryOffset)); | 586 __ lw(at, FieldMemOperand(func, JSFunction::kCodeEntryOffset)); |
551 __ Jump(at); | 587 __ Jump(at); |
552 frame_access_state()->ClearSPDelta(); | 588 frame_access_state()->ClearSPDelta(); |
553 break; | 589 break; |
554 } | 590 } |
555 case kArchPrepareCallCFunction: { | 591 case kArchPrepareCallCFunction: { |
556 int const num_parameters = MiscField::decode(instr->opcode()); | 592 int const num_parameters = MiscField::decode(instr->opcode()); |
557 __ PrepareCallCFunction(num_parameters, kScratchReg); | 593 __ PrepareCallCFunction(num_parameters, kScratchReg); |
558 // Frame alignment requires using FP-relative frame addressing. | 594 // Frame alignment requires using FP-relative frame addressing. |
559 frame_access_state()->SetFrameAccessToFP(); | 595 frame_access_state()->SetFrameAccessToFP(); |
(...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1824 padding_size -= v8::internal::Assembler::kInstrSize; | 1860 padding_size -= v8::internal::Assembler::kInstrSize; |
1825 } | 1861 } |
1826 } | 1862 } |
1827 } | 1863 } |
1828 | 1864 |
1829 #undef __ | 1865 #undef __ |
1830 | 1866 |
1831 } // namespace compiler | 1867 } // namespace compiler |
1832 } // namespace internal | 1868 } // namespace internal |
1833 } // namespace v8 | 1869 } // namespace v8 |
OLD | NEW |