| 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 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 614 |
| 615 Node* ChangeLowering::LoadMapInstanceType(Node* map) { | 615 Node* ChangeLowering::LoadMapInstanceType(Node* map) { |
| 616 return graph()->NewNode( | 616 return graph()->NewNode( |
| 617 machine()->Load(MachineType::Uint8()), map, | 617 machine()->Load(MachineType::Uint8()), map, |
| 618 jsgraph()->IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag), | 618 jsgraph()->IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag), |
| 619 graph()->start(), graph()->start()); | 619 graph()->start(), graph()->start()); |
| 620 } | 620 } |
| 621 | 621 |
| 622 Reduction ChangeLowering::ObjectIsNumber(Node* node) { | 622 Reduction ChangeLowering::ObjectIsNumber(Node* node) { |
| 623 Node* input = NodeProperties::GetValueInput(node, 0); | 623 Node* input = NodeProperties::GetValueInput(node, 0); |
| 624 Type* input_type = NodeProperties::GetType(input); | 624 // TODO(bmeurer): Optimize somewhat based on input type. |
| 625 if (input_type->Is(Type::TaggedPointer())) { | 625 Node* check = IsSmi(input); |
| 626 node->ReplaceInput(0, LoadHeapObjectMap(input, graph()->start())); | 626 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
| 627 node->AppendInput( | 627 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 628 graph()->zone(), | 628 Node* vtrue = jsgraph()->Int32Constant(1); |
| 629 jsgraph()->HeapConstant(isolate()->factory()->heap_number_map())); | 629 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 630 NodeProperties::ChangeOp(node, machine()->WordEqual()); | 630 Node* vfalse = graph()->NewNode( |
| 631 } else { | 631 machine()->WordEqual(), LoadHeapObjectMap(input, if_false), |
| 632 Node* check = IsSmi(input); | 632 jsgraph()->HeapConstant(isolate()->factory()->heap_number_map())); |
| 633 Node* branch = | 633 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 634 graph()->NewNode(common()->Branch(), check, graph()->start()); | 634 node->ReplaceInput(0, vtrue); |
| 635 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 635 node->AppendInput(graph()->zone(), vfalse); |
| 636 Node* vtrue = jsgraph()->Int32Constant(1); | 636 node->AppendInput(graph()->zone(), control); |
| 637 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 637 NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); |
| 638 Node* vfalse = graph()->NewNode( | |
| 639 machine()->WordEqual(), LoadHeapObjectMap(input, if_false), | |
| 640 jsgraph()->HeapConstant(isolate()->factory()->heap_number_map())); | |
| 641 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); | |
| 642 node->ReplaceInput(0, vtrue); | |
| 643 node->AppendInput(graph()->zone(), vfalse); | |
| 644 node->AppendInput(graph()->zone(), control); | |
| 645 NodeProperties::ChangeOp(node, | |
| 646 common()->Phi(MachineRepresentation::kBit, 2)); | |
| 647 } | |
| 648 return Changed(node); | 638 return Changed(node); |
| 649 } | 639 } |
| 650 | 640 |
| 651 Reduction ChangeLowering::ObjectIsReceiver(Node* node) { | 641 Reduction ChangeLowering::ObjectIsReceiver(Node* node) { |
| 642 Node* input = NodeProperties::GetValueInput(node, 0); |
| 643 // TODO(bmeurer): Optimize somewhat based on input type. |
| 652 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); | 644 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
| 653 Node* input = NodeProperties::GetValueInput(node, 0); | 645 Node* check = IsSmi(input); |
| 654 Type* input_type = NodeProperties::GetType(input); | 646 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
| 655 if (input_type->Is(Type::TaggedPointer())) { | 647 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 656 node->ReplaceInput(0, jsgraph()->Uint32Constant(FIRST_JS_RECEIVER_TYPE)); | 648 Node* vtrue = jsgraph()->Int32Constant(0); |
| 657 node->AppendInput(graph()->zone(), LoadMapInstanceType(LoadHeapObjectMap( | 649 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 658 input, graph()->start()))); | 650 Node* vfalse = |
| 659 NodeProperties::ChangeOp(node, machine()->Uint32LessThanOrEqual()); | 651 graph()->NewNode(machine()->Uint32LessThanOrEqual(), |
| 660 } else { | 652 jsgraph()->Uint32Constant(FIRST_JS_RECEIVER_TYPE), |
| 661 Node* check = IsSmi(input); | 653 LoadMapInstanceType(LoadHeapObjectMap(input, if_false))); |
| 662 Node* branch = | 654 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 663 graph()->NewNode(common()->Branch(), check, graph()->start()); | 655 node->ReplaceInput(0, vtrue); |
| 664 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 656 node->AppendInput(graph()->zone(), vfalse); |
| 665 Node* vtrue = jsgraph()->Int32Constant(0); | 657 node->AppendInput(graph()->zone(), control); |
| 666 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 658 NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); |
| 667 Node* vfalse = graph()->NewNode( | |
| 668 machine()->Uint32LessThanOrEqual(), | |
| 669 jsgraph()->Uint32Constant(FIRST_JS_RECEIVER_TYPE), | |
| 670 LoadMapInstanceType(LoadHeapObjectMap(input, if_false))); | |
| 671 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); | |
| 672 node->ReplaceInput(0, vtrue); | |
| 673 node->AppendInput(graph()->zone(), vfalse); | |
| 674 node->AppendInput(graph()->zone(), control); | |
| 675 NodeProperties::ChangeOp(node, | |
| 676 common()->Phi(MachineRepresentation::kBit, 2)); | |
| 677 } | |
| 678 return Changed(node); | 659 return Changed(node); |
| 679 } | 660 } |
| 680 | 661 |
| 681 Reduction ChangeLowering::ObjectIsUndetectable(Node* node) { | 662 Reduction ChangeLowering::ObjectIsUndetectable(Node* node) { |
| 682 Node* input = NodeProperties::GetValueInput(node, 0); | 663 Node* input = NodeProperties::GetValueInput(node, 0); |
| 683 Type* input_type = NodeProperties::GetType(input); | 664 // TODO(bmeurer): Optimize somewhat based on input type. |
| 684 if (input_type->Is(Type::TaggedPointer())) { | 665 Node* check = IsSmi(input); |
| 685 node->ReplaceInput( | 666 Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
| 686 0, graph()->NewNode( | 667 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 687 machine()->Word32Equal(), | 668 Node* vtrue = jsgraph()->Int32Constant(0); |
| 688 graph()->NewNode( | 669 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 689 machine()->Word32And(), | 670 Node* vfalse = graph()->NewNode( |
| 690 jsgraph()->Uint32Constant(1 << Map::kIsUndetectable), | 671 machine()->Word32Equal(), |
| 691 LoadMapBitField(LoadHeapObjectMap(input, graph()->start()))), | 672 graph()->NewNode( |
| 692 jsgraph()->Int32Constant(0))); | 673 machine()->Word32Equal(), |
| 693 node->AppendInput(graph()->zone(), jsgraph()->Int32Constant(0)); | 674 graph()->NewNode(machine()->Word32And(), |
| 694 NodeProperties::ChangeOp(node, machine()->Word32Equal()); | 675 jsgraph()->Uint32Constant(1 << Map::kIsUndetectable), |
| 695 } else { | 676 LoadMapBitField(LoadHeapObjectMap(input, if_false))), |
| 696 Node* check = IsSmi(input); | 677 jsgraph()->Int32Constant(0)), |
| 697 Node* branch = | 678 jsgraph()->Int32Constant(0)); |
| 698 graph()->NewNode(common()->Branch(), check, graph()->start()); | 679 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 699 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 680 node->ReplaceInput(0, vtrue); |
| 700 Node* vtrue = jsgraph()->Int32Constant(0); | 681 node->AppendInput(graph()->zone(), vfalse); |
| 701 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 682 node->AppendInput(graph()->zone(), control); |
| 702 Node* vfalse = graph()->NewNode( | 683 NodeProperties::ChangeOp(node, common()->Phi(MachineRepresentation::kBit, 2)); |
| 703 machine()->Word32Equal(), | |
| 704 graph()->NewNode( | |
| 705 machine()->Word32Equal(), | |
| 706 graph()->NewNode( | |
| 707 machine()->Word32And(), | |
| 708 jsgraph()->Uint32Constant(1 << Map::kIsUndetectable), | |
| 709 LoadMapBitField(LoadHeapObjectMap(input, if_false))), | |
| 710 jsgraph()->Int32Constant(0)), | |
| 711 jsgraph()->Int32Constant(0)); | |
| 712 Node* control = graph()->NewNode(common()->Merge(2), if_true, if_false); | |
| 713 node->ReplaceInput(0, vtrue); | |
| 714 node->AppendInput(graph()->zone(), vfalse); | |
| 715 node->AppendInput(graph()->zone(), control); | |
| 716 NodeProperties::ChangeOp(node, | |
| 717 common()->Phi(MachineRepresentation::kBit, 2)); | |
| 718 } | |
| 719 return Changed(node); | 684 return Changed(node); |
| 720 } | 685 } |
| 721 | 686 |
| 722 Reduction ChangeLowering::ObjectIsSmi(Node* node) { | 687 Reduction ChangeLowering::ObjectIsSmi(Node* node) { |
| 723 node->ReplaceInput(0, | 688 node->ReplaceInput(0, |
| 724 graph()->NewNode(machine()->WordAnd(), node->InputAt(0), | 689 graph()->NewNode(machine()->WordAnd(), node->InputAt(0), |
| 725 jsgraph()->IntPtrConstant(kSmiTagMask))); | 690 jsgraph()->IntPtrConstant(kSmiTagMask))); |
| 726 node->AppendInput(graph()->zone(), jsgraph()->IntPtrConstant(kSmiTag)); | 691 node->AppendInput(graph()->zone(), jsgraph()->IntPtrConstant(kSmiTag)); |
| 727 NodeProperties::ChangeOp(node, machine()->WordEqual()); | 692 NodeProperties::ChangeOp(node, machine()->WordEqual()); |
| 728 return Changed(node); | 693 return Changed(node); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 739 } | 704 } |
| 740 | 705 |
| 741 | 706 |
| 742 MachineOperatorBuilder* ChangeLowering::machine() const { | 707 MachineOperatorBuilder* ChangeLowering::machine() const { |
| 743 return jsgraph()->machine(); | 708 return jsgraph()->machine(); |
| 744 } | 709 } |
| 745 | 710 |
| 746 } // namespace compiler | 711 } // namespace compiler |
| 747 } // namespace internal | 712 } // namespace internal |
| 748 } // namespace v8 | 713 } // namespace v8 |
| OLD | NEW |