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