| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_COMPILER_JS_OPERATOR_H_ | 5 #ifndef V8_COMPILER_JS_OPERATOR_H_ |
| 6 #define V8_COMPILER_JS_OPERATOR_H_ | 6 #define V8_COMPILER_JS_OPERATOR_H_ |
| 7 | 7 |
| 8 #include "src/base/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
| 9 #include "src/globals.h" | 9 #include "src/globals.h" |
| 10 #include "src/handles.h" | 10 #include "src/handles.h" |
| 11 #include "src/runtime/runtime.h" | 11 #include "src/runtime/runtime.h" |
| 12 #include "src/type-hints.h" | 12 #include "src/type-hints.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 class AllocationSite; | 17 class AllocationSite; |
| 18 class BoilerplateDescription; | 18 class BoilerplateDescription; |
| 19 class ConstantElementsPair; | 19 class ConstantElementsPair; |
| 20 class SharedFunctionInfo; | 20 class SharedFunctionInfo; |
| 21 class FeedbackVector; | 21 class FeedbackVector; |
| 22 | 22 |
| 23 namespace compiler { | 23 namespace compiler { |
| 24 | 24 |
| 25 // Forward declarations. | 25 // Forward declarations. |
| 26 class Operator; | 26 class Operator; |
| 27 struct JSOperatorGlobalCache; | 27 struct JSOperatorGlobalCache; |
| 28 | 28 |
| 29 // Defines the frequency a given Call/Construct site was executed. For some |
| 30 // call sites the frequency is not known. |
| 31 class CallFrequency final { |
| 32 public: |
| 33 CallFrequency() : value_(std::numeric_limits<float>::quiet_NaN()) {} |
| 34 explicit CallFrequency(float value) : value_(value) { |
| 35 DCHECK(!std::isnan(value)); |
| 36 } |
| 37 |
| 38 bool IsKnown() const { return !IsUnknown(); } |
| 39 bool IsUnknown() const { return std::isnan(value_); } |
| 40 float value() const { |
| 41 DCHECK(IsKnown()); |
| 42 return value_; |
| 43 } |
| 44 |
| 45 bool operator==(CallFrequency const& that) const { |
| 46 return bit_cast<uint32_t>(this->value_) == bit_cast<uint32_t>(that.value_); |
| 47 } |
| 48 bool operator!=(CallFrequency const& that) const { return !(*this == that); } |
| 49 |
| 50 friend size_t hash_value(CallFrequency f) { |
| 51 return bit_cast<uint32_t>(f.value_); |
| 52 } |
| 53 |
| 54 private: |
| 55 float value_; |
| 56 }; |
| 57 |
| 58 std::ostream& operator<<(std::ostream&, CallFrequency); |
| 59 |
| 29 // Defines a pair of {FeedbackVector} and {FeedbackSlot}, which | 60 // Defines a pair of {FeedbackVector} and {FeedbackSlot}, which |
| 30 // is used to access the type feedback for a certain {Node}. | 61 // is used to access the type feedback for a certain {Node}. |
| 31 class V8_EXPORT_PRIVATE VectorSlotPair { | 62 class V8_EXPORT_PRIVATE VectorSlotPair { |
| 32 public: | 63 public: |
| 33 VectorSlotPair(); | 64 VectorSlotPair(); |
| 34 VectorSlotPair(Handle<FeedbackVector> vector, FeedbackSlot slot) | 65 VectorSlotPair(Handle<FeedbackVector> vector, FeedbackSlot slot) |
| 35 : vector_(vector), slot_(slot) {} | 66 : vector_(vector), slot_(slot) {} |
| 36 | 67 |
| 37 bool IsValid() const { return !vector_.is_null() && !slot_.IsInvalid(); } | 68 bool IsValid() const { return !vector_.is_null() && !slot_.IsInvalid(); } |
| 38 | 69 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 57 | 88 |
| 58 | 89 |
| 59 // The ToBooleanHints are used as parameter by JSToBoolean operators. | 90 // The ToBooleanHints are used as parameter by JSToBoolean operators. |
| 60 ToBooleanHints ToBooleanHintsOf(Operator const* op); | 91 ToBooleanHints ToBooleanHintsOf(Operator const* op); |
| 61 | 92 |
| 62 | 93 |
| 63 // Defines the arity and the feedback for a JavaScript constructor call. This is | 94 // Defines the arity and the feedback for a JavaScript constructor call. This is |
| 64 // used as a parameter by JSConstruct operators. | 95 // used as a parameter by JSConstruct operators. |
| 65 class ConstructParameters final { | 96 class ConstructParameters final { |
| 66 public: | 97 public: |
| 67 ConstructParameters(uint32_t arity, float frequency, | 98 ConstructParameters(uint32_t arity, CallFrequency frequency, |
| 68 VectorSlotPair const& feedback) | 99 VectorSlotPair const& feedback) |
| 69 : arity_(arity), frequency_(frequency), feedback_(feedback) {} | 100 : arity_(arity), frequency_(frequency), feedback_(feedback) {} |
| 70 | 101 |
| 71 uint32_t arity() const { return arity_; } | 102 uint32_t arity() const { return arity_; } |
| 72 float frequency() const { return frequency_; } | 103 CallFrequency frequency() const { return frequency_; } |
| 73 VectorSlotPair const& feedback() const { return feedback_; } | 104 VectorSlotPair const& feedback() const { return feedback_; } |
| 74 | 105 |
| 75 private: | 106 private: |
| 76 uint32_t const arity_; | 107 uint32_t const arity_; |
| 77 float const frequency_; | 108 CallFrequency const frequency_; |
| 78 VectorSlotPair const feedback_; | 109 VectorSlotPair const feedback_; |
| 79 }; | 110 }; |
| 80 | 111 |
| 81 bool operator==(ConstructParameters const&, ConstructParameters const&); | 112 bool operator==(ConstructParameters const&, ConstructParameters const&); |
| 82 bool operator!=(ConstructParameters const&, ConstructParameters const&); | 113 bool operator!=(ConstructParameters const&, ConstructParameters const&); |
| 83 | 114 |
| 84 size_t hash_value(ConstructParameters const&); | 115 size_t hash_value(ConstructParameters const&); |
| 85 | 116 |
| 86 std::ostream& operator<<(std::ostream&, ConstructParameters const&); | 117 std::ostream& operator<<(std::ostream&, ConstructParameters const&); |
| 87 | 118 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 176 |
| 146 std::ostream& operator<<(std::ostream&, CallForwardVarargsParameters const&); | 177 std::ostream& operator<<(std::ostream&, CallForwardVarargsParameters const&); |
| 147 | 178 |
| 148 CallForwardVarargsParameters const& CallForwardVarargsParametersOf( | 179 CallForwardVarargsParameters const& CallForwardVarargsParametersOf( |
| 149 Operator const*) WARN_UNUSED_RESULT; | 180 Operator const*) WARN_UNUSED_RESULT; |
| 150 | 181 |
| 151 // Defines the arity and the call flags for a JavaScript function call. This is | 182 // Defines the arity and the call flags for a JavaScript function call. This is |
| 152 // used as a parameter by JSCall operators. | 183 // used as a parameter by JSCall operators. |
| 153 class CallParameters final { | 184 class CallParameters final { |
| 154 public: | 185 public: |
| 155 CallParameters(size_t arity, float frequency, VectorSlotPair const& feedback, | 186 CallParameters(size_t arity, CallFrequency frequency, |
| 156 TailCallMode tail_call_mode, ConvertReceiverMode convert_mode) | 187 VectorSlotPair const& feedback, TailCallMode tail_call_mode, |
| 188 ConvertReceiverMode convert_mode) |
| 157 : bit_field_(ArityField::encode(arity) | | 189 : bit_field_(ArityField::encode(arity) | |
| 158 ConvertReceiverModeField::encode(convert_mode) | | 190 ConvertReceiverModeField::encode(convert_mode) | |
| 159 TailCallModeField::encode(tail_call_mode)), | 191 TailCallModeField::encode(tail_call_mode)), |
| 160 frequency_(frequency), | 192 frequency_(frequency), |
| 161 feedback_(feedback) {} | 193 feedback_(feedback) {} |
| 162 | 194 |
| 163 size_t arity() const { return ArityField::decode(bit_field_); } | 195 size_t arity() const { return ArityField::decode(bit_field_); } |
| 164 float frequency() const { return frequency_; } | 196 CallFrequency frequency() const { return frequency_; } |
| 165 ConvertReceiverMode convert_mode() const { | 197 ConvertReceiverMode convert_mode() const { |
| 166 return ConvertReceiverModeField::decode(bit_field_); | 198 return ConvertReceiverModeField::decode(bit_field_); |
| 167 } | 199 } |
| 168 TailCallMode tail_call_mode() const { | 200 TailCallMode tail_call_mode() const { |
| 169 return TailCallModeField::decode(bit_field_); | 201 return TailCallModeField::decode(bit_field_); |
| 170 } | 202 } |
| 171 VectorSlotPair const& feedback() const { return feedback_; } | 203 VectorSlotPair const& feedback() const { return feedback_; } |
| 172 | 204 |
| 173 bool operator==(CallParameters const& that) const { | 205 bool operator==(CallParameters const& that) const { |
| 174 return this->bit_field_ == that.bit_field_ && | 206 return this->bit_field_ == that.bit_field_ && |
| 175 this->frequency_ == that.frequency_ && | 207 this->frequency_ == that.frequency_ && |
| 176 this->feedback_ == that.feedback_; | 208 this->feedback_ == that.feedback_; |
| 177 } | 209 } |
| 178 bool operator!=(CallParameters const& that) const { return !(*this == that); } | 210 bool operator!=(CallParameters const& that) const { return !(*this == that); } |
| 179 | 211 |
| 180 private: | 212 private: |
| 181 friend size_t hash_value(CallParameters const& p) { | 213 friend size_t hash_value(CallParameters const& p) { |
| 182 return base::hash_combine(p.bit_field_, p.frequency_, p.feedback_); | 214 return base::hash_combine(p.bit_field_, p.frequency_, p.feedback_); |
| 183 } | 215 } |
| 184 | 216 |
| 185 typedef BitField<size_t, 0, 29> ArityField; | 217 typedef BitField<size_t, 0, 29> ArityField; |
| 186 typedef BitField<ConvertReceiverMode, 29, 2> ConvertReceiverModeField; | 218 typedef BitField<ConvertReceiverMode, 29, 2> ConvertReceiverModeField; |
| 187 typedef BitField<TailCallMode, 31, 1> TailCallModeField; | 219 typedef BitField<TailCallMode, 31, 1> TailCallModeField; |
| 188 | 220 |
| 189 uint32_t const bit_field_; | 221 uint32_t const bit_field_; |
| 190 float const frequency_; | 222 CallFrequency const frequency_; |
| 191 VectorSlotPair const feedback_; | 223 VectorSlotPair const feedback_; |
| 192 }; | 224 }; |
| 193 | 225 |
| 194 size_t hash_value(CallParameters const&); | 226 size_t hash_value(CallParameters const&); |
| 195 | 227 |
| 196 std::ostream& operator<<(std::ostream&, CallParameters const&); | 228 std::ostream& operator<<(std::ostream&, CallParameters const&); |
| 197 | 229 |
| 198 const CallParameters& CallParametersOf(const Operator* op); | 230 const CallParameters& CallParametersOf(const Operator* op); |
| 199 | 231 |
| 200 | 232 |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 int number_of_elements); | 661 int number_of_elements); |
| 630 const Operator* CreateLiteralObject(Handle<BoilerplateDescription> constant, | 662 const Operator* CreateLiteralObject(Handle<BoilerplateDescription> constant, |
| 631 int literal_flags, int literal_index, | 663 int literal_flags, int literal_index, |
| 632 int number_of_properties); | 664 int number_of_properties); |
| 633 const Operator* CreateLiteralRegExp(Handle<String> constant_pattern, | 665 const Operator* CreateLiteralRegExp(Handle<String> constant_pattern, |
| 634 int literal_flags, int literal_index); | 666 int literal_flags, int literal_index); |
| 635 | 667 |
| 636 const Operator* CallForwardVarargs(uint32_t start_index, | 668 const Operator* CallForwardVarargs(uint32_t start_index, |
| 637 TailCallMode tail_call_mode); | 669 TailCallMode tail_call_mode); |
| 638 const Operator* Call( | 670 const Operator* Call( |
| 639 size_t arity, float frequency = 0.0f, | 671 size_t arity, CallFrequency frequency = CallFrequency(), |
| 640 VectorSlotPair const& feedback = VectorSlotPair(), | 672 VectorSlotPair const& feedback = VectorSlotPair(), |
| 641 ConvertReceiverMode convert_mode = ConvertReceiverMode::kAny, | 673 ConvertReceiverMode convert_mode = ConvertReceiverMode::kAny, |
| 642 TailCallMode tail_call_mode = TailCallMode::kDisallow); | 674 TailCallMode tail_call_mode = TailCallMode::kDisallow); |
| 643 const Operator* CallWithSpread(uint32_t arity); | 675 const Operator* CallWithSpread(uint32_t arity); |
| 644 const Operator* CallRuntime(Runtime::FunctionId id); | 676 const Operator* CallRuntime(Runtime::FunctionId id); |
| 645 const Operator* CallRuntime(Runtime::FunctionId id, size_t arity); | 677 const Operator* CallRuntime(Runtime::FunctionId id, size_t arity); |
| 646 const Operator* CallRuntime(const Runtime::Function* function, size_t arity); | 678 const Operator* CallRuntime(const Runtime::Function* function, size_t arity); |
| 647 const Operator* Construct(uint32_t arity, float frequency, | 679 const Operator* Construct(uint32_t arity, |
| 648 VectorSlotPair const& feedback); | 680 CallFrequency frequency = CallFrequency(), |
| 681 VectorSlotPair const& feedback = VectorSlotPair()); |
| 649 const Operator* ConstructWithSpread(uint32_t arity); | 682 const Operator* ConstructWithSpread(uint32_t arity); |
| 650 | 683 |
| 651 const Operator* ConvertReceiver(ConvertReceiverMode convert_mode); | 684 const Operator* ConvertReceiver(ConvertReceiverMode convert_mode); |
| 652 | 685 |
| 653 const Operator* LoadProperty(VectorSlotPair const& feedback); | 686 const Operator* LoadProperty(VectorSlotPair const& feedback); |
| 654 const Operator* LoadNamed(Handle<Name> name, VectorSlotPair const& feedback); | 687 const Operator* LoadNamed(Handle<Name> name, VectorSlotPair const& feedback); |
| 655 | 688 |
| 656 const Operator* StoreProperty(LanguageMode language_mode, | 689 const Operator* StoreProperty(LanguageMode language_mode, |
| 657 VectorSlotPair const& feedback); | 690 VectorSlotPair const& feedback); |
| 658 const Operator* StoreNamed(LanguageMode language_mode, Handle<Name> name, | 691 const Operator* StoreNamed(LanguageMode language_mode, Handle<Name> name, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 Zone* const zone_; | 751 Zone* const zone_; |
| 719 | 752 |
| 720 DISALLOW_COPY_AND_ASSIGN(JSOperatorBuilder); | 753 DISALLOW_COPY_AND_ASSIGN(JSOperatorBuilder); |
| 721 }; | 754 }; |
| 722 | 755 |
| 723 } // namespace compiler | 756 } // namespace compiler |
| 724 } // namespace internal | 757 } // namespace internal |
| 725 } // namespace v8 | 758 } // namespace v8 |
| 726 | 759 |
| 727 #endif // V8_COMPILER_JS_OPERATOR_H_ | 760 #endif // V8_COMPILER_JS_OPERATOR_H_ |
| OLD | NEW |