1 #ifdef USE_PRAGMA_IDENT_HDR 2 #pragma ident "@(#)addnode.hpp 1.59 07/10/23 13:12:52 JVM" 3 #endif 4 /* 5 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 // Portions of code courtesy of Clifford Click 29 30 class PhaseTransform; 31 32 //------------------------------AddNode---------------------------------------- 33 // Classic Add functionality. This covers all the usual 'add' behaviors for 34 // an algebraic ring. Add-integer, add-float, add-double, and binary-or are 35 // all inherited from this class. The various identity values are supplied 36 // by virtual functions. 37 class AddNode : public Node { 38 virtual uint hash() const; 39 public: 40 AddNode( Node *in1, Node *in2 ) : Node(0,in1,in2) { 41 init_class_id(Class_Add); 42 } 43 44 // Handle algebraic identities here. If we have an identity, return the Node 45 // we are equivalent to. We look for "add of zero" as an identity. 46 virtual Node *Identity( PhaseTransform *phase ); 47 48 // We also canonicalize the Node, moving constants to the right input, 49 // and flatten expressions (so that 1+x+2 becomes x+3). 50 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 51 52 // Compute a new Type for this node. Basically we just do the pre-check, 53 // then call the virtual add() to set the type. 54 virtual const Type *Value( PhaseTransform *phase ) const; 55 56 // Check if this addition involves the additive identity 57 virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const; 58 59 // Supplied function returns the sum of the inputs. 60 // This also type-checks the inputs for sanity. Guaranteed never to 61 // be passed a TOP or BOTTOM type, these are filtered out by a pre-check. 62 virtual const Type *add_ring( const Type *, const Type * ) const = 0; 63 64 // Supplied function to return the additive identity type 65 virtual const Type *add_id() const = 0; 66 67 }; 68 69 //------------------------------AddINode--------------------------------------- 70 // Add 2 integers 71 class AddINode : public AddNode { 72 public: 73 AddINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 74 virtual int Opcode() const; 75 virtual const Type *add_ring( const Type *, const Type * ) const; 76 virtual const Type *add_id() const { return TypeInt::ZERO; } 77 virtual const Type *bottom_type() const { return TypeInt::INT; } 78 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 79 virtual Node *Identity( PhaseTransform *phase ); 80 virtual uint ideal_reg() const { return Op_RegI; } 81 }; 82 83 //------------------------------AddLNode--------------------------------------- 84 // Add 2 longs 85 class AddLNode : public AddNode { 86 public: 87 AddLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 88 virtual int Opcode() const; 89 virtual const Type *add_ring( const Type *, const Type * ) const; 90 virtual const Type *add_id() const { return TypeLong::ZERO; } 91 virtual const Type *bottom_type() const { return TypeLong::LONG; } 92 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 93 virtual Node *Identity( PhaseTransform *phase ); 94 virtual uint ideal_reg() const { return Op_RegL; } 95 }; 96 97 //------------------------------AddFNode--------------------------------------- 98 // Add 2 floats 99 class AddFNode : public AddNode { 100 public: 101 AddFNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 102 virtual int Opcode() const; 103 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 104 virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const; 105 virtual const Type *add_ring( const Type *, const Type * ) const; 106 virtual const Type *add_id() const { return TypeF::ZERO; } 107 virtual const Type *bottom_type() const { return Type::FLOAT; } 108 virtual Node *Identity( PhaseTransform *phase ) { return this; } 109 virtual uint ideal_reg() const { return Op_RegF; } 110 }; 111 112 //------------------------------AddDNode--------------------------------------- 113 // Add 2 doubles 114 class AddDNode : public AddNode { 115 public: 116 AddDNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 117 virtual int Opcode() const; 118 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 119 virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const; 120 virtual const Type *add_ring( const Type *, const Type * ) const; 121 virtual const Type *add_id() const { return TypeD::ZERO; } 122 virtual const Type *bottom_type() const { return Type::DOUBLE; } 123 virtual Node *Identity( PhaseTransform *phase ) { return this; } 124 virtual uint ideal_reg() const { return Op_RegD; } 125 }; 126 127 //------------------------------AddPNode--------------------------------------- 128 // Add pointer plus integer to get pointer. NOT commutative, really. 129 // So not really an AddNode. Lives here, because people associate it with 130 // an add. 131 class AddPNode : public Node { 132 public: 133 enum { Control, // When is it safe to do this add? 134 Base, // Base oop, for GC purposes 135 Address, // Actually address, derived from base 136 Offset } ; // Offset added to address 137 AddPNode( Node *base, Node *ptr, Node *off ) : Node(0,base,ptr,off) { 138 init_class_id(Class_AddP); 139 } 140 virtual int Opcode() const; 141 virtual Node *Identity( PhaseTransform *phase ); 142 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 143 virtual const Type *Value( PhaseTransform *phase ) const; 144 virtual const Type *bottom_type() const; 145 virtual uint ideal_reg() const { return Op_RegP; } 146 Node *base_node() { assert( req() > Base, "Missing base"); return in(Base); } 147 static Node* Ideal_base_and_offset(Node* ptr, PhaseTransform* phase, 148 // second return value: 149 intptr_t& offset); 150 151 // Collect the AddP offset values into the elements array, giving up 152 // if there are more than length. 153 int unpack_offsets(Node* elements[], int length); 154 155 // Do not match base-ptr edge 156 virtual uint match_edge(uint idx) const; 157 static const Type *mach_bottom_type(const MachNode* n); // used by ad_<arch>.hpp 158 }; 159 160 //------------------------------OrINode---------------------------------------- 161 // Logically OR 2 integers. Included with the ADD nodes because it inherits 162 // all the behavior of addition on a ring. 163 class OrINode : public AddNode { 164 public: 165 OrINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 166 virtual int Opcode() const; 167 virtual const Type *add_ring( const Type *, const Type * ) const; 168 virtual const Type *add_id() const { return TypeInt::ZERO; } 169 virtual const Type *bottom_type() const { return TypeInt::INT; } 170 virtual Node *Identity( PhaseTransform *phase ); 171 virtual uint ideal_reg() const { return Op_RegI; } 172 }; 173 174 //------------------------------OrLNode---------------------------------------- 175 // Logically OR 2 longs. Included with the ADD nodes because it inherits 176 // all the behavior of addition on a ring. 177 class OrLNode : public AddNode { 178 public: 179 OrLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 180 virtual int Opcode() const; 181 virtual const Type *add_ring( const Type *, const Type * ) const; 182 virtual const Type *add_id() const { return TypeLong::ZERO; } 183 virtual const Type *bottom_type() const { return TypeLong::LONG; } 184 virtual Node *Identity( PhaseTransform *phase ); 185 virtual uint ideal_reg() const { return Op_RegL; } 186 }; 187 188 //------------------------------XorINode--------------------------------------- 189 // XOR'ing 2 integers 190 class XorINode : public AddNode { 191 public: 192 XorINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 193 virtual int Opcode() const; 194 virtual const Type *add_ring( const Type *, const Type * ) const; 195 virtual const Type *add_id() const { return TypeInt::ZERO; } 196 virtual const Type *bottom_type() const { return TypeInt::INT; } 197 virtual uint ideal_reg() const { return Op_RegI; } 198 }; 199 200 //------------------------------XorINode--------------------------------------- 201 // XOR'ing 2 longs 202 class XorLNode : public AddNode { 203 public: 204 XorLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 205 virtual int Opcode() const; 206 virtual const Type *add_ring( const Type *, const Type * ) const; 207 virtual const Type *add_id() const { return TypeLong::ZERO; } 208 virtual const Type *bottom_type() const { return TypeLong::LONG; } 209 virtual uint ideal_reg() const { return Op_RegL; } 210 }; 211 212 //------------------------------MaxNode---------------------------------------- 213 // Max (or min) of 2 values. Included with the ADD nodes because it inherits 214 // all the behavior of addition on a ring. Only new thing is that we allow 215 // 2 equal inputs to be equal. 216 class MaxNode : public AddNode { 217 public: 218 MaxNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 219 virtual int Opcode() const = 0; 220 }; 221 222 //------------------------------MaxINode--------------------------------------- 223 // Maximum of 2 integers. Included with the ADD nodes because it inherits 224 // all the behavior of addition on a ring. 225 class MaxINode : public MaxNode { 226 public: 227 MaxINode( Node *in1, Node *in2 ) : MaxNode(in1,in2) {} 228 virtual int Opcode() const; 229 virtual const Type *add_ring( const Type *, const Type * ) const; 230 virtual const Type *add_id() const { return TypeInt::make(min_jint); } 231 virtual const Type *bottom_type() const { return TypeInt::INT; } 232 virtual uint ideal_reg() const { return Op_RegI; } 233 }; 234 235 //------------------------------MinINode--------------------------------------- 236 // MINimum of 2 integers. Included with the ADD nodes because it inherits 237 // all the behavior of addition on a ring. 238 class MinINode : public MaxNode { 239 public: 240 MinINode( Node *in1, Node *in2 ) : MaxNode(in1,in2) {} 241 virtual int Opcode() const; 242 virtual const Type *add_ring( const Type *, const Type * ) const; 243 virtual const Type *add_id() const { return TypeInt::make(max_jint); } 244 virtual const Type *bottom_type() const { return TypeInt::INT; } 245 virtual uint ideal_reg() const { return Op_RegI; } 246 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 247 };