js-operator.cc 56.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// 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.

#include "src/compiler/js-operator.h"

#include <limits>

#include "src/base/lazy-instance.h"
#include "src/compiler/opcodes.h"
#include "src/compiler/operator.h"
12
#include "src/compiler/vector-slot-pair.h"
13
#include "src/handles/handles-inl.h"
14
#include "src/objects/objects-inl.h"
15 16 17 18 19

namespace v8 {
namespace internal {
namespace compiler {

20
std::ostream& operator<<(std::ostream& os, CallFrequency const& f) {
21 22 23 24
  if (f.IsUnknown()) return os << "unknown";
  return os << f.value();
}

25
CallFrequency CallFrequencyOf(Operator const* op) {
26 27
  DCHECK(op->opcode() == IrOpcode::kJSCallWithArrayLike ||
         op->opcode() == IrOpcode::kJSConstructWithArrayLike);
28 29 30
  return OpParameter<CallFrequency>(op);
}

31 32 33 34 35 36 37 38 39 40 41
std::ostream& operator<<(std::ostream& os,
                         ConstructForwardVarargsParameters const& p) {
  return os << p.arity() << ", " << p.start_index();
}

ConstructForwardVarargsParameters const& ConstructForwardVarargsParametersOf(
    Operator const* op) {
  DCHECK_EQ(IrOpcode::kJSConstructForwardVarargs, op->opcode());
  return OpParameter<ConstructForwardVarargsParameters>(op);
}

42 43
bool operator==(ConstructParameters const& lhs,
                ConstructParameters const& rhs) {
44 45
  return lhs.arity() == rhs.arity() && lhs.frequency() == rhs.frequency() &&
         lhs.feedback() == rhs.feedback();
46 47
}

48 49
bool operator!=(ConstructParameters const& lhs,
                ConstructParameters const& rhs) {
50 51 52
  return !(lhs == rhs);
}

53
size_t hash_value(ConstructParameters const& p) {
54
  return base::hash_combine(p.arity(), p.frequency(), p.feedback());
55 56
}

57
std::ostream& operator<<(std::ostream& os, ConstructParameters const& p) {
58
  return os << p.arity() << ", " << p.frequency();
59 60
}

61
ConstructParameters const& ConstructParametersOf(Operator const* op) {
62 63
  DCHECK(op->opcode() == IrOpcode::kJSConstruct ||
         op->opcode() == IrOpcode::kJSConstructWithSpread);
64
  return OpParameter<ConstructParameters>(op);
65 66
}

67
std::ostream& operator<<(std::ostream& os, CallParameters const& p) {
68
  return os << p.arity() << ", " << p.frequency() << ", " << p.convert_mode();
69 70
}

71
const CallParameters& CallParametersOf(const Operator* op) {
72 73
  DCHECK(op->opcode() == IrOpcode::kJSCall ||
         op->opcode() == IrOpcode::kJSCallWithSpread);
74
  return OpParameter<CallParameters>(op);
75 76
}

77 78
std::ostream& operator<<(std::ostream& os,
                         CallForwardVarargsParameters const& p) {
79
  return os << p.arity() << ", " << p.start_index();
80 81 82 83 84 85 86 87
}

CallForwardVarargsParameters const& CallForwardVarargsParametersOf(
    Operator const* op) {
  DCHECK_EQ(IrOpcode::kJSCallForwardVarargs, op->opcode());
  return OpParameter<CallForwardVarargsParameters>(op);
}

88

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
bool operator==(CallRuntimeParameters const& lhs,
                CallRuntimeParameters const& rhs) {
  return lhs.id() == rhs.id() && lhs.arity() == rhs.arity();
}


bool operator!=(CallRuntimeParameters const& lhs,
                CallRuntimeParameters const& rhs) {
  return !(lhs == rhs);
}


size_t hash_value(CallRuntimeParameters const& p) {
  return base::hash_combine(p.id(), p.arity());
}


std::ostream& operator<<(std::ostream& os, CallRuntimeParameters const& p) {
  return os << p.id() << ", " << p.arity();
}


111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
const CallRuntimeParameters& CallRuntimeParametersOf(const Operator* op) {
  DCHECK_EQ(IrOpcode::kJSCallRuntime, op->opcode());
  return OpParameter<CallRuntimeParameters>(op);
}


ContextAccess::ContextAccess(size_t depth, size_t index, bool immutable)
    : immutable_(immutable),
      depth_(static_cast<uint16_t>(depth)),
      index_(static_cast<uint32_t>(index)) {
  DCHECK(depth <= std::numeric_limits<uint16_t>::max());
  DCHECK(index <= std::numeric_limits<uint32_t>::max());
}


126
bool operator==(ContextAccess const& lhs, ContextAccess const& rhs) {
127 128 129 130 131
  return lhs.depth() == rhs.depth() && lhs.index() == rhs.index() &&
         lhs.immutable() == rhs.immutable();
}


132
bool operator!=(ContextAccess const& lhs, ContextAccess const& rhs) {
133 134 135 136
  return !(lhs == rhs);
}


137 138 139 140 141 142 143 144 145 146 147 148
size_t hash_value(ContextAccess const& access) {
  return base::hash_combine(access.depth(), access.index(), access.immutable());
}


std::ostream& operator<<(std::ostream& os, ContextAccess const& access) {
  return os << access.depth() << ", " << access.index() << ", "
            << access.immutable();
}


ContextAccess const& ContextAccessOf(Operator const* op) {
149 150 151 152 153
  DCHECK(op->opcode() == IrOpcode::kJSLoadContext ||
         op->opcode() == IrOpcode::kJSStoreContext);
  return OpParameter<ContextAccess>(op);
}

154
CreateFunctionContextParameters::CreateFunctionContextParameters(
155 156 157 158
    Handle<ScopeInfo> scope_info, int slot_count, ScopeType scope_type)
    : scope_info_(scope_info),
      slot_count_(slot_count),
      scope_type_(scope_type) {}
159 160 161

bool operator==(CreateFunctionContextParameters const& lhs,
                CreateFunctionContextParameters const& rhs) {
162 163
  return lhs.scope_info().location() == rhs.scope_info().location() &&
         lhs.slot_count() == rhs.slot_count() &&
164 165 166 167 168 169 170 171 172
         lhs.scope_type() == rhs.scope_type();
}

bool operator!=(CreateFunctionContextParameters const& lhs,
                CreateFunctionContextParameters const& rhs) {
  return !(lhs == rhs);
}

size_t hash_value(CreateFunctionContextParameters const& parameters) {
173 174
  return base::hash_combine(parameters.scope_info().location(),
                            parameters.slot_count(),
175 176 177 178 179 180 181 182 183 184 185 186 187 188
                            static_cast<int>(parameters.scope_type()));
}

std::ostream& operator<<(std::ostream& os,
                         CreateFunctionContextParameters const& parameters) {
  return os << parameters.slot_count() << ", " << parameters.scope_type();
}

CreateFunctionContextParameters const& CreateFunctionContextParametersOf(
    Operator const* op) {
  DCHECK_EQ(IrOpcode::kJSCreateFunctionContext, op->opcode());
  return OpParameter<CreateFunctionContextParameters>(op);
}

189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
bool operator==(StoreNamedOwnParameters const& lhs,
                StoreNamedOwnParameters const& rhs) {
  return lhs.name().location() == rhs.name().location() &&
         lhs.feedback() == rhs.feedback();
}

bool operator!=(StoreNamedOwnParameters const& lhs,
                StoreNamedOwnParameters const& rhs) {
  return !(lhs == rhs);
}

size_t hash_value(StoreNamedOwnParameters const& p) {
  return base::hash_combine(p.name().location(), p.feedback());
}

std::ostream& operator<<(std::ostream& os, StoreNamedOwnParameters const& p) {
  return os << Brief(*p.name());
}

StoreNamedOwnParameters const& StoreNamedOwnParametersOf(const Operator* op) {
  DCHECK_EQ(IrOpcode::kJSStoreNamedOwn, op->opcode());
  return OpParameter<StoreNamedOwnParameters>(op);
}

213
bool operator==(FeedbackParameter const& lhs, FeedbackParameter const& rhs) {
214 215 216
  return lhs.feedback() == rhs.feedback();
}

217
bool operator!=(FeedbackParameter const& lhs, FeedbackParameter const& rhs) {
218 219 220
  return !(lhs == rhs);
}

221
size_t hash_value(FeedbackParameter const& p) {
222 223 224
  return base::hash_combine(p.feedback());
}

225
std::ostream& operator<<(std::ostream& os, FeedbackParameter const& p) {
226 227 228
  return os;
}

229
FeedbackParameter const& FeedbackParameterOf(const Operator* op) {
230
  DCHECK(op->opcode() == IrOpcode::kJSCreateEmptyLiteralArray ||
231
         op->opcode() == IrOpcode::kJSInstanceOf ||
232 233
         op->opcode() == IrOpcode::kJSStoreDataPropertyInLiteral ||
         op->opcode() == IrOpcode::kJSStoreInArrayLiteral);
234
  return OpParameter<FeedbackParameter>(op);
235 236
}

237
bool operator==(NamedAccess const& lhs, NamedAccess const& rhs) {
238
  return lhs.name().location() == rhs.name().location() &&
239
         lhs.language_mode() == rhs.language_mode() &&
240
         lhs.feedback() == rhs.feedback();
241 242 243
}


244
bool operator!=(NamedAccess const& lhs, NamedAccess const& rhs) {
245 246 247 248
  return !(lhs == rhs);
}


249
size_t hash_value(NamedAccess const& p) {
250 251
  return base::hash_combine(p.name().location(), p.language_mode(),
                            p.feedback());
252 253 254
}


255
std::ostream& operator<<(std::ostream& os, NamedAccess const& p) {
256
  return os << Brief(*p.name()) << ", " << p.language_mode();
257 258 259
}


260 261 262 263 264 265 266 267
NamedAccess const& NamedAccessOf(const Operator* op) {
  DCHECK(op->opcode() == IrOpcode::kJSLoadNamed ||
         op->opcode() == IrOpcode::kJSStoreNamed);
  return OpParameter<NamedAccess>(op);
}


std::ostream& operator<<(std::ostream& os, PropertyAccess const& p) {
268
  return os << p.language_mode() << ", " << p.feedback();
269 270 271
}


272
bool operator==(PropertyAccess const& lhs, PropertyAccess const& rhs) {
273 274
  return lhs.language_mode() == rhs.language_mode() &&
         lhs.feedback() == rhs.feedback();
275 276 277
}


278
bool operator!=(PropertyAccess const& lhs, PropertyAccess const& rhs) {
279 280 281 282
  return !(lhs == rhs);
}


283
PropertyAccess const& PropertyAccessOf(const Operator* op) {
284 285
  DCHECK(op->opcode() == IrOpcode::kJSHasProperty ||
         op->opcode() == IrOpcode::kJSLoadProperty ||
286 287
         op->opcode() == IrOpcode::kJSStoreProperty);
  return OpParameter<PropertyAccess>(op);
288 289 290
}


291
size_t hash_value(PropertyAccess const& p) {
292
  return base::hash_combine(p.language_mode(), p.feedback());
293 294 295
}


296 297
bool operator==(LoadGlobalParameters const& lhs,
                LoadGlobalParameters const& rhs) {
298 299
  return lhs.name().location() == rhs.name().location() &&
         lhs.feedback() == rhs.feedback() &&
300
         lhs.typeof_mode() == rhs.typeof_mode();
301 302 303 304 305 306 307 308 309 310
}


bool operator!=(LoadGlobalParameters const& lhs,
                LoadGlobalParameters const& rhs) {
  return !(lhs == rhs);
}


size_t hash_value(LoadGlobalParameters const& p) {
311
  return base::hash_combine(p.name().location(), p.typeof_mode());
312 313 314 315
}


std::ostream& operator<<(std::ostream& os, LoadGlobalParameters const& p) {
316
  return os << Brief(*p.name()) << ", " << p.typeof_mode();
317 318 319 320
}


const LoadGlobalParameters& LoadGlobalParametersOf(const Operator* op) {
321
  DCHECK_EQ(IrOpcode::kJSLoadGlobal, op->opcode());
322 323 324 325 326 327 328
  return OpParameter<LoadGlobalParameters>(op);
}


bool operator==(StoreGlobalParameters const& lhs,
                StoreGlobalParameters const& rhs) {
  return lhs.language_mode() == rhs.language_mode() &&
329
         lhs.name().location() == rhs.name().location() &&
330
         lhs.feedback() == rhs.feedback();
331 332 333 334 335 336 337 338 339 340
}


bool operator!=(StoreGlobalParameters const& lhs,
                StoreGlobalParameters const& rhs) {
  return !(lhs == rhs);
}


size_t hash_value(StoreGlobalParameters const& p) {
341
  return base::hash_combine(p.language_mode(), p.name().location(),
342
                            p.feedback());
343 344 345 346
}


std::ostream& operator<<(std::ostream& os, StoreGlobalParameters const& p) {
347
  return os << p.language_mode() << ", " << Brief(*p.name());
348 349 350 351 352 353
}


const StoreGlobalParameters& StoreGlobalParametersOf(const Operator* op) {
  DCHECK_EQ(IrOpcode::kJSStoreGlobal, op->opcode());
  return OpParameter<StoreGlobalParameters>(op);
354 355 356
}


357
CreateArgumentsType const& CreateArgumentsTypeOf(const Operator* op) {
358
  DCHECK_EQ(IrOpcode::kJSCreateArguments, op->opcode());
359
  return OpParameter<CreateArgumentsType>(op);
360 361 362
}


363 364 365
bool operator==(CreateArrayParameters const& lhs,
                CreateArrayParameters const& rhs) {
  return lhs.arity() == rhs.arity() &&
366
         lhs.site().address() == rhs.site().address();
367 368 369 370 371 372 373 374 375 376
}


bool operator!=(CreateArrayParameters const& lhs,
                CreateArrayParameters const& rhs) {
  return !(lhs == rhs);
}


size_t hash_value(CreateArrayParameters const& p) {
377
  return base::hash_combine(p.arity(), p.site().address());
378 379 380 381 382
}


std::ostream& operator<<(std::ostream& os, CreateArrayParameters const& p) {
  os << p.arity();
383 384
  Handle<AllocationSite> site;
  if (p.site().ToHandle(&site)) os << ", " << Brief(*site);
385 386 387 388 389 390 391 392
  return os;
}

const CreateArrayParameters& CreateArrayParametersOf(const Operator* op) {
  DCHECK_EQ(IrOpcode::kJSCreateArray, op->opcode());
  return OpParameter<CreateArrayParameters>(op);
}

393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
bool operator==(CreateArrayIteratorParameters const& lhs,
                CreateArrayIteratorParameters const& rhs) {
  return lhs.kind() == rhs.kind();
}

bool operator!=(CreateArrayIteratorParameters const& lhs,
                CreateArrayIteratorParameters const& rhs) {
  return !(lhs == rhs);
}

size_t hash_value(CreateArrayIteratorParameters const& p) {
  return static_cast<size_t>(p.kind());
}

std::ostream& operator<<(std::ostream& os,
                         CreateArrayIteratorParameters const& p) {
  return os << p.kind();
}

const CreateArrayIteratorParameters& CreateArrayIteratorParametersOf(
    const Operator* op) {
  DCHECK_EQ(IrOpcode::kJSCreateArrayIterator, op->opcode());
  return OpParameter<CreateArrayIteratorParameters>(op);
}

418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
bool operator==(CreateCollectionIteratorParameters const& lhs,
                CreateCollectionIteratorParameters const& rhs) {
  return lhs.collection_kind() == rhs.collection_kind() &&
         lhs.iteration_kind() == rhs.iteration_kind();
}

bool operator!=(CreateCollectionIteratorParameters const& lhs,
                CreateCollectionIteratorParameters const& rhs) {
  return !(lhs == rhs);
}

size_t hash_value(CreateCollectionIteratorParameters const& p) {
  return base::hash_combine(static_cast<size_t>(p.collection_kind()),
                            static_cast<size_t>(p.iteration_kind()));
}

std::ostream& operator<<(std::ostream& os,
                         CreateCollectionIteratorParameters const& p) {
  return os << p.collection_kind() << " " << p.iteration_kind();
}

const CreateCollectionIteratorParameters& CreateCollectionIteratorParametersOf(
    const Operator* op) {
  DCHECK_EQ(IrOpcode::kJSCreateCollectionIterator, op->opcode());
  return OpParameter<CreateCollectionIteratorParameters>(op);
}

445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
bool operator==(CreateBoundFunctionParameters const& lhs,
                CreateBoundFunctionParameters const& rhs) {
  return lhs.arity() == rhs.arity() &&
         lhs.map().location() == rhs.map().location();
}

bool operator!=(CreateBoundFunctionParameters const& lhs,
                CreateBoundFunctionParameters const& rhs) {
  return !(lhs == rhs);
}

size_t hash_value(CreateBoundFunctionParameters const& p) {
  return base::hash_combine(p.arity(), p.map().location());
}

std::ostream& operator<<(std::ostream& os,
                         CreateBoundFunctionParameters const& p) {
  os << p.arity();
  if (!p.map().is_null()) os << ", " << Brief(*p.map());
  return os;
}

const CreateBoundFunctionParameters& CreateBoundFunctionParametersOf(
    const Operator* op) {
  DCHECK_EQ(IrOpcode::kJSCreateBoundFunction, op->opcode());
  return OpParameter<CreateBoundFunctionParameters>(op);
}
472

473 474
bool operator==(CreateClosureParameters const& lhs,
                CreateClosureParameters const& rhs) {
475
  return lhs.allocation() == rhs.allocation() &&
476
         lhs.code().location() == rhs.code().location() &&
477
         lhs.feedback_cell().location() == rhs.feedback_cell().location() &&
478
         lhs.shared_info().location() == rhs.shared_info().location();
479 480 481 482 483 484 485 486 487 488
}


bool operator!=(CreateClosureParameters const& lhs,
                CreateClosureParameters const& rhs) {
  return !(lhs == rhs);
}


size_t hash_value(CreateClosureParameters const& p) {
489
  return base::hash_combine(p.allocation(), p.shared_info().location(),
490
                            p.feedback_cell().location());
491 492 493 494
}


std::ostream& operator<<(std::ostream& os, CreateClosureParameters const& p) {
495
  return os << p.allocation() << ", " << Brief(*p.shared_info()) << ", "
496
            << Brief(*p.feedback_cell()) << ", " << Brief(*p.code());
497 498 499 500 501 502 503 504 505
}


const CreateClosureParameters& CreateClosureParametersOf(const Operator* op) {
  DCHECK_EQ(IrOpcode::kJSCreateClosure, op->opcode());
  return OpParameter<CreateClosureParameters>(op);
}


506 507
bool operator==(CreateLiteralParameters const& lhs,
                CreateLiteralParameters const& rhs) {
508
  return lhs.constant().location() == rhs.constant().location() &&
509 510
         lhs.feedback() == rhs.feedback() && lhs.length() == rhs.length() &&
         lhs.flags() == rhs.flags();
511 512 513 514 515 516 517 518 519 520
}


bool operator!=(CreateLiteralParameters const& lhs,
                CreateLiteralParameters const& rhs) {
  return !(lhs == rhs);
}


size_t hash_value(CreateLiteralParameters const& p) {
521 522
  return base::hash_combine(p.constant().location(), p.feedback(), p.length(),
                            p.flags());
523 524 525 526
}


std::ostream& operator<<(std::ostream& os, CreateLiteralParameters const& p) {
527
  return os << Brief(*p.constant()) << ", " << p.length() << ", " << p.flags();
528 529 530 531 532
}


const CreateLiteralParameters& CreateLiteralParametersOf(const Operator* op) {
  DCHECK(op->opcode() == IrOpcode::kJSCreateLiteralArray ||
533 534
         op->opcode() == IrOpcode::kJSCreateLiteralObject ||
         op->opcode() == IrOpcode::kJSCreateLiteralRegExp);
535 536 537
  return OpParameter<CreateLiteralParameters>(op);
}

538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
bool operator==(CloneObjectParameters const& lhs,
                CloneObjectParameters const& rhs) {
  return lhs.feedback() == rhs.feedback() && lhs.flags() == rhs.flags();
}

bool operator!=(CloneObjectParameters const& lhs,
                CloneObjectParameters const& rhs) {
  return !(lhs == rhs);
}

size_t hash_value(CloneObjectParameters const& p) {
  return base::hash_combine(p.feedback(), p.flags());
}

std::ostream& operator<<(std::ostream& os, CloneObjectParameters const& p) {
  return os << p.flags();
}

const CloneObjectParameters& CloneObjectParametersOf(const Operator* op) {
  DCHECK(op->opcode() == IrOpcode::kJSCloneObject);
  return OpParameter<CloneObjectParameters>(op);
}

561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
size_t hash_value(ForInMode mode) { return static_cast<uint8_t>(mode); }

std::ostream& operator<<(std::ostream& os, ForInMode mode) {
  switch (mode) {
    case ForInMode::kUseEnumCacheKeysAndIndices:
      return os << "UseEnumCacheKeysAndIndices";
    case ForInMode::kUseEnumCacheKeys:
      return os << "UseEnumCacheKeys";
    case ForInMode::kGeneric:
      return os << "Generic";
  }
  UNREACHABLE();
}

ForInMode ForInModeOf(Operator const* op) {
  DCHECK(op->opcode() == IrOpcode::kJSForInNext ||
         op->opcode() == IrOpcode::kJSForInPrepare);
  return OpParameter<ForInMode>(op);
}

581
BinaryOperationHint BinaryOperationHintOf(const Operator* op) {
582
  DCHECK_EQ(IrOpcode::kJSAdd, op->opcode());
583
  return OpParameter<BinaryOperationHint>(op);
584 585
}

586
CompareOperationHint CompareOperationHintOf(const Operator* op) {
587 588 589 590 591 592
  DCHECK(op->opcode() == IrOpcode::kJSEqual ||
         op->opcode() == IrOpcode::kJSStrictEqual ||
         op->opcode() == IrOpcode::kJSLessThan ||
         op->opcode() == IrOpcode::kJSGreaterThan ||
         op->opcode() == IrOpcode::kJSLessThanOrEqual ||
         op->opcode() == IrOpcode::kJSGreaterThanOrEqual);
593
  return OpParameter<CompareOperationHint>(op);
594 595
}

596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
#define CACHED_OP_LIST(V)                                                \
  V(BitwiseOr, Operator::kNoProperties, 2, 1)                            \
  V(BitwiseXor, Operator::kNoProperties, 2, 1)                           \
  V(BitwiseAnd, Operator::kNoProperties, 2, 1)                           \
  V(ShiftLeft, Operator::kNoProperties, 2, 1)                            \
  V(ShiftRight, Operator::kNoProperties, 2, 1)                           \
  V(ShiftRightLogical, Operator::kNoProperties, 2, 1)                    \
  V(Subtract, Operator::kNoProperties, 2, 1)                             \
  V(Multiply, Operator::kNoProperties, 2, 1)                             \
  V(Divide, Operator::kNoProperties, 2, 1)                               \
  V(Modulus, Operator::kNoProperties, 2, 1)                              \
  V(Exponentiate, Operator::kNoProperties, 2, 1)                         \
  V(BitwiseNot, Operator::kNoProperties, 1, 1)                           \
  V(Decrement, Operator::kNoProperties, 1, 1)                            \
  V(Increment, Operator::kNoProperties, 1, 1)                            \
  V(Negate, Operator::kNoProperties, 1, 1)                               \
  V(ToLength, Operator::kNoProperties, 1, 1)                             \
  V(ToName, Operator::kNoProperties, 1, 1)                               \
  V(ToNumber, Operator::kNoProperties, 1, 1)                             \
  V(ToNumberConvertBigInt, Operator::kNoProperties, 1, 1)                \
  V(ToNumeric, Operator::kNoProperties, 1, 1)                            \
  V(ToObject, Operator::kFoldable, 1, 1)                                 \
  V(ToString, Operator::kNoProperties, 1, 1)                             \
  V(Create, Operator::kNoProperties, 2, 1)                               \
  V(CreateIterResultObject, Operator::kEliminatable, 2, 1)               \
  V(CreateStringIterator, Operator::kEliminatable, 1, 1)                 \
  V(CreateKeyValueArray, Operator::kEliminatable, 2, 1)                  \
  V(CreatePromise, Operator::kEliminatable, 0, 1)                        \
  V(CreateTypedArray, Operator::kNoProperties, 5, 1)                     \
  V(CreateObject, Operator::kNoProperties, 1, 1)                         \
  V(ObjectIsArray, Operator::kNoProperties, 1, 1)                        \
  V(HasInPrototypeChain, Operator::kNoProperties, 2, 1)                  \
  V(OrdinaryHasInstance, Operator::kNoProperties, 2, 1)                  \
  V(ForInEnumerate, Operator::kNoProperties, 1, 1)                       \
  V(AsyncFunctionEnter, Operator::kNoProperties, 2, 1)                   \
  V(AsyncFunctionReject, Operator::kNoDeopt | Operator::kNoThrow, 3, 1)  \
  V(AsyncFunctionResolve, Operator::kNoDeopt | Operator::kNoThrow, 3, 1) \
  V(LoadMessage, Operator::kNoThrow | Operator::kNoWrite, 0, 1)          \
  V(StoreMessage, Operator::kNoRead | Operator::kNoThrow, 1, 0)          \
  V(GeneratorRestoreContinuation, Operator::kNoThrow, 1, 1)              \
  V(GeneratorRestoreContext, Operator::kNoThrow, 1, 1)                   \
  V(GeneratorRestoreInputOrDebugPos, Operator::kNoThrow, 1, 1)           \
  V(StackCheck, Operator::kNoWrite, 0, 0)                                \
  V(Debugger, Operator::kNoProperties, 0, 0)                             \
  V(FulfillPromise, Operator::kNoDeopt | Operator::kNoThrow, 2, 1)       \
  V(PerformPromiseThen, Operator::kNoDeopt | Operator::kNoThrow, 4, 1)   \
  V(PromiseResolve, Operator::kNoProperties, 2, 1)                       \
  V(RejectPromise, Operator::kNoDeopt | Operator::kNoThrow, 3, 1)        \
  V(ResolvePromise, Operator::kNoDeopt | Operator::kNoThrow, 2, 1)       \
  V(GetSuperConstructor, Operator::kNoWrite, 1, 1)                       \
  V(ParseInt, Operator::kNoProperties, 2, 1)                             \
647
  V(RegExpTest, Operator::kNoProperties, 2, 1)
648

649
#define BINARY_OP_LIST(V) V(Add)
650 651 652 653 654 655 656 657 658

#define COMPARE_OP_LIST(V)                    \
  V(Equal, Operator::kNoProperties)           \
  V(StrictEqual, Operator::kPure)             \
  V(LessThan, Operator::kNoProperties)        \
  V(GreaterThan, Operator::kNoProperties)     \
  V(LessThanOrEqual, Operator::kNoProperties) \
  V(GreaterThanOrEqual, Operator::kNoProperties)

659
struct JSOperatorGlobalCache final {
660 661 662 663 664 665 666 667 668
#define CACHED_OP(Name, properties, value_input_count, value_output_count) \
  struct Name##Operator final : public Operator {                          \
    Name##Operator()                                                       \
        : Operator(IrOpcode::kJS##Name, properties, "JS" #Name,            \
                   value_input_count, Operator::ZeroIfPure(properties),    \
                   Operator::ZeroIfEliminatable(properties),               \
                   value_output_count, Operator::ZeroIfPure(properties),   \
                   Operator::ZeroIfNoThrow(properties)) {}                 \
  };                                                                       \
669
  Name##Operator k##Name##Operator;
670 671 672 673 674 675 676 677 678 679 680 681 682 683
  CACHED_OP_LIST(CACHED_OP)
#undef CACHED_OP

#define BINARY_OP(Name)                                                       \
  template <BinaryOperationHint kHint>                                        \
  struct Name##Operator final : public Operator1<BinaryOperationHint> {       \
    Name##Operator()                                                          \
        : Operator1<BinaryOperationHint>(IrOpcode::kJS##Name,                 \
                                         Operator::kNoProperties, "JS" #Name, \
                                         2, 1, 1, 1, 1, 2, kHint) {}          \
  };                                                                          \
  Name##Operator<BinaryOperationHint::kNone> k##Name##NoneOperator;           \
  Name##Operator<BinaryOperationHint::kSignedSmall>                           \
      k##Name##SignedSmallOperator;                                           \
684 685
  Name##Operator<BinaryOperationHint::kSignedSmallInputs>                     \
      k##Name##SignedSmallInputsOperator;                                     \
686
  Name##Operator<BinaryOperationHint::kSigned32> k##Name##Signed32Operator;   \
687
  Name##Operator<BinaryOperationHint::kNumber> k##Name##NumberOperator;       \
688 689
  Name##Operator<BinaryOperationHint::kNumberOrOddball>                       \
      k##Name##NumberOrOddballOperator;                                       \
690
  Name##Operator<BinaryOperationHint::kString> k##Name##StringOperator;       \
691
  Name##Operator<BinaryOperationHint::kBigInt> k##Name##BigIntOperator;       \
692 693 694 695
  Name##Operator<BinaryOperationHint::kAny> k##Name##AnyOperator;
  BINARY_OP_LIST(BINARY_OP)
#undef BINARY_OP

696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
#define COMPARE_OP(Name, properties)                                         \
  template <CompareOperationHint kHint>                                      \
  struct Name##Operator final : public Operator1<CompareOperationHint> {     \
    Name##Operator()                                                         \
        : Operator1<CompareOperationHint>(                                   \
              IrOpcode::kJS##Name, properties, "JS" #Name, 2, 1, 1, 1, 1,    \
              Operator::ZeroIfNoThrow(properties), kHint) {}                 \
  };                                                                         \
  Name##Operator<CompareOperationHint::kNone> k##Name##NoneOperator;         \
  Name##Operator<CompareOperationHint::kSignedSmall>                         \
      k##Name##SignedSmallOperator;                                          \
  Name##Operator<CompareOperationHint::kNumber> k##Name##NumberOperator;     \
  Name##Operator<CompareOperationHint::kNumberOrOddball>                     \
      k##Name##NumberOrOddballOperator;                                      \
  Name##Operator<CompareOperationHint::kInternalizedString>                  \
      k##Name##InternalizedStringOperator;                                   \
  Name##Operator<CompareOperationHint::kString> k##Name##StringOperator;     \
713
  Name##Operator<CompareOperationHint::kSymbol> k##Name##SymbolOperator;     \
714
  Name##Operator<CompareOperationHint::kBigInt> k##Name##BigIntOperator;     \
715
  Name##Operator<CompareOperationHint::kReceiver> k##Name##ReceiverOperator; \
716 717
  Name##Operator<CompareOperationHint::kReceiverOrNullOrUndefined>           \
      k##Name##ReceiverOrNullOrUndefinedOperator;                            \
718 719 720
  Name##Operator<CompareOperationHint::kAny> k##Name##AnyOperator;
  COMPARE_OP_LIST(COMPARE_OP)
#undef COMPARE_OP
721 722
};

