Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/x64/macro-assembler-x64.cc

Issue 1760253003: [crankshaft] Support ES6 tail call elimination. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@tco-crank-2
Patch Set: Addressing comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/x64/macro-assembler-x64.h ('k') | test/mjsunit/es6/tail-call.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base/bits.h" 7 #include "src/base/bits.h"
8 #include "src/base/division-by-constant.h" 8 #include "src/base/division-by-constant.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 4076 matching lines...) Expand 10 before | Expand all | Expand 10 after
4087 4087
4088 void MacroAssembler::DebugBreak() { 4088 void MacroAssembler::DebugBreak() {
4089 Set(rax, 0); // No arguments. 4089 Set(rax, 0); // No arguments.
4090 LoadAddress(rbx, 4090 LoadAddress(rbx,
4091 ExternalReference(Runtime::kHandleDebuggerStatement, isolate())); 4091 ExternalReference(Runtime::kHandleDebuggerStatement, isolate()));
4092 CEntryStub ces(isolate(), 1); 4092 CEntryStub ces(isolate(), 1);
4093 DCHECK(AllowThisStubCall(&ces)); 4093 DCHECK(AllowThisStubCall(&ces));
4094 Call(ces.GetCode(), RelocInfo::DEBUGGER_STATEMENT); 4094 Call(ces.GetCode(), RelocInfo::DEBUGGER_STATEMENT);
4095 } 4095 }
4096 4096
4097 void MacroAssembler::PrepareForTailCall(const ParameterCount& callee_args_count,
4098 Register caller_args_count_reg,
4099 Register scratch0, Register scratch1,
4100 ReturnAddressState ra_state) {
4101 #if DEBUG
4102 if (callee_args_count.is_reg()) {
4103 DCHECK(!AreAliased(callee_args_count.reg(), caller_args_count_reg, scratch0,
4104 scratch1));
4105 } else {
4106 DCHECK(!AreAliased(caller_args_count_reg, scratch0, scratch1));
4107 }
4108 #endif
4109
4110 // Calculate the destination address where we will put the return address
4111 // after we drop current frame.
4112 Register new_sp_reg = scratch0;
4113 if (callee_args_count.is_reg()) {
4114 subp(caller_args_count_reg, callee_args_count.reg());
4115 leap(new_sp_reg, Operand(rbp, caller_args_count_reg, times_pointer_size,
4116 StandardFrameConstants::kCallerPCOffset));
4117 } else {
4118 leap(new_sp_reg, Operand(rbp, caller_args_count_reg, times_pointer_size,
4119 StandardFrameConstants::kCallerPCOffset -
4120 callee_args_count.immediate() * kPointerSize));
4121 }
4122
4123 if (FLAG_debug_code) {
4124 cmpp(rsp, new_sp_reg);
4125 Check(below, kStackAccessBelowStackPointer);
4126 }
4127
4128 // Copy return address from caller's frame to current frame's return address
4129 // to avoid its trashing and let the following loop copy it to the right
4130 // place.
4131 Register tmp_reg = scratch1;
4132 if (ra_state == ReturnAddressState::kOnStack) {
4133 movp(tmp_reg, Operand(rbp, StandardFrameConstants::kCallerPCOffset));
4134 movp(Operand(rsp, 0), tmp_reg);
4135 } else {
4136 DCHECK(ReturnAddressState::kNotOnStack == ra_state);
4137 Push(Operand(rbp, StandardFrameConstants::kCallerPCOffset));
4138 }
4139
4140 // Restore caller's frame pointer now as it could be overwritten by
4141 // the copying loop.
4142 movp(rbp, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
4143
4144 // +2 here is to copy both receiver and return address.
4145 Register count_reg = caller_args_count_reg;
4146 if (callee_args_count.is_reg()) {
4147 leap(count_reg, Operand(callee_args_count.reg(), 2));
4148 } else {
4149 movp(count_reg, Immediate(callee_args_count.immediate() + 2));
4150 // TODO(ishell): Unroll copying loop for small immediate values.
4151 }
4152
4153 // Now copy callee arguments to the caller frame going backwards to avoid
4154 // callee arguments corruption (source and destination areas could overlap).
4155 Label loop, entry;
4156 jmp(&entry, Label::kNear);
4157 bind(&loop);
4158 decp(count_reg);
4159 movp(tmp_reg, Operand(rsp, count_reg, times_pointer_size, 0));
4160 movp(Operand(new_sp_reg, count_reg, times_pointer_size, 0), tmp_reg);
4161 bind(&entry);
4162 cmpp(count_reg, Immediate(0));
4163 j(not_equal, &loop, Label::kNear);
4164
4165 // Leave current frame.
4166 movp(rsp, new_sp_reg);
4167 }
4097 4168
4098 void MacroAssembler::InvokeFunction(Register function, 4169 void MacroAssembler::InvokeFunction(Register function,
4099 Register new_target, 4170 Register new_target,
4100 const ParameterCount& actual, 4171 const ParameterCount& actual,
4101 InvokeFlag flag, 4172 InvokeFlag flag,
4102 const CallWrapper& call_wrapper) { 4173 const CallWrapper& call_wrapper) {
4103 movp(rbx, FieldOperand(function, JSFunction::kSharedFunctionInfoOffset)); 4174 movp(rbx, FieldOperand(function, JSFunction::kSharedFunctionInfoOffset));
4104 LoadSharedFunctionInfoSpecialField( 4175 LoadSharedFunctionInfoSpecialField(
4105 rbx, rbx, SharedFunctionInfo::kFormalParameterCountOffset); 4176 rbx, rbx, SharedFunctionInfo::kFormalParameterCountOffset);
4106 4177
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
5579 movl(rax, dividend); 5650 movl(rax, dividend);
5580 shrl(rax, Immediate(31)); 5651 shrl(rax, Immediate(31));
5581 addl(rdx, rax); 5652 addl(rdx, rax);
5582 } 5653 }
5583 5654
5584 5655
5585 } // namespace internal 5656 } // namespace internal
5586 } // namespace v8 5657 } // namespace v8
5587 5658
5588 #endif // V8_TARGET_ARCH_X64 5659 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/macro-assembler-x64.h ('k') | test/mjsunit/es6/tail-call.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698