Correctify instanceof and make it optimizable.
[platform/upstream/v8.git] / src / code-factory.cc
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.
4
5 #include "src/code-factory.h"
6
7 #include "src/bootstrapper.h"
8 #include "src/ic/ic.h"
9
10 namespace v8 {
11 namespace internal {
12
13
14 // static
15 Callable CodeFactory::LoadIC(Isolate* isolate, TypeofMode typeof_mode,
16                              LanguageMode language_mode) {
17   return Callable(
18       LoadIC::initialize_stub(
19           isolate, LoadICState(typeof_mode, language_mode).GetExtraICState()),
20       LoadDescriptor(isolate));
21 }
22
23
24 // static
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));
32 }
33
34
35 // static
36 Callable CodeFactory::KeyedLoadIC(Isolate* isolate,
37                                   LanguageMode language_mode) {
38   ExtraICState state = is_strong(language_mode) ? LoadICState::kStrongModeState
39                                                 : kNoExtraICState;
40   return Callable(KeyedLoadIC::initialize_stub(isolate, state),
41                   LoadDescriptor(isolate));
42 }
43
44
45 // static
46 Callable CodeFactory::KeyedLoadICInOptimizedCode(
47     Isolate* isolate, LanguageMode language_mode,
48     InlineCacheState initialization_state) {
49   ExtraICState state = is_strong(language_mode) ? LoadICState::kStrongModeState
50                                                 : kNoExtraICState;
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));
55   }
56   return Callable(code, LoadDescriptor(isolate));
57 }
58
59
60 // static
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));
65 }
66
67
68 // static
69 Callable CodeFactory::CallICInOptimizedCode(Isolate* isolate, int argc,
70                                             CallICState::CallType call_type) {
71   return Callable(
72       CallIC::initialize_stub_in_optimized_code(isolate, argc, call_type),
73       CallFunctionWithFeedbackAndVectorDescriptor(isolate));
74 }
75
76
77 // static
78 Callable CodeFactory::StoreIC(Isolate* isolate, LanguageMode language_mode) {
79   return Callable(
80       StoreIC::initialize_stub(isolate, language_mode, UNINITIALIZED),
81       FLAG_vector_stores ? VectorStoreICTrampolineDescriptor(isolate)
82                          : StoreDescriptor(isolate));
83 }
84
85
86 // static
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),
96                   descriptor);
97 }
98
99
100 // static
101 Callable CodeFactory::KeyedStoreIC(Isolate* isolate,
102                                    LanguageMode language_mode) {
103   return Callable(
104       KeyedStoreIC::initialize_stub(isolate, language_mode, UNINITIALIZED),
105       FLAG_vector_stores ? VectorStoreICTrampolineDescriptor(isolate)
106                          : StoreDescriptor(isolate));
107 }
108
109
110 // static
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),
120                   descriptor);
121 }
122
123
124 // static
125 Callable CodeFactory::CompareIC(Isolate* isolate, Token::Value op,
126                                 Strength strength) {
127   Handle<Code> code = CompareIC::GetUninitialized(isolate, op, strength);
128   return Callable(code, CompareDescriptor(isolate));
129 }
130
131
132 // static
133 Callable CodeFactory::BinaryOpIC(Isolate* isolate, Token::Value op,
134                                  Strength strength) {
135   BinaryOpICStub stub(isolate, op, strength);
136   return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
137 }
138
139
140 // static
141 Callable CodeFactory::LoadGlobalViaContext(Isolate* isolate, int depth) {
142   LoadGlobalViaContextStub stub(isolate, depth);
143   return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
144 }
145
146
147 // static
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());
152 }
153
154
155 // static
156 Callable CodeFactory::InstanceOf(Isolate* isolate) {
157   InstanceOfStub stub(isolate);
158   return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
159 }
160
161
162 // static
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());
168 }
169
170
171 // static
172 Callable CodeFactory::ToNumber(Isolate* isolate) {
173   ToNumberStub stub(isolate);
174   return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
175 }
176
177
178 // static
179 Callable CodeFactory::ToObject(Isolate* isolate) {
180   ToObjectStub stub(isolate);
181   return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
182 }
183
184
185 // static
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());
190 }
191
192
193 // static
194 Callable CodeFactory::Typeof(Isolate* isolate) {
195   TypeofStub stub(isolate);
196   return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
197 }
198
199
200 // static
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());
205 }
206
207
208 // static
209 Callable CodeFactory::FastCloneShallowObject(Isolate* isolate, int length) {
210   FastCloneShallowObjectStub stub(isolate, length);
211   return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
212 }
213
214
215 // static
216 Callable CodeFactory::FastNewClosure(Isolate* isolate,
217                                      LanguageMode language_mode,
218                                      FunctionKind kind) {
219   FastNewClosureStub stub(isolate, language_mode, kind);
220   return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
221 }
222
223
224 // static
225 Callable CodeFactory::AllocateHeapNumber(Isolate* isolate) {
226   AllocateHeapNumberStub stub(isolate);
227   return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
228 }
229
230
231 // static
232 Callable CodeFactory::CallFunction(Isolate* isolate, int argc,
233                                    CallFunctionFlags flags) {
234   CallFunctionStub stub(isolate, argc, flags);
235   return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
236 }
237
238 }  // namespace internal
239 }  // namespace v8