Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5 | #include "src/code-factory.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6 | |
| 7 | #include "src/bootstrapper.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/ic/ic.h" |
| 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 14 | // static |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 15 | Callable CodeFactory::LoadIC(Isolate* isolate, TypeofMode typeof_mode) { |
| 16 | return Callable(LoadIC::initialize_stub( |
| 17 | isolate, LoadICState(typeof_mode).GetExtraICState()), |
| 18 | LoadDescriptor(isolate)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | |
| 22 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 23 | Callable CodeFactory::LoadICInOptimizedCode( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 24 | Isolate* isolate, TypeofMode typeof_mode, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 25 | InlineCacheState initialization_state) { |
| 26 | auto code = LoadIC::initialize_stub_in_optimized_code( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 27 | isolate, LoadICState(typeof_mode).GetExtraICState(), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | initialization_state); |
| 29 | return Callable(code, LoadWithVectorDescriptor(isolate)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | |
| 33 | // static |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 34 | Callable CodeFactory::KeyedLoadIC(Isolate* isolate) { |
| 35 | return Callable(KeyedLoadIC::initialize_stub(isolate, kNoExtraICState), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 36 | LoadDescriptor(isolate)); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 41 | Callable CodeFactory::KeyedLoadICInOptimizedCode( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 42 | Isolate* isolate, InlineCacheState initialization_state) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 43 | auto code = KeyedLoadIC::initialize_stub_in_optimized_code( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 44 | isolate, initialization_state, kNoExtraICState); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 45 | if (initialization_state != MEGAMORPHIC) { |
| 46 | return Callable(code, LoadWithVectorDescriptor(isolate)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 47 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 48 | return Callable(code, LoadDescriptor(isolate)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | |
| 52 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | Callable CodeFactory::CallIC(Isolate* isolate, int argc, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 54 | ConvertReceiverMode mode, |
| 55 | TailCallMode tail_call_mode) { |
| 56 | return Callable(CallIC::initialize_stub(isolate, argc, mode, tail_call_mode), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 57 | CallFunctionWithFeedbackDescriptor(isolate)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | |
| 61 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 62 | Callable CodeFactory::CallICInOptimizedCode(Isolate* isolate, int argc, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 63 | 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 Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | |
| 71 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 72 | Callable 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 |
| 80 | Callable 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 |
| 93 | Callable 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 |
| 102 | Callable 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 Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 115 | Callable CodeFactory::CompareIC(Isolate* isolate, Token::Value op) { |
| 116 | Handle<Code> code = CompareIC::GetUninitialized(isolate, op); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 117 | return Callable(code, CompareDescriptor(isolate)); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | // static |
| 122 | Callable CodeFactory::CompareNilIC(Isolate* isolate, NilValue nil_value) { |
| 123 | Handle<Code> code = CompareNilICStub::GetUninitialized(isolate, nil_value); |
| 124 | return Callable(code, CompareNilDescriptor(isolate)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | |
| 128 | // static |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 129 | Callable CodeFactory::BinaryOpIC(Isolate* isolate, Token::Value op) { |
| 130 | BinaryOpICStub stub(isolate, op); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 131 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 136 | Callable CodeFactory::InstanceOf(Isolate* isolate) { |
| 137 | InstanceOfStub stub(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 138 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 143 | Callable CodeFactory::ToBoolean(Isolate* isolate) { |
| 144 | Handle<Code> code = ToBooleanStub::GetUninitialized(isolate); |
| 145 | return Callable(code, ToBooleanDescriptor(isolate)); |
| 146 | } |
| 147 | |
| 148 | |
| 149 | // static |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | Callable CodeFactory::ToNumber(Isolate* isolate) { |
| 151 | ToNumberStub stub(isolate); |
| 152 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 153 | } |
| 154 | |
| 155 | |
| 156 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 157 | Callable CodeFactory::ToString(Isolate* isolate) { |
| 158 | ToStringStub stub(isolate); |
| 159 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 160 | } |
| 161 | |
| 162 | |
| 163 | // static |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 164 | Callable CodeFactory::ToName(Isolate* isolate) { |
| 165 | ToNameStub stub(isolate); |
| 166 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 167 | } |
| 168 | |
| 169 | |
| 170 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 171 | Callable CodeFactory::ToLength(Isolate* isolate) { |
| 172 | ToLengthStub stub(isolate); |
| 173 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | // static |
| 178 | Callable CodeFactory::ToObject(Isolate* isolate) { |
| 179 | ToObjectStub stub(isolate); |
| 180 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 181 | } |
| 182 | |
| 183 | |
| 184 | // static |
| 185 | Callable CodeFactory::NumberToString(Isolate* isolate) { |
| 186 | NumberToStringStub stub(isolate); |
| 187 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 188 | } |
| 189 | |
| 190 | |
| 191 | // static |
| 192 | Callable CodeFactory::RegExpConstructResult(Isolate* isolate) { |
| 193 | RegExpConstructResultStub stub(isolate); |
| 194 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 195 | } |
| 196 | |
| 197 | |
| 198 | // static |
| 199 | Callable CodeFactory::RegExpExec(Isolate* isolate) { |
| 200 | RegExpExecStub stub(isolate); |
| 201 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 202 | } |
| 203 | |
| 204 | |
| 205 | // static |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 206 | Callable 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 214 | Callable CodeFactory::StringCompare(Isolate* isolate) { |
| 215 | StringCompareStub stub(isolate); |
| 216 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 217 | } |
| 218 | |
| 219 | |
| 220 | // static |
| 221 | Callable CodeFactory::SubString(Isolate* isolate) { |
| 222 | SubStringStub stub(isolate); |
| 223 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 224 | } |
| 225 | |
| 226 | |
| 227 | // static |
| 228 | Callable CodeFactory::Typeof(Isolate* isolate) { |
| 229 | TypeofStub stub(isolate); |
| 230 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 231 | } |
| 232 | |
| 233 | |
| 234 | // static |
| 235 | Callable CodeFactory::FastCloneRegExp(Isolate* isolate) { |
| 236 | FastCloneRegExpStub stub(isolate); |
| 237 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | // static |
| 242 | Callable 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 |
| 250 | Callable CodeFactory::FastCloneShallowObject(Isolate* isolate, int length) { |
| 251 | FastCloneShallowObjectStub stub(isolate, length); |
| 252 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 253 | } |
| 254 | |
| 255 | |
| 256 | // static |
| 257 | Callable 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 |
| 264 | Callable 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 Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 273 | Callable CodeFactory::FastNewObject(Isolate* isolate) { |
| 274 | FastNewObjectStub stub(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 275 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 276 | } |
| 277 | |
| 278 | |
| 279 | // static |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 280 | Callable CodeFactory::FastNewRestParameter(Isolate* isolate) { |
| 281 | FastNewRestParameterStub stub(isolate); |
| 282 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 283 | } |
| 284 | |
| 285 | |
| 286 | // static |
| 287 | Callable CodeFactory::FastNewSloppyArguments(Isolate* isolate) { |
| 288 | FastNewSloppyArgumentsStub stub(isolate); |
| 289 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 290 | } |
| 291 | |
| 292 | |
| 293 | // static |
| 294 | Callable CodeFactory::FastNewStrictArguments(Isolate* isolate) { |
| 295 | FastNewStrictArgumentsStub stub(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 296 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 297 | } |
| 298 | |
| 299 | |
| 300 | // static |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 301 | Callable CodeFactory::AllocateHeapNumber(Isolate* isolate) { |
| 302 | AllocateHeapNumberStub stub(isolate); |
| 303 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 304 | } |
| 305 | |
| 306 | |
| 307 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 308 | Callable CodeFactory::AllocateMutableHeapNumber(Isolate* isolate) { |
| 309 | AllocateMutableHeapNumberStub stub(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 310 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 311 | } |
| 312 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 313 | |
| 314 | // static |
| 315 | Callable CodeFactory::AllocateInNewSpace(Isolate* isolate) { |
| 316 | AllocateInNewSpaceStub stub(isolate); |
| 317 | return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); |
| 318 | } |
| 319 | |
| 320 | |
| 321 | // static |
| 322 | Callable CodeFactory::ArgumentAdaptor(Isolate* isolate) { |
| 323 | return Callable(isolate->builtins()->ArgumentsAdaptorTrampoline(), |
| 324 | ArgumentAdaptorDescriptor(isolate)); |
| 325 | } |
| 326 | |
| 327 | |
| 328 | // static |
| 329 | Callable CodeFactory::Call(Isolate* isolate, ConvertReceiverMode mode) { |
| 330 | return Callable(isolate->builtins()->Call(mode), |
| 331 | CallTrampolineDescriptor(isolate)); |
| 332 | } |
| 333 | |
| 334 | |
| 335 | // static |
| 336 | Callable CodeFactory::CallFunction(Isolate* isolate, ConvertReceiverMode mode) { |
| 337 | return Callable(isolate->builtins()->CallFunction(mode), |
| 338 | CallTrampolineDescriptor(isolate)); |
| 339 | } |
| 340 | |
| 341 | |
| 342 | // static |
| 343 | Callable CodeFactory::Construct(Isolate* isolate) { |
| 344 | return Callable(isolate->builtins()->Construct(), |
| 345 | ConstructTrampolineDescriptor(isolate)); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | // static |
| 350 | Callable CodeFactory::ConstructFunction(Isolate* isolate) { |
| 351 | return Callable(isolate->builtins()->ConstructFunction(), |
| 352 | ConstructTrampolineDescriptor(isolate)); |
| 353 | } |
| 354 | |
| 355 | |
| 356 | // static |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 357 | Callable CodeFactory::InterpreterPushArgsAndCall(Isolate* isolate, |
| 358 | TailCallMode tail_call_mode) { |
| 359 | return Callable( |
| 360 | isolate->builtins()->InterpreterPushArgsAndCall(tail_call_mode), |
| 361 | InterpreterPushArgsAndCallDescriptor(isolate)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | |
| 365 | // static |
| 366 | Callable CodeFactory::InterpreterPushArgsAndConstruct(Isolate* isolate) { |
| 367 | return Callable(isolate->builtins()->InterpreterPushArgsAndConstruct(), |
| 368 | InterpreterPushArgsAndConstructDescriptor(isolate)); |
| 369 | } |
| 370 | |
| 371 | |
| 372 | // static |
| 373 | Callable 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 Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 380 | } // namespace internal |
| 381 | } // namespace v8 |