OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_NODE_MATCHERS_H_ | 5 #ifndef V8_COMPILER_NODE_MATCHERS_H_ |
6 #define V8_COMPILER_NODE_MATCHERS_H_ | 6 #define V8_COMPILER_NODE_MATCHERS_H_ |
7 | 7 |
8 #include "src/compiler/common-operator.h" | 8 #include "src/compiler/common-operator.h" |
9 #include "src/compiler/node.h" | 9 #include "src/compiler/node.h" |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 T value_; | 63 T value_; |
64 bool has_value_; | 64 bool has_value_; |
65 }; | 65 }; |
66 | 66 |
67 | 67 |
68 // A pattern matcher for integer constants. | 68 // A pattern matcher for integer constants. |
69 template <typename T> | 69 template <typename T> |
70 struct IntMatcher V8_FINAL : public ValueMatcher<T> { | 70 struct IntMatcher FINAL : public ValueMatcher<T> { |
71 explicit IntMatcher(Node* node) : ValueMatcher<T>(node) {} | 71 explicit IntMatcher(Node* node) : ValueMatcher<T>(node) {} |
72 | 72 |
73 bool IsPowerOf2() const { | 73 bool IsPowerOf2() const { |
74 return this->HasValue() && this->Value() > 0 && | 74 return this->HasValue() && this->Value() > 0 && |
75 (this->Value() & (this->Value() - 1)) == 0; | 75 (this->Value() & (this->Value() - 1)) == 0; |
76 } | 76 } |
77 }; | 77 }; |
78 | 78 |
79 typedef IntMatcher<int32_t> Int32Matcher; | 79 typedef IntMatcher<int32_t> Int32Matcher; |
80 typedef IntMatcher<uint32_t> Uint32Matcher; | 80 typedef IntMatcher<uint32_t> Uint32Matcher; |
81 typedef IntMatcher<int64_t> Int64Matcher; | 81 typedef IntMatcher<int64_t> Int64Matcher; |
82 typedef IntMatcher<uint64_t> Uint64Matcher; | 82 typedef IntMatcher<uint64_t> Uint64Matcher; |
83 | 83 |
84 | 84 |
85 // A pattern matcher for floating point constants. | 85 // A pattern matcher for floating point constants. |
86 template <typename T> | 86 template <typename T> |
87 struct FloatMatcher V8_FINAL : public ValueMatcher<T> { | 87 struct FloatMatcher FINAL : public ValueMatcher<T> { |
88 explicit FloatMatcher(Node* node) : ValueMatcher<T>(node) {} | 88 explicit FloatMatcher(Node* node) : ValueMatcher<T>(node) {} |
89 | 89 |
90 bool IsNaN() const { return this->HasValue() && std::isnan(this->Value()); } | 90 bool IsNaN() const { return this->HasValue() && std::isnan(this->Value()); } |
91 }; | 91 }; |
92 | 92 |
93 typedef FloatMatcher<double> Float64Matcher; | 93 typedef FloatMatcher<double> Float64Matcher; |
94 | 94 |
95 | 95 |
96 // A pattern matcher for heap object constants. | 96 // A pattern matcher for heap object constants. |
97 struct HeapObjectMatcher V8_FINAL | 97 struct HeapObjectMatcher FINAL |
98 : public ValueMatcher<PrintableUnique<HeapObject> > { | 98 : public ValueMatcher<PrintableUnique<HeapObject> > { |
99 explicit HeapObjectMatcher(Node* node) | 99 explicit HeapObjectMatcher(Node* node) |
100 : ValueMatcher<PrintableUnique<HeapObject> >(node) {} | 100 : ValueMatcher<PrintableUnique<HeapObject> >(node) {} |
101 | 101 |
102 bool IsKnownGlobal(HeapObject* global) const { | 102 bool IsKnownGlobal(HeapObject* global) const { |
103 return HasValue() && Value().IsKnownGlobal(global); | 103 return HasValue() && Value().IsKnownGlobal(global); |
104 } | 104 } |
105 }; | 105 }; |
106 | 106 |
107 | 107 |
108 // For shorter pattern matching code, this struct matches both the left and | 108 // For shorter pattern matching code, this struct matches both the left and |
109 // right hand sides of a binary operation and can put constants on the right | 109 // right hand sides of a binary operation and can put constants on the right |
110 // if they appear on the left hand side of a commutative operation. | 110 // if they appear on the left hand side of a commutative operation. |
111 template <typename Left, typename Right> | 111 template <typename Left, typename Right> |
112 struct BinopMatcher V8_FINAL : public NodeMatcher { | 112 struct BinopMatcher FINAL : public NodeMatcher { |
113 explicit BinopMatcher(Node* node) | 113 explicit BinopMatcher(Node* node) |
114 : NodeMatcher(node), left_(InputAt(0)), right_(InputAt(1)) { | 114 : NodeMatcher(node), left_(InputAt(0)), right_(InputAt(1)) { |
115 if (HasProperty(Operator::kCommutative)) PutConstantOnRight(); | 115 if (HasProperty(Operator::kCommutative)) PutConstantOnRight(); |
116 } | 116 } |
117 | 117 |
118 const Left& left() const { return left_; } | 118 const Left& left() const { return left_; } |
119 const Right& right() const { return right_; } | 119 const Right& right() const { return right_; } |
120 | 120 |
121 bool IsFoldable() const { return left().HasValue() && right().HasValue(); } | 121 bool IsFoldable() const { return left().HasValue() && right().HasValue(); } |
122 bool LeftEqualsRight() const { return left().node() == right().node(); } | 122 bool LeftEqualsRight() const { return left().node() == right().node(); } |
(...skipping 14 matching lines...) Expand all Loading... |
137 typedef BinopMatcher<Int32Matcher, Int32Matcher> Int32BinopMatcher; | 137 typedef BinopMatcher<Int32Matcher, Int32Matcher> Int32BinopMatcher; |
138 typedef BinopMatcher<Uint32Matcher, Uint32Matcher> Uint32BinopMatcher; | 138 typedef BinopMatcher<Uint32Matcher, Uint32Matcher> Uint32BinopMatcher; |
139 typedef BinopMatcher<Int64Matcher, Int64Matcher> Int64BinopMatcher; | 139 typedef BinopMatcher<Int64Matcher, Int64Matcher> Int64BinopMatcher; |
140 typedef BinopMatcher<Uint64Matcher, Uint64Matcher> Uint64BinopMatcher; | 140 typedef BinopMatcher<Uint64Matcher, Uint64Matcher> Uint64BinopMatcher; |
141 typedef BinopMatcher<Float64Matcher, Float64Matcher> Float64BinopMatcher; | 141 typedef BinopMatcher<Float64Matcher, Float64Matcher> Float64BinopMatcher; |
142 } | 142 } |
143 } | 143 } |
144 } // namespace v8::internal::compiler | 144 } // namespace v8::internal::compiler |
145 | 145 |
146 #endif // V8_COMPILER_NODE_MATCHERS_H_ | 146 #endif // V8_COMPILER_NODE_MATCHERS_H_ |
OLD | NEW |