723
namespace {
724
DEFINE_LAZY_LEAKY_OBJECT_GETTER(JSOperatorGlobalCache, GetJSOperatorGlobalCache)
725
}
726 727

JSOperatorBuilder::JSOperatorBuilder(Zone* zone)
728
    : cache_(*GetJSOperatorGlobalCache()), zone_(zone) {}
729

730 731 732
#define CACHED_OP(Name, properties, value_input_count, value_output_count) \
  const Operator* JSOperatorBuilder::Name() {                              \
    return &cache_.k##Name##Operator;                                      \
733
  }
734 735 736 737 738 739 740 741 742 743
CACHED_OP_LIST(CACHED_OP)
#undef CACHED_OP

#define BINARY_OP(Name)                                               \
  const Operator* JSOperatorBuilder::Name(BinaryOperationHint hint) { \
    switch (hint) {                                                   \
      case BinaryOperationHint::kNone:                                \
        return &cache_.k##Name##NoneOperator;                         \
      case BinaryOperationHint::kSignedSmall:                         \
        return &cache_.k##Name##SignedSmallOperator;                  \
744 745
      case BinaryOperationHint::kSignedSmallInputs:                   \
        return &cache_.k##Name##SignedSmallInputsOperator;            \
746 747
      case BinaryOperationHint::kSigned32:                            \
        return &cache_.k##Name##Signed32Operator;                     \
748 749
      case BinaryOperationHint::kNumber:                              \
        return &cache_.k##Name##NumberOperator;                       \
750 751
      case BinaryOperationHint::kNumberOrOddball:                     \
        return &cache_.k##Name##NumberOrOddballOperator;              \
752 753
      case BinaryOperationHint::kString:                              \
        return &cache_.k##Name##StringOperator;                       \
754 755
      case BinaryOperationHint::kBigInt:                              \
        return &cache_.k##Name##BigIntOperator;                       \
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
      case BinaryOperationHint::kAny:                                 \
        return &cache_.k##Name##AnyOperator;                          \
    }                                                                 \
    UNREACHABLE();                                                    \
    return nullptr;                                                   \
  }
