OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/effect-control-linearizer.h" | 5 #include "src/compiler/effect-control-linearizer.h" |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/compiler/access-builder.h" | 8 #include "src/compiler/access-builder.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 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 } | 760 } |
761 NodeProperties::ReplaceUses(node, state.value, state.effect, state.control); | 761 NodeProperties::ReplaceUses(node, state.value, state.effect, state.control); |
762 *effect = state.effect; | 762 *effect = state.effect; |
763 *control = state.control; | 763 *control = state.control; |
764 return true; | 764 return true; |
765 } | 765 } |
766 | 766 |
767 EffectControlLinearizer::ValueEffectControl | 767 EffectControlLinearizer::ValueEffectControl |
768 EffectControlLinearizer::LowerChangeFloat64ToTagged(Node* node, Node* effect, | 768 EffectControlLinearizer::LowerChangeFloat64ToTagged(Node* node, Node* effect, |
769 Node* control) { | 769 Node* control) { |
| 770 CheckForMinusZeroMode mode = CheckMinusZeroModeOf(node->op()); |
770 Node* value = node->InputAt(0); | 771 Node* value = node->InputAt(0); |
771 return AllocateHeapNumberWithValue(value, effect, control); | 772 |
| 773 Node* value32 = graph()->NewNode(machine()->RoundFloat64ToInt32(), value); |
| 774 Node* check_same = graph()->NewNode( |
| 775 machine()->Float64Equal(), value, |
| 776 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value32)); |
| 777 Node* branch_same = graph()->NewNode(common()->Branch(), check_same, control); |
| 778 |
| 779 Node* if_smi = graph()->NewNode(common()->IfTrue(), branch_same); |
| 780 Node* vsmi; |
| 781 Node* if_box = graph()->NewNode(common()->IfFalse(), branch_same); |
| 782 |
| 783 if (mode == CheckForMinusZeroMode::kCheckForMinusZero) { |
| 784 // Check if {value} is -0. |
| 785 Node* check_zero = graph()->NewNode(machine()->Word32Equal(), value32, |
| 786 jsgraph()->Int32Constant(0)); |
| 787 Node* branch_zero = graph()->NewNode(common()->Branch(BranchHint::kFalse), |
| 788 check_zero, if_smi); |
| 789 |
| 790 Node* if_zero = graph()->NewNode(common()->IfTrue(), branch_zero); |
| 791 Node* if_notzero = graph()->NewNode(common()->IfFalse(), branch_zero); |
| 792 |
| 793 // In case of 0, we need to check the high bits for the IEEE -0 pattern. |
| 794 Node* check_negative = graph()->NewNode( |
| 795 machine()->Int32LessThan(), |
| 796 graph()->NewNode(machine()->Float64ExtractHighWord32(), value), |
| 797 jsgraph()->Int32Constant(0)); |
| 798 Node* branch_negative = graph()->NewNode( |
| 799 common()->Branch(BranchHint::kFalse), check_negative, if_zero); |
| 800 |
| 801 Node* if_negative = graph()->NewNode(common()->IfTrue(), branch_negative); |
| 802 Node* if_notnegative = |
| 803 graph()->NewNode(common()->IfFalse(), branch_negative); |
| 804 |
| 805 // We need to create a box for negative 0. |
| 806 if_smi = graph()->NewNode(common()->Merge(2), if_notzero, if_notnegative); |
| 807 if_box = graph()->NewNode(common()->Merge(2), if_box, if_negative); |
| 808 } |
| 809 |
| 810 // On 64-bit machines we can just wrap the 32-bit integer in a smi, for 32-bit |
| 811 // machines we need to deal with potential overflow and fallback to boxing. |
| 812 if (machine()->Is64()) { |
| 813 vsmi = ChangeInt32ToSmi(value32); |
| 814 } else { |
| 815 Node* smi_tag = graph()->NewNode(machine()->Int32AddWithOverflow(), value32, |
| 816 value32, if_smi); |
| 817 |
| 818 Node* check_ovf = |
| 819 graph()->NewNode(common()->Projection(1), smi_tag, if_smi); |
| 820 Node* branch_ovf = graph()->NewNode(common()->Branch(BranchHint::kFalse), |
| 821 check_ovf, if_smi); |
| 822 |
| 823 Node* if_ovf = graph()->NewNode(common()->IfTrue(), branch_ovf); |
| 824 if_box = graph()->NewNode(common()->Merge(2), if_ovf, if_box); |
| 825 |
| 826 if_smi = graph()->NewNode(common()->IfFalse(), branch_ovf); |
| 827 vsmi = graph()->NewNode(common()->Projection(0), smi_tag, if_smi); |
| 828 } |
| 829 |
| 830 // Allocate the box for the {value}. |
| 831 ValueEffectControl box = AllocateHeapNumberWithValue(value, effect, if_box); |
| 832 |
| 833 control = graph()->NewNode(common()->Merge(2), if_smi, box.control); |
| 834 value = graph()->NewNode(common()->Phi(MachineRepresentation::kTagged, 2), |
| 835 vsmi, box.value, control); |
| 836 effect = |
| 837 graph()->NewNode(common()->EffectPhi(2), effect, box.effect, control); |
| 838 return ValueEffectControl(value, effect, control); |
772 } | 839 } |
773 | 840 |
774 EffectControlLinearizer::ValueEffectControl | 841 EffectControlLinearizer::ValueEffectControl |
775 EffectControlLinearizer::LowerChangeBitToTagged(Node* node, Node* effect, | 842 EffectControlLinearizer::LowerChangeBitToTagged(Node* node, Node* effect, |
776 Node* control) { | 843 Node* control) { |
777 Node* value = node->InputAt(0); | 844 Node* value = node->InputAt(0); |
778 | 845 |
779 Node* branch = graph()->NewNode(common()->Branch(), value, control); | 846 Node* branch = graph()->NewNode(common()->Branch(), value, control); |
780 | 847 |
781 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 848 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
(...skipping 2612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3394 isolate(), graph()->zone(), callable.descriptor(), 0, flags, | 3461 isolate(), graph()->zone(), callable.descriptor(), 0, flags, |
3395 Operator::kEliminatable); | 3462 Operator::kEliminatable); |
3396 to_number_operator_.set(common()->Call(desc)); | 3463 to_number_operator_.set(common()->Call(desc)); |
3397 } | 3464 } |
3398 return to_number_operator_.get(); | 3465 return to_number_operator_.get(); |
3399 } | 3466 } |
3400 | 3467 |
3401 } // namespace compiler | 3468 } // namespace compiler |
3402 } // namespace internal | 3469 } // namespace internal |
3403 } // namespace v8 | 3470 } // namespace v8 |
OLD | NEW |