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/change-lowering.h" | 5 #include "src/compiler/change-lowering.h" |
6 | 6 |
7 #include "src/address-map.h" | 7 #include "src/address-map.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 } | 589 } |
590 | 590 |
591 Node* ChangeLowering::IsSmi(Node* value) { | 591 Node* ChangeLowering::IsSmi(Node* value) { |
592 return graph()->NewNode( | 592 return graph()->NewNode( |
593 machine()->WordEqual(), | 593 machine()->WordEqual(), |
594 graph()->NewNode(machine()->WordAnd(), value, | 594 graph()->NewNode(machine()->WordAnd(), value, |
595 jsgraph()->IntPtrConstant(kSmiTagMask)), | 595 jsgraph()->IntPtrConstant(kSmiTagMask)), |
596 jsgraph()->IntPtrConstant(kSmiTag)); | 596 jsgraph()->IntPtrConstant(kSmiTag)); |
597 } | 597 } |
598 | 598 |
599 Node* ChangeLowering::LoadHeapObjectMap(Node* object, Node* control) { | 599 Node* ChangeLowering::LoadHeapObjectMap(Node* object, Node* effect, |
| 600 Node* control) { |
600 return graph()->NewNode( | 601 return graph()->NewNode( |
601 machine()->Load(MachineType::AnyTagged()), object, | 602 machine()->Load(MachineType::AnyTagged()), object, |
602 jsgraph()->IntPtrConstant(HeapObject::kMapOffset - kHeapObjectTag), | 603 jsgraph()->IntPtrConstant(HeapObject::kMapOffset - kHeapObjectTag), |
603 graph()->start(), control); | 604 effect, control); |
604 } | 605 } |
605 | 606 |
606 Node* ChangeLowering::LoadMapInstanceType(Node* map) { | 607 Node* ChangeLowering::LoadMapInstanceType(Node* map, Node* effect, |
| 608 Node* control) { |
607 return graph()->NewNode( | 609 return graph()->NewNode( |
608 machine()->Load(MachineType::Uint8()), map, | 610 machine()->Load(MachineType::Uint8()), map, |
609 jsgraph()->IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag), | 611 jsgraph()->IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag), |
610 graph()->start(), graph()->start()); | 612 effect, control); |
611 } | 613 } |
612 | 614 |
613 Reduction ChangeLowering::ObjectIsNumber(Node* node) { | 615 Reduction ChangeLowering::ObjectIsNumber(Node* node) { |
614 Node* input = NodeProperties::GetValueInput(node, 0); | 616 Node* input = NodeProperties::GetValueInput(node, 0); |
| 617 Node* control = NodeProperties::GetControlInput(node, 0); |
| 618 Node* effect = NodeProperties::GetEffectInput(node, 0); |
615 // TODO(bmeurer): Optimize somewhat based on input type. | 619 // TODO(bmeurer): Optimize somewhat based on input type. |
616 Node* check = IsSmi(input); | 620 Node* check = IsSmi(input); |
617 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 621 Node* branch = graph()->NewNode(common()->Branch(), check, control); |
618 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 622 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
619 Node* vtrue = jsgraph()->Int32Constant(1); | 623 Node* vtrue = jsgraph()->Int32Constant(1); |
620 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 624 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 625 Node* load_map = LoadHeapObjectMap(input, effect, if_false); |
621 Node* vfalse = graph()->NewNode( | 626 Node* vfalse = graph()->NewNode( |
622 machine()->WordEqual(), LoadHeapObjectMap(input, if_false), | 627 machine()->WordEqual(), load_map, |
623 jsgraph()->HeapConstant(isolate()->factory()->heap_number_map())); | 628 jsgraph()->HeapConstant(isolate()->factory()->heap_number_map())); |
624 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); | 629 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
625 node->ReplaceInput(0, vtrue); | 630 Node* ephi = |
626 node->AppendInput(graph()->zone(), vfalse); | 631 graph()->NewNode(common()->EffectPhi(2), effect, load_map, merge); |
627 node->AppendInput(graph()->zone(), control); | 632 Node* phi = graph()->NewNode(common()->Phi(MachineRepresentation::kBit, 2), |
628 NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); | 633 vtrue, vfalse, merge); |
| 634 ReplaceWithValue(node, phi, ephi, merge); |
629 return Changed(node); | 635 return Changed(node); |
630 } | 636 } |
631 | 637 |
632 Reduction ChangeLowering::ObjectIsReceiver(Node* node) { | 638 Reduction ChangeLowering::ObjectIsReceiver(Node* node) { |
633 Node* input = NodeProperties::GetValueInput(node, 0); | 639 Node* input = NodeProperties::GetValueInput(node, 0); |
634 // TODO(bmeurer): Optimize somewhat based on input type. | 640 // TODO(bmeurer): Optimize somewhat based on input type. |
635 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); | 641 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
636 Node* check = IsSmi(input); | 642 Node* check = IsSmi(input); |
637 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); | 643 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
638 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 644 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
639 Node* vtrue = jsgraph()->Int32Constant(0); | 645 Node* vtrue = jsgraph()->Int32Constant(0); |
640 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 646 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
641 Node* vfalse = | 647 Node* load_map = LoadHeapObjectMap(input, graph()->start(), if_false); |
642 graph()->NewNode(machine()->Uint32LessThanOrEqual(), | 648 Node* load_instance_type = |
643 jsgraph()->Uint32Constant(FIRST_JS_RECEIVER_TYPE), | 649 LoadMapInstanceType(load_map, graph()->start(), graph()->start()); |
644 LoadMapInstanceType(LoadHeapObjectMap(input, if_false))); | 650 Node* vfalse = graph()->NewNode( |
| 651 machine()->Uint32LessThanOrEqual(), |
| 652 jsgraph()->Uint32Constant(FIRST_JS_RECEIVER_TYPE), load_instance_type); |
645 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); | 653 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
646 node->ReplaceInput(0, vtrue); | 654 node->ReplaceInput(0, vtrue); |
647 node->AppendInput(graph()->zone(), vfalse); | 655 node->AppendInput(graph()->zone(), vfalse); |
648 node->AppendInput(graph()->zone(), control); | 656 node->AppendInput(graph()->zone(), control); |
649 NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); | 657 NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); |
650 return Changed(node); | 658 return Changed(node); |
651 } | 659 } |
652 | 660 |
653 Reduction ChangeLowering::ObjectIsSmi(Node* node) { | 661 Reduction ChangeLowering::ObjectIsSmi(Node* node) { |
654 node->ReplaceInput(0, | 662 node->ReplaceInput(0, |
(...skipping 15 matching lines...) Expand all Loading... |
670 } | 678 } |
671 | 679 |
672 | 680 |
673 MachineOperatorBuilder* ChangeLowering::machine() const { | 681 MachineOperatorBuilder* ChangeLowering::machine() const { |
674 return jsgraph()->machine(); | 682 return jsgraph()->machine(); |
675 } | 683 } |
676 | 684 |
677 } // namespace compiler | 685 } // namespace compiler |
678 } // namespace internal | 686 } // namespace internal |
679 } // namespace v8 | 687 } // namespace v8 |
OLD | NEW |