BINARY_OP_LIST(BINARY_OP)
#undef BINARY_OP

#define COMPARE_OP(Name, ...)                                          \
  const Operator* JSOperatorBuilder::Name(CompareOperationHint hint) { \
    switch (hint) {                                                    \
      case CompareOperationHint::kNone:                                \
        return &cache_.k##Name##NoneOperator;                          \
      case CompareOperationHint::kSignedSmall:                         \
        return &cache_.k##Name##SignedSmallOperator;                   \
      case CompareOperationHint::kNumber:                              \
        return &cache_.k##Name##NumberOperator;                        \
      case CompareOperationHint::kNumberOrOddball:                     \
        return &cache_.k##Name##NumberOrOddballOperator;               \
776 777
      case CompareOperationHint::kInternalizedString:                  \
        return &cache_.k##Name##InternalizedStringOperator;            \
778 779
      case CompareOperationHint::kString:                              \
        return &cache_.k##Name##StringOperator;                        \
780 781
      case CompareOperationHint::kSymbol:                              \
        return &cache_.k##Name##SymbolOperator;                        \
782 783
      case CompareOperationHint::kBigInt:                              \
        return &cache_.k##Name##BigIntOperator;                        \
784 785
      case CompareOperationHint::kReceiver:                            \
        return &cache_.k##Name##ReceiverOperator;                      \
786 787
      case CompareOperationHint::kReceiverOrNullOrUndefined:           \
        return &cache_.k##Name##ReceiverOrNullOrUndefinedOperator;     \
788 789 790 791 792 793 794 795
      case CompareOperationHint::kAny:                                 \
        return &cache_.k##Name##AnyOperator;                           \
    }                                                                  \
    UNREACHABLE();                                                     \
    return nullptr;                                                    \
  }
