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 |
| 11 #include "src/assembler.h" |
10 #include "src/compiler/node.h" | 12 #include "src/compiler/node.h" |
11 #include "src/compiler/operator.h" | 13 #include "src/compiler/operator.h" |
12 #include "src/unique.h" | 14 #include "src/unique.h" |
13 | 15 |
14 namespace v8 { | 16 namespace v8 { |
15 namespace internal { | 17 namespace internal { |
16 namespace compiler { | 18 namespace compiler { |
17 | 19 |
18 // A pattern matcher for nodes. | 20 // A pattern matcher for nodes. |
19 struct NodeMatcher { | 21 struct NodeMatcher { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 150 |
149 // A pattern matcher for heap object constants. | 151 // A pattern matcher for heap object constants. |
150 template <typename T> | 152 template <typename T> |
151 struct HeapObjectMatcher FINAL | 153 struct HeapObjectMatcher FINAL |
152 : public ValueMatcher<Unique<T>, IrOpcode::kHeapConstant> { | 154 : public ValueMatcher<Unique<T>, IrOpcode::kHeapConstant> { |
153 explicit HeapObjectMatcher(Node* node) | 155 explicit HeapObjectMatcher(Node* node) |
154 : ValueMatcher<Unique<T>, IrOpcode::kHeapConstant>(node) {} | 156 : ValueMatcher<Unique<T>, IrOpcode::kHeapConstant>(node) {} |
155 }; | 157 }; |
156 | 158 |
157 | 159 |
| 160 // A pattern matcher for external reference constants. |
| 161 struct ExternalReferenceMatcher FINAL |
| 162 : public ValueMatcher<ExternalReference, IrOpcode::kExternalConstant> { |
| 163 explicit ExternalReferenceMatcher(Node* node) |
| 164 : ValueMatcher<ExternalReference, IrOpcode::kExternalConstant>(node) {} |
| 165 }; |
| 166 |
| 167 |
| 168 // For shorter pattern matching code, this struct matches the inputs to |
| 169 // machine-level load operations. |
| 170 template <typename Object> |
| 171 struct LoadMatcher : public NodeMatcher { |
| 172 explicit LoadMatcher(Node* node) |
| 173 : NodeMatcher(node), object_(InputAt(0)), index_(InputAt(1)) {} |
| 174 |
| 175 typedef Object ObjectMatcher; |
| 176 |
| 177 Object const& object() const { return object_; } |
| 178 IntPtrMatcher const& index() const { return index_; } |
| 179 |
| 180 private: |
| 181 Object const object_; |
| 182 IntPtrMatcher const index_; |
| 183 }; |
| 184 |
| 185 |
158 // For shorter pattern matching code, this struct matches both the left and | 186 // For shorter pattern matching code, this struct matches both the left and |
159 // right hand sides of a binary operation and can put constants on the right | 187 // right hand sides of a binary operation and can put constants on the right |
160 // if they appear on the left hand side of a commutative operation. | 188 // if they appear on the left hand side of a commutative operation. |
161 template <typename Left, typename Right> | 189 template <typename Left, typename Right> |
162 struct BinopMatcher : public NodeMatcher { | 190 struct BinopMatcher : public NodeMatcher { |
163 explicit BinopMatcher(Node* node) | 191 explicit BinopMatcher(Node* node) |
164 : NodeMatcher(node), left_(InputAt(0)), right_(InputAt(1)) { | 192 : NodeMatcher(node), left_(InputAt(0)), right_(InputAt(1)) { |
165 if (HasProperty(Operator::kCommutative)) PutConstantOnRight(); | 193 if (HasProperty(Operator::kCommutative)) PutConstantOnRight(); |
166 } | 194 } |
167 BinopMatcher(Node* node, bool allow_input_swap) | 195 BinopMatcher(Node* node, bool allow_input_swap) |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 typedef BaseWithIndexAndDisplacementMatcher<Int32AddMatcher> | 539 typedef BaseWithIndexAndDisplacementMatcher<Int32AddMatcher> |
512 BaseWithIndexAndDisplacement32Matcher; | 540 BaseWithIndexAndDisplacement32Matcher; |
513 typedef BaseWithIndexAndDisplacementMatcher<Int64AddMatcher> | 541 typedef BaseWithIndexAndDisplacementMatcher<Int64AddMatcher> |
514 BaseWithIndexAndDisplacement64Matcher; | 542 BaseWithIndexAndDisplacement64Matcher; |
515 | 543 |
516 } // namespace compiler | 544 } // namespace compiler |
517 } // namespace internal | 545 } // namespace internal |
518 } // namespace v8 | 546 } // namespace v8 |
519 | 547 |
520 #endif // V8_COMPILER_NODE_MATCHERS_H_ | 548 #endif // V8_COMPILER_NODE_MATCHERS_H_ |
OLD | NEW |