< 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);

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



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









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

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
















566   return CastP2XNode::bottom_type();
567 }
568 
569 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
570   return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
571 }
572 
573 //------------------------------Identity---------------------------------------
574 Node* CastP2XNode::Identity(PhaseGVN* phase) {
575   if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
576   return this;
577 }
578 
579 Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency) {
580   Node* cast= NULL;
581   if (type->isa_int()) {
582     cast = make_cast(Op_CastII, c, in, type, dependency);
583   } else if (type->isa_long()) {
584     cast = make_cast(Op_CastLL, c, in, type, dependency);
585   } 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);

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

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