COMPARE_OP_LIST(COMPARE_OP)
#undef COMPARE_OP
796

797 798
const Operator* JSOperatorBuilder::StoreDataPropertyInLiteral(
    const VectorSlotPair& feedback) {
799 800
  FeedbackParameter parameters(feedback);
  return new (zone()) Operator1<FeedbackParameter>(  // --
801 802 803 804 805 806 807
      IrOpcode::kJSStoreDataPropertyInLiteral,
      Operator::kNoThrow,              // opcode
      "JSStoreDataPropertyInLiteral",  // name
      4, 1, 1, 0, 1, 0,                // counts
      parameters);                     // parameter
}

808 809 810 811 812 813 814
const Operator* JSOperatorBuilder::StoreInArrayLiteral(
    const VectorSlotPair& feedback) {
  FeedbackParameter parameters(feedback);
  return new (zone()) Operator1<FeedbackParameter>(  // --
      IrOpcode::kJSStoreInArrayLiteral,
      Operator::kNoThrow,       // opcode
      "JSStoreInArrayLiteral",  // name
815
      3, 1, 1, 0, 1, 1,         // counts
816 817 818
      parameters);              // parameter
}

819 820 821
const Operator* JSOperatorBuilder::CallForwardVarargs(size_t arity,
                                                      uint32_t start_index) {
  CallForwardVarargsParameters parameters(arity, start_index);
822 823 824
  return new (zone()) Operator1<CallForwardVarargsParameters>(   // --
      IrOpcode::kJSCallForwardVarargs, Operator::kNoProperties,  // opcode
      "JSCallForwardVarargs",                                    // name
825
      parameters.arity(), 1, 1, 1, 1, 2,                         // counts
826 827 828
      parameters);                                               // parameter
}

