1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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 #ifndef SHARE_VM_OPTO_CASTNODE_HPP
  26 #define SHARE_VM_OPTO_CASTNODE_HPP
  27 
  28 #include "opto/node.hpp"
  29 #include "opto/opcodes.hpp"
  30 
  31 
  32 //------------------------------ConstraintCastNode-----------------------------
  33 // cast to a different range
  34 class ConstraintCastNode: public TypeNode {
  35   protected:
  36   // Can this node be removed post CCP or does it carry a required dependency?
  37   const bool _carry_dependency;
  38   virtual uint cmp( const Node &n ) const;
  39   virtual uint size_of() const;
  40 
  41   public:
  42   ConstraintCastNode(Node *n, const Type *t, bool carry_dependency)
  43     : TypeNode(t,2), _carry_dependency(carry_dependency) {
  44     init_class_id(Class_ConstraintCast);
  45     init_req(1, n);
  46   }
  47   virtual Node* Identity(PhaseGVN* phase);
  48   virtual const Type* Value(PhaseGVN* phase) const;
  49   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
  50   virtual int Opcode() const;
  51   virtual uint ideal_reg() const = 0;
  52   virtual bool depends_only_on_test() const { return !_carry_dependency; }
  53   bool carry_dependency() const { return _carry_dependency; }
  54   TypeNode* dominating_cast(PhaseTransform *phase) const;
  55   static Node* make_cast(int opcode,  Node* c, Node *n, const Type *t, bool carry_dependency);
  56 
  57 #ifndef PRODUCT
  58   virtual void dump_spec(outputStream *st) const;
  59 #endif
  60 };
  61 
  62 //------------------------------CastIINode-------------------------------------
  63 // cast integer to integer (different range)
  64 class CastIINode: public ConstraintCastNode {
  65   protected:
  66   // Is this node dependent on a range check?
  67   const bool _range_check_dependency;
  68   virtual uint cmp(const Node &n) const;
  69   virtual uint size_of() const;
  70 
  71   public:
  72   CastIINode(Node* n, const Type* t, bool carry_dependency = false, bool range_check_dependency = false)
  73     : ConstraintCastNode(n, t, carry_dependency), _range_check_dependency(range_check_dependency) {
  74     init_class_id(Class_CastII);
  75   }
  76   virtual int Opcode() const;
  77   virtual uint ideal_reg() const { return Op_RegI; }
  78   virtual const Type* Value(PhaseGVN* phase) const;
  79   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
  80   const bool has_range_check() { return _range_check_dependency; }
  81 #ifndef PRODUCT
  82   virtual void dump_spec(outputStream* st) const;
  83 #endif
  84 };
  85 
  86 //------------------------------CastPPNode-------------------------------------
  87 // cast pointer to pointer (different type)
  88 class CastPPNode: public ConstraintCastNode {
  89   public:
  90   CastPPNode (Node *n, const Type *t, bool carry_dependency = false)
  91     : ConstraintCastNode(n, t, carry_dependency) {
  92   }
  93   virtual int Opcode() const;
  94   virtual uint ideal_reg() const { return Op_RegP; }
  95 };
  96 
  97 //------------------------------CheckCastPPNode--------------------------------
  98 // for _checkcast, cast pointer to pointer (different type), without JOIN,
  99 class CheckCastPPNode: public ConstraintCastNode {
 100   public:
 101   CheckCastPPNode(Node *c, Node *n, const Type *t, bool carry_dependency = false)
 102     : ConstraintCastNode(n, t, carry_dependency) {
 103     init_class_id(Class_CheckCastPP);
 104     init_req(0, c);
 105   }
 106 
 107   virtual Node* Identity(PhaseGVN* phase);
 108   virtual const Type* Value(PhaseGVN* phase) const;
 109   virtual int   Opcode() const;
 110   virtual uint  ideal_reg() const { return Op_RegP; }
 111 };
 112 
 113 
 114 //------------------------------CastX2PNode-------------------------------------
 115 // convert a machine-pointer-sized integer to a raw pointer
 116 class CastX2PNode : public Node {
 117   public:
 118   CastX2PNode( Node *n ) : Node(NULL, n) {}
 119   virtual int Opcode() const;
 120   virtual const Type* Value(PhaseGVN* phase) const;
 121   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 122   virtual Node* Identity(PhaseGVN* phase);
 123   virtual uint ideal_reg() const { return Op_RegP; }
 124   virtual const Type *bottom_type() const { return TypeRawPtr::BOTTOM; }
 125 };
 126 
 127 //------------------------------CastP2XNode-------------------------------------
 128 // Used in both 32-bit and 64-bit land.
 129 // Used for card-marks and unsafe pointer math.
 130 class CastP2XNode : public Node {
 131   public:
 132   CastP2XNode( Node *ctrl, Node *n ) : Node(ctrl, n) {}
 133   virtual int Opcode() const;
 134   virtual const Type* Value(PhaseGVN* phase) const;
 135   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 136   virtual Node* Identity(PhaseGVN* phase);
 137   virtual uint ideal_reg() const { return Op_RegX; }
 138   virtual const Type *bottom_type() const { return TypeX_X; }
 139   // Return false to keep node from moving away from an associated card mark.
 140   virtual bool depends_only_on_test() const { return false; }
 141 };
 142 
 143 
 144 
 145 #endif // SHARE_VM_OPTO_CASTNODE_HPP