| OLD | NEW | 
|---|
|  | (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 #include "src/compiler/generic-node-inl.h" |  | 
| 6 #include "src/compiler/node-matchers.h" |  | 
| 7 |  | 
| 8 namespace v8 { |  | 
| 9 namespace internal { |  | 
| 10 namespace compiler { |  | 
| 11 |  | 
| 12 const int ScaleFactorMatcher::kMatchedFactors[] = {1, 2, 4, 8}; |  | 
| 13 |  | 
| 14 |  | 
| 15 ScaleFactorMatcher::ScaleFactorMatcher(Node* node) |  | 
| 16     : NodeMatcher(node), left_(NULL), power_(0) { |  | 
| 17   if (opcode() != IrOpcode::kInt32Mul) return; |  | 
| 18   // TODO(dcarney): should test 64 bit ints as well. |  | 
| 19   Int32BinopMatcher m(this->node()); |  | 
| 20   if (!m.right().HasValue()) return; |  | 
| 21   int32_t value = m.right().Value(); |  | 
| 22   switch (value) { |  | 
| 23     case 8: |  | 
| 24       power_++;  // Fall through. |  | 
| 25     case 4: |  | 
| 26       power_++;  // Fall through. |  | 
| 27     case 2: |  | 
| 28       power_++;  // Fall through. |  | 
| 29     case 1: |  | 
| 30       break; |  | 
| 31     default: |  | 
| 32       return; |  | 
| 33   } |  | 
| 34   left_ = m.left().node(); |  | 
| 35 } |  | 
| 36 |  | 
| 37 |  | 
| 38 IndexAndDisplacementMatcher::IndexAndDisplacementMatcher(Node* node) |  | 
| 39     : NodeMatcher(node), index_node_(node), displacement_(0), power_(0) { |  | 
| 40   if (opcode() == IrOpcode::kInt32Add) { |  | 
| 41     Int32BinopMatcher m(this->node()); |  | 
| 42     if (m.right().HasValue()) { |  | 
| 43       displacement_ = m.right().Value(); |  | 
| 44       index_node_ = m.left().node(); |  | 
| 45     } |  | 
| 46   } |  | 
| 47   // Test scale factor. |  | 
| 48   ScaleFactorMatcher scale_matcher(index_node_); |  | 
| 49   if (scale_matcher.Matches()) { |  | 
| 50     index_node_ = scale_matcher.Left(); |  | 
| 51     power_ = scale_matcher.Power(); |  | 
| 52   } |  | 
| 53 } |  | 
| 54 |  | 
| 55 |  | 
| 56 const int LeaMultiplyMatcher::kMatchedFactors[7] = {1, 2, 3, 4, 5, 8, 9}; |  | 
| 57 |  | 
| 58 |  | 
| 59 LeaMultiplyMatcher::LeaMultiplyMatcher(Node* node) |  | 
| 60     : NodeMatcher(node), left_(NULL), power_(0), displacement_(0) { |  | 
| 61   if (opcode() != IrOpcode::kInt32Mul && opcode() != IrOpcode::kInt64Mul) { |  | 
| 62     return; |  | 
| 63   } |  | 
| 64   int64_t value; |  | 
| 65   Node* left = NULL; |  | 
| 66   { |  | 
| 67     Int32BinopMatcher m(this->node()); |  | 
| 68     if (m.right().HasValue()) { |  | 
| 69       value = m.right().Value(); |  | 
| 70       left = m.left().node(); |  | 
| 71     } else { |  | 
| 72       Int64BinopMatcher m(this->node()); |  | 
| 73       if (m.right().HasValue()) { |  | 
| 74         value = m.right().Value(); |  | 
| 75         left = m.left().node(); |  | 
| 76       } else { |  | 
| 77         return; |  | 
| 78       } |  | 
| 79     } |  | 
| 80   } |  | 
| 81   switch (value) { |  | 
| 82     case 9: |  | 
| 83     case 8: |  | 
| 84       power_++;  // Fall through. |  | 
| 85     case 5: |  | 
| 86     case 4: |  | 
| 87       power_++;  // Fall through. |  | 
| 88     case 3: |  | 
| 89     case 2: |  | 
| 90       power_++;  // Fall through. |  | 
| 91     case 1: |  | 
| 92       break; |  | 
| 93     default: |  | 
| 94       return; |  | 
| 95   } |  | 
| 96   if (!base::bits::IsPowerOfTwo64(value)) { |  | 
| 97     displacement_ = 1; |  | 
| 98   } |  | 
| 99   left_ = left; |  | 
| 100 } |  | 
| 101 |  | 
| 102 }  // namespace compiler |  | 
| 103 }  // namespace internal |  | 
| 104 }  // namespace v8 |  | 
| OLD | NEW | 
|---|