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-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 | 521 |
522 Reduction JSTypedLowering::ReduceJSToNumber(Node* node) { | 522 Reduction JSTypedLowering::ReduceJSToNumber(Node* node) { |
523 // Try to reduce the input first. | 523 // Try to reduce the input first. |
524 Node* const input = node->InputAt(0); | 524 Node* const input = node->InputAt(0); |
525 Reduction reduction = ReduceJSToNumberInput(input); | 525 Reduction reduction = ReduceJSToNumberInput(input); |
526 if (reduction.Changed()) { | 526 if (reduction.Changed()) { |
527 NodeProperties::ReplaceWithValue(node, reduction.replacement()); | 527 NodeProperties::ReplaceWithValue(node, reduction.replacement()); |
528 return reduction; | 528 return reduction; |
529 } | 529 } |
530 Type* const input_type = NodeProperties::GetBounds(input).upper; | 530 Type* const input_type = NodeProperties::GetBounds(input).upper; |
531 if (input->opcode() == IrOpcode::kPhi && input_type->Is(Type::Primitive())) { | 531 if (input_type->Is(Type::PlainPrimitive())) { |
532 Node* const context = node->InputAt(1); | 532 // Converting a plain primitive to a number has no observable side effects. |
533 // JSToNumber(phi(x1,...,xn,control):primitive) | |
534 // => phi(JSToNumber(x1),...,JSToNumber(xn),control):number | |
535 RelaxEffects(node); | 533 RelaxEffects(node); |
536 int const input_count = input->InputCount() - 1; | 534 // JSToNumber(phi(x1,...,xn,control):plain-primitive,context) |
537 Node* const control = input->InputAt(input_count); | 535 // => phi(JSToNumber(x1,no-context),...,JSToNumber(xn,no-context),control) |
538 DCHECK_LE(0, input_count); | 536 if (input->opcode() == IrOpcode::kPhi) { |
539 DCHECK(NodeProperties::IsControl(control)); | 537 int const input_count = input->InputCount() - 1; |
540 DCHECK(NodeProperties::GetBounds(node).upper->Is(Type::Number())); | 538 Node* const control = input->InputAt(input_count); |
541 DCHECK(!NodeProperties::GetBounds(input).upper->Is(Type::Number())); | 539 DCHECK_LE(0, input_count); |
542 node->set_op(common()->Phi(kMachAnyTagged, input_count)); | 540 DCHECK(NodeProperties::IsControl(control)); |
543 for (int i = 0; i < input_count; ++i) { | 541 DCHECK(NodeProperties::GetBounds(node).upper->Is(Type::Number())); |
544 Node* value = input->InputAt(i); | 542 DCHECK(!NodeProperties::GetBounds(input).upper->Is(Type::Number())); |
545 // Recursively try to reduce the value first. | 543 node->set_op(common()->Phi(kMachAnyTagged, input_count)); |
546 Reduction reduction = ReduceJSToNumberInput(value); | 544 for (int i = 0; i < input_count; ++i) { |
547 if (reduction.Changed()) { | 545 Node* value = input->InputAt(i); |
548 value = reduction.replacement(); | 546 // Recursively try to reduce the value first. |
| 547 Reduction reduction = ReduceJSToNumberInput(value); |
| 548 if (reduction.Changed()) { |
| 549 value = reduction.replacement(); |
| 550 } else { |
| 551 value = graph()->NewNode(javascript()->ToNumber(), value, |
| 552 jsgraph()->NoContextConstant(), |
| 553 graph()->start(), graph()->start()); |
| 554 } |
| 555 if (i < node->InputCount()) { |
| 556 node->ReplaceInput(i, value); |
| 557 } else { |
| 558 node->AppendInput(graph()->zone(), value); |
| 559 } |
| 560 } |
| 561 if (input_count < node->InputCount()) { |
| 562 node->ReplaceInput(input_count, control); |
549 } else { | 563 } else { |
550 value = graph()->NewNode(javascript()->ToNumber(), value, context, | 564 node->AppendInput(graph()->zone(), control); |
551 graph()->start(), graph()->start()); | |
552 } | 565 } |
553 if (i < node->InputCount()) { | 566 node->TrimInputCount(input_count + 1); |
554 node->ReplaceInput(i, value); | |
555 } else { | |
556 node->AppendInput(graph()->zone(), value); | |
557 } | |
558 } | 567 } |
559 if (input_count < node->InputCount()) { | |
560 node->ReplaceInput(input_count, control); | |
561 } else { | |
562 node->AppendInput(graph()->zone(), control); | |
563 } | |
564 node->TrimInputCount(input_count + 1); | |
565 return Changed(node); | 568 return Changed(node); |
566 } | 569 } |
567 return NoChange(); | 570 return NoChange(); |
568 } | 571 } |
569 | 572 |
570 | 573 |
571 Reduction JSTypedLowering::ReduceJSToStringInput(Node* input) { | 574 Reduction JSTypedLowering::ReduceJSToStringInput(Node* input) { |
572 if (input->opcode() == IrOpcode::kJSToString) { | 575 if (input->opcode() == IrOpcode::kJSToString) { |
573 // Recursively try to reduce the input first. | 576 // Recursively try to reduce the input first. |
574 Reduction result = ReduceJSToStringInput(input->InputAt(0)); | 577 Reduction result = ReduceJSToStringInput(input->InputAt(0)); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 | 984 |
982 Node* JSTypedLowering::Word32Shl(Node* const lhs, int32_t const rhs) { | 985 Node* JSTypedLowering::Word32Shl(Node* const lhs, int32_t const rhs) { |
983 if (rhs == 0) return lhs; | 986 if (rhs == 0) return lhs; |
984 return graph()->NewNode(machine()->Word32Shl(), lhs, | 987 return graph()->NewNode(machine()->Word32Shl(), lhs, |
985 jsgraph()->Int32Constant(rhs)); | 988 jsgraph()->Int32Constant(rhs)); |
986 } | 989 } |
987 | 990 |
988 } // namespace compiler | 991 } // namespace compiler |
989 } // namespace internal | 992 } // namespace internal |
990 } // namespace v8 | 993 } // namespace v8 |
OLD | NEW |