829 830
const Operator* JSOperatorBuilder::Call(size_t arity,
                                        CallFrequency const& frequency,
831
                                        VectorSlotPair const& feedback,
832 833
                                        ConvertReceiverMode convert_mode,
                                        SpeculationMode speculation_mode) {
834 835
  DCHECK_IMPLIES(speculation_mode == SpeculationMode::kAllowSpeculation,
                 feedback.IsValid());
836 837
  CallParameters parameters(arity, frequency, feedback, convert_mode,
                            speculation_mode);
838 839 840 841 842
  return new (zone()) Operator1<CallParameters>(   // --
      IrOpcode::kJSCall, Operator::kNoProperties,  // opcode
      "JSCall",                                    // name
      parameters.arity(), 1, 1, 1, 1, 2,           // inputs/outputs
      parameters);                                 // parameter
843 844
}

845 846
const Operator* JSOperatorBuilder::CallWithArrayLike(
    CallFrequency const& frequency) {
847 848 849 850 851
  return new (zone()) Operator1<CallFrequency>(                 // --
      IrOpcode::kJSCallWithArrayLike, Operator::kNoProperties,  // opcode
      "JSCallWithArrayLike",                                    // name
      3, 1, 1, 1, 1, 2,                                         // counts
      frequency);                                               // parameter
852 853
}

854
const Operator* JSOperatorBuilder::CallWithSpread(
855 856
    uint32_t arity, CallFrequency const& frequency,
    VectorSlotPair const& feedback, SpeculationMode speculation_mode) {
857 858
  DCHECK_IMPLIES(speculation_mode == SpeculationMode::kAllowSpeculation,
                 feedback.IsValid());
859
  CallParameters parameters(arity, frequency, feedback,
860
                            ConvertReceiverMode::kAny, speculation_mode);
861
  return new (zone()) Operator1<CallParameters>(             // --
862 863 864 865
      IrOpcode::kJSCallWithSpread, Operator::kNoProperties,  // opcode
      "JSCallWithSpread",                                    // name
      parameters.arity(), 1, 1, 1, 1, 2,                     // counts
      parameters);                                           // parameter
866
}
867

868 869 870 871 872 873
const Operator* JSOperatorBuilder::CallRuntime(Runtime::FunctionId id) {
  const Runtime::Function* f = Runtime::FunctionForId(id);
  return CallRuntime(f, f->nargs);
}


