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 #include "src/compiler/node.h" | 10 #include "src/compiler/node.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 bool Is##Opcode() const { return opcode() == IrOpcode::k##Opcode; } | 32 bool Is##Opcode() const { return opcode() == IrOpcode::k##Opcode; } |
33 ALL_OP_LIST(DEFINE_IS_OPCODE) | 33 ALL_OP_LIST(DEFINE_IS_OPCODE) |
34 #undef DEFINE_IS_OPCODE | 34 #undef DEFINE_IS_OPCODE |
35 | 35 |
36 private: | 36 private: |
37 Node* node_; | 37 Node* node_; |
38 }; | 38 }; |
39 | 39 |
40 | 40 |
41 // A pattern matcher for abitrary value constants. | 41 // A pattern matcher for abitrary value constants. |
42 template <typename T, IrOpcode::Value kMatchOpcode> | 42 template <typename T, IrOpcode::Value kOpcode> |
43 struct ValueMatcher : public NodeMatcher { | 43 struct ValueMatcher : public NodeMatcher { |
44 typedef T ValueType; | 44 typedef T ValueType; |
45 static const IrOpcode::Value kOpcode = kMatchOpcode; | |
46 | 45 |
47 explicit ValueMatcher(Node* node) | 46 explicit ValueMatcher(Node* node) |
48 : NodeMatcher(node), value_(), has_value_(opcode() == kOpcode) { | 47 : NodeMatcher(node), value_(), has_value_(opcode() == kOpcode) { |
49 if (has_value_) { | 48 if (has_value_) { |
50 value_ = OpParameter<T>(node); | 49 value_ = OpParameter<T>(node); |
51 } | 50 } |
52 } | 51 } |
53 | 52 |
54 bool HasValue() const { return has_value_; } | 53 bool HasValue() const { return has_value_; } |
55 const T& Value() const { | 54 const T& Value() const { |
56 DCHECK(HasValue()); | 55 DCHECK(HasValue()); |
57 return value_; | 56 return value_; |
58 } | 57 } |
59 | 58 |
60 bool Is(const T& value) const { | 59 bool Is(const T& value) const { |
61 return this->HasValue() && this->Value() == value; | 60 return this->HasValue() && this->Value() == value; |
62 } | 61 } |
63 | 62 |
64 bool IsInRange(const T& low, const T& high) const { | 63 bool IsInRange(const T& low, const T& high) const { |
65 return this->HasValue() && low <= this->Value() && this->Value() <= high; | 64 return this->HasValue() && low <= this->Value() && this->Value() <= high; |
66 } | 65 } |
67 | 66 |
68 private: | 67 private: |
69 T value_; | 68 T value_; |
70 bool has_value_; | 69 bool has_value_; |
71 }; | 70 }; |
72 | 71 |
73 | 72 |
| 73 template <> |
| 74 inline ValueMatcher<int64_t, IrOpcode::kInt64Constant>::ValueMatcher(Node* node) |
| 75 : NodeMatcher(node), value_(), has_value_(false) { |
| 76 if (opcode() == IrOpcode::kInt32Constant) { |
| 77 value_ = OpParameter<int32_t>(node); |
| 78 has_value_ = true; |
| 79 } else if (opcode() == IrOpcode::kInt64Constant) { |
| 80 value_ = OpParameter<int64_t>(node); |
| 81 has_value_ = true; |
| 82 } |
| 83 } |
| 84 |
| 85 |
| 86 template <> |
| 87 inline ValueMatcher<uint64_t, IrOpcode::kInt64Constant>::ValueMatcher( |
| 88 Node* node) |
| 89 : NodeMatcher(node), value_(), has_value_(false) { |
| 90 if (opcode() == IrOpcode::kInt32Constant) { |
| 91 value_ = OpParameter<uint32_t>(node); |
| 92 has_value_ = true; |
| 93 } else if (opcode() == IrOpcode::kInt64Constant) { |
| 94 value_ = OpParameter<uint64_t>(node); |
| 95 has_value_ = true; |
| 96 } |
| 97 } |
| 98 |
| 99 |
74 // A pattern matcher for integer constants. | 100 // A pattern matcher for integer constants. |
75 template <typename T, IrOpcode::Value kOpcode> | 101 template <typename T, IrOpcode::Value kOpcode> |
76 struct IntMatcher FINAL : public ValueMatcher<T, kOpcode> { | 102 struct IntMatcher FINAL : public ValueMatcher<T, kOpcode> { |
77 explicit IntMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {} | 103 explicit IntMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {} |
78 | 104 |
79 bool IsPowerOf2() const { | 105 bool IsPowerOf2() const { |
80 return this->HasValue() && this->Value() > 0 && | 106 return this->HasValue() && this->Value() > 0 && |
81 (this->Value() & (this->Value() - 1)) == 0; | 107 (this->Value() & (this->Value() - 1)) == 0; |
82 } | 108 } |
83 bool IsNegativePowerOf2() const { | 109 bool IsNegativePowerOf2() const { |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 typedef BaseWithIndexAndDisplacementMatcher<Int32AddMatcher> | 506 typedef BaseWithIndexAndDisplacementMatcher<Int32AddMatcher> |
481 BaseWithIndexAndDisplacement32Matcher; | 507 BaseWithIndexAndDisplacement32Matcher; |
482 typedef BaseWithIndexAndDisplacementMatcher<Int64AddMatcher> | 508 typedef BaseWithIndexAndDisplacementMatcher<Int64AddMatcher> |
483 BaseWithIndexAndDisplacement64Matcher; | 509 BaseWithIndexAndDisplacement64Matcher; |
484 | 510 |
485 } // namespace compiler | 511 } // namespace compiler |
486 } // namespace internal | 512 } // namespace internal |
487 } // namespace v8 | 513 } // namespace v8 |
488 | 514 |
489 #endif // V8_COMPILER_NODE_MATCHERS_H_ | 515 #endif // V8_COMPILER_NODE_MATCHERS_H_ |
OLD | NEW |