blob: 9898282d31d958ad1c08991e60e2c210c73a2d76 [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
122Callable CodeFactory::CompareNilIC(Isolate* isolate, NilValue nil_value) {
123 Handle<Code> code = CompareNilICStub::GetUninitialized(isolate, nil_value);
124 return Callable(code, CompareNilDescriptor(isolate));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000125}
126
127
128// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100129Callable CodeFactory::BinaryOpIC(Isolate* isolate, Token::Value op) {
130 BinaryOpICStub stub(isolate, op);
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::InstanceOf(Isolate* isolate) {
137 InstanceOfStub stub(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000138 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
139}
140
141
142// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000143Callable CodeFactory::ToBoolean(Isolate* isolate) {
144 Handle<Code> code = ToBooleanStub::GetUninitialized(isolate);
145 return Callable(code, ToBooleanDescriptor(isolate));
146}
147
148
149// static
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000150Callable CodeFactory::ToNumber(Isolate* isolate) {
151 ToNumberStub stub(isolate);
152 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
153}
154
155
156// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000157Callable CodeFactory::ToString(Isolate* isolate) {
158 ToStringStub stub(isolate);
159 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
160}
161
162
163// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100164Callable CodeFactory::ToName(Isolate* isolate) {
165 ToNameStub stub(isolate);
166 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
167}
168
169
170// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000171Callable CodeFactory::ToLength(Isolate* isolate) {
172 ToLengthStub stub(isolate);
173 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
174}
175
176
177// static
178Callable CodeFactory::ToObject(Isolate* isolate) {
179 ToObjectStub stub(isolate);
180 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
181}
182
183
184// static
185Callable CodeFactory::NumberToString(Isolate* isolate) {
186 NumberToStringStub stub(isolate);
187 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
188}
189
190
191// static
192Callable CodeFactory::RegExpConstructResult(Isolate* isolate) {
193 RegExpConstructResultStub stub(isolate);
194 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
195}
196
197
198// static
199Callable CodeFactory::RegExpExec(Isolate* isolate) {
200 RegExpExecStub stub(isolate);
201 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
202}
203
204
205// static
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000206Callable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags,
207 PretenureFlag pretenure_flag) {
208 StringAddStub stub(isolate, flags, pretenure_flag);
209 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
210}
211
212
213// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000214Callable CodeFactory::StringCompare(Isolate* isolate) {
215 StringCompareStub stub(isolate);
216 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
217}
218
219
220// static
221Callable CodeFactory::SubString(Isolate* isolate) {
222 SubStringStub stub(isolate);
223 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
224}
225
226
227// static
228Callable CodeFactory::Typeof(Isolate* isolate) {
229 TypeofStub stub(isolate);
230 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
231}
232
233
234// static
235Callable CodeFactory::FastCloneRegExp(Isolate* isolate) {
236 FastCloneRegExpStub stub(isolate);
237 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
238}
239
240
241// static
242Callable CodeFactory::FastCloneShallowArray(Isolate* isolate) {
243 // TODO(mstarzinger): Thread through AllocationSiteMode at some point.
244 FastCloneShallowArrayStub stub(isolate, DONT_TRACK_ALLOCATION_SITE);
245 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
246}
247
248
249// static
250Callable CodeFactory::FastCloneShallowObject(Isolate* isolate, int length) {
251 FastCloneShallowObjectStub stub(isolate, length);
252 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
253}
254
255
256// static
257Callable CodeFactory::FastNewContext(Isolate* isolate, int slot_count) {
258 FastNewContextStub stub(isolate, slot_count);
259 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
260}
261
262
263// static
264Callable CodeFactory::FastNewClosure(Isolate* isolate,
265 LanguageMode language_mode,
266 FunctionKind kind) {
267 FastNewClosureStub stub(isolate, language_mode, kind);
268 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
269}
270
271
272// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100273Callable CodeFactory::FastNewObject(Isolate* isolate) {
274 FastNewObjectStub stub(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000275 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
276}
277
278
279// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100280Callable CodeFactory::FastNewRestParameter(Isolate* isolate) {
281 FastNewRestParameterStub stub(isolate);
282 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
283}
284
285
286// static
287Callable CodeFactory::FastNewSloppyArguments(Isolate* isolate) {
288 FastNewSloppyArgumentsStub stub(isolate);
289 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
290}
291
292
293// static
294Callable CodeFactory::FastNewStrictArguments(Isolate* isolate) {
295 FastNewStrictArgumentsStub stub(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000296 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
297}
298
299
300// static
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400301Callable CodeFactory::AllocateHeapNumber(Isolate* isolate) {
302 AllocateHeapNumberStub stub(isolate);
303 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
304}
305
306
307// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000308Callable CodeFactory::AllocateMutableHeapNumber(Isolate* isolate) {
309 AllocateMutableHeapNumberStub stub(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000310 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
311}
312
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000313
314// static
315Callable CodeFactory::AllocateInNewSpace(Isolate* isolate) {
316 AllocateInNewSpaceStub stub(isolate);
317 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
318}
319
320
321// static
322Callable CodeFactory::ArgumentAdaptor(Isolate* isolate) {
323 return Callable(isolate->builtins()->ArgumentsAdaptorTrampoline(),
324 ArgumentAdaptorDescriptor(isolate));
325}
326
327
328// static
329Callable CodeFactory::Call(Isolate* isolate, ConvertReceiverMode mode) {
330 return Callable(isolate->builtins()->Call(mode),
331 CallTrampolineDescriptor(isolate));
332}
333
334
335// static
336Callable CodeFactory::CallFunction(Isolate* isolate, ConvertReceiverMode mode) {
337 return Callable(isolate->builtins()->CallFunction(mode),
338 CallTrampolineDescriptor(isolate));
339}
340
341
342// static
343Callable CodeFactory::Construct(Isolate* isolate) {
344 return Callable(isolate->builtins()->Construct(),
345 ConstructTrampolineDescriptor(isolate));
346}
347
348
349// static
350Callable CodeFactory::ConstructFunction(Isolate* isolate) {
351 return Callable(isolate->builtins()->ConstructFunction(),
352 ConstructTrampolineDescriptor(isolate));
353}
354
355
356// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100357Callable CodeFactory::InterpreterPushArgsAndCall(Isolate* isolate,
358 TailCallMode tail_call_mode) {
359 return Callable(
360 isolate->builtins()->InterpreterPushArgsAndCall(tail_call_mode),
361 InterpreterPushArgsAndCallDescriptor(isolate));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000362}
363
364
365// static
366Callable CodeFactory::InterpreterPushArgsAndConstruct(Isolate* isolate) {
367 return Callable(isolate->builtins()->InterpreterPushArgsAndConstruct(),
368 InterpreterPushArgsAndConstructDescriptor(isolate));
369}
370
371
372// static
373Callable CodeFactory::InterpreterCEntry(Isolate* isolate, int result_size) {
374 // Note: If we ever use fpregs in the interpreter then we will need to
375 // save fpregs too.
376 CEntryStub stub(isolate, result_size, kDontSaveFPRegs, kArgvInRegister);
377 return Callable(stub.GetCode(), InterpreterCEntryDescriptor(isolate));
378}
379
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000380} // namespace internal
381} // namespace v8