annotate src/share/vm/c1/c1_Canonicalizer.cpp @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents 3cf667df43ef
children b812ff5abc73
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1295
diff changeset
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1295
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1295
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1295
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_c1_Canonicalizer.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 static void do_print_value(Value* vp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 (*vp)->print_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
31 }
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 void Canonicalizer::set_canonical(Value x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 assert(x != NULL, "value must exist");
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Note: we can not currently substitute root nodes which show up in
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // the instruction stream (because the instruction list is embedded
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // in the instructions).
a61af66fc99e Initial load
duke
parents:
diff changeset
38 if (canonical() != x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 if (PrintCanonicalization) {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 canonical()->input_values_do(do_print_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
41 canonical()->print_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
42 tty->print_cr("canonicalized to:");
a61af66fc99e Initial load
duke
parents:
diff changeset
43 x->input_values_do(do_print_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
44 x->print_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
45 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47 assert(_canonical->type()->tag() == x->type()->tag(), "types must match");
a61af66fc99e Initial load
duke
parents:
diff changeset
48 _canonical = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 void Canonicalizer::move_const_to_right(Op2* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 if (x->x()->type()->is_constant() && x->is_commutative()) x->swap_operands();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 void Canonicalizer::do_Op2(Op2* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 if (x->x() == x->y()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 case Bytecodes::_isub: set_constant(0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 case Bytecodes::_lsub: set_constant(jlong_cast(0)); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 case Bytecodes::_iand: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
64 case Bytecodes::_land: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
65 case Bytecodes::_ior: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
66 case Bytecodes::_lor : set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 case Bytecodes::_ixor: set_constant(0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 case Bytecodes::_lxor: set_constant(jlong_cast(0)); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 if (x->x()->type()->is_constant() && x->y()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // do constant folding for selected operations
a61af66fc99e Initial load
duke
parents:
diff changeset
74 switch (x->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 case intTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
76 { jint a = x->x()->type()->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 jint b = x->y()->type()->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 case Bytecodes::_iadd: set_constant(a + b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 case Bytecodes::_isub: set_constant(a - b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 case Bytecodes::_imul: set_constant(a * b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 case Bytecodes::_idiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (b != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if (a == min_jint && b == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 set_constant(min_jint);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 set_constant(a / b);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 case Bytecodes::_irem:
a61af66fc99e Initial load
duke
parents:
diff changeset
93 if (b != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (a == min_jint && b == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 set_constant(a % b);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 case Bytecodes::_iand: set_constant(a & b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 case Bytecodes::_ior : set_constant(a | b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 case Bytecodes::_ixor: set_constant(a ^ b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 case longTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
109 { jlong a = x->x()->type()->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 jlong b = x->y()->type()->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 case Bytecodes::_ladd: set_constant(a + b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 case Bytecodes::_lsub: set_constant(a - b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 case Bytecodes::_lmul: set_constant(a * b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 case Bytecodes::_ldiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
116 if (b != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 set_constant(SharedRuntime::ldiv(b, a));
a61af66fc99e Initial load
duke
parents:
diff changeset
118 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 case Bytecodes::_lrem:
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (b != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 set_constant(SharedRuntime::lrem(b, a));
a61af66fc99e Initial load
duke
parents:
diff changeset
124 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 case Bytecodes::_land: set_constant(a & b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 case Bytecodes::_lor : set_constant(a | b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 case Bytecodes::_lxor: set_constant(a ^ b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // other cases not implemented (must be extremely careful with floats & doubles!)
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // make sure constant is on the right side, if any
a61af66fc99e Initial load
duke
parents:
diff changeset
137 move_const_to_right(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (x->y()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // do constant folding for selected operations
a61af66fc99e Initial load
duke
parents:
diff changeset
141 switch (x->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 case intTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
143 if (x->y()->type()->as_IntConstant()->value() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 case Bytecodes::_iadd: set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 case Bytecodes::_isub: set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 case Bytecodes::_imul: set_constant(0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Note: for div and rem, make sure that C semantics
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // corresponds to Java semantics!
a61af66fc99e Initial load
duke
parents:
diff changeset
150 case Bytecodes::_iand: set_constant(0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 case Bytecodes::_ior : set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 case longTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (x->y()->type()->as_LongConstant()->value() == (jlong)0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 case Bytecodes::_ladd: set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 case Bytecodes::_lsub: set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 case Bytecodes::_lmul: set_constant((jlong)0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // Note: for div and rem, make sure that C semantics
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // corresponds to Java semantics!
a61af66fc99e Initial load
duke
parents:
diff changeset
163 case Bytecodes::_land: set_constant((jlong)0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 case Bytecodes::_lor : set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 void Canonicalizer::do_Phi (Phi* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
174 void Canonicalizer::do_Constant (Constant* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
175 void Canonicalizer::do_Local (Local* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
176 void Canonicalizer::do_LoadField (LoadField* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // checks if v is in the block that is currently processed by
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // GraphBuilder. This is the only block that has not BlockEnd yet.
a61af66fc99e Initial load
duke
parents:
diff changeset
180 static bool in_current_block(Value v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 int max_distance = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 while (max_distance > 0 && v != NULL && v->as_BlockEnd() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 v = v->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 max_distance--;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186 return v == NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 void Canonicalizer::do_StoreField (StoreField* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // If a value is going to be stored into a field or array some of
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // the conversions emitted by javac are unneeded because the fields
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // are packed to their natural size.
a61af66fc99e Initial load
duke
parents:
diff changeset
193 Convert* conv = x->value()->as_Convert();
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (conv) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 Value value = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 BasicType type = x->field()->type()->basic_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 switch (conv->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 case Bytecodes::_i2b: if (type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 case Bytecodes::_i2c: if (type == T_CHAR || type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // limit this optimization to current block
a61af66fc99e Initial load
duke
parents:
diff changeset
203 if (value != NULL && in_current_block(conv)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 set_canonical(new StoreField(x->obj(), x->offset(), x->field(), value, x->is_static(),
a61af66fc99e Initial load
duke
parents:
diff changeset
205 x->lock_stack(), x->state_before(), x->is_loaded(), x->is_initialized()));
a61af66fc99e Initial load
duke
parents:
diff changeset
206 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 void Canonicalizer::do_ArrayLength (ArrayLength* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 NewArray* array = x->array()->as_NewArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
214 if (array != NULL && array->length() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 Constant* length = array->length()->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
216 if (length != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // do not use the Constant itself, but create a new Constant
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // with same value Otherwise a Constant is live over multiple
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // blocks without being registered in a state array.
a61af66fc99e Initial load
duke
parents:
diff changeset
220 assert(length->type()->as_IntConstant() != NULL, "array length must be integer");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 set_constant(length->type()->as_IntConstant()->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 LoadField* lf = x->array()->as_LoadField();
1295
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
225 if (lf != NULL) {
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
226 ciField* field = lf->field();
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
227 if (field->is_constant() && field->is_static()) {
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
228 // final static field
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
229 ciObject* c = field->constant_value().as_object();
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
230 if (c->is_array()) {
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
231 ciArray* array = (ciArray*) c;
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
232 set_constant(array->length());
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
233 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 void Canonicalizer::do_LoadIndexed (LoadIndexed* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
240 void Canonicalizer::do_StoreIndexed (StoreIndexed* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // If a value is going to be stored into a field or array some of
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // the conversions emitted by javac are unneeded because the fields
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // are packed to their natural size.
a61af66fc99e Initial load
duke
parents:
diff changeset
244 Convert* conv = x->value()->as_Convert();
a61af66fc99e Initial load
duke
parents:
diff changeset
245 if (conv) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 Value value = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
247 BasicType type = x->elt_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
248 switch (conv->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 case Bytecodes::_i2b: if (type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
250 case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
251 case Bytecodes::_i2c: if (type == T_CHAR || type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // limit this optimization to current block
a61af66fc99e Initial load
duke
parents:
diff changeset
254 if (value != NULL && in_current_block(conv)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 set_canonical(new StoreIndexed(x->array(), x->index(), x->length(),
a61af66fc99e Initial load
duke
parents:
diff changeset
256 x->elt_type(), value, x->lock_stack()));
a61af66fc99e Initial load
duke
parents:
diff changeset
257 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 void Canonicalizer::do_NegateOp(NegateOp* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 ValueType* t = x->x()->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
267 if (t->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 switch (t->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 case intTag : set_constant(-t->as_IntConstant ()->value()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
270 case longTag : set_constant(-t->as_LongConstant ()->value()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 case floatTag : set_constant(-t->as_FloatConstant ()->value()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
272 case doubleTag: set_constant(-t->as_DoubleConstant()->value()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
273 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 void Canonicalizer::do_ArithmeticOp (ArithmeticOp* x) { do_Op2(x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 void Canonicalizer::do_ShiftOp (ShiftOp* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 ValueType* t = x->x()->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
284 ValueType* t2 = x->y()->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
285 if (t->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 switch (t->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 case intTag : if (t->as_IntConstant()->value() == 0) { set_constant(0); return; } break;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 case longTag : if (t->as_LongConstant()->value() == (jlong)0) { set_constant(jlong_cast(0)); return; } break;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if (t2->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 if (t->tag() == intTag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 int value = t->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
294 int shift = t2->as_IntConstant()->value() & 31;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 jint mask = ~(~0 << (32 - shift));
a61af66fc99e Initial load
duke
parents:
diff changeset
296 if (shift == 0) mask = ~0;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 case Bytecodes::_ishl: set_constant(value << shift); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
299 case Bytecodes::_ishr: set_constant(value >> shift); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
300 case Bytecodes::_iushr: set_constant((value >> shift) & mask); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302 } else if (t->tag() == longTag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 jlong value = t->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
304 int shift = t2->as_IntConstant()->value() & 63;
a61af66fc99e Initial load
duke
parents:
diff changeset
305 jlong mask = ~(~jlong_cast(0) << (64 - shift));
a61af66fc99e Initial load
duke
parents:
diff changeset
306 if (shift == 0) mask = ~jlong_cast(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 case Bytecodes::_lshl: set_constant(value << shift); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
309 case Bytecodes::_lshr: set_constant(value >> shift); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 case Bytecodes::_lushr: set_constant((value >> shift) & mask); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315 if (t2->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
316 switch (t2->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 case intTag : if (t2->as_IntConstant()->value() == 0) set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
318 case longTag : if (t2->as_IntConstant()->value() == 0) set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
319 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324
a61af66fc99e Initial load
duke
parents:
diff changeset
325 void Canonicalizer::do_LogicOp (LogicOp* x) { do_Op2(x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 void Canonicalizer::do_CompareOp (CompareOp* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 if (x->x() == x->y()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 switch (x->x()->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 case longTag: set_constant(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 case floatTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
331 FloatConstant* fc = x->x()->type()->as_FloatConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
332 if (fc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 if (g_isnan(fc->value())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 set_constant(x->op() == Bytecodes::_fcmpl ? -1 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
335 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341 case doubleTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 DoubleConstant* dc = x->x()->type()->as_DoubleConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if (dc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (g_isnan(dc->value())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 set_constant(x->op() == Bytecodes::_dcmpl ? -1 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349 }
a61af66fc99e Initial load
duke
parents:
diff changeset
350 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353 } else if (x->x()->type()->is_constant() && x->y()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 switch (x->x()->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 case longTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 jlong vx = x->x()->type()->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
357 jlong vy = x->y()->type()->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
358 if (vx == vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
359 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 else if (vx < vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
361 set_constant(-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
362 else
a61af66fc99e Initial load
duke
parents:
diff changeset
363 set_constant(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
364 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 case floatTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 float vx = x->x()->type()->as_FloatConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
369 float vy = x->y()->type()->as_FloatConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
370 if (g_isnan(vx) || g_isnan(vy))
a61af66fc99e Initial load
duke
parents:
diff changeset
371 set_constant(x->op() == Bytecodes::_fcmpl ? -1 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 else if (vx == vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
373 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
374 else if (vx < vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
375 set_constant(-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
376 else
a61af66fc99e Initial load
duke
parents:
diff changeset
377 set_constant(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
378 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
379 }
a61af66fc99e Initial load
duke
parents:
diff changeset
380
a61af66fc99e Initial load
duke
parents:
diff changeset
381 case doubleTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 double vx = x->x()->type()->as_DoubleConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
383 double vy = x->y()->type()->as_DoubleConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
384 if (g_isnan(vx) || g_isnan(vy))
a61af66fc99e Initial load
duke
parents:
diff changeset
385 set_constant(x->op() == Bytecodes::_dcmpl ? -1 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
386 else if (vx == vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
387 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
388 else if (vx < vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
389 set_constant(-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
390 else
a61af66fc99e Initial load
duke
parents:
diff changeset
391 set_constant(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
392 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
393 }
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399
a61af66fc99e Initial load
duke
parents:
diff changeset
400 void Canonicalizer::do_IfInstanceOf(IfInstanceOf* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
401
a61af66fc99e Initial load
duke
parents:
diff changeset
402 void Canonicalizer::do_IfOp(IfOp* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
403 // Caution: do not use do_Op2(x) here for now since
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // we map the condition to the op for now!
a61af66fc99e Initial load
duke
parents:
diff changeset
405 move_const_to_right(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 void Canonicalizer::do_Intrinsic (Intrinsic* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 switch (x->id()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
411 case vmIntrinsics::_floatToRawIntBits : {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 FloatConstant* c = x->argument_at(0)->type()->as_FloatConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
413 if (c != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
414 JavaValue v;
a61af66fc99e Initial load
duke
parents:
diff changeset
415 v.set_jfloat(c->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
416 set_constant(v.get_jint());
a61af66fc99e Initial load
duke
parents:
diff changeset
417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
418 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420 case vmIntrinsics::_intBitsToFloat : {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 IntConstant* c = x->argument_at(0)->type()->as_IntConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
422 if (c != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 JavaValue v;
a61af66fc99e Initial load
duke
parents:
diff changeset
424 v.set_jint(c->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
425 set_constant(v.get_jfloat());
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
429 case vmIntrinsics::_doubleToRawLongBits : {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 DoubleConstant* c = x->argument_at(0)->type()->as_DoubleConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
431 if (c != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 JavaValue v;
a61af66fc99e Initial load
duke
parents:
diff changeset
433 v.set_jdouble(c->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
434 set_constant(v.get_jlong());
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
438 case vmIntrinsics::_longBitsToDouble : {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 LongConstant* c = x->argument_at(0)->type()->as_LongConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
440 if (c != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 JavaValue v;
a61af66fc99e Initial load
duke
parents:
diff changeset
442 v.set_jlong(c->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
443 set_constant(v.get_jdouble());
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449
a61af66fc99e Initial load
duke
parents:
diff changeset
450 void Canonicalizer::do_Convert (Convert* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 if (x->value()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 case Bytecodes::_i2b: set_constant((int)((x->value()->type()->as_IntConstant()->value() << 24) >> 24)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
454 case Bytecodes::_i2s: set_constant((int)((x->value()->type()->as_IntConstant()->value() << 16) >> 16)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
455 case Bytecodes::_i2c: set_constant((int)(x->value()->type()->as_IntConstant()->value() & ((1<<16)-1))); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 case Bytecodes::_i2l: set_constant((jlong)(x->value()->type()->as_IntConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 case Bytecodes::_i2f: set_constant((float)(x->value()->type()->as_IntConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
458 case Bytecodes::_i2d: set_constant((double)(x->value()->type()->as_IntConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
459 case Bytecodes::_l2i: set_constant((int)(x->value()->type()->as_LongConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 case Bytecodes::_l2f: set_constant(SharedRuntime::l2f(x->value()->type()->as_LongConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
461 case Bytecodes::_l2d: set_constant(SharedRuntime::l2d(x->value()->type()->as_LongConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
462 case Bytecodes::_f2d: set_constant((double)(x->value()->type()->as_FloatConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
463 case Bytecodes::_f2i: set_constant(SharedRuntime::f2i(x->value()->type()->as_FloatConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
464 case Bytecodes::_f2l: set_constant(SharedRuntime::f2l(x->value()->type()->as_FloatConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
465 case Bytecodes::_d2f: set_constant((float)(x->value()->type()->as_DoubleConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 case Bytecodes::_d2i: set_constant(SharedRuntime::d2i(x->value()->type()->as_DoubleConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
467 case Bytecodes::_d2l: set_constant(SharedRuntime::d2l(x->value()->type()->as_DoubleConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
468 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
469 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
470 }
a61af66fc99e Initial load
duke
parents:
diff changeset
471 }
a61af66fc99e Initial load
duke
parents:
diff changeset
472
a61af66fc99e Initial load
duke
parents:
diff changeset
473 Value value = x->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
474 BasicType type = T_ILLEGAL;
a61af66fc99e Initial load
duke
parents:
diff changeset
475 LoadField* lf = value->as_LoadField();
a61af66fc99e Initial load
duke
parents:
diff changeset
476 if (lf) {
a61af66fc99e Initial load
duke
parents:
diff changeset
477 type = lf->field_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
478 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
479 LoadIndexed* li = value->as_LoadIndexed();
a61af66fc99e Initial load
duke
parents:
diff changeset
480 if (li) {
a61af66fc99e Initial load
duke
parents:
diff changeset
481 type = li->elt_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
482 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
483 Convert* conv = value->as_Convert();
a61af66fc99e Initial load
duke
parents:
diff changeset
484 if (conv) {
a61af66fc99e Initial load
duke
parents:
diff changeset
485 switch (conv->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 case Bytecodes::_i2b: type = T_BYTE; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
487 case Bytecodes::_i2s: type = T_SHORT; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
488 case Bytecodes::_i2c: type = T_CHAR; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490 }
a61af66fc99e Initial load
duke
parents:
diff changeset
491 }
a61af66fc99e Initial load
duke
parents:
diff changeset
492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
493 if (type != T_ILLEGAL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
494 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
495 case Bytecodes::_i2b: if (type == T_BYTE) set_canonical(x->value()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
496 case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) set_canonical(x->value()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
497 case Bytecodes::_i2c: if (type == T_CHAR) set_canonical(x->value()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 }
a61af66fc99e Initial load
duke
parents:
diff changeset
499 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
500 Op2* op2 = x->value()->as_Op2();
a61af66fc99e Initial load
duke
parents:
diff changeset
501 if (op2 && op2->op() == Bytecodes::_iand && op2->y()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
502 jint safebits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
503 jint mask = op2->y()->type()->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
504 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 case Bytecodes::_i2b: safebits = 0x7f; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 case Bytecodes::_i2s: safebits = 0x7fff; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
507 case Bytecodes::_i2c: safebits = 0xffff; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
508 }
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // When casting a masked integer to a smaller signed type, if
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // the mask doesn't include the sign bit the cast isn't needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
511 if (safebits && (mask & ~safebits) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
512 set_canonical(x->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515 }
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 }
a61af66fc99e Initial load
duke
parents:
diff changeset
518
a61af66fc99e Initial load
duke
parents:
diff changeset
519 void Canonicalizer::do_NullCheck (NullCheck* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 if (x->obj()->as_NewArray() != NULL || x->obj()->as_NewInstance() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
521 set_canonical(x->obj());
a61af66fc99e Initial load
duke
parents:
diff changeset
522 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
523 Constant* con = x->obj()->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
524 if (con) {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 ObjectType* c = con->type()->as_ObjectType();
a61af66fc99e Initial load
duke
parents:
diff changeset
526 if (c && c->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
527 ObjectConstant* oc = c->as_ObjectConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
528 if (!oc || !oc->value()->is_null_object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
529 set_canonical(con);
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 void Canonicalizer::do_Invoke (Invoke* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
537 void Canonicalizer::do_NewInstance (NewInstance* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
538 void Canonicalizer::do_NewTypeArray (NewTypeArray* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
539 void Canonicalizer::do_NewObjectArray (NewObjectArray* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
540 void Canonicalizer::do_NewMultiArray (NewMultiArray* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
541 void Canonicalizer::do_CheckCast (CheckCast* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
542 if (x->klass()->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
543 Value obj = x->obj();
a61af66fc99e Initial load
duke
parents:
diff changeset
544 ciType* klass = obj->exact_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
545 if (klass == NULL) klass = obj->declared_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
546 if (klass != NULL && klass->is_loaded() && klass->is_subtype_of(x->klass())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
547 set_canonical(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
548 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
550 // checkcast of null returns null
a61af66fc99e Initial load
duke
parents:
diff changeset
551 if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
552 set_canonical(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
555 }
a61af66fc99e Initial load
duke
parents:
diff changeset
556 void Canonicalizer::do_InstanceOf (InstanceOf* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
557 if (x->klass()->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 Value obj = x->obj();
a61af66fc99e Initial load
duke
parents:
diff changeset
559 ciType* exact = obj->exact_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
560 if (exact != NULL && exact->is_loaded() && (obj->as_NewInstance() || obj->as_NewArray())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
561 set_constant(exact->is_subtype_of(x->klass()) ? 1 : 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
562 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
564 // instanceof null returns false
a61af66fc99e Initial load
duke
parents:
diff changeset
565 if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 }
a61af66fc99e Initial load
duke
parents:
diff changeset
571 void Canonicalizer::do_MonitorEnter (MonitorEnter* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
572 void Canonicalizer::do_MonitorExit (MonitorExit* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
573 void Canonicalizer::do_BlockBegin (BlockBegin* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
574 void Canonicalizer::do_Goto (Goto* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
575
a61af66fc99e Initial load
duke
parents:
diff changeset
576
a61af66fc99e Initial load
duke
parents:
diff changeset
577 static bool is_true(jlong x, If::Condition cond, jlong y) {
a61af66fc99e Initial load
duke
parents:
diff changeset
578 switch (cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
579 case If::eql: return x == y;
a61af66fc99e Initial load
duke
parents:
diff changeset
580 case If::neq: return x != y;
a61af66fc99e Initial load
duke
parents:
diff changeset
581 case If::lss: return x < y;
a61af66fc99e Initial load
duke
parents:
diff changeset
582 case If::leq: return x <= y;
a61af66fc99e Initial load
duke
parents:
diff changeset
583 case If::gtr: return x > y;
a61af66fc99e Initial load
duke
parents:
diff changeset
584 case If::geq: return x >= y;
a61af66fc99e Initial load
duke
parents:
diff changeset
585 }
a61af66fc99e Initial load
duke
parents:
diff changeset
586 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
587 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591 void Canonicalizer::do_If(If* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
592 // move const to right
a61af66fc99e Initial load
duke
parents:
diff changeset
593 if (x->x()->type()->is_constant()) x->swap_operands();
a61af66fc99e Initial load
duke
parents:
diff changeset
594 // simplify
a61af66fc99e Initial load
duke
parents:
diff changeset
595 const Value l = x->x(); ValueType* lt = l->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
596 const Value r = x->y(); ValueType* rt = r->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
597
a61af66fc99e Initial load
duke
parents:
diff changeset
598 if (l == r && !lt->is_float_kind()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
599 // pattern: If (a cond a) => simplify to Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
600 BlockBegin* sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
601 switch (x->cond()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
602 case If::eql: sux = x->sux_for(true); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
603 case If::neq: sux = x->sux_for(false); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
604 case If::lss: sux = x->sux_for(false); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
605 case If::leq: sux = x->sux_for(true); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
606 case If::gtr: sux = x->sux_for(false); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
607 case If::geq: sux = x->sux_for(true); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
608 }
a61af66fc99e Initial load
duke
parents:
diff changeset
609 // If is a safepoint then the debug information should come from the state_before of the If.
a61af66fc99e Initial load
duke
parents:
diff changeset
610 set_canonical(new Goto(sux, x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
611 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
612 }
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 if (lt->is_constant() && rt->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
615 if (x->x()->as_Constant() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // pattern: If (lc cond rc) => simplify to: Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
617 BlockBegin* sux = x->x()->as_Constant()->compare(x->cond(), x->y(),
a61af66fc99e Initial load
duke
parents:
diff changeset
618 x->sux_for(true),
a61af66fc99e Initial load
duke
parents:
diff changeset
619 x->sux_for(false));
a61af66fc99e Initial load
duke
parents:
diff changeset
620 if (sux != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
621 // If is a safepoint then the debug information should come from the state_before of the If.
a61af66fc99e Initial load
duke
parents:
diff changeset
622 set_canonical(new Goto(sux, x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
623 }
a61af66fc99e Initial load
duke
parents:
diff changeset
624 }
a61af66fc99e Initial load
duke
parents:
diff changeset
625 } else if (rt->as_IntConstant() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
626 // pattern: If (l cond rc) => investigate further
a61af66fc99e Initial load
duke
parents:
diff changeset
627 const jint rc = rt->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
628 if (l->as_CompareOp() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 // pattern: If ((a cmp b) cond rc) => simplify to: If (x cond y) or: Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
630 CompareOp* cmp = l->as_CompareOp();
a61af66fc99e Initial load
duke
parents:
diff changeset
631 bool unordered_is_less = cmp->op() == Bytecodes::_fcmpl || cmp->op() == Bytecodes::_dcmpl;
a61af66fc99e Initial load
duke
parents:
diff changeset
632 BlockBegin* lss_sux = x->sux_for(is_true(-1, x->cond(), rc)); // successor for a < b
a61af66fc99e Initial load
duke
parents:
diff changeset
633 BlockBegin* eql_sux = x->sux_for(is_true( 0, x->cond(), rc)); // successor for a = b
a61af66fc99e Initial load
duke
parents:
diff changeset
634 BlockBegin* gtr_sux = x->sux_for(is_true(+1, x->cond(), rc)); // successor for a > b
a61af66fc99e Initial load
duke
parents:
diff changeset
635 BlockBegin* nan_sux = unordered_is_less ? lss_sux : gtr_sux ; // successor for unordered
a61af66fc99e Initial load
duke
parents:
diff changeset
636 // Note: At this point all successors (lss_sux, eql_sux, gtr_sux, nan_sux) are
a61af66fc99e Initial load
duke
parents:
diff changeset
637 // equal to x->tsux() or x->fsux(). Furthermore, nan_sux equals either
a61af66fc99e Initial load
duke
parents:
diff changeset
638 // lss_sux or gtr_sux.
a61af66fc99e Initial load
duke
parents:
diff changeset
639 if (lss_sux == eql_sux && eql_sux == gtr_sux) {
a61af66fc99e Initial load
duke
parents:
diff changeset
640 // all successors identical => simplify to: Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
641 set_canonical(new Goto(lss_sux, x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
642 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
643 // two successors differ and two successors are the same => simplify to: If (x cmp y)
a61af66fc99e Initial load
duke
parents:
diff changeset
644 // determine new condition & successors
a61af66fc99e Initial load
duke
parents:
diff changeset
645 If::Condition cond;
a61af66fc99e Initial load
duke
parents:
diff changeset
646 BlockBegin* tsux = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
647 BlockBegin* fsux = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
648 if (lss_sux == eql_sux) { cond = If::leq; tsux = lss_sux; fsux = gtr_sux; }
a61af66fc99e Initial load
duke
parents:
diff changeset
649 else if (lss_sux == gtr_sux) { cond = If::neq; tsux = lss_sux; fsux = eql_sux; }
a61af66fc99e Initial load
duke
parents:
diff changeset
650 else if (eql_sux == gtr_sux) { cond = If::geq; tsux = eql_sux; fsux = lss_sux; }
a61af66fc99e Initial load
duke
parents:
diff changeset
651 else { ShouldNotReachHere(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
652 If* canon = new If(cmp->x(), cond, nan_sux == tsux, cmp->y(), tsux, fsux, cmp->state_before(), x->is_safepoint());
a61af66fc99e Initial load
duke
parents:
diff changeset
653 if (cmp->x() == cmp->y()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
654 do_If(canon);
a61af66fc99e Initial load
duke
parents:
diff changeset
655 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
656 set_canonical(canon);
a61af66fc99e Initial load
duke
parents:
diff changeset
657 set_bci(cmp->bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
658 }
a61af66fc99e Initial load
duke
parents:
diff changeset
659 }
a61af66fc99e Initial load
duke
parents:
diff changeset
660 } else if (l->as_InstanceOf() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
661 // NOTE: Code permanently disabled for now since it leaves the old InstanceOf
a61af66fc99e Initial load
duke
parents:
diff changeset
662 // instruction in the graph (it is pinned). Need to fix this at some point.
a61af66fc99e Initial load
duke
parents:
diff changeset
663 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
664 // pattern: If ((obj instanceof klass) cond rc) => simplify to: IfInstanceOf or: Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
665 InstanceOf* inst = l->as_InstanceOf();
a61af66fc99e Initial load
duke
parents:
diff changeset
666 BlockBegin* is_inst_sux = x->sux_for(is_true(1, x->cond(), rc)); // successor for instanceof == 1
a61af66fc99e Initial load
duke
parents:
diff changeset
667 BlockBegin* no_inst_sux = x->sux_for(is_true(0, x->cond(), rc)); // successor for instanceof == 0
a61af66fc99e Initial load
duke
parents:
diff changeset
668 if (is_inst_sux == no_inst_sux && inst->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
669 // both successors identical and klass is loaded => simplify to: Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
670 set_canonical(new Goto(is_inst_sux, x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
671 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
672 // successors differ => simplify to: IfInstanceOf
a61af66fc99e Initial load
duke
parents:
diff changeset
673 set_canonical(new IfInstanceOf(inst->klass(), inst->obj(), true, inst->bci(), is_inst_sux, no_inst_sux));
a61af66fc99e Initial load
duke
parents:
diff changeset
674 }
a61af66fc99e Initial load
duke
parents:
diff changeset
675 }
a61af66fc99e Initial load
duke
parents:
diff changeset
676 } else if (rt == objectNull && (l->as_NewInstance() || l->as_NewArray())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
677 if (x->cond() == Instruction::eql) {
a61af66fc99e Initial load
duke
parents:
diff changeset
678 set_canonical(new Goto(x->fsux(), x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
679 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
680 assert(x->cond() == Instruction::neq, "only other valid case");
a61af66fc99e Initial load
duke
parents:
diff changeset
681 set_canonical(new Goto(x->tsux(), x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
683 }
a61af66fc99e Initial load
duke
parents:
diff changeset
684 }
a61af66fc99e Initial load
duke
parents:
diff changeset
685
a61af66fc99e Initial load
duke
parents:
diff changeset
686
a61af66fc99e Initial load
duke
parents:
diff changeset
687 void Canonicalizer::do_TableSwitch(TableSwitch* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
688 if (x->tag()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
689 int v = x->tag()->type()->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
690 BlockBegin* sux = x->default_sux();
a61af66fc99e Initial load
duke
parents:
diff changeset
691 if (v >= x->lo_key() && v <= x->hi_key()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
692 sux = x->sux_at(v - x->lo_key());
a61af66fc99e Initial load
duke
parents:
diff changeset
693 }
a61af66fc99e Initial load
duke
parents:
diff changeset
694 set_canonical(new Goto(sux, x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
695 } else if (x->number_of_sux() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
696 // NOTE: Code permanently disabled for now since the switch statement's
a61af66fc99e Initial load
duke
parents:
diff changeset
697 // tag expression may produce side-effects in which case it must
a61af66fc99e Initial load
duke
parents:
diff changeset
698 // be executed.
a61af66fc99e Initial load
duke
parents:
diff changeset
699 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
700 // simplify to Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
701 set_canonical(new Goto(x->default_sux(), x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
702 } else if (x->number_of_sux() == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
703 // NOTE: Code permanently disabled for now since it produces two new nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
704 // (Constant & If) and the Canonicalizer cannot return them correctly
a61af66fc99e Initial load
duke
parents:
diff changeset
705 // yet. For now we copied the corresponding code directly into the
a61af66fc99e Initial load
duke
parents:
diff changeset
706 // GraphBuilder (i.e., we should never reach here).
a61af66fc99e Initial load
duke
parents:
diff changeset
707 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
708 // simplify to If
a61af66fc99e Initial load
duke
parents:
diff changeset
709 assert(x->lo_key() == x->hi_key(), "keys must be the same");
a61af66fc99e Initial load
duke
parents:
diff changeset
710 Constant* key = new Constant(new IntConstant(x->lo_key()));
a61af66fc99e Initial load
duke
parents:
diff changeset
711 set_canonical(new If(x->tag(), If::eql, true, key, x->sux_at(0), x->default_sux(), x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
712 }
a61af66fc99e Initial load
duke
parents:
diff changeset
713 }
a61af66fc99e Initial load
duke
parents:
diff changeset
714
a61af66fc99e Initial load
duke
parents:
diff changeset
715
a61af66fc99e Initial load
duke
parents:
diff changeset
716 void Canonicalizer::do_LookupSwitch(LookupSwitch* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
717 if (x->tag()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
718 int v = x->tag()->type()->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
719 BlockBegin* sux = x->default_sux();
a61af66fc99e Initial load
duke
parents:
diff changeset
720 for (int i = 0; i < x->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
721 if (v == x->key_at(i)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
722 sux = x->sux_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
723 }
a61af66fc99e Initial load
duke
parents:
diff changeset
724 }
a61af66fc99e Initial load
duke
parents:
diff changeset
725 set_canonical(new Goto(sux, x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
726 } else if (x->number_of_sux() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
727 // NOTE: Code permanently disabled for now since the switch statement's
a61af66fc99e Initial load
duke
parents:
diff changeset
728 // tag expression may produce side-effects in which case it must
a61af66fc99e Initial load
duke
parents:
diff changeset
729 // be executed.
a61af66fc99e Initial load
duke
parents:
diff changeset
730 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
731 // simplify to Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
732 set_canonical(new Goto(x->default_sux(), x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
733 } else if (x->number_of_sux() == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
734 // NOTE: Code permanently disabled for now since it produces two new nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
735 // (Constant & If) and the Canonicalizer cannot return them correctly
a61af66fc99e Initial load
duke
parents:
diff changeset
736 // yet. For now we copied the corresponding code directly into the
a61af66fc99e Initial load
duke
parents:
diff changeset
737 // GraphBuilder (i.e., we should never reach here).
a61af66fc99e Initial load
duke
parents:
diff changeset
738 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
739 // simplify to If
a61af66fc99e Initial load
duke
parents:
diff changeset
740 assert(x->length() == 1, "length must be the same");
a61af66fc99e Initial load
duke
parents:
diff changeset
741 Constant* key = new Constant(new IntConstant(x->key_at(0)));
a61af66fc99e Initial load
duke
parents:
diff changeset
742 set_canonical(new If(x->tag(), If::eql, true, key, x->sux_at(0), x->default_sux(), x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
743 }
a61af66fc99e Initial load
duke
parents:
diff changeset
744 }
a61af66fc99e Initial load
duke
parents:
diff changeset
745
a61af66fc99e Initial load
duke
parents:
diff changeset
746
a61af66fc99e Initial load
duke
parents:
diff changeset
747 void Canonicalizer::do_Return (Return* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
748 void Canonicalizer::do_Throw (Throw* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
749 void Canonicalizer::do_Base (Base* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
750 void Canonicalizer::do_OsrEntry (OsrEntry* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
751 void Canonicalizer::do_ExceptionObject(ExceptionObject* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
752
a61af66fc99e Initial load
duke
parents:
diff changeset
753 static bool match_index_and_scale(Instruction* instr,
a61af66fc99e Initial load
duke
parents:
diff changeset
754 Instruction** index,
a61af66fc99e Initial load
duke
parents:
diff changeset
755 int* log2_scale,
a61af66fc99e Initial load
duke
parents:
diff changeset
756 Instruction** instr_to_unpin) {
a61af66fc99e Initial load
duke
parents:
diff changeset
757 *instr_to_unpin = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
758
a61af66fc99e Initial load
duke
parents:
diff changeset
759 // Skip conversion ops
a61af66fc99e Initial load
duke
parents:
diff changeset
760 Convert* convert = instr->as_Convert();
a61af66fc99e Initial load
duke
parents:
diff changeset
761 if (convert != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
762 instr = convert->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
763 }
a61af66fc99e Initial load
duke
parents:
diff changeset
764
a61af66fc99e Initial load
duke
parents:
diff changeset
765 ShiftOp* shift = instr->as_ShiftOp();
a61af66fc99e Initial load
duke
parents:
diff changeset
766 if (shift != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
767 if (shift->is_pinned()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
768 *instr_to_unpin = shift;
a61af66fc99e Initial load
duke
parents:
diff changeset
769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
770 // Constant shift value?
a61af66fc99e Initial load
duke
parents:
diff changeset
771 Constant* con = shift->y()->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
772 if (con == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
773 // Well-known type and value?
a61af66fc99e Initial load
duke
parents:
diff changeset
774 IntConstant* val = con->type()->as_IntConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
775 if (val == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
776 if (shift->x()->type() != intType) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
777 *index = shift->x();
a61af66fc99e Initial load
duke
parents:
diff changeset
778 int tmp_scale = val->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
779 if (tmp_scale >= 0 && tmp_scale < 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
780 *log2_scale = tmp_scale;
a61af66fc99e Initial load
duke
parents:
diff changeset
781 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
782 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
783 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
784 }
a61af66fc99e Initial load
duke
parents:
diff changeset
785 }
a61af66fc99e Initial load
duke
parents:
diff changeset
786
a61af66fc99e Initial load
duke
parents:
diff changeset
787 ArithmeticOp* arith = instr->as_ArithmeticOp();
a61af66fc99e Initial load
duke
parents:
diff changeset
788 if (arith != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
789 if (arith->is_pinned()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
790 *instr_to_unpin = arith;
a61af66fc99e Initial load
duke
parents:
diff changeset
791 }
a61af66fc99e Initial load
duke
parents:
diff changeset
792 // Check for integer multiply
a61af66fc99e Initial load
duke
parents:
diff changeset
793 if (arith->op() == Bytecodes::_imul) {
a61af66fc99e Initial load
duke
parents:
diff changeset
794 // See if either arg is a known constant
a61af66fc99e Initial load
duke
parents:
diff changeset
795 Constant* con = arith->x()->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
796 if (con != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
797 *index = arith->y();
a61af66fc99e Initial load
duke
parents:
diff changeset
798 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
799 con = arith->y()->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
800 if (con == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
801 *index = arith->x();
a61af66fc99e Initial load
duke
parents:
diff changeset
802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
803 if ((*index)->type() != intType) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
804 // Well-known type and value?
a61af66fc99e Initial load
duke
parents:
diff changeset
805 IntConstant* val = con->type()->as_IntConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
806 if (val == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
807 switch (val->value()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
808 case 1: *log2_scale = 0; return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
809 case 2: *log2_scale = 1; return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
810 case 4: *log2_scale = 2; return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
811 case 8: *log2_scale = 3; return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
812 default: return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
815 }
a61af66fc99e Initial load
duke
parents:
diff changeset
816
a61af66fc99e Initial load
duke
parents:
diff changeset
817 // Unknown instruction sequence; don't touch it
a61af66fc99e Initial load
duke
parents:
diff changeset
818 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
819 }
a61af66fc99e Initial load
duke
parents:
diff changeset
820
a61af66fc99e Initial load
duke
parents:
diff changeset
821
a61af66fc99e Initial load
duke
parents:
diff changeset
822 static bool match(UnsafeRawOp* x,
a61af66fc99e Initial load
duke
parents:
diff changeset
823 Instruction** base,
a61af66fc99e Initial load
duke
parents:
diff changeset
824 Instruction** index,
a61af66fc99e Initial load
duke
parents:
diff changeset
825 int* log2_scale) {
a61af66fc99e Initial load
duke
parents:
diff changeset
826 Instruction* instr_to_unpin = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
827 ArithmeticOp* root = x->base()->as_ArithmeticOp();
a61af66fc99e Initial load
duke
parents:
diff changeset
828 if (root == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
829 // Limit ourselves to addition for now
a61af66fc99e Initial load
duke
parents:
diff changeset
830 if (root->op() != Bytecodes::_ladd) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
831 // Try to find shift or scale op
a61af66fc99e Initial load
duke
parents:
diff changeset
832 if (match_index_and_scale(root->y(), index, log2_scale, &instr_to_unpin)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
833 *base = root->x();
a61af66fc99e Initial load
duke
parents:
diff changeset
834 } else if (match_index_and_scale(root->x(), index, log2_scale, &instr_to_unpin)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
835 *base = root->y();
a61af66fc99e Initial load
duke
parents:
diff changeset
836 } else if (root->y()->as_Convert() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
837 Convert* convert = root->y()->as_Convert();
a61af66fc99e Initial load
duke
parents:
diff changeset
838 if (convert->op() == Bytecodes::_i2l && convert->value()->type() == intType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
839 // pick base and index, setting scale at 1
a61af66fc99e Initial load
duke
parents:
diff changeset
840 *base = root->x();
a61af66fc99e Initial load
duke
parents:
diff changeset
841 *index = convert->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
842 *log2_scale = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
843 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
844 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
845 }
a61af66fc99e Initial load
duke
parents:
diff changeset
846 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
847 // doesn't match any expected sequences
a61af66fc99e Initial load
duke
parents:
diff changeset
848 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
849 }
a61af66fc99e Initial load
duke
parents:
diff changeset
850
a61af66fc99e Initial load
duke
parents:
diff changeset
851 // If the value is pinned then it will be always be computed so
a61af66fc99e Initial load
duke
parents:
diff changeset
852 // there's no profit to reshaping the expression.
a61af66fc99e Initial load
duke
parents:
diff changeset
853 return !root->is_pinned();
a61af66fc99e Initial load
duke
parents:
diff changeset
854 }
a61af66fc99e Initial load
duke
parents:
diff changeset
855
a61af66fc99e Initial load
duke
parents:
diff changeset
856
a61af66fc99e Initial load
duke
parents:
diff changeset
857 void Canonicalizer::do_UnsafeRawOp(UnsafeRawOp* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
858 Instruction* base = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
859 Instruction* index = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
860 int log2_scale;
a61af66fc99e Initial load
duke
parents:
diff changeset
861
a61af66fc99e Initial load
duke
parents:
diff changeset
862 if (match(x, &base, &index, &log2_scale)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
863 x->set_base(base);
a61af66fc99e Initial load
duke
parents:
diff changeset
864 x->set_index(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
865 x->set_log2_scale(log2_scale);
a61af66fc99e Initial load
duke
parents:
diff changeset
866 if (PrintUnsafeOptimization) {
a61af66fc99e Initial load
duke
parents:
diff changeset
867 tty->print_cr("Canonicalizer: UnsafeRawOp id %d: base = id %d, index = id %d, log2_scale = %d",
a61af66fc99e Initial load
duke
parents:
diff changeset
868 x->id(), x->base()->id(), x->index()->id(), x->log2_scale());
a61af66fc99e Initial load
duke
parents:
diff changeset
869 }
a61af66fc99e Initial load
duke
parents:
diff changeset
870 }
a61af66fc99e Initial load
duke
parents:
diff changeset
871 }
a61af66fc99e Initial load
duke
parents:
diff changeset
872
a61af66fc99e Initial load
duke
parents:
diff changeset
873 void Canonicalizer::do_RoundFP(RoundFP* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
874 void Canonicalizer::do_UnsafeGetRaw(UnsafeGetRaw* x) { if (OptimizeUnsafes) do_UnsafeRawOp(x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
875 void Canonicalizer::do_UnsafePutRaw(UnsafePutRaw* x) { if (OptimizeUnsafes) do_UnsafeRawOp(x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
876 void Canonicalizer::do_UnsafeGetObject(UnsafeGetObject* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
877 void Canonicalizer::do_UnsafePutObject(UnsafePutObject* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
878 void Canonicalizer::do_UnsafePrefetchRead (UnsafePrefetchRead* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
879 void Canonicalizer::do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
880 void Canonicalizer::do_ProfileCall(ProfileCall* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
881 void Canonicalizer::do_ProfileCounter(ProfileCounter* x) {}