20cd7802ddd76e5a273a0997d682d1ef357ad3a8
[platform/upstream/v8.git] / src / interface-descriptors.cc
1 // Copyright 2012 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 #include "src/v8.h"
6
7 #include "src/interface-descriptors.h"
8
9 namespace v8 {
10 namespace internal {
11
12 namespace {
13 // Constructors for common combined semantic and representation types.
14 Type* SmiType() {
15   return Type::Intersect(Type::SignedSmall(), Type::TaggedSigned());
16 }
17
18
19 Type* UntaggedSigned32() {
20   return Type::Intersect(Type::Signed32(), Type::UntaggedSigned32());
21 }
22
23
24 Type* AnyTagged() {
25   return Type::Intersect(
26       Type::Any(), Type::Union(Type::TaggedPointer(), Type::TaggedSigned()));
27 }
28
29
30 Type* ExternalPointer() {
31   return Type::Intersect(Type::Internal(), Type::UntaggedPointer());
32 }
33 }
34
35
36 Type::FunctionType* CallInterfaceDescriptor::BuildDefaultFunctionType(
37     Isolate* isolate, int parameter_count) {
38   Type::FunctionType* function =
39       Type::FunctionType::New(AnyTagged(), Type::Undefined(), parameter_count,
40                               isolate->interface_descriptor_zone());
41   while (parameter_count-- != 0) {
42     function->InitParameter(parameter_count, AnyTagged());
43   }
44   return function;
45 }
46
47
48 void CallInterfaceDescriptorData::InitializePlatformSpecific(
49     int register_parameter_count, Register* registers,
50     PlatformInterfaceDescriptor* platform_descriptor) {
51   platform_specific_descriptor_ = platform_descriptor;
52   register_param_count_ = register_parameter_count;
53
54   // InterfaceDescriptor owns a copy of the registers array.
55   register_params_.Reset(NewArray<Register>(register_parameter_count));
56   for (int i = 0; i < register_parameter_count; i++) {
57     register_params_[i] = registers[i];
58   }
59 }
60
61 const char* CallInterfaceDescriptor::DebugName(Isolate* isolate) const {
62   CallInterfaceDescriptorData* start = isolate->call_descriptor_data(0);
63   size_t index = data_ - start;
64   DCHECK(index < CallDescriptors::NUMBER_OF_DESCRIPTORS);
65   CallDescriptors::Key key = static_cast<CallDescriptors::Key>(index);
66   switch (key) {
67 #define DEF_CASE(NAME)        \
68   case CallDescriptors::NAME: \
69     return #NAME " Descriptor";
70     INTERFACE_DESCRIPTOR_LIST(DEF_CASE)
71 #undef DEF_CASE
72     case CallDescriptors::NUMBER_OF_DESCRIPTORS:
73       break;
74   }
75   return "";
76 }
77
78
79 Type::FunctionType* LoadDescriptor::BuildCallInterfaceDescriptorFunctionType(
80     Isolate* isolate, int paramater_count) {
81   Type::FunctionType* function = Type::FunctionType::New(
82       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
83   function->InitParameter(0, AnyTagged());
84   function->InitParameter(1, AnyTagged());
85   function->InitParameter(2, SmiType());
86   return function;
87 }
88
89 void LoadDescriptor::InitializePlatformSpecific(
90     CallInterfaceDescriptorData* data) {
91   Register registers[] = {ReceiverRegister(), NameRegister(), SlotRegister()};
92   data->InitializePlatformSpecific(arraysize(registers), registers);
93 }
94
95
96 void StoreDescriptor::InitializePlatformSpecific(
97     CallInterfaceDescriptorData* data) {
98   Register registers[] = {ReceiverRegister(), NameRegister(), ValueRegister()};
99   data->InitializePlatformSpecific(arraysize(registers), registers);
100 }
101
102
103 Type::FunctionType*
104 StoreTransitionDescriptor::BuildCallInterfaceDescriptorFunctionType(
105     Isolate* isolate, int paramater_count) {
106   Type::FunctionType* function = Type::FunctionType::New(
107       AnyTagged(), Type::Undefined(), 4, isolate->interface_descriptor_zone());
108   function->InitParameter(0, AnyTagged());  // Receiver
109   function->InitParameter(1, AnyTagged());  // Name
110   function->InitParameter(2, AnyTagged());  // Value
111   function->InitParameter(3, AnyTagged());  // Map
112   return function;
113 }
114
115
116 Type::FunctionType*
117 LoadGlobalViaContextDescriptor::BuildCallInterfaceDescriptorFunctionType(
118     Isolate* isolate, int paramater_count) {
119   Type::FunctionType* function = Type::FunctionType::New(
120       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
121   function->InitParameter(0, SmiType());
122   function->InitParameter(1, SmiType());
123   function->InitParameter(2, AnyTagged());
124   return function;
125 }
126
127
128 void LoadGlobalViaContextDescriptor::InitializePlatformSpecific(
129     CallInterfaceDescriptorData* data) {
130   Register registers[] = {DepthRegister(), SlotRegister(), NameRegister()};
131   data->InitializePlatformSpecific(arraysize(registers), registers);
132 }
133
134
135 Type::FunctionType*
136 StoreGlobalViaContextDescriptor::BuildCallInterfaceDescriptorFunctionType(
137     Isolate* isolate, int paramater_count) {
138   Type::FunctionType* function = Type::FunctionType::New(
139       AnyTagged(), Type::Undefined(), 4, isolate->interface_descriptor_zone());
140   function->InitParameter(0, SmiType());
141   function->InitParameter(1, SmiType());
142   function->InitParameter(2, AnyTagged());
143   function->InitParameter(3, AnyTagged());
144   return function;
145 }
146
147
148 void StoreGlobalViaContextDescriptor::InitializePlatformSpecific(
149     CallInterfaceDescriptorData* data) {
150   Register registers[] = {DepthRegister(), SlotRegister(), NameRegister(),
151                           ValueRegister()};
152   data->InitializePlatformSpecific(arraysize(registers), registers);
153 }
154
155
156 void InstanceofDescriptor::InitializePlatformSpecific(
157     CallInterfaceDescriptorData* data) {
158   Register registers[] = {left(), right()};
159   data->InitializePlatformSpecific(arraysize(registers), registers);
160 }
161
162
163 void MathPowTaggedDescriptor::InitializePlatformSpecific(
164     CallInterfaceDescriptorData* data) {
165   Register registers[] = {exponent()};
166   data->InitializePlatformSpecific(arraysize(registers), registers);
167 }
168
169
170 void MathPowIntegerDescriptor::InitializePlatformSpecific(
171     CallInterfaceDescriptorData* data) {
172   Register registers[] = {exponent()};
173   data->InitializePlatformSpecific(arraysize(registers), registers);
174 }
175
176
177 Type::FunctionType*
178 LoadWithVectorDescriptor::BuildCallInterfaceDescriptorFunctionType(
179     Isolate* isolate, int paramater_count) {
180   Type::FunctionType* function = Type::FunctionType::New(
181       AnyTagged(), Type::Undefined(), 4, isolate->interface_descriptor_zone());
182   function->InitParameter(0, AnyTagged());
183   function->InitParameter(1, AnyTagged());
184   function->InitParameter(2, SmiType());
185   function->InitParameter(3, AnyTagged());
186   return function;
187 }
188
189
190 void LoadWithVectorDescriptor::InitializePlatformSpecific(
191     CallInterfaceDescriptorData* data) {
192   Register registers[] = {ReceiverRegister(), NameRegister(), SlotRegister(),
193                           VectorRegister()};
194   data->InitializePlatformSpecific(arraysize(registers), registers);
195 }
196
197
198 Type::FunctionType*
199 VectorStoreICDescriptor::BuildCallInterfaceDescriptorFunctionType(
200     Isolate* isolate, int paramater_count) {
201   Type::FunctionType* function = Type::FunctionType::New(
202       AnyTagged(), Type::Undefined(), 5, isolate->interface_descriptor_zone());
203   function->InitParameter(0, AnyTagged());
204   function->InitParameter(1, AnyTagged());
205   function->InitParameter(2, AnyTagged());
206   function->InitParameter(3, SmiType());
207   function->InitParameter(4, AnyTagged());
208   return function;
209 }
210
211
212 void VectorStoreICDescriptor::InitializePlatformSpecific(
213     CallInterfaceDescriptorData* data) {
214   Register registers[] = {ReceiverRegister(), NameRegister(), ValueRegister(),
215                           SlotRegister(), VectorRegister()};
216   data->InitializePlatformSpecific(arraysize(registers), registers);
217 }
218
219
220 Type::FunctionType*
221 VectorStoreICTrampolineDescriptor::BuildCallInterfaceDescriptorFunctionType(
222     Isolate* isolate, int paramater_count) {
223   Type::FunctionType* function = Type::FunctionType::New(
224       AnyTagged(), Type::Undefined(), 4, isolate->interface_descriptor_zone());
225   function->InitParameter(0, AnyTagged());
226   function->InitParameter(1, AnyTagged());
227   function->InitParameter(2, AnyTagged());
228   function->InitParameter(3, SmiType());
229   return function;
230 }
231
232
233 void VectorStoreICTrampolineDescriptor::InitializePlatformSpecific(
234     CallInterfaceDescriptorData* data) {
235   Register registers[] = {ReceiverRegister(), NameRegister(), ValueRegister(),
236                           SlotRegister()};
237   data->InitializePlatformSpecific(arraysize(registers), registers);
238 }
239
240
241 Type::FunctionType*
242 ApiGetterDescriptor::BuildCallInterfaceDescriptorFunctionType(
243     Isolate* isolate, int paramater_count) {
244   Type::FunctionType* function = Type::FunctionType::New(
245       AnyTagged(), Type::Undefined(), 1, isolate->interface_descriptor_zone());
246   function->InitParameter(0, ExternalPointer());
247   return function;
248 }
249
250
251 void ApiGetterDescriptor::InitializePlatformSpecific(
252     CallInterfaceDescriptorData* data) {
253   Register registers[] = {function_address()};
254   data->InitializePlatformSpecific(arraysize(registers), registers);
255 }
256
257
258 void ArgumentsAccessReadDescriptor::InitializePlatformSpecific(
259     CallInterfaceDescriptorData* data) {
260   Register registers[] = {index(), parameter_count()};
261   data->InitializePlatformSpecific(arraysize(registers), registers);
262 }
263
264
265 void ContextOnlyDescriptor::InitializePlatformSpecific(
266     CallInterfaceDescriptorData* data) {
267   data->InitializePlatformSpecific(0, nullptr);
268 }
269
270
271 void GrowArrayElementsDescriptor::InitializePlatformSpecific(
272     CallInterfaceDescriptorData* data) {
273   Register registers[] = {ObjectRegister(), KeyRegister()};
274   data->InitializePlatformSpecific(arraysize(registers), registers);
275 }
276
277
278 Type::FunctionType*
279 FastCloneShallowArrayDescriptor::BuildCallInterfaceDescriptorFunctionType(
280     Isolate* isolate, int paramater_count) {
281   Type::FunctionType* function = Type::FunctionType::New(
282       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
283   function->InitParameter(0, AnyTagged());
284   function->InitParameter(1, SmiType());
285   function->InitParameter(2, AnyTagged());
286   return function;
287 }
288
289
290 Type::FunctionType*
291 CreateAllocationSiteDescriptor::BuildCallInterfaceDescriptorFunctionType(
292     Isolate* isolate, int paramater_count) {
293   Type::FunctionType* function = Type::FunctionType::New(
294       AnyTagged(), Type::Undefined(), 2, isolate->interface_descriptor_zone());
295   function->InitParameter(0, AnyTagged());
296   function->InitParameter(1, SmiType());
297   return function;
298 }
299
300
301 Type::FunctionType*
302 CreateWeakCellDescriptor::BuildCallInterfaceDescriptorFunctionType(
303     Isolate* isolate, int paramater_count) {
304   Type::FunctionType* function = Type::FunctionType::New(
305       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
306   function->InitParameter(0, AnyTagged());
307   function->InitParameter(1, SmiType());
308   function->InitParameter(2, AnyTagged());
309   return function;
310 }
311
312
313 Type::FunctionType*
314 CallFunctionWithFeedbackDescriptor::BuildCallInterfaceDescriptorFunctionType(
315     Isolate* isolate, int paramater_count) {
316   Type::FunctionType* function = Type::FunctionType::New(
317       AnyTagged(), Type::Undefined(), 2, isolate->interface_descriptor_zone());
318   function->InitParameter(0, Type::Receiver());  // JSFunction
319   function->InitParameter(1, SmiType());
320   return function;
321 }
322
323
324 Type::FunctionType* CallFunctionWithFeedbackAndVectorDescriptor::
325     BuildCallInterfaceDescriptorFunctionType(Isolate* isolate,
326                                              int paramater_count) {
327   Type::FunctionType* function = Type::FunctionType::New(
328       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
329   function->InitParameter(0, Type::Receiver());  // JSFunction
330   function->InitParameter(1, SmiType());
331   function->InitParameter(2, AnyTagged());
332   return function;
333 }
334
335
336 Type::FunctionType*
337 ArrayConstructorDescriptor::BuildCallInterfaceDescriptorFunctionType(
338     Isolate* isolate, int paramater_count) {
339   Type::FunctionType* function = Type::FunctionType::New(
340       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
341   function->InitParameter(0, Type::Receiver());  // JSFunction
342   function->InitParameter(1, AnyTagged());
343   function->InitParameter(2, UntaggedSigned32());
344   return function;
345 }
346
347
348 Type::FunctionType*
349 InternalArrayConstructorDescriptor::BuildCallInterfaceDescriptorFunctionType(
350     Isolate* isolate, int paramater_count) {
351   Type::FunctionType* function = Type::FunctionType::New(
352       AnyTagged(), Type::Undefined(), 2, isolate->interface_descriptor_zone());
353   function->InitParameter(0, Type::Receiver());  // JSFunction
354   function->InitParameter(1, UntaggedSigned32());
355   return function;
356 }
357
358
359 Type::FunctionType*
360 ArgumentAdaptorDescriptor::BuildCallInterfaceDescriptorFunctionType(
361     Isolate* isolate, int paramater_count) {
362   Type::FunctionType* function = Type::FunctionType::New(
363       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
364   function->InitParameter(0, Type::Receiver());    // JSFunction
365   function->InitParameter(1, UntaggedSigned32());  // actual number of arguments
366   function->InitParameter(2,
367                           UntaggedSigned32());  // expected number of arguments
368   return function;
369 }
370
371
372 Type::FunctionType*
373 ApiFunctionDescriptor::BuildCallInterfaceDescriptorFunctionType(
374     Isolate* isolate, int paramater_count) {
375   Type::FunctionType* function = Type::FunctionType::New(
376       AnyTagged(), Type::Undefined(), 5, isolate->interface_descriptor_zone());
377   function->InitParameter(0, AnyTagged());         // callee
378   function->InitParameter(1, AnyTagged());         // call_data
379   function->InitParameter(2, AnyTagged());         // holder
380   function->InitParameter(3, ExternalPointer());   // api_function_address
381   function->InitParameter(4, UntaggedSigned32());  // actual number of arguments
382   return function;
383 }
384
385
386 Type::FunctionType*
387 ApiAccessorDescriptor::BuildCallInterfaceDescriptorFunctionType(
388     Isolate* isolate, int paramater_count) {
389   Type::FunctionType* function = Type::FunctionType::New(
390       AnyTagged(), Type::Undefined(), 4, isolate->interface_descriptor_zone());
391   function->InitParameter(0, AnyTagged());        // callee
392   function->InitParameter(1, AnyTagged());        // call_data
393   function->InitParameter(2, AnyTagged());        // holder
394   function->InitParameter(3, ExternalPointer());  // api_function_address
395   return function;
396 }
397
398
399 Type::FunctionType* MathRoundVariantCallFromUnoptimizedCodeDescriptor::
400     BuildCallInterfaceDescriptorFunctionType(Isolate* isolate,
401                                              int paramater_count) {
402   Type::FunctionType* function = Type::FunctionType::New(
403       AnyTagged(), Type::Undefined(), 4, isolate->interface_descriptor_zone());
404   function->InitParameter(0, Type::Receiver());
405   function->InitParameter(1, SmiType());
406   function->InitParameter(2, AnyTagged());
407   function->InitParameter(3, AnyTagged());
408   return function;
409 }
410
411
412 Type::FunctionType* MathRoundVariantCallFromOptimizedCodeDescriptor::
413     BuildCallInterfaceDescriptorFunctionType(Isolate* isolate,
414                                              int paramater_count) {
415   Type::FunctionType* function = Type::FunctionType::New(
416       AnyTagged(), Type::Undefined(), 5, isolate->interface_descriptor_zone());
417   function->InitParameter(0, Type::Receiver());
418   function->InitParameter(1, SmiType());
419   function->InitParameter(2, AnyTagged());
420   function->InitParameter(3, AnyTagged());
421   function->InitParameter(4, AnyTagged());
422   return function;
423 }
424 }  // namespace internal
425 }  // namespace v8