874 875
const Operator* JSOperatorBuilder::CallRuntime(Runtime::FunctionId id,
                                               size_t arity) {
876 877 878 879 880 881 882 883
  const Runtime::Function* f = Runtime::FunctionForId(id);
  return CallRuntime(f, arity);
}


const Operator* JSOperatorBuilder::CallRuntime(const Runtime::Function* f,
                                               size_t arity) {
  CallRuntimeParameters parameters(f->function_id, arity);
884 885 886 887
  DCHECK(f->nargs == -1 || f->nargs == static_cast<int>(parameters.arity()));
  return new (zone()) Operator1<CallRuntimeParameters>(   // --
      IrOpcode::kJSCallRuntime, Operator::kNoProperties,  // opcode
      "JSCallRuntime",                                    // name
888
      parameters.arity(), 1, 1, f->result_size, 1, 2,     // inputs/outputs
889
      parameters);                                        // parameter
890 891 892 893 894 895 896 897 898 899
}

const Operator* JSOperatorBuilder::ConstructForwardVarargs(
    size_t arity, uint32_t start_index) {
  ConstructForwardVarargsParameters parameters(arity, start_index);
  return new (zone()) Operator1<ConstructForwardVarargsParameters>(   // --
      IrOpcode::kJSConstructForwardVarargs, Operator::kNoProperties,  // opcode
      "JSConstructForwardVarargs",                                    // name
      parameters.arity(), 1, 1, 1, 1, 2,                              // counts
      parameters);  // parameter
900 901
}

902 903
// Note: frequency is taken by reference to work around a GCC bug
// on AIX (v8:8193).
904
const Operator* JSOperatorBuilder::Construct(uint32_t arity,
905
                                             CallFrequency const& frequency,
906 907 908 909 910 911 912
                                             VectorSlotPair const& feedback) {
  ConstructParameters parameters(arity, frequency, feedback);
  return new (zone()) Operator1<ConstructParameters>(   // --
      IrOpcode::kJSConstruct, Operator::kNoProperties,  // opcode
      "JSConstruct",                                    // name
      parameters.arity(), 1, 1, 1, 1, 2,                // counts
      parameters);                                      // parameter
913 914
}

915
const Operator* JSOperatorBuilder::ConstructWithArrayLike(
916
    CallFrequency const& frequency) {
917 918 919 920 921 922 923 924
  return new (zone()) Operator1<CallFrequency>(  // --
      IrOpcode::kJSConstructWithArrayLike,       // opcode
      Operator::kNoProperties,                   // properties
      "JSConstructWithArrayLike",                // name
      3, 1, 1, 1, 1, 2,                          // counts
      frequency);                                // parameter
}

925
const Operator* JSOperatorBuilder::ConstructWithSpread(
926 927
    uint32_t arity, CallFrequency const& frequency,
    VectorSlotPair const& feedback) {
928 929
  ConstructParameters parameters(arity, frequency, feedback);
  return new (zone()) Operator1<ConstructParameters>(             // --
930 931 932 933
      IrOpcode::kJSConstructWithSpread, Operator::kNoProperties,  // opcode
      "JSConstructWithSpread",                                    // name
      parameters.arity(), 1, 1, 1, 1, 2,                          // counts
      parameters);                                                // parameter
934
}
935

936
const Operator* JSOperatorBuilder::LoadNamed(Handle<Name> name,
937
                                             const VectorSlotPair& feedback) {
938
  NamedAccess access(LanguageMode::kSloppy, name, feedback);
939
  return new (zone()) Operator1<NamedAccess>(           // --
940 941
      IrOpcode::kJSLoadNamed, Operator::kNoProperties,  // opcode
      "JSLoadNamed",                                    // name
942
      1, 1, 1, 1, 1, 2,                                 // counts
943
      access);                                          // parameter
944 945
}

946
const Operator* JSOperatorBuilder::LoadProperty(
947
    VectorSlotPair const& feedback) {
948
  PropertyAccess access(LanguageMode::kSloppy, feedback);
949
  return new (zone()) Operator1<PropertyAccess>(           // --
950 951
      IrOpcode::kJSLoadProperty, Operator::kNoProperties,  // opcode
      "JSLoadProperty",                                    // name
952
      2, 1, 1, 1, 1, 2,                                    // counts
953
      access);                                             // parameter
954 955
}

956 957 958 959 960 961 962 963 964
const Operator* JSOperatorBuilder::HasProperty(VectorSlotPair const& feedback) {
  PropertyAccess access(LanguageMode::kSloppy, feedback);
  return new (zone()) Operator1<PropertyAccess>(          // --
      IrOpcode::kJSHasProperty, Operator::kNoProperties,  // opcode
      "JSHasProperty",                                    // name
      2, 1, 1, 1, 1, 2,                                   // counts
      access);                                            // parameter
}

965 966 967 968 969 970 971 972 973
const Operator* JSOperatorBuilder::InstanceOf(VectorSlotPair const& feedback) {
  FeedbackParameter parameter(feedback);
  return new (zone()) Operator1<FeedbackParameter>(      // --
      IrOpcode::kJSInstanceOf, Operator::kNoProperties,  // opcode
      "JSInstanceOf",                                    // name
      2, 1, 1, 1, 1, 2,                                  // counts
      parameter);                                        // parameter
}

974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
const Operator* JSOperatorBuilder::ForInNext(ForInMode mode) {
  return new (zone()) Operator1<ForInMode>(             // --
      IrOpcode::kJSForInNext, Operator::kNoProperties,  // opcode
      "JSForInNext",                                    // name
      4, 1, 1, 1, 1, 2,                                 // counts
      mode);                                            // parameter
}

const Operator* JSOperatorBuilder::ForInPrepare(ForInMode mode) {
  return new (zone()) Operator1<ForInMode>(     // --
      IrOpcode::kJSForInPrepare,                // opcode
      Operator::kNoWrite | Operator::kNoThrow,  // flags
      "JSForInPrepare",                         // name
      1, 1, 1, 3, 1, 1,                         // counts
      mode);                                    // parameter
}

991 992 993 994 995 996
const Operator* JSOperatorBuilder::GeneratorStore(int register_count) {
  return new (zone()) Operator1<int>(                   // --
      IrOpcode::kJSGeneratorStore, Operator::kNoThrow,  // opcode
      "JSGeneratorStore",                               // name
      3 + register_count, 1, 1, 0, 1, 0,                // counts
      register_count);                                  // parameter
997 998
}

999 1000 1001 1002 1003
int RegisterCountOf(Operator const* op) {
  DCHECK_EQ(IrOpcode::kJSCreateAsyncFunctionObject, op->opcode());
  return OpParameter<int>(op);
}

1004
int GeneratorStoreValueCountOf(const Operator* op) {
1005 1006 1007 1008
  DCHECK_EQ(IrOpcode::kJSGeneratorStore, op->opcode());
  return OpParameter<int>(op);
}

1009 1010 1011 1012 1013 1014 1015
const Operator* JSOperatorBuilder::GeneratorRestoreRegister(int index) {
  return new (zone()) Operator1<int>(                             // --
      IrOpcode::kJSGeneratorRestoreRegister, Operator::kNoThrow,  // opcode
      "JSGeneratorRestoreRegister",                               // name
      1, 1, 1, 1, 1, 0,                                           // counts
      index);                                                     // parameter
}
1016

1017 1018 1019 1020 1021
int RestoreRegisterIndexOf(const Operator* op) {
  DCHECK_EQ(IrOpcode::kJSGeneratorRestoreRegister, op->opcode());
  return OpParameter<int>(op);
}

1022
const Operator* JSOperatorBuilder::StoreNamed(LanguageMode language_mode,
1023 1024 1025 1026
                                              Handle<Name> name,
                                              VectorSlotPair const& feedback) {
  NamedAccess access(language_mode, name, feedback);
  return new (zone()) Operator1<NamedAccess>(            // --
1027 1028
      IrOpcode::kJSStoreNamed, Operator::kNoProperties,  // opcode
      "JSStoreNamed",                                    // name
1029
      2, 1, 1, 0, 1, 2,                                  // counts
1030
      access);                                           // parameter
1031 1032 1033
}


