1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
|
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/linkage.h"
#include "src/codegen/assembler-inl.h"
#include "src/codegen/macro-assembler.h"
#include "src/codegen/optimized-compilation-info.h"
#include "src/compiler/frame.h"
#include "src/compiler/osr.h"
#include "src/compiler/pipeline.h"
namespace v8 {
namespace internal {
namespace compiler {
namespace {
// Offsets from callee to caller frame, in slots.
constexpr int kFirstCallerSlotOffset = 1;
constexpr int kNoCallerSlotOffset = 0;
inline LinkageLocation regloc(Register reg, MachineType type) {
return LinkageLocation::ForRegister(reg.code(), type);
}
inline LinkageLocation regloc(DoubleRegister reg, MachineType type) {
return LinkageLocation::ForRegister(reg.code(), type);
}
} // namespace
std::ostream& operator<<(std::ostream& os, const CallDescriptor::Kind& k) {
switch (k) {
case CallDescriptor::kCallCodeObject:
os << "Code";
break;
case CallDescriptor::kCallJSFunction:
os << "JS";
break;
case CallDescriptor::kCallAddress:
os << "Addr";
break;
#if V8_ENABLE_WEBASSEMBLY
case CallDescriptor::kCallWasmCapiFunction:
os << "WasmExit";
break;
case CallDescriptor::kCallWasmFunction:
os << "WasmFunction";
break;
case CallDescriptor::kCallWasmImportWrapper:
os << "WasmImportWrapper";
break;
#endif // V8_ENABLE_WEBASSEMBLY
case CallDescriptor::kCallBuiltinPointer:
os << "BuiltinPointer";
break;
}
return os;
}
std::ostream& operator<<(std::ostream& os, const CallDescriptor& d) {
// TODO(svenpanne) Output properties etc. and be less cryptic.
return os << d.kind() << ":" << d.debug_name() << ":r" << d.ReturnCount()
<< "s" << d.ParameterSlotCount() << "i" << d.InputCount() << "f"
<< d.FrameStateCount();
}
MachineSignature* CallDescriptor::GetMachineSignature(Zone* zone) const {
size_t param_count = ParameterCount();
size_t return_count = ReturnCount();
MachineType* types = zone->NewArray<MachineType>(param_count + return_count);
int current = 0;
for (size_t i = 0; i < return_count; ++i) {
types[current++] = GetReturnType(i);
}
for (size_t i = 0; i < param_count; ++i) {
types[current++] = GetParameterType(i);
}
return zone->New<MachineSignature>(return_count, param_count, types);
}
int CallDescriptor::GetStackParameterDelta(
CallDescriptor const* tail_caller) const {
// In the IsTailCallForTierUp case, the callee has
// identical linkage and runtime arguments to the caller, thus the stack
// parameter delta is 0. We don't explicitly pass the runtime arguments as
// inputs to the TailCall node, since they already exist on the stack.
if (IsTailCallForTierUp()) return 0;
// Add padding if necessary before computing the stack parameter delta.
int callee_slots_above_sp = AddArgumentPaddingSlots(GetOffsetToReturns());
int tail_caller_slots_above_sp =
AddArgumentPaddingSlots(tail_caller->GetOffsetToReturns());
int stack_param_delta = callee_slots_above_sp - tail_caller_slots_above_sp;
DCHECK(!ShouldPadArguments(stack_param_delta));
return stack_param_delta;
}
int CallDescriptor::GetOffsetToFirstUnusedStackSlot() const {
int offset = kFirstCallerSlotOffset;
for (size_t i = 0; i < InputCount(); ++i) {
LinkageLocation operand = GetInputLocation(i);
if (!operand.IsRegister()) {
DCHECK(operand.IsCallerFrameSlot());
int slot_offset = -operand.GetLocation();
offset = std::max(offset, slot_offset + operand.GetSizeInPointers());
}
}
return offset;
}
int CallDescriptor::GetOffsetToReturns() const {
// Find the return slot with the least offset relative to the callee.
int offset = kNoCallerSlotOffset;
for (size_t i = 0; i < ReturnCount(); ++i) {
LinkageLocation operand = GetReturnLocation(i);
if (!operand.IsRegister()) {
DCHECK(operand.IsCallerFrameSlot());
int slot_offset = -operand.GetLocation();
offset = std::min(offset, slot_offset);
}
}
// If there was a return slot, return the offset minus 1 slot.
if (offset != kNoCallerSlotOffset) {
return offset - 1;
}
// Otherwise, return the first slot after the parameters area, including
// optional padding slots.
int last_argument_slot = GetOffsetToFirstUnusedStackSlot() - 1;
offset = AddArgumentPaddingSlots(last_argument_slot);
DCHECK_IMPLIES(offset == 0, ParameterSlotCount() == 0);
return offset;
}
uint32_t CallDescriptor::GetTaggedParameterSlots() const {
uint32_t count = 0;
uint32_t first_offset = kMaxInt;
for (size_t i = 0; i < InputCount(); ++i) {
LinkageLocation operand = GetInputLocation(i);
if (!operand.IsRegister() && operand.GetType().IsTagged()) {
++count;
// Caller frame slots have negative indices and start at -1. Flip it
// back to a positive offset (to be added to the frame's SP to find the
// slot).
int slot_offset = -operand.GetLocation() - 1;
DCHECK_GE(slot_offset, 0);
first_offset = std::min(first_offset, static_cast<uint32_t>(slot_offset));
}
}
if (count > 0) {
DCHECK(first_offset != kMaxInt);
return (first_offset << 16) | (count & 0xFFFFu);
}
return 0;
}
bool CallDescriptor::CanTailCall(const CallDescriptor* callee) const {
if (ReturnCount() != callee->ReturnCount()) return false;
const int stack_returns_delta =
GetOffsetToReturns() - callee->GetOffsetToReturns();
for (size_t i = 0; i < ReturnCount(); ++i) {
if (GetReturnLocation(i).IsCallerFrameSlot() &&
callee->GetReturnLocation(i).IsCallerFrameSlot()) {
if (GetReturnLocation(i).AsCallerFrameSlot() + stack_returns_delta !=
callee->GetReturnLocation(i).AsCallerFrameSlot()) {
return false;
}
} else if (!LinkageLocation::IsSameLocation(GetReturnLocation(i),
callee->GetReturnLocation(i))) {
return false;
}
}
return true;
}
// TODO(jkummerow, sigurds): Arguably frame size calculation should be
// keyed on code/frame type, not on CallDescriptor kind. Think about a
// good way to organize this logic.
int CallDescriptor::CalculateFixedFrameSize(CodeKind code_kind) const {
switch (kind_) {
case kCallJSFunction:
return StandardFrameConstants::kFixedSlotCount;
case kCallAddress:
#if V8_ENABLE_WEBASSEMBLY
if (code_kind == CodeKind::C_WASM_ENTRY) {
return CWasmEntryFrameConstants::kFixedSlotCount;
}
#endif // V8_ENABLE_WEBASSEMBLY
return CommonFrameConstants::kFixedSlotCountAboveFp +
CommonFrameConstants::kCPSlotCount;
case kCallCodeObject:
case kCallBuiltinPointer:
return TypedFrameConstants::kFixedSlotCount;
#if V8_ENABLE_WEBASSEMBLY
case kCallWasmFunction:
case kCallWasmImportWrapper:
return WasmFrameConstants::kFixedSlotCount;
case kCallWasmCapiFunction:
return WasmExitFrameConstants::kFixedSlotCount;
#endif // V8_ENABLE_WEBASSEMBLY
}
UNREACHABLE();
}
EncodedCSignature CallDescriptor::ToEncodedCSignature() const {
int parameter_count = static_cast<int>(ParameterCount());
EncodedCSignature sig(parameter_count);
CHECK_LT(parameter_count, EncodedCSignature::kInvalidParamCount);
for (int i = 0; i < parameter_count; ++i) {
if (IsFloatingPoint(GetParameterType(i).representation())) {
sig.SetFloat(i);
}
}
if (ReturnCount() > 0) {
DCHECK_EQ(1, ReturnCount());
if (IsFloatingPoint(GetReturnType(0).representation())) {
sig.SetFloat(EncodedCSignature::kReturnIndex);
}
}
return sig;
}
void CallDescriptor::ComputeParamCounts() const {
gp_param_count_ = 0;
fp_param_count_ = 0;
for (size_t i = 0; i < ParameterCount(); ++i) {
if (IsFloatingPoint(GetParameterType(i).representation())) {
++fp_param_count_.value();
} else {
++gp_param_count_.value();
}
}
}
CallDescriptor* Linkage::ComputeIncoming(Zone* zone,
OptimizedCompilationInfo* info) {
#if V8_ENABLE_WEBASSEMBLY
DCHECK(info->IsOptimizing() || info->IsWasm());
#else
DCHECK(info->IsOptimizing());
#endif // V8_ENABLE_WEBASSEMBLY
if (!info->closure().is_null()) {
// If we are compiling a JS function, use a JS call descriptor,
// plus the receiver.
SharedFunctionInfo shared = info->closure()->shared();
return GetJSCallDescriptor(
zone, info->is_osr(),
shared.internal_formal_parameter_count_with_receiver(),
CallDescriptor::kCanUseRoots);
}
return nullptr; // TODO(titzer): ?
}
// static
bool Linkage::NeedsFrameStateInput(Runtime::FunctionId function) {
switch (function) {
// Most runtime functions need a FrameState. A few chosen ones that we know
// not to call into arbitrary JavaScript, not to throw, and not to lazily
// deoptimize are allowlisted here and can be called without a FrameState.
case Runtime::kAbort:
case Runtime::kAllocateInOldGeneration:
case Runtime::kCreateIterResultObject:
case Runtime::kGrowableSharedArrayBufferByteLength:
case Runtime::kIncBlockCounter:
case Runtime::kIsFunction:
case Runtime::kNewClosure:
case Runtime::kNewClosure_Tenured:
case Runtime::kNewFunctionContext:
case Runtime::kPushBlockContext:
case Runtime::kPushCatchContext:
case Runtime::kReThrow:
case Runtime::kReThrowWithMessage:
case Runtime::kStringEqual:
case Runtime::kStringLessThan:
case Runtime::kStringLessThanOrEqual:
case Runtime::kStringGreaterThan:
case Runtime::kStringGreaterThanOrEqual:
case Runtime::kToFastProperties: // TODO(conradw): Is it safe?
case Runtime::kTraceEnter:
case Runtime::kTraceExit:
return false;
// Some inline intrinsics are also safe to call without a FrameState.
case Runtime::kInlineCreateIterResultObject:
case Runtime::kInlineIncBlockCounter:
case Runtime::kInlineGeneratorClose:
case Runtime::kInlineGeneratorGetResumeMode:
case Runtime::kInlineCreateJSGeneratorObject:
return false;
default:
break;
}
// For safety, default to needing a FrameState unless allowlisted.
return true;
}
CallDescriptor* Linkage::GetRuntimeCallDescriptor(
Zone* zone, Runtime::FunctionId function_id, int js_parameter_count,
Operator::Properties properties, CallDescriptor::Flags flags) {
const Runtime::Function* function = Runtime::FunctionForId(function_id);
const int return_count = function->result_size;
const char* debug_name = function->name;
if (!Linkage::NeedsFrameStateInput(function_id)) {
flags = static_cast<CallDescriptor::Flags>(
flags & ~CallDescriptor::kNeedsFrameState);
}
return GetCEntryStubCallDescriptor(zone, return_count, js_parameter_count,
debug_name, properties, flags);
}
CallDescriptor* Linkage::GetCEntryStubCallDescriptor(
Zone* zone, int return_count, int js_parameter_count,
const char* debug_name, Operator::Properties properties,
CallDescriptor::Flags flags, StackArgumentOrder stack_order) {
const size_t function_count = 1;
const size_t num_args_count = 1;
const size_t context_count = 1;
const size_t parameter_count = function_count +
static_cast<size_t>(js_parameter_count) +
num_args_count + context_count;
LocationSignature::Builder locations(zone, static_cast<size_t>(return_count),
static_cast<size_t>(parameter_count));
// Add returns.
if (locations.return_count_ > 0) {
locations.AddReturn(regloc(kReturnRegister0, MachineType::AnyTagged()));
}
if (locations.return_count_ > 1) {
locations.AddReturn(regloc(kReturnRegister1, MachineType::AnyTagged()));
}
if (locations.return_count_ > 2) {
locations.AddReturn(regloc(kReturnRegister2, MachineType::AnyTagged()));
}
// All parameters to the runtime call go on the stack.
for (int i = 0; i < js_parameter_count; i++) {
locations.AddParam(LinkageLocation::ForCallerFrameSlot(
i - js_parameter_count, MachineType::AnyTagged()));
}
// Add runtime function itself.
locations.AddParam(
regloc(kRuntimeCallFunctionRegister, MachineType::Pointer()));
// Add runtime call argument count.
locations.AddParam(
regloc(kRuntimeCallArgCountRegister, MachineType::Int32()));
// Add context.
locations.AddParam(regloc(kContextRegister, MachineType::AnyTagged()));
// The target for runtime calls is a code object.
MachineType target_type = MachineType::AnyTagged();
LinkageLocation target_loc =
LinkageLocation::ForAnyRegister(MachineType::AnyTagged());
return zone->New<CallDescriptor>( // --
CallDescriptor::kCallCodeObject, // kind
target_type, // target MachineType
target_loc, // target location
locations.Build(), // location_sig
js_parameter_count, // stack_parameter_count
properties, // properties
kNoCalleeSaved, // callee-saved
kNoCalleeSavedFp, // callee-saved fp
flags, // flags
debug_name, // debug name
stack_order); // stack order
}
CallDescriptor* Linkage::GetJSCallDescriptor(Zone* zone, bool is_osr,
int js_parameter_count,
CallDescriptor::Flags flags) {
const size_t return_count = 1;
const size_t context_count = 1;
const size_t new_target_count = 1;
const size_t num_args_count = 1;
const size_t parameter_count =
js_parameter_count + new_target_count + num_args_count + context_count;
LocationSignature::Builder locations(zone, return_count, parameter_count);
// All JS calls have exactly one return value.
locations.AddReturn(regloc(kReturnRegister0, MachineType::AnyTagged()));
// All parameters to JS calls go on the stack.
for (int i = 0; i < js_parameter_count; i++) {
int spill_slot_index = -i - 1;
locations.AddParam(LinkageLocation::ForCallerFrameSlot(
spill_slot_index, MachineType::AnyTagged()));
}
// Add JavaScript call new target value.
locations.AddParam(
regloc(kJavaScriptCallNewTargetRegister, MachineType::AnyTagged()));
// Add JavaScript call argument count.
locations.AddParam(
regloc(kJavaScriptCallArgCountRegister, MachineType::Int32()));
// Add context.
locations.AddParam(regloc(kContextRegister, MachineType::AnyTagged()));
// The target for JS function calls is the JSFunction object.
MachineType target_type = MachineType::AnyTagged();
// When entering into an OSR function from unoptimized code the JSFunction
// is not in a register, but it is on the stack in the marker spill slot.
LinkageLocation target_loc =
is_osr ? LinkageLocation::ForSavedCallerFunction()
: regloc(kJSFunctionRegister, MachineType::AnyTagged());
return zone->New<CallDescriptor>( // --
CallDescriptor::kCallJSFunction, // kind
target_type, // target MachineType
target_loc, // target location
locations.Build(), // location_sig
js_parameter_count, // stack_parameter_count
Operator::kNoProperties, // properties
kNoCalleeSaved, // callee-saved
kNoCalleeSavedFp, // callee-saved fp
flags, // flags
"js-call"); // debug name
}
// TODO(turbofan): cache call descriptors for code stub calls.
// TODO(jgruber): Clean up stack parameter count handling. The descriptor
// already knows the formal stack parameter count and ideally only additional
// stack parameters should be passed into this method. All call-sites should
// be audited for correctness (e.g. many used to assume a stack parameter count
// of 0).
CallDescriptor* Linkage::GetStubCallDescriptor(
Zone* zone, const CallInterfaceDescriptor& descriptor,
int stack_parameter_count, CallDescriptor::Flags flags,
Operator::Properties properties, StubCallMode stub_mode) {
const int register_parameter_count = descriptor.GetRegisterParameterCount();
const int js_parameter_count =
register_parameter_count + stack_parameter_count;
const int context_count = descriptor.HasContextParameter() ? 1 : 0;
const size_t parameter_count =
static_cast<size_t>(js_parameter_count + context_count);
DCHECK_GE(stack_parameter_count, descriptor.GetStackParameterCount());
size_t return_count = descriptor.GetReturnCount();
LocationSignature::Builder locations(zone, return_count, parameter_count);
// Add returns.
static constexpr Register return_registers[] = {
kReturnRegister0, kReturnRegister1, kReturnRegister2};
size_t num_returns = 0;
size_t num_fp_returns = 0;
for (size_t i = 0; i < locations.return_count_; i++) {
MachineType type = descriptor.GetReturnType(static_cast<int>(i));
if (IsFloatingPoint(type.representation())) {
DCHECK_LT(num_fp_returns, 1); // Only 1 FP return is supported.
locations.AddReturn(regloc(kFPReturnRegister0, type));
num_fp_returns++;
} else {
DCHECK_LT(num_returns, arraysize(return_registers));
locations.AddReturn(regloc(return_registers[num_returns], type));
num_returns++;
}
}
USE(num_fp_returns);
// Add parameters in registers and on the stack.
for (int i = 0; i < js_parameter_count; i++) {
if (i < register_parameter_count) {
// The first parameters go in registers.
// TODO(bbudge) Add floating point registers to the InterfaceDescriptor
// and use them for FP types. Currently, this works because on most
// platforms, all FP registers are available for use. On ia32, xmm0 is
// not allocatable and so we must work around that with platform-specific
// descriptors, adjusting the GP register set to avoid eax, which has
// register code 0.
Register reg = descriptor.GetRegisterParameter(i);
MachineType type = descriptor.GetParameterType(i);
locations.AddParam(regloc(reg, type));
} else {
// The rest of the parameters go on the stack.
int stack_slot = i - register_parameter_count - stack_parameter_count;
locations.AddParam(LinkageLocation::ForCallerFrameSlot(
stack_slot, i < descriptor.GetParameterCount()
? descriptor.GetParameterType(i)
: MachineType::AnyTagged()));
}
}
// Add context.
if (context_count) {
locations.AddParam(regloc(kContextRegister, MachineType::AnyTagged()));
}
// The target for stub calls depends on the requested mode.
CallDescriptor::Kind kind;
MachineType target_type;
switch (stub_mode) {
case StubCallMode::kCallCodeObject:
kind = CallDescriptor::kCallCodeObject;
target_type = MachineType::AnyTagged();
break;
#if V8_ENABLE_WEBASSEMBLY
case StubCallMode::kCallWasmRuntimeStub:
kind = CallDescriptor::kCallWasmFunction;
target_type = MachineType::Pointer();
break;
#endif // V8_ENABLE_WEBASSEMBLY
case StubCallMode::kCallBuiltinPointer:
kind = CallDescriptor::kCallBuiltinPointer;
target_type = MachineType::AnyTagged();
break;
}
RegList allocatable_registers = descriptor.allocatable_registers();
RegList callee_saved_registers = kNoCalleeSaved;
if (descriptor.CalleeSaveRegisters()) {
callee_saved_registers = allocatable_registers;
DCHECK(!callee_saved_registers.is_empty());
}
LinkageLocation target_loc = LinkageLocation::ForAnyRegister(target_type);
return zone->New<CallDescriptor>( // --
kind, // kind
target_type, // target MachineType
target_loc, // target location
locations.Build(), // location_sig
stack_parameter_count, // stack_parameter_count
properties, // properties
callee_saved_registers, // callee-saved registers
kNoCalleeSavedFp, // callee-saved fp
CallDescriptor::kCanUseRoots | flags, // flags
descriptor.DebugName(), // debug name
descriptor.GetStackArgumentOrder(), // stack order
allocatable_registers);
}
// static
CallDescriptor* Linkage::GetBytecodeDispatchCallDescriptor(
Zone* zone, const CallInterfaceDescriptor& descriptor,
int stack_parameter_count) {
const int register_parameter_count = descriptor.GetRegisterParameterCount();
const int parameter_count = register_parameter_count + stack_parameter_count;
DCHECK_EQ(descriptor.GetReturnCount(), 1);
LocationSignature::Builder locations(zone, 1, parameter_count);
locations.AddReturn(regloc(kReturnRegister0, descriptor.GetReturnType(0)));
// Add parameters in registers and on the stack.
for (int i = 0; i < parameter_count; i++) {
if (i < register_parameter_count) {
// The first parameters go in registers.
Register reg = descriptor.GetRegisterParameter(i);
MachineType type = descriptor.GetParameterType(i);
locations.AddParam(regloc(reg, type));
} else {
// The rest of the parameters go on the stack.
int stack_slot = i - register_parameter_count - stack_parameter_count;
locations.AddParam(LinkageLocation::ForCallerFrameSlot(
stack_slot, MachineType::AnyTagged()));
}
}
// The target for interpreter dispatches is a code entry address.
MachineType target_type = MachineType::Pointer();
LinkageLocation target_loc = LinkageLocation::ForAnyRegister(target_type);
const CallDescriptor::Flags kFlags =
CallDescriptor::kCanUseRoots | CallDescriptor::kFixedTargetRegister;
return zone->New<CallDescriptor>( // --
CallDescriptor::kCallAddress, // kind
target_type, // target MachineType
target_loc, // target location
locations.Build(), // location_sig
stack_parameter_count, // stack_parameter_count
Operator::kNoProperties, // properties
kNoCalleeSaved, // callee-saved registers
kNoCalleeSavedFp, // callee-saved fp
kFlags, // flags
descriptor.DebugName());
}
LinkageLocation Linkage::GetOsrValueLocation(int index) const {
CHECK(incoming_->IsJSFunctionCall());
int parameter_count = static_cast<int>(incoming_->JSParameterCount() - 1);
int first_stack_slot = OsrHelper::FirstStackSlotIndex(parameter_count);
if (index == kOsrContextSpillSlotIndex) {
// Context. Use the parameter location of the context spill slot.
// Parameter (arity + 2) is special for the context of the function frame.
// >> context_index = target + receiver + params + new_target + #args
int context_index = 1 + 1 + parameter_count + 1 + 1;
return incoming_->GetInputLocation(context_index);
} else if (index >= first_stack_slot) {
// Local variable stored in this (callee) stack.
int spill_index =
index - first_stack_slot + StandardFrameConstants::kFixedSlotCount;
return LinkageLocation::ForCalleeFrameSlot(spill_index,
MachineType::AnyTagged());
} else {
// Parameter. Use the assigned location from the incoming call descriptor.
int parameter_index = 1 + index; // skip index 0, which is the target.
return incoming_->GetInputLocation(parameter_index);
}
}
namespace {
inline bool IsTaggedReg(const LinkageLocation& loc, Register reg) {
return loc.IsRegister() && loc.AsRegister() == reg.code() &&
loc.GetType().representation() ==
MachineRepresentation::kTaggedPointer;
}
} // namespace
bool Linkage::ParameterHasSecondaryLocation(int index) const {
// TODO(titzer): this should be configurable, not call-type specific.
if (incoming_->IsJSFunctionCall()) {
LinkageLocation loc = GetParameterLocation(index);
return IsTaggedReg(loc, kJSFunctionRegister) ||
IsTaggedReg(loc, kContextRegister);
}
#if V8_ENABLE_WEBASSEMBLY
if (incoming_->IsWasmFunctionCall()) {
LinkageLocation loc = GetParameterLocation(index);
return IsTaggedReg(loc, kWasmInstanceRegister);
}
#endif // V8_ENABLE_WEBASSEMBLY
return false;
}
LinkageLocation Linkage::GetParameterSecondaryLocation(int index) const {
// TODO(titzer): these constants are necessary due to offset/slot# mismatch
static const int kJSContextSlot = 2 + StandardFrameConstants::kCPSlotCount;
static const int kJSFunctionSlot = 3 + StandardFrameConstants::kCPSlotCount;
DCHECK(ParameterHasSecondaryLocation(index));
LinkageLocation loc = GetParameterLocation(index);
// TODO(titzer): this should be configurable, not call-type specific.
if (incoming_->IsJSFunctionCall()) {
if (IsTaggedReg(loc, kJSFunctionRegister)) {
return LinkageLocation::ForCalleeFrameSlot(kJSFunctionSlot,
MachineType::AnyTagged());
} else {
DCHECK(IsTaggedReg(loc, kContextRegister));
return LinkageLocation::ForCalleeFrameSlot(kJSContextSlot,
MachineType::AnyTagged());
}
}
#if V8_ENABLE_WEBASSEMBLY
static const int kWasmInstanceSlot = 3 + StandardFrameConstants::kCPSlotCount;
if (incoming_->IsWasmFunctionCall()) {
DCHECK(IsTaggedReg(loc, kWasmInstanceRegister));
return LinkageLocation::ForCalleeFrameSlot(kWasmInstanceSlot,
MachineType::AnyTagged());
}
#endif // V8_ENABLE_WEBASSEMBLY
UNREACHABLE();
}
} // namespace compiler
} // namespace internal
} // namespace v8
|