code-factory.cc 17 KB
Newer Older
1 2 3 4
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#include "src/code-factory.h"
6 7 8 9 10 11 12

#include "src/bootstrapper.h"
#include "src/ic/ic.h"

namespace v8 {
namespace internal {

13

14
// static
15
Callable CodeFactory::LoadIC(Isolate* isolate) {
16
  if (FLAG_tf_load_ic_stub) {
ishell's avatar
ishell committed
17
    LoadICTrampolineTFStub stub(isolate);
18 19
    return Callable(stub.GetCode(), LoadDescriptor(isolate));
  }
ishell's avatar
ishell committed
20
  LoadICTrampolineStub stub(isolate);
verwaest's avatar
verwaest committed
21
  return Callable(stub.GetCode(), LoadDescriptor(isolate));
22 23
}

24 25 26 27 28
// static
Callable CodeFactory::ApiGetter(Isolate* isolate) {
  CallApiGetterStub stub(isolate);
  return Callable(stub.GetCode(), ApiGetterDescriptor(isolate));
}
29

30
// static
31
Callable CodeFactory::LoadICInOptimizedCode(Isolate* isolate) {
ishell's avatar
ishell committed
32
  auto code = LoadIC::initialize_stub_in_optimized_code(isolate);
33
  return Callable(code, LoadWithVectorDescriptor(isolate));
34 35
}

36 37
// static
Callable CodeFactory::LoadGlobalIC(Isolate* isolate, TypeofMode typeof_mode) {
ishell's avatar
ishell committed
38
  LoadGlobalICTrampolineStub stub(isolate, LoadGlobalICState(typeof_mode));
39 40 41 42 43 44 45
  return Callable(stub.GetCode(), LoadDescriptor(isolate));
}

// static
Callable CodeFactory::LoadGlobalICInOptimizedCode(Isolate* isolate,
                                                  TypeofMode typeof_mode) {
  auto code = LoadGlobalIC::initialize_stub_in_optimized_code(
ishell's avatar
ishell committed
46
      isolate, LoadGlobalICState(typeof_mode).GetExtraICState());
47 48
  return Callable(code, LoadWithVectorDescriptor(isolate));
}
49

50
// static
51
Callable CodeFactory::KeyedLoadIC(Isolate* isolate) {
ishell's avatar
ishell committed
52
  KeyedLoadICTrampolineStub stub(isolate);
verwaest's avatar
verwaest committed
53
  return Callable(stub.GetCode(), LoadDescriptor(isolate));
54 55 56
}


57
// static
58 59 60 61
Callable CodeFactory::KeyedLoadICInOptimizedCode(Isolate* isolate) {
  auto code =
      KeyedLoadIC::initialize_stub_in_optimized_code(isolate, kNoExtraICState);
  return Callable(code, LoadWithVectorDescriptor(isolate));
62 63 64
}


65
// static
66
Callable CodeFactory::CallIC(Isolate* isolate, int argc,
ishell's avatar
ishell committed
67 68
                             ConvertReceiverMode mode,
                             TailCallMode tail_call_mode) {
verwaest's avatar
verwaest committed
69 70
  CallICTrampolineStub stub(isolate, CallICState(argc, mode, tail_call_mode));
  return Callable(stub.GetCode(), CallFunctionWithFeedbackDescriptor(isolate));
71 72 73 74
}


// static
75
Callable CodeFactory::CallICInOptimizedCode(Isolate* isolate, int argc,
ishell's avatar
ishell committed
76 77 78 79 80
                                            ConvertReceiverMode mode,
                                            TailCallMode tail_call_mode) {
  return Callable(CallIC::initialize_stub_in_optimized_code(isolate, argc, mode,
                                                            tail_call_mode),
                  CallFunctionWithFeedbackAndVectorDescriptor(isolate));
81 82 83
}


84
// static
85
Callable CodeFactory::StoreIC(Isolate* isolate, LanguageMode language_mode) {
verwaest's avatar
verwaest committed
86 87
  VectorStoreICTrampolineStub stub(isolate, StoreICState(language_mode));
  return Callable(stub.GetCode(), VectorStoreICTrampolineDescriptor(isolate));
88 89 90 91
}


// static
92 93 94 95 96 97
Callable CodeFactory::StoreICInOptimizedCode(Isolate* isolate,
                                             LanguageMode language_mode) {
  CallInterfaceDescriptor descriptor = VectorStoreICDescriptor(isolate);
  return Callable(
      StoreIC::initialize_stub_in_optimized_code(isolate, language_mode),
      descriptor);
98 99 100 101
}


// static
102 103
Callable CodeFactory::KeyedStoreIC(Isolate* isolate,
                                   LanguageMode language_mode) {
verwaest's avatar
verwaest committed
104 105
  VectorKeyedStoreICTrampolineStub stub(isolate, StoreICState(language_mode));
  return Callable(stub.GetCode(), VectorStoreICTrampolineDescriptor(isolate));
106 107 108 109
}


// static
110 111 112 113 114 115
Callable CodeFactory::KeyedStoreICInOptimizedCode(Isolate* isolate,
                                                  LanguageMode language_mode) {
  CallInterfaceDescriptor descriptor = VectorStoreICDescriptor(isolate);
  return Callable(
      KeyedStoreIC::initialize_stub_in_optimized_code(isolate, language_mode),
      descriptor);
116 117 118 119
}


// static
120 121
Callable CodeFactory::CompareIC(Isolate* isolate, Token::Value op) {
  Handle<Code> code = CompareIC::GetUninitialized(isolate, op);
122
  return Callable(code, CompareDescriptor(isolate));
123 124 125 126
}


// static
127 128
Callable CodeFactory::BinaryOpIC(Isolate* isolate, Token::Value op) {
  BinaryOpICStub stub(isolate, op);
129
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
130 131 132
}


133
// static
134 135
Callable CodeFactory::InstanceOf(Isolate* isolate) {
  InstanceOfStub stub(isolate);
136 137 138 139
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


140
// static
141
Callable CodeFactory::ToBoolean(Isolate* isolate) {
142 143
  ToBooleanStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
144 145 146 147 148
}


// static
Callable CodeFactory::ToNumber(Isolate* isolate) {
149 150
  return Callable(isolate->builtins()->ToNumber(),
                  TypeConversionDescriptor(isolate));
151 152 153
}


154 155
// static
Callable CodeFactory::NonNumberToNumber(Isolate* isolate) {
156 157
  return Callable(isolate->builtins()->NonNumberToNumber(),
                  TypeConversionDescriptor(isolate));
158 159 160 161
}

// static
Callable CodeFactory::StringToNumber(Isolate* isolate) {
162 163
  return Callable(isolate->builtins()->StringToNumber(),
                  TypeConversionDescriptor(isolate));
164 165
}

166 167 168 169 170 171 172
// static
Callable CodeFactory::ToString(Isolate* isolate) {
  ToStringStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


173 174 175 176 177 178 179
// static
Callable CodeFactory::ToName(Isolate* isolate) {
  ToNameStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


180 181 182 183 184 185
// static
Callable CodeFactory::ToInteger(Isolate* isolate) {
  ToIntegerStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

186 187 188 189 190 191 192
// static
Callable CodeFactory::ToLength(Isolate* isolate) {
  ToLengthStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


193 194 195 196 197 198 199
// static
Callable CodeFactory::ToObject(Isolate* isolate) {
  ToObjectStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


200 201 202 203 204 205 206 207 208 209 210 211 212 213
// static
Callable CodeFactory::NumberToString(Isolate* isolate) {
  NumberToStringStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


// static
Callable CodeFactory::RegExpConstructResult(Isolate* isolate) {
  RegExpConstructResultStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


214 215 216 217 218 219
// static
Callable CodeFactory::RegExpExec(Isolate* isolate) {
  RegExpExecStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

220 221 222 223 224 225 226 227 228 229 230 231
// static
Callable CodeFactory::Add(Isolate* isolate) {
  AddStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::Subtract(Isolate* isolate) {
  SubtractStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

232 233 234 235 236 237
// static
Callable CodeFactory::Multiply(Isolate* isolate) {
  MultiplyStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

238 239 240 241 242 243
// static
Callable CodeFactory::Divide(Isolate* isolate) {
  DivideStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

244 245 246 247 248
// static
Callable CodeFactory::Modulus(Isolate* isolate) {
  ModulusStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266

// static
Callable CodeFactory::ShiftRight(Isolate* isolate) {
  ShiftRightStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::ShiftRightLogical(Isolate* isolate) {
  ShiftRightLogicalStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::ShiftLeft(Isolate* isolate) {
  ShiftLeftStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}
267

268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
// static
Callable CodeFactory::BitwiseAnd(Isolate* isolate) {
  BitwiseAndStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::BitwiseOr(Isolate* isolate) {
  BitwiseOrStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::BitwiseXor(Isolate* isolate) {
  BitwiseXorStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

286 287 288 289 290 291 292 293 294 295 296 297
// static
Callable CodeFactory::Inc(Isolate* isolate) {
  IncStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::Dec(Isolate* isolate) {
  DecStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
// static
Callable CodeFactory::LessThan(Isolate* isolate) {
  LessThanStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::LessThanOrEqual(Isolate* isolate) {
  LessThanOrEqualStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::GreaterThan(Isolate* isolate) {
  GreaterThanStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::GreaterThanOrEqual(Isolate* isolate) {
  GreaterThanOrEqualStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
320 321 322 323 324 325 326 327 328 329 330 331
}

// static
Callable CodeFactory::Equal(Isolate* isolate) {
  EqualStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::NotEqual(Isolate* isolate) {
  NotEqualStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
332 333
}

334 335 336 337 338
// static
Callable CodeFactory::StrictEqual(Isolate* isolate) {
  StrictEqualStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}
339

340 341 342 343 344 345
// static
Callable CodeFactory::StrictNotEqual(Isolate* isolate) {
  StrictNotEqualStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

346 347 348 349 350 351 352
// static
Callable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags,
                                PretenureFlag pretenure_flag) {
  StringAddStub stub(isolate, flags, pretenure_flag);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

353
// static
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
Callable CodeFactory::StringCompare(Isolate* isolate, Token::Value token) {
  switch (token) {
    case Token::EQ:
    case Token::EQ_STRICT:
      return StringEqual(isolate);
    case Token::NE:
    case Token::NE_STRICT:
      return StringNotEqual(isolate);
    case Token::LT:
      return StringLessThan(isolate);
    case Token::GT:
      return StringGreaterThan(isolate);
    case Token::LTE:
      return StringLessThanOrEqual(isolate);
    case Token::GTE:
      return StringGreaterThanOrEqual(isolate);
    default:
      break;
  }
  UNREACHABLE();
  return StringEqual(isolate);
375 376
}

377 378 379 380 381 382 383 384 385 386 387
// static
Callable CodeFactory::StringEqual(Isolate* isolate) {
  StringEqualStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::StringNotEqual(Isolate* isolate) {
  StringNotEqualStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}
388

389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
// static
Callable CodeFactory::StringLessThan(Isolate* isolate) {
  StringLessThanStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::StringLessThanOrEqual(Isolate* isolate) {
  StringLessThanOrEqualStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::StringGreaterThan(Isolate* isolate) {
  StringGreaterThanStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

// static
Callable CodeFactory::StringGreaterThanOrEqual(Isolate* isolate) {
  StringGreaterThanOrEqualStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

413 414 415 416 417 418 419
// static
Callable CodeFactory::SubString(Isolate* isolate) {
  SubStringStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


420 421 422 423 424 425
// static
Callable CodeFactory::ResumeGenerator(Isolate* isolate) {
  return Callable(isolate->builtins()->ResumeGeneratorTrampoline(),
                  ResumeGeneratorDescriptor(isolate));
}

426 427 428 429 430 431 432
// static
Callable CodeFactory::Typeof(Isolate* isolate) {
  TypeofStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


433 434 435 436 437 438 439
// static
Callable CodeFactory::FastCloneRegExp(Isolate* isolate) {
  FastCloneRegExpStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
// static
Callable CodeFactory::FastCloneShallowArray(Isolate* isolate) {
  // TODO(mstarzinger): Thread through AllocationSiteMode at some point.
  FastCloneShallowArrayStub stub(isolate, DONT_TRACK_ALLOCATION_SITE);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


// static
Callable CodeFactory::FastCloneShallowObject(Isolate* isolate, int length) {
  FastCloneShallowObjectStub stub(isolate, length);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


455 456 457 458 459 460 461
// static
Callable CodeFactory::FastNewContext(Isolate* isolate, int slot_count) {
  FastNewContextStub stub(isolate, slot_count);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


462 463 464 465 466 467
// static
Callable CodeFactory::FastNewClosure(Isolate* isolate,
                                     LanguageMode language_mode,
                                     FunctionKind kind) {
  FastNewClosureStub stub(isolate, language_mode, kind);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
468 469 470 471 472 473 474
}


// static
Callable CodeFactory::FastNewObject(Isolate* isolate) {
  FastNewObjectStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
475 476 477
}


478
// static
479 480 481
Callable CodeFactory::FastNewRestParameter(Isolate* isolate,
                                           bool skip_stub_frame) {
  FastNewRestParameterStub stub(isolate, skip_stub_frame);
482 483 484 485
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


486
// static
487 488 489
Callable CodeFactory::FastNewSloppyArguments(Isolate* isolate,
                                             bool skip_stub_frame) {
  FastNewSloppyArgumentsStub stub(isolate, skip_stub_frame);
490 491 492 493
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


494
// static
495 496 497
Callable CodeFactory::FastNewStrictArguments(Isolate* isolate,
                                             bool skip_stub_frame) {
  FastNewStrictArgumentsStub stub(isolate, skip_stub_frame);
498 499 500 501
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


502 503 504 505 506 507
// static
Callable CodeFactory::AllocateHeapNumber(Isolate* isolate) {
  AllocateHeapNumberStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}

bbudge's avatar
bbudge committed
508 509 510 511 512 513 514
#define SIMD128_ALLOC(TYPE, Type, type, lane_count, lane_type)          \
  Callable CodeFactory::Allocate##Type(Isolate* isolate) {              \
    Allocate##Type##Stub stub(isolate);                                 \
    return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor()); \
  }
SIMD128_TYPES(SIMD128_ALLOC)
#undef SIMD128_ALLOC
515

516 517 518 519 520 521 522
// static
Callable CodeFactory::ArgumentAdaptor(Isolate* isolate) {
  return Callable(isolate->builtins()->ArgumentsAdaptorTrampoline(),
                  ArgumentAdaptorDescriptor(isolate));
}


523
// static
524 525 526
Callable CodeFactory::Call(Isolate* isolate, ConvertReceiverMode mode,
                           TailCallMode tail_call_mode) {
  return Callable(isolate->builtins()->Call(mode, tail_call_mode),
527 528 529 530
                  CallTrampolineDescriptor(isolate));
}


531
// static
532 533
Callable CodeFactory::CallFunction(Isolate* isolate, ConvertReceiverMode mode) {
  return Callable(isolate->builtins()->CallFunction(mode),
534 535 536 537
                  CallTrampolineDescriptor(isolate));
}


538 539 540 541 542 543 544
// static
Callable CodeFactory::Construct(Isolate* isolate) {
  return Callable(isolate->builtins()->Construct(),
                  ConstructTrampolineDescriptor(isolate));
}


545 546 547 548 549 550
// static
Callable CodeFactory::ConstructFunction(Isolate* isolate) {
  return Callable(isolate->builtins()->ConstructFunction(),
                  ConstructTrampolineDescriptor(isolate));
}

551 552 553 554 555
// static
Callable CodeFactory::HasProperty(Isolate* isolate) {
  HasPropertyStub stub(isolate);
  return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}
556

557
// static
558 559 560 561 562
Callable CodeFactory::InterpreterPushArgsAndCall(Isolate* isolate,
                                                 TailCallMode tail_call_mode) {
  return Callable(
      isolate->builtins()->InterpreterPushArgsAndCall(tail_call_mode),
      InterpreterPushArgsAndCallDescriptor(isolate));
563 564
}

565

566 567 568 569 570 571 572
// static
Callable CodeFactory::InterpreterPushArgsAndConstruct(Isolate* isolate) {
  return Callable(isolate->builtins()->InterpreterPushArgsAndConstruct(),
                  InterpreterPushArgsAndConstructDescriptor(isolate));
}


573
// static
574
Callable CodeFactory::InterpreterCEntry(Isolate* isolate, int result_size) {
575 576
  // Note: If we ever use fpregs in the interpreter then we will need to
  // save fpregs too.
577
  CEntryStub stub(isolate, result_size, kDontSaveFPRegs, kArgvInRegister);
578
  return Callable(stub.GetCode(), InterpreterCEntryDescriptor(isolate));
579 580
}

581 582
}  // namespace internal
}  // namespace v8