1034
const Operator* JSOperatorBuilder::StoreProperty(
1035 1036 1037
    LanguageMode language_mode, VectorSlotPair const& feedback) {
  PropertyAccess access(language_mode, feedback);
  return new (zone()) Operator1<PropertyAccess>(            // --
1038 1039
      IrOpcode::kJSStoreProperty, Operator::kNoProperties,  // opcode
      "JSStoreProperty",                                    // name
1040
      3, 1, 1, 0, 1, 2,                                     // counts
1041
      access);                                              // parameter
1042 1043
}

1044 1045 1046 1047 1048 1049 1050 1051 1052
const Operator* JSOperatorBuilder::StoreNamedOwn(
    Handle<Name> name, VectorSlotPair const& feedback) {
  StoreNamedOwnParameters parameters(name, feedback);
  return new (zone()) Operator1<StoreNamedOwnParameters>(   // --
      IrOpcode::kJSStoreNamedOwn, Operator::kNoProperties,  // opcode
      "JSStoreNamedOwn",                                    // name
      2, 1, 1, 0, 1, 2,                                     // counts
      parameters);                                          // parameter
}
1053

1054 1055
const Operator* JSOperatorBuilder::DeleteProperty() {
  return new (zone()) Operator(                              // --
1056 1057
      IrOpcode::kJSDeleteProperty, Operator::kNoProperties,  // opcode
      "JSDeleteProperty",                                    // name
1058
      3, 1, 1, 1, 1, 2);                                     // counts
1059 1060
}

1061 1062 1063 1064 1065 1066
const Operator* JSOperatorBuilder::CreateGeneratorObject() {
  return new (zone()) Operator(                                     // --
      IrOpcode::kJSCreateGeneratorObject, Operator::kEliminatable,  // opcode
      "JSCreateGeneratorObject",                                    // name
      2, 1, 1, 1, 1, 0);                                            // counts
}
1067

1068
const Operator* JSOperatorBuilder::LoadGlobal(const Handle<Name>& name,
1069
                                              const VectorSlotPair& feedback,
1070 1071
                                              TypeofMode typeof_mode) {
  LoadGlobalParameters parameters(name, feedback, typeof_mode);
1072
  return new (zone()) Operator1<LoadGlobalParameters>(   // --
1073 1074
      IrOpcode::kJSLoadGlobal, Operator::kNoProperties,  // opcode
      "JSLoadGlobal",                                    // name
1075
      0, 1, 1, 1, 1, 2,                                  // counts
1076 1077 1078 1079 1080
      parameters);                                       // parameter
}


const Operator* JSOperatorBuilder::StoreGlobal(LanguageMode language_mode,
1081
                                               const Handle<Name>& name,
1082 1083
                                               const VectorSlotPair& feedback) {
  StoreGlobalParameters parameters(language_mode, feedback, name);
1084
  return new (zone()) Operator1<StoreGlobalParameters>(   // --
1085 1086
      IrOpcode::kJSStoreGlobal, Operator::kNoProperties,  // opcode
      "JSStoreGlobal",                                    // name
1087
      1, 1, 1, 0, 1, 2,                                   // counts
1088 1089 1090 1091
      parameters);                                        // parameter
}


1092 1093 1094
const Operator* JSOperatorBuilder::LoadContext(size_t depth, size_t index,
                                               bool immutable) {
  ContextAccess access(depth, index, immutable);
1095 1096 1097 1098
  return new (zone()) Operator1<ContextAccess>(  // --
      IrOpcode::kJSLoadContext,                  // opcode
      Operator::kNoWrite | Operator::kNoThrow,   // flags
      "JSLoadContext",                           // name
1099
      0, 1, 0, 1, 1, 0,                          // counts
1100
      access);                                   // parameter
1101 1102 1103 1104 1105
}


const Operator* JSOperatorBuilder::StoreContext(size_t depth, size_t index) {
  ContextAccess access(depth, index, false);
1106 1107 1108 1109
  return new (zone()) Operator1<ContextAccess>(  // --
      IrOpcode::kJSStoreContext,                 // opcode
      Operator::kNoRead | Operator::kNoThrow,    // flags
      "JSStoreContext",                          // name
1110
      1, 1, 1, 0, 1, 0,                          // counts
1111
      access);                                   // parameter
1112 1113
}

1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
const Operator* JSOperatorBuilder::LoadModule(int32_t cell_index) {
  return new (zone()) Operator1<int32_t>(       // --
      IrOpcode::kJSLoadModule,                  // opcode
      Operator::kNoWrite | Operator::kNoThrow,  // flags
      "JSLoadModule",                           // name
      1, 1, 1, 1, 1, 0,                         // counts
      cell_index);                              // parameter
}

const Operator* JSOperatorBuilder::StoreModule(int32_t cell_index) {
  return new (zone()) Operator1<int32_t>(      // --
      IrOpcode::kJSStoreModule,                // opcode
      Operator::kNoRead | Operator::kNoThrow,  // flags
      "JSStoreModule",                         // name
      2, 1, 1, 0, 1, 0,                        // counts
      cell_index);                             // parameter
}
1131

1132
const Operator* JSOperatorBuilder::CreateArguments(CreateArgumentsType type) {
1133 1134 1135 1136 1137
  return new (zone()) Operator1<CreateArgumentsType>(         // --
      IrOpcode::kJSCreateArguments, Operator::kEliminatable,  // opcode
      "JSCreateArguments",                                    // name
      1, 1, 0, 1, 1, 0,                                       // counts
      type);                                                  // parameter
1138
}
1139

1140 1141
const Operator* JSOperatorBuilder::CreateArray(
    size_t arity, MaybeHandle<AllocationSite> site) {
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
  // constructor, new_target, arg1, ..., argN
  int const value_input_count = static_cast<int>(arity) + 2;
  CreateArrayParameters parameters(arity, site);
  return new (zone()) Operator1<CreateArrayParameters>(   // --
      IrOpcode::kJSCreateArray, Operator::kNoProperties,  // opcode
      "JSCreateArray",                                    // name
      value_input_count, 1, 1, 1, 1, 2,                   // counts
      parameters);                                        // parameter
}

1152 1153 1154 1155 1156 1157 1158 1159 1160
const Operator* JSOperatorBuilder::CreateArrayIterator(IterationKind kind) {
  CreateArrayIteratorParameters parameters(kind);
  return new (zone()) Operator1<CreateArrayIteratorParameters>(   // --
      IrOpcode::kJSCreateArrayIterator, Operator::kEliminatable,  // opcode
      "JSCreateArrayIterator",                                    // name
      1, 1, 1, 1, 1, 0,                                           // counts
      parameters);                                                // parameter
}

1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
const Operator* JSOperatorBuilder::CreateAsyncFunctionObject(
    int register_count) {
  return new (zone()) Operator1<int>(          // --
      IrOpcode::kJSCreateAsyncFunctionObject,  // opcode
      Operator::kEliminatable,                 // flags
      "JSCreateAsyncFunctionObject",           // name
      3, 1, 1, 1, 1, 0,                        // counts
      register_count);                         // parameter
}

1171 1172 1173 1174 1175 1176 1177 1178 1179
const Operator* JSOperatorBuilder::CreateCollectionIterator(
    CollectionKind collection_kind, IterationKind iteration_kind) {
  CreateCollectionIteratorParameters parameters(collection_kind,
                                                iteration_kind);
  return new (zone()) Operator1<CreateCollectionIteratorParameters>(
      IrOpcode::kJSCreateCollectionIterator, Operator::kEliminatable,
      "JSCreateCollectionIterator", 1, 1, 1, 1, 1, 0, parameters);
}

