< prev index next >

src/hotspot/share/opto/castnode.cpp

Print this page

 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 
 35 //=============================================================================
 36 // If input is already higher or equal to cast type, then this is an identity.
 37 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
 38   Node* dom = dominating_cast(phase, phase);
 39   if (dom != NULL) {
 40     return dom;
 41   }
 42   if (_dependency != RegularDependency) {
 43     return this;
 44   }
 45   return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
 46 }
 47 
 48 //------------------------------Value------------------------------------------
 49 // Take 'join' of input and cast-up type
 50 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {
 51   if (in(0) && phase->type(in(0)) == Type::TOP) return Type::TOP;

 61       if( t1 == Type::TOP )  assert(ft == Type::TOP, "special case #1");
 62       const Type* rt = t1->join_speculative(_type);
 63       if (rt->empty())       assert(ft == Type::TOP, "special case #2");
 64       break;
 65     }
 66     case Op_CastPP:
 67     if (phase->type(in(1)) == TypePtr::NULL_PTR &&
 68         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
 69     assert(ft == Type::TOP, "special case #3");
 70     break;
 71   }
 72 #endif //ASSERT
 73 
 74   return ft;
 75 }
 76 
 77 //------------------------------Ideal------------------------------------------
 78 // Return a node which is more "ideal" than the current node.  Strip out
 79 // control copies
 80 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 81   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;














 82 }
 83 
 84 bool ConstraintCastNode::cmp(const Node &n) const {
 85   return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._dependency == _dependency;
 86 }
 87 
 88 uint ConstraintCastNode::size_of() const {
 89   return sizeof(*this);
 90 }
 91 
 92 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, DependencyType dependency) {
 93   switch(opcode) {
 94   case Op_CastII: {
 95     Node* cast = new CastIINode(n, t, dependency);
 96     cast->set_req(0, c);
 97     return cast;
 98   }
 99   case Op_CastLL: {
100     Node* cast = new CastLLNode(n, t, dependency);
101     cast->set_req(0, c);

358   return ConstraintCastNode::cmp(n) && ((CastIINode&)n)._range_check_dependency == _range_check_dependency;
359 }
360 
361 uint CastIINode::size_of() const {
362   return sizeof(*this);
363 }
364 
365 #ifndef PRODUCT
366 void CastIINode::dump_spec(outputStream* st) const {
367   ConstraintCastNode::dump_spec(st);
368   if (_range_check_dependency) {
369     st->print(" range check dependency");
370   }
371 }
372 #endif
373 
374 //=============================================================================
375 //------------------------------Identity---------------------------------------
376 // If input is already higher or equal to cast type, then this is an identity.
377 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {



378   Node* dom = dominating_cast(phase, phase);
379   if (dom != NULL) {
380     return dom;
381   }
382   if (_dependency != RegularDependency) {
383     return this;
384   }
385   const Type* t = phase->type(in(1));
386   if (EnableVectorReboxing && in(1)->Opcode() == Op_VectorBox) {
387     if (t->higher_equal_speculative(phase->type(this))) {
388       return in(1);
389     }
390   } else if (t == phase->type(this)) {
391     // Toned down to rescue meeting at a Phi 3 different oops all implementing
392     // the same interface.
393     return in(1);
394   }
395   return this;
396 }
397 
398 //------------------------------Value------------------------------------------
399 // Take 'join' of input and cast-up type, unless working with an Interface
400 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
401   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
402 
403   const Type *inn = phase->type(in(1));
404   if( inn == Type::TOP ) return Type::TOP;  // No information yet
405 
406   const TypePtr *in_type   = inn->isa_ptr();
407   const TypePtr *my_type   = _type->isa_ptr();
408   const Type *result = _type;
409   if( in_type != NULL && my_type != NULL ) {
410     TypePtr::PTR   in_ptr    = in_type->ptr();









411     if (in_ptr == TypePtr::Null) {
412       result = in_type;
413     } else if (in_ptr == TypePtr::Constant) {
414       if (my_type->isa_rawptr()) {
415         result = my_type;
416       } else {
417         const TypeOopPtr *jptr = my_type->isa_oopptr();
418         assert(jptr, "");
419         result = !in_type->higher_equal(_type)
420           ? my_type->cast_to_ptr_type(TypePtr::NotNull)
421           : in_type;
422       }
423     } else {
424       result =  my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
425     }
426   }
427 
428   // This is the code from TypePtr::xmeet() that prevents us from
429   // having 2 ways to represent the same type. We have to replicate it
430   // here because we don't go through meet/join.

545     break;
546   }
547   return NULL;
548 }
549 
550 //------------------------------Identity---------------------------------------
551 Node* CastX2PNode::Identity(PhaseGVN* phase) {
552   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
553   return this;
554 }
555 
556 //=============================================================================
557 //------------------------------Value------------------------------------------
558 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
559   const Type* t = phase->type(in(1));
560   if (t == Type::TOP) return Type::TOP;
561   if (t->base() == Type::RawPtr && t->singleton()) {
562     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
563     return TypeX::make(bits);
564   }
















