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/node.h" | 8 #include "src/compiler/node.h" |
9 #include "src/compiler/operator.h" | 9 #include "src/compiler/operator.h" |
10 #include "src/unique.h" | 10 #include "src/unique.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 explicit FloatMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {} | 89 explicit FloatMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {} |
90 | 90 |
91 bool IsNaN() const { return this->HasValue() && std::isnan(this->Value()); } | 91 bool IsNaN() const { return this->HasValue() && std::isnan(this->Value()); } |
92 }; | 92 }; |
93 | 93 |
94 typedef FloatMatcher<float, IrOpcode::kFloat32Constant> Float32Matcher; | 94 typedef FloatMatcher<float, IrOpcode::kFloat32Constant> Float32Matcher; |
95 typedef FloatMatcher<double, IrOpcode::kFloat64Constant> Float64Matcher; | 95 typedef FloatMatcher<double, IrOpcode::kFloat64Constant> Float64Matcher; |
96 typedef FloatMatcher<double, IrOpcode::kNumberConstant> NumberMatcher; | 96 typedef FloatMatcher<double, IrOpcode::kNumberConstant> NumberMatcher; |
97 | 97 |
98 | 98 |
| 99 // A pattern matcher for any numberic constant. |
| 100 struct NumericValueMatcher : public NodeMatcher { |
| 101 explicit NumericValueMatcher(Node* const node) : NodeMatcher(node) { |
| 102 switch (opcode()) { |
| 103 case IrOpcode::kInt32Constant: |
| 104 has_value_ = true; |
| 105 value_ = OpParameter<int32_t>(node); |
| 106 break; |
| 107 case IrOpcode::kFloat32Constant: |
| 108 has_value_ = true; |
| 109 value_ = OpParameter<float>(node); |
| 110 break; |
| 111 case IrOpcode::kFloat64Constant: |
| 112 case IrOpcode::kNumberConstant: |
| 113 has_value_ = true; |
| 114 value_ = OpParameter<double>(node); |
| 115 break; |
| 116 default: |
| 117 has_value_ = false; |
| 118 break; |
| 119 } |
| 120 } |
| 121 |
| 122 bool HasValue() const { return has_value_; } |
| 123 double Value() const { |
| 124 DCHECK(HasValue()); |
| 125 return value_; |
| 126 } |
| 127 |
| 128 private: |
| 129 double value_; |
| 130 bool has_value_; |
| 131 }; |
| 132 |
| 133 |
99 // A pattern matcher for heap object constants. | 134 // A pattern matcher for heap object constants. |
100 template <typename T> | 135 template <typename T> |
101 struct HeapObjectMatcher FINAL | 136 struct HeapObjectMatcher FINAL |
102 : public ValueMatcher<Unique<T>, IrOpcode::kHeapConstant> { | 137 : public ValueMatcher<Unique<T>, IrOpcode::kHeapConstant> { |
103 explicit HeapObjectMatcher(Node* node) | 138 explicit HeapObjectMatcher(Node* node) |
104 : ValueMatcher<Unique<T>, IrOpcode::kHeapConstant>(node) {} | 139 : ValueMatcher<Unique<T>, IrOpcode::kHeapConstant>(node) {} |
105 }; | 140 }; |
106 | 141 |
107 | 142 |
108 // For shorter pattern matching code, this struct matches both the left and | 143 // For shorter pattern matching code, this struct matches both the left and |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 int power_; | 255 int power_; |
221 int displacement_; | 256 int displacement_; |
222 }; | 257 }; |
223 | 258 |
224 | 259 |
225 } // namespace compiler | 260 } // namespace compiler |
226 } // namespace internal | 261 } // namespace internal |
227 } // namespace v8 | 262 } // namespace v8 |
228 | 263 |
229 #endif // V8_COMPILER_NODE_MATCHERS_H_ | 264 #endif // V8_COMPILER_NODE_MATCHERS_H_ |
OLD | NEW |