Chromium Code Reviews| 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 #include "src/compiler/type-hints.h" | 5 #include "src/compiler/type-hints.h" |
| 6 | 6 |
| 7 namespace v8 { | 7 namespace v8 { |
| 8 namespace internal { | 8 namespace internal { |
| 9 namespace compiler { | 9 namespace compiler { |
| 10 | 10 |
| 11 std::ostream& operator<<(std::ostream& os, BinaryOperationHints::Hint hint) { | 11 std::ostream& operator<<(std::ostream& os, BinaryOperationHints::Hint hint) { |
| 12 switch (hint) { | 12 switch (hint) { |
| 13 case BinaryOperationHints::kNone: | 13 case BinaryOperationHints::kNone: |
| 14 return os << "None"; | 14 return os << "None"; |
| 15 case BinaryOperationHints::kSignedSmall: | 15 case BinaryOperationHints::kSignedSmall: |
| 16 return os << "SignedSmall"; | 16 return os << "SignedSmall"; |
| 17 case BinaryOperationHints::kSigned32: | 17 case BinaryOperationHints::kSigned32: |
| 18 return os << "Signed32"; | 18 return os << "Signed32"; |
| 19 case BinaryOperationHints::kNumberOrUndefined: | 19 case BinaryOperationHints::kNumberOrUndefined: |
| 20 return os << "NumberOrUndefined"; | 20 return os << "NumberOrUndefined"; |
| 21 case BinaryOperationHints::kString: | 21 case BinaryOperationHints::kString: |
| 22 return os << "String"; | 22 return os << "String"; |
| 23 case BinaryOperationHints::kAny: | 23 case BinaryOperationHints::kAny: |
| 24 return os << "Any"; | 24 return os << "Any"; |
| 25 } | 25 } |
| 26 UNREACHABLE(); | 26 UNREACHABLE(); |
| 27 return os; | 27 return os; |
| 28 } | 28 } |
| 29 | 29 |
| 30 | |
| 31 std::ostream& operator<<(std::ostream& os, BinaryOperationHints hints) { | 30 std::ostream& operator<<(std::ostream& os, BinaryOperationHints hints) { |
| 32 return os << hints.left() << "*" << hints.right() << "->" << hints.result(); | 31 return os << hints.left() << "*" << hints.right() << "->" << hints.result(); |
| 33 } | 32 } |
| 34 | 33 |
| 34 std::ostream& operator<<(std::ostream& os, CompareOperationHints::Hint hint) { | |
| 35 switch (hint) { | |
| 36 case CompareOperationHints::kNone: | |
| 37 return os << "None"; | |
| 38 case CompareOperationHints::kSignedSmall: | |
| 39 return os << "SignedSmall"; | |
| 40 case CompareOperationHints::kSigned32: | |
| 41 return os << "Signed32"; | |
| 42 case CompareOperationHints::kNumberOrUndefined: | |
| 43 return os << "NumberOrUndefined"; | |
| 44 case CompareOperationHints::kString: | |
| 45 return os << "String"; | |
| 46 case CompareOperationHints::kAny: | |
| 47 return os << "Any"; | |
| 48 } | |
| 49 UNREACHABLE(); | |
| 50 return os; | |
| 51 } | |
| 52 | |
| 53 std::ostream& operator<<(std::ostream& os, CompareOperationHints hints) { | |
| 54 return os << hints.left() << "*" << hints.right() << " (" << hints.combined() | |
| 55 << ")"; | |
| 56 } | |
| 35 | 57 |
| 36 std::ostream& operator<<(std::ostream& os, ToBooleanHint hint) { | 58 std::ostream& operator<<(std::ostream& os, ToBooleanHint hint) { |
| 37 switch (hint) { | 59 switch (hint) { |
| 38 case ToBooleanHint::kNone: | 60 case ToBooleanHint::kNone: |
| 39 return os << "None"; | 61 return os << "None"; |
| 40 case ToBooleanHint::kUndefined: | 62 case ToBooleanHint::kUndefined: |
| 41 return os << "Undefined"; | 63 return os << "Undefined"; |
| 42 case ToBooleanHint::kBoolean: | 64 case ToBooleanHint::kBoolean: |
| 43 return os << "Boolean"; | 65 return os << "Boolean"; |
| 44 case ToBooleanHint::kNull: | 66 case ToBooleanHint::kNull: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 55 return os << "HeapNumber"; | 77 return os << "HeapNumber"; |
| 56 case ToBooleanHint::kSimdValue: | 78 case ToBooleanHint::kSimdValue: |
| 57 return os << "SimdValue"; | 79 return os << "SimdValue"; |
| 58 case ToBooleanHint::kAny: | 80 case ToBooleanHint::kAny: |
| 59 return os << "Any"; | 81 return os << "Any"; |
| 60 } | 82 } |
| 61 UNREACHABLE(); | 83 UNREACHABLE(); |
| 62 return os; | 84 return os; |
| 63 } | 85 } |
| 64 | 86 |
| 65 | |
| 66 std::ostream& operator<<(std::ostream& os, ToBooleanHints hints) { | 87 std::ostream& operator<<(std::ostream& os, ToBooleanHints hints) { |
| 67 if (hints == ToBooleanHint::kAny) return os << "Any"; | 88 if (hints == ToBooleanHint::kAny) return os << "Any"; |
| 68 if (hints == ToBooleanHint::kNone) return os << "None"; | 89 if (hints == ToBooleanHint::kNone) return os << "None"; |
| 69 bool first = true; | 90 bool first = true; |
| 70 for (ToBooleanHints::mask_type i = 0; i < sizeof(i) * CHAR_BIT; ++i) { | 91 for (ToBooleanHints::mask_type i = 0; i < sizeof(i) * CHAR_BIT; ++i) { |
| 71 ToBooleanHint const hint = static_cast<ToBooleanHint>(1u << i); | 92 ToBooleanHint const hint = static_cast<ToBooleanHint>(1u << i); |
| 72 if (hints & hint) { | 93 if (hints & hint) { |
| 73 if (!first) os << "|"; | 94 if (!first) os << "|"; |
| 74 first = false; | 95 first = false; |
| 75 os << hint; | 96 os << hint; |
| 76 } | 97 } |
| 77 } | 98 } |
| 78 return os; | 99 return os; |
| 79 } | 100 } |
| 80 | 101 |
| 81 // static | 102 // static |
| 82 bool BinaryOperationHints::Is(Hint h1, Hint h2) { | 103 bool BinaryOperationHints::Is(Hint h1, Hint h2) { |
| 83 if (h1 == h2) return true; | 104 if (h1 == h2) return true; |
| 84 switch (h1) { | 105 switch (h1) { |
| 85 case kNone: | 106 case BinaryOperationHints::kNone: |
|
Benedikt Meurer
2016/06/07 04:11:00
This change doesn't seem necessary?
Jarin
2016/06/09 13:37:32
Done.
| |
| 86 return true; | 107 return true; |
| 87 case kSignedSmall: | 108 case BinaryOperationHints::kSignedSmall: |
| 88 return h2 == kSigned32 || h2 == kNumberOrUndefined || h2 == kAny; | 109 return h2 == BinaryOperationHints::kSigned32 || |
| 89 case kSigned32: | 110 h2 == BinaryOperationHints::kNumberOrUndefined || |
| 90 return h2 == kNumberOrUndefined || h2 == kAny; | 111 h2 == BinaryOperationHints::kAny; |
| 91 case kNumberOrUndefined: | 112 case BinaryOperationHints::kSigned32: |
| 92 return h2 == kAny; | 113 return h2 == BinaryOperationHints::kNumberOrUndefined || |
| 93 case kString: | 114 h2 == BinaryOperationHints::kAny; |
| 94 return h2 == kAny; | 115 case BinaryOperationHints::kNumberOrUndefined: |
| 95 case kAny: | 116 return h2 == BinaryOperationHints::kAny; |
| 117 case BinaryOperationHints::kString: | |
| 118 return h2 == BinaryOperationHints::kAny; | |
| 119 case BinaryOperationHints::kAny: | |
| 96 return false; | 120 return false; |
| 97 } | 121 } |
| 98 UNREACHABLE(); | 122 UNREACHABLE(); |
| 99 return false; | 123 return false; |
| 100 } | 124 } |
| 101 | 125 |
| 102 // static | 126 // static |
| 103 BinaryOperationHints::Hint BinaryOperationHints::Combine(Hint h1, Hint h2) { | 127 BinaryOperationHints::Hint BinaryOperationHints::Combine(Hint h1, Hint h2) { |
| 104 if (Is(h1, h2)) return h2; | 128 if (Is(h1, h2)) return h2; |
| 105 if (Is(h2, h1)) return h1; | 129 if (Is(h2, h1)) return h1; |
| 106 return kAny; | 130 return BinaryOperationHints::kAny; |
|
Benedikt Meurer
2016/06/07 04:11:00
This change doesn't seem necessary?
Jarin
2016/06/09 13:37:32
Done.
| |
| 107 } | 131 } |
| 108 | 132 |
| 109 } // namespace compiler | 133 } // namespace compiler |
| 110 } // namespace internal | 134 } // namespace internal |
| 111 } // namespace v8 | 135 } // namespace v8 |
| OLD | NEW |