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 value_ = 0; // Make the compiler happy. | |
119 break; | |
120 } | |
121 } | |
122 | |
123 bool HasValue() const { return has_value_; } | |
124 double Value() const { | |
125 DCHECK(HasValue()); | |
126 return value_; | |
127 } | |
128 | |
129 private: | |
130 double value_; | |
131 bool has_value_; | |
132 }; | |
133 | |
134 | |
135 // A pattern matcher for heap object constants. | 99 // A pattern matcher for heap object constants. |
136 template <typename T> | 100 template <typename T> |
137 struct HeapObjectMatcher FINAL | 101 struct HeapObjectMatcher FINAL |
138 : public ValueMatcher<Unique<T>, IrOpcode::kHeapConstant> { | 102 : public ValueMatcher<Unique<T>, IrOpcode::kHeapConstant> { |
139 explicit HeapObjectMatcher(Node* node) | 103 explicit HeapObjectMatcher(Node* node) |
140 : ValueMatcher<Unique<T>, IrOpcode::kHeapConstant>(node) {} | 104 : ValueMatcher<Unique<T>, IrOpcode::kHeapConstant>(node) {} |
141 }; | 105 }; |
142 | 106 |
143 | 107 |
144 // 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 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 int power_; | 220 int power_; |
257 int displacement_; | 221 int displacement_; |
258 }; | 222 }; |
259 | 223 |
260 | 224 |
261 } // namespace compiler | 225 } // namespace compiler |
262 } // namespace internal | 226 } // namespace internal |
263 } // namespace v8 | 227 } // namespace v8 |
264 | 228 |
265 #endif // V8_COMPILER_NODE_MATCHERS_H_ | 229 #endif // V8_COMPILER_NODE_MATCHERS_H_ |
OLD | NEW |