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.
5 #include "src/code-factory.h"
7 #include "src/bootstrapper.h"
15 Callable CodeFactory::LoadIC(Isolate* isolate, TypeofMode typeof_mode,
16 LanguageMode language_mode) {
18 LoadIC::initialize_stub(
19 isolate, LoadICState(typeof_mode, language_mode).GetExtraICState()),
20 LoadDescriptor(isolate));
25 Callable CodeFactory::LoadICInOptimizedCode(
26 Isolate* isolate, TypeofMode typeof_mode, LanguageMode language_mode,
27 InlineCacheState initialization_state) {
28 auto code = LoadIC::initialize_stub_in_optimized_code(
29 isolate, LoadICState(typeof_mode, language_mode).GetExtraICState(),
30 initialization_state);
31 return Callable(code, LoadWithVectorDescriptor(isolate));
36 Callable CodeFactory::KeyedLoadIC(Isolate* isolate,
37 LanguageMode language_mode) {
38 ExtraICState state = is_strong(language_mode) ? LoadICState::kStrongModeState
40 return Callable(KeyedLoadIC::initialize_stub(isolate, state),
41 LoadDescriptor(isolate));
46 Callable CodeFactory::KeyedLoadICInOptimizedCode(
47 Isolate* isolate, LanguageMode language_mode,
48 InlineCacheState initialization_state) {
49 ExtraICState state = is_strong(language_mode) ? LoadICState::kStrongModeState
51 auto code = KeyedLoadIC::initialize_stub_in_optimized_code(
52 isolate, initialization_state, state);
53 if (initialization_state != MEGAMORPHIC) {
54 return Callable(code, LoadWithVectorDescriptor(isolate));
56 return Callable(code, LoadDescriptor(isolate));
61 Callable CodeFactory::CallIC(Isolate* isolate, int argc,
62 CallICState::CallType call_type) {
63 return Callable(CallIC::initialize_stub(isolate, argc, call_type),
64 CallFunctionWithFeedbackDescriptor(isolate));
69 Callable CodeFactory::CallICInOptimizedCode(Isolate* isolate, int argc,
70 CallICState::CallType call_type) {
72 CallIC::initialize_stub_in_optimized_code(isolate, argc, call_type),
73 CallFunctionWithFeedbackAndVectorDescriptor(isolate));
78 Callable CodeFactory::StoreIC(Isolate* isolate, LanguageMode language_mode) {
80 StoreIC::initialize_stub(isolate, language_mode, UNINITIALIZED),
81 FLAG_vector_stores ? VectorStoreICTrampolineDescriptor(isolate)
82 : StoreDescriptor(isolate));
87 Callable CodeFactory::StoreICInOptimizedCode(
88 Isolate* isolate, LanguageMode language_mode,
89 InlineCacheState initialization_state) {
90 CallInterfaceDescriptor descriptor =
91 FLAG_vector_stores && initialization_state != MEGAMORPHIC
92 ? VectorStoreICDescriptor(isolate)
93 : StoreDescriptor(isolate);
94 return Callable(StoreIC::initialize_stub_in_optimized_code(
95 isolate, language_mode, initialization_state),
101 Callable CodeFactory::KeyedStoreIC(Isolate* isolate,
102 LanguageMode language_mode) {
104 KeyedStoreIC::initialize_stub(isolate, language_mode, UNINITIALIZED),
105 FLAG_vector_stores ? VectorStoreICTrampolineDescriptor(isolate)
106 : StoreDescriptor(isolate));
111 Callable CodeFactory::KeyedStoreICInOptimizedCode(
112 Isolate* isolate, LanguageMode language_mode,
113 InlineCacheState initialization_state) {
114 CallInterfaceDescriptor descriptor =
115 FLAG_vector_stores && initialization_state != MEGAMORPHIC
116 ? VectorStoreICDescriptor(isolate)
117 : StoreDescriptor(isolate);
118 return Callable(KeyedStoreIC::initialize_stub_in_optimized_code(
119 isolate, language_mode, initialization_state),
125 Callable CodeFactory::CompareIC(Isolate* isolate, Token::Value op,
127 Handle<Code> code = CompareIC::GetUninitialized(isolate, op, strength);
128 return Callable(code, CompareDescriptor(isolate));
133 Callable CodeFactory::BinaryOpIC(Isolate* isolate, Token::Value op,
135 BinaryOpICStub stub(isolate, op, strength);
136 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
141 Callable CodeFactory::LoadGlobalViaContext(Isolate* isolate, int depth) {
142 LoadGlobalViaContextStub stub(isolate, depth);
143 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
148 Callable CodeFactory::StoreGlobalViaContext(Isolate* isolate, int depth,
149 LanguageMode language_mode) {
150 StoreGlobalViaContextStub stub(isolate, depth, language_mode);
151 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
156 Callable CodeFactory::InstanceOf(Isolate* isolate) {
157 InstanceOfStub stub(isolate);
158 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
163 Callable CodeFactory::ToBoolean(Isolate* isolate,
164 ToBooleanStub::ResultMode mode,
165 ToBooleanStub::Types types) {
166 ToBooleanStub stub(isolate, mode, types);
167 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
172 Callable CodeFactory::ToNumber(Isolate* isolate) {
173 ToNumberStub stub(isolate);
174 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
179 Callable CodeFactory::ToObject(Isolate* isolate) {
180 ToObjectStub stub(isolate);
181 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
186 Callable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags,
187 PretenureFlag pretenure_flag) {
188 StringAddStub stub(isolate, flags, pretenure_flag);
189 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
194 Callable CodeFactory::Typeof(Isolate* isolate) {
195 TypeofStub stub(isolate);
196 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
201 Callable CodeFactory::FastCloneShallowArray(Isolate* isolate) {
202 // TODO(mstarzinger): Thread through AllocationSiteMode at some point.
203 FastCloneShallowArrayStub stub(isolate, DONT_TRACK_ALLOCATION_SITE);
204 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
209 Callable CodeFactory::FastCloneShallowObject(Isolate* isolate, int length) {
210 FastCloneShallowObjectStub stub(isolate, length);
211 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
216 Callable CodeFactory::FastNewClosure(Isolate* isolate,
217 LanguageMode language_mode,
219 FastNewClosureStub stub(isolate, language_mode, kind);
220 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
225 Callable CodeFactory::AllocateHeapNumber(Isolate* isolate) {
226 AllocateHeapNumberStub stub(isolate);
227 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
232 Callable CodeFactory::CallFunction(Isolate* isolate, int argc,
233 CallFunctionFlags flags) {
234 CallFunctionStub stub(isolate, argc, flags);
235 return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
238 } // namespace internal