1 /* 2 * Copyright (c) 1997, 2010, 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_ADDNODE_HPP 26 #define SHARE_VM_OPTO_ADDNODE_HPP 27 28 #include "opto/node.hpp" 29 #include "opto/opcodes.hpp" 30 #include "opto/type.hpp" 31 32 // Portions of code courtesy of Clifford Click 33 34 class PhaseTransform; 35 36 //------------------------------AddNode---------------------------------------- 37 // Classic Add functionality. This covers all the usual 'add' behaviors for 38 // an algebraic ring. Add-integer, add-float, add-double, and binary-or are 39 // all inherited from this class. The various identity values are supplied 40 // by virtual functions. 41 class AddNode : public Node { 42 virtual uint hash() const; 43 public: 44 AddNode(Node *in1, Node *in2) : Node(0,in1,in2) { 45 init_class_id(Class_Add); 46 } 47 48 // Handle algebraic identities here. If we have an identity, return the Node 49 // we are equivalent to. We look for "add of zero" as an identity. 50 virtual Node* Identity(PhaseGVN* phase); 51 52 // We also canonicalize the Node, moving constants to the right input, 53 // and flatten expressions (so that 1+x+2 becomes x+3). 54 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 55 56 // Compute a new Type for this node. Basically we just do the pre-check, 57 // then call the virtual add() to set the type. 58 virtual const Type* Value(PhaseGVN* phase) const; 59 60 // Check if this addition involves the additive identity 61 virtual const Type *add_of_identity(const Type *t1, const Type *t2) const; 62 63 // Supplied function returns the sum of the inputs. 64 // This also type-checks the inputs for sanity. Guaranteed never to 65 // be passed a TOP or BOTTOM type, these are filtered out by a pre-check. 66 virtual const Type *add_ring(const Type*, const Type*) const = 0; 67 68 // Supplied function to return the additive identity type 69 virtual const Type *add_id() const = 0; 70 71 static AddNode* make(BasicType bt, Node *in1, Node *in2); 72 }; 73 74 //------------------------------AddINode--------------------------------------- 75 // Add 2 integers 76 class AddINode : public AddNode { 77 public: 78 AddINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 79 virtual int Opcode() const; 80 virtual const Type *add_ring( const Type *, const Type * ) const; 81 virtual const Type *add_id() const { return TypeInt::ZERO; } 82 virtual const Type *bottom_type() const { return TypeInt::INT; } 83 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 84 virtual Node* Identity(PhaseGVN* phase); 85 virtual uint ideal_reg() const { return Op_RegI; } 86 }; 87 88 //------------------------------AddLNode--------------------------------------- 89 // Add 2 longs 90 class AddLNode : public AddNode { 91 public: 92 AddLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 93 virtual int Opcode() const; 94 virtual const Type *add_ring( const Type *, const Type * ) const; 95 virtual const Type *add_id() const { return TypeLong::ZERO; } 96 virtual const Type *bottom_type() const { return TypeLong::LONG; } 97 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 98 virtual Node* Identity(PhaseGVN* phase); 99 virtual uint ideal_reg() const { return Op_RegL; } 100 }; 101 102 //------------------------------AddFNode--------------------------------------- 103 // Add 2 floats 104 class AddFNode : public AddNode { 105 public: 106 AddFNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 107 virtual int Opcode() const; 108 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 109 virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const; 110 virtual const Type *add_ring( const Type *, const Type * ) const; 111 virtual const Type *add_id() const { return TypeF::ZERO; } 112 virtual const Type *bottom_type() const { return Type::FLOAT; } 113 virtual Node* Identity(PhaseGVN* phase) { return this; } 114 virtual uint ideal_reg() const { return Op_RegF; } 115 }; 116 117 //------------------------------AddDNode--------------------------------------- 118 // Add 2 doubles 119 class AddDNode : public AddNode { 120 public: 121 AddDNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 122 virtual int Opcode() const; 123 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 124 virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const; 125 virtual const Type *add_ring( const Type *, const Type * ) const; 126 virtual const Type *add_id() const { return TypeD::ZERO; } 127 virtual const Type *bottom_type() const { return Type::DOUBLE; } 128 virtual Node* Identity(PhaseGVN* phase) { return this; } 129 virtual uint ideal_reg() const { return Op_RegD; } 130 }; 131 132 //------------------------------AddPNode--------------------------------------- 133 // Add pointer plus integer to get pointer. NOT commutative, really. 134 // So not really an AddNode. Lives here, because people associate it with 135 // an add. 136 class AddPNode : public Node { 137 public: 138 enum { Control, // When is it safe to do this add? 139 Base, // Base oop, for GC purposes 140 Address, // Actually address, derived from base 141 Offset } ; // Offset added to address 142 AddPNode( Node *base, Node *ptr, Node *off ) : Node(0,base,ptr,off) { 143 init_class_id(Class_AddP); 144 } 145 virtual int Opcode() const; 146 virtual Node* Identity(PhaseGVN* phase); 147 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 148 virtual const Type* Value(PhaseGVN* phase) const; 149 virtual const Type *bottom_type() const; 150 virtual uint ideal_reg() const { return Op_RegP; } 151 Node *base_node() { assert( req() > Base, "Missing base"); return in(Base); } 152 static Node* Ideal_base_and_offset(Node* ptr, PhaseTransform* phase, 153 // second return value: 154 intptr_t& offset); 155 156 // Collect the AddP offset values into the elements array, giving up 157 // if there are more than length. 158 int unpack_offsets(Node* elements[], int length); 159 160 // Do not match base-ptr edge 161 virtual uint match_edge(uint idx) const; 162 }; 163 164 //------------------------------OrINode---------------------------------------- 165 // Logically OR 2 integers. Included with the ADD nodes because it inherits 166 // all the behavior of addition on a ring. 167 class OrINode : public AddNode { 168 public: 169 OrINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 170 virtual int Opcode() const; 171 virtual const Type *add_ring( const Type *, const Type * ) const; 172 virtual const Type *add_id() const { return TypeInt::ZERO; } 173 virtual const Type *bottom_type() const { return TypeInt::INT; } 174 virtual Node* Identity(PhaseGVN* phase); 175 virtual uint ideal_reg() const { return Op_RegI; } 176 }; 177 178 //------------------------------OrLNode---------------------------------------- 179 // Logically OR 2 longs. Included with the ADD nodes because it inherits 180 // all the behavior of addition on a ring. 181 class OrLNode : public AddNode { 182 public: 183 OrLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 184 virtual int Opcode() const; 185 virtual const Type *add_ring( const Type *, const Type * ) const; 186 virtual const Type *add_id() const { return TypeLong::ZERO; } 187 virtual const Type *bottom_type() const { return TypeLong::LONG; } 188 virtual Node* Identity(PhaseGVN* phase); 189 virtual uint ideal_reg() const { return Op_RegL; } 190 }; 191 192 //------------------------------XorINode--------------------------------------- 193 // XOR'ing 2 integers 194 class XorINode : public AddNode { 195 public: 196 XorINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 197 virtual int Opcode() const; 198 virtual const Type *add_ring( const Type *, const Type * ) const; 199 virtual const Type *add_id() const { return TypeInt::ZERO; } 200 virtual const Type *bottom_type() const { return TypeInt::INT; } 201 virtual uint ideal_reg() const { return Op_RegI; } 202 }; 203 204 //------------------------------XorINode--------------------------------------- 205 // XOR'ing 2 longs 206 class XorLNode : public AddNode { 207 public: 208 XorLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 209 virtual int Opcode() const; 210 virtual const Type *add_ring( const Type *, const Type * ) const; 211 virtual const Type *add_id() const { return TypeLong::ZERO; } 212 virtual const Type *bottom_type() const { return TypeLong::LONG; } 213 virtual uint ideal_reg() const { return Op_RegL; } 214 }; 215 216 //------------------------------MaxNode---------------------------------------- 217 // Max (or min) of 2 values. Included with the ADD nodes because it inherits 218 // all the behavior of addition on a ring. Only new thing is that we allow 219 // 2 equal inputs to be equal. 220 class MaxNode : public AddNode { 221 public: 222 MaxNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {} 223 virtual int Opcode() const = 0; 224 }; 225 226 //------------------------------MaxINode--------------------------------------- 227 // Maximum of 2 integers. Included with the ADD nodes because it inherits 228 // all the behavior of addition on a ring. 229 class MaxINode : public MaxNode { 230 public: 231 MaxINode( Node *in1, Node *in2 ) : MaxNode(in1,in2) {} 232 virtual int Opcode() const; 233 virtual const Type *add_ring( const Type *, const Type * ) const; 234 virtual const Type *add_id() const { return TypeInt::make(min_jint); } 235 virtual const Type *bottom_type() const { return TypeInt::INT; } 236 virtual uint ideal_reg() const { return Op_RegI; } 237 }; 238 239 //------------------------------MinINode--------------------------------------- 240 // MINimum of 2 integers. Included with the ADD nodes because it inherits 241 // all the behavior of addition on a ring. 242 class MinINode : public MaxNode { 243 public: 244 MinINode( Node *in1, Node *in2 ) : MaxNode(in1,in2) {} 245 virtual int Opcode() const; 246 virtual const Type *add_ring( const Type *, const Type * ) const; 247 virtual const Type *add_id() const { return TypeInt::make(max_jint); } 248 virtual const Type *bottom_type() const { return TypeInt::INT; } 249 virtual uint ideal_reg() const { return Op_RegI; } 250 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 251 }; 252 253 #endif // SHARE_VM_OPTO_ADDNODE_HPP