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

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;

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

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