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/js-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/node-matchers.h" | 7 #include "src/compiler/node-matchers.h" |
8 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
9 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 return NoChange(); | 346 return NoChange(); |
347 } | 347 } |
348 | 348 |
349 // ES6 section 20.2.2.24 Math.max ( value1, value2, ...values ) | 349 // ES6 section 20.2.2.24 Math.max ( value1, value2, ...values ) |
350 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { | 350 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { |
351 JSCallReduction r(node); | 351 JSCallReduction r(node); |
352 if (r.InputsMatchZero()) { | 352 if (r.InputsMatchZero()) { |
353 // Math.max() -> -Infinity | 353 // Math.max() -> -Infinity |
354 return Replace(jsgraph()->Constant(-V8_INFINITY)); | 354 return Replace(jsgraph()->Constant(-V8_INFINITY)); |
355 } | 355 } |
356 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 356 if (r.InputsMatchAll(Type::PlainPrimitive())) { |
357 // Math.max(a:plain-primitive) -> ToNumber(a) | 357 // Math.max(a:plain-primitive, b:plain-primitive, ...) |
358 Node* value = ToNumber(r.GetJSCallInput(0)); | 358 Node* value = ToNumber(r.GetJSCallInput(0)); |
359 return Replace(value); | |
360 } | |
361 if (r.InputsMatchAll(Type::Integral32())) { | |
362 // Math.max(a:int32, b:int32, ...) | |
363 Node* value = r.GetJSCallInput(0); | |
364 for (int i = 1; i < r.GetJSCallArity(); i++) { | 359 for (int i = 1; i < r.GetJSCallArity(); i++) { |
365 Node* const input = r.GetJSCallInput(i); | 360 Node* input = ToNumber(r.GetJSCallInput(i)); |
366 value = graph()->NewNode( | 361 value = graph()->NewNode(simplified()->NumberMax(), value, input); |
367 common()->Select(MachineRepresentation::kNone), | |
368 graph()->NewNode(simplified()->NumberLessThan(), input, value), value, | |
369 input); | |
370 } | 362 } |
371 return Replace(value); | 363 return Replace(value); |
372 } | 364 } |
373 return NoChange(); | 365 return NoChange(); |
374 } | 366 } |
375 | 367 |
376 // ES6 section 20.2.2.25 Math.min ( value1, value2, ...values ) | 368 // ES6 section 20.2.2.25 Math.min ( value1, value2, ...values ) |
377 Reduction JSBuiltinReducer::ReduceMathMin(Node* node) { | 369 Reduction JSBuiltinReducer::ReduceMathMin(Node* node) { |
378 JSCallReduction r(node); | 370 JSCallReduction r(node); |
379 if (r.InputsMatchZero()) { | 371 if (r.InputsMatchZero()) { |
380 // Math.min() -> Infinity | 372 // Math.min() -> Infinity |
381 return Replace(jsgraph()->Constant(V8_INFINITY)); | 373 return Replace(jsgraph()->Constant(V8_INFINITY)); |
382 } | 374 } |
383 if (r.InputsMatchOne(Type::PlainPrimitive())) { | 375 if (r.InputsMatchAll(Type::PlainPrimitive())) { |
384 // Math.min(a:plain-primitive) -> ToNumber(a) | 376 // Math.min(a:plain-primitive, b:plain-primitive, ...) |
385 Node* value = ToNumber(r.GetJSCallInput(0)); | 377 Node* value = ToNumber(r.GetJSCallInput(0)); |
386 return Replace(value); | |
387 } | |
388 if (r.InputsMatchAll(Type::Integral32())) { | |
389 // Math.min(a:int32, b:int32, ...) | |
390 Node* value = r.GetJSCallInput(0); | |
391 for (int i = 1; i < r.GetJSCallArity(); i++) { | 378 for (int i = 1; i < r.GetJSCallArity(); i++) { |
392 Node* const input = r.GetJSCallInput(i); | 379 Node* input = ToNumber(r.GetJSCallInput(i)); |
393 value = graph()->NewNode( | 380 value = graph()->NewNode(simplified()->NumberMin(), value, input); |
394 common()->Select(MachineRepresentation::kNone), | |
395 graph()->NewNode(simplified()->NumberLessThan(), input, value), input, | |
396 value); | |
397 } | 381 } |
398 return Replace(value); | 382 return Replace(value); |
399 } | 383 } |
400 return NoChange(); | 384 return NoChange(); |
401 } | 385 } |
402 | 386 |
403 // ES6 section 20.2.2.26 Math.pow ( x, y ) | 387 // ES6 section 20.2.2.26 Math.pow ( x, y ) |
404 Reduction JSBuiltinReducer::ReduceMathPow(Node* node) { | 388 Reduction JSBuiltinReducer::ReduceMathPow(Node* node) { |
405 JSCallReduction r(node); | 389 JSCallReduction r(node); |
406 if (r.InputsMatchTwo(Type::PlainPrimitive(), Type::PlainPrimitive())) { | 390 if (r.InputsMatchTwo(Type::PlainPrimitive(), Type::PlainPrimitive())) { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 } | 681 } |
698 | 682 |
699 | 683 |
700 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { | 684 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { |
701 return jsgraph()->simplified(); | 685 return jsgraph()->simplified(); |
702 } | 686 } |
703 | 687 |
704 } // namespace compiler | 688 } // namespace compiler |
705 } // namespace internal | 689 } // namespace internal |
706 } // namespace v8 | 690 } // namespace v8 |
OLD | NEW |