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 <cmath> | 8 #include <cmath> |
9 | 9 |
10 // TODO(turbofan): Move ExternalReference out of assembler.h | 10 // TODO(turbofan): Move ExternalReference out of assembler.h |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 has_value_ = true; | 98 has_value_ = true; |
99 } else if (opcode() == IrOpcode::kInt64Constant) { | 99 } else if (opcode() == IrOpcode::kInt64Constant) { |
100 value_ = OpParameter<uint64_t>(node); | 100 value_ = OpParameter<uint64_t>(node); |
101 has_value_ = true; | 101 has_value_ = true; |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 // A pattern matcher for integer constants. | 106 // A pattern matcher for integer constants. |
107 template <typename T, IrOpcode::Value kOpcode> | 107 template <typename T, IrOpcode::Value kOpcode> |
108 struct IntMatcher FINAL : public ValueMatcher<T, kOpcode> { | 108 struct IntMatcher final : public ValueMatcher<T, kOpcode> { |
109 explicit IntMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {} | 109 explicit IntMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {} |
110 | 110 |
111 bool IsMultipleOf(T n) const { | 111 bool IsMultipleOf(T n) const { |
112 return this->HasValue() && (this->Value() % n) == 0; | 112 return this->HasValue() && (this->Value() % n) == 0; |
113 } | 113 } |
114 bool IsPowerOf2() const { | 114 bool IsPowerOf2() const { |
115 return this->HasValue() && this->Value() > 0 && | 115 return this->HasValue() && this->Value() > 0 && |
116 (this->Value() & (this->Value() - 1)) == 0; | 116 (this->Value() & (this->Value() - 1)) == 0; |
117 } | 117 } |
118 bool IsNegativePowerOf2() const { | 118 bool IsNegativePowerOf2() const { |
(...skipping 10 matching lines...) Expand all Loading... |
129 typedef Int32Matcher IntPtrMatcher; | 129 typedef Int32Matcher IntPtrMatcher; |
130 typedef Uint32Matcher UintPtrMatcher; | 130 typedef Uint32Matcher UintPtrMatcher; |
131 #else | 131 #else |
132 typedef Int64Matcher IntPtrMatcher; | 132 typedef Int64Matcher IntPtrMatcher; |
133 typedef Uint64Matcher UintPtrMatcher; | 133 typedef Uint64Matcher UintPtrMatcher; |
134 #endif | 134 #endif |
135 | 135 |
136 | 136 |
137 // A pattern matcher for floating point constants. | 137 // A pattern matcher for floating point constants. |
138 template <typename T, IrOpcode::Value kOpcode> | 138 template <typename T, IrOpcode::Value kOpcode> |
139 struct FloatMatcher FINAL : public ValueMatcher<T, kOpcode> { | 139 struct FloatMatcher final : public ValueMatcher<T, kOpcode> { |
140 explicit FloatMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {} | 140 explicit FloatMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {} |
141 | 141 |
142 bool IsMinusZero() const { | 142 bool IsMinusZero() const { |
143 return this->Is(0.0) && std::signbit(this->Value()); | 143 return this->Is(0.0) && std::signbit(this->Value()); |
144 } | 144 } |
145 bool IsNaN() const { return this->HasValue() && std::isnan(this->Value()); } | 145 bool IsNaN() const { return this->HasValue() && std::isnan(this->Value()); } |
146 bool IsZero() const { return this->Is(0.0) && !std::signbit(this->Value()); } | 146 bool IsZero() const { return this->Is(0.0) && !std::signbit(this->Value()); } |
147 }; | 147 }; |
148 | 148 |
149 typedef FloatMatcher<float, IrOpcode::kFloat32Constant> Float32Matcher; | 149 typedef FloatMatcher<float, IrOpcode::kFloat32Constant> Float32Matcher; |
150 typedef FloatMatcher<double, IrOpcode::kFloat64Constant> Float64Matcher; | 150 typedef FloatMatcher<double, IrOpcode::kFloat64Constant> Float64Matcher; |
151 typedef FloatMatcher<double, IrOpcode::kNumberConstant> NumberMatcher; | 151 typedef FloatMatcher<double, IrOpcode::kNumberConstant> NumberMatcher; |
152 | 152 |
153 | 153 |
154 // A pattern matcher for heap object constants. | 154 // A pattern matcher for heap object constants. |
155 template <typename T> | 155 template <typename T> |
156 struct HeapObjectMatcher FINAL | 156 struct HeapObjectMatcher final |
157 : public ValueMatcher<Unique<T>, IrOpcode::kHeapConstant> { | 157 : public ValueMatcher<Unique<T>, IrOpcode::kHeapConstant> { |
158 explicit HeapObjectMatcher(Node* node) | 158 explicit HeapObjectMatcher(Node* node) |
159 : ValueMatcher<Unique<T>, IrOpcode::kHeapConstant>(node) {} | 159 : ValueMatcher<Unique<T>, IrOpcode::kHeapConstant>(node) {} |
160 }; | 160 }; |
161 | 161 |
162 | 162 |
163 // A pattern matcher for external reference constants. | 163 // A pattern matcher for external reference constants. |
164 struct ExternalReferenceMatcher FINAL | 164 struct ExternalReferenceMatcher final |
165 : public ValueMatcher<ExternalReference, IrOpcode::kExternalConstant> { | 165 : public ValueMatcher<ExternalReference, IrOpcode::kExternalConstant> { |
166 explicit ExternalReferenceMatcher(Node* node) | 166 explicit ExternalReferenceMatcher(Node* node) |
167 : ValueMatcher<ExternalReference, IrOpcode::kExternalConstant>(node) {} | 167 : ValueMatcher<ExternalReference, IrOpcode::kExternalConstant>(node) {} |
168 }; | 168 }; |
169 | 169 |
170 | 170 |
171 // For shorter pattern matching code, this struct matches the inputs to | 171 // For shorter pattern matching code, this struct matches the inputs to |
172 // machine-level load operations. | 172 // machine-level load operations. |
173 template <typename Object> | 173 template <typename Object> |
174 struct LoadMatcher : public NodeMatcher { | 174 struct LoadMatcher : public NodeMatcher { |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 Node* branch_; | 591 Node* branch_; |
592 Node* if_true_; | 592 Node* if_true_; |
593 Node* if_false_; | 593 Node* if_false_; |
594 }; | 594 }; |
595 | 595 |
596 } // namespace compiler | 596 } // namespace compiler |
597 } // namespace internal | 597 } // namespace internal |
598 } // namespace v8 | 598 } // namespace v8 |
599 | 599 |
600 #endif // V8_COMPILER_NODE_MATCHERS_H_ | 600 #endif // V8_COMPILER_NODE_MATCHERS_H_ |
OLD | NEW |