1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
const Operator* JSOperatorBuilder::CreateBoundFunction(size_t arity,
                                                       Handle<Map> map) {
  // bound_target_function, bound_this, arg1, ..., argN
  int const value_input_count = static_cast<int>(arity) + 2;
  CreateBoundFunctionParameters parameters(arity, map);
  return new (zone()) Operator1<CreateBoundFunctionParameters>(   // --
      IrOpcode::kJSCreateBoundFunction, Operator::kEliminatable,  // opcode
      "JSCreateBoundFunction",                                    // name
      value_input_count, 1, 1, 1, 1, 0,                           // counts
      parameters);                                                // parameter
}

1192
const Operator* JSOperatorBuilder::CreateClosure(
1193
    Handle<SharedFunctionInfo> shared_info, Handle<FeedbackCell> feedback_cell,
1194
    Handle<Code> code, AllocationType allocation) {
1195
  CreateClosureParameters parameters(shared_info, feedback_cell, code,
1196
                                     allocation);
1197 1198 1199 1200 1201
  return new (zone()) Operator1<CreateClosureParameters>(   // --
      IrOpcode::kJSCreateClosure, Operator::kEliminatable,  // opcode
      "JSCreateClosure",                                    // name
      0, 1, 1, 1, 1, 0,                                     // counts
      parameters);                                          // parameter
1202 1203
}

1204
const Operator* JSOperatorBuilder::CreateLiteralArray(
1205
    Handle<ArrayBoilerplateDescription> description,
1206
    VectorSlotPair const& feedback, int literal_flags, int number_of_elements) {
1207 1208
  CreateLiteralParameters parameters(description, feedback, number_of_elements,
                                     literal_flags);
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
  return new (zone()) Operator1<CreateLiteralParameters>(  // --
      IrOpcode::kJSCreateLiteralArray,                     // opcode
      Operator::kNoProperties,                             // properties
      "JSCreateLiteralArray",                              // name
      0, 1, 1, 1, 1, 2,                                    // counts
      parameters);                                         // parameter
}

const Operator* JSOperatorBuilder::CreateEmptyLiteralArray(
    VectorSlotPair const& feedback) {
  FeedbackParameter parameters(feedback);
  return new (zone()) Operator1<FeedbackParameter>(  // --
      IrOpcode::kJSCreateEmptyLiteralArray,          // opcode
      Operator::kEliminatable,                       // properties
      "JSCreateEmptyLiteralArray",                   // name
      0, 1, 1, 1, 1, 0,                              // counts
      parameters);                                   // parameter
1226 1227
}

1228 1229 1230 1231 1232 1233 1234 1235
const Operator* JSOperatorBuilder::CreateArrayFromIterable() {
  return new (zone()) Operator(              // --
      IrOpcode::kJSCreateArrayFromIterable,  // opcode
      Operator::kNoProperties,               // properties
      "JSCreateArrayFromIterable",           // name
      1, 1, 1, 1, 1, 2);                     // counts
}

1236
const Operator* JSOperatorBuilder::CreateLiteralObject(
1237
    Handle<ObjectBoilerplateDescription> constant_properties,
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
    VectorSlotPair const& feedback, int literal_flags,
    int number_of_properties) {
  CreateLiteralParameters parameters(constant_properties, feedback,
                                     number_of_properties, literal_flags);
  return new (zone()) Operator1<CreateLiteralParameters>(  // --
      IrOpcode::kJSCreateLiteralObject,                    // opcode
      Operator::kNoProperties,                             // properties
      "JSCreateLiteralObject",                             // name
      0, 1, 1, 1, 1, 2,                                    // counts
      parameters);                                         // parameter
1248 1249
}

1250 1251 1252 1253 1254 1255 1256
const Operator* JSOperatorBuilder::CloneObject(VectorSlotPair const& feedback,
                                               int literal_flags) {
  CloneObjectParameters parameters(feedback, literal_flags);
  return new (zone()) Operator1<CloneObjectParameters>(  // --
      IrOpcode::kJSCloneObject,                          // opcode
      Operator::kNoProperties,                           // properties
      "JSCloneObject",                                   // name
1257
      1, 1, 1, 1, 1, 2,                                  // counts
1258 1259 1260
      parameters);                                       // parameter
}

1261 1262
const Operator* JSOperatorBuilder::CreateEmptyLiteralObject() {
  return new (zone()) Operator(               // --
1263 1264 1265
      IrOpcode::kJSCreateEmptyLiteralObject,  // opcode
      Operator::kNoProperties,                // properties
      "JSCreateEmptyLiteralObject",           // name
1266
      1, 1, 1, 1, 1, 2);                      // counts
1267
}
1268 1269

const Operator* JSOperatorBuilder::CreateLiteralRegExp(
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
    Handle<String> constant_pattern, VectorSlotPair const& feedback,
    int literal_flags) {
  CreateLiteralParameters parameters(constant_pattern, feedback, -1,
                                     literal_flags);
  return new (zone()) Operator1<CreateLiteralParameters>(  // --
      IrOpcode::kJSCreateLiteralRegExp,                    // opcode
      Operator::kNoProperties,                             // properties
      "JSCreateLiteralRegExp",                             // name
      0, 1, 1, 1, 1, 2,                                    // counts
      parameters);                                         // parameter
1280 1281
}

1282 1283 1284 1285
const Operator* JSOperatorBuilder::CreateFunctionContext(
    Handle<ScopeInfo> scope_info, int slot_count, ScopeType scope_type) {
  CreateFunctionContextParameters parameters(scope_info, slot_count,
                                             scope_type);
1286
  return new (zone()) Operator1<CreateFunctionContextParameters>(   // --
1287 1288
      IrOpcode::kJSCreateFunctionContext, Operator::kNoProperties,  // opcode
      "JSCreateFunctionContext",                                    // name
1289
      0, 1, 1, 1, 1, 2,                                             // counts
1290
      parameters);                                                  // parameter
1291 1292
}

1293
const Operator* JSOperatorBuilder::CreateCatchContext(
1294 1295
    const Handle<ScopeInfo>& scope_info) {
  return new (zone()) Operator1<Handle<ScopeInfo>>(
1296 1297
      IrOpcode::kJSCreateCatchContext, Operator::kNoProperties,  // opcode
      "JSCreateCatchContext",                                    // name
1298
      1, 1, 1, 1, 1, 2,                                          // counts
1299
      scope_info);                                               // parameter
1300 1301
}

1302 1303 1304 1305 1306
const Operator* JSOperatorBuilder::CreateWithContext(
    const Handle<ScopeInfo>& scope_info) {
  return new (zone()) Operator1<Handle<ScopeInfo>>(
      IrOpcode::kJSCreateWithContext, Operator::kNoProperties,  // opcode
      "JSCreateWithContext",                                    // name
1307
      1, 1, 1, 1, 1, 2,                                         // counts
1308 1309
      scope_info);                                              // parameter
}
1310 1311

const Operator* JSOperatorBuilder::CreateBlockContext(
1312
    const Handle<ScopeInfo>& scope_info) {
1313
  return new (zone()) Operator1<Handle<ScopeInfo>>(              // --
1314 1315
      IrOpcode::kJSCreateBlockContext, Operator::kNoProperties,  // opcode
      "JSCreateBlockContext",                                    // name
1316
      0, 1, 1, 1, 1, 2,                                          // counts
1317
      scope_info);                                               // parameter
1318 1319
}

1320 1321
Handle<ScopeInfo> ScopeInfoOf(const Operator* op) {
  DCHECK(IrOpcode::kJSCreateBlockContext == op->opcode() ||
1322 1323
         IrOpcode::kJSCreateWithContext == op->opcode() ||
         IrOpcode::kJSCreateCatchContext == op->opcode());
1324 1325 1326
  return OpParameter<Handle<ScopeInfo>>(op);
}

1327 1328 1329 1330
#undef BINARY_OP_LIST
#undef CACHED_OP_LIST
#undef COMPARE_OP_LIST

1331 1332 1333
}  // namespace compiler
}  // namespace internal
}  // namespace v8