565   return CastP2XNode::bottom_type();
566 }
567 
568 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
569   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
570 }
571 
572 //------------------------------Identity---------------------------------------
573 Node* CastP2XNode::Identity(PhaseGVN* phase) {
574   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
575   return this;
576 }
577 
578 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
579   Node* cast= NULL;
580   if (type->isa_int()) {
581     cast = make_cast(Op_CastII, c, in, type, dependency);
582   } else if (type->isa_long()) {
583     cast = make_cast(Op_CastLL, c, in, type, dependency);
584   } 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 
 38 //=============================================================================
 39 // If input is already higher or equal to cast type, then this is an identity.
 40 Node* ConstraintCastNode::Identity(PhaseGVN* phase) {
 41   Node* dom = dominating_cast(phase, phase);
 42   if (dom != NULL) {
 43     return dom;
 44   }
 45   if (_dependency != RegularDependency) {
 46     return this;
 47   }
 48   return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
 49 }
 50 
 51 //------------------------------Value------------------------------------------
 52 // Take 'join' of input and cast-up type
 53 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {
 54   if (in(0) && phase->type(in(0)) == Type::TOP) return Type::TOP;

 64       if( t1 == Type::TOP )  assert(ft == Type::TOP, "special case #1");
 65       const Type* rt = t1->join_speculative(_type);
 66       if (rt->empty())       assert(ft == Type::TOP, "special case #2");
 67       break;
 68     }
 69     case Op_CastPP:
 70     if (phase->type(in(1)) == TypePtr::NULL_PTR &&
 71         _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
 72     assert(ft == Type::TOP, "special case #3");
 73     break;
 74   }
 75 #endif //ASSERT
 76 
 77   return ft;
 78 }
 79 
 80 //------------------------------Ideal------------------------------------------
 81 // Return a node which is more "ideal" than the current node.  Strip out
 82 // control copies
 83 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 84   if (in(0) && remove_dead_region(phase, can_reshape)) {
 85     return this;
 86   }
 87 
 88   // Push cast through InlineTypePtrNode
 89   InlineTypePtrNode* vt = in(1)->isa_InlineTypePtr();
 90   if (vt != NULL && phase->type(vt)->filter_speculative(_type) != Type::TOP) {
 91     Node* cast = clone();
 92     cast->set_req(1, vt->get_oop());
 93     vt = vt->clone()->as_InlineTypePtr();
 94     vt->set_oop(phase->transform(cast));
 95     return vt;
 96   }
 97 
 98   return NULL;
 99 }
100 
101 bool ConstraintCastNode::cmp(const Node &n) const {
102   return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._dependency == _dependency;
103 }
104 
105 uint ConstraintCastNode::size_of() const {
106   return sizeof(*this);
107 }
108 
109 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, DependencyType dependency) {
110   switch(opcode) {
111   case Op_CastII: {
112     Node* cast = new CastIINode(n, t, dependency);
113     cast->set_req(0, c);
114     return cast;
115   }
116   case Op_CastLL: {
117     Node* cast = new CastLLNode(n, t, dependency);
118     cast->set_req(0, c);

375   return ConstraintCastNode::cmp(n) && ((CastIINode&)n)._range_check_dependency == _range_check_dependency;
376 }
377 
378 uint CastIINode::size_of() const {
379   return sizeof(*this);
380 }
381 
382 #ifndef PRODUCT
383 void CastIINode::dump_spec(outputStream* st) const {
384   ConstraintCastNode::dump_spec(st);
385   if (_range_check_dependency) {
386     st->print(" range check dependency");
387   }
388 }
389 #endif
390 
391 //=============================================================================
392 //------------------------------Identity---------------------------------------
393 // If input is already higher or equal to cast type, then this is an identity.
394 Node* CheckCastPPNode::Identity(PhaseGVN* phase) {
395   if (in(1)->is_InlineTypeBase() && _type->isa_oopptr() && phase->type(in(1))->inline_klass()->is_subtype_of(_type->is_oopptr()->klass())) {
396     return in(1);
397   }
398   Node* dom = dominating_cast(phase, phase);
399   if (dom != NULL) {
400     return dom;
401   }
402   if (_dependency != RegularDependency) {
403     return this;
404   }
405   const Type* t = phase->type(in(1));
406   if (EnableVectorReboxing && in(1)->Opcode() == Op_VectorBox) {
407     if (t->higher_equal_speculative(phase->type(this))) {
408       return in(1);
409     }
410   } else if (t == phase->type(this)) {
411     // Toned down to rescue meeting at a Phi 3 different oops all implementing
412     // the same interface.
413     return in(1);
414   }
415   return this;
416 }
417 
418 //------------------------------Value------------------------------------------
419 // Take 'join' of input and cast-up type, unless working with an Interface
420 const Type* CheckCastPPNode::Value(PhaseGVN* phase) const {
421   if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
422 
423   const Type *inn = phase->type(in(1));
424   if( inn == Type::TOP ) return Type::TOP;  // No information yet
425 
426   const TypePtr *in_type   = inn->isa_ptr();
427   const TypePtr *my_type   = _type->isa_ptr();
428   const Type *result = _type;
429   if (in_type != NULL && my_type != NULL) {
430     if (!StressReflectiveCode && my_type->isa_aryptr() && in_type->isa_aryptr()) {
431       // Propagate array properties (not flat/null-free)
432       // Don't do this when StressReflectiveCode is enabled because it might lead to
433       // a dying data path while the corresponding flat/null-free check is not folded.
434       my_type = my_type->is_aryptr()->update_properties(in_type->is_aryptr());
435       if (my_type == NULL) {
436         return Type::TOP; // Inconsistent properties
437       }
438     }
439     TypePtr::PTR in_ptr = in_type->ptr();
440     if (in_ptr == TypePtr::Null) {
441       result = in_type;
442     } else if (in_ptr == TypePtr::Constant) {
443       if (my_type->isa_rawptr()) {
444         result = my_type;
445       } else {
446         const TypeOopPtr *jptr = my_type->isa_oopptr();
447         assert(jptr, "");
448         result = !in_type->higher_equal(_type)
449           ? my_type->cast_to_ptr_type(TypePtr::NotNull)
450           : in_type;
451       }
452     } else {
453       result =  my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
454     }
455   }
456 
457   // This is the code from TypePtr::xmeet() that prevents us from
458   // having 2 ways to represent the same type. We have to replicate it
459   // here because we don't go through meet/join.

574     break;
575   }
576   return NULL;
577 }
578 
579 //------------------------------Identity---------------------------------------
580 Node* CastX2PNode::Identity(PhaseGVN* phase) {
581   if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
582   return this;
583 }
584 
585 //=============================================================================
586 //------------------------------Value------------------------------------------
587 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
588   const Type* t = phase->type(in(1));
589   if (t == Type::TOP) return Type::TOP;
590   if (t->base() == Type::RawPtr && t->singleton()) {
591     uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
592     return TypeX::make(bits);
593   }
594 
595   if (t->is_zero_type() || !t->maybe_null()) {
596     for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
597       Node* u = fast_out(i);
598       if (u->Opcode() == Op_OrL) {
599         for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
600           Node* cmp = u->fast_out(j);
601           if (cmp->Opcode() == Op_CmpL) {
602             // Give CmpL a chance to get optimized
603             phase->record_for_igvn(cmp);
604           }
605         }
606       }
607     }
608   }
609 
610   return CastP2XNode::bottom_type();
611 }
612 
613 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
614   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
615 }
616 
617 //------------------------------Identity---------------------------------------
618 Node* CastP2XNode::Identity(PhaseGVN* phase) {
619   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
620   return this;
621 }
622 
623 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
624   Node* cast= NULL;
625   if (type->isa_int()) {
626     cast = make_cast(Op_CastII, c, in, type, dependency);
627   } else if (type->isa_long()) {
628     cast = make_cast(Op_CastLL, c, in, type, dependency);
629   } else if (type->isa_float()) {
< prev index next >