Chromium Code Reviews| 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 "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 Loading... | |
| 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 static const int kMatchedFactors[4]; | |
| 149 | |
| 148 explicit ScaleFactorMatcher(Node* node) | 150 explicit ScaleFactorMatcher(Node* node) |
| 149 : NodeMatcher(node), left_(NULL), power_(0) { | 151 : NodeMatcher(node), left_(NULL), power_(0) { |
| 150 Match(); | 152 Match(); |
| 151 } | 153 } |
| 152 | 154 |
| 153 bool Matches() { return left_ != NULL; } | 155 bool Matches() { return left_ != NULL; } |
| 154 int Power() { | 156 int Power() { |
| 155 DCHECK(Matches()); | 157 DCHECK(Matches()); |
| 156 return power_; | 158 return power_; |
| 157 } | 159 } |
| 158 Node* Left() { | 160 Node* Left() { |
| 159 DCHECK(Matches()); | 161 DCHECK(Matches()); |
| 160 return left_; | 162 return left_; |
| 161 } | 163 } |
| 162 | 164 |
| 163 private: | 165 private: |
| 164 void Match() { | 166 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 | 167 |
| 184 Node* left_; | 168 Node* left_; |
| 185 int power_; | 169 int power_; |
| 186 }; | 170 }; |
| 187 | 171 |
| 188 | 172 |
| 189 // Fairly intel-specify node matcher used for matching index and displacement | 173 // Fairly intel-specify node matcher used for matching index and displacement |
| 190 // operands in addressing modes. | 174 // operands in addressing modes. |
| 191 // Matches nodes of form: | 175 // Matches nodes of form: |
| 192 // [x * N] | 176 // [x * N] |
| 193 // [x * N + K] | 177 // [x * N + K] |
| 194 // [x + K] | 178 // [x + K] |
| 195 // [x] -- fallback case | 179 // [x] -- fallback case |
| 196 // for N in {1,2,4,8} and K int32_t | 180 // for N in {1,2,4,8} and K int32_t |
| 197 class IndexAndDisplacementMatcher : public NodeMatcher { | 181 class IndexAndDisplacementMatcher : public NodeMatcher { |
| 198 public: | 182 public: |
| 199 explicit IndexAndDisplacementMatcher(Node* node) | 183 explicit IndexAndDisplacementMatcher(Node* node) |
| 200 : NodeMatcher(node), index_node_(node), displacement_(0), power_(0) { | 184 : NodeMatcher(node), index_node_(node), displacement_(0), power_(0) { |
| 201 Match(); | 185 Match(); |
| 202 } | 186 } |
| 203 | 187 |
| 204 Node* index_node() { return index_node_; } | 188 Node* index_node() { return index_node_; } |
| 205 int displacement() { return displacement_; } | 189 int displacement() { return displacement_; } |
| 206 int power() { return power_; } | 190 int power() { return power_; } |
| 207 | 191 |
| 208 private: | 192 private: |
| 209 void Match() { | 193 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 | 194 |
| 226 Node* index_node_; | 195 Node* index_node_; |
| 227 int displacement_; | 196 int displacement_; |
| 228 int power_; | 197 int power_; |
| 229 }; | 198 }; |
| 230 | 199 |
| 231 | 200 |
| 201 // Fairly intel-specify node matcher used for matching multiplies that can be | |
| 202 // transformed to lea instructions. | |
| 203 // Matches nodes of form: | |
| 204 // [x * N] | |
| 205 // for N in {1,2,3,4,5,8,9} | |
| 206 class LeaMultiplyMatcher : public NodeMatcher { | |
| 207 public: | |
| 208 static const int kMatchedFactors[7]; | |
| 209 | |
| 210 explicit LeaMultiplyMatcher(Node* node) | |
| 211 : NodeMatcher(node), left_(NULL), power_(0), displacement_(0) { | |
| 212 Match(); | |
| 213 } | |
| 214 | |
| 215 bool Matches() { return left_ != NULL; } | |
|
Benedikt Meurer
2014/09/30 04:55:04
Nit: const
dcarney
2014/09/30 08:03:22
Done.
| |
| 216 int Power() { | |
|
Benedikt Meurer
2014/09/30 04:55:04
Nit: const
dcarney
2014/09/30 08:03:22
Done.
| |
| 217 DCHECK(Matches()); | |
| 218 return power_; | |
| 219 } | |
| 220 Node* Left() { | |
|
Benedikt Meurer
2014/09/30 04:55:04
Nit: const
dcarney
2014/09/30 08:03:22
Done.
| |
| 221 DCHECK(Matches()); | |
| 222 return left_; | |
| 223 } | |
| 224 // Displacement will be either 0 or 1. | |
| 225 int32_t Displacement() { | |
|
Benedikt Meurer
2014/09/30 04:55:04
Nit: const
dcarney
2014/09/30 08:03:22
Done.
| |
| 226 DCHECK(Matches()); | |
| 227 return displacement_; | |
| 228 } | |
| 229 | |
| 230 private: | |
| 231 void Match(); | |
|
Benedikt Meurer
2014/09/30 04:55:04
Hm, those Match method(s) could be inlined into th
dcarney
2014/09/30 08:03:22
Done.
| |
| 232 | |
| 233 Node* left_; | |
| 234 int power_; | |
| 235 int displacement_; | |
| 236 }; | |
| 237 | |
| 238 | |
| 232 } // namespace compiler | 239 } // namespace compiler |
| 233 } // namespace internal | 240 } // namespace internal |
| 234 } // namespace v8 | 241 } // namespace v8 |
| 235 | 242 |
| 236 #endif // V8_COMPILER_NODE_MATCHERS_H_ | 243 #endif // V8_COMPILER_NODE_MATCHERS_H_ |
| OLD | NEW |