-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
interface-descriptors.h
1987 lines (1698 loc) Β· 78.3 KB
/
interface-descriptors.h
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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.
#ifndef V8_CODEGEN_INTERFACE_DESCRIPTORS_H_
#define V8_CODEGEN_INTERFACE_DESCRIPTORS_H_
#include <memory>
#include "src/base/logging.h"
#include "src/codegen/machine-type.h"
#include "src/codegen/register-arch.h"
#include "src/codegen/tnode.h"
#include "src/common/globals.h"
#include "src/execution/isolate.h"
namespace v8 {
namespace internal {
#define TORQUE_BUILTIN_LIST_TFC(V) \
BUILTIN_LIST_FROM_TORQUE(IGNORE_BUILTIN, IGNORE_BUILTIN, V, IGNORE_BUILTIN, \
IGNORE_BUILTIN, IGNORE_BUILTIN)
#define INTERFACE_DESCRIPTOR_LIST(V) \
V(Abort) \
V(Allocate) \
V(ApiCallback) \
V(ApiGetter) \
V(ArrayConstructor) \
V(ArrayNArgumentsConstructor) \
V(ArrayNoArgumentConstructor) \
V(ArraySingleArgumentConstructor) \
V(AsyncFunctionStackParameter) \
V(BigIntToI32Pair) \
V(BigIntToI64) \
V(BinaryOp) \
V(BinaryOp_Baseline) \
V(BinaryOp_WithFeedback) \
V(CallForwardVarargs) \
V(CallFunctionTemplate) \
V(CallTrampoline) \
V(CallTrampoline_Baseline) \
V(CallTrampoline_Baseline_Compact) \
V(CallTrampoline_WithFeedback) \
V(CallVarargs) \
V(CallWithArrayLike) \
V(CallWithArrayLike_WithFeedback) \
V(CallWithSpread) \
V(CallWithSpread_Baseline) \
V(CallWithSpread_WithFeedback) \
V(CEntry1ArgvOnStack) \
V(CloneObjectBaseline) \
V(CloneObjectWithVector) \
V(Compare) \
V(Compare_Baseline) \
V(Compare_WithFeedback) \
V(ConstructForwardVarargs) \
V(ConstructStub) \
V(ConstructVarargs) \
V(ConstructWithArrayLike) \
V(ConstructWithArrayLike_WithFeedback) \
V(Construct_WithFeedback) \
V(Construct_Baseline) \
V(ConstructWithSpread) \
V(ConstructWithSpread_Baseline) \
V(ConstructWithSpread_WithFeedback) \
V(ContextOnly) \
V(CppBuiltinAdaptor) \
V(DynamicCheckMaps) \
V(EphemeronKeyBarrier) \
V(FastNewObject) \
V(ForInPrepare) \
V(GetIteratorStackParameter) \
V(GetProperty) \
V(GrowArrayElements) \
V(I32PairToBigInt) \
V(I64ToBigInt) \
V(InterpreterCEntry1) \
V(InterpreterCEntry2) \
V(InterpreterDispatch) \
V(TailCallOptimizedCodeSlot) \
V(InterpreterPushArgsThenCall) \
V(InterpreterPushArgsThenConstruct) \
V(JSTrampoline) \
V(BaselineOutOfLinePrologue) \
V(BaselineLeaveFrame) \
V(Load) \
V(LoadBaseline) \
V(LoadGlobal) \
V(LoadGlobalBaseline) \
V(LoadGlobalNoFeedback) \
V(LoadGlobalWithVector) \
V(LoadNoFeedback) \
V(LoadWithVector) \
V(LoadWithReceiverAndVector) \
V(LoadWithReceiverBaseline) \
V(LookupBaseline) \
V(NoContext) \
V(RecordWrite) \
V(ResumeGenerator) \
V(SuspendGeneratorBaseline) \
V(ResumeGeneratorBaseline) \
V(RunMicrotasks) \
V(RunMicrotasksEntry) \
V(SingleParameterOnStack) \
V(Store) \
V(StoreBaseline) \
V(StoreGlobal) \
V(StoreGlobalBaseline) \
V(StoreGlobalWithVector) \
V(StoreTransition) \
V(StoreWithVector) \
V(StringAt) \
V(StringAtAsString) \
V(StringSubstring) \
V(TypeConversion) \
V(TypeConversionNoContext) \
V(TypeConversion_Baseline) \
V(Typeof) \
V(UnaryOp_Baseline) \
V(UnaryOp_WithFeedback) \
V(Void) \
V(WasmFloat32ToNumber) \
V(WasmFloat64ToNumber) \
V(WasmI32AtomicWait32) \
V(WasmI64AtomicWait32) \
BUILTIN_LIST_TFS(V) \
TORQUE_BUILTIN_LIST_TFC(V)
enum class StackArgumentOrder {
kDefault, // Arguments in the stack are pushed in the default/stub order (the
// first argument is pushed first).
kJS, // Arguments in the stack are pushed in the same order as the one used
// by JS-to-JS function calls. This should be used if calling a
// JSFunction or if the builtin is expected to be called directly from a
// JSFunction. This order is reversed compared to kDefault.
};
class V8_EXPORT_PRIVATE CallInterfaceDescriptorData {
public:
enum Flag {
kNoFlags = 0u,
kNoContext = 1u << 0,
// This indicates that the code uses a special frame that does not scan the
// stack arguments, e.g. EntryFrame. And this allows the code to use
// untagged stack arguments.
kNoStackScan = 1u << 1,
// In addition to the specified parameters, additional arguments can be
// passed on the stack.
// This does not indicate if arguments adaption is used or not.
kAllowVarArgs = 1u << 2,
};
using Flags = base::Flags<Flag>;
static constexpr int kUninitializedCount = -1;
CallInterfaceDescriptorData() = default;
CallInterfaceDescriptorData(const CallInterfaceDescriptorData&) = delete;
CallInterfaceDescriptorData& operator=(const CallInterfaceDescriptorData&) =
delete;
// The passed registers are owned by the caller, and their lifetime is
// expected to exceed that of this data. In practice, they are expected to
// be in a static local.
void InitializeRegisters(Flags flags, int return_count, int parameter_count,
StackArgumentOrder stack_order,
int register_parameter_count,
const Register* registers);
// if machine_types is null, then an array of size
// (return_count + parameter_count) will be created with
// MachineType::AnyTagged() for each member.
//
// if machine_types is not null, then it should be of the size
// (return_count + parameter_count). Those members of the parameter array will
// be initialized from {machine_types}, and the rest initialized to
// MachineType::AnyTagged().
void InitializeTypes(const MachineType* machine_types,
int machine_types_length);
void Reset();
bool IsInitialized() const {
return IsInitializedRegisters() && IsInitializedTypes();
}
Flags flags() const { return flags_; }
int return_count() const { return return_count_; }
int param_count() const { return param_count_; }
int register_param_count() const { return register_param_count_; }
Register register_param(int index) const { return register_params_[index]; }
MachineType return_type(int index) const {
DCHECK_LT(index, return_count_);
return machine_types_[index];
}
MachineType param_type(int index) const {
DCHECK_LT(index, param_count_);
return machine_types_[return_count_ + index];
}
StackArgumentOrder stack_order() const { return stack_order_; }
void RestrictAllocatableRegisters(const Register* registers, size_t num) {
DCHECK_EQ(allocatable_registers_, 0);
for (size_t i = 0; i < num; ++i) {
allocatable_registers_ |= registers[i].bit();
}
DCHECK_GT(NumRegs(allocatable_registers_), 0);
}
RegList allocatable_registers() const { return allocatable_registers_; }
private:
bool IsInitializedRegisters() const {
const bool initialized =
return_count_ != kUninitializedCount &&
param_count_ != kUninitializedCount &&
(register_param_count_ == 0 || register_params_ != nullptr);
// Register initialization happens before type initialization.
return initialized;
}
bool IsInitializedTypes() const {
const bool initialized = machine_types_ != nullptr;
// Register initialization happens before type initialization.
return initialized;
}
#ifdef DEBUG
bool AllStackParametersAreTagged() const;
#endif // DEBUG
int register_param_count_ = kUninitializedCount;
int return_count_ = kUninitializedCount;
int param_count_ = kUninitializedCount;
Flags flags_ = kNoFlags;
StackArgumentOrder stack_order_ = StackArgumentOrder::kDefault;
// Specifying the set of registers that could be used by the register
// allocator. Currently, it's only used by RecordWrite code stub.
RegList allocatable_registers_ = 0;
// |registers_params_| defines registers that are used for parameter passing.
// |machine_types_| defines machine types for resulting values and incomping
// parameters.
// The register params array is owned by the caller, and it's expected that it
// is a static local stored in the caller function. The machine types are
// allocated dynamically by the InterfaceDescriptor and freed on destruction.
const Register* register_params_ = nullptr;
MachineType* machine_types_ = nullptr;
};
class V8_EXPORT_PRIVATE CallDescriptors : public AllStatic {
public:
enum Key {
#define DEF_ENUM(name, ...) name,
INTERFACE_DESCRIPTOR_LIST(DEF_ENUM)
#undef DEF_ENUM
NUMBER_OF_DESCRIPTORS
};
static void InitializeOncePerProcess();
static void TearDown();
static CallInterfaceDescriptorData* call_descriptor_data(
CallDescriptors::Key key) {
return &call_descriptor_data_[key];
}
static Key GetKey(const CallInterfaceDescriptorData* data) {
ptrdiff_t index = data - call_descriptor_data_;
DCHECK_LE(0, index);
DCHECK_LT(index, CallDescriptors::NUMBER_OF_DESCRIPTORS);
return static_cast<CallDescriptors::Key>(index);
}
private:
static CallInterfaceDescriptorData
call_descriptor_data_[NUMBER_OF_DESCRIPTORS];
};
#if defined(V8_TARGET_ARCH_IA32)
// To support all possible cases, we must limit the number of register args for
// TFS builtins on ia32 to 3. Out of the 6 allocatable registers, esi is taken
// as the context register and ebx is the root register. One register must
// remain available to store the jump/call target. Thus 3 registers remain for
// arguments. The reason this applies to TFS builtins specifically is because
// this becomes relevant for builtins used as targets of Torque function
// pointers (which must have a register available to store the target).
// TODO(jgruber): Ideally we should just decrement kMaxBuiltinRegisterParams but
// that comes with its own set of complications. It's possible, but requires
// refactoring the calling convention of other existing stubs.
constexpr int kMaxBuiltinRegisterParams = 4;
constexpr int kMaxTFSBuiltinRegisterParams = 3;
#else
constexpr int kMaxBuiltinRegisterParams = 5;
constexpr int kMaxTFSBuiltinRegisterParams = kMaxBuiltinRegisterParams;
#endif
STATIC_ASSERT(kMaxTFSBuiltinRegisterParams <= kMaxBuiltinRegisterParams);
constexpr int kJSBuiltinRegisterParams = 4;
// Polymorphic base class for call interface descriptors, which defines getters
// for the various descriptor properties via a runtime-loaded
// CallInterfaceDescriptorData field.
class V8_EXPORT_PRIVATE CallInterfaceDescriptor {
public:
using Flags = CallInterfaceDescriptorData::Flags;
CallInterfaceDescriptor() : data_(nullptr) {}
~CallInterfaceDescriptor() = default;
explicit CallInterfaceDescriptor(CallDescriptors::Key key)
: data_(CallDescriptors::call_descriptor_data(key)) {}
Flags flags() const { return data()->flags(); }
bool HasContextParameter() const {
return (flags() & CallInterfaceDescriptorData::kNoContext) == 0;
}
bool AllowVarArgs() const {
return flags() & CallInterfaceDescriptorData::kAllowVarArgs;
}
int GetReturnCount() const { return data()->return_count(); }
MachineType GetReturnType(int index) const {
DCHECK_LT(index, data()->return_count());
return data()->return_type(index);
}
int GetParameterCount() const { return data()->param_count(); }
int GetRegisterParameterCount() const {
return data()->register_param_count();
}
int GetStackParameterCount() const {
return data()->param_count() - data()->register_param_count();
}
Register GetRegisterParameter(int index) const {
DCHECK_LT(index, data()->register_param_count());
return data()->register_param(index);
}
MachineType GetParameterType(int index) const {
DCHECK_LT(index, data()->param_count());
return data()->param_type(index);
}
RegList allocatable_registers() const {
return data()->allocatable_registers();
}
StackArgumentOrder GetStackArgumentOrder() const {
return data()->stack_order();
}
static constexpr inline Register ContextRegister() {
return kContextRegister;
}
const char* DebugName() const;
bool operator==(const CallInterfaceDescriptor& other) const {
return data() == other.data();
}
protected:
const CallInterfaceDescriptorData* data() const { return data_; }
// Helper for defining the default register set.
//
// Use auto for the return type to allow different architectures to have
// differently sized default register arrays.
static constexpr inline auto DefaultRegisterArray();
static constexpr inline std::array<Register, kJSBuiltinRegisterParams>
DefaultJSRegisterArray();
// Checks if float parameters are not assigned invalid registers.
bool CheckFloatingPointParameters(CallInterfaceDescriptorData* data) {
for (int i = 0; i < data->register_param_count(); i++) {
if (IsFloatingPoint(data->param_type(i).representation())) {
if (!IsValidFloatParameterRegister(data->register_param(i))) {
return false;
}
}
}
return true;
}
bool IsValidFloatParameterRegister(Register reg);
private:
const CallInterfaceDescriptorData* data_;
};
// CRTP base class for call interface descriptors, which defines static getters
// for the various descriptor properties based on static values defined in the
// subclass.
template <typename DerivedDescriptor>
class StaticCallInterfaceDescriptor : public CallInterfaceDescriptor {
public:
// ===========================================================================
// The following are the descriptor's CRTP configuration points, overwritable
// by DerivedDescriptor.
static constexpr int kReturnCount =
CallInterfaceDescriptorData::kUninitializedCount;
static constexpr int kParameterCount =
CallInterfaceDescriptorData::kUninitializedCount;
static constexpr bool kNoContext = false;
static constexpr bool kAllowVarArgs = false;
static constexpr bool kNoStackScan = false;
static constexpr auto kStackArgumentOrder = StackArgumentOrder::kDefault;
// The set of registers available to the parameters, as a
// std::array<Register,N>. Can be larger or smaller than kParameterCount; if
// larger then any remaining registers are ignored; if smaller, any parameters
// after registers().size() will be stack registers.
//
// Defaults to CallInterfaceDescriptor::DefaultRegisterArray().
static constexpr inline auto registers();
// An additional limit on the number of register parameters allowed. This is
// here so that it can be overwritten to kMaxTFSBuiltinRegisterParams for TFS
// builtins, see comment on kMaxTFSBuiltinRegisterParams above.
static constexpr int kMaxRegisterParams = kMaxBuiltinRegisterParams;
// If set to true, the descriptor will restrict the set of allocatable
// registers to the set returned by registers(). Then, it is expected that
// the first kParameterCount registers() are the parameters of the builtin.
static constexpr bool kRestrictAllocatableRegisters = false;
// End of customization points.
// ===========================================================================
static constexpr inline Flags flags() {
return Flags((DerivedDescriptor::kNoContext
? CallInterfaceDescriptorData::kNoContext
: 0) |
(DerivedDescriptor::kAllowVarArgs
? CallInterfaceDescriptorData::kAllowVarArgs
: 0) |
(DerivedDescriptor::kNoStackScan
? CallInterfaceDescriptorData::kNoStackScan
: 0));
}
static constexpr inline bool AllowVarArgs() {
return DerivedDescriptor::kAllowVarArgs;
}
static constexpr inline bool HasContextParameter() {
return !DerivedDescriptor::kNoContext;
}
static constexpr inline int GetReturnCount();
static constexpr inline int GetParameterCount();
static constexpr inline int GetRegisterParameterCount();
static constexpr inline int GetStackParameterCount();
static constexpr inline Register* GetRegisterData();
static constexpr inline Register GetRegisterParameter(int i);
explicit StaticCallInterfaceDescriptor(CallDescriptors::Key key)
: CallInterfaceDescriptor(key) {}
private:
// {CallDescriptors} is allowed to call the private {Initialize} method.
friend class CallDescriptors;
inline void Initialize(CallInterfaceDescriptorData* data);
// Set up the types of the descriptor. This is a static function, so that it
// is overwritable by subclasses. By default, all parameters have
// MachineType::AnyTagged() type.
static void InitializeTypes(CallInterfaceDescriptorData* data) {
data->InitializeTypes(nullptr, 0);
}
};
template <typename Descriptor>
class StaticJSCallInterfaceDescriptor
: public StaticCallInterfaceDescriptor<Descriptor> {
public:
static constexpr auto kStackArgumentOrder = StackArgumentOrder::kJS;
static constexpr inline auto registers();
using StaticCallInterfaceDescriptor<
Descriptor>::StaticCallInterfaceDescriptor;
};
template <Builtins::Name kBuiltin>
struct CallInterfaceDescriptorFor;
// Stub class replacing std::array<Register, 0>, as a workaround for MSVC's
// https://github.com/microsoft/STL/issues/942
struct EmptyRegisterArray {
Register* data() { return nullptr; }
size_t size() const { return 0; }
Register operator[](size_t i) const { UNREACHABLE(); }
};
// Helper method for defining an array of registers for the various
// Descriptor::registers() methods.
template <typename... Registers>
constexpr std::array<Register, 1 + sizeof...(Registers)> RegisterArray(
Register first_reg, Registers... regs) {
return {first_reg, regs...};
}
constexpr EmptyRegisterArray RegisterArray() { return {}; }
#define DECLARE_DESCRIPTOR_WITH_BASE(name, base) \
public: \
/* StaticCallInterfaceDescriptor can call Initialize methods */ \
friend class StaticCallInterfaceDescriptor<name>; \
explicit name() : base(key()) {} \
static inline CallDescriptors::Key key();
#define DECLARE_DEFAULT_DESCRIPTOR(name) \
DECLARE_DESCRIPTOR_WITH_BASE(name, StaticCallInterfaceDescriptor) \
static constexpr int kMaxRegisterParams = kMaxTFSBuiltinRegisterParams; \
\
protected: \
explicit name(CallDescriptors::Key key) \
: StaticCallInterfaceDescriptor(key) {} \
\
public:
#define DECLARE_JS_COMPATIBLE_DESCRIPTOR(name) \
DECLARE_DESCRIPTOR_WITH_BASE(name, StaticJSCallInterfaceDescriptor) \
protected: \
explicit name(CallDescriptors::Key key) \
: StaticJSCallInterfaceDescriptor(key) {} \
\
public:
#define DEFINE_RESULT_AND_PARAMETERS(return_count, ...) \
static constexpr int kReturnCount = return_count; \
enum ParameterIndices { \
__dummy = -1, /* to be able to pass zero arguments */ \
##__VA_ARGS__, \
\
kParameterCount, \
kContext = kParameterCount /* implicit parameter */ \
};
// This is valid only for builtins that use EntryFrame, which does not scan
// stack arguments on GC.
#define DEFINE_PARAMETERS_ENTRY(...) \
static constexpr bool kNoContext = true; \
static constexpr bool kNoStackScan = true; \
static constexpr StackArgumentOrder kStackArgumentOrder = \
StackArgumentOrder::kDefault; \
static constexpr int kReturnCount = 1; \
enum ParameterIndices { \
__dummy = -1, /* to be able to pass zero arguments */ \
##__VA_ARGS__, \
\
kParameterCount \
};
#define DEFINE_PARAMETERS(...) DEFINE_RESULT_AND_PARAMETERS(1, ##__VA_ARGS__)
#define DEFINE_PARAMETERS_NO_CONTEXT(...) \
DEFINE_PARAMETERS(__VA_ARGS__) \
static constexpr bool kNoContext = true;
#define DEFINE_PARAMETERS_VARARGS(...) \
DEFINE_PARAMETERS(__VA_ARGS__) \
static constexpr bool kAllowVarArgs = true; \
static constexpr StackArgumentOrder kStackArgumentOrder = \
StackArgumentOrder::kJS;
#define DEFINE_PARAMETERS_NO_CONTEXT_VARARGS(...) \
DEFINE_PARAMETERS_NO_CONTEXT(__VA_ARGS__) \
static constexpr bool kAllowVarArgs = true; \
static constexpr StackArgumentOrder kStackArgumentOrder = \
StackArgumentOrder::kJS;
#define DEFINE_RESULT_AND_PARAMETERS_NO_CONTEXT(return_count, ...) \
DEFINE_RESULT_AND_PARAMETERS(return_count, ##__VA_ARGS__) \
static constexpr bool kNoContext = true;
#define DEFINE_RESULT_AND_PARAMETER_TYPES(...) \
static void InitializeTypes(CallInterfaceDescriptorData* data) { \
MachineType machine_types[] = {__VA_ARGS__}; \
static_assert( \
kReturnCount + kParameterCount == arraysize(machine_types), \
"Parameter names definition is not consistent with parameter types"); \
data->InitializeTypes(machine_types, arraysize(machine_types)); \
}
#define DEFINE_PARAMETER_TYPES(...) \
DEFINE_RESULT_AND_PARAMETER_TYPES(MachineType::AnyTagged() /* result */, \
##__VA_ARGS__)
// When the extra arguments described here are located in the stack, they are
// just above the return address in the frame (first arguments).
#define DEFINE_JS_PARAMETERS(...) \
static constexpr bool kAllowVarArgs = true; \
static constexpr int kReturnCount = 1; \
static constexpr StackArgumentOrder kStackArgumentOrder = \
StackArgumentOrder::kJS; \
enum ParameterIndices { \
kTarget, \
kNewTarget, \
kActualArgumentsCount, \
##__VA_ARGS__, \
kParameterCount, \
kContext = kParameterCount /* implicit parameter */ \
};
#define DEFINE_JS_PARAMETERS_NO_CONTEXT(...) \
static constexpr bool kAllowVarArgs = true; \
static constexpr bool kNoContext = true; \
static constexpr int kReturnCount = 1; \
static constexpr StackArgumentOrder kStackArgumentOrder = \
StackArgumentOrder::kJS; \
enum ParameterIndices { \
kTarget, \
kNewTarget, \
kActualArgumentsCount, \
##__VA_ARGS__, \
kParameterCount, \
};
#define DEFINE_JS_PARAMETER_TYPES(...) \
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), /* kTarget */ \
MachineType::AnyTagged(), /* kNewTarget */ \
MachineType::Int32(), /* kActualArgumentsCount */ \
##__VA_ARGS__)
#define DECLARE_DESCRIPTOR(name) \
DECLARE_DESCRIPTOR_WITH_BASE(name, StaticCallInterfaceDescriptor) \
protected: \
explicit name(CallDescriptors::Key key) \
: StaticCallInterfaceDescriptor(key) {} \
\
public:
class V8_EXPORT_PRIVATE VoidDescriptor
: public StaticCallInterfaceDescriptor<VoidDescriptor> {
public:
DEFINE_PARAMETERS()
DEFINE_PARAMETER_TYPES()
DECLARE_DESCRIPTOR(VoidDescriptor)
static constexpr auto registers();
};
// Dummy descriptor used to mark builtins that don't yet have their proper
// descriptor associated.
using DummyDescriptor = VoidDescriptor;
// Dummy descriptor that marks builtins with C calling convention.
using CCallDescriptor = VoidDescriptor;
// Marks deoptimization entry builtins. Precise calling conventions currently
// differ based on the platform.
// TODO(jgruber): Once this is unified, we could create a better description
// here.
using DeoptimizationEntryDescriptor = VoidDescriptor;
class AllocateDescriptor
: public StaticCallInterfaceDescriptor<AllocateDescriptor> {
public:
DEFINE_PARAMETERS_NO_CONTEXT(kRequestedSize)
DEFINE_RESULT_AND_PARAMETER_TYPES(MachineType::TaggedPointer(), // result 1
MachineType::IntPtr()) // kRequestedSize
DECLARE_DESCRIPTOR(AllocateDescriptor)
static constexpr auto registers();
};
// This descriptor defines the JavaScript calling convention that can be used
// by stubs: target, new.target, argc (not including the receiver) and context
// are passed in registers while receiver and the rest of the JS arguments are
// passed on the stack.
class JSTrampolineDescriptor
: public StaticJSCallInterfaceDescriptor<JSTrampolineDescriptor> {
public:
DEFINE_JS_PARAMETERS()
DEFINE_JS_PARAMETER_TYPES()
DECLARE_JS_COMPATIBLE_DESCRIPTOR(JSTrampolineDescriptor)
};
class ContextOnlyDescriptor
: public StaticCallInterfaceDescriptor<ContextOnlyDescriptor> {
public:
DEFINE_PARAMETERS()
DEFINE_PARAMETER_TYPES()
DECLARE_DESCRIPTOR(ContextOnlyDescriptor)
static constexpr auto registers();
};
class NoContextDescriptor
: public StaticCallInterfaceDescriptor<NoContextDescriptor> {
public:
DEFINE_PARAMETERS_NO_CONTEXT()
DEFINE_PARAMETER_TYPES()
DECLARE_DESCRIPTOR(NoContextDescriptor)
static constexpr auto registers();
};
// LoadDescriptor is used by all stubs that implement Load/KeyedLoad ICs.
class LoadDescriptor : public StaticCallInterfaceDescriptor<LoadDescriptor> {
public:
DEFINE_PARAMETERS(kReceiver, kName, kSlot)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kReceiver
MachineType::AnyTagged(), // kName
MachineType::TaggedSigned()) // kSlot
DECLARE_DESCRIPTOR(LoadDescriptor)
static constexpr inline Register ReceiverRegister();
static constexpr inline Register NameRegister();
static constexpr inline Register SlotRegister();
static constexpr auto registers();
};
// LoadBaselineDescriptor is a load descriptor that does not take a context as
// input.
class LoadBaselineDescriptor
: public StaticCallInterfaceDescriptor<LoadBaselineDescriptor> {
public:
DEFINE_PARAMETERS_NO_CONTEXT(kReceiver, kName, kSlot)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kReceiver
MachineType::AnyTagged(), // kName
MachineType::TaggedSigned()) // kSlot
DECLARE_DESCRIPTOR(LoadBaselineDescriptor)
static constexpr auto registers();
};
class LoadGlobalNoFeedbackDescriptor
: public StaticCallInterfaceDescriptor<LoadGlobalNoFeedbackDescriptor> {
public:
DEFINE_PARAMETERS(kName, kICKind)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kName
MachineType::TaggedSigned()) // kICKind
DECLARE_DESCRIPTOR(LoadGlobalNoFeedbackDescriptor)
static constexpr inline Register ICKindRegister();
static constexpr auto registers();
};
class LoadNoFeedbackDescriptor
: public StaticCallInterfaceDescriptor<LoadNoFeedbackDescriptor> {
public:
DEFINE_PARAMETERS(kReceiver, kName, kICKind)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kReceiver
MachineType::AnyTagged(), // kName
MachineType::TaggedSigned()) // kICKind
DECLARE_DESCRIPTOR(LoadNoFeedbackDescriptor)
static constexpr inline Register ICKindRegister();
static constexpr auto registers();
};
class LoadGlobalDescriptor
: public StaticCallInterfaceDescriptor<LoadGlobalDescriptor> {
public:
DEFINE_PARAMETERS(kName, kSlot)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kName
MachineType::TaggedSigned()) // kSlot
DECLARE_DESCRIPTOR(LoadGlobalDescriptor)
static constexpr auto registers();
};
class LoadGlobalBaselineDescriptor
: public StaticCallInterfaceDescriptor<LoadGlobalBaselineDescriptor> {
public:
DEFINE_PARAMETERS_NO_CONTEXT(kName, kSlot)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kName
MachineType::TaggedSigned()) // kSlot
DECLARE_DESCRIPTOR(LoadGlobalBaselineDescriptor)
static constexpr auto registers();
};
class LookupBaselineDescriptor
: public StaticCallInterfaceDescriptor<LookupBaselineDescriptor> {
public:
DEFINE_PARAMETERS_NO_CONTEXT(kName, kDepth, kSlot)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kName
MachineType::AnyTagged(), // kDepth
MachineType::AnyTagged()) // kSlot
DECLARE_DESCRIPTOR(LookupBaselineDescriptor)
};
class StoreDescriptor : public StaticCallInterfaceDescriptor<StoreDescriptor> {
public:
DEFINE_PARAMETERS(kReceiver, kName, kValue, kSlot)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kReceiver
MachineType::AnyTagged(), // kName
MachineType::AnyTagged(), // kValue
MachineType::TaggedSigned()) // kSlot
DECLARE_DESCRIPTOR(StoreDescriptor)
static constexpr inline Register ReceiverRegister();
static constexpr inline Register NameRegister();
static constexpr inline Register ValueRegister();
static constexpr inline Register SlotRegister();
static constexpr auto registers();
};
class StoreBaselineDescriptor
: public StaticCallInterfaceDescriptor<StoreBaselineDescriptor> {
public:
DEFINE_PARAMETERS_NO_CONTEXT(kReceiver, kName, kValue, kSlot)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kReceiver
MachineType::AnyTagged(), // kName
MachineType::AnyTagged(), // kValue
MachineType::TaggedSigned()) // kSlot
DECLARE_DESCRIPTOR(StoreBaselineDescriptor)
static constexpr auto registers();
};
class StoreTransitionDescriptor
: public StaticCallInterfaceDescriptor<StoreTransitionDescriptor> {
public:
DEFINE_PARAMETERS(kReceiver, kName, kMap, kValue, kSlot, kVector)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kReceiver
MachineType::AnyTagged(), // kName
MachineType::AnyTagged(), // kMap
MachineType::AnyTagged(), // kValue
MachineType::TaggedSigned(), // kSlot
MachineType::AnyTagged()) // kVector
DECLARE_DESCRIPTOR(StoreTransitionDescriptor)
static constexpr inline Register MapRegister();
static constexpr auto registers();
};
class StoreWithVectorDescriptor
: public StaticCallInterfaceDescriptor<StoreWithVectorDescriptor> {
public:
DEFINE_PARAMETERS(kReceiver, kName, kValue, kSlot, kVector)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kReceiver
MachineType::AnyTagged(), // kName
MachineType::AnyTagged(), // kValue
MachineType::TaggedSigned(), // kSlot
MachineType::AnyTagged()) // kVector
DECLARE_DESCRIPTOR(StoreWithVectorDescriptor)
static constexpr inline Register VectorRegister();
static constexpr auto registers();
};
class StoreGlobalDescriptor
: public StaticCallInterfaceDescriptor<StoreGlobalDescriptor> {
public:
DEFINE_PARAMETERS(kName, kValue, kSlot)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kName
MachineType::AnyTagged(), // kValue
MachineType::TaggedSigned()) // kSlot
DECLARE_DESCRIPTOR(StoreGlobalDescriptor)
static constexpr auto registers();
};
class StoreGlobalBaselineDescriptor
: public StaticCallInterfaceDescriptor<StoreGlobalBaselineDescriptor> {
public:
DEFINE_PARAMETERS_NO_CONTEXT(kName, kValue, kSlot)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kName
MachineType::AnyTagged(), // kValue
MachineType::TaggedSigned()) // kSlot
DECLARE_DESCRIPTOR(StoreGlobalBaselineDescriptor)
static constexpr auto registers();
};
class StoreGlobalWithVectorDescriptor
: public StaticCallInterfaceDescriptor<StoreGlobalWithVectorDescriptor> {
public:
DEFINE_PARAMETERS(kName, kValue, kSlot, kVector)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kName
MachineType::AnyTagged(), // kValue
MachineType::TaggedSigned(), // kSlot
MachineType::AnyTagged()) // kVector
DECLARE_DESCRIPTOR(StoreGlobalWithVectorDescriptor)
static constexpr auto registers();
};
class LoadWithVectorDescriptor
: public StaticCallInterfaceDescriptor<LoadWithVectorDescriptor> {
public:
// TODO(v8:9497): Revert the Machine type for kSlot to the
// TaggedSigned once Torque can emit better call descriptors
DEFINE_PARAMETERS(kReceiver, kName, kSlot, kVector)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kReceiver
MachineType::AnyTagged(), // kName
MachineType::AnyTagged(), // kSlot
MachineType::AnyTagged()) // kVector
DECLARE_DESCRIPTOR(LoadWithVectorDescriptor)
static constexpr inline Register VectorRegister();
static constexpr auto registers();
};
// Like LoadWithVectorDescriptor, except we pass the receiver (the object which
// should be used as the receiver for accessor function calls) and the lookup
// start object separately.
class LoadWithReceiverAndVectorDescriptor
: public StaticCallInterfaceDescriptor<
LoadWithReceiverAndVectorDescriptor> {
public:
// TODO(v8:9497): Revert the Machine type for kSlot to the
// TaggedSigned once Torque can emit better call descriptors
DEFINE_PARAMETERS(kReceiver, kLookupStartObject, kName, kSlot, kVector)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kReceiver
MachineType::AnyTagged(), // kLookupStartObject
MachineType::AnyTagged(), // kName
MachineType::AnyTagged(), // kSlot
MachineType::AnyTagged()) // kVector
DECLARE_DESCRIPTOR(LoadWithReceiverAndVectorDescriptor)
static constexpr inline Register LookupStartObjectRegister();
static constexpr auto registers();
};
class LoadWithReceiverBaselineDescriptor
: public StaticCallInterfaceDescriptor<LoadWithReceiverBaselineDescriptor> {
public:
// TODO(v8:9497): Revert the Machine type for kSlot to the
// TaggedSigned once Torque can emit better call descriptors
DEFINE_PARAMETERS_NO_CONTEXT(kReceiver, kLookupStartObject, kName, kSlot)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kReceiver
MachineType::AnyTagged(), // kLookupStartObject
MachineType::AnyTagged(), // kName
MachineType::AnyTagged()) // kSlot
DECLARE_DESCRIPTOR(LoadWithReceiverBaselineDescriptor)
static constexpr auto registers();
};
class LoadGlobalWithVectorDescriptor
: public StaticCallInterfaceDescriptor<LoadGlobalWithVectorDescriptor> {
public:
DEFINE_PARAMETERS(kName, kSlot, kVector)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kName
MachineType::TaggedSigned(), // kSlot
MachineType::AnyTagged()) // kVector
DECLARE_DESCRIPTOR(LoadGlobalWithVectorDescriptor)
static constexpr inline Register VectorRegister();
static constexpr auto registers();
};
class DynamicCheckMapsDescriptor final
: public StaticCallInterfaceDescriptor<DynamicCheckMapsDescriptor> {
public:
DEFINE_PARAMETERS(kMap, kSlot, kHandler)
DEFINE_RESULT_AND_PARAMETER_TYPES(MachineType::Int32(), // return val
MachineType::TaggedPointer(), // kMap
MachineType::IntPtr(), // kSlot
MachineType::TaggedSigned()) // kHandler
DECLARE_DESCRIPTOR(DynamicCheckMapsDescriptor)
static constexpr auto registers();
static constexpr bool kRestrictAllocatableRegisters = true;
};
class FastNewObjectDescriptor
: public StaticCallInterfaceDescriptor<FastNewObjectDescriptor> {
public:
DEFINE_PARAMETERS(kTarget, kNewTarget)
DEFINE_PARAMETER_TYPES(MachineType::AnyTagged(), // kTarget
MachineType::AnyTagged()) // kNewTarget
DECLARE_DESCRIPTOR(FastNewObjectDescriptor)
static constexpr inline Register TargetRegister();
static constexpr inline Register NewTargetRegister();
static constexpr auto registers();
};
class RecordWriteDescriptor final
: public StaticCallInterfaceDescriptor<RecordWriteDescriptor> {
public:
DEFINE_PARAMETERS_NO_CONTEXT(kObject, kSlot, kRememberedSet, kFPMode)
DEFINE_PARAMETER_TYPES(MachineType::TaggedPointer(), // kObject
MachineType::Pointer(), // kSlot
MachineType::TaggedSigned(), // kRememberedSet
MachineType::TaggedSigned()) // kFPMode