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 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 typedef BitField<Hint, 0, 3> LeftField; | 57 typedef BitField<Hint, 0, 3> LeftField; |
58 typedef BitField<Hint, 3, 3> RightField; | 58 typedef BitField<Hint, 3, 3> RightField; |
59 typedef BitField<Hint, 6, 3> ResultField; | 59 typedef BitField<Hint, 6, 3> ResultField; |
60 | 60 |
61 uint32_t bit_field_; | 61 uint32_t bit_field_; |
62 }; | 62 }; |
63 | 63 |
64 std::ostream& operator<<(std::ostream&, BinaryOperationHints::Hint); | 64 std::ostream& operator<<(std::ostream&, BinaryOperationHints::Hint); |
65 std::ostream& operator<<(std::ostream&, BinaryOperationHints); | 65 std::ostream& operator<<(std::ostream&, BinaryOperationHints); |
66 | 66 |
| 67 // Type hints for an binary operation. |
| 68 class CompareOperationHints final { |
| 69 public: |
| 70 enum Hint { |
| 71 kNone, |
| 72 kBoolean, |
| 73 kSignedSmall, |
| 74 kNumber, |
| 75 kString, |
| 76 kInternalizedString, |
| 77 kUniqueName, |
| 78 kReceiver, |
| 79 kAny |
| 80 }; |
| 81 |
| 82 CompareOperationHints() : CompareOperationHints(kNone, kNone, kNone) {} |
| 83 CompareOperationHints(Hint left, Hint right, Hint combined) |
| 84 : bit_field_(LeftField::encode(left) | RightField::encode(right) | |
| 85 CombinedField::encode(combined)) {} |
| 86 |
| 87 static CompareOperationHints Any() { |
| 88 return CompareOperationHints(kAny, kAny, kAny); |
| 89 } |
| 90 |
| 91 Hint left() const { return LeftField::decode(bit_field_); } |
| 92 Hint right() const { return RightField::decode(bit_field_); } |
| 93 Hint combined() const { return CombinedField::decode(bit_field_); } |
| 94 |
| 95 bool operator==(CompareOperationHints const& that) const { |
| 96 return this->bit_field_ == that.bit_field_; |
| 97 } |
| 98 bool operator!=(CompareOperationHints const& that) const { |
| 99 return !(*this == that); |
| 100 } |
| 101 |
| 102 friend size_t hash_value(CompareOperationHints const& hints) { |
| 103 return hints.bit_field_; |
| 104 } |
| 105 |
| 106 private: |
| 107 typedef BitField<Hint, 0, 4> LeftField; |
| 108 typedef BitField<Hint, 4, 4> RightField; |
| 109 typedef BitField<Hint, 8, 4> CombinedField; |
| 110 |
| 111 uint32_t bit_field_; |
| 112 }; |
| 113 |
| 114 std::ostream& operator<<(std::ostream&, CompareOperationHints::Hint); |
| 115 std::ostream& operator<<(std::ostream&, CompareOperationHints); |
67 | 116 |
68 // Type hints for the ToBoolean type conversion. | 117 // Type hints for the ToBoolean type conversion. |
69 enum class ToBooleanHint : uint16_t { | 118 enum class ToBooleanHint : uint16_t { |
70 kNone = 0u, | 119 kNone = 0u, |
71 kUndefined = 1u << 0, | 120 kUndefined = 1u << 0, |
72 kBoolean = 1u << 1, | 121 kBoolean = 1u << 1, |
73 kNull = 1u << 2, | 122 kNull = 1u << 2, |
74 kSmallInteger = 1u << 3, | 123 kSmallInteger = 1u << 3, |
75 kReceiver = 1u << 4, | 124 kReceiver = 1u << 4, |
76 kString = 1u << 5, | 125 kString = 1u << 5, |
(...skipping 10 matching lines...) Expand all Loading... |
87 | 136 |
88 std::ostream& operator<<(std::ostream&, ToBooleanHints); | 137 std::ostream& operator<<(std::ostream&, ToBooleanHints); |
89 | 138 |
90 DEFINE_OPERATORS_FOR_FLAGS(ToBooleanHints) | 139 DEFINE_OPERATORS_FOR_FLAGS(ToBooleanHints) |
91 | 140 |
92 } // namespace compiler | 141 } // namespace compiler |
93 } // namespace internal | 142 } // namespace internal |
94 } // namespace v8 | 143 } // namespace v8 |
95 | 144 |
96 #endif // V8_COMPILER_TYPE_HINTS_H_ | 145 #endif // V8_COMPILER_TYPE_HINTS_H_ |
OLD | NEW |