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/access-builder.h" | 5 #include "src/compiler/access-builder.h" |
6 #include "src/compiler/graph-inl.h" | 6 #include "src/compiler/graph-inl.h" |
7 #include "src/compiler/js-builtin-reducer.h" | 7 #include "src/compiler/js-builtin-reducer.h" |
8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" |
9 #include "src/compiler/node-aux-data-inl.h" | 9 #include "src/compiler/node-aux-data-inl.h" |
10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 Node* ConvertToNumber(Node* node) { | 172 Node* ConvertToNumber(Node* node) { |
173 // Avoid introducing too many eager ToNumber() operations. | 173 // Avoid introducing too many eager ToNumber() operations. |
174 Reduction reduced = lowering_->ReduceJSToNumberInput(node); | 174 Reduction reduced = lowering_->ReduceJSToNumberInput(node); |
175 if (reduced.Changed()) return reduced.replacement(); | 175 if (reduced.Changed()) return reduced.replacement(); |
176 Node* n = graph()->NewNode(javascript()->ToNumber(), node, context(), | 176 Node* n = graph()->NewNode(javascript()->ToNumber(), node, context(), |
177 effect(), control()); | 177 effect(), control()); |
178 update_effect(n); | 178 update_effect(n); |
179 return n; | 179 return n; |
180 } | 180 } |
181 | 181 |
182 // Try narrowing a double or number operation to an Int32 operation. | |
183 bool TryNarrowingToI32(Type* type, Node* node) { | |
184 switch (node->opcode()) { | |
185 case IrOpcode::kFloat64Add: | |
186 case IrOpcode::kNumberAdd: { | |
187 JSBinopReduction r(lowering_, node); | |
188 if (r.BothInputsAre(Type::Integral32())) { | |
189 node->set_op(lowering_->machine()->Int32Add()); | |
190 // TODO(titzer): narrow bounds instead of overwriting. | |
191 NodeProperties::SetBounds(node, Bounds(type)); | |
192 return true; | |
193 } | |
194 } | |
195 case IrOpcode::kFloat64Sub: | |
196 case IrOpcode::kNumberSubtract: { | |
197 JSBinopReduction r(lowering_, node); | |
198 if (r.BothInputsAre(Type::Integral32())) { | |
199 node->set_op(lowering_->machine()->Int32Sub()); | |
200 // TODO(titzer): narrow bounds instead of overwriting. | |
201 NodeProperties::SetBounds(node, Bounds(type)); | |
202 return true; | |
203 } | |
204 } | |
205 default: | |
206 return false; | |
207 } | |
208 } | |
209 | |
210 Node* ConvertToI32(bool is_signed, Node* node) { | 182 Node* ConvertToI32(bool is_signed, Node* node) { |
211 Type* type = is_signed ? Type::Signed32() : Type::Unsigned32(); | |
212 if (node->OwnedBy(node_)) { | |
213 // If this node {node_} has the only edge to {node}, then try narrowing | |
214 // its operation to an Int32 add or subtract. | |
215 if (TryNarrowingToI32(type, node)) return node; | |
216 } else { | |
217 // Otherwise, {node} has multiple uses. Leave it as is and let the | |
218 // further lowering passes deal with it, which use a full backwards | |
219 // fixpoint. | |
220 } | |
221 | |
222 // Avoid introducing too many eager NumberToXXnt32() operations. | 183 // Avoid introducing too many eager NumberToXXnt32() operations. |
223 node = ConvertToNumber(node); | 184 node = ConvertToNumber(node); |
| 185 Type* type = is_signed ? Type::Signed32() : Type::Unsigned32(); |
224 Type* input_type = NodeProperties::GetBounds(node).upper; | 186 Type* input_type = NodeProperties::GetBounds(node).upper; |
225 | 187 |
226 if (input_type->Is(type)) return node; // already in the value range. | 188 if (input_type->Is(type)) return node; // already in the value range. |
227 | 189 |
228 const Operator* op = is_signed ? simplified()->NumberToInt32() | 190 const Operator* op = is_signed ? simplified()->NumberToInt32() |
229 : simplified()->NumberToUint32(); | 191 : simplified()->NumberToUint32(); |
230 Node* n = graph()->NewNode(op, node); | 192 Node* n = graph()->NewNode(op, node); |
231 return n; | 193 return n; |
232 } | 194 } |
233 | 195 |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 return JSBuiltinReducer(jsgraph()).Reduce(node); | 762 return JSBuiltinReducer(jsgraph()).Reduce(node); |
801 default: | 763 default: |
802 break; | 764 break; |
803 } | 765 } |
804 return NoChange(); | 766 return NoChange(); |
805 } | 767 } |
806 | 768 |
807 } // namespace compiler | 769 } // namespace compiler |
808 } // namespace internal | 770 } // namespace internal |
809 } // namespace v8 | 771 } // namespace v8 |
OLD | NEW |