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