Tue, 09 Mar 2010 20:16:19 +0100
6919934: JSR 292 needs to support x86 C1
Summary: This implements JSR 292 support for C1 x86.
Reviewed-by: never, jrose, kvn
1 /*
2 * Copyright 1997-2008 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 */
25 // Portions of code courtesy of Clifford Click
27 class PhaseTransform;
29 //------------------------------MulNode----------------------------------------
30 // Classic MULTIPLY functionality. This covers all the usual 'multiply'
31 // behaviors for an algebraic ring. Multiply-integer, multiply-float,
32 // multiply-double, and binary-and are all inherited from this class. The
33 // various identity values are supplied by virtual functions.
34 class MulNode : public Node {
35 virtual uint hash() const;
36 public:
37 MulNode( Node *in1, Node *in2 ): Node(0,in1,in2) {
38 init_class_id(Class_Mul);
39 }
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 );
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);
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;
53 // Supplied function returns the product of the inputs.
54 // This also type-checks the inputs for sanity. Guaranteed never to
55 // be passed a TOP or BOTTOM type, these are filtered out by a pre-check.
56 // This call recognizes the multiplicative zero type.
57 virtual const Type *mul_ring( const Type *, const Type * ) const = 0;
59 // Supplied function to return the multiplicative identity type
60 virtual const Type *mul_id() const = 0;
62 // Supplied function to return the additive identity type
63 virtual const Type *add_id() const = 0;
65 // Supplied function to return the additive opcode
66 virtual int add_opcode() const = 0;
68 // Supplied function to return the multiplicative opcode
69 virtual int mul_opcode() const = 0;
71 };
73 //------------------------------MulINode---------------------------------------
74 // Multiply 2 integers
75 class MulINode : public MulNode {
76 public:
77 MulINode( Node *in1, Node *in2 ) : MulNode(in1,in2) {}
78 virtual int Opcode() const;
79 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
80 virtual const Type *mul_ring( const Type *, const Type * ) const;
81 const Type *mul_id() const { return TypeInt::ONE; }
82 const Type *add_id() const { return TypeInt::ZERO; }
83 int add_opcode() const { return Op_AddI; }
84 int mul_opcode() const { return Op_MulI; }
85 const Type *bottom_type() const { return TypeInt::INT; }
86 virtual uint ideal_reg() const { return Op_RegI; }
87 };
89 //------------------------------MulLNode---------------------------------------
90 // Multiply 2 longs
91 class MulLNode : public MulNode {
92 public:
93 MulLNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {}
94 virtual int Opcode() const;
95 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
96 virtual const Type *mul_ring( const Type *, const Type * ) const;
97 const Type *mul_id() const { return TypeLong::ONE; }
98 const Type *add_id() const { return TypeLong::ZERO; }
99 int add_opcode() const { return Op_AddL; }
100 int mul_opcode() const { return Op_MulL; }
101 const Type *bottom_type() const { return TypeLong::LONG; }
102 virtual uint ideal_reg() const { return Op_RegL; }
103 };
106 //------------------------------MulFNode---------------------------------------
107 // Multiply 2 floats
108 class MulFNode : public MulNode {
109 public:
110 MulFNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {}
111 virtual int Opcode() const;
112 virtual const Type *mul_ring( const Type *, const Type * ) const;
113 const Type *mul_id() const { return TypeF::ONE; }
114 const Type *add_id() const { return TypeF::ZERO; }
115 int add_opcode() const { return Op_AddF; }
116 int mul_opcode() const { return Op_MulF; }
117 const Type *bottom_type() const { return Type::FLOAT; }
118 virtual uint ideal_reg() const { return Op_RegF; }
119 };
121 //------------------------------MulDNode---------------------------------------
122 // Multiply 2 doubles
123 class MulDNode : public MulNode {
124 public:
125 MulDNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {}
126 virtual int Opcode() const;
127 virtual const Type *mul_ring( const Type *, const Type * ) const;
128 const Type *mul_id() const { return TypeD::ONE; }
129 const Type *add_id() const { return TypeD::ZERO; }
130 int add_opcode() const { return Op_AddD; }
131 int mul_opcode() const { return Op_MulD; }
132 const Type *bottom_type() const { return Type::DOUBLE; }
133 virtual uint ideal_reg() const { return Op_RegD; }
134 };
136 //-------------------------------MulHiLNode------------------------------------
137 // Upper 64 bits of a 64 bit by 64 bit multiply
138 class MulHiLNode : public Node {
139 public:
140 MulHiLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
141 virtual int Opcode() const;
142 virtual const Type *Value( PhaseTransform *phase ) const;
143 const Type *bottom_type() const { return TypeLong::LONG; }
144 virtual uint ideal_reg() const { return Op_RegL; }
145 };
147 //------------------------------AndINode---------------------------------------
148 // Logically AND 2 integers. Included with the MUL nodes because it inherits
149 // all the behavior of multiplication on a ring.
150 class AndINode : public MulINode {
151 public:
152 AndINode( Node *in1, Node *in2 ) : MulINode(in1,in2) {}
153 virtual int Opcode() const;
154 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
155 virtual Node *Identity( PhaseTransform *phase );
156 virtual const Type *mul_ring( const Type *, const Type * ) const;
157 const Type *mul_id() const { return TypeInt::MINUS_1; }
158 const Type *add_id() const { return TypeInt::ZERO; }
159 int add_opcode() const { return Op_OrI; }
160 int mul_opcode() const { return Op_AndI; }
161 virtual uint ideal_reg() const { return Op_RegI; }
162 };
164 //------------------------------AndINode---------------------------------------
165 // Logically AND 2 longs. Included with the MUL nodes because it inherits
166 // all the behavior of multiplication on a ring.
167 class AndLNode : public MulLNode {
168 public:
169 AndLNode( Node *in1, Node *in2 ) : MulLNode(in1,in2) {}
170 virtual int Opcode() const;
171 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
172 virtual Node *Identity( PhaseTransform *phase );
173 virtual const Type *mul_ring( const Type *, const Type * ) const;
174 const Type *mul_id() const { return TypeLong::MINUS_1; }
175 const Type *add_id() const { return TypeLong::ZERO; }
176 int add_opcode() const { return Op_OrL; }
177 int mul_opcode() const { return Op_AndL; }
178 virtual uint ideal_reg() const { return Op_RegL; }
179 };
181 //------------------------------LShiftINode------------------------------------
182 // Logical shift left
183 class LShiftINode : public Node {
184 public:
185 LShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
186 virtual int Opcode() const;
187 virtual Node *Identity( PhaseTransform *phase );
188 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
189 virtual const Type *Value( PhaseTransform *phase ) const;
190 const Type *bottom_type() const { return TypeInt::INT; }
191 virtual uint ideal_reg() const { return Op_RegI; }
192 };
194 //------------------------------LShiftLNode------------------------------------
195 // Logical shift left
196 class LShiftLNode : public Node {
197 public:
198 LShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
199 virtual int Opcode() const;
200 virtual Node *Identity( PhaseTransform *phase );
201 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
202 virtual const Type *Value( PhaseTransform *phase ) const;
203 const Type *bottom_type() const { return TypeLong::LONG; }
204 virtual uint ideal_reg() const { return Op_RegL; }
205 };
207 //------------------------------RShiftINode------------------------------------
208 // Signed shift right
209 class RShiftINode : public Node {
210 public:
211 RShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
212 virtual int Opcode() const;
213 virtual Node *Identity( PhaseTransform *phase );
214 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
215 virtual const Type *Value( PhaseTransform *phase ) const;
216 const Type *bottom_type() const { return TypeInt::INT; }
217 virtual uint ideal_reg() const { return Op_RegI; }
218 };
220 //------------------------------RShiftLNode------------------------------------
221 // Signed shift right
222 class RShiftLNode : public Node {
223 public:
224 RShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
225 virtual int Opcode() const;
226 virtual Node *Identity( PhaseTransform *phase );
227 virtual const Type *Value( PhaseTransform *phase ) const;
228 const Type *bottom_type() const { return TypeLong::LONG; }
229 virtual uint ideal_reg() const { return Op_RegL; }
230 };
233 //------------------------------URShiftINode-----------------------------------
234 // Logical shift right
235 class URShiftINode : public Node {
236 public:
237 URShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
238 virtual int Opcode() const;
239 virtual Node *Identity( PhaseTransform *phase );
240 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
241 virtual const Type *Value( PhaseTransform *phase ) const;
242 const Type *bottom_type() const { return TypeInt::INT; }
243 virtual uint ideal_reg() const { return Op_RegI; }
244 };
246 //------------------------------URShiftLNode-----------------------------------
247 // Logical shift right
248 class URShiftLNode : public Node {
249 public:
250 URShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
251 virtual int Opcode() const;
252 virtual Node *Identity( PhaseTransform *phase );
253 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
254 virtual const Type *Value( PhaseTransform *phase ) const;
255 const Type *bottom_type() const { return TypeLong::LONG; }
256 virtual uint ideal_reg() const { return Op_RegL; }
257 };