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

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

Issue 615483003: [turbofan] x64 lea multiplication matching (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 | « BUILD.gn ('k') | src/compiler/node-matchers.cc » ('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/node.h" 8 #include "src/compiler/node.h"
9 #include "src/compiler/operator.h" 9 #include "src/compiler/operator.h"
10 10
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 typedef BinopMatcher<Int64Matcher, Int64Matcher> Int64BinopMatcher; 138 typedef BinopMatcher<Int64Matcher, Int64Matcher> Int64BinopMatcher;
139 typedef BinopMatcher<Uint64Matcher, Uint64Matcher> Uint64BinopMatcher; 139 typedef BinopMatcher<Uint64Matcher, Uint64Matcher> Uint64BinopMatcher;
140 typedef BinopMatcher<Float64Matcher, Float64Matcher> Float64BinopMatcher; 140 typedef BinopMatcher<Float64Matcher, Float64Matcher> Float64BinopMatcher;
141 141
142 142
143 // Fairly intel-specify node matcher used for matching scale factors in 143 // Fairly intel-specify node matcher used for matching scale factors in
144 // addressing modes. 144 // addressing modes.
145 // Matches nodes of form [x * N] for N in {1,2,4,8} 145 // Matches nodes of form [x * N] for N in {1,2,4,8}
146 class ScaleFactorMatcher : public NodeMatcher { 146 class ScaleFactorMatcher : public NodeMatcher {
147 public: 147 public:
148 explicit ScaleFactorMatcher(Node* node) 148 static const int kMatchedFactors[4];
149 : NodeMatcher(node), left_(NULL), power_(0) {
150 Match();
151 }
152 149
153 bool Matches() { return left_ != NULL; } 150 explicit ScaleFactorMatcher(Node* node);
154 int Power() { 151
152 bool Matches() const { return left_ != NULL; }
153 int Power() const {
155 DCHECK(Matches()); 154 DCHECK(Matches());
156 return power_; 155 return power_;
157 } 156 }
158 Node* Left() { 157 Node* Left() const {
159 DCHECK(Matches()); 158 DCHECK(Matches());
160 return left_; 159 return left_;
161 } 160 }
162 161
163 private: 162 private:
164 void Match() {
165 if (opcode() != IrOpcode::kInt32Mul) return;
166 Int32BinopMatcher m(node());
167 if (!m.right().HasValue()) return;
168 int32_t value = m.right().Value();
169 switch (value) {
170 case 8:
171 power_++; // Fall through.
172 case 4:
173 power_++; // Fall through.
174 case 2:
175 power_++; // Fall through.
176 case 1:
177 break;
178 default:
179 return;
180 }
181 left_ = m.left().node();
182 }
183
184 Node* left_; 163 Node* left_;
185 int power_; 164 int power_;
186 }; 165 };
187 166
188 167
189 // Fairly intel-specify node matcher used for matching index and displacement 168 // Fairly intel-specify node matcher used for matching index and displacement
190 // operands in addressing modes. 169 // operands in addressing modes.
191 // Matches nodes of form: 170 // Matches nodes of form:
192 // [x * N] 171 // [x * N]
193 // [x * N + K] 172 // [x * N + K]
194 // [x + K] 173 // [x + K]
195 // [x] -- fallback case 174 // [x] -- fallback case
196 // for N in {1,2,4,8} and K int32_t 175 // for N in {1,2,4,8} and K int32_t
197 class IndexAndDisplacementMatcher : public NodeMatcher { 176 class IndexAndDisplacementMatcher : public NodeMatcher {
198 public: 177 public:
199 explicit IndexAndDisplacementMatcher(Node* node) 178 explicit IndexAndDisplacementMatcher(Node* node);
200 : NodeMatcher(node), index_node_(node), displacement_(0), power_(0) {
201 Match();
202 }
203 179
204 Node* index_node() { return index_node_; } 180 Node* index_node() const { return index_node_; }
205 int displacement() { return displacement_; } 181 int displacement() const { return displacement_; }
206 int power() { return power_; } 182 int power() const { return power_; }
207 183
208 private: 184 private:
209 void Match() {
210 if (opcode() == IrOpcode::kInt32Add) {
211 // Assume reduction has put constant on the right.
212 Int32BinopMatcher m(node());
213 if (m.right().HasValue()) {
214 displacement_ = m.right().Value();
215 index_node_ = m.left().node();
216 }
217 }
218 // Test scale factor.
219 ScaleFactorMatcher scale_matcher(index_node_);
220 if (scale_matcher.Matches()) {
221 index_node_ = scale_matcher.Left();
222 power_ = scale_matcher.Power();
223 }
224 }
225
226 Node* index_node_; 185 Node* index_node_;
227 int displacement_; 186 int displacement_;
228 int power_; 187 int power_;
229 }; 188 };
230 189
231 190
191 // Fairly intel-specify node matcher used for matching multiplies that can be
192 // transformed to lea instructions.
193 // Matches nodes of form:
194 // [x * N]
195 // for N in {1,2,3,4,5,8,9}
196 class LeaMultiplyMatcher : public NodeMatcher {
197 public:
198 static const int kMatchedFactors[7];
199
200 explicit LeaMultiplyMatcher(Node* node);
201
202 bool Matches() const { return left_ != NULL; }
203 int Power() const {
204 DCHECK(Matches());
205 return power_;
206 }
207 Node* Left() const {
208 DCHECK(Matches());
209 return left_;
210 }
211 // Displacement will be either 0 or 1.
212 int32_t Displacement() const {
213 DCHECK(Matches());
214 return displacement_;
215 }
216
217 private:
218 Node* left_;
219 int power_;
220 int displacement_;
221 };
222
223
232 } // namespace compiler 224 } // namespace compiler
233 } // namespace internal 225 } // namespace internal
234 } // namespace v8 226 } // namespace v8
235 227
236 #endif // V8_COMPILER_NODE_MATCHERS_H_ 228 #endif // V8_COMPILER_NODE_MATCHERS_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/compiler/node-matchers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698