blob: fbfdd5f644c1b921973b7472b28c66e3393d8f2d [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005#include "src/code-factory.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006
7#include "src/bootstrapper.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/ic/ic.h"
9
10namespace v8 {
11namespace internal {
12
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013
Ben Murdochb8a8cc12014-11-26 15:28:44 +000014// static
Ben Murdoch097c5b22016-05-18 11:27:45 +010015Callable CodeFactory::LoadIC(Isolate* isolate, TypeofMode typeof_mode) {
16 return Callable(LoadIC::initialize_stub(
17 isolate, LoadICState(typeof_mode).GetExtraICState()),
18 LoadDescriptor(isolate));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019}
20
21
22// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000023Callable CodeFactory::LoadICInOptimizedCode(
Ben Murdoch097c5b22016-05-18 11:27:45 +010024 Isolate* isolate, TypeofMode typeof_mode,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000025 InlineCacheState initialization_state) {
26 auto code = LoadIC::initialize_stub_in_optimized_code(
Ben Murdoch097c5b22016-05-18 11:27:45 +010027 isolate, LoadICState(typeof_mode).GetExtraICState(),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028 initialization_state);
29 return Callable(code, LoadWithVectorDescriptor(isolate));
Emily Bernierd0a1eb72015-03-24 16:35:39 -040030}
31
32
33// static
Ben Murdoch097c5b22016-05-18 11:27:45 +010034Callable CodeFactory::KeyedLoadIC(Isolate* isolate) {
35 return Callable(KeyedLoadIC::initialize_stub(isolate, kNoExtraICState),
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036 LoadDescriptor(isolate));
37}
38
39
40// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000041Callable CodeFactory::KeyedLoadICInOptimizedCode(
Ben Murdoch097c5b22016-05-18 11:27:45 +010042 Isolate* isolate, InlineCacheState initialization_state) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000043 auto code = KeyedLoadIC::initialize_stub_in_optimized_code(
Ben Murdoch097c5b22016-05-18 11:27:45 +010044 isolate, initialization_state, kNoExtraICState);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000045 if (initialization_state != MEGAMORPHIC) {
46 return Callable(code, LoadWithVectorDescriptor(isolate));
Emily Bernierd0a1eb72015-03-24 16:35:39 -040047 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000048 return Callable(code, LoadDescriptor(isolate));
Emily Bernierd0a1eb72015-03-24 16:35:39 -040049}
50
51
52// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000053Callable CodeFactory::CallIC(Isolate* isolate, int argc,
Ben Murdoch097c5b22016-05-18 11:27:45 +010054 ConvertReceiverMode mode,
55 TailCallMode tail_call_mode) {
56 return Callable(CallIC::initialize_stub(isolate, argc, mode, tail_call_mode),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000057 CallFunctionWithFeedbackDescriptor(isolate));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000058}
59
60
61// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000062Callable CodeFactory::CallICInOptimizedCode(Isolate* isolate, int argc,
Ben Murdoch097c5b22016-05-18 11:27:45 +010063 ConvertReceiverMode mode,
64 TailCallMode tail_call_mode) {
65 return Callable(CallIC::initialize_stub_in_optimized_code(isolate, argc, mode,
66 tail_call_mode),
67 CallFunctionWithFeedbackAndVectorDescriptor(isolate));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000068}
69
70
71// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000072Callable CodeFactory::StoreIC(Isolate* isolate, LanguageMode language_mode) {
73 return Callable(
74 StoreIC::initialize_stub(isolate, language_mode, UNINITIALIZED),
75 VectorStoreICTrampolineDescriptor(isolate));
76}
77
78
79// static
80Callable CodeFactory::StoreICInOptimizedCode(
81 Isolate* isolate, LanguageMode language_mode,
82 InlineCacheState initialization_state) {
83 CallInterfaceDescriptor descriptor = initialization_state != MEGAMORPHIC
84 ? VectorStoreICDescriptor(isolate)
85 : StoreDescriptor(isolate);
86 return Callable(StoreIC::initialize_stub_in_optimized_code(
87 isolate, language_mode, initialization_state),
88 descriptor);
89}
90
91
92// static
93Callable CodeFactory::KeyedStoreIC(Isolate* isolate,
94 LanguageMode language_mode) {
95 return Callable(
96 KeyedStoreIC::initialize_stub(isolate, language_mode, UNINITIALIZED),
97 VectorStoreICTrampolineDescriptor(isolate));
98}
99
100
101// static
102Callable CodeFactory::KeyedStoreICInOptimizedCode(
103 Isolate* isolate, LanguageMode language_mode,
104 InlineCacheState initialization_state) {
105 CallInterfaceDescriptor descriptor = initialization_state != MEGAMORPHIC
106 ? VectorStoreICDescriptor(isolate)
107 : StoreDescriptor(isolate);
108 return Callable(KeyedStoreIC::initialize_stub_in_optimized_code(
109 isolate, language_mode, initialization_state),
110 descriptor);
111}
112
113
114// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100115Callable CodeFactory::CompareIC(Isolate* isolate, Token::Value op) {
116 Handle<Code> code = CompareIC::GetUninitialized(isolate, op);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000117 return Callable(code, CompareDescriptor(isolate));
118}
119
120
121// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100122Callable CodeFactory::BinaryOpIC(Isolate* isolate, Token::Value op) {
123 BinaryOpICStub stub(isolate, op);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000124 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
125}
126
127
128// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000129Callable CodeFactory::InstanceOf(Isolate* isolate) {
130 InstanceOfStub stub(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000131 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
132}
133
134
135// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000136Callable CodeFactory::ToBoolean(Isolate* isolate) {
Ben Murdochda12d292016-06-02 14:46:10 +0100137 ToBooleanStub stub(isolate);
138 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000139}
140
141
142// static
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000143Callable CodeFactory::ToNumber(Isolate* isolate) {
144 ToNumberStub stub(isolate);
145 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
146}
147
148
149// static
Ben Murdochda12d292016-06-02 14:46:10 +0100150Callable CodeFactory::NonNumberToNumber(Isolate* isolate) {
151 NonNumberToNumberStub stub(isolate);
152 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
153}
154
155// static
156Callable CodeFactory::StringToNumber(Isolate* isolate) {
157 StringToNumberStub stub(isolate);
158 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
159}
160
161// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000162Callable CodeFactory::ToString(Isolate* isolate) {
163 ToStringStub stub(isolate);
164 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
165}
166
167
168// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100169Callable CodeFactory::ToName(Isolate* isolate) {
170 ToNameStub stub(isolate);
171 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
172}
173
174
175// static
Ben Murdochda12d292016-06-02 14:46:10 +0100176Callable CodeFactory::ToInteger(Isolate* isolate) {
177 ToIntegerStub stub(isolate);
178 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
179}
180
181// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000182Callable CodeFactory::ToLength(Isolate* isolate) {
183 ToLengthStub stub(isolate);
184 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
185}
186
187
188// static
189Callable CodeFactory::ToObject(Isolate* isolate) {
190 ToObjectStub stub(isolate);
191 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
192}
193
194
195// static
196Callable CodeFactory::NumberToString(Isolate* isolate) {
197 NumberToStringStub stub(isolate);
198 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
199}
200
201
202// static
203Callable CodeFactory::RegExpConstructResult(Isolate* isolate) {
204 RegExpConstructResultStub stub(isolate);
205 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
206}
207
208
209// static
210Callable CodeFactory::RegExpExec(Isolate* isolate) {
211 RegExpExecStub stub(isolate);
212 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
213}
214
Ben Murdochda12d292016-06-02 14:46:10 +0100215// static
216Callable CodeFactory::Add(Isolate* isolate) {
217 AddStub stub(isolate);
218 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
219}
220
221// static
222Callable CodeFactory::Subtract(Isolate* isolate) {
223 SubtractStub stub(isolate);
224 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
225}
226
227// static
228Callable CodeFactory::BitwiseAnd(Isolate* isolate) {
229 BitwiseAndStub stub(isolate);
230 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
231}
232
233// static
234Callable CodeFactory::BitwiseOr(Isolate* isolate) {
235 BitwiseOrStub stub(isolate);
236 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
237}
238
239// static
240Callable CodeFactory::BitwiseXor(Isolate* isolate) {
241 BitwiseXorStub stub(isolate);
242 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
243}
244
245// static
246Callable CodeFactory::LessThan(Isolate* isolate) {
247 LessThanStub stub(isolate);
248 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
249}
250
251// static
252Callable CodeFactory::LessThanOrEqual(Isolate* isolate) {
253 LessThanOrEqualStub stub(isolate);
254 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
255}
256
257// static
258Callable CodeFactory::GreaterThan(Isolate* isolate) {
259 GreaterThanStub stub(isolate);
260 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
261}
262
263// static
264Callable CodeFactory::GreaterThanOrEqual(Isolate* isolate) {
265 GreaterThanOrEqualStub stub(isolate);
266 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
267}
268
269// static
270Callable CodeFactory::Equal(Isolate* isolate) {
271 EqualStub stub(isolate);
272 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
273}
274
275// static
276Callable CodeFactory::NotEqual(Isolate* isolate) {
277 NotEqualStub stub(isolate);
278 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
279}
280
281// static
282Callable CodeFactory::StrictEqual(Isolate* isolate) {
283 StrictEqualStub stub(isolate);
284 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
285}
286
287// static
288Callable CodeFactory::StrictNotEqual(Isolate* isolate) {
289 StrictNotEqualStub stub(isolate);
290 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
291}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000292
293// static
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000294Callable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags,
295 PretenureFlag pretenure_flag) {
296 StringAddStub stub(isolate, flags, pretenure_flag);
297 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
298}
299
Ben Murdochda12d292016-06-02 14:46:10 +0100300// static
301Callable CodeFactory::StringCompare(Isolate* isolate, Token::Value token) {
302 switch (token) {
303 case Token::EQ:
304 case Token::EQ_STRICT:
305 return StringEqual(isolate);
306 case Token::NE:
307 case Token::NE_STRICT:
308 return StringNotEqual(isolate);
309 case Token::LT:
310 return StringLessThan(isolate);
311 case Token::GT:
312 return StringGreaterThan(isolate);
313 case Token::LTE:
314 return StringLessThanOrEqual(isolate);
315 case Token::GTE:
316 return StringGreaterThanOrEqual(isolate);
317 default:
318 break;
319 }
320 UNREACHABLE();
321 return StringEqual(isolate);
322}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000323
324// static
Ben Murdochda12d292016-06-02 14:46:10 +0100325Callable CodeFactory::StringEqual(Isolate* isolate) {
326 StringEqualStub stub(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000327 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
328}
329
Ben Murdochda12d292016-06-02 14:46:10 +0100330// static
331Callable CodeFactory::StringNotEqual(Isolate* isolate) {
332 StringNotEqualStub stub(isolate);
333 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
334}
335
336// static
337Callable CodeFactory::StringLessThan(Isolate* isolate) {
338 StringLessThanStub stub(isolate);
339 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
340}
341
342// static
343Callable CodeFactory::StringLessThanOrEqual(Isolate* isolate) {
344 StringLessThanOrEqualStub stub(isolate);
345 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
346}
347
348// static
349Callable CodeFactory::StringGreaterThan(Isolate* isolate) {
350 StringGreaterThanStub stub(isolate);
351 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
352}
353
354// static
355Callable CodeFactory::StringGreaterThanOrEqual(Isolate* isolate) {
356 StringGreaterThanOrEqualStub stub(isolate);
357 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
358}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000359
360// static
361Callable CodeFactory::SubString(Isolate* isolate) {
362 SubStringStub stub(isolate);
363 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
364}
365
366
367// static
Ben Murdochda12d292016-06-02 14:46:10 +0100368Callable CodeFactory::StoreInterceptor(Isolate* isolate) {
369 StoreInterceptorStub stub(isolate);
370 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
371}
372
373// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000374Callable CodeFactory::Typeof(Isolate* isolate) {
375 TypeofStub stub(isolate);
376 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
377}
378
379
380// static
381Callable CodeFactory::FastCloneRegExp(Isolate* isolate) {
382 FastCloneRegExpStub stub(isolate);
383 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
384}
385
386
387// static
388Callable CodeFactory::FastCloneShallowArray(Isolate* isolate) {
389 // TODO(mstarzinger): Thread through AllocationSiteMode at some point.
390 FastCloneShallowArrayStub stub(isolate, DONT_TRACK_ALLOCATION_SITE);
391 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
392}
393
394
395// static
396Callable CodeFactory::FastCloneShallowObject(Isolate* isolate, int length) {
397 FastCloneShallowObjectStub stub(isolate, length);
398 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
399}
400
401
402// static
403Callable CodeFactory::FastNewContext(Isolate* isolate, int slot_count) {
404 FastNewContextStub stub(isolate, slot_count);
405 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
406}
407
408
409// static
410Callable CodeFactory::FastNewClosure(Isolate* isolate,
411 LanguageMode language_mode,
412 FunctionKind kind) {
413 FastNewClosureStub stub(isolate, language_mode, kind);
414 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
415}
416
417
418// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100419Callable CodeFactory::FastNewObject(Isolate* isolate) {
420 FastNewObjectStub stub(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000421 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
422}
423
424
425// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100426Callable CodeFactory::FastNewRestParameter(Isolate* isolate) {
427 FastNewRestParameterStub stub(isolate);
428 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
429}
430
431
432// static
433Callable CodeFactory::FastNewSloppyArguments(Isolate* isolate) {
434 FastNewSloppyArgumentsStub stub(isolate);
435 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
436}
437
438
439// static
440Callable CodeFactory::FastNewStrictArguments(Isolate* isolate) {
441 FastNewStrictArgumentsStub stub(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000442 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
443}
444
445
446// static
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400447Callable CodeFactory::AllocateHeapNumber(Isolate* isolate) {
448 AllocateHeapNumberStub stub(isolate);
449 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
450}
451
452
453// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000454Callable CodeFactory::AllocateMutableHeapNumber(Isolate* isolate) {
455 AllocateMutableHeapNumberStub stub(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000456 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
457}
458
Ben Murdochda12d292016-06-02 14:46:10 +0100459#define SIMD128_ALLOC(TYPE, Type, type, lane_count, lane_type) \
460 Callable CodeFactory::Allocate##Type(Isolate* isolate) { \
461 Allocate##Type##Stub stub(isolate); \
462 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); \
463 }
464SIMD128_TYPES(SIMD128_ALLOC)
465#undef SIMD128_ALLOC
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000466
467// static
468Callable CodeFactory::AllocateInNewSpace(Isolate* isolate) {
469 AllocateInNewSpaceStub stub(isolate);
470 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
471}
472
473
474// static
475Callable CodeFactory::ArgumentAdaptor(Isolate* isolate) {
476 return Callable(isolate->builtins()->ArgumentsAdaptorTrampoline(),
477 ArgumentAdaptorDescriptor(isolate));
478}
479
480
481// static
Ben Murdochda12d292016-06-02 14:46:10 +0100482Callable CodeFactory::Call(Isolate* isolate, ConvertReceiverMode mode,
483 TailCallMode tail_call_mode) {
484 return Callable(isolate->builtins()->Call(mode, tail_call_mode),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000485 CallTrampolineDescriptor(isolate));
486}
487
488
489// static
490Callable CodeFactory::CallFunction(Isolate* isolate, ConvertReceiverMode mode) {
491 return Callable(isolate->builtins()->CallFunction(mode),
492 CallTrampolineDescriptor(isolate));
493}
494
495
496// static
497Callable CodeFactory::Construct(Isolate* isolate) {
498 return Callable(isolate->builtins()->Construct(),
499 ConstructTrampolineDescriptor(isolate));
500}
501
502
503// static
504Callable CodeFactory::ConstructFunction(Isolate* isolate) {
505 return Callable(isolate->builtins()->ConstructFunction(),
506 ConstructTrampolineDescriptor(isolate));
507}
508
509
510// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100511Callable CodeFactory::InterpreterPushArgsAndCall(Isolate* isolate,
512 TailCallMode tail_call_mode) {
513 return Callable(
514 isolate->builtins()->InterpreterPushArgsAndCall(tail_call_mode),
515 InterpreterPushArgsAndCallDescriptor(isolate));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000516}
517
518
519// static
520Callable CodeFactory::InterpreterPushArgsAndConstruct(Isolate* isolate) {
521 return Callable(isolate->builtins()->InterpreterPushArgsAndConstruct(),
522 InterpreterPushArgsAndConstructDescriptor(isolate));
523}
524
525
526// static
527Callable CodeFactory::InterpreterCEntry(Isolate* isolate, int result_size) {
528 // Note: If we ever use fpregs in the interpreter then we will need to
529 // save fpregs too.
530 CEntryStub stub(isolate, result_size, kDontSaveFPRegs, kArgvInRegister);
531 return Callable(stub.GetCode(), InterpreterCEntryDescriptor(isolate));
532}
533
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000534} // namespace internal
535} // namespace v8