1701 } |
1701 } |
1702 } |
1702 } |
1703 } |
1703 } |
1704 |
1704 |
1705 if (uncasted) { |
1705 if (uncasted) { |
1706 // Add a cast node between the phi to be removed and its unique input. |
1706 // Add cast nodes between the phi to be removed and its unique input. |
1707 // Wait until after parsing for the type information to propagate from the casts. |
1707 // Wait until after parsing for the type information to propagate from the casts. |
1708 assert(can_reshape, "Invalid during parsing"); |
1708 assert(can_reshape, "Invalid during parsing"); |
1709 const Type* phi_type = bottom_type(); |
1709 const Type* phi_type = bottom_type(); |
1710 assert(phi_type->isa_int() || phi_type->isa_ptr(), "bad phi type"); |
1710 assert(phi_type->isa_int() || phi_type->isa_ptr(), "bad phi type"); |
1711 int opcode; |
1711 // Add casts to carry the control dependency of the Phi that is |
1712 // Determine the type of cast to be added. |
1712 // going away |
|
1713 Node* cast = NULL; |
1713 if (phi_type->isa_int()) { |
1714 if (phi_type->isa_int()) { |
1714 opcode = Op_CastII; |
1715 cast = ConstraintCastNode::make_cast(Op_CastII, r, uin, phi_type, true); |
1715 } else { |
1716 } else { |
1716 const Type* uin_type = phase->type(uin); |
1717 const Type* uin_type = phase->type(uin); |
1717 if ((phi_type->join(TypePtr::NOTNULL) == uin_type->join(TypePtr::NOTNULL)) || |
1718 if (!phi_type->isa_oopptr() && !uin_type->isa_oopptr()) { |
1718 (!phi_type->isa_oopptr() && !uin_type->isa_oopptr())) { |
1719 cast = ConstraintCastNode::make_cast(Op_CastPP, r, uin, phi_type, true); |
1719 opcode = Op_CastPP; |
|
1720 } else { |
1720 } else { |
1721 opcode = Op_CheckCastPP; |
1721 // Use a CastPP for a cast to not null and a CheckCastPP for |
1722 } |
1722 // a cast to a new klass (and both if both null-ness and |
1723 } |
1723 // klass change). |
1724 // Add a cast to carry the control dependency of the Phi that is |
1724 |
1725 // going away |
1725 // If the type of phi is not null but the type of uin may be |
1726 Node* cast = ConstraintCastNode::make_cast(opcode, r, uin, phi_type, true); |
1726 // null, uin's type must be casted to not null |
|
1727 if (phi_type->join(TypePtr::NOTNULL) == phi_type->remove_speculative() && |
|
1728 uin_type->join(TypePtr::NOTNULL) != uin_type->remove_speculative()) { |
|
1729 cast = ConstraintCastNode::make_cast(Op_CastPP, r, uin, TypePtr::NOTNULL, true); |
|
1730 } |
|
1731 |
|
1732 // If the type of phi and uin, both casted to not null, |
|
1733 // differ the klass of uin must be (check)cast'ed to match |
|
1734 // that of phi |
|
1735 if (phi_type->join_speculative(TypePtr::NOTNULL) != uin_type->join_speculative(TypePtr::NOTNULL)) { |
|
1736 Node* n = uin; |
|
1737 if (cast != NULL) { |
|
1738 cast = phase->transform(cast); |
|
1739 n = cast; |
|
1740 } |
|
1741 cast = ConstraintCastNode::make_cast(Op_CheckCastPP, r, n, phi_type, true); |
|
1742 } |
|
1743 if (cast == NULL) { |
|
1744 cast = ConstraintCastNode::make_cast(Op_CastPP, r, uin, phi_type, true); |
|
1745 } |
|
1746 } |
|
1747 } |
|
1748 assert(cast != NULL, "cast should be set"); |
1727 cast = phase->transform(cast); |
1749 cast = phase->transform(cast); |
1728 // set all inputs to the new cast so the Phi is removed by Identity |
1750 // set all inputs to the new cast(s) so the Phi is removed by Identity |
1729 PhaseIterGVN* igvn = phase->is_IterGVN(); |
1751 PhaseIterGVN* igvn = phase->is_IterGVN(); |
1730 for (uint i = 1; i < req(); i++) { |
1752 for (uint i = 1; i < req(); i++) { |
1731 set_req_X(i, cast, igvn); |
1753 set_req_X(i, cast, igvn); |
1732 } |
1754 } |
1733 uin = cast; |
1755 uin = cast; |