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
36 //=============================================================================
37 // If input is already higher or equal to cast type, then this is an identity.
38 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
39 Node* dom = dominating_cast(phase, phase);
40 if (dom != nullptr) {
41 return dom;
42 }
43 if (_dependency != RegularDependency) {
44 return this;
45 }
46 return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
47 }
48
49 //------------------------------Value------------------------------------------
50 // Take 'join' of input and cast-up type
51 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {
80 assert(ft == Type::TOP, "special case #2");
81 }
82 break;
83 }
84 case Op_CastPP:
85 if (in_type == TypePtr::NULL_PTR &&
86 _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull) {
87 assert(ft == Type::TOP, "special case #3");
88 break;
89 }
90 }
91 #endif //ASSERT
92
93 return ft;
94 }
95
96 //------------------------------Ideal------------------------------------------
97 // Return a node which is more "ideal" than the current node. Strip out
98 // control copies
99 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
100 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
101 }
102
103 bool ConstraintCastNode::cmp(const Node &n) const {
104 return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._dependency == _dependency;
105 }
106
107 uint ConstraintCastNode::size_of() const {
108 return sizeof(*this);
109 }
110
111 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, DependencyType dependency) {
112 switch(opcode) {
113 case Op_CastII: {
114 Node* cast = new CastIINode(n, t, dependency);
115 cast->set_req(0, c);
116 return cast;
117 }
118 case Op_CastLL: {
119 Node* cast = new CastLLNode(n, t, dependency);
120 cast->set_req(0, c);
386 if (in1 != nullptr && in1->Opcode() == Op_ConvI2L) {
387 const Type* t = Value(phase);
388 const Type* t_in = phase->type(in1);
389 if (t != Type::TOP && t_in != Type::TOP) {
390 const TypeLong* tl = t->is_long();
391 const TypeLong* t_in_l = t_in->is_long();
392 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");
393 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");
394 if (tl != t_in_l) {
395 const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
396 Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
397 Node* convi2l = in1->clone();
398 convi2l->set_req(1, castii);
399 return convi2l;
400 }
401 }
402 }
403 return optimize_integer_cast(phase, T_LONG);
404 }
405
406 //------------------------------Value------------------------------------------
407 // Take 'join' of input and cast-up type, unless working with an Interface
408 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
409 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
410
411 const Type *inn = phase->type(in(1));
412 if( inn == Type::TOP ) return Type::TOP; // No information yet
413
414 if (inn->isa_oopptr() && _type->isa_oopptr()) {
415 return ConstraintCastNode::Value(phase);
416 }
417
418 const TypePtr *in_type = inn->isa_ptr();
419 const TypePtr *my_type = _type->isa_ptr();
420 const Type *result = _type;
421 if (in_type != nullptr && my_type != nullptr) {
422 TypePtr::PTR in_ptr = in_type->ptr();
423 if (in_ptr == TypePtr::Null) {
424 result = in_type;
425 } else if (in_ptr != TypePtr::Constant) {
426 result = my_type->cast_to_ptr_type(my_type->join_ptr(in_ptr));
427 }
428 }
429
430 return result;
431 }
432
433 //=============================================================================
434 //------------------------------Value------------------------------------------
435 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
436 const Type* t = phase->type(in(1));
437 if (t == Type::TOP) return Type::TOP;
438 if (t->base() == Type_X && t->singleton()) {
439 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
440 if (bits == 0) return TypePtr::NULL_PTR;
441 return TypeRawPtr::make((address) bits);
442 }
443 return CastX2PNode::bottom_type();
444 }
445
446 //------------------------------Idealize---------------------------------------
493 break;
494 }
495 return nullptr;
496 }
497
498 //------------------------------Identity---------------------------------------
499 Node* CastX2PNode::Identity(PhaseGVN* phase) {
500 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
501 return this;
502 }
503
504 //=============================================================================
505 //------------------------------Value------------------------------------------
506 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
507 const Type* t = phase->type(in(1));
508 if (t == Type::TOP) return Type::TOP;
509 if (t->base() == Type::RawPtr && t->singleton()) {
510 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
511 return TypeX::make(bits);
512 }
513 return CastP2XNode::bottom_type();
514 }
515
516 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
517 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
518 }
519
520 //------------------------------Identity---------------------------------------
521 Node* CastP2XNode::Identity(PhaseGVN* phase) {
522 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
523 return this;
524 }
525
526 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
527 Node* cast= nullptr;
528 if (type->isa_int()) {
529 cast = make_cast(Op_CastII, c, in, type, dependency);
530 } else if (type->isa_long()) {
531 cast = make_cast(Op_CastLL, c, in, type, dependency);
532 } else if (type->isa_float()) {
|
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
39 //=============================================================================
40 // If input is already higher or equal to cast type, then this is an identity.
41 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
42 Node* dom = dominating_cast(phase, phase);
43 if (dom != nullptr) {
44 return dom;
45 }
46 if (_dependency != RegularDependency) {
47 return this;
48 }
49 return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
50 }
51
52 //------------------------------Value------------------------------------------
53 // Take 'join' of input and cast-up type
54 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {
83 assert(ft == Type::TOP, "special case #2");
84 }
85 break;
86 }
87 case Op_CastPP:
88 if (in_type == TypePtr::NULL_PTR &&
89 _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull) {
90 assert(ft == Type::TOP, "special case #3");
91 break;
92 }
93 }
94 #endif //ASSERT
95
96 return ft;
97 }
98
99 //------------------------------Ideal------------------------------------------
100 // Return a node which is more "ideal" than the current node. Strip out
101 // control copies
102 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
103 if (in(0) && remove_dead_region(phase, can_reshape)) {
104 return this;
105 }
106
107 // Push cast through InlineTypeNode
108 InlineTypeNode* vt = in(1)->isa_InlineType();
109 if (vt != nullptr && phase->type(vt)->filter_speculative(_type) != Type::TOP) {
110 Node* cast = clone();
111 cast->set_req(1, vt->get_oop());
112 vt = vt->clone()->as_InlineType();
113 vt->set_oop(phase->transform(cast));
114 return vt;
115 }
116
117 return nullptr;
118 }
119
120 bool ConstraintCastNode::cmp(const Node &n) const {
121 return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._dependency == _dependency;
122 }
123
124 uint ConstraintCastNode::size_of() const {
125 return sizeof(*this);
126 }
127
128 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, DependencyType dependency) {
129 switch(opcode) {
130 case Op_CastII: {
131 Node* cast = new CastIINode(n, t, dependency);
132 cast->set_req(0, c);
133 return cast;
134 }
135 case Op_CastLL: {
136 Node* cast = new CastLLNode(n, t, dependency);
137 cast->set_req(0, c);
403 if (in1 != nullptr && in1->Opcode() == Op_ConvI2L) {
404 const Type* t = Value(phase);
405 const Type* t_in = phase->type(in1);
406 if (t != Type::TOP && t_in != Type::TOP) {
407 const TypeLong* tl = t->is_long();
408 const TypeLong* t_in_l = t_in->is_long();
409 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");
410 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");
411 if (tl != t_in_l) {
412 const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
413 Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
414 Node* convi2l = in1->clone();
415 convi2l->set_req(1, castii);
416 return convi2l;
417 }
418 }
419 }
420 return optimize_integer_cast(phase, T_LONG);
421 }
422
423 //=============================================================================
424 //------------------------------Identity---------------------------------------
425 // If input is already higher or equal to cast type, then this is an identity.
426 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {
427 if (in(1)->is_InlineType() && _type->isa_instptr() && phase->type(in(1))->inline_klass()->is_subtype_of(_type->is_instptr()->instance_klass())) {
428 return in(1);
429 }
430 return ConstraintCastNode::Identity(phase);
431 }
432
433 //------------------------------Value------------------------------------------
434 // Take 'join' of input and cast-up type, unless working with an Interface
435 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
436 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
437
438 const Type *inn = phase->type(in(1));
439 if( inn == Type::TOP ) return Type::TOP; // No information yet
440
441 if (inn->isa_oopptr() && _type->isa_oopptr()) {
442 return ConstraintCastNode::Value(phase);
443 }
444
445 const TypePtr *in_type = inn->isa_ptr();
446 const TypePtr *my_type = _type->isa_ptr();
447 const Type *result = _type;
448 if (in_type != nullptr && my_type != nullptr) {
449 // TODO 8302672
450 if (!StressReflectiveCode && my_type->isa_aryptr() && in_type->isa_aryptr()) {
451 // Propagate array properties (not flat/null-free)
452 // Don't do this when StressReflectiveCode is enabled because it might lead to
453 // a dying data path while the corresponding flat/null-free check is not folded.
454 my_type = my_type->is_aryptr()->update_properties(in_type->is_aryptr());
455 if (my_type == nullptr) {
456 return Type::TOP; // Inconsistent properties
457 }
458 }
459 TypePtr::PTR in_ptr = in_type->ptr();
460 if (in_ptr == TypePtr::Null) {
461 result = in_type;
462 } else if (in_ptr != TypePtr::Constant) {
463 result = my_type->cast_to_ptr_type(my_type->join_ptr(in_ptr));
464 }
465 }
466
467 return result;
468 }
469
470 //=============================================================================
471 //------------------------------Value------------------------------------------
472 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
473 const Type* t = phase->type(in(1));
474 if (t == Type::TOP) return Type::TOP;
475 if (t->base() == Type_X && t->singleton()) {
476 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
477 if (bits == 0) return TypePtr::NULL_PTR;
478 return TypeRawPtr::make((address) bits);
479 }
480 return CastX2PNode::bottom_type();
481 }
482
483 //------------------------------Idealize---------------------------------------
530 break;
531 }
532 return nullptr;
533 }
534
535 //------------------------------Identity---------------------------------------
536 Node* CastX2PNode::Identity(PhaseGVN* phase) {
537 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
538 return this;
539 }
540
541 //=============================================================================
542 //------------------------------Value------------------------------------------
543 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
544 const Type* t = phase->type(in(1));
545 if (t == Type::TOP) return Type::TOP;
546 if (t->base() == Type::RawPtr && t->singleton()) {
547 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
548 return TypeX::make(bits);
549 }
550
551 if (t->is_zero_type() || !t->maybe_null()) {
552 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
553 Node* u = fast_out(i);
554 if (u->Opcode() == Op_OrL) {
555 for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
556 Node* cmp = u->fast_out(j);
557 if (cmp->Opcode() == Op_CmpL) {
558 // Give CmpL a chance to get optimized
559 phase->record_for_igvn(cmp);
560 }
561 }
562 }
563 }
564 }
565
566 return CastP2XNode::bottom_type();
567 }
568
569 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
570 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
571 }
572
573 //------------------------------Identity---------------------------------------
574 Node* CastP2XNode::Identity(PhaseGVN* phase) {
575 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
576 return this;
577 }
578
579 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
580 Node* cast= nullptr;
581 if (type->isa_int()) {
582 cast = make_cast(Op_CastII, c, in, type, dependency);
583 } else if (type->isa_long()) {
584 cast = make_cast(Op_CastLL, c, in, type, dependency);
585 } else if (type->isa_float()) {
|