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