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 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 Node* is_safe = | 1525 Node* is_safe = |
1526 graph()->NewNode(machine()->Uint32LessThanOrEqual(), value, max_int); | 1526 graph()->NewNode(machine()->Uint32LessThanOrEqual(), value, max_int); |
1527 control = effect = graph()->NewNode( | 1527 control = effect = graph()->NewNode( |
1528 common()->DeoptimizeUnless(DeoptimizeReason::kLostPrecision), is_safe, | 1528 common()->DeoptimizeUnless(DeoptimizeReason::kLostPrecision), is_safe, |
1529 frame_state, effect, control); | 1529 frame_state, effect, control); |
1530 | 1530 |
1531 return ValueEffectControl(value, effect, control); | 1531 return ValueEffectControl(value, effect, control); |
1532 } | 1532 } |
1533 | 1533 |
1534 EffectControlLinearizer::ValueEffectControl | 1534 EffectControlLinearizer::ValueEffectControl |
1535 EffectControlLinearizer::BuildCheckedFloat64ToInt32(Node* value, | 1535 EffectControlLinearizer::BuildCheckedFloat64ToInt32(CheckForMinusZeroMode mode, |
| 1536 Node* value, |
1536 Node* frame_state, | 1537 Node* frame_state, |
1537 Node* effect, | 1538 Node* effect, |
1538 Node* control) { | 1539 Node* control) { |
1539 Node* value32 = graph()->NewNode(machine()->RoundFloat64ToInt32(), value); | 1540 Node* value32 = graph()->NewNode(machine()->RoundFloat64ToInt32(), value); |
1540 Node* check_same = graph()->NewNode( | 1541 Node* check_same = graph()->NewNode( |
1541 machine()->Float64Equal(), value, | 1542 machine()->Float64Equal(), value, |
1542 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value32)); | 1543 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value32)); |
1543 control = effect = graph()->NewNode( | 1544 control = effect = graph()->NewNode( |
1544 common()->DeoptimizeUnless(DeoptimizeReason::kLostPrecisionOrNaN), | 1545 common()->DeoptimizeUnless(DeoptimizeReason::kLostPrecisionOrNaN), |
1545 check_same, frame_state, effect, control); | 1546 check_same, frame_state, effect, control); |
1546 | 1547 |
1547 // Check if {value} is -0. | 1548 if (mode == CheckForMinusZeroMode::kCheckForMinusZero) { |
1548 Node* check_zero = graph()->NewNode(machine()->Word32Equal(), value32, | 1549 // Check if {value} is -0. |
1549 jsgraph()->Int32Constant(0)); | 1550 Node* check_zero = graph()->NewNode(machine()->Word32Equal(), value32, |
1550 Node* branch_zero = graph()->NewNode(common()->Branch(BranchHint::kFalse), | 1551 jsgraph()->Int32Constant(0)); |
1551 check_zero, control); | 1552 Node* branch_zero = graph()->NewNode(common()->Branch(BranchHint::kFalse), |
| 1553 check_zero, control); |
1552 | 1554 |
1553 Node* if_zero = graph()->NewNode(common()->IfTrue(), branch_zero); | 1555 Node* if_zero = graph()->NewNode(common()->IfTrue(), branch_zero); |
1554 Node* if_notzero = graph()->NewNode(common()->IfFalse(), branch_zero); | 1556 Node* if_notzero = graph()->NewNode(common()->IfFalse(), branch_zero); |
1555 | 1557 |
1556 // In case of 0, we need to check the high bits for the IEEE -0 pattern. | 1558 // In case of 0, we need to check the high bits for the IEEE -0 pattern. |
1557 Node* check_negative = graph()->NewNode( | 1559 Node* check_negative = graph()->NewNode( |
1558 machine()->Int32LessThan(), | 1560 machine()->Int32LessThan(), |
1559 graph()->NewNode(machine()->Float64ExtractHighWord32(), value), | 1561 graph()->NewNode(machine()->Float64ExtractHighWord32(), value), |
1560 jsgraph()->Int32Constant(0)); | 1562 jsgraph()->Int32Constant(0)); |
1561 | 1563 |
1562 Node* deopt_minus_zero = | 1564 Node* deopt_minus_zero = |
1563 graph()->NewNode(common()->DeoptimizeIf(DeoptimizeReason::kMinusZero), | 1565 graph()->NewNode(common()->DeoptimizeIf(DeoptimizeReason::kMinusZero), |
1564 check_negative, frame_state, effect, if_zero); | 1566 check_negative, frame_state, effect, if_zero); |
1565 | 1567 |
1566 Node* merge = | 1568 control = |
1567 graph()->NewNode(common()->Merge(2), deopt_minus_zero, if_notzero); | 1569 graph()->NewNode(common()->Merge(2), deopt_minus_zero, if_notzero); |
| 1570 effect = graph()->NewNode(common()->EffectPhi(2), deopt_minus_zero, effect, |
| 1571 control); |
| 1572 } |
1568 | 1573 |
1569 effect = | 1574 return ValueEffectControl(value32, effect, control); |
1570 graph()->NewNode(common()->EffectPhi(2), deopt_minus_zero, effect, merge); | |
1571 | |
1572 return ValueEffectControl(value32, effect, merge); | |
1573 } | 1575 } |
1574 | 1576 |
1575 EffectControlLinearizer::ValueEffectControl | 1577 EffectControlLinearizer::ValueEffectControl |
1576 EffectControlLinearizer::LowerCheckedFloat64ToInt32(Node* node, | 1578 EffectControlLinearizer::LowerCheckedFloat64ToInt32(Node* node, |
1577 Node* frame_state, | 1579 Node* frame_state, |
1578 Node* effect, | 1580 Node* effect, |
1579 Node* control) { | 1581 Node* control) { |
| 1582 CheckForMinusZeroMode mode = CheckMinusZeroModeOf(node->op()); |
1580 Node* value = node->InputAt(0); | 1583 Node* value = node->InputAt(0); |
1581 | 1584 |
1582 return BuildCheckedFloat64ToInt32(value, frame_state, effect, control); | 1585 return BuildCheckedFloat64ToInt32(mode, value, frame_state, effect, control); |
1583 } | 1586 } |
1584 | 1587 |
1585 EffectControlLinearizer::ValueEffectControl | 1588 EffectControlLinearizer::ValueEffectControl |
1586 EffectControlLinearizer::LowerCheckedTaggedSignedToInt32(Node* node, | 1589 EffectControlLinearizer::LowerCheckedTaggedSignedToInt32(Node* node, |
1587 Node* frame_state, | 1590 Node* frame_state, |
1588 Node* effect, | 1591 Node* effect, |
1589 Node* control) { | 1592 Node* control) { |
1590 Node* value = node->InputAt(0); | 1593 Node* value = node->InputAt(0); |
1591 | 1594 |
1592 Node* check = ObjectIsSmi(value); | 1595 Node* check = ObjectIsSmi(value); |
1593 control = effect = | 1596 control = effect = |
1594 graph()->NewNode(common()->DeoptimizeUnless(DeoptimizeReason::kNotASmi), | 1597 graph()->NewNode(common()->DeoptimizeUnless(DeoptimizeReason::kNotASmi), |
1595 check, frame_state, effect, control); | 1598 check, frame_state, effect, control); |
1596 value = ChangeSmiToInt32(value); | 1599 value = ChangeSmiToInt32(value); |
1597 | 1600 |
1598 return ValueEffectControl(value, effect, control); | 1601 return ValueEffectControl(value, effect, control); |
1599 } | 1602 } |
1600 | 1603 |
1601 EffectControlLinearizer::ValueEffectControl | 1604 EffectControlLinearizer::ValueEffectControl |
1602 EffectControlLinearizer::LowerCheckedTaggedToInt32(Node* node, | 1605 EffectControlLinearizer::LowerCheckedTaggedToInt32(Node* node, |
1603 Node* frame_state, | 1606 Node* frame_state, |
1604 Node* effect, | 1607 Node* effect, |
1605 Node* control) { | 1608 Node* control) { |
| 1609 CheckForMinusZeroMode mode = CheckMinusZeroModeOf(node->op()); |
1606 Node* value = node->InputAt(0); | 1610 Node* value = node->InputAt(0); |
1607 | 1611 |
1608 Node* check = ObjectIsSmi(value); | 1612 Node* check = ObjectIsSmi(value); |
1609 Node* branch = | 1613 Node* branch = |
1610 graph()->NewNode(common()->Branch(BranchHint::kTrue), check, control); | 1614 graph()->NewNode(common()->Branch(BranchHint::kTrue), check, control); |
1611 | 1615 |
1612 // In the Smi case, just convert to int32. | 1616 // In the Smi case, just convert to int32. |
1613 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 1617 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
1614 Node* etrue = effect; | 1618 Node* etrue = effect; |
1615 Node* vtrue = ChangeSmiToInt32(value); | 1619 Node* vtrue = ChangeSmiToInt32(value); |
1616 | 1620 |
1617 // In the non-Smi case, check the heap numberness, load the number and convert | 1621 // In the non-Smi case, check the heap numberness, load the number and convert |
1618 // to int32. | 1622 // to int32. |
1619 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 1623 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
1620 Node* efalse = effect; | 1624 Node* efalse = effect; |
1621 Node* vfalse; | 1625 Node* vfalse; |
1622 { | 1626 { |
1623 Node* value_map = efalse = | 1627 Node* value_map = efalse = |
1624 graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()), | 1628 graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()), |
1625 value, efalse, if_false); | 1629 value, efalse, if_false); |
1626 Node* check = graph()->NewNode(machine()->WordEqual(), value_map, | 1630 Node* check = graph()->NewNode(machine()->WordEqual(), value_map, |
1627 jsgraph()->HeapNumberMapConstant()); | 1631 jsgraph()->HeapNumberMapConstant()); |
1628 if_false = efalse = graph()->NewNode( | 1632 if_false = efalse = graph()->NewNode( |
1629 common()->DeoptimizeUnless(DeoptimizeReason::kNotAHeapNumber), check, | 1633 common()->DeoptimizeUnless(DeoptimizeReason::kNotAHeapNumber), check, |
1630 frame_state, efalse, if_false); | 1634 frame_state, efalse, if_false); |
1631 vfalse = efalse = graph()->NewNode( | 1635 vfalse = efalse = graph()->NewNode( |
1632 simplified()->LoadField(AccessBuilder::ForHeapNumberValue()), value, | 1636 simplified()->LoadField(AccessBuilder::ForHeapNumberValue()), value, |
1633 efalse, if_false); | 1637 efalse, if_false); |
1634 ValueEffectControl state = | 1638 ValueEffectControl state = |
1635 BuildCheckedFloat64ToInt32(vfalse, frame_state, efalse, if_false); | 1639 BuildCheckedFloat64ToInt32(mode, vfalse, frame_state, efalse, if_false); |
1636 if_false = state.control; | 1640 if_false = state.control; |
1637 efalse = state.effect; | 1641 efalse = state.effect; |
1638 vfalse = state.value; | 1642 vfalse = state.value; |
1639 } | 1643 } |
1640 | 1644 |
1641 control = graph()->NewNode(common()->Merge(2), if_true, if_false); | 1645 control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
1642 effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); | 1646 effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); |
1643 value = graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2), | 1647 value = graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2), |
1644 vtrue, vfalse, control); | 1648 vtrue, vfalse, control); |
1645 | 1649 |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2714 isolate(), graph()->zone(), callable.descriptor(), 0, flags, | 2718 isolate(), graph()->zone(), callable.descriptor(), 0, flags, |
2715 Operator::kNoThrow); | 2719 Operator::kNoThrow); |
2716 to_number_operator_.set(common()->Call(desc)); | 2720 to_number_operator_.set(common()->Call(desc)); |
2717 } | 2721 } |
2718 return to_number_operator_.get(); | 2722 return to_number_operator_.get(); |
2719 } | 2723 } |
2720 | 2724 |
2721 } // namespace compiler | 2725 } // namespace compiler |
2722 } // namespace internal | 2726 } // namespace internal |
2723 } // namespace v8 | 2727 } // namespace v8 |
OLD | NEW |