89ee9759a9575bd7732eb32346946d23ac535f08
[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(), 1, isolate->interface_descriptor_zone());
121   function->InitParameter(0, UntaggedSigned32());
122   return function;
123 }
124
125
126 void LoadGlobalViaContextDescriptor::InitializePlatformSpecific(
127     CallInterfaceDescriptorData* data) {
128   Register registers[] = {SlotRegister()};
129   data->InitializePlatformSpecific(arraysize(registers), registers);
130 }
131
132
133 Type::FunctionType*
134 StoreGlobalViaContextDescriptor::BuildCallInterfaceDescriptorFunctionType(
135     Isolate* isolate, int paramater_count) {
136   Type::FunctionType* function = Type::FunctionType::New(
137       AnyTagged(), Type::Undefined(), 2, isolate->interface_descriptor_zone());
138   function->InitParameter(0, UntaggedSigned32());
139   function->InitParameter(1, AnyTagged());
140   return function;
141 }
142
143
144 void StoreGlobalViaContextDescriptor::InitializePlatformSpecific(
145     CallInterfaceDescriptorData* data) {
146   Register registers[] = {SlotRegister(), ValueRegister()};
147   data->InitializePlatformSpecific(arraysize(registers), registers);
148 }
149
150
151 void InstanceofDescriptor::InitializePlatformSpecific(
152     CallInterfaceDescriptorData* data) {
153   Register registers[] = {left(), right()};
154   data->InitializePlatformSpecific(arraysize(registers), registers);
155 }
156
157
158 void MathPowTaggedDescriptor::InitializePlatformSpecific(
159     CallInterfaceDescriptorData* data) {
160   Register registers[] = {exponent()};
161   data->InitializePlatformSpecific(arraysize(registers), registers);
162 }
163
164
165 void MathPowIntegerDescriptor::InitializePlatformSpecific(
166     CallInterfaceDescriptorData* data) {
167   Register registers[] = {exponent()};
168   data->InitializePlatformSpecific(arraysize(registers), registers);
169 }
170
171
172 Type::FunctionType*
173 LoadWithVectorDescriptor::BuildCallInterfaceDescriptorFunctionType(
174     Isolate* isolate, int paramater_count) {
175   Type::FunctionType* function = Type::FunctionType::New(
176       AnyTagged(), Type::Undefined(), 4, isolate->interface_descriptor_zone());
177   function->InitParameter(0, AnyTagged());
178   function->InitParameter(1, AnyTagged());
179   function->InitParameter(2, SmiType());
180   function->InitParameter(3, AnyTagged());
181   return function;
182 }
183
184
185 void LoadWithVectorDescriptor::InitializePlatformSpecific(
186     CallInterfaceDescriptorData* data) {
187   Register registers[] = {ReceiverRegister(), NameRegister(), SlotRegister(),
188                           VectorRegister()};
189   data->InitializePlatformSpecific(arraysize(registers), registers);
190 }
191
192
193 Type::FunctionType*
194 VectorStoreICDescriptor::BuildCallInterfaceDescriptorFunctionType(
195     Isolate* isolate, int paramater_count) {
196   Type::FunctionType* function = Type::FunctionType::New(
197       AnyTagged(), Type::Undefined(), 5, isolate->interface_descriptor_zone());
198   function->InitParameter(0, AnyTagged());
199   function->InitParameter(1, AnyTagged());
200   function->InitParameter(2, AnyTagged());
201   function->InitParameter(3, SmiType());
202   function->InitParameter(4, AnyTagged());
203   return function;
204 }
205
206
207 void VectorStoreICDescriptor::InitializePlatformSpecific(
208     CallInterfaceDescriptorData* data) {
209   Register registers[] = {ReceiverRegister(), NameRegister(), ValueRegister(),
210                           SlotRegister(), VectorRegister()};
211   data->InitializePlatformSpecific(arraysize(registers), registers);
212 }
213
214
215 Type::FunctionType*
216 VectorStoreICTrampolineDescriptor::BuildCallInterfaceDescriptorFunctionType(
217     Isolate* isolate, int paramater_count) {
218   Type::FunctionType* function = Type::FunctionType::New(
219       AnyTagged(), Type::Undefined(), 4, isolate->interface_descriptor_zone());
220   function->InitParameter(0, AnyTagged());
221   function->InitParameter(1, AnyTagged());
222   function->InitParameter(2, AnyTagged());
223   function->InitParameter(3, SmiType());
224   return function;
225 }
226
227
228 void VectorStoreICTrampolineDescriptor::InitializePlatformSpecific(
229     CallInterfaceDescriptorData* data) {
230   Register registers[] = {ReceiverRegister(), NameRegister(), ValueRegister(),
231                           SlotRegister()};
232   data->InitializePlatformSpecific(arraysize(registers), registers);
233 }
234
235
236 Type::FunctionType*
237 ApiGetterDescriptor::BuildCallInterfaceDescriptorFunctionType(
238     Isolate* isolate, int paramater_count) {
239   Type::FunctionType* function = Type::FunctionType::New(
240       AnyTagged(), Type::Undefined(), 1, isolate->interface_descriptor_zone());
241   function->InitParameter(0, ExternalPointer());
242   return function;
243 }
244
245
246 void ApiGetterDescriptor::InitializePlatformSpecific(
247     CallInterfaceDescriptorData* data) {
248   Register registers[] = {function_address()};
249   data->InitializePlatformSpecific(arraysize(registers), registers);
250 }
251
252
253 void ArgumentsAccessReadDescriptor::InitializePlatformSpecific(
254     CallInterfaceDescriptorData* data) {
255   Register registers[] = {index(), parameter_count()};
256   data->InitializePlatformSpecific(arraysize(registers), registers);
257 }
258
259
260 void ContextOnlyDescriptor::InitializePlatformSpecific(
261     CallInterfaceDescriptorData* data) {
262   data->InitializePlatformSpecific(0, nullptr);
263 }
264
265
266 void GrowArrayElementsDescriptor::InitializePlatformSpecific(
267     CallInterfaceDescriptorData* data) {
268   Register registers[] = {ObjectRegister(), KeyRegister()};
269   data->InitializePlatformSpecific(arraysize(registers), registers);
270 }
271
272
273 Type::FunctionType*
274 FastCloneShallowArrayDescriptor::BuildCallInterfaceDescriptorFunctionType(
275     Isolate* isolate, int paramater_count) {
276   Type::FunctionType* function = Type::FunctionType::New(
277       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
278   function->InitParameter(0, AnyTagged());
279   function->InitParameter(1, SmiType());
280   function->InitParameter(2, AnyTagged());
281   return function;
282 }
283
284
285 Type::FunctionType*
286 CreateAllocationSiteDescriptor::BuildCallInterfaceDescriptorFunctionType(
287     Isolate* isolate, int paramater_count) {
288   Type::FunctionType* function = Type::FunctionType::New(
289       AnyTagged(), Type::Undefined(), 2, isolate->interface_descriptor_zone());
290   function->InitParameter(0, AnyTagged());
291   function->InitParameter(1, SmiType());
292   return function;
293 }
294
295
296 Type::FunctionType*
297 CreateWeakCellDescriptor::BuildCallInterfaceDescriptorFunctionType(
298     Isolate* isolate, int paramater_count) {
299   Type::FunctionType* function = Type::FunctionType::New(
300       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
301   function->InitParameter(0, AnyTagged());
302   function->InitParameter(1, SmiType());
303   function->InitParameter(2, AnyTagged());
304   return function;
305 }
306
307
308 Type::FunctionType*
309 CallFunctionWithFeedbackDescriptor::BuildCallInterfaceDescriptorFunctionType(
310     Isolate* isolate, int paramater_count) {
311   Type::FunctionType* function = Type::FunctionType::New(
312       AnyTagged(), Type::Undefined(), 2, isolate->interface_descriptor_zone());
313   function->InitParameter(0, Type::Receiver());  // JSFunction
314   function->InitParameter(1, SmiType());
315   return function;
316 }
317
318
319 Type::FunctionType* CallFunctionWithFeedbackAndVectorDescriptor::
320     BuildCallInterfaceDescriptorFunctionType(Isolate* isolate,
321                                              int paramater_count) {
322   Type::FunctionType* function = Type::FunctionType::New(
323       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
324   function->InitParameter(0, Type::Receiver());  // JSFunction
325   function->InitParameter(1, SmiType());
326   function->InitParameter(2, AnyTagged());
327   return function;
328 }
329
330
331 Type::FunctionType*
332 ArrayConstructorDescriptor::BuildCallInterfaceDescriptorFunctionType(
333     Isolate* isolate, int paramater_count) {
334   Type::FunctionType* function = Type::FunctionType::New(
335       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
336   function->InitParameter(0, Type::Receiver());  // JSFunction
337   function->InitParameter(1, AnyTagged());
338   function->InitParameter(2, UntaggedSigned32());
339   return function;
340 }
341
342
343 Type::FunctionType*
344 InternalArrayConstructorDescriptor::BuildCallInterfaceDescriptorFunctionType(
345     Isolate* isolate, int paramater_count) {
346   Type::FunctionType* function = Type::FunctionType::New(
347       AnyTagged(), Type::Undefined(), 2, isolate->interface_descriptor_zone());
348   function->InitParameter(0, Type::Receiver());  // JSFunction
349   function->InitParameter(1, UntaggedSigned32());
350   return function;
351 }
352
353
354 Type::FunctionType*
355 ArgumentAdaptorDescriptor::BuildCallInterfaceDescriptorFunctionType(
356     Isolate* isolate, int paramater_count) {
357   Type::FunctionType* function = Type::FunctionType::New(
358       AnyTagged(), Type::Undefined(), 3, isolate->interface_descriptor_zone());
359   function->InitParameter(0, Type::Receiver());    // JSFunction
360   function->InitParameter(1, UntaggedSigned32());  // actual number of arguments
361   function->InitParameter(2,
362                           UntaggedSigned32());  // expected number of arguments
363   return function;
364 }
365
366
367 Type::FunctionType*
368 ApiFunctionDescriptor::BuildCallInterfaceDescriptorFunctionType(
369     Isolate* isolate, int paramater_count) {
370   Type::FunctionType* function = Type::FunctionType::New(
371       AnyTagged(), Type::Undefined(), 5, isolate->interface_descriptor_zone());
372   function->InitParameter(0, AnyTagged());         // callee
373   function->InitParameter(1, AnyTagged());         // call_data
374   function->InitParameter(2, AnyTagged());         // holder
375   function->InitParameter(3, ExternalPointer());   // api_function_address
376   function->InitParameter(4, UntaggedSigned32());  // actual number of arguments
377   return function;
378 }
379
380
381 Type::FunctionType*
382 ApiAccessorDescriptor::BuildCallInterfaceDescriptorFunctionType(
383     Isolate* isolate, int paramater_count) {
384   Type::FunctionType* function = Type::FunctionType::New(
385       AnyTagged(), Type::Undefined(), 4, isolate->interface_descriptor_zone());
386   function->InitParameter(0, AnyTagged());        // callee
387   function->InitParameter(1, AnyTagged());        // call_data
388   function->InitParameter(2, AnyTagged());        // holder
389   function->InitParameter(3, ExternalPointer());  // api_function_address
390   return function;
391 }
392
393
394 Type::FunctionType* MathRoundVariantCallFromUnoptimizedCodeDescriptor::
395     BuildCallInterfaceDescriptorFunctionType(Isolate* isolate,
396                                              int paramater_count) {
397   Type::FunctionType* function = Type::FunctionType::New(
398       AnyTagged(), Type::Undefined(), 4, isolate->interface_descriptor_zone());
399   function->InitParameter(0, Type::Receiver());
400   function->InitParameter(1, SmiType());
401   function->InitParameter(2, AnyTagged());
402   function->InitParameter(3, AnyTagged());
403   return function;
404 }
405
406
407 Type::FunctionType* MathRoundVariantCallFromOptimizedCodeDescriptor::
408     BuildCallInterfaceDescriptorFunctionType(Isolate* isolate,
409                                              int paramater_count) {
410   Type::FunctionType* function = Type::FunctionType::New(
411       AnyTagged(), Type::Undefined(), 5, isolate->interface_descriptor_zone());
412   function->InitParameter(0, Type::Receiver());
413   function->InitParameter(1, SmiType());
414   function->InitParameter(2, AnyTagged());
415   function->InitParameter(3, AnyTagged());
416   function->InitParameter(4, AnyTagged());
417   return function;
418 }
419 }  // namespace internal
420 }  // namespace v8