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 3 // found in the LICENSE file. 4 5 #ifndef V8_COMPILER_TYPE_HINTS_H_ 6 #define V8_COMPILER_TYPE_HINTS_H_ 7 8 #include "src/base/flags.h" 9 #include "src/utils.h" 10 11 namespace v8 { 12 namespace internal { 13 namespace compiler { 14 15 // Type hints for an binary operation. 16 class BinaryOperationHints final { 17 public: 18 enum Hint { kNone, kSignedSmall, kSigned32, kNumber, kString, kAny }; 19 20 BinaryOperationHints() : BinaryOperationHints(kNone, kNone, kNone) {} 21 BinaryOperationHints(Hint left, Hint right, Hint result) 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 33 bool operator==(BinaryOperationHints const& that) const { 34 return this->bit_field_ == that.bit_field_; 35 } 36 bool operator!=(BinaryOperationHints const& that) const { 37 return !(*this == that); 38 } 39 40 friend size_t hash_value(BinaryOperationHints const& hints) { 41 return hints.bit_field_; 42 } 43 44 private: 45 typedef BitField<Hint, 0, 3> LeftField; 46 typedef BitField<Hint, 3, 3> RightField; 47 typedef BitField<Hint, 6, 3> ResultField; 48 49 uint32_t bit_field_; 50 }; 51 52 std::ostream& operator<<(std::ostream&, BinaryOperationHints::Hint); 53 std::ostream& operator<<(std::ostream&, BinaryOperationHints); 54 55 56 // Type hints for the ToBoolean type conversion. 57 enum class ToBooleanHint : uint16_t { 58 kNone = 0u, 59 kUndefined = 1u << 0, 60 kBoolean = 1u << 1, 61 kNull = 1u << 2, 62 kSmallInteger = 1u << 3, 63 kReceiver = 1u << 4, 64 kString = 1u << 5, 65 kSymbol = 1u << 6, 66 kHeapNumber = 1u << 7, 67 kSimdValue = 1u << 8, 68 kAny = kUndefined | kBoolean | kNull | kSmallInteger | kReceiver | kString | 69 kSymbol | kHeapNumber | kSimdValue 70 }; 71 72 std::ostream& operator<<(std::ostream&, ToBooleanHint); 73 74 typedef base::Flags<ToBooleanHint, uint16_t> ToBooleanHints; 75 76 std::ostream& operator<<(std::ostream&, ToBooleanHints); 77 78 DEFINE_OPERATORS_FOR_FLAGS(ToBooleanHints) 79 80 } // namespace compiler 81 } // namespace internal 82 } // namespace v8 83 84 #endif // V8_COMPILER_TYPE_HINTS_H_ 85