Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: src/compiler/node-matchers.h

Issue 552653003: [turbofan] Fix the node matchers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address nit. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/node.h ('k') | src/compiler/operator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common-operator.h"
9 #include "src/compiler/node.h" 8 #include "src/compiler/node.h"
9 #include "src/compiler/operator.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 namespace compiler { 13 namespace compiler {
14 14
15 // A pattern matcher for nodes. 15 // A pattern matcher for nodes.
16 struct NodeMatcher { 16 struct NodeMatcher {
17 explicit NodeMatcher(Node* node) : node_(node) {} 17 explicit NodeMatcher(Node* node) : node_(node) {}
18 18
19 Node* node() const { return node_; } 19 Node* node() const { return node_; }
20 const Operator* op() const { return node()->op(); } 20 const Operator* op() const { return node()->op(); }
21 IrOpcode::Value opcode() const { return node()->opcode(); } 21 IrOpcode::Value opcode() const { return node()->opcode(); }
22 22
23 bool HasProperty(Operator::Property property) const { 23 bool HasProperty(Operator::Property property) const {
24 return op()->HasProperty(property); 24 return op()->HasProperty(property);
25 } 25 }
26 Node* InputAt(int index) const { return node()->InputAt(index); } 26 Node* InputAt(int index) const { return node()->InputAt(index); }
27 27
28 #define DEFINE_IS_OPCODE(Opcode) \ 28 #define DEFINE_IS_OPCODE(Opcode) \
29 bool Is##Opcode() const { return opcode() == IrOpcode::k##Opcode; } 29 bool Is##Opcode() const { return opcode() == IrOpcode::k##Opcode; }
30 ALL_OP_LIST(DEFINE_IS_OPCODE) 30 ALL_OP_LIST(DEFINE_IS_OPCODE)
31 #undef DEFINE_IS_OPCODE 31 #undef DEFINE_IS_OPCODE
32 32
33 private: 33 private:
34 Node* node_; 34 Node* node_;
35 }; 35 };
36 36
37 37
38 // A pattern matcher for abitrary value constants. 38 // A pattern matcher for abitrary value constants.
39 template <typename T> 39 template <typename T, IrOpcode::Value kOpcode>
40 struct ValueMatcher : public NodeMatcher { 40 struct ValueMatcher : public NodeMatcher {
41 explicit ValueMatcher(Node* node) 41 explicit ValueMatcher(Node* node)
42 : NodeMatcher(node), 42 : NodeMatcher(node), value_(), has_value_(opcode() == kOpcode) {
43 value_(), 43 if (has_value_) {
44 has_value_(CommonOperatorTraits<T>::HasValue(node->op())) { 44 value_ = OpParameter<T>(node);
45 if (has_value_) value_ = CommonOperatorTraits<T>::ValueOf(node->op()); 45 }
46 } 46 }
47 47
48 bool HasValue() const { return has_value_; } 48 bool HasValue() const { return has_value_; }
49 T Value() const { 49 const T& Value() const {
50 DCHECK(HasValue()); 50 DCHECK(HasValue());
51 return value_; 51 return value_;
52 } 52 }
53 53
54 bool Is(T value) const { 54 bool Is(const T& value) const {
55 return HasValue() && CommonOperatorTraits<T>::Equals(Value(), value); 55 return this->HasValue() && this->Value() == value;
56 } 56 }
57 57
58 bool IsInRange(T low, T high) const { 58 bool IsInRange(const T& low, const T& high) const {
59 return HasValue() && low <= value_ && value_ <= high; 59 return this->HasValue() && low <= this->Value() && this->Value() <= high;
60 } 60 }
61 61
62 private: 62 private:
63 T value_; 63 T value_;
64 bool has_value_; 64 bool has_value_;
65 }; 65 };
66 66
67 67
68 // A pattern matcher for integer constants. 68 // A pattern matcher for integer constants.
69 template <typename T> 69 template <typename T, IrOpcode::Value kOpcode>
70 struct IntMatcher FINAL : public ValueMatcher<T> { 70 struct IntMatcher FINAL : public ValueMatcher<T, kOpcode> {
71 explicit IntMatcher(Node* node) : ValueMatcher<T>(node) {} 71 explicit IntMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {}
72 72
73 bool IsPowerOf2() const { 73 bool IsPowerOf2() const {
74 return this->HasValue() && this->Value() > 0 && 74 return this->HasValue() && this->Value() > 0 &&
75 (this->Value() & (this->Value() - 1)) == 0; 75 (this->Value() & (this->Value() - 1)) == 0;
76 } 76 }
77 }; 77 };
78 78
79 typedef IntMatcher<int32_t> Int32Matcher; 79 typedef IntMatcher<int32_t, IrOpcode::kInt32Constant> Int32Matcher;
80 typedef IntMatcher<uint32_t> Uint32Matcher; 80 typedef IntMatcher<uint32_t, IrOpcode::kInt32Constant> Uint32Matcher;
81 typedef IntMatcher<int64_t> Int64Matcher; 81 typedef IntMatcher<int64_t, IrOpcode::kInt64Constant> Int64Matcher;
82 typedef IntMatcher<uint64_t> Uint64Matcher; 82 typedef IntMatcher<uint64_t, IrOpcode::kInt64Constant> Uint64Matcher;
83 83
84 84
85 // A pattern matcher for floating point constants. 85 // A pattern matcher for floating point constants.
86 template <typename T> 86 template <typename T, IrOpcode::Value kOpcode>
87 struct FloatMatcher FINAL : public ValueMatcher<T> { 87 struct FloatMatcher FINAL : public ValueMatcher<T, kOpcode> {
88 explicit FloatMatcher(Node* node) : ValueMatcher<T>(node) {} 88 explicit FloatMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {}
89 89
90 bool IsNaN() const { return this->HasValue() && std::isnan(this->Value()); } 90 bool IsNaN() const { return this->HasValue() && std::isnan(this->Value()); }
91 }; 91 };
92 92
93 typedef FloatMatcher<double> Float64Matcher; 93 typedef FloatMatcher<double, IrOpcode::kFloat64Constant> Float64Matcher;
94 typedef FloatMatcher<double, IrOpcode::kNumberConstant> NumberMatcher;
94 95
95 96
96 // A pattern matcher for heap object constants. 97 // A pattern matcher for heap object constants.
97 struct HeapObjectMatcher FINAL : public ValueMatcher<Handle<HeapObject> > { 98 template <typename T>
99 struct HeapObjectMatcher FINAL
100 : public ValueMatcher<Unique<T>, IrOpcode::kHeapConstant> {
98 explicit HeapObjectMatcher(Node* node) 101 explicit HeapObjectMatcher(Node* node)
99 : ValueMatcher<Handle<HeapObject> >(node) {} 102 : ValueMatcher<Unique<T>, IrOpcode::kHeapConstant>(node) {}
100
101 bool IsKnownGlobal(Handle<HeapObject> global) const {
102 return HasValue() && Value().is_identical_to(global);
103 }
104 }; 103 };
105 104
106 105
107 // For shorter pattern matching code, this struct matches both the left and 106 // For shorter pattern matching code, this struct matches both the left and
108 // right hand sides of a binary operation and can put constants on the right 107 // right hand sides of a binary operation and can put constants on the right
109 // if they appear on the left hand side of a commutative operation. 108 // if they appear on the left hand side of a commutative operation.
110 template <typename Left, typename Right> 109 template <typename Left, typename Right>
111 struct BinopMatcher FINAL : public NodeMatcher { 110 struct BinopMatcher FINAL : public NodeMatcher {
112 explicit BinopMatcher(Node* node) 111 explicit BinopMatcher(Node* node)
113 : NodeMatcher(node), left_(InputAt(0)), right_(InputAt(1)) { 112 : NodeMatcher(node), left_(InputAt(0)), right_(InputAt(1)) {
(...skipping 17 matching lines...) Expand all
131 130
132 Left left_; 131 Left left_;
133 Right right_; 132 Right right_;
134 }; 133 };
135 134
136 typedef BinopMatcher<Int32Matcher, Int32Matcher> Int32BinopMatcher; 135 typedef BinopMatcher<Int32Matcher, Int32Matcher> Int32BinopMatcher;
137 typedef BinopMatcher<Uint32Matcher, Uint32Matcher> Uint32BinopMatcher; 136 typedef BinopMatcher<Uint32Matcher, Uint32Matcher> Uint32BinopMatcher;
138 typedef BinopMatcher<Int64Matcher, Int64Matcher> Int64BinopMatcher; 137 typedef BinopMatcher<Int64Matcher, Int64Matcher> Int64BinopMatcher;
139 typedef BinopMatcher<Uint64Matcher, Uint64Matcher> Uint64BinopMatcher; 138 typedef BinopMatcher<Uint64Matcher, Uint64Matcher> Uint64BinopMatcher;
140 typedef BinopMatcher<Float64Matcher, Float64Matcher> Float64BinopMatcher; 139 typedef BinopMatcher<Float64Matcher, Float64Matcher> Float64BinopMatcher;
141 } 140
142 } 141 } // namespace compiler
143 } // namespace v8::internal::compiler 142 } // namespace internal
143 } // namespace v8
144 144
145 #endif // V8_COMPILER_NODE_MATCHERS_H_ 145 #endif // V8_COMPILER_NODE_MATCHERS_H_
OLDNEW
« no previous file with comments | « src/compiler/node.h ('k') | src/compiler/operator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698