@@ -374,8 +374,8 @@ struct CallBuffer {
374374// TODO(bmeurer): Get rid of the CallBuffer business and make
375375// InstructionSelector::VisitCall platform independent instead.
376376void InstructionSelector::InitializeCallBuffer (Node* call, CallBuffer* buffer,
377- bool call_code_immediate ,
378- bool call_address_immediate ) {
377+ CallBufferFlags flags ,
378+ int stack_param_delta ) {
379379 OperandGenerator g (this );
380380 DCHECK_LE (call->op ()->ValueOutputCount (),
381381 static_cast <int >(buffer->descriptor ->ReturnCount ()));
@@ -426,6 +426,8 @@ void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer,
426426
427427 // The first argument is always the callee code.
428428 Node* callee = call->InputAt (0 );
429+ bool call_code_immediate = (flags & kCallCodeImmediate ) != 0 ;
430+ bool call_address_immediate = (flags & kCallAddressImmediate ) != 0 ;
429431 switch (buffer->descriptor ->kind ()) {
430432 case CallDescriptor::kCallCodeObject :
431433 buffer->instruction_args .push_back (
@@ -478,14 +480,20 @@ void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer,
478480 // as an InstructionOperand argument to the call.
479481 auto iter (call->inputs ().begin ());
480482 size_t pushed_count = 0 ;
483+ bool call_tail = (flags & kCallTail ) != 0 ;
481484 for (size_t index = 0 ; index < input_count; ++iter, ++index) {
482485 DCHECK (iter != call->inputs ().end ());
483486 DCHECK ((*iter)->op ()->opcode () != IrOpcode::kFrameState );
484487 if (index == 0 ) continue ; // The first argument (callee) is already done.
488+
489+ LinkageLocation location = buffer->descriptor ->GetInputLocation (index);
490+ if (call_tail) {
491+ location = LinkageLocation::ConvertToTailCallerLocation (
492+ location, stack_param_delta);
493+ }
485494 InstructionOperand op =
486- g.UseLocation (*iter, buffer->descriptor ->GetInputLocation (index),
487- buffer->descriptor ->GetInputType (index));
488- if (UnallocatedOperand::cast (op).HasFixedSlotPolicy ()) {
495+ g.UseLocation (*iter, location, buffer->descriptor ->GetInputType (index));
496+ if (UnallocatedOperand::cast (op).HasFixedSlotPolicy () && !call_tail) {
489497 int stack_index = -UnallocatedOperand::cast (op).fixed_slot_index () - 1 ;
490498 if (static_cast <size_t >(stack_index) >= buffer->pushed_nodes .size ()) {
491499 buffer->pushed_nodes .resize (stack_index + 1 , NULL );
@@ -1173,7 +1181,8 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
11731181 // the code object in a register if there are multiple uses of it.
11741182 // Improve constant pool and the heuristics in the register allocator
11751183 // for where to emit constants.
1176- InitializeCallBuffer (node, &buffer, true , true );
1184+ CallBufferFlags call_buffer_flags (kCallCodeImmediate | kCallAddressImmediate );
1185+ InitializeCallBuffer (node, &buffer, call_buffer_flags);
11771186
11781187 EmitPrepareArguments (&(buffer.pushed_nodes ), descriptor, node);
11791188
@@ -1226,11 +1235,17 @@ void InstructionSelector::VisitTailCall(Node* node) {
12261235
12271236 // TODO(turbofan): Relax restriction for stack parameters.
12281237
1229- if (linkage ()->GetIncomingDescriptor ()->CanTailCall (node)) {
1238+ int stack_param_delta = 0 ;
1239+ if (linkage ()->GetIncomingDescriptor ()->CanTailCall (node,
1240+ &stack_param_delta)) {
12301241 CallBuffer buffer (zone (), descriptor, nullptr );
12311242
12321243 // Compute InstructionOperands for inputs and outputs.
1233- InitializeCallBuffer (node, &buffer, true , IsTailCallAddressImmediate ());
1244+ CallBufferFlags flags (kCallCodeImmediate | kCallTail );
1245+ if (IsTailCallAddressImmediate ()) {
1246+ flags |= kCallAddressImmediate ;
1247+ }
1248+ InitializeCallBuffer (node, &buffer, flags, stack_param_delta);
12341249
12351250 // Select the appropriate opcode based on the call type.
12361251 InstructionCode opcode;
@@ -1247,6 +1262,8 @@ void InstructionSelector::VisitTailCall(Node* node) {
12471262 }
12481263 opcode |= MiscField::encode (descriptor->flags ());
12491264
1265+ buffer.instruction_args .push_back (g.TempImmediate (stack_param_delta));
1266+
12501267 // Emit the tailcall instruction.
12511268 Emit (opcode, 0 , nullptr , buffer.instruction_args .size (),
12521269 &buffer.instruction_args .front ());
@@ -1260,7 +1277,11 @@ void InstructionSelector::VisitTailCall(Node* node) {
12601277 CallBuffer buffer (zone (), descriptor, frame_state_descriptor);
12611278
12621279 // Compute InstructionOperands for inputs and outputs.
1263- InitializeCallBuffer (node, &buffer, true , IsTailCallAddressImmediate ());
1280+ CallBufferFlags flags = kCallCodeImmediate ;
1281+ if (IsTailCallAddressImmediate ()) {
1282+ flags |= kCallAddressImmediate ;
1283+ }
1284+ InitializeCallBuffer (node, &buffer, flags);
12641285
12651286 EmitPrepareArguments (&(buffer.pushed_nodes ), descriptor, node);
12661287
0 commit comments