blob: 5e217b0ac5cd275882fc665680da93b7ce2cb305 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
3// found in the LICENSE file.
4
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005#include "src/ast/scopes.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006#include "src/code-stubs.h"
7#include "src/compiler.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/compiler/common-operator.h"
9#include "src/compiler/frame.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010#include "src/compiler/linkage.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/compiler/node.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012#include "src/compiler/osr.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013#include "src/compiler/pipeline.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000014
15namespace v8 {
16namespace internal {
17namespace compiler {
18
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019namespace {
20LinkageLocation regloc(Register reg) {
21 return LinkageLocation::ForRegister(reg.code());
22}
23
24
25MachineType reptyp(Representation representation) {
26 switch (representation.kind()) {
27 case Representation::kInteger8:
28 return MachineType::Int8();
29 case Representation::kUInteger8:
30 return MachineType::Uint8();
31 case Representation::kInteger16:
32 return MachineType::Int16();
33 case Representation::kUInteger16:
34 return MachineType::Uint16();
35 case Representation::kInteger32:
36 return MachineType::Int32();
37 case Representation::kSmi:
38 case Representation::kTagged:
39 case Representation::kHeapObject:
40 return MachineType::AnyTagged();
41 case Representation::kDouble:
42 return MachineType::Float64();
43 case Representation::kExternal:
44 return MachineType::Pointer();
45 case Representation::kNone:
46 case Representation::kNumRepresentations:
47 break;
48 }
49 UNREACHABLE();
50 return MachineType::None();
51}
52} // namespace
53
Ben Murdochb8a8cc12014-11-26 15:28:44 +000054
Emily Bernierd0a1eb72015-03-24 16:35:39 -040055std::ostream& operator<<(std::ostream& os, const CallDescriptor::Kind& k) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056 switch (k) {
57 case CallDescriptor::kCallCodeObject:
58 os << "Code";
59 break;
60 case CallDescriptor::kCallJSFunction:
61 os << "JS";
62 break;
63 case CallDescriptor::kCallAddress:
64 os << "Addr";
65 break;
66 }
67 return os;
68}
69
70
Emily Bernierd0a1eb72015-03-24 16:35:39 -040071std::ostream& operator<<(std::ostream& os, const CallDescriptor& d) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072 // TODO(svenpanne) Output properties etc. and be less cryptic.
73 return os << d.kind() << ":" << d.debug_name() << ":r" << d.ReturnCount()
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000074 << "s" << d.StackParameterCount() << "i" << d.InputCount() << "f"
75 << d.FrameStateCount() << "t" << d.SupportsTailCalls();
76}
77
78
79bool CallDescriptor::HasSameReturnLocationsAs(
80 const CallDescriptor* other) const {
81 if (ReturnCount() != other->ReturnCount()) return false;
82 for (size_t i = 0; i < ReturnCount(); ++i) {
83 if (GetReturnLocation(i) != other->GetReturnLocation(i)) return false;
84 }
85 return true;
86}
87
88
89bool CallDescriptor::CanTailCall(const Node* node,
90 int* stack_param_delta) const {
Ben Murdochc5610432016-08-08 18:44:38 +010091 CallDescriptor const* other = CallDescriptorOf(node->op());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000092 size_t current_input = 0;
93 size_t other_input = 0;
94 *stack_param_delta = 0;
95 bool more_other = true;
96 bool more_this = true;
97 while (more_other || more_this) {
98 if (other_input < other->InputCount()) {
99 if (!other->GetInputLocation(other_input).IsRegister()) {
100 (*stack_param_delta)--;
101 }
102 } else {
103 more_other = false;
104 }
105 if (current_input < InputCount()) {
106 if (!GetInputLocation(current_input).IsRegister()) {
107 (*stack_param_delta)++;
108 }
109 } else {
110 more_this = false;
111 }
112 ++current_input;
113 ++other_input;
114 }
Ben Murdochc5610432016-08-08 18:44:38 +0100115 return HasSameReturnLocationsAs(CallDescriptorOf(node->op()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000116}
117
118
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400119CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100120 DCHECK(!info->IsStub());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400121 if (!info->closure().is_null()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000122 // If we are compiling a JS function, use a JS call descriptor,
123 // plus the receiver.
124 SharedFunctionInfo* shared = info->closure()->shared();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000125 return GetJSCallDescriptor(zone, info->is_osr(),
126 1 + shared->internal_formal_parameter_count(),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400127 CallDescriptor::kNoFlags);
128 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000129 return nullptr; // TODO(titzer): ?
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000130}
131
132
133// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000134int Linkage::FrameStateInputCount(Runtime::FunctionId function) {
135 // Most runtime functions need a FrameState. A few chosen ones that we know
136 // not to call into arbitrary JavaScript, not to throw, and not to deoptimize
137 // are blacklisted here and can be called without a FrameState.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000138 switch (function) {
Ben Murdochc5610432016-08-08 18:44:38 +0100139 case Runtime::kAbort:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000140 case Runtime::kAllocateInTargetSpace:
141 case Runtime::kCreateIterResultObject:
Ben Murdoch097c5b22016-05-18 11:27:45 +0100142 case Runtime::kDefineDataPropertyInLiteral:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000143 case Runtime::kDefineGetterPropertyUnchecked: // TODO(jarin): Is it safe?
144 case Runtime::kDefineSetterPropertyUnchecked: // TODO(jarin): Is it safe?
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000145 case Runtime::kForInDone:
146 case Runtime::kForInStep:
Ben Murdochc5610432016-08-08 18:44:38 +0100147 case Runtime::kGeneratorSetContext:
148 case Runtime::kGeneratorGetContinuation:
149 case Runtime::kGeneratorSetContinuation:
150 case Runtime::kGeneratorLoadRegister:
151 case Runtime::kGeneratorStoreRegister:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000152 case Runtime::kGetSuperConstructor:
Ben Murdoch097c5b22016-05-18 11:27:45 +0100153 case Runtime::kIsFunction:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000154 case Runtime::kNewClosure:
155 case Runtime::kNewClosure_Tenured:
156 case Runtime::kNewFunctionContext:
157 case Runtime::kPushBlockContext:
158 case Runtime::kPushCatchContext:
159 case Runtime::kReThrow:
160 case Runtime::kStringCompare:
Ben Murdochda12d292016-06-02 14:46:10 +0100161 case Runtime::kStringEqual:
162 case Runtime::kStringNotEqual:
163 case Runtime::kStringLessThan:
164 case Runtime::kStringLessThanOrEqual:
165 case Runtime::kStringGreaterThan:
166 case Runtime::kStringGreaterThanOrEqual:
Ben Murdochc5610432016-08-08 18:44:38 +0100167 case Runtime::kToFastProperties: // TODO(conradw): Is it safe?
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000168 case Runtime::kTraceEnter:
169 case Runtime::kTraceExit:
170 return 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000171 case Runtime::kInlineGetPrototype:
Ben Murdochda12d292016-06-02 14:46:10 +0100172 case Runtime::kInlineNewObject:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000173 case Runtime::kInlineRegExpConstructResult:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400174 case Runtime::kInlineRegExpExec:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000175 case Runtime::kInlineSubString:
176 case Runtime::kInlineToInteger:
177 case Runtime::kInlineToLength:
178 case Runtime::kInlineToName:
179 case Runtime::kInlineToNumber:
180 case Runtime::kInlineToObject:
Ben Murdochda12d292016-06-02 14:46:10 +0100181 case Runtime::kInlineToPrimitive:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000182 case Runtime::kInlineToPrimitive_Number:
183 case Runtime::kInlineToPrimitive_String:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000184 case Runtime::kInlineToString:
185 return 1;
186 case Runtime::kInlineCall:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000187 case Runtime::kInlineDeoptimizeNow:
188 case Runtime::kInlineThrowNotDateError:
189 return 2;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000190 default:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000191 break;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000192 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000193
194 // Most inlined runtime functions (except the ones listed above) can be called
195 // without a FrameState or will be lowered by JSIntrinsicLowering internally.
196 const Runtime::Function* const f = Runtime::FunctionForId(function);
197 if (f->intrinsic_type == Runtime::IntrinsicType::INLINE) return 0;
198
199 return 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000200}
201
202
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000203bool CallDescriptor::UsesOnlyRegisters() const {
204 for (size_t i = 0; i < InputCount(); ++i) {
205 if (!GetInputLocation(i).IsRegister()) return false;
206 }
207 for (size_t i = 0; i < ReturnCount(); ++i) {
208 if (!GetReturnLocation(i).IsRegister()) return false;
209 }
210 return true;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000211}
212
213
214CallDescriptor* Linkage::GetRuntimeCallDescriptor(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000215 Zone* zone, Runtime::FunctionId function_id, int js_parameter_count,
216 Operator::Properties properties, CallDescriptor::Flags flags) {
217 const size_t function_count = 1;
218 const size_t num_args_count = 1;
219 const size_t context_count = 1;
220 const size_t parameter_count = function_count +
221 static_cast<size_t>(js_parameter_count) +
222 num_args_count + context_count;
223
224 const Runtime::Function* function = Runtime::FunctionForId(function_id);
225 const size_t return_count = static_cast<size_t>(function->result_size);
226
227 LocationSignature::Builder locations(zone, return_count, parameter_count);
228 MachineSignature::Builder types(zone, return_count, parameter_count);
229
230 // Add returns.
231 if (locations.return_count_ > 0) {
232 locations.AddReturn(regloc(kReturnRegister0));
233 }
234 if (locations.return_count_ > 1) {
235 locations.AddReturn(regloc(kReturnRegister1));
236 }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100237 if (locations.return_count_ > 2) {
238 locations.AddReturn(regloc(kReturnRegister2));
239 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000240 for (size_t i = 0; i < return_count; i++) {
241 types.AddReturn(MachineType::AnyTagged());
242 }
243
244 // All parameters to the runtime call go on the stack.
245 for (int i = 0; i < js_parameter_count; i++) {
246 locations.AddParam(
247 LinkageLocation::ForCallerFrameSlot(i - js_parameter_count));
248 types.AddParam(MachineType::AnyTagged());
249 }
250 // Add runtime function itself.
251 locations.AddParam(regloc(kRuntimeCallFunctionRegister));
252 types.AddParam(MachineType::AnyTagged());
253
254 // Add runtime call argument count.
255 locations.AddParam(regloc(kRuntimeCallArgCountRegister));
256 types.AddParam(MachineType::Pointer());
257
258 // Add context.
259 locations.AddParam(regloc(kContextRegister));
260 types.AddParam(MachineType::AnyTagged());
261
262 if (Linkage::FrameStateInputCount(function_id) == 0) {
263 flags = static_cast<CallDescriptor::Flags>(
264 flags & ~CallDescriptor::kNeedsFrameState);
265 }
266
267 // The target for runtime calls is a code object.
268 MachineType target_type = MachineType::AnyTagged();
269 LinkageLocation target_loc = LinkageLocation::ForAnyRegister();
270 return new (zone) CallDescriptor( // --
271 CallDescriptor::kCallCodeObject, // kind
272 target_type, // target MachineType
273 target_loc, // target location
274 types.Build(), // machine_sig
275 locations.Build(), // location_sig
276 js_parameter_count, // stack_parameter_count
277 properties, // properties
278 kNoCalleeSaved, // callee-saved
279 kNoCalleeSaved, // callee-saved fp
280 flags, // flags
281 function->name); // debug name
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000282}
283
284
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000285CallDescriptor* Linkage::GetJSCallDescriptor(Zone* zone, bool is_osr,
286 int js_parameter_count,
287 CallDescriptor::Flags flags) {
288 const size_t return_count = 1;
289 const size_t context_count = 1;
290 const size_t new_target_count = 1;
291 const size_t num_args_count = 1;
292 const size_t parameter_count =
293 js_parameter_count + new_target_count + num_args_count + context_count;
294
295 LocationSignature::Builder locations(zone, return_count, parameter_count);
296 MachineSignature::Builder types(zone, return_count, parameter_count);
297
298 // All JS calls have exactly one return value.
299 locations.AddReturn(regloc(kReturnRegister0));
300 types.AddReturn(MachineType::AnyTagged());
301
302 // All parameters to JS calls go on the stack.
303 for (int i = 0; i < js_parameter_count; i++) {
304 int spill_slot_index = i - js_parameter_count;
305 locations.AddParam(LinkageLocation::ForCallerFrameSlot(spill_slot_index));
306 types.AddParam(MachineType::AnyTagged());
307 }
308
309 // Add JavaScript call new target value.
310 locations.AddParam(regloc(kJavaScriptCallNewTargetRegister));
311 types.AddParam(MachineType::AnyTagged());
312
313 // Add JavaScript call argument count.
314 locations.AddParam(regloc(kJavaScriptCallArgCountRegister));
315 types.AddParam(MachineType::Int32());
316
317 // Add context.
318 locations.AddParam(regloc(kContextRegister));
319 types.AddParam(MachineType::AnyTagged());
320
321 // The target for JS function calls is the JSFunction object.
322 MachineType target_type = MachineType::AnyTagged();
Ben Murdoch097c5b22016-05-18 11:27:45 +0100323 // When entering into an OSR function from unoptimized code the JSFunction
324 // is not in a register, but it is on the stack in the marker spill slot.
Ben Murdochda12d292016-06-02 14:46:10 +0100325 LinkageLocation target_loc = is_osr
326 ? LinkageLocation::ForSavedCallerFunction()
327 : regloc(kJSFunctionRegister);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000328 return new (zone) CallDescriptor( // --
329 CallDescriptor::kCallJSFunction, // kind
330 target_type, // target MachineType
331 target_loc, // target location
332 types.Build(), // machine_sig
333 locations.Build(), // location_sig
334 js_parameter_count, // stack_parameter_count
335 Operator::kNoProperties, // properties
336 kNoCalleeSaved, // callee-saved
337 kNoCalleeSaved, // callee-saved fp
338 CallDescriptor::kCanUseRoots | // flags
339 flags, // flags
340 "js-call");
341}
342
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000343// TODO(all): Add support for return representations/locations to
344// CallInterfaceDescriptor.
345// TODO(turbofan): cache call descriptors for code stub calls.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000346CallDescriptor* Linkage::GetStubCallDescriptor(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000347 Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor,
348 int stack_parameter_count, CallDescriptor::Flags flags,
349 Operator::Properties properties, MachineType return_type,
350 size_t return_count) {
351 const int register_parameter_count = descriptor.GetRegisterParameterCount();
352 const int js_parameter_count =
353 register_parameter_count + stack_parameter_count;
354 const int context_count = 1;
355 const size_t parameter_count =
356 static_cast<size_t>(js_parameter_count + context_count);
357
358 LocationSignature::Builder locations(zone, return_count, parameter_count);
359 MachineSignature::Builder types(zone, return_count, parameter_count);
360
361 // Add returns.
362 if (locations.return_count_ > 0) {
363 locations.AddReturn(regloc(kReturnRegister0));
364 }
365 if (locations.return_count_ > 1) {
366 locations.AddReturn(regloc(kReturnRegister1));
367 }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100368 if (locations.return_count_ > 2) {
369 locations.AddReturn(regloc(kReturnRegister2));
370 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000371 for (size_t i = 0; i < return_count; i++) {
372 types.AddReturn(return_type);
373 }
374
375 // Add parameters in registers and on the stack.
376 for (int i = 0; i < js_parameter_count; i++) {
377 if (i < register_parameter_count) {
378 // The first parameters go in registers.
379 Register reg = descriptor.GetRegisterParameter(i);
380 Representation rep =
381 RepresentationFromType(descriptor.GetParameterType(i));
382 locations.AddParam(regloc(reg));
383 types.AddParam(reptyp(rep));
384 } else {
385 // The rest of the parameters go on the stack.
386 int stack_slot = i - register_parameter_count - stack_parameter_count;
387 locations.AddParam(LinkageLocation::ForCallerFrameSlot(stack_slot));
388 types.AddParam(MachineType::AnyTagged());
389 }
390 }
391 // Add context.
392 locations.AddParam(regloc(kContextRegister));
393 types.AddParam(MachineType::AnyTagged());
394
395 // The target for stub calls is a code object.
396 MachineType target_type = MachineType::AnyTagged();
397 LinkageLocation target_loc = LinkageLocation::ForAnyRegister();
398 return new (zone) CallDescriptor( // --
399 CallDescriptor::kCallCodeObject, // kind
400 target_type, // target MachineType
401 target_loc, // target location
402 types.Build(), // machine_sig
403 locations.Build(), // location_sig
404 stack_parameter_count, // stack_parameter_count
405 properties, // properties
406 kNoCalleeSaved, // callee-saved registers
407 kNoCalleeSaved, // callee-saved fp
Ben Murdochda12d292016-06-02 14:46:10 +0100408 CallDescriptor::kCanUseRoots | // flags
409 flags, // flags
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000410 descriptor.DebugName(isolate));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000411}
412
Ben Murdochc5610432016-08-08 18:44:38 +0100413// static
414CallDescriptor* Linkage::GetAllocateCallDescriptor(Zone* zone) {
415 LocationSignature::Builder locations(zone, 1, 1);
416 MachineSignature::Builder types(zone, 1, 1);
417
418 locations.AddParam(regloc(kAllocateSizeRegister));
419 types.AddParam(MachineType::Int32());
420
421 locations.AddReturn(regloc(kReturnRegister0));
422 types.AddReturn(MachineType::AnyTagged());
423
424 // The target for allocate calls is a code object.
425 MachineType target_type = MachineType::AnyTagged();
426 LinkageLocation target_loc = LinkageLocation::ForAnyRegister();
427 return new (zone) CallDescriptor( // --
428 CallDescriptor::kCallCodeObject, // kind
429 target_type, // target MachineType
430 target_loc, // target location
431 types.Build(), // machine_sig
432 locations.Build(), // location_sig
433 0, // stack_parameter_count
434 Operator::kNoThrow, // properties
435 kNoCalleeSaved, // callee-saved registers
436 kNoCalleeSaved, // callee-saved fp
437 CallDescriptor::kCanUseRoots, // flags
438 "Allocate");
439}
440
441// static
442CallDescriptor* Linkage::GetBytecodeDispatchCallDescriptor(
443 Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor,
444 int stack_parameter_count) {
445 const int register_parameter_count = descriptor.GetRegisterParameterCount();
446 const int parameter_count = register_parameter_count + stack_parameter_count;
447
448 LocationSignature::Builder locations(zone, 0, parameter_count);
449 MachineSignature::Builder types(zone, 0, parameter_count);
450
451 // Add parameters in registers and on the stack.
452 for (int i = 0; i < parameter_count; i++) {
453 if (i < register_parameter_count) {
454 // The first parameters go in registers.
455 Register reg = descriptor.GetRegisterParameter(i);
456 Representation rep =
457 RepresentationFromType(descriptor.GetParameterType(i));
458 locations.AddParam(regloc(reg));
459 types.AddParam(reptyp(rep));
460 } else {
461 // The rest of the parameters go on the stack.
462 int stack_slot = i - register_parameter_count - stack_parameter_count;
463 locations.AddParam(LinkageLocation::ForCallerFrameSlot(stack_slot));
464 types.AddParam(MachineType::AnyTagged());
465 }
466 }
467
468 // The target for interpreter dispatches is a code entry address.
469 MachineType target_type = MachineType::Pointer();
470 LinkageLocation target_loc = LinkageLocation::ForAnyRegister();
471 return new (zone) CallDescriptor( // --
472 CallDescriptor::kCallAddress, // kind
473 target_type, // target MachineType
474 target_loc, // target location
475 types.Build(), // machine_sig
476 locations.Build(), // location_sig
477 stack_parameter_count, // stack_parameter_count
478 Operator::kNoProperties, // properties
479 kNoCalleeSaved, // callee-saved registers
480 kNoCalleeSaved, // callee-saved fp
481 CallDescriptor::kCanUseRoots | // flags
482 CallDescriptor::kSupportsTailCalls, // flags
483 descriptor.DebugName(isolate));
484}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000485
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000486LinkageLocation Linkage::GetOsrValueLocation(int index) const {
487 CHECK(incoming_->IsJSFunctionCall());
488 int parameter_count = static_cast<int>(incoming_->JSParameterCount() - 1);
489 int first_stack_slot = OsrHelper::FirstStackSlotIndex(parameter_count);
490
491 if (index == kOsrContextSpillSlotIndex) {
492 // Context. Use the parameter location of the context spill slot.
493 // Parameter (arity + 2) is special for the context of the function frame.
494 // >> context_index = target + receiver + params + new_target + #args
495 int context_index = 1 + 1 + parameter_count + 1 + 1;
496 return incoming_->GetInputLocation(context_index);
497 } else if (index >= first_stack_slot) {
498 // Local variable stored in this (callee) stack.
499 int spill_index =
500 index - first_stack_slot + StandardFrameConstants::kFixedSlotCount;
501 return LinkageLocation::ForCalleeFrameSlot(spill_index);
502 } else {
503 // Parameter. Use the assigned location from the incoming call descriptor.
504 int parameter_index = 1 + index; // skip index 0, which is the target.
505 return incoming_->GetInputLocation(parameter_index);
506 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000507}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000508
509
510bool Linkage::ParameterHasSecondaryLocation(int index) const {
Ben Murdochda12d292016-06-02 14:46:10 +0100511 if (!incoming_->IsJSFunctionCall()) return false;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000512 LinkageLocation loc = GetParameterLocation(index);
513 return (loc == regloc(kJSFunctionRegister) ||
514 loc == regloc(kContextRegister));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000515}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000516
517LinkageLocation Linkage::GetParameterSecondaryLocation(int index) const {
518 DCHECK(ParameterHasSecondaryLocation(index));
519 LinkageLocation loc = GetParameterLocation(index);
520
521 if (loc == regloc(kJSFunctionRegister)) {
522 return LinkageLocation::ForCalleeFrameSlot(Frame::kJSFunctionSlot);
523 } else {
524 DCHECK(loc == regloc(kContextRegister));
525 return LinkageLocation::ForCalleeFrameSlot(Frame::kContextSlot);
526 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000527}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000528
529
530} // namespace compiler
531} // namespace internal
532} // namespace v8