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