10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "opto/addnode.hpp"
27 #include "opto/callnode.hpp"
28 #include "opto/castnode.hpp"
29 #include "opto/connode.hpp"
30 #include "opto/matcher.hpp"
31 #include "opto/phaseX.hpp"
32 #include "opto/subnode.hpp"
33 #include "opto/type.hpp"
34 #include "castnode.hpp"
35 #include "utilities/checkedCast.hpp"
36
37 //=============================================================================
38 // If input is already higher or equal to cast type, then this is an identity.
39 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
40 if (_dependency == UnconditionalDependency) {
41 return this;
42 }
43 Node* dom = dominating_cast(phase, phase);
44 if (dom != nullptr) {
45 return dom;
46 }
47 return higher_equal_types(phase, in(1)) ? in(1) : this;
48 }
49
50 //------------------------------Value------------------------------------------
51 // Take 'join' of input and cast-up type
81 assert(ft == Type::TOP, "special case #2");
82 }
83 break;
84 }
85 case Op_CastPP:
86 if (in_type == TypePtr::NULL_PTR &&
87 _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull) {
88 assert(ft == Type::TOP, "special case #3");
89 break;
90 }
91 }
92 #endif //ASSERT
93
94 return ft;
95 }
96
97 //------------------------------Ideal------------------------------------------
98 // Return a node which is more "ideal" than the current node. Strip out
99 // control copies
100 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
101 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
102 }
103
104 uint ConstraintCastNode::hash() const {
105 return TypeNode::hash() + (int)_dependency + (_extra_types != nullptr ? _extra_types->hash() : 0);
106 }
107
108 bool ConstraintCastNode::cmp(const Node &n) const {
109 if (!TypeNode::cmp(n)) {
110 return false;
111 }
112 ConstraintCastNode& cast = (ConstraintCastNode&) n;
113 if (cast._dependency != _dependency) {
114 return false;
115 }
116 if (_extra_types == nullptr || cast._extra_types == nullptr) {
117 return _extra_types == cast._extra_types;
118 }
119 return _extra_types->eq(cast._extra_types);
120 }
121
421 if (in1 != nullptr && in1->Opcode() == Op_ConvI2L) {
422 const Type* t = Value(phase);
423 const Type* t_in = phase->type(in1);
424 if (t != Type::TOP && t_in != Type::TOP) {
425 const TypeLong* tl = t->is_long();
426 const TypeLong* t_in_l = t_in->is_long();
427 assert(tl->_lo >= t_in_l->_lo && tl->_hi <= t_in_l->_hi, "CastLL type should be narrower than or equal to the type of its input");
428 assert((tl != t_in_l) == (tl->_lo > t_in_l->_lo || tl->_hi < t_in_l->_hi), "if type differs then this nodes's type must be narrower");
429 if (tl != t_in_l) {
430 const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
431 Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
432 Node* convi2l = in1->clone();
433 convi2l->set_req(1, castii);
434 return convi2l;
435 }
436 }
437 }
438 return optimize_integer_cast(phase, T_LONG);
439 }
440
441 //------------------------------Value------------------------------------------
442 // Take 'join' of input and cast-up type, unless working with an Interface
443 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
444 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
445
446 const Type *inn = phase->type(in(1));
447 if( inn == Type::TOP ) return Type::TOP; // No information yet
448
449 if (inn->isa_oopptr() && _type->isa_oopptr()) {
450 return ConstraintCastNode::Value(phase);
451 }
452
453 const TypePtr *in_type = inn->isa_ptr();
454 const TypePtr *my_type = _type->isa_ptr();
455 const Type *result = _type;
456 if (in_type != nullptr && my_type != nullptr) {
457 TypePtr::PTR in_ptr = in_type->ptr();
458 if (in_ptr == TypePtr::Null) {
459 result = in_type;
460 } else if (in_ptr != TypePtr::Constant) {
461 result = my_type->cast_to_ptr_type(my_type->join_ptr(in_ptr));
462 }
463 }
464
465 return result;
466 }
467
468 //=============================================================================
469 //------------------------------Value------------------------------------------
470 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
471 const Type* t = phase->type(in(1));
472 if (t == Type::TOP) return Type::TOP;
473 if (t->base() == Type_X && t->singleton()) {
474 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
475 if (bits == 0) return TypePtr::NULL_PTR;
476 return TypeRawPtr::make((address) bits);
477 }
478 return CastX2PNode::bottom_type();
479 }
480
481 //------------------------------Idealize---------------------------------------
528 break;
529 }
530 return nullptr;
531 }
532
533 //------------------------------Identity---------------------------------------
534 Node* CastX2PNode::Identity(PhaseGVN* phase) {
535 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
536 return this;
537 }
538
539 //=============================================================================
540 //------------------------------Value------------------------------------------
541 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
542 const Type* t = phase->type(in(1));
543 if (t == Type::TOP) return Type::TOP;
544 if (t->base() == Type::RawPtr && t->singleton()) {
545 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
546 return TypeX::make(bits);
547 }
548 return CastP2XNode::bottom_type();
549 }
550
551 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
552 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
553 }
554
555 //------------------------------Identity---------------------------------------
556 Node* CastP2XNode::Identity(PhaseGVN* phase) {
557 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
558 return this;
559 }
560
561 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency,
562 const TypeTuple* types) {
563 Node* cast= nullptr;
564 if (type->isa_int()) {
565 cast = make_cast(Op_CastII, c, in, type, dependency, types);
566 } else if (type->isa_long()) {
567 cast = make_cast(Op_CastLL, c, in, type, dependency, types);
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "opto/addnode.hpp"
27 #include "opto/callnode.hpp"
28 #include "opto/castnode.hpp"
29 #include "opto/connode.hpp"
30 #include "opto/graphKit.hpp"
31 #include "opto/inlinetypenode.hpp"
32 #include "opto/matcher.hpp"
33 #include "opto/phaseX.hpp"
34 #include "opto/rootnode.hpp"
35 #include "opto/subnode.hpp"
36 #include "opto/type.hpp"
37 #include "castnode.hpp"
38 #include "utilities/checkedCast.hpp"
39
40 //=============================================================================
41 // If input is already higher or equal to cast type, then this is an identity.
42 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
43 if (_dependency == UnconditionalDependency) {
44 return this;
45 }
46 Node* dom = dominating_cast(phase, phase);
47 if (dom != nullptr) {
48 return dom;
49 }
50 return higher_equal_types(phase, in(1)) ? in(1) : this;
51 }
52
53 //------------------------------Value------------------------------------------
54 // Take 'join' of input and cast-up type
84 assert(ft == Type::TOP, "special case #2");
85 }
86 break;
87 }
88 case Op_CastPP:
89 if (in_type == TypePtr::NULL_PTR &&
90 _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull) {
91 assert(ft == Type::TOP, "special case #3");
92 break;
93 }
94 }
95 #endif //ASSERT
96
97 return ft;
98 }
99
100 //------------------------------Ideal------------------------------------------
101 // Return a node which is more "ideal" than the current node. Strip out
102 // control copies
103 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
104 if (in(0) && remove_dead_region(phase, can_reshape)) {
105 return this;
106 }
107
108 // Push cast through InlineTypeNode
109 InlineTypeNode* vt = in(1)->isa_InlineType();
110 if (vt != nullptr && phase->type(vt)->filter_speculative(_type) != Type::TOP) {
111 Node* cast = clone();
112 cast->set_req(1, vt->get_oop());
113 vt = vt->clone()->as_InlineType();
114 if (!_type->maybe_null()) {
115 vt->as_InlineType()->set_is_init(*phase);
116 }
117 vt->set_oop(*phase, phase->transform(cast));
118 return vt;
119 }
120
121 return nullptr;
122 }
123
124 uint ConstraintCastNode::hash() const {
125 return TypeNode::hash() + (int)_dependency + (_extra_types != nullptr ? _extra_types->hash() : 0);
126 }
127
128 bool ConstraintCastNode::cmp(const Node &n) const {
129 if (!TypeNode::cmp(n)) {
130 return false;
131 }
132 ConstraintCastNode& cast = (ConstraintCastNode&) n;
133 if (cast._dependency != _dependency) {
134 return false;
135 }
136 if (_extra_types == nullptr || cast._extra_types == nullptr) {
137 return _extra_types == cast._extra_types;
138 }
139 return _extra_types->eq(cast._extra_types);
140 }
141
441 if (in1 != nullptr && in1->Opcode() == Op_ConvI2L) {
442 const Type* t = Value(phase);
443 const Type* t_in = phase->type(in1);
444 if (t != Type::TOP && t_in != Type::TOP) {
445 const TypeLong* tl = t->is_long();
446 const TypeLong* t_in_l = t_in->is_long();
447 assert(tl->_lo >= t_in_l->_lo && tl->_hi <= t_in_l->_hi, "CastLL type should be narrower than or equal to the type of its input");
448 assert((tl != t_in_l) == (tl->_lo > t_in_l->_lo || tl->_hi < t_in_l->_hi), "if type differs then this nodes's type must be narrower");
449 if (tl != t_in_l) {
450 const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
451 Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
452 Node* convi2l = in1->clone();
453 convi2l->set_req(1, castii);
454 return convi2l;
455 }
456 }
457 }
458 return optimize_integer_cast(phase, T_LONG);
459 }
460
461 //=============================================================================
462 //------------------------------Identity---------------------------------------
463 // If input is already higher or equal to cast type, then this is an identity.
464 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {
465 if (in(1)->is_InlineType() && _type->isa_instptr() && phase->type(in(1))->inline_klass()->is_subtype_of(_type->is_instptr()->instance_klass())) {
466 return in(1);
467 }
468 return ConstraintCastNode::Identity(phase);
469 }
470
471 //------------------------------Value------------------------------------------
472 // Take 'join' of input and cast-up type, unless working with an Interface
473 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
474 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
475
476 const Type *inn = phase->type(in(1));
477 if( inn == Type::TOP ) return Type::TOP; // No information yet
478
479 if (inn->isa_oopptr() && _type->isa_oopptr()) {
480 return ConstraintCastNode::Value(phase);
481 }
482
483 const TypePtr *in_type = inn->isa_ptr();
484 const TypePtr *my_type = _type->isa_ptr();
485 const Type *result = _type;
486 if (in_type != nullptr && my_type != nullptr) {
487 // TODO 8302672
488 if (!StressReflectiveCode && my_type->isa_aryptr() && in_type->isa_aryptr()) {
489 // Propagate array properties (not flat/null-free)
490 // Don't do this when StressReflectiveCode is enabled because it might lead to
491 // a dying data path while the corresponding flat/null-free check is not folded.
492 my_type = my_type->is_aryptr()->update_properties(in_type->is_aryptr());
493 if (my_type == nullptr) {
494 return Type::TOP; // Inconsistent properties
495 }
496 }
497 TypePtr::PTR in_ptr = in_type->ptr();
498 if (in_ptr == TypePtr::Null) {
499 result = in_type;
500 } else if (in_ptr != TypePtr::Constant) {
501 result = my_type->cast_to_ptr_type(my_type->join_ptr(in_ptr));
502 }
503 }
504
505 return result;
506 }
507
508 //=============================================================================
509 //------------------------------Value------------------------------------------
510 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
511 const Type* t = phase->type(in(1));
512 if (t == Type::TOP) return Type::TOP;
513 if (t->base() == Type_X && t->singleton()) {
514 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
515 if (bits == 0) return TypePtr::NULL_PTR;
516 return TypeRawPtr::make((address) bits);
517 }
518 return CastX2PNode::bottom_type();
519 }
520
521 //------------------------------Idealize---------------------------------------
568 break;
569 }
570 return nullptr;
571 }
572
573 //------------------------------Identity---------------------------------------
574 Node* CastX2PNode::Identity(PhaseGVN* phase) {
575 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
576 return this;
577 }
578
579 //=============================================================================
580 //------------------------------Value------------------------------------------
581 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
582 const Type* t = phase->type(in(1));
583 if (t == Type::TOP) return Type::TOP;
584 if (t->base() == Type::RawPtr && t->singleton()) {
585 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
586 return TypeX::make(bits);
587 }
588
589 if (t->is_zero_type() || !t->maybe_null()) {
590 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
591 Node* u = fast_out(i);
592 if (u->Opcode() == Op_OrL) {
593 for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
594 Node* cmp = u->fast_out(j);
595 if (cmp->Opcode() == Op_CmpL) {
596 // Give CmpL a chance to get optimized
597 phase->record_for_igvn(cmp);
598 }
599 }
600 }
601 }
602 }
603
604 return CastP2XNode::bottom_type();
605 }
606
607 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
608 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
609 }
610
611 //------------------------------Identity---------------------------------------
612 Node* CastP2XNode::Identity(PhaseGVN* phase) {
613 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
614 return this;
615 }
616
617 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency,
618 const TypeTuple* types) {
619 Node* cast= nullptr;
620 if (type->isa_int()) {
621 cast = make_cast(Op_CastII, c, in, type, dependency, types);
622 } else if (type->isa_long()) {
623 cast = make_cast(Op_CastLL, c, in, type, dependency, types);
|