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

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

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef V8_COMPILER_NODE_MATCHERS_H_
6 #define V8_COMPILER_NODE_MATCHERS_H_
7
8 #include "src/compiler/common-operator.h"
9
10 namespace v8 {
11 namespace internal {
12 namespace compiler {
13
14 // A pattern matcher for nodes.
15 struct NodeMatcher {
16 explicit NodeMatcher(Node* node) : node_(node) { }
17
18 Node* node() const { return node_; }
19 Operator* op() const { return node()->op(); }
20 IrOpcode::Value opcode() const { return node()->opcode(); }
21
22 bool HasProperty(Operator::Property property) const {
23 return op()->HasProperty(property);
24 }
25 Node* InputAt(int index) const { return node()->InputAt(index); }
26
27 #define DEFINE_IS_OPCODE(Opcode) \
28 bool Is##Opcode() const { return opcode() == IrOpcode::k##Opcode; }
29 ALL_OP_LIST(DEFINE_IS_OPCODE)
30 #undef DEFINE_IS_OPCODE
31
32 private:
33 Node* node_;
34 };
35
36
37 // A pattern matcher for abitrary value constants.
38 template <typename T>
39 struct ValueMatcher : public NodeMatcher {
40 explicit ValueMatcher(Node* node)
41 : NodeMatcher(node), value_(),
42 has_value_(CommonOperatorTraits<T>::HasValue(node->op())) {
43 if (has_value_) value_ = CommonOperatorTraits<T>::ValueOf(node->op());
44 }
45
46 bool HasValue() const { return has_value_; }
47 T Value() const { ASSERT(HasValue()); return value_; }
48
49 bool Is(T value) const {
50 return HasValue() && CommonOperatorTraits<T>::Equals(Value(), value);
51 }
52
53 bool IsInRange(T low, T high) const {
54 return HasValue() && low <= value_ && value_ <= high;
55 }
56
57 private:
58 T value_;
59 bool has_value_;
60 };
61
62
63 // A pattern matcher for integer constants.
64 template <typename T>
65 struct IntMatcher V8_FINAL : public ValueMatcher<T> {
66 explicit IntMatcher(Node* node) : ValueMatcher<T>(node) { }
67
68 bool IsPowerOf2() const {
69 return this->HasValue() && this->Value() > 0 &&
70 (this->Value() & (this->Value() - 1)) == 0;
71 }
72 };
73
74 typedef IntMatcher<int32_t> Int32Matcher;
75 typedef IntMatcher<uint32_t> Uint32Matcher;
76 typedef IntMatcher<int64_t> Int64Matcher;
77 typedef IntMatcher<uint64_t> Uint64Matcher;
78
79
80 // A pattern matcher for floating point constants.
81 template <typename T>
82 struct FloatMatcher V8_FINAL : public ValueMatcher<T> {
83 explicit FloatMatcher(Node* node) : ValueMatcher<T>(node) { }
84
85 bool IsNaN() const {
86 return this->HasValue() && std::isnan(this->Value());
87 }
88 };
89
90 typedef FloatMatcher<double> Float64Matcher;
91
92
93 // For shorter pattern matching code, this struct matches both the left and
94 // right hand sides of a binary operation and can put constants on the right
95 // if they appear on the left hand side of a commutative operation.
96 template <typename Left, typename Right>
97 struct BinopMatcher V8_FINAL : public NodeMatcher {
98 explicit BinopMatcher(Node* node)
99 : NodeMatcher(node), left_(InputAt(0)), right_(InputAt(1)) {
100 if (HasProperty(Operator::kCommutative)) PutConstantOnRight();
101 }
102
103 const Left& left() const { return left_; }
104 const Right& right() const { return right_; }
105
106 bool IsFoldable() const { return left().HasValue() && right().HasValue(); }
107 bool LeftEqualsRight() const { return left().node() == right().node(); }
108
109 private:
110 void PutConstantOnRight() {
111 if (left().HasValue() && !right().HasValue()) {
112 std::swap(left_, right_);
113 node()->ReplaceInput(0, left().node());
114 node()->ReplaceInput(1, right().node());
115 }
116 }
117
118 Left left_;
119 Right right_;
120 };
121
122 typedef BinopMatcher<Int32Matcher, Int32Matcher> Int32BinopMatcher;
123 typedef BinopMatcher<Uint32Matcher, Uint32Matcher> Uint32BinopMatcher;
124 typedef BinopMatcher<Int64Matcher, Int64Matcher> Int64BinopMatcher;
125 typedef BinopMatcher<Uint64Matcher, Uint64Matcher> Uint64BinopMatcher;
126 typedef BinopMatcher<Float64Matcher, Float64Matcher> Float64BinopMatcher;
127
128 } } } // namespace v8::internal::compiler
129
130 #endif // V8_COMPILER_NODE_MATCHERS_H_
OLDNEW
« no previous file with comments | « src/compiler/node-cache.cc ('k') | src/compiler/node-properties.h » ('j') | src/lithium-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698