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::kNumber: | 19 case BinaryOperationHints::kNumberOrUndefined: |
20 return os << "Number"; | 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 | 30 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 ToBooleanHint const hint = static_cast<ToBooleanHint>(1u << i); | 71 ToBooleanHint const hint = static_cast<ToBooleanHint>(1u << i); |
72 if (hints & hint) { | 72 if (hints & hint) { |
73 if (!first) os << "|"; | 73 if (!first) os << "|"; |
74 first = false; | 74 first = false; |
75 os << hint; | 75 os << hint; |
76 } | 76 } |
77 } | 77 } |
78 return os; | 78 return os; |
79 } | 79 } |
80 | 80 |
| 81 // static |
| 82 bool BinaryOperationHints::Is(Hint h1, Hint h2) { |
| 83 if (h1 == h2) return true; |
| 84 switch (h1) { |
| 85 case kNone: |
| 86 return true; |
| 87 case kSignedSmall: |
| 88 return h2 == kSigned32 || h2 == kNumberOrUndefined || h2 == kAny; |
| 89 case kSigned32: |
| 90 return h2 == kNumberOrUndefined || h2 == kAny; |
| 91 case kNumberOrUndefined: |
| 92 return h2 == kAny; |
| 93 case kString: |
| 94 return h2 == kAny; |
| 95 case kAny: |
| 96 return false; |
| 97 } |
| 98 UNREACHABLE(); |
| 99 return false; |
| 100 } |
| 101 |
| 102 // static |
| 103 BinaryOperationHints::Hint BinaryOperationHints::Combine(Hint h1, Hint h2) { |
| 104 if (Is(h1, h2)) return h2; |
| 105 if (Is(h2, h1)) return h1; |
| 106 return kAny; |
| 107 } |
| 108 |
81 } // namespace compiler | 109 } // namespace compiler |
82 } // namespace internal | 110 } // namespace internal |
83 } // namespace v8 | 111 } // namespace v8 |
OLD | NEW |