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