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 #include "src/compiler/instruction-selector-impl.h" | 5 #include "src/compiler/instruction-selector-impl.h" |
6 #include "src/compiler/node-matchers.h" | 6 #include "src/compiler/node-matchers.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 namespace compiler { | 10 namespace compiler { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return false; | 47 return false; |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 bool CanBeBetterLeftOperand(Node* node) const { | 51 bool CanBeBetterLeftOperand(Node* node) const { |
52 return !selector()->IsLive(node); | 52 return !selector()->IsLive(node); |
53 } | 53 } |
54 }; | 54 }; |
55 | 55 |
56 | 56 |
57 // Matches nodes of form [x * N] for N in {1,2,4,8} | |
58 class ScaleFactorMatcher : public NodeMatcher { | |
59 public: | |
60 explicit ScaleFactorMatcher(Node* node) | |
61 : NodeMatcher(node), left_(NULL), power_(0) { | |
62 Match(); | |
63 } | |
64 | |
65 bool Matches() { return left_ != NULL; } | |
66 int Power() { | |
67 DCHECK(Matches()); | |
68 return power_; | |
69 } | |
70 Node* Left() { | |
71 DCHECK(Matches()); | |
72 return left_; | |
73 } | |
74 | |
75 private: | |
76 void Match() { | |
77 if (opcode() != IrOpcode::kInt32Mul) return; | |
78 Int32BinopMatcher m(node()); | |
79 if (!m.right().HasValue()) return; | |
80 int32_t value = m.right().Value(); | |
81 switch (value) { | |
82 case 8: | |
83 power_++; // Fall through. | |
84 case 4: | |
85 power_++; // Fall through. | |
86 case 2: | |
87 power_++; // Fall through. | |
88 case 1: | |
89 break; | |
90 default: | |
91 return; | |
92 } | |
93 left_ = m.left().node(); | |
94 } | |
95 | |
96 Node* left_; | |
97 int power_; | |
98 }; | |
99 | |
100 | |
101 // Matches nodes of form: | |
102 // [x * N] | |
103 // [x * N + K] | |
104 // [x + K] | |
105 // [x] -- fallback case | |
106 // for N in {1,2,4,8} and K int32_t | |
107 class IndexAndDisplacementMatcher : public NodeMatcher { | |
108 public: | |
109 explicit IndexAndDisplacementMatcher(Node* node) | |
110 : NodeMatcher(node), index_node_(node), displacement_(0), power_(0) { | |
111 Match(); | |
112 } | |
113 | |
114 Node* index_node() { return index_node_; } | |
115 int displacement() { return displacement_; } | |
116 int power() { return power_; } | |
117 | |
118 private: | |
119 void Match() { | |
120 if (opcode() == IrOpcode::kInt32Add) { | |
121 // Assume reduction has put constant on the right. | |
122 Int32BinopMatcher m(node()); | |
123 if (m.right().HasValue()) { | |
124 displacement_ = m.right().Value(); | |
125 index_node_ = m.left().node(); | |
126 } | |
127 } | |
128 // Test scale factor. | |
129 ScaleFactorMatcher scale_matcher(index_node_); | |
130 if (scale_matcher.Matches()) { | |
131 index_node_ = scale_matcher.Left(); | |
132 power_ = scale_matcher.Power(); | |
133 } | |
134 } | |
135 | |
136 Node* index_node_; | |
137 int displacement_; | |
138 int power_; | |
139 }; | |
140 | |
141 | |
142 class AddressingModeMatcher { | 57 class AddressingModeMatcher { |
143 public: | 58 public: |
144 AddressingModeMatcher(X64OperandGenerator* g, Node* base, Node* index) | 59 AddressingModeMatcher(X64OperandGenerator* g, Node* base, Node* index) |
145 : base_operand_(NULL), | 60 : base_operand_(NULL), |
146 index_operand_(NULL), | 61 index_operand_(NULL), |
147 displacement_operand_(NULL), | 62 displacement_operand_(NULL), |
148 mode_(kMode_None) { | 63 mode_(kMode_None) { |
149 Int32Matcher index_imm(index); | 64 Int32Matcher index_imm(index); |
150 if (index_imm.HasValue()) { | 65 if (index_imm.HasValue()) { |
151 int32_t value = index_imm.Value(); | 66 int32_t value = index_imm.Value(); |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 call_instr->MarkAsCall(); | 797 call_instr->MarkAsCall(); |
883 if (deoptimization != NULL) { | 798 if (deoptimization != NULL) { |
884 DCHECK(continuation != NULL); | 799 DCHECK(continuation != NULL); |
885 call_instr->MarkAsControl(); | 800 call_instr->MarkAsControl(); |
886 } | 801 } |
887 } | 802 } |
888 | 803 |
889 } // namespace compiler | 804 } // namespace compiler |
890 } // namespace internal | 805 } // namespace internal |
891 } // namespace v8 | 806 } // namespace v8 |
OLD | NEW |