1 // Copyright 2013 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_COMPILER_JS_OPERATOR_H_ 6 #define V8_COMPILER_JS_OPERATOR_H_ 7 8 #include "src/base/compiler-specific.h" 9 #include "src/globals.h" 10 #include "src/handles.h" 11 #include "src/runtime/runtime.h" 12 #include "src/type-hints.h" 13 #include "src/vector-slot-pair.h" 14 15 namespace v8 { 16 namespace internal { 17 18 class AllocationSite; 19 class BoilerplateDescription; 20 class ConstantElementsPair; 21 class FeedbackCell; 22 class SharedFunctionInfo; 23 24 namespace compiler { 25 26 // Forward declarations. 27 class Operator; 28 struct JSOperatorGlobalCache; 29 30 // Defines the frequency a given Call/Construct site was executed. For some 31 // call sites the frequency is not known. 32 class CallFrequency final { 33 public: CallFrequency()34 CallFrequency() : value_(std::numeric_limits<float>::quiet_NaN()) {} CallFrequency(float value)35 explicit CallFrequency(float value) : value_(value) { 36 DCHECK(!std::isnan(value)); 37 } 38 IsKnown()39 bool IsKnown() const { return !IsUnknown(); } IsUnknown()40 bool IsUnknown() const { return std::isnan(value_); } value()41 float value() const { 42 DCHECK(IsKnown()); 43 return value_; 44 } 45 46 bool operator==(CallFrequency const& that) const { 47 return bit_cast<uint32_t>(this->value_) == bit_cast<uint32_t>(that.value_); 48 } 49 bool operator!=(CallFrequency const& that) const { return !(*this == that); } 50 hash_value(CallFrequency f)51 friend size_t hash_value(CallFrequency f) { 52 return bit_cast<uint32_t>(f.value_); 53 } 54 55 private: 56 float value_; 57 }; 58 59 std::ostream& operator<<(std::ostream&, CallFrequency); 60 61 CallFrequency CallFrequencyOf(Operator const* op) V8_WARN_UNUSED_RESULT; 62 63 // Defines the flags for a JavaScript call forwarding parameters. This 64 // is used as parameter by JSConstructForwardVarargs operators. 65 class ConstructForwardVarargsParameters final { 66 public: ConstructForwardVarargsParameters(size_t arity,uint32_t start_index)67 ConstructForwardVarargsParameters(size_t arity, uint32_t start_index) 68 : bit_field_(ArityField::encode(arity) | 69 StartIndexField::encode(start_index)) {} 70 arity()71 size_t arity() const { return ArityField::decode(bit_field_); } start_index()72 uint32_t start_index() const { return StartIndexField::decode(bit_field_); } 73 74 bool operator==(ConstructForwardVarargsParameters const& that) const { 75 return this->bit_field_ == that.bit_field_; 76 } 77 bool operator!=(ConstructForwardVarargsParameters const& that) const { 78 return !(*this == that); 79 } 80 81 private: hash_value(ConstructForwardVarargsParameters const & p)82 friend size_t hash_value(ConstructForwardVarargsParameters const& p) { 83 return p.bit_field_; 84 } 85 86 typedef BitField<size_t, 0, 16> ArityField; 87 typedef BitField<uint32_t, 16, 16> StartIndexField; 88 89 uint32_t const bit_field_; 90 }; 91 92 std::ostream& operator<<(std::ostream&, 93 ConstructForwardVarargsParameters const&); 94 95 ConstructForwardVarargsParameters const& ConstructForwardVarargsParametersOf( 96 Operator const*) V8_WARN_UNUSED_RESULT; 97 98 // Defines the arity and the feedback for a JavaScript constructor call. This is 99 // used as a parameter by JSConstruct and JSConstructWithSpread operators. 100 class ConstructParameters final { 101 public: ConstructParameters(uint32_t arity,CallFrequency frequency,VectorSlotPair const & feedback)102 ConstructParameters(uint32_t arity, CallFrequency frequency, 103 VectorSlotPair const& feedback) 104 : arity_(arity), frequency_(frequency), feedback_(feedback) {} 105 arity()106 uint32_t arity() const { return arity_; } frequency()107 CallFrequency frequency() const { return frequency_; } feedback()108 VectorSlotPair const& feedback() const { return feedback_; } 109 110 private: 111 uint32_t const arity_; 112 CallFrequency const frequency_; 113 VectorSlotPair const feedback_; 114 }; 115 116 bool operator==(ConstructParameters const&, ConstructParameters const&); 117 bool operator!=(ConstructParameters const&, ConstructParameters const&); 118 119 size_t hash_value(ConstructParameters const&); 120 121 std::ostream& operator<<(std::ostream&, ConstructParameters const&); 122 123 ConstructParameters const& ConstructParametersOf(Operator const*); 124 125 // Defines the flags for a JavaScript call forwarding parameters. This 126 // is used as parameter by JSCallForwardVarargs operators. 127 class CallForwardVarargsParameters final { 128 public: CallForwardVarargsParameters(size_t arity,uint32_t start_index)129 CallForwardVarargsParameters(size_t arity, uint32_t start_index) 130 : bit_field_(ArityField::encode(arity) | 131 StartIndexField::encode(start_index)) {} 132 arity()133 size_t arity() const { return ArityField::decode(bit_field_); } start_index()134 uint32_t start_index() const { return StartIndexField::decode(bit_field_); } 135 136 bool operator==(CallForwardVarargsParameters const& that) const { 137 return this->bit_field_ == that.bit_field_; 138 } 139 bool operator!=(CallForwardVarargsParameters const& that) const { 140 return !(*this == that); 141 } 142 143 private: hash_value(CallForwardVarargsParameters const & p)144 friend size_t hash_value(CallForwardVarargsParameters const& p) { 145 return p.bit_field_; 146 } 147 148 typedef BitField<size_t, 0, 15> ArityField; 149 typedef BitField<uint32_t, 15, 15> StartIndexField; 150 151 uint32_t const bit_field_; 152 }; 153 154 std::ostream& operator<<(std::ostream&, CallForwardVarargsParameters const&); 155 156 CallForwardVarargsParameters const& CallForwardVarargsParametersOf( 157 Operator const*) V8_WARN_UNUSED_RESULT; 158 159 // Defines the arity and the call flags for a JavaScript function call. This is 160 // used as a parameter by JSCall and JSCallWithSpread operators. 161 class CallParameters final { 162 public: CallParameters(size_t arity,CallFrequency const & frequency,VectorSlotPair const & feedback,ConvertReceiverMode convert_mode,SpeculationMode speculation_mode)163 CallParameters(size_t arity, CallFrequency const& frequency, 164 VectorSlotPair const& feedback, 165 ConvertReceiverMode convert_mode, 166 SpeculationMode speculation_mode) 167 : bit_field_(ArityField::encode(arity) | 168 SpeculationModeField::encode(speculation_mode) | 169 ConvertReceiverModeField::encode(convert_mode)), 170 frequency_(frequency), 171 feedback_(feedback) {} 172 arity()173 size_t arity() const { return ArityField::decode(bit_field_); } frequency()174 CallFrequency const& frequency() const { return frequency_; } convert_mode()175 ConvertReceiverMode convert_mode() const { 176 return ConvertReceiverModeField::decode(bit_field_); 177 } feedback()178 VectorSlotPair const& feedback() const { return feedback_; } 179 speculation_mode()180 SpeculationMode speculation_mode() const { 181 return SpeculationModeField::decode(bit_field_); 182 } 183 184 bool operator==(CallParameters const& that) const { 185 return this->bit_field_ == that.bit_field_ && 186 this->frequency_ == that.frequency_ && 187 this->feedback_ == that.feedback_; 188 } 189 bool operator!=(CallParameters const& that) const { return !(*this == that); } 190 191 private: hash_value(CallParameters const & p)192 friend size_t hash_value(CallParameters const& p) { 193 return base::hash_combine(p.bit_field_, p.frequency_, p.feedback_); 194 } 195 196 typedef BitField<size_t, 0, 28> ArityField; 197 typedef BitField<SpeculationMode, 28, 1> SpeculationModeField; 198 typedef BitField<ConvertReceiverMode, 29, 2> ConvertReceiverModeField; 199 200 uint32_t const bit_field_; 201 CallFrequency const frequency_; 202 VectorSlotPair const feedback_; 203 }; 204 205 size_t hash_value(CallParameters const&); 206 207 std::ostream& operator<<(std::ostream&, CallParameters const&); 208 209 const CallParameters& CallParametersOf(const Operator* op); 210 211 212 // Defines the arity and the ID for a runtime function call. This is used as a 213 // parameter by JSCallRuntime operators. 214 class CallRuntimeParameters final { 215 public: CallRuntimeParameters(Runtime::FunctionId id,size_t arity)216 CallRuntimeParameters(Runtime::FunctionId id, size_t arity) 217 : id_(id), arity_(arity) {} 218 id()219 Runtime::FunctionId id() const { return id_; } arity()220 size_t arity() const { return arity_; } 221 222 private: 223 const Runtime::FunctionId id_; 224 const size_t arity_; 225 }; 226 227 bool operator==(CallRuntimeParameters const&, CallRuntimeParameters const&); 228 bool operator!=(CallRuntimeParameters const&, CallRuntimeParameters const&); 229 230 size_t hash_value(CallRuntimeParameters const&); 231 232 std::ostream& operator<<(std::ostream&, CallRuntimeParameters const&); 233 234 const CallRuntimeParameters& CallRuntimeParametersOf(const Operator* op); 235 236 237 // Defines the location of a context slot relative to a specific scope. This is 238 // used as a parameter by JSLoadContext and JSStoreContext operators and allows 239 // accessing a context-allocated variable without keeping track of the scope. 240 class ContextAccess final { 241 public: 242 ContextAccess(size_t depth, size_t index, bool immutable); 243 depth()244 size_t depth() const { return depth_; } index()245 size_t index() const { return index_; } immutable()246 bool immutable() const { return immutable_; } 247 248 private: 249 // For space reasons, we keep this tightly packed, otherwise we could just use 250 // a simple int/int/bool POD. 251 const bool immutable_; 252 const uint16_t depth_; 253 const uint32_t index_; 254 }; 255 256 bool operator==(ContextAccess const&, ContextAccess const&); 257 bool operator!=(ContextAccess const&, ContextAccess const&); 258 259 size_t hash_value(ContextAccess const&); 260 261 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, ContextAccess const&); 262 263 V8_EXPORT_PRIVATE ContextAccess const& ContextAccessOf(Operator const*); 264 265 // Defines the slot count and ScopeType for a new function or eval context. This 266 // is used as a parameter by the JSCreateFunctionContext operator. 267 class CreateFunctionContextParameters final { 268 public: 269 CreateFunctionContextParameters(Handle<ScopeInfo> scope_info, int slot_count, 270 ScopeType scope_type); 271 scope_info()272 Handle<ScopeInfo> scope_info() const { return scope_info_; } slot_count()273 int slot_count() const { return slot_count_; } scope_type()274 ScopeType scope_type() const { return scope_type_; } 275 276 private: 277 Handle<ScopeInfo> scope_info_; 278 int const slot_count_; 279 ScopeType const scope_type_; 280 }; 281 282 bool operator==(CreateFunctionContextParameters const& lhs, 283 CreateFunctionContextParameters const& rhs); 284 bool operator!=(CreateFunctionContextParameters const& lhs, 285 CreateFunctionContextParameters const& rhs); 286 287 size_t hash_value(CreateFunctionContextParameters const& parameters); 288 289 std::ostream& operator<<(std::ostream& os, 290 CreateFunctionContextParameters const& parameters); 291 292 CreateFunctionContextParameters const& CreateFunctionContextParametersOf( 293 Operator const*); 294 295 // Defines parameters for JSStoreNamedOwn operator. 296 class StoreNamedOwnParameters final { 297 public: StoreNamedOwnParameters(Handle<Name> name,VectorSlotPair const & feedback)298 StoreNamedOwnParameters(Handle<Name> name, VectorSlotPair const& feedback) 299 : name_(name), feedback_(feedback) {} 300 name()301 Handle<Name> name() const { return name_; } feedback()302 VectorSlotPair const& feedback() const { return feedback_; } 303 304 private: 305 Handle<Name> const name_; 306 VectorSlotPair const feedback_; 307 }; 308 309 bool operator==(StoreNamedOwnParameters const&, StoreNamedOwnParameters const&); 310 bool operator!=(StoreNamedOwnParameters const&, StoreNamedOwnParameters const&); 311 312 size_t hash_value(StoreNamedOwnParameters const&); 313 314 std::ostream& operator<<(std::ostream&, StoreNamedOwnParameters const&); 315 316 const StoreNamedOwnParameters& StoreNamedOwnParametersOf(const Operator* op); 317 318 // Defines the feedback, i.e., vector and index, for storing a data property in 319 // an object literal. This is used as a parameter by JSCreateEmptyLiteralArray 320 // and JSStoreDataPropertyInLiteral operators. 321 class FeedbackParameter final { 322 public: FeedbackParameter(VectorSlotPair const & feedback)323 explicit FeedbackParameter(VectorSlotPair const& feedback) 324 : feedback_(feedback) {} 325 feedback()326 VectorSlotPair const& feedback() const { return feedback_; } 327 328 private: 329 VectorSlotPair const feedback_; 330 }; 331 332 bool operator==(FeedbackParameter const&, FeedbackParameter const&); 333 bool operator!=(FeedbackParameter const&, FeedbackParameter const&); 334 335 size_t hash_value(FeedbackParameter const&); 336 337 std::ostream& operator<<(std::ostream&, FeedbackParameter const&); 338 339 const FeedbackParameter& FeedbackParameterOf(const Operator* op); 340 341 // Defines the property of an object for a named access. This is 342 // used as a parameter by the JSLoadNamed and JSStoreNamed operators. 343 class NamedAccess final { 344 public: NamedAccess(LanguageMode language_mode,Handle<Name> name,VectorSlotPair const & feedback)345 NamedAccess(LanguageMode language_mode, Handle<Name> name, 346 VectorSlotPair const& feedback) 347 : name_(name), feedback_(feedback), language_mode_(language_mode) {} 348 name()349 Handle<Name> name() const { return name_; } language_mode()350 LanguageMode language_mode() const { return language_mode_; } feedback()351 VectorSlotPair const& feedback() const { return feedback_; } 352 353 private: 354 Handle<Name> const name_; 355 VectorSlotPair const feedback_; 356 LanguageMode const language_mode_; 357 }; 358 359 bool operator==(NamedAccess const&, NamedAccess const&); 360 bool operator!=(NamedAccess const&, NamedAccess const&); 361 362 size_t hash_value(NamedAccess const&); 363 364 std::ostream& operator<<(std::ostream&, NamedAccess const&); 365 366 const NamedAccess& NamedAccessOf(const Operator* op); 367 368 369 // Defines the property being loaded from an object by a named load. This is 370 // used as a parameter by JSLoadGlobal operator. 371 class LoadGlobalParameters final { 372 public: LoadGlobalParameters(const Handle<Name> & name,const VectorSlotPair & feedback,TypeofMode typeof_mode)373 LoadGlobalParameters(const Handle<Name>& name, const VectorSlotPair& feedback, 374 TypeofMode typeof_mode) 375 : name_(name), feedback_(feedback), typeof_mode_(typeof_mode) {} 376 name()377 const Handle<Name>& name() const { return name_; } typeof_mode()378 TypeofMode typeof_mode() const { return typeof_mode_; } 379 feedback()380 const VectorSlotPair& feedback() const { return feedback_; } 381 382 private: 383 const Handle<Name> name_; 384 const VectorSlotPair feedback_; 385 const TypeofMode typeof_mode_; 386 }; 387 388 bool operator==(LoadGlobalParameters const&, LoadGlobalParameters const&); 389 bool operator!=(LoadGlobalParameters const&, LoadGlobalParameters const&); 390 391 size_t hash_value(LoadGlobalParameters const&); 392 393 std::ostream& operator<<(std::ostream&, LoadGlobalParameters const&); 394 395 const LoadGlobalParameters& LoadGlobalParametersOf(const Operator* op); 396 397 398 // Defines the property being stored to an object by a named store. This is 399 // used as a parameter by JSStoreGlobal operator. 400 class StoreGlobalParameters final { 401 public: StoreGlobalParameters(LanguageMode language_mode,const VectorSlotPair & feedback,const Handle<Name> & name)402 StoreGlobalParameters(LanguageMode language_mode, 403 const VectorSlotPair& feedback, 404 const Handle<Name>& name) 405 : language_mode_(language_mode), name_(name), feedback_(feedback) {} 406 language_mode()407 LanguageMode language_mode() const { return language_mode_; } feedback()408 const VectorSlotPair& feedback() const { return feedback_; } name()409 const Handle<Name>& name() const { return name_; } 410 411 private: 412 const LanguageMode language_mode_; 413 const Handle<Name> name_; 414 const VectorSlotPair feedback_; 415 }; 416 417 bool operator==(StoreGlobalParameters const&, StoreGlobalParameters const&); 418 bool operator!=(StoreGlobalParameters const&, StoreGlobalParameters const&); 419 420 size_t hash_value(StoreGlobalParameters const&); 421 422 std::ostream& operator<<(std::ostream&, StoreGlobalParameters const&); 423 424 const StoreGlobalParameters& StoreGlobalParametersOf(const Operator* op); 425 426 427 // Defines the property of an object for a keyed access. This is used 428 // as a parameter by the JSLoadProperty and JSStoreProperty operators. 429 class PropertyAccess final { 430 public: PropertyAccess(LanguageMode language_mode,VectorSlotPair const & feedback)431 PropertyAccess(LanguageMode language_mode, VectorSlotPair const& feedback) 432 : feedback_(feedback), language_mode_(language_mode) {} 433 language_mode()434 LanguageMode language_mode() const { return language_mode_; } feedback()435 VectorSlotPair const& feedback() const { return feedback_; } 436 437 private: 438 VectorSlotPair const feedback_; 439 LanguageMode const language_mode_; 440 }; 441 442 bool operator==(PropertyAccess const&, PropertyAccess const&); 443 bool operator!=(PropertyAccess const&, PropertyAccess const&); 444 445 size_t hash_value(PropertyAccess const&); 446 447 std::ostream& operator<<(std::ostream&, PropertyAccess const&); 448 449 PropertyAccess const& PropertyAccessOf(const Operator* op); 450 451 452 // CreateArgumentsType is used as parameter to JSCreateArguments nodes. 453 CreateArgumentsType const& CreateArgumentsTypeOf(const Operator* op); 454 455 456 // Defines shared information for the array that should be created. This is 457 // used as parameter by JSCreateArray operators. 458 class CreateArrayParameters final { 459 public: CreateArrayParameters(size_t arity,Handle<AllocationSite> site)460 explicit CreateArrayParameters(size_t arity, Handle<AllocationSite> site) 461 : arity_(arity), site_(site) {} 462 arity()463 size_t arity() const { return arity_; } site()464 Handle<AllocationSite> site() const { return site_; } 465 466 private: 467 size_t const arity_; 468 Handle<AllocationSite> const site_; 469 }; 470 471 bool operator==(CreateArrayParameters const&, CreateArrayParameters const&); 472 bool operator!=(CreateArrayParameters const&, CreateArrayParameters const&); 473 474 size_t hash_value(CreateArrayParameters const&); 475 476 std::ostream& operator<<(std::ostream&, CreateArrayParameters const&); 477 478 const CreateArrayParameters& CreateArrayParametersOf(const Operator* op); 479 480 // Defines shared information for the array iterator that should be created. 481 // This is used as parameter by JSCreateArrayIterator operators. 482 class CreateArrayIteratorParameters final { 483 public: CreateArrayIteratorParameters(IterationKind kind)484 explicit CreateArrayIteratorParameters(IterationKind kind) : kind_(kind) {} 485 kind()486 IterationKind kind() const { return kind_; } 487 488 private: 489 IterationKind const kind_; 490 }; 491 492 bool operator==(CreateArrayIteratorParameters const&, 493 CreateArrayIteratorParameters const&); 494 bool operator!=(CreateArrayIteratorParameters const&, 495 CreateArrayIteratorParameters const&); 496 497 size_t hash_value(CreateArrayIteratorParameters const&); 498 499 std::ostream& operator<<(std::ostream&, CreateArrayIteratorParameters const&); 500 501 const CreateArrayIteratorParameters& CreateArrayIteratorParametersOf( 502 const Operator* op); 503 504 // Defines shared information for the array iterator that should be created. 505 // This is used as parameter by JSCreateCollectionIterator operators. 506 class CreateCollectionIteratorParameters final { 507 public: CreateCollectionIteratorParameters(CollectionKind collection_kind,IterationKind iteration_kind)508 explicit CreateCollectionIteratorParameters(CollectionKind collection_kind, 509 IterationKind iteration_kind) 510 : collection_kind_(collection_kind), iteration_kind_(iteration_kind) { 511 CHECK(!(collection_kind == CollectionKind::kSet && 512 iteration_kind == IterationKind::kKeys)); 513 } 514 collection_kind()515 CollectionKind collection_kind() const { return collection_kind_; } iteration_kind()516 IterationKind iteration_kind() const { return iteration_kind_; } 517 518 private: 519 CollectionKind const collection_kind_; 520 IterationKind const iteration_kind_; 521 }; 522 523 bool operator==(CreateCollectionIteratorParameters const&, 524 CreateCollectionIteratorParameters const&); 525 bool operator!=(CreateCollectionIteratorParameters const&, 526 CreateCollectionIteratorParameters const&); 527 528 size_t hash_value(CreateCollectionIteratorParameters const&); 529 530 std::ostream& operator<<(std::ostream&, 531 CreateCollectionIteratorParameters const&); 532 533 const CreateCollectionIteratorParameters& CreateCollectionIteratorParametersOf( 534 const Operator* op); 535 536 // Defines shared information for the bound function that should be created. 537 // This is used as parameter by JSCreateBoundFunction operators. 538 class CreateBoundFunctionParameters final { 539 public: CreateBoundFunctionParameters(size_t arity,Handle<Map> map)540 CreateBoundFunctionParameters(size_t arity, Handle<Map> map) 541 : arity_(arity), map_(map) {} 542 arity()543 size_t arity() const { return arity_; } map()544 Handle<Map> map() const { return map_; } 545 546 private: 547 size_t const arity_; 548 Handle<Map> const map_; 549 }; 550 551 bool operator==(CreateBoundFunctionParameters const&, 552 CreateBoundFunctionParameters const&); 553 bool operator!=(CreateBoundFunctionParameters const&, 554 CreateBoundFunctionParameters const&); 555 556 size_t hash_value(CreateBoundFunctionParameters const&); 557 558 std::ostream& operator<<(std::ostream&, CreateBoundFunctionParameters const&); 559 560 const CreateBoundFunctionParameters& CreateBoundFunctionParametersOf( 561 const Operator* op); 562 563 // Defines shared information for the closure that should be created. This is 564 // used as a parameter by JSCreateClosure operators. 565 class CreateClosureParameters final { 566 public: CreateClosureParameters(Handle<SharedFunctionInfo> shared_info,Handle<FeedbackCell> feedback_cell,Handle<Code> code,PretenureFlag pretenure)567 CreateClosureParameters(Handle<SharedFunctionInfo> shared_info, 568 Handle<FeedbackCell> feedback_cell, Handle<Code> code, 569 PretenureFlag pretenure) 570 : shared_info_(shared_info), 571 feedback_cell_(feedback_cell), 572 code_(code), 573 pretenure_(pretenure) {} 574 shared_info()575 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } feedback_cell()576 Handle<FeedbackCell> feedback_cell() const { return feedback_cell_; } code()577 Handle<Code> code() const { return code_; } pretenure()578 PretenureFlag pretenure() const { return pretenure_; } 579 580 private: 581 Handle<SharedFunctionInfo> const shared_info_; 582 Handle<FeedbackCell> const feedback_cell_; 583 Handle<Code> const code_; 584 PretenureFlag const pretenure_; 585 }; 586 587 bool operator==(CreateClosureParameters const&, CreateClosureParameters const&); 588 bool operator!=(CreateClosureParameters const&, CreateClosureParameters const&); 589 590 size_t hash_value(CreateClosureParameters const&); 591 592 std::ostream& operator<<(std::ostream&, CreateClosureParameters const&); 593 594 const CreateClosureParameters& CreateClosureParametersOf(const Operator* op); 595 596 // Defines shared information for the literal that should be created. This is 597 // used as parameter by JSCreateLiteralArray, JSCreateLiteralObject and 598 // JSCreateLiteralRegExp operators. 599 class CreateLiteralParameters final { 600 public: CreateLiteralParameters(Handle<HeapObject> constant,VectorSlotPair const & feedback,int length,int flags)601 CreateLiteralParameters(Handle<HeapObject> constant, 602 VectorSlotPair const& feedback, int length, int flags) 603 : constant_(constant), 604 feedback_(feedback), 605 length_(length), 606 flags_(flags) {} 607 constant()608 Handle<HeapObject> constant() const { return constant_; } feedback()609 VectorSlotPair const& feedback() const { return feedback_; } length()610 int length() const { return length_; } flags()611 int flags() const { return flags_; } 612 613 private: 614 Handle<HeapObject> const constant_; 615 VectorSlotPair const feedback_; 616 int const length_; 617 int const flags_; 618 }; 619 620 bool operator==(CreateLiteralParameters const&, CreateLiteralParameters const&); 621 bool operator!=(CreateLiteralParameters const&, CreateLiteralParameters const&); 622 623 size_t hash_value(CreateLiteralParameters const&); 624 625 std::ostream& operator<<(std::ostream&, CreateLiteralParameters const&); 626 627 const CreateLiteralParameters& CreateLiteralParametersOf(const Operator* op); 628 629 // Descriptor used by the JSForInPrepare and JSForInNext opcodes. 630 enum class ForInMode : uint8_t { 631 kUseEnumCacheKeysAndIndices, 632 kUseEnumCacheKeys, 633 kGeneric 634 }; 635 636 size_t hash_value(ForInMode); 637 638 std::ostream& operator<<(std::ostream&, ForInMode); 639 640 ForInMode ForInModeOf(Operator const* op) V8_WARN_UNUSED_RESULT; 641 642 BinaryOperationHint BinaryOperationHintOf(const Operator* op); 643 644 CompareOperationHint CompareOperationHintOf(const Operator* op); 645 646 int GeneratorStoreRegisterCountOf(const Operator* op) V8_WARN_UNUSED_RESULT; 647 int RestoreRegisterIndexOf(const Operator* op) V8_WARN_UNUSED_RESULT; 648 649 Handle<ScopeInfo> ScopeInfoOf(const Operator* op) V8_WARN_UNUSED_RESULT; 650 651 // Interface for building JavaScript-level operators, e.g. directly from the 652 // AST. Most operators have no parameters, thus can be globally shared for all 653 // graphs. 654 class V8_EXPORT_PRIVATE JSOperatorBuilder final NON_EXPORTED_BASE(ZoneObject)655 : public NON_EXPORTED_BASE(ZoneObject) { 656 public: 657 explicit JSOperatorBuilder(Zone* zone); 658 659 const Operator* Equal(CompareOperationHint hint); 660 const Operator* StrictEqual(CompareOperationHint hint); 661 const Operator* LessThan(CompareOperationHint hint); 662 const Operator* GreaterThan(CompareOperationHint hint); 663 const Operator* LessThanOrEqual(CompareOperationHint hint); 664 const Operator* GreaterThanOrEqual(CompareOperationHint hint); 665 666 const Operator* BitwiseOr(); 667 const Operator* BitwiseXor(); 668 const Operator* BitwiseAnd(); 669 const Operator* ShiftLeft(); 670 const Operator* ShiftRight(); 671 const Operator* ShiftRightLogical(); 672 const Operator* Add(BinaryOperationHint hint); 673 const Operator* Subtract(); 674 const Operator* Multiply(); 675 const Operator* Divide(); 676 const Operator* Modulus(); 677 const Operator* Exponentiate(); 678 679 const Operator* BitwiseNot(); 680 const Operator* Decrement(); 681 const Operator* Increment(); 682 const Operator* Negate(); 683 684 const Operator* ToInteger(); 685 const Operator* ToLength(); 686 const Operator* ToName(); 687 const Operator* ToNumber(); 688 const Operator* ToNumeric(); 689 const Operator* ToObject(); 690 const Operator* ToString(); 691 692 const Operator* Create(); 693 const Operator* CreateArguments(CreateArgumentsType type); 694 const Operator* CreateArray(size_t arity, Handle<AllocationSite> site); 695 const Operator* CreateArrayIterator(IterationKind); 696 const Operator* CreateCollectionIterator(CollectionKind, IterationKind); 697 const Operator* CreateBoundFunction(size_t arity, Handle<Map> map); 698 const Operator* CreateClosure(Handle<SharedFunctionInfo> shared_info, 699 Handle<FeedbackCell> feedback_cell, 700 Handle<Code> code, 701 PretenureFlag pretenure = NOT_TENURED); 702 const Operator* CreateIterResultObject(); 703 const Operator* CreateStringIterator(); 704 const Operator* CreateKeyValueArray(); 705 const Operator* CreateObject(); 706 const Operator* CreatePromise(); 707 const Operator* CreateTypedArray(); 708 const Operator* CreateLiteralArray(Handle<ConstantElementsPair> constant, 709 VectorSlotPair const& feedback, 710 int literal_flags, int number_of_elements); 711 const Operator* CreateEmptyLiteralArray(VectorSlotPair const& feedback); 712 const Operator* CreateEmptyLiteralObject(); 713 714 const Operator* CreateLiteralObject(Handle<BoilerplateDescription> constant, 715 VectorSlotPair const& feedback, 716 int literal_flags, 717 int number_of_properties); 718 const Operator* CreateLiteralRegExp(Handle<String> constant_pattern, 719 VectorSlotPair const& feedback, 720 int literal_flags); 721 722 const Operator* CallForwardVarargs(size_t arity, uint32_t start_index); 723 const Operator* Call( 724 size_t arity, CallFrequency const& frequency = CallFrequency(), 725 VectorSlotPair const& feedback = VectorSlotPair(), 726 ConvertReceiverMode convert_mode = ConvertReceiverMode::kAny, 727 SpeculationMode speculation_mode = SpeculationMode::kDisallowSpeculation); 728 const Operator* CallWithArrayLike(CallFrequency frequency); 729 const Operator* CallWithSpread( 730 uint32_t arity, CallFrequency const& frequency = CallFrequency(), 731 VectorSlotPair const& feedback = VectorSlotPair(), 732 SpeculationMode speculation_mode = SpeculationMode::kDisallowSpeculation); 733 const Operator* CallRuntime(Runtime::FunctionId id); 734 const Operator* CallRuntime(Runtime::FunctionId id, size_t arity); 735 const Operator* CallRuntime(const Runtime::Function* function, size_t arity); 736 737 const Operator* ConstructForwardVarargs(size_t arity, uint32_t start_index); 738 const Operator* Construct(uint32_t arity, 739 CallFrequency frequency = CallFrequency(), 740 VectorSlotPair const& feedback = VectorSlotPair()); 741 const Operator* ConstructWithArrayLike(CallFrequency frequency); 742 const Operator* ConstructWithSpread( 743 uint32_t arity, CallFrequency frequency = CallFrequency(), 744 VectorSlotPair const& feedback = VectorSlotPair()); 745 746 const Operator* LoadProperty(VectorSlotPair const& feedback); 747 const Operator* LoadNamed(Handle<Name> name, VectorSlotPair const& feedback); 748 749 const Operator* StoreProperty(LanguageMode language_mode, 750 VectorSlotPair const& feedback); 751 const Operator* StoreNamed(LanguageMode language_mode, Handle<Name> name, 752 VectorSlotPair const& feedback); 753 754 const Operator* StoreNamedOwn(Handle<Name> name, 755 VectorSlotPair const& feedback); 756 const Operator* StoreDataPropertyInLiteral(const VectorSlotPair& feedback); 757 const Operator* StoreInArrayLiteral(const VectorSlotPair& feedback); 758 759 const Operator* DeleteProperty(); 760 761 const Operator* HasProperty(); 762 763 const Operator* GetSuperConstructor(); 764 765 const Operator* CreateGeneratorObject(); 766 767 const Operator* LoadGlobal(const Handle<Name>& name, 768 const VectorSlotPair& feedback, 769 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF); 770 const Operator* StoreGlobal(LanguageMode language_mode, 771 const Handle<Name>& name, 772 const VectorSlotPair& feedback); 773 774 const Operator* LoadContext(size_t depth, size_t index, bool immutable); 775 const Operator* StoreContext(size_t depth, size_t index); 776 777 const Operator* LoadModule(int32_t cell_index); 778 const Operator* StoreModule(int32_t cell_index); 779 780 const Operator* HasInPrototypeChain(); 781 const Operator* InstanceOf(const VectorSlotPair& feedback); 782 const Operator* OrdinaryHasInstance(); 783 784 const Operator* ForInEnumerate(); 785 const Operator* ForInNext(ForInMode); 786 const Operator* ForInPrepare(ForInMode); 787 788 const Operator* LoadMessage(); 789 const Operator* StoreMessage(); 790 791 // Used to implement Ignition's SuspendGenerator bytecode. 792 const Operator* GeneratorStore(int register_count); 793 794 // Used to implement Ignition's SwitchOnGeneratorState bytecode. 795 const Operator* GeneratorRestoreContinuation(); 796 const Operator* GeneratorRestoreContext(); 797 798 // Used to implement Ignition's ResumeGenerator bytecode. 799 const Operator* GeneratorRestoreRegister(int index); 800 const Operator* GeneratorRestoreInputOrDebugPos(); 801 802 const Operator* StackCheck(); 803 const Operator* Debugger(); 804 805 const Operator* FulfillPromise(); 806 const Operator* PerformPromiseThen(); 807 const Operator* PromiseResolve(); 808 const Operator* RejectPromise(); 809 const Operator* ResolvePromise(); 810 811 const Operator* CreateFunctionContext(Handle<ScopeInfo> scope_info, 812 int slot_count, ScopeType scope_type); 813 const Operator* CreateCatchContext(const Handle<ScopeInfo>& scope_info); 814 const Operator* CreateWithContext(const Handle<ScopeInfo>& scope_info); 815 const Operator* CreateBlockContext(const Handle<ScopeInfo>& scpope_info); 816 817 const Operator* ObjectIsArray(); 818 const Operator* ParseInt(); 819 820 private: 821 Zone* zone() const { return zone_; } 822 823 const JSOperatorGlobalCache& cache_; 824 Zone* const zone_; 825 826 DISALLOW_COPY_AND_ASSIGN(JSOperatorBuilder); 827 }; 828 829 } // namespace compiler 830 } // namespace internal 831 } // namespace v8 832 833 #endif // V8_COMPILER_JS_OPERATOR_H_ 834