deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / interface-descriptors.h
1 // 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
5 #ifndef V8_CALL_INTERFACE_DESCRIPTOR_H_
6 #define V8_CALL_INTERFACE_DESCRIPTOR_H_
7
8 #include "src/assembler.h"
9 #include "src/macro-assembler.h"
10
11 namespace v8 {
12 namespace internal {
13
14 class PlatformInterfaceDescriptor;
15
16 #define INTERFACE_DESCRIPTOR_LIST(V)          \
17   V(Load)                                     \
18   V(Store)                                    \
19   V(StoreTransition)                          \
20   V(ElementTransitionAndStore)                \
21   V(Instanceof)                               \
22   V(VectorLoadICTrampoline)                   \
23   V(VectorLoadIC)                             \
24   V(FastNewClosure)                           \
25   V(FastNewContext)                           \
26   V(ToNumber)                                 \
27   V(NumberToString)                           \
28   V(FastCloneShallowArray)                    \
29   V(FastCloneShallowObject)                   \
30   V(CreateAllocationSite)                     \
31   V(CreateWeakCell)                           \
32   V(CallFunction)                             \
33   V(CallFunctionWithFeedback)                 \
34   V(CallFunctionWithFeedbackAndVector)        \
35   V(CallConstruct)                            \
36   V(RegExpConstructResult)                    \
37   V(TransitionElementsKind)                   \
38   V(AllocateHeapNumber)                       \
39   V(ArrayConstructorConstantArgCount)         \
40   V(ArrayConstructor)                         \
41   V(InternalArrayConstructorConstantArgCount) \
42   V(InternalArrayConstructor)                 \
43   V(Compare)                                  \
44   V(CompareNil)                               \
45   V(ToBoolean)                                \
46   V(BinaryOp)                                 \
47   V(BinaryOpWithAllocationSite)               \
48   V(StringAdd)                                \
49   V(Keyed)                                    \
50   V(Named)                                    \
51   V(CallHandler)                              \
52   V(ArgumentAdaptor)                          \
53   V(ApiFunction)                              \
54   V(ApiAccessor)                              \
55   V(ApiGetter)                                \
56   V(ArgumentsAccessRead)                      \
57   V(StoreArrayLiteralElement)                 \
58   V(MathPowTagged)                            \
59   V(MathPowInteger)                           \
60   V(ContextOnly)
61
62
63 class CallInterfaceDescriptorData {
64  public:
65   CallInterfaceDescriptorData() : register_param_count_(-1) {}
66
67   // A copy of the passed in registers and param_representations is made
68   // and owned by the CallInterfaceDescriptorData.
69
70   // TODO(mvstanton): Instead of taking parallel arrays register and
71   // param_representations, how about a struct that puts the representation
72   // and register side by side (eg, RegRep(r1, Representation::Tagged()).
73   // The same should go for the CodeStubDescriptor class.
74   void Initialize(int register_parameter_count, Register* registers,
75                   Representation* param_representations,
76                   PlatformInterfaceDescriptor* platform_descriptor = NULL);
77
78   bool IsInitialized() const { return register_param_count_ >= 0; }
79
80   int register_param_count() const { return register_param_count_; }
81   Register register_param(int index) const { return register_params_[index]; }
82   Register* register_params() const { return register_params_.get(); }
83   Representation register_param_representation(int index) const {
84     return register_param_representations_[index];
85   }
86   Representation* register_param_representations() const {
87     return register_param_representations_.get();
88   }
89   PlatformInterfaceDescriptor* platform_specific_descriptor() const {
90     return platform_specific_descriptor_;
91   }
92
93  private:
94   int register_param_count_;
95
96   // The Register params are allocated dynamically by the
97   // InterfaceDescriptor, and freed on destruction. This is because static
98   // arrays of Registers cause creation of runtime static initializers
99   // which we don't want.
100   SmartArrayPointer<Register> register_params_;
101   // Specifies Representations for the stub's parameter. Points to an array of
102   // Representations of the same length of the numbers of parameters to the
103   // stub, or if NULL (the default value), Representation of each parameter
104   // assumed to be Tagged().
105   SmartArrayPointer<Representation> register_param_representations_;
106
107   PlatformInterfaceDescriptor* platform_specific_descriptor_;
108
109   DISALLOW_COPY_AND_ASSIGN(CallInterfaceDescriptorData);
110 };
111
112
113 class CallDescriptors {
114  public:
115   enum Key {
116 #define DEF_ENUM(name) name,
117     INTERFACE_DESCRIPTOR_LIST(DEF_ENUM)
118 #undef DEF_ENUM
119     NUMBER_OF_DESCRIPTORS
120   };
121 };
122
123
124 class CallInterfaceDescriptor {
125  public:
126   CallInterfaceDescriptor() : data_(NULL) {}
127
128   CallInterfaceDescriptor(Isolate* isolate, CallDescriptors::Key key)
129       : data_(isolate->call_descriptor_data(key)) {}
130
131   int GetEnvironmentLength() const { return data()->register_param_count(); }
132
133   int GetRegisterParameterCount() const {
134     return data()->register_param_count();
135   }
136
137   Register GetParameterRegister(int index) const {
138     return data()->register_param(index);
139   }
140
141   Representation GetParameterRepresentation(int index) const {
142     DCHECK(index < data()->register_param_count());
143     if (data()->register_param_representations() == NULL) {
144       return Representation::Tagged();
145     }
146
147     return data()->register_param_representation(index);
148   }
149
150   // "Environment" versions of parameter functions. The first register
151   // parameter (context) is not included.
152   int GetEnvironmentParameterCount() const {
153     return GetEnvironmentLength() - 1;
154   }
155
156   Register GetEnvironmentParameterRegister(int index) const {
157     return GetParameterRegister(index + 1);
158   }
159
160   Representation GetEnvironmentParameterRepresentation(int index) const {
161     return GetParameterRepresentation(index + 1);
162   }
163
164   // Some platforms have extra information to associate with the descriptor.
165   PlatformInterfaceDescriptor* platform_specific_descriptor() const {
166     return data()->platform_specific_descriptor();
167   }
168
169   static const Register ContextRegister();
170
171   const char* DebugName(Isolate* isolate) const;
172
173  protected:
174   const CallInterfaceDescriptorData* data() const { return data_; }
175
176  private:
177   const CallInterfaceDescriptorData* data_;
178 };
179
180
181 #define DECLARE_DESCRIPTOR(name, base)                                     \
182   explicit name(Isolate* isolate) : base(isolate, key()) {                 \
183     if (!data()->IsInitialized())                                          \
184       Initialize(isolate->call_descriptor_data(key()));                    \
185   }                                                                        \
186                                                                            \
187  protected:                                                                \
188   void Initialize(CallInterfaceDescriptorData* data);                      \
189   name(Isolate* isolate, CallDescriptors::Key key) : base(isolate, key) {} \
190                                                                            \
191  public:                                                                   \
192   static inline CallDescriptors::Key key();
193
194
195 // LoadDescriptor is used by all stubs that implement Load/KeyedLoad ICs.
196 class LoadDescriptor : public CallInterfaceDescriptor {
197  public:
198   DECLARE_DESCRIPTOR(LoadDescriptor, CallInterfaceDescriptor)
199
200   enum ParameterIndices { kReceiverIndex, kNameIndex };
201   static const Register ReceiverRegister();
202   static const Register NameRegister();
203 };
204
205
206 class StoreDescriptor : public CallInterfaceDescriptor {
207  public:
208   DECLARE_DESCRIPTOR(StoreDescriptor, CallInterfaceDescriptor)
209
210   enum ParameterIndices {
211     kReceiverIndex,
212     kNameIndex,
213     kValueIndex,
214     kParameterCount
215   };
216   static const Register ReceiverRegister();
217   static const Register NameRegister();
218   static const Register ValueRegister();
219 };
220
221
222 class StoreTransitionDescriptor : public StoreDescriptor {
223  public:
224   DECLARE_DESCRIPTOR(StoreTransitionDescriptor, StoreDescriptor)
225
226   // Extends StoreDescriptor with Map parameter.
227   enum ParameterIndices {
228     kReceiverIndex,
229     kNameIndex,
230     kValueIndex,
231     kMapIndex,
232     kParameterCount
233   };
234   static const Register MapRegister();
235 };
236
237
238 class ElementTransitionAndStoreDescriptor : public StoreDescriptor {
239  public:
240   DECLARE_DESCRIPTOR(ElementTransitionAndStoreDescriptor, StoreDescriptor)
241
242   static const Register MapRegister();
243 };
244
245
246 class InstanceofDescriptor : public CallInterfaceDescriptor {
247  public:
248   DECLARE_DESCRIPTOR(InstanceofDescriptor, CallInterfaceDescriptor)
249
250   enum ParameterIndices { kLeftIndex, kRightIndex, kParameterCount };
251   static const Register left();
252   static const Register right();
253 };
254
255
256 class VectorLoadICTrampolineDescriptor : public LoadDescriptor {
257  public:
258   DECLARE_DESCRIPTOR(VectorLoadICTrampolineDescriptor, LoadDescriptor)
259
260   enum ParameterIndices { kReceiverIndex, kNameIndex, kSlotIndex };
261
262   static const Register SlotRegister();
263 };
264
265
266 class VectorLoadICDescriptor : public VectorLoadICTrampolineDescriptor {
267  public:
268   DECLARE_DESCRIPTOR(VectorLoadICDescriptor, VectorLoadICTrampolineDescriptor)
269
270   enum ParameterIndices {
271     kReceiverIndex,
272     kNameIndex,
273     kSlotIndex,
274     kVectorIndex
275   };
276
277   static const Register VectorRegister();
278 };
279
280
281 class FastNewClosureDescriptor : public CallInterfaceDescriptor {
282  public:
283   DECLARE_DESCRIPTOR(FastNewClosureDescriptor, CallInterfaceDescriptor)
284 };
285
286
287 class FastNewContextDescriptor : public CallInterfaceDescriptor {
288  public:
289   DECLARE_DESCRIPTOR(FastNewContextDescriptor, CallInterfaceDescriptor)
290 };
291
292
293 class ToNumberDescriptor : public CallInterfaceDescriptor {
294  public:
295   DECLARE_DESCRIPTOR(ToNumberDescriptor, CallInterfaceDescriptor)
296 };
297
298
299 class NumberToStringDescriptor : public CallInterfaceDescriptor {
300  public:
301   DECLARE_DESCRIPTOR(NumberToStringDescriptor, CallInterfaceDescriptor)
302 };
303
304
305 class FastCloneShallowArrayDescriptor : public CallInterfaceDescriptor {
306  public:
307   DECLARE_DESCRIPTOR(FastCloneShallowArrayDescriptor, CallInterfaceDescriptor)
308 };
309
310
311 class FastCloneShallowObjectDescriptor : public CallInterfaceDescriptor {
312  public:
313   DECLARE_DESCRIPTOR(FastCloneShallowObjectDescriptor, CallInterfaceDescriptor)
314 };
315
316
317 class CreateAllocationSiteDescriptor : public CallInterfaceDescriptor {
318  public:
319   DECLARE_DESCRIPTOR(CreateAllocationSiteDescriptor, CallInterfaceDescriptor)
320 };
321
322
323 class CreateWeakCellDescriptor : public CallInterfaceDescriptor {
324  public:
325   enum ParameterIndices {
326     kVectorIndex,
327     kSlotIndex,
328     kValueIndex,
329     kParameterCount
330   };
331
332   DECLARE_DESCRIPTOR(CreateWeakCellDescriptor, CallInterfaceDescriptor)
333 };
334
335
336 class CallFunctionDescriptor : public CallInterfaceDescriptor {
337  public:
338   DECLARE_DESCRIPTOR(CallFunctionDescriptor, CallInterfaceDescriptor)
339 };
340
341
342 class CallFunctionWithFeedbackDescriptor : public CallInterfaceDescriptor {
343  public:
344   DECLARE_DESCRIPTOR(CallFunctionWithFeedbackDescriptor,
345                      CallInterfaceDescriptor)
346 };
347
348
349 class CallFunctionWithFeedbackAndVectorDescriptor
350     : public CallInterfaceDescriptor {
351  public:
352   DECLARE_DESCRIPTOR(CallFunctionWithFeedbackAndVectorDescriptor,
353                      CallInterfaceDescriptor)
354 };
355
356
357 class CallConstructDescriptor : public CallInterfaceDescriptor {
358  public:
359   DECLARE_DESCRIPTOR(CallConstructDescriptor, CallInterfaceDescriptor)
360 };
361
362
363 class RegExpConstructResultDescriptor : public CallInterfaceDescriptor {
364  public:
365   DECLARE_DESCRIPTOR(RegExpConstructResultDescriptor, CallInterfaceDescriptor)
366 };
367
368
369 class TransitionElementsKindDescriptor : public CallInterfaceDescriptor {
370  public:
371   DECLARE_DESCRIPTOR(TransitionElementsKindDescriptor, CallInterfaceDescriptor)
372 };
373
374
375 class AllocateHeapNumberDescriptor : public CallInterfaceDescriptor {
376  public:
377   DECLARE_DESCRIPTOR(AllocateHeapNumberDescriptor, CallInterfaceDescriptor)
378 };
379
380
381 class ArrayConstructorConstantArgCountDescriptor
382     : public CallInterfaceDescriptor {
383  public:
384   DECLARE_DESCRIPTOR(ArrayConstructorConstantArgCountDescriptor,
385                      CallInterfaceDescriptor)
386 };
387
388
389 class ArrayConstructorDescriptor : public CallInterfaceDescriptor {
390  public:
391   DECLARE_DESCRIPTOR(ArrayConstructorDescriptor, CallInterfaceDescriptor)
392 };
393
394
395 class InternalArrayConstructorConstantArgCountDescriptor
396     : public CallInterfaceDescriptor {
397  public:
398   DECLARE_DESCRIPTOR(InternalArrayConstructorConstantArgCountDescriptor,
399                      CallInterfaceDescriptor)
400 };
401
402
403 class InternalArrayConstructorDescriptor : public CallInterfaceDescriptor {
404  public:
405   DECLARE_DESCRIPTOR(InternalArrayConstructorDescriptor,
406                      CallInterfaceDescriptor)
407 };
408
409
410 class CompareDescriptor : public CallInterfaceDescriptor {
411  public:
412   DECLARE_DESCRIPTOR(CompareDescriptor, CallInterfaceDescriptor)
413 };
414
415
416 class CompareNilDescriptor : public CallInterfaceDescriptor {
417  public:
418   DECLARE_DESCRIPTOR(CompareNilDescriptor, CallInterfaceDescriptor)
419 };
420
421
422 class ToBooleanDescriptor : public CallInterfaceDescriptor {
423  public:
424   DECLARE_DESCRIPTOR(ToBooleanDescriptor, CallInterfaceDescriptor)
425 };
426
427
428 class BinaryOpDescriptor : public CallInterfaceDescriptor {
429  public:
430   DECLARE_DESCRIPTOR(BinaryOpDescriptor, CallInterfaceDescriptor)
431 };
432
433
434 class BinaryOpWithAllocationSiteDescriptor : public CallInterfaceDescriptor {
435  public:
436   DECLARE_DESCRIPTOR(BinaryOpWithAllocationSiteDescriptor,
437                      CallInterfaceDescriptor)
438 };
439
440
441 class StringAddDescriptor : public CallInterfaceDescriptor {
442  public:
443   DECLARE_DESCRIPTOR(StringAddDescriptor, CallInterfaceDescriptor)
444 };
445
446
447 class KeyedDescriptor : public CallInterfaceDescriptor {
448  public:
449   DECLARE_DESCRIPTOR(KeyedDescriptor, CallInterfaceDescriptor)
450 };
451
452
453 class NamedDescriptor : public CallInterfaceDescriptor {
454  public:
455   DECLARE_DESCRIPTOR(NamedDescriptor, CallInterfaceDescriptor)
456 };
457
458
459 class CallHandlerDescriptor : public CallInterfaceDescriptor {
460  public:
461   DECLARE_DESCRIPTOR(CallHandlerDescriptor, CallInterfaceDescriptor)
462 };
463
464
465 class ArgumentAdaptorDescriptor : public CallInterfaceDescriptor {
466  public:
467   DECLARE_DESCRIPTOR(ArgumentAdaptorDescriptor, CallInterfaceDescriptor)
468 };
469
470
471 class ApiFunctionDescriptor : public CallInterfaceDescriptor {
472  public:
473   DECLARE_DESCRIPTOR(ApiFunctionDescriptor, CallInterfaceDescriptor)
474 };
475
476
477 class ApiAccessorDescriptor : public CallInterfaceDescriptor {
478  public:
479   DECLARE_DESCRIPTOR(ApiAccessorDescriptor, CallInterfaceDescriptor)
480 };
481
482
483 class ApiGetterDescriptor : public CallInterfaceDescriptor {
484  public:
485   DECLARE_DESCRIPTOR(ApiGetterDescriptor, CallInterfaceDescriptor)
486
487   static const Register function_address();
488 };
489
490
491 class ArgumentsAccessReadDescriptor : public CallInterfaceDescriptor {
492  public:
493   DECLARE_DESCRIPTOR(ArgumentsAccessReadDescriptor, CallInterfaceDescriptor)
494
495   static const Register index();
496   static const Register parameter_count();
497 };
498
499
500 class StoreArrayLiteralElementDescriptor : public CallInterfaceDescriptor {
501  public:
502   DECLARE_DESCRIPTOR(StoreArrayLiteralElementDescriptor,
503                      CallInterfaceDescriptor)
504 };
505
506
507 class MathPowTaggedDescriptor : public CallInterfaceDescriptor {
508  public:
509   DECLARE_DESCRIPTOR(MathPowTaggedDescriptor, CallInterfaceDescriptor)
510
511   static const Register exponent();
512 };
513
514
515 class MathPowIntegerDescriptor : public CallInterfaceDescriptor {
516  public:
517   DECLARE_DESCRIPTOR(MathPowIntegerDescriptor, CallInterfaceDescriptor)
518
519   static const Register exponent();
520 };
521
522
523 class ContextOnlyDescriptor : public CallInterfaceDescriptor {
524  public:
525   DECLARE_DESCRIPTOR(ContextOnlyDescriptor, CallInterfaceDescriptor)
526 };
527
528 #undef DECLARE_DESCRIPTOR
529
530
531 // We define the association between CallDescriptors::Key and the specialized
532 // descriptor here to reduce boilerplate and mistakes.
533 #define DEF_KEY(name) \
534   CallDescriptors::Key name##Descriptor::key() { return CallDescriptors::name; }
535 INTERFACE_DESCRIPTOR_LIST(DEF_KEY)
536 #undef DEF_KEY
537 }
538 }  // namespace v8::internal
539
540
541 #if V8_TARGET_ARCH_ARM64
542 #include "src/arm64/interface-descriptors-arm64.h"
543 #elif V8_TARGET_ARCH_ARM
544 #include "src/arm/interface-descriptors-arm.h"
545 #endif
546
547 #endif  // V8_CALL_INTERFACE_DESCRIPTOR_H_