| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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_TYPE_HINTS_H_ | 5 #ifndef V8_COMPILER_TYPE_HINTS_H_ |
| 6 #define V8_COMPILER_TYPE_HINTS_H_ | 6 #define V8_COMPILER_TYPE_HINTS_H_ |
| 7 | 7 |
| 8 #include "src/base/flags.h" | 8 #include "src/base/flags.h" |
| 9 #include "src/utils.h" | 9 #include "src/utils.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 namespace compiler { | 13 namespace compiler { |
| 14 | 14 |
| 15 // Type hints for an binary operation. | 15 // Type hints for an binary operation. |
| 16 class BinaryOperationHints final { | 16 enum class BinaryOperationHint : uint8_t { |
| 17 public: | 17 kNone, |
| 18 enum Hint { kNone, kSignedSmall, kSigned32, kNumberOrOddball, kString, kAny }; | 18 kSignedSmall, |
| 19 | 19 kSigned32, |
| 20 BinaryOperationHints() : BinaryOperationHints(kNone, kNone, kNone) {} | 20 kNumberOrOddball, |
| 21 BinaryOperationHints(Hint left, Hint right, Hint result) | 21 kAny |
| 22 : bit_field_(LeftField::encode(left) | RightField::encode(right) | | |
| 23 ResultField::encode(result)) {} | |
| 24 | |
| 25 static BinaryOperationHints Any() { | |
| 26 return BinaryOperationHints(kAny, kAny, kAny); | |
| 27 } | |
| 28 | |
| 29 Hint left() const { return LeftField::decode(bit_field_); } | |
| 30 Hint right() const { return RightField::decode(bit_field_); } | |
| 31 Hint result() const { return ResultField::decode(bit_field_); } | |
| 32 Hint combined() const { return Combine(Combine(left(), right()), result()); } | |
| 33 | |
| 34 // Hint 'subtyping' and generalization. | |
| 35 static bool Is(Hint h1, Hint h2); | |
| 36 static Hint Combine(Hint h1, Hint h2); | |
| 37 | |
| 38 bool operator==(BinaryOperationHints const& that) const { | |
| 39 return this->bit_field_ == that.bit_field_; | |
| 40 } | |
| 41 bool operator!=(BinaryOperationHints const& that) const { | |
| 42 return !(*this == that); | |
| 43 } | |
| 44 | |
| 45 friend size_t hash_value(BinaryOperationHints const& hints) { | |
| 46 return hints.bit_field_; | |
| 47 } | |
| 48 | |
| 49 private: | |
| 50 typedef BitField<Hint, 0, 3> LeftField; | |
| 51 typedef BitField<Hint, 3, 3> RightField; | |
| 52 typedef BitField<Hint, 6, 3> ResultField; | |
| 53 | |
| 54 uint32_t bit_field_; | |
| 55 }; | 22 }; |
| 56 | 23 |
| 57 std::ostream& operator<<(std::ostream&, BinaryOperationHints::Hint); | 24 inline size_t hash_value(BinaryOperationHint hint) { |
| 58 std::ostream& operator<<(std::ostream&, BinaryOperationHints); | 25 return static_cast<unsigned>(hint); |
| 26 } |
| 59 | 27 |
| 60 // Type hints for an binary operation. | 28 std::ostream& operator<<(std::ostream&, BinaryOperationHint); |
| 61 class CompareOperationHints final { | |
| 62 public: | |
| 63 enum Hint { | |
| 64 kNone, | |
| 65 kBoolean, | |
| 66 kSignedSmall, | |
| 67 kNumber, | |
| 68 kNumberOrOddball, | |
| 69 kString, | |
| 70 kInternalizedString, | |
| 71 kUniqueName, | |
| 72 kReceiver, | |
| 73 kAny | |
| 74 }; | |
| 75 | 29 |
| 76 CompareOperationHints() : CompareOperationHints(kNone, kNone, kNone) {} | 30 // Type hints for an compare operation. |
| 77 CompareOperationHints(Hint left, Hint right, Hint combined) | 31 enum class CompareOperationHint : uint8_t { |
| 78 : bit_field_(LeftField::encode(left) | RightField::encode(right) | | 32 kNone, |
| 79 CombinedField::encode(combined)) {} | 33 kSignedSmall, |
| 80 | 34 kNumber, |
| 81 static CompareOperationHints Any() { | 35 kNumberOrOddball, |
| 82 return CompareOperationHints(kAny, kAny, kAny); | 36 kAny |
| 83 } | |
| 84 | |
| 85 Hint left() const { return LeftField::decode(bit_field_); } | |
| 86 Hint right() const { return RightField::decode(bit_field_); } | |
| 87 Hint combined() const { return CombinedField::decode(bit_field_); } | |
| 88 | |
| 89 bool operator==(CompareOperationHints const& that) const { | |
| 90 return this->bit_field_ == that.bit_field_; | |
| 91 } | |
| 92 bool operator!=(CompareOperationHints const& that) const { | |
| 93 return !(*this == that); | |
| 94 } | |
| 95 | |
| 96 friend size_t hash_value(CompareOperationHints const& hints) { | |
| 97 return hints.bit_field_; | |
| 98 } | |
| 99 | |
| 100 private: | |
| 101 typedef BitField<Hint, 0, 4> LeftField; | |
| 102 typedef BitField<Hint, 4, 4> RightField; | |
| 103 typedef BitField<Hint, 8, 4> CombinedField; | |
| 104 | |
| 105 uint32_t bit_field_; | |
| 106 }; | 37 }; |
| 107 | 38 |
| 108 std::ostream& operator<<(std::ostream&, CompareOperationHints::Hint); | 39 inline size_t hash_value(CompareOperationHint hint) { |
| 109 std::ostream& operator<<(std::ostream&, CompareOperationHints); | 40 return static_cast<unsigned>(hint); |
| 41 } |
| 42 |
| 43 std::ostream& operator<<(std::ostream&, CompareOperationHint); |
| 110 | 44 |
| 111 // Type hints for the ToBoolean type conversion. | 45 // Type hints for the ToBoolean type conversion. |
| 112 enum class ToBooleanHint : uint16_t { | 46 enum class ToBooleanHint : uint16_t { |
| 113 kNone = 0u, | 47 kNone = 0u, |
| 114 kUndefined = 1u << 0, | 48 kUndefined = 1u << 0, |
| 115 kBoolean = 1u << 1, | 49 kBoolean = 1u << 1, |
| 116 kNull = 1u << 2, | 50 kNull = 1u << 2, |
| 117 kSmallInteger = 1u << 3, | 51 kSmallInteger = 1u << 3, |
| 118 kReceiver = 1u << 4, | 52 kReceiver = 1u << 4, |
| 119 kString = 1u << 5, | 53 kString = 1u << 5, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 130 | 64 |
| 131 std::ostream& operator<<(std::ostream&, ToBooleanHints); | 65 std::ostream& operator<<(std::ostream&, ToBooleanHints); |
| 132 | 66 |
| 133 DEFINE_OPERATORS_FOR_FLAGS(ToBooleanHints) | 67 DEFINE_OPERATORS_FOR_FLAGS(ToBooleanHints) |
| 134 | 68 |
| 135 } // namespace compiler | 69 } // namespace compiler |
| 136 } // namespace internal | 70 } // namespace internal |
| 137 } // namespace v8 | 71 } // namespace v8 |
| 138 | 72 |
| 139 #endif // V8_COMPILER_TYPE_HINTS_H_ | 73 #endif // V8_COMPILER_TYPE_HINTS_H_ |
| OLD | NEW |