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