9 * This code is distributed in the hope that it will be useful, but WITHOUT
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 "opto/addnode.hpp"
26 #include "opto/callnode.hpp"
27 #include "opto/castnode.hpp"
28 #include "opto/connode.hpp"
29 #include "opto/matcher.hpp"
30 #include "opto/phaseX.hpp"
31 #include "opto/subnode.hpp"
32 #include "opto/type.hpp"
33 #include "castnode.hpp"
34 #include "utilities/checkedCast.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 if (_dependency == UnconditionalDependency) {
40 return this;
41 }
42 Node* dom = dominating_cast(phase, phase);
43 if (dom != nullptr) {
44 return dom;
45 }
46 return higher_equal_types(phase, in(1)) ? in(1) : this;
47 }
48
49 //------------------------------Value------------------------------------------
50 // Take 'join' of input and cast-up type
79 if (rt->empty()) {
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 if (in(0) != nullptr && remove_dead_region(phase, can_reshape)) {
101 return this;
102 }
103 if (in(1) != nullptr && phase->type(in(1)) != Type::TOP) {
104 return TypeNode::Ideal(phase, can_reshape);
105 }
106 return nullptr;
107 }
108
109 uint ConstraintCastNode::hash() const {
110 return TypeNode::hash() + (int)_dependency + (_extra_types != nullptr ? _extra_types->hash() : 0);
111 }
112
113 bool ConstraintCastNode::cmp(const Node &n) const {
114 if (!TypeNode::cmp(n)) {
115 return false;
116 }
117 ConstraintCastNode& cast = (ConstraintCastNode&) n;
118 if (cast._dependency != _dependency) {
119 return false;
120 }
121 if (_extra_types == nullptr || cast._extra_types == nullptr) {
122 return _extra_types == cast._extra_types;
123 }
124 return _extra_types->eq(cast._extra_types);
125 }
338 if (in1 != nullptr && in1->Opcode() == Op_ConvI2L) {
339 const Type* t = Value(phase);
340 const Type* t_in = phase->type(in1);
341 if (t != Type::TOP && t_in != Type::TOP) {
342 const TypeLong* tl = t->is_long();
343 const TypeLong* t_in_l = t_in->is_long();
344 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");
345 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");
346 if (tl != t_in_l) {
347 const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
348 Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
349 Node* convi2l = in1->clone();
350 convi2l->set_req(1, castii);
351 return convi2l;
352 }
353 }
354 }
355 return optimize_integer_cast(phase, T_LONG);
356 }
357
358 //------------------------------Value------------------------------------------
359 // Take 'join' of input and cast-up type, unless working with an Interface
360 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
361 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
362
363 const Type *inn = phase->type(in(1));
364 if( inn == Type::TOP ) return Type::TOP; // No information yet
365
366 if (inn->isa_oopptr() && _type->isa_oopptr()) {
367 return ConstraintCastNode::Value(phase);
368 }
369
370 const TypePtr *in_type = inn->isa_ptr();
371 const TypePtr *my_type = _type->isa_ptr();
372 const Type *result = _type;
373 if (in_type != nullptr && my_type != nullptr) {
374 TypePtr::PTR in_ptr = in_type->ptr();
375 if (in_ptr == TypePtr::Null) {
376 result = in_type;
377 } else if (in_ptr != TypePtr::Constant) {
378 result = my_type->cast_to_ptr_type(my_type->join_ptr(in_ptr));
379 }
380 }
381
382 return result;
383 }
384
385 //=============================================================================
386 //------------------------------Value------------------------------------------
387 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
388 const Type* t = phase->type(in(1));
389 if (t == Type::TOP) return Type::TOP;
390 if (t->base() == Type_X && t->singleton()) {
391 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
392 if (bits == 0) return TypePtr::NULL_PTR;
393 return TypeRawPtr::make((address) bits);
394 }
395 return CastX2PNode::bottom_type();
396 }
397
398 //------------------------------Idealize---------------------------------------
445 break;
446 }
447 return nullptr;
448 }
449
450 //------------------------------Identity---------------------------------------
451 Node* CastX2PNode::Identity(PhaseGVN* phase) {
452 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
453 return this;
454 }
455
456 //=============================================================================
457 //------------------------------Value------------------------------------------
458 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
459 const Type* t = phase->type(in(1));
460 if (t == Type::TOP) return Type::TOP;
461 if (t->base() == Type::RawPtr && t->singleton()) {
462 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
463 return TypeX::make(bits);
464 }
465 return CastP2XNode::bottom_type();
466 }
467
468 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
469 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
470 }
471
472 //------------------------------Identity---------------------------------------
473 Node* CastP2XNode::Identity(PhaseGVN* phase) {
474 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
475 return this;
476 }
477
478 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency,
479 const TypeTuple* types) {
480 if (type->isa_int()) {
481 return new CastIINode(c, in, type, dependency, false, types);
482 } else if (type->isa_long()) {
483 return new CastLLNode(c, in, type, dependency, types);
484 } else if (type->isa_half_float()) {
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
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 "opto/addnode.hpp"
26 #include "opto/callnode.hpp"
27 #include "opto/castnode.hpp"
28 #include "opto/connode.hpp"
29 #include "opto/graphKit.hpp"
30 #include "opto/inlinetypenode.hpp"
31 #include "opto/matcher.hpp"
32 #include "opto/phaseX.hpp"
33 #include "opto/rootnode.hpp"
34 #include "opto/subnode.hpp"
35 #include "opto/type.hpp"
36 #include "castnode.hpp"
37 #include "utilities/checkedCast.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 if (_dependency == UnconditionalDependency) {
43 return this;
44 }
45 Node* dom = dominating_cast(phase, phase);
46 if (dom != nullptr) {
47 return dom;
48 }
49 return higher_equal_types(phase, in(1)) ? in(1) : this;
50 }
51
52 //------------------------------Value------------------------------------------
53 // Take 'join' of input and cast-up type
82 if (rt->empty()) {
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) != nullptr && 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 if (!_type->maybe_null()) {
114 vt->as_InlineType()->set_is_init(*phase);
115 }
116 vt->set_oop(*phase, phase->transform(cast));
117 return vt;
118 }
119
120 if (in(1) != nullptr && phase->type(in(1)) != Type::TOP) {
121 return TypeNode::Ideal(phase, can_reshape);
122 }
123
124 return nullptr;
125 }
126
127 uint ConstraintCastNode::hash() const {
128 return TypeNode::hash() + (int)_dependency + (_extra_types != nullptr ? _extra_types->hash() : 0);
129 }
130
131 bool ConstraintCastNode::cmp(const Node &n) const {
132 if (!TypeNode::cmp(n)) {
133 return false;
134 }
135 ConstraintCastNode& cast = (ConstraintCastNode&) n;
136 if (cast._dependency != _dependency) {
137 return false;
138 }
139 if (_extra_types == nullptr || cast._extra_types == nullptr) {
140 return _extra_types == cast._extra_types;
141 }
142 return _extra_types->eq(cast._extra_types);
143 }
356 if (in1 != nullptr && in1->Opcode() == Op_ConvI2L) {
357 const Type* t = Value(phase);
358 const Type* t_in = phase->type(in1);
359 if (t != Type::TOP && t_in != Type::TOP) {
360 const TypeLong* tl = t->is_long();
361 const TypeLong* t_in_l = t_in->is_long();
362 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");
363 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");
364 if (tl != t_in_l) {
365 const TypeInt* ti = TypeInt::make(checked_cast<jint>(tl->_lo), checked_cast<jint>(tl->_hi), tl->_widen);
366 Node* castii = phase->transform(new CastIINode(in(0), in1->in(1), ti));
367 Node* convi2l = in1->clone();
368 convi2l->set_req(1, castii);
369 return convi2l;
370 }
371 }
372 }
373 return optimize_integer_cast(phase, T_LONG);
374 }
375
376 //=============================================================================
377 //------------------------------Identity---------------------------------------
378 // If input is already higher or equal to cast type, then this is an identity.
379 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {
380 if (in(1)->is_InlineType() && _type->isa_instptr() && phase->type(in(1))->inline_klass()->is_subtype_of(_type->is_instptr()->instance_klass())) {
381 return in(1);
382 }
383 return ConstraintCastNode::Identity(phase);
384 }
385
386 //------------------------------Value------------------------------------------
387 // Take 'join' of input and cast-up type, unless working with an Interface
388 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
389 if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
390
391 const Type *inn = phase->type(in(1));
392 if( inn == Type::TOP ) return Type::TOP; // No information yet
393
394 if (inn->isa_oopptr() && _type->isa_oopptr()) {
395 return ConstraintCastNode::Value(phase);
396 }
397
398 const TypePtr *in_type = inn->isa_ptr();
399 const TypePtr *my_type = _type->isa_ptr();
400 const Type *result = _type;
401 if (in_type != nullptr && my_type != nullptr) {
402 // TODO 8302672
403 if (!StressReflectiveCode && my_type->isa_aryptr() && in_type->isa_aryptr()) {
404 // Propagate array properties (not flat/null-free)
405 // Don't do this when StressReflectiveCode is enabled because it might lead to
406 // a dying data path while the corresponding flat/null-free check is not folded.
407 my_type = my_type->is_aryptr()->update_properties(in_type->is_aryptr());
408 if (my_type == nullptr) {
409 return Type::TOP; // Inconsistent properties
410 }
411 }
412 TypePtr::PTR in_ptr = in_type->ptr();
413 if (in_ptr == TypePtr::Null) {
414 result = in_type;
415 } else if (in_ptr != TypePtr::Constant) {
416 result = my_type->cast_to_ptr_type(my_type->join_ptr(in_ptr));
417 }
418 }
419
420 return result;
421 }
422
423 //=============================================================================
424 //------------------------------Value------------------------------------------
425 const Type* CastX2PNode::Value(PhaseGVN* phase) const {
426 const Type* t = phase->type(in(1));
427 if (t == Type::TOP) return Type::TOP;
428 if (t->base() == Type_X && t->singleton()) {
429 uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
430 if (bits == 0) return TypePtr::NULL_PTR;
431 return TypeRawPtr::make((address) bits);
432 }
433 return CastX2PNode::bottom_type();
434 }
435
436 //------------------------------Idealize---------------------------------------
483 break;
484 }
485 return nullptr;
486 }
487
488 //------------------------------Identity---------------------------------------
489 Node* CastX2PNode::Identity(PhaseGVN* phase) {
490 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
491 return this;
492 }
493
494 //=============================================================================
495 //------------------------------Value------------------------------------------
496 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
497 const Type* t = phase->type(in(1));
498 if (t == Type::TOP) return Type::TOP;
499 if (t->base() == Type::RawPtr && t->singleton()) {
500 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
501 return TypeX::make(bits);
502 }
503
504 if (t->is_zero_type() || !t->maybe_null()) {
505 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
506 Node* u = fast_out(i);
507 if (u->Opcode() == Op_OrL) {
508 for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
509 Node* cmp = u->fast_out(j);
510 if (cmp->Opcode() == Op_CmpL) {
511 // Give CmpL a chance to get optimized
512 phase->record_for_igvn(cmp);
513 }
514 }
515 }
516 }
517 }
518
519 return CastP2XNode::bottom_type();
520 }
521
522 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
523 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : nullptr;
524 }
525
526 //------------------------------Identity---------------------------------------
527 Node* CastP2XNode::Identity(PhaseGVN* phase) {
528 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
529 return this;
530 }
531
532 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency,
533 const TypeTuple* types) {
534 if (type->isa_int()) {
535 return new CastIINode(c, in, type, dependency, false, types);
536 } else if (type->isa_long()) {
537 return new CastLLNode(c, in, type, dependency, types);
538 } else if (type->isa_half_float()) {
|