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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 Left left_; | 132 Left left_; |
133 Right right_; | 133 Right right_; |
134 }; | 134 }; |
135 | 135 |
136 typedef BinopMatcher<Int32Matcher, Int32Matcher> Int32BinopMatcher; | 136 typedef BinopMatcher<Int32Matcher, Int32Matcher> Int32BinopMatcher; |
137 typedef BinopMatcher<Uint32Matcher, Uint32Matcher> Uint32BinopMatcher; | 137 typedef BinopMatcher<Uint32Matcher, Uint32Matcher> Uint32BinopMatcher; |
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 |
| 143 // Fairly intel-specify node matcher used for matching scale factors in |
| 144 // addressing modes. |
| 145 // Matches nodes of form [x * N] for N in {1,2,4,8} |
| 146 class ScaleFactorMatcher : public NodeMatcher { |
| 147 public: |
| 148 explicit ScaleFactorMatcher(Node* node) |
| 149 : NodeMatcher(node), left_(NULL), power_(0) { |
| 150 Match(); |
| 151 } |
| 152 |
| 153 bool Matches() { return left_ != NULL; } |
| 154 int Power() { |
| 155 DCHECK(Matches()); |
| 156 return power_; |
| 157 } |
| 158 Node* Left() { |
| 159 DCHECK(Matches()); |
| 160 return left_; |
| 161 } |
| 162 |
| 163 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_; |
| 185 int power_; |
| 186 }; |
| 187 |
| 188 |
| 189 // Fairly intel-specify node matcher used for matching index and displacement |
| 190 // operands in addressing modes. |
| 191 // Matches nodes of form: |
| 192 // [x * N] |
| 193 // [x * N + K] |
| 194 // [x + K] |
| 195 // [x] -- fallback case |
| 196 // for N in {1,2,4,8} and K int32_t |
| 197 class IndexAndDisplacementMatcher : public NodeMatcher { |
| 198 public: |
| 199 explicit IndexAndDisplacementMatcher(Node* node) |
| 200 : NodeMatcher(node), index_node_(node), displacement_(0), power_(0) { |
| 201 Match(); |
| 202 } |
| 203 |
| 204 Node* index_node() { return index_node_; } |
| 205 int displacement() { return displacement_; } |
| 206 int power() { return power_; } |
| 207 |
| 208 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_; |
| 227 int displacement_; |
| 228 int power_; |
| 229 }; |
| 230 |
| 231 |
142 } // namespace compiler | 232 } // namespace compiler |
143 } // namespace internal | 233 } // namespace internal |
144 } // namespace v8 | 234 } // namespace v8 |
145 | 235 |
146 #endif // V8_COMPILER_NODE_MATCHERS_H_ | 236 #endif // V8_COMPILER_NODE_MATCHERS_H_ |
OLD | NEW |