Wed, 02 Feb 2011 11:35:26 -0500
7016023: Enable building ARM and PPC from src/closed repository
Reviewed-by: dholmes, bdelsart
duke@435 | 1 | /* |
trims@1907 | 2 | * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "c1/c1_IR.hpp" |
stefank@2314 | 27 | #include "c1/c1_Instruction.hpp" |
stefank@2314 | 28 | #include "c1/c1_InstructionPrinter.hpp" |
stefank@2314 | 29 | #include "c1/c1_ValueStack.hpp" |
stefank@2314 | 30 | #include "ci/ciObjArrayKlass.hpp" |
stefank@2314 | 31 | #include "ci/ciTypeArrayKlass.hpp" |
duke@435 | 32 | |
duke@435 | 33 | |
duke@435 | 34 | // Implementation of Instruction |
duke@435 | 35 | |
duke@435 | 36 | |
duke@435 | 37 | Instruction::Condition Instruction::mirror(Condition cond) { |
duke@435 | 38 | switch (cond) { |
duke@435 | 39 | case eql: return eql; |
duke@435 | 40 | case neq: return neq; |
duke@435 | 41 | case lss: return gtr; |
duke@435 | 42 | case leq: return geq; |
duke@435 | 43 | case gtr: return lss; |
duke@435 | 44 | case geq: return leq; |
duke@435 | 45 | } |
duke@435 | 46 | ShouldNotReachHere(); |
duke@435 | 47 | return eql; |
duke@435 | 48 | } |
duke@435 | 49 | |
duke@435 | 50 | |
duke@435 | 51 | Instruction::Condition Instruction::negate(Condition cond) { |
duke@435 | 52 | switch (cond) { |
duke@435 | 53 | case eql: return neq; |
duke@435 | 54 | case neq: return eql; |
duke@435 | 55 | case lss: return geq; |
duke@435 | 56 | case leq: return gtr; |
duke@435 | 57 | case gtr: return leq; |
duke@435 | 58 | case geq: return lss; |
duke@435 | 59 | } |
duke@435 | 60 | ShouldNotReachHere(); |
duke@435 | 61 | return eql; |
duke@435 | 62 | } |
duke@435 | 63 | |
roland@2174 | 64 | void Instruction::update_exception_state(ValueStack* state) { |
roland@2174 | 65 | if (state != NULL && (state->kind() == ValueStack::EmptyExceptionState || state->kind() == ValueStack::ExceptionState)) { |
roland@2174 | 66 | assert(state->kind() == ValueStack::EmptyExceptionState || Compilation::current()->env()->jvmti_can_access_local_variables(), "unexpected state kind"); |
roland@2174 | 67 | _exception_state = state; |
roland@2174 | 68 | } else { |
roland@2174 | 69 | _exception_state = NULL; |
roland@2174 | 70 | } |
roland@2174 | 71 | } |
roland@2174 | 72 | |
duke@435 | 73 | |
duke@435 | 74 | Instruction* Instruction::prev(BlockBegin* block) { |
duke@435 | 75 | Instruction* p = NULL; |
duke@435 | 76 | Instruction* q = block; |
duke@435 | 77 | while (q != this) { |
duke@435 | 78 | assert(q != NULL, "this is not in the block's instruction list"); |
duke@435 | 79 | p = q; q = q->next(); |
duke@435 | 80 | } |
duke@435 | 81 | return p; |
duke@435 | 82 | } |
duke@435 | 83 | |
duke@435 | 84 | |
roland@2174 | 85 | void Instruction::state_values_do(ValueVisitor* f) { |
roland@2174 | 86 | if (state_before() != NULL) { |
roland@2174 | 87 | state_before()->values_do(f); |
roland@2174 | 88 | } |
roland@2174 | 89 | if (exception_state() != NULL){ |
roland@2174 | 90 | exception_state()->values_do(f); |
roland@2174 | 91 | } |
roland@2174 | 92 | } |
roland@2174 | 93 | |
roland@2174 | 94 | |
duke@435 | 95 | #ifndef PRODUCT |
roland@2174 | 96 | void Instruction::check_state(ValueStack* state) { |
roland@2174 | 97 | if (state != NULL) { |
roland@2174 | 98 | state->verify(); |
roland@2174 | 99 | } |
roland@2174 | 100 | } |
roland@2174 | 101 | |
roland@2174 | 102 | |
duke@435 | 103 | void Instruction::print() { |
duke@435 | 104 | InstructionPrinter ip; |
duke@435 | 105 | print(ip); |
duke@435 | 106 | } |
duke@435 | 107 | |
duke@435 | 108 | |
duke@435 | 109 | void Instruction::print_line() { |
duke@435 | 110 | InstructionPrinter ip; |
duke@435 | 111 | ip.print_line(this); |
duke@435 | 112 | } |
duke@435 | 113 | |
duke@435 | 114 | |
duke@435 | 115 | void Instruction::print(InstructionPrinter& ip) { |
duke@435 | 116 | ip.print_head(); |
duke@435 | 117 | ip.print_line(this); |
duke@435 | 118 | tty->cr(); |
duke@435 | 119 | } |
duke@435 | 120 | #endif // PRODUCT |
duke@435 | 121 | |
duke@435 | 122 | |
duke@435 | 123 | // perform constant and interval tests on index value |
duke@435 | 124 | bool AccessIndexed::compute_needs_range_check() { |
duke@435 | 125 | Constant* clength = length()->as_Constant(); |
duke@435 | 126 | Constant* cindex = index()->as_Constant(); |
duke@435 | 127 | if (clength && cindex) { |
duke@435 | 128 | IntConstant* l = clength->type()->as_IntConstant(); |
duke@435 | 129 | IntConstant* i = cindex->type()->as_IntConstant(); |
duke@435 | 130 | if (l && i && i->value() < l->value() && i->value() >= 0) { |
duke@435 | 131 | return false; |
duke@435 | 132 | } |
duke@435 | 133 | } |
duke@435 | 134 | return true; |
duke@435 | 135 | } |
duke@435 | 136 | |
duke@435 | 137 | |
duke@435 | 138 | ciType* LoadIndexed::exact_type() const { |
duke@435 | 139 | ciType* array_type = array()->exact_type(); |
duke@435 | 140 | if (array_type == NULL) { |
duke@435 | 141 | return NULL; |
duke@435 | 142 | } |
duke@435 | 143 | assert(array_type->is_array_klass(), "what else?"); |
duke@435 | 144 | ciArrayKlass* ak = (ciArrayKlass*)array_type; |
duke@435 | 145 | |
duke@435 | 146 | if (ak->element_type()->is_instance_klass()) { |
duke@435 | 147 | ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type(); |
duke@435 | 148 | if (ik->is_loaded() && ik->is_final()) { |
duke@435 | 149 | return ik; |
duke@435 | 150 | } |
duke@435 | 151 | } |
duke@435 | 152 | return NULL; |
duke@435 | 153 | } |
duke@435 | 154 | |
duke@435 | 155 | |
duke@435 | 156 | ciType* LoadIndexed::declared_type() const { |
duke@435 | 157 | ciType* array_type = array()->declared_type(); |
duke@435 | 158 | if (array_type == NULL) { |
duke@435 | 159 | return NULL; |
duke@435 | 160 | } |
duke@435 | 161 | assert(array_type->is_array_klass(), "what else?"); |
duke@435 | 162 | ciArrayKlass* ak = (ciArrayKlass*)array_type; |
duke@435 | 163 | return ak->element_type(); |
duke@435 | 164 | } |
duke@435 | 165 | |
duke@435 | 166 | |
duke@435 | 167 | ciType* LoadField::declared_type() const { |
duke@435 | 168 | return field()->type(); |
duke@435 | 169 | } |
duke@435 | 170 | |
duke@435 | 171 | |
duke@435 | 172 | ciType* LoadField::exact_type() const { |
duke@435 | 173 | ciType* type = declared_type(); |
duke@435 | 174 | // for primitive arrays, the declared type is the exact type |
duke@435 | 175 | if (type->is_type_array_klass()) { |
duke@435 | 176 | return type; |
duke@435 | 177 | } |
duke@435 | 178 | if (type->is_instance_klass()) { |
duke@435 | 179 | ciInstanceKlass* ik = (ciInstanceKlass*)type; |
duke@435 | 180 | if (ik->is_loaded() && ik->is_final()) { |
duke@435 | 181 | return type; |
duke@435 | 182 | } |
duke@435 | 183 | } |
duke@435 | 184 | return NULL; |
duke@435 | 185 | } |
duke@435 | 186 | |
duke@435 | 187 | |
duke@435 | 188 | ciType* NewTypeArray::exact_type() const { |
duke@435 | 189 | return ciTypeArrayKlass::make(elt_type()); |
duke@435 | 190 | } |
duke@435 | 191 | |
duke@435 | 192 | |
duke@435 | 193 | ciType* NewObjectArray::exact_type() const { |
duke@435 | 194 | return ciObjArrayKlass::make(klass()); |
duke@435 | 195 | } |
duke@435 | 196 | |
duke@435 | 197 | |
duke@435 | 198 | ciType* NewInstance::exact_type() const { |
duke@435 | 199 | return klass(); |
duke@435 | 200 | } |
duke@435 | 201 | |
duke@435 | 202 | |
duke@435 | 203 | ciType* CheckCast::declared_type() const { |
duke@435 | 204 | return klass(); |
duke@435 | 205 | } |
duke@435 | 206 | |
duke@435 | 207 | ciType* CheckCast::exact_type() const { |
duke@435 | 208 | if (klass()->is_instance_klass()) { |
duke@435 | 209 | ciInstanceKlass* ik = (ciInstanceKlass*)klass(); |
duke@435 | 210 | if (ik->is_loaded() && ik->is_final()) { |
duke@435 | 211 | return ik; |
duke@435 | 212 | } |
duke@435 | 213 | } |
duke@435 | 214 | return NULL; |
duke@435 | 215 | } |
duke@435 | 216 | |
duke@435 | 217 | // Implementation of ArithmeticOp |
duke@435 | 218 | |
duke@435 | 219 | bool ArithmeticOp::is_commutative() const { |
duke@435 | 220 | switch (op()) { |
duke@435 | 221 | case Bytecodes::_iadd: // fall through |
duke@435 | 222 | case Bytecodes::_ladd: // fall through |
duke@435 | 223 | case Bytecodes::_fadd: // fall through |
duke@435 | 224 | case Bytecodes::_dadd: // fall through |
duke@435 | 225 | case Bytecodes::_imul: // fall through |
duke@435 | 226 | case Bytecodes::_lmul: // fall through |
duke@435 | 227 | case Bytecodes::_fmul: // fall through |
duke@435 | 228 | case Bytecodes::_dmul: return true; |
duke@435 | 229 | } |
duke@435 | 230 | return false; |
duke@435 | 231 | } |
duke@435 | 232 | |
duke@435 | 233 | |
duke@435 | 234 | bool ArithmeticOp::can_trap() const { |
duke@435 | 235 | switch (op()) { |
duke@435 | 236 | case Bytecodes::_idiv: // fall through |
duke@435 | 237 | case Bytecodes::_ldiv: // fall through |
duke@435 | 238 | case Bytecodes::_irem: // fall through |
duke@435 | 239 | case Bytecodes::_lrem: return true; |
duke@435 | 240 | } |
duke@435 | 241 | return false; |
duke@435 | 242 | } |
duke@435 | 243 | |
duke@435 | 244 | |
duke@435 | 245 | // Implementation of LogicOp |
duke@435 | 246 | |
duke@435 | 247 | bool LogicOp::is_commutative() const { |
duke@435 | 248 | #ifdef ASSERT |
duke@435 | 249 | switch (op()) { |
duke@435 | 250 | case Bytecodes::_iand: // fall through |
duke@435 | 251 | case Bytecodes::_land: // fall through |
duke@435 | 252 | case Bytecodes::_ior : // fall through |
duke@435 | 253 | case Bytecodes::_lor : // fall through |
duke@435 | 254 | case Bytecodes::_ixor: // fall through |
duke@435 | 255 | case Bytecodes::_lxor: break; |
duke@435 | 256 | default : ShouldNotReachHere(); |
duke@435 | 257 | } |
duke@435 | 258 | #endif |
duke@435 | 259 | // all LogicOps are commutative |
duke@435 | 260 | return true; |
duke@435 | 261 | } |
duke@435 | 262 | |
duke@435 | 263 | |
duke@435 | 264 | // Implementation of IfOp |
duke@435 | 265 | |
duke@435 | 266 | bool IfOp::is_commutative() const { |
duke@435 | 267 | return cond() == eql || cond() == neq; |
duke@435 | 268 | } |
duke@435 | 269 | |
duke@435 | 270 | |
duke@435 | 271 | // Implementation of StateSplit |
duke@435 | 272 | |
duke@435 | 273 | void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) { |
duke@435 | 274 | NOT_PRODUCT(bool assigned = false;) |
duke@435 | 275 | for (int i = 0; i < list.length(); i++) { |
duke@435 | 276 | BlockBegin** b = list.adr_at(i); |
duke@435 | 277 | if (*b == old_block) { |
duke@435 | 278 | *b = new_block; |
duke@435 | 279 | NOT_PRODUCT(assigned = true;) |
duke@435 | 280 | } |
duke@435 | 281 | } |
duke@435 | 282 | assert(assigned == true, "should have assigned at least once"); |
duke@435 | 283 | } |
duke@435 | 284 | |
duke@435 | 285 | |
duke@435 | 286 | IRScope* StateSplit::scope() const { |
duke@435 | 287 | return _state->scope(); |
duke@435 | 288 | } |
duke@435 | 289 | |
duke@435 | 290 | |
iveresov@1939 | 291 | void StateSplit::state_values_do(ValueVisitor* f) { |
roland@2174 | 292 | Instruction::state_values_do(f); |
duke@435 | 293 | if (state() != NULL) state()->values_do(f); |
duke@435 | 294 | } |
duke@435 | 295 | |
duke@435 | 296 | |
iveresov@1939 | 297 | void BlockBegin::state_values_do(ValueVisitor* f) { |
duke@435 | 298 | StateSplit::state_values_do(f); |
duke@435 | 299 | |
duke@435 | 300 | if (is_set(BlockBegin::exception_entry_flag)) { |
duke@435 | 301 | for (int i = 0; i < number_of_exception_states(); i++) { |
duke@435 | 302 | exception_state_at(i)->values_do(f); |
duke@435 | 303 | } |
duke@435 | 304 | } |
duke@435 | 305 | } |
duke@435 | 306 | |
duke@435 | 307 | |
duke@435 | 308 | // Implementation of Invoke |
duke@435 | 309 | |
duke@435 | 310 | |
duke@435 | 311 | Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args, |
twisti@1730 | 312 | int vtable_index, ciMethod* target, ValueStack* state_before) |
roland@2174 | 313 | : StateSplit(result_type, state_before) |
duke@435 | 314 | , _code(code) |
duke@435 | 315 | , _recv(recv) |
duke@435 | 316 | , _args(args) |
duke@435 | 317 | , _vtable_index(vtable_index) |
duke@435 | 318 | , _target(target) |
duke@435 | 319 | { |
duke@435 | 320 | set_flag(TargetIsLoadedFlag, target->is_loaded()); |
duke@435 | 321 | set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method()); |
duke@435 | 322 | set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict()); |
duke@435 | 323 | |
duke@435 | 324 | assert(args != NULL, "args must exist"); |
duke@435 | 325 | #ifdef ASSERT |
iveresov@1939 | 326 | AssertValues assert_value; |
iveresov@1939 | 327 | values_do(&assert_value); |
iveresov@1939 | 328 | #endif |
duke@435 | 329 | |
duke@435 | 330 | // provide an initial guess of signature size. |
duke@435 | 331 | _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0)); |
duke@435 | 332 | if (has_receiver()) { |
duke@435 | 333 | _signature->append(as_BasicType(receiver()->type())); |
twisti@1730 | 334 | } else if (is_invokedynamic()) { |
twisti@1730 | 335 | // Add the synthetic MethodHandle argument to the signature. |
twisti@1730 | 336 | _signature->append(T_OBJECT); |
duke@435 | 337 | } |
duke@435 | 338 | for (int i = 0; i < number_of_arguments(); i++) { |
duke@435 | 339 | ValueType* t = argument_at(i)->type(); |
duke@435 | 340 | BasicType bt = as_BasicType(t); |
duke@435 | 341 | _signature->append(bt); |
duke@435 | 342 | } |
duke@435 | 343 | } |
duke@435 | 344 | |
duke@435 | 345 | |
iveresov@1939 | 346 | void Invoke::state_values_do(ValueVisitor* f) { |
twisti@1730 | 347 | StateSplit::state_values_do(f); |
twisti@1730 | 348 | if (state_before() != NULL) state_before()->values_do(f); |
twisti@1730 | 349 | if (state() != NULL) state()->values_do(f); |
twisti@1730 | 350 | } |
twisti@1730 | 351 | |
twisti@1730 | 352 | |
duke@435 | 353 | // Implementation of Contant |
duke@435 | 354 | intx Constant::hash() const { |
roland@2174 | 355 | if (state_before() == NULL) { |
duke@435 | 356 | switch (type()->tag()) { |
duke@435 | 357 | case intTag: |
duke@435 | 358 | return HASH2(name(), type()->as_IntConstant()->value()); |
duke@435 | 359 | case longTag: |
duke@435 | 360 | { |
duke@435 | 361 | jlong temp = type()->as_LongConstant()->value(); |
duke@435 | 362 | return HASH3(name(), high(temp), low(temp)); |
duke@435 | 363 | } |
duke@435 | 364 | case floatTag: |
duke@435 | 365 | return HASH2(name(), jint_cast(type()->as_FloatConstant()->value())); |
duke@435 | 366 | case doubleTag: |
duke@435 | 367 | { |
duke@435 | 368 | jlong temp = jlong_cast(type()->as_DoubleConstant()->value()); |
duke@435 | 369 | return HASH3(name(), high(temp), low(temp)); |
duke@435 | 370 | } |
duke@435 | 371 | case objectTag: |
duke@435 | 372 | assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values"); |
duke@435 | 373 | return HASH2(name(), type()->as_ObjectType()->constant_value()); |
duke@435 | 374 | } |
duke@435 | 375 | } |
duke@435 | 376 | return 0; |
duke@435 | 377 | } |
duke@435 | 378 | |
duke@435 | 379 | bool Constant::is_equal(Value v) const { |
duke@435 | 380 | if (v->as_Constant() == NULL) return false; |
duke@435 | 381 | |
duke@435 | 382 | switch (type()->tag()) { |
duke@435 | 383 | case intTag: |
duke@435 | 384 | { |
duke@435 | 385 | IntConstant* t1 = type()->as_IntConstant(); |
duke@435 | 386 | IntConstant* t2 = v->type()->as_IntConstant(); |
duke@435 | 387 | return (t1 != NULL && t2 != NULL && |
duke@435 | 388 | t1->value() == t2->value()); |
duke@435 | 389 | } |
duke@435 | 390 | case longTag: |
duke@435 | 391 | { |
duke@435 | 392 | LongConstant* t1 = type()->as_LongConstant(); |
duke@435 | 393 | LongConstant* t2 = v->type()->as_LongConstant(); |
duke@435 | 394 | return (t1 != NULL && t2 != NULL && |
duke@435 | 395 | t1->value() == t2->value()); |
duke@435 | 396 | } |
duke@435 | 397 | case floatTag: |
duke@435 | 398 | { |
duke@435 | 399 | FloatConstant* t1 = type()->as_FloatConstant(); |
duke@435 | 400 | FloatConstant* t2 = v->type()->as_FloatConstant(); |
duke@435 | 401 | return (t1 != NULL && t2 != NULL && |
duke@435 | 402 | jint_cast(t1->value()) == jint_cast(t2->value())); |
duke@435 | 403 | } |
duke@435 | 404 | case doubleTag: |
duke@435 | 405 | { |
duke@435 | 406 | DoubleConstant* t1 = type()->as_DoubleConstant(); |
duke@435 | 407 | DoubleConstant* t2 = v->type()->as_DoubleConstant(); |
duke@435 | 408 | return (t1 != NULL && t2 != NULL && |
duke@435 | 409 | jlong_cast(t1->value()) == jlong_cast(t2->value())); |
duke@435 | 410 | } |
duke@435 | 411 | case objectTag: |
duke@435 | 412 | { |
duke@435 | 413 | ObjectType* t1 = type()->as_ObjectType(); |
duke@435 | 414 | ObjectType* t2 = v->type()->as_ObjectType(); |
duke@435 | 415 | return (t1 != NULL && t2 != NULL && |
duke@435 | 416 | t1->is_loaded() && t2->is_loaded() && |
duke@435 | 417 | t1->constant_value() == t2->constant_value()); |
duke@435 | 418 | } |
duke@435 | 419 | } |
duke@435 | 420 | return false; |
duke@435 | 421 | } |
duke@435 | 422 | |
roland@2254 | 423 | Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const { |
duke@435 | 424 | Constant* rc = right->as_Constant(); |
duke@435 | 425 | // other is not a constant |
roland@2254 | 426 | if (rc == NULL) return not_comparable; |
duke@435 | 427 | |
duke@435 | 428 | ValueType* lt = type(); |
duke@435 | 429 | ValueType* rt = rc->type(); |
duke@435 | 430 | // different types |
roland@2254 | 431 | if (lt->base() != rt->base()) return not_comparable; |
duke@435 | 432 | switch (lt->tag()) { |
duke@435 | 433 | case intTag: { |
duke@435 | 434 | int x = lt->as_IntConstant()->value(); |
duke@435 | 435 | int y = rt->as_IntConstant()->value(); |
duke@435 | 436 | switch (cond) { |
roland@2254 | 437 | case If::eql: return x == y ? cond_true : cond_false; |
roland@2254 | 438 | case If::neq: return x != y ? cond_true : cond_false; |
roland@2254 | 439 | case If::lss: return x < y ? cond_true : cond_false; |
roland@2254 | 440 | case If::leq: return x <= y ? cond_true : cond_false; |
roland@2254 | 441 | case If::gtr: return x > y ? cond_true : cond_false; |
roland@2254 | 442 | case If::geq: return x >= y ? cond_true : cond_false; |
duke@435 | 443 | } |
duke@435 | 444 | break; |
duke@435 | 445 | } |
duke@435 | 446 | case longTag: { |
duke@435 | 447 | jlong x = lt->as_LongConstant()->value(); |
duke@435 | 448 | jlong y = rt->as_LongConstant()->value(); |
duke@435 | 449 | switch (cond) { |
roland@2254 | 450 | case If::eql: return x == y ? cond_true : cond_false; |
roland@2254 | 451 | case If::neq: return x != y ? cond_true : cond_false; |
roland@2254 | 452 | case If::lss: return x < y ? cond_true : cond_false; |
roland@2254 | 453 | case If::leq: return x <= y ? cond_true : cond_false; |
roland@2254 | 454 | case If::gtr: return x > y ? cond_true : cond_false; |
roland@2254 | 455 | case If::geq: return x >= y ? cond_true : cond_false; |
duke@435 | 456 | } |
duke@435 | 457 | break; |
duke@435 | 458 | } |
duke@435 | 459 | case objectTag: { |
duke@435 | 460 | ciObject* xvalue = lt->as_ObjectType()->constant_value(); |
duke@435 | 461 | ciObject* yvalue = rt->as_ObjectType()->constant_value(); |
duke@435 | 462 | assert(xvalue != NULL && yvalue != NULL, "not constants"); |
duke@435 | 463 | if (xvalue->is_loaded() && yvalue->is_loaded()) { |
duke@435 | 464 | switch (cond) { |
roland@2254 | 465 | case If::eql: return xvalue == yvalue ? cond_true : cond_false; |
roland@2254 | 466 | case If::neq: return xvalue != yvalue ? cond_true : cond_false; |
duke@435 | 467 | } |
duke@435 | 468 | } |
duke@435 | 469 | break; |
duke@435 | 470 | } |
duke@435 | 471 | } |
roland@2254 | 472 | return not_comparable; |
duke@435 | 473 | } |
duke@435 | 474 | |
duke@435 | 475 | |
duke@435 | 476 | // Implementation of BlockBegin |
duke@435 | 477 | |
duke@435 | 478 | void BlockBegin::set_end(BlockEnd* end) { |
duke@435 | 479 | assert(end != NULL, "should not reset block end to NULL"); |
duke@435 | 480 | BlockEnd* old_end = _end; |
duke@435 | 481 | if (end == old_end) { |
duke@435 | 482 | return; |
duke@435 | 483 | } |
duke@435 | 484 | // Must make the predecessors/successors match up with the |
duke@435 | 485 | // BlockEnd's notion. |
duke@435 | 486 | int i, n; |
duke@435 | 487 | if (old_end != NULL) { |
duke@435 | 488 | // disconnect from the old end |
duke@435 | 489 | old_end->set_begin(NULL); |
duke@435 | 490 | |
duke@435 | 491 | // disconnect this block from it's current successors |
duke@435 | 492 | for (i = 0; i < _successors.length(); i++) { |
duke@435 | 493 | _successors.at(i)->remove_predecessor(this); |
duke@435 | 494 | } |
duke@435 | 495 | } |
duke@435 | 496 | _end = end; |
duke@435 | 497 | |
duke@435 | 498 | _successors.clear(); |
duke@435 | 499 | // Now reset successors list based on BlockEnd |
duke@435 | 500 | n = end->number_of_sux(); |
duke@435 | 501 | for (i = 0; i < n; i++) { |
duke@435 | 502 | BlockBegin* sux = end->sux_at(i); |
duke@435 | 503 | _successors.append(sux); |
duke@435 | 504 | sux->_predecessors.append(this); |
duke@435 | 505 | } |
duke@435 | 506 | _end->set_begin(this); |
duke@435 | 507 | } |
duke@435 | 508 | |
duke@435 | 509 | |
duke@435 | 510 | void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) { |
duke@435 | 511 | // disconnect any edges between from and to |
duke@435 | 512 | #ifndef PRODUCT |
duke@435 | 513 | if (PrintIR && Verbose) { |
duke@435 | 514 | tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id()); |
duke@435 | 515 | } |
duke@435 | 516 | #endif |
duke@435 | 517 | for (int s = 0; s < from->number_of_sux();) { |
duke@435 | 518 | BlockBegin* sux = from->sux_at(s); |
duke@435 | 519 | if (sux == to) { |
duke@435 | 520 | int index = sux->_predecessors.index_of(from); |
duke@435 | 521 | if (index >= 0) { |
duke@435 | 522 | sux->_predecessors.remove_at(index); |
duke@435 | 523 | } |
duke@435 | 524 | from->_successors.remove_at(s); |
duke@435 | 525 | } else { |
duke@435 | 526 | s++; |
duke@435 | 527 | } |
duke@435 | 528 | } |
duke@435 | 529 | } |
duke@435 | 530 | |
duke@435 | 531 | |
duke@435 | 532 | void BlockBegin::disconnect_from_graph() { |
duke@435 | 533 | // disconnect this block from all other blocks |
duke@435 | 534 | for (int p = 0; p < number_of_preds(); p++) { |
duke@435 | 535 | pred_at(p)->remove_successor(this); |
duke@435 | 536 | } |
duke@435 | 537 | for (int s = 0; s < number_of_sux(); s++) { |
duke@435 | 538 | sux_at(s)->remove_predecessor(this); |
duke@435 | 539 | } |
duke@435 | 540 | } |
duke@435 | 541 | |
duke@435 | 542 | void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) { |
duke@435 | 543 | // modify predecessors before substituting successors |
duke@435 | 544 | for (int i = 0; i < number_of_sux(); i++) { |
duke@435 | 545 | if (sux_at(i) == old_sux) { |
duke@435 | 546 | // remove old predecessor before adding new predecessor |
duke@435 | 547 | // otherwise there is a dead predecessor in the list |
duke@435 | 548 | new_sux->remove_predecessor(old_sux); |
duke@435 | 549 | new_sux->add_predecessor(this); |
duke@435 | 550 | } |
duke@435 | 551 | } |
duke@435 | 552 | old_sux->remove_predecessor(this); |
duke@435 | 553 | end()->substitute_sux(old_sux, new_sux); |
duke@435 | 554 | } |
duke@435 | 555 | |
duke@435 | 556 | |
duke@435 | 557 | |
duke@435 | 558 | // In general it is not possible to calculate a value for the field "depth_first_number" |
duke@435 | 559 | // of the inserted block, without recomputing the values of the other blocks |
duke@435 | 560 | // in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless. |
duke@435 | 561 | BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) { |
roland@2174 | 562 | BlockBegin* new_sux = new BlockBegin(-99); |
duke@435 | 563 | |
duke@435 | 564 | // mark this block (special treatment when block order is computed) |
duke@435 | 565 | new_sux->set(critical_edge_split_flag); |
duke@435 | 566 | |
duke@435 | 567 | // This goto is not a safepoint. |
duke@435 | 568 | Goto* e = new Goto(sux, false); |
roland@2174 | 569 | new_sux->set_next(e, end()->state()->bci()); |
duke@435 | 570 | new_sux->set_end(e); |
duke@435 | 571 | // setup states |
duke@435 | 572 | ValueStack* s = end()->state(); |
duke@435 | 573 | new_sux->set_state(s->copy()); |
duke@435 | 574 | e->set_state(s->copy()); |
duke@435 | 575 | assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!"); |
duke@435 | 576 | assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!"); |
duke@435 | 577 | assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!"); |
duke@435 | 578 | |
duke@435 | 579 | // link predecessor to new block |
duke@435 | 580 | end()->substitute_sux(sux, new_sux); |
duke@435 | 581 | |
duke@435 | 582 | // The ordering needs to be the same, so remove the link that the |
duke@435 | 583 | // set_end call above added and substitute the new_sux for this |
duke@435 | 584 | // block. |
duke@435 | 585 | sux->remove_predecessor(new_sux); |
duke@435 | 586 | |
duke@435 | 587 | // the successor could be the target of a switch so it might have |
duke@435 | 588 | // multiple copies of this predecessor, so substitute the new_sux |
duke@435 | 589 | // for the first and delete the rest. |
duke@435 | 590 | bool assigned = false; |
duke@435 | 591 | BlockList& list = sux->_predecessors; |
duke@435 | 592 | for (int i = 0; i < list.length(); i++) { |
duke@435 | 593 | BlockBegin** b = list.adr_at(i); |
duke@435 | 594 | if (*b == this) { |
duke@435 | 595 | if (assigned) { |
duke@435 | 596 | list.remove_at(i); |
duke@435 | 597 | // reprocess this index |
duke@435 | 598 | i--; |
duke@435 | 599 | } else { |
duke@435 | 600 | assigned = true; |
duke@435 | 601 | *b = new_sux; |
duke@435 | 602 | } |
duke@435 | 603 | // link the new block back to it's predecessors. |
duke@435 | 604 | new_sux->add_predecessor(this); |
duke@435 | 605 | } |
duke@435 | 606 | } |
duke@435 | 607 | assert(assigned == true, "should have assigned at least once"); |
duke@435 | 608 | return new_sux; |
duke@435 | 609 | } |
duke@435 | 610 | |
duke@435 | 611 | |
duke@435 | 612 | void BlockBegin::remove_successor(BlockBegin* pred) { |
duke@435 | 613 | int idx; |
duke@435 | 614 | while ((idx = _successors.index_of(pred)) >= 0) { |
duke@435 | 615 | _successors.remove_at(idx); |
duke@435 | 616 | } |
duke@435 | 617 | } |
duke@435 | 618 | |
duke@435 | 619 | |
duke@435 | 620 | void BlockBegin::add_predecessor(BlockBegin* pred) { |
duke@435 | 621 | _predecessors.append(pred); |
duke@435 | 622 | } |
duke@435 | 623 | |
duke@435 | 624 | |
duke@435 | 625 | void BlockBegin::remove_predecessor(BlockBegin* pred) { |
duke@435 | 626 | int idx; |
duke@435 | 627 | while ((idx = _predecessors.index_of(pred)) >= 0) { |
duke@435 | 628 | _predecessors.remove_at(idx); |
duke@435 | 629 | } |
duke@435 | 630 | } |
duke@435 | 631 | |
duke@435 | 632 | |
duke@435 | 633 | void BlockBegin::add_exception_handler(BlockBegin* b) { |
duke@435 | 634 | assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist"); |
duke@435 | 635 | // add only if not in the list already |
duke@435 | 636 | if (!_exception_handlers.contains(b)) _exception_handlers.append(b); |
duke@435 | 637 | } |
duke@435 | 638 | |
duke@435 | 639 | int BlockBegin::add_exception_state(ValueStack* state) { |
duke@435 | 640 | assert(is_set(exception_entry_flag), "only for xhandlers"); |
duke@435 | 641 | if (_exception_states == NULL) { |
duke@435 | 642 | _exception_states = new ValueStackStack(4); |
duke@435 | 643 | } |
duke@435 | 644 | _exception_states->append(state); |
duke@435 | 645 | return _exception_states->length() - 1; |
duke@435 | 646 | } |
duke@435 | 647 | |
duke@435 | 648 | |
duke@435 | 649 | void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) { |
duke@435 | 650 | if (!mark.at(block_id())) { |
duke@435 | 651 | mark.at_put(block_id(), true); |
duke@435 | 652 | closure->block_do(this); |
duke@435 | 653 | BlockEnd* e = end(); // must do this after block_do because block_do may change it! |
duke@435 | 654 | { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); } |
duke@435 | 655 | { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); } |
duke@435 | 656 | } |
duke@435 | 657 | } |
duke@435 | 658 | |
duke@435 | 659 | |
duke@435 | 660 | void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) { |
duke@435 | 661 | if (!mark.at(block_id())) { |
duke@435 | 662 | mark.at_put(block_id(), true); |
duke@435 | 663 | BlockEnd* e = end(); |
duke@435 | 664 | { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); } |
duke@435 | 665 | { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); } |
duke@435 | 666 | closure->block_do(this); |
duke@435 | 667 | } |
duke@435 | 668 | } |
duke@435 | 669 | |
duke@435 | 670 | |
duke@435 | 671 | void BlockBegin::iterate_preorder(BlockClosure* closure) { |
duke@435 | 672 | boolArray mark(number_of_blocks(), false); |
duke@435 | 673 | iterate_preorder(mark, closure); |
duke@435 | 674 | } |
duke@435 | 675 | |
duke@435 | 676 | |
duke@435 | 677 | void BlockBegin::iterate_postorder(BlockClosure* closure) { |
duke@435 | 678 | boolArray mark(number_of_blocks(), false); |
duke@435 | 679 | iterate_postorder(mark, closure); |
duke@435 | 680 | } |
duke@435 | 681 | |
duke@435 | 682 | |
iveresov@1939 | 683 | void BlockBegin::block_values_do(ValueVisitor* f) { |
duke@435 | 684 | for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f); |
duke@435 | 685 | } |
duke@435 | 686 | |
duke@435 | 687 | |
duke@435 | 688 | #ifndef PRODUCT |
iveresov@2138 | 689 | #define TRACE_PHI(code) if (PrintPhiFunctions) { code; } |
duke@435 | 690 | #else |
iveresov@2138 | 691 | #define TRACE_PHI(coce) |
duke@435 | 692 | #endif |
duke@435 | 693 | |
duke@435 | 694 | |
duke@435 | 695 | bool BlockBegin::try_merge(ValueStack* new_state) { |
duke@435 | 696 | TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id())); |
duke@435 | 697 | |
duke@435 | 698 | // local variables used for state iteration |
duke@435 | 699 | int index; |
duke@435 | 700 | Value new_value, existing_value; |
duke@435 | 701 | |
duke@435 | 702 | ValueStack* existing_state = state(); |
duke@435 | 703 | if (existing_state == NULL) { |
duke@435 | 704 | TRACE_PHI(tty->print_cr("first call of try_merge for this block")); |
duke@435 | 705 | |
duke@435 | 706 | if (is_set(BlockBegin::was_visited_flag)) { |
duke@435 | 707 | // this actually happens for complicated jsr/ret structures |
duke@435 | 708 | return false; // BAILOUT in caller |
duke@435 | 709 | } |
duke@435 | 710 | |
duke@435 | 711 | // copy state because it is altered |
roland@2174 | 712 | new_state = new_state->copy(ValueStack::BlockBeginState, bci()); |
duke@435 | 713 | |
duke@435 | 714 | // Use method liveness to invalidate dead locals |
duke@435 | 715 | MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci()); |
duke@435 | 716 | if (liveness.is_valid()) { |
duke@435 | 717 | assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness"); |
duke@435 | 718 | |
duke@435 | 719 | for_each_local_value(new_state, index, new_value) { |
duke@435 | 720 | if (!liveness.at(index) || new_value->type()->is_illegal()) { |
duke@435 | 721 | new_state->invalidate_local(index); |
duke@435 | 722 | TRACE_PHI(tty->print_cr("invalidating dead local %d", index)); |
duke@435 | 723 | } |
duke@435 | 724 | } |
duke@435 | 725 | } |
duke@435 | 726 | |
duke@435 | 727 | if (is_set(BlockBegin::parser_loop_header_flag)) { |
duke@435 | 728 | TRACE_PHI(tty->print_cr("loop header block, initializing phi functions")); |
duke@435 | 729 | |
duke@435 | 730 | for_each_stack_value(new_state, index, new_value) { |
duke@435 | 731 | new_state->setup_phi_for_stack(this, index); |
duke@435 | 732 | TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", new_state->stack_at(index)->type()->tchar(), new_state->stack_at(index)->id(), index)); |
duke@435 | 733 | } |
duke@435 | 734 | |
duke@435 | 735 | BitMap requires_phi_function = new_state->scope()->requires_phi_function(); |
duke@435 | 736 | |
duke@435 | 737 | for_each_local_value(new_state, index, new_value) { |
duke@435 | 738 | bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1)); |
duke@435 | 739 | if (requires_phi || !SelectivePhiFunctions) { |
duke@435 | 740 | new_state->setup_phi_for_local(this, index); |
duke@435 | 741 | TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", new_state->local_at(index)->type()->tchar(), new_state->local_at(index)->id(), index)); |
duke@435 | 742 | } |
duke@435 | 743 | } |
duke@435 | 744 | } |
duke@435 | 745 | |
duke@435 | 746 | // initialize state of block |
duke@435 | 747 | set_state(new_state); |
duke@435 | 748 | |
roland@2174 | 749 | } else if (existing_state->is_same(new_state)) { |
duke@435 | 750 | TRACE_PHI(tty->print_cr("exisiting state found")); |
duke@435 | 751 | |
duke@435 | 752 | assert(existing_state->scope() == new_state->scope(), "not matching"); |
duke@435 | 753 | assert(existing_state->locals_size() == new_state->locals_size(), "not matching"); |
duke@435 | 754 | assert(existing_state->stack_size() == new_state->stack_size(), "not matching"); |
duke@435 | 755 | |
duke@435 | 756 | if (is_set(BlockBegin::was_visited_flag)) { |
duke@435 | 757 | TRACE_PHI(tty->print_cr("loop header block, phis must be present")); |
duke@435 | 758 | |
duke@435 | 759 | if (!is_set(BlockBegin::parser_loop_header_flag)) { |
duke@435 | 760 | // this actually happens for complicated jsr/ret structures |
duke@435 | 761 | return false; // BAILOUT in caller |
duke@435 | 762 | } |
duke@435 | 763 | |
duke@435 | 764 | for_each_local_value(existing_state, index, existing_value) { |
duke@435 | 765 | Value new_value = new_state->local_at(index); |
duke@435 | 766 | if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) { |
duke@435 | 767 | // The old code invalidated the phi function here |
duke@435 | 768 | // Because dead locals are replaced with NULL, this is a very rare case now, so simply bail out |
duke@435 | 769 | return false; // BAILOUT in caller |
duke@435 | 770 | } |
duke@435 | 771 | } |
duke@435 | 772 | |
duke@435 | 773 | #ifdef ASSERT |
duke@435 | 774 | // check that all necessary phi functions are present |
duke@435 | 775 | for_each_stack_value(existing_state, index, existing_value) { |
duke@435 | 776 | assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required"); |
duke@435 | 777 | } |
duke@435 | 778 | for_each_local_value(existing_state, index, existing_value) { |
duke@435 | 779 | assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required"); |
duke@435 | 780 | } |
duke@435 | 781 | #endif |
duke@435 | 782 | |
duke@435 | 783 | } else { |
duke@435 | 784 | TRACE_PHI(tty->print_cr("creating phi functions on demand")); |
duke@435 | 785 | |
duke@435 | 786 | // create necessary phi functions for stack |
duke@435 | 787 | for_each_stack_value(existing_state, index, existing_value) { |
duke@435 | 788 | Value new_value = new_state->stack_at(index); |
duke@435 | 789 | Phi* existing_phi = existing_value->as_Phi(); |
duke@435 | 790 | |
duke@435 | 791 | if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) { |
duke@435 | 792 | existing_state->setup_phi_for_stack(this, index); |
duke@435 | 793 | TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", existing_state->stack_at(index)->type()->tchar(), existing_state->stack_at(index)->id(), index)); |
duke@435 | 794 | } |
duke@435 | 795 | } |
duke@435 | 796 | |
duke@435 | 797 | // create necessary phi functions for locals |
duke@435 | 798 | for_each_local_value(existing_state, index, existing_value) { |
duke@435 | 799 | Value new_value = new_state->local_at(index); |
duke@435 | 800 | Phi* existing_phi = existing_value->as_Phi(); |
duke@435 | 801 | |
duke@435 | 802 | if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) { |
duke@435 | 803 | existing_state->invalidate_local(index); |
duke@435 | 804 | TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index)); |
duke@435 | 805 | } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) { |
duke@435 | 806 | existing_state->setup_phi_for_local(this, index); |
duke@435 | 807 | TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", existing_state->local_at(index)->type()->tchar(), existing_state->local_at(index)->id(), index)); |
duke@435 | 808 | } |
duke@435 | 809 | } |
duke@435 | 810 | } |
duke@435 | 811 | |
duke@435 | 812 | assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal"); |
duke@435 | 813 | |
duke@435 | 814 | } else { |
duke@435 | 815 | assert(false, "stack or locks not matching (invalid bytecodes)"); |
duke@435 | 816 | return false; |
duke@435 | 817 | } |
duke@435 | 818 | |
duke@435 | 819 | TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id())); |
duke@435 | 820 | |
duke@435 | 821 | return true; |
duke@435 | 822 | } |
duke@435 | 823 | |
duke@435 | 824 | |
duke@435 | 825 | #ifndef PRODUCT |
duke@435 | 826 | void BlockBegin::print_block() { |
duke@435 | 827 | InstructionPrinter ip; |
duke@435 | 828 | print_block(ip, false); |
duke@435 | 829 | } |
duke@435 | 830 | |
duke@435 | 831 | |
duke@435 | 832 | void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) { |
duke@435 | 833 | ip.print_instr(this); tty->cr(); |
duke@435 | 834 | ip.print_stack(this->state()); tty->cr(); |
duke@435 | 835 | ip.print_inline_level(this); |
duke@435 | 836 | ip.print_head(); |
duke@435 | 837 | for (Instruction* n = next(); n != NULL; n = n->next()) { |
duke@435 | 838 | if (!live_only || n->is_pinned() || n->use_count() > 0) { |
duke@435 | 839 | ip.print_line(n); |
duke@435 | 840 | } |
duke@435 | 841 | } |
duke@435 | 842 | tty->cr(); |
duke@435 | 843 | } |
duke@435 | 844 | #endif // PRODUCT |
duke@435 | 845 | |
duke@435 | 846 | |
duke@435 | 847 | // Implementation of BlockList |
duke@435 | 848 | |
duke@435 | 849 | void BlockList::iterate_forward (BlockClosure* closure) { |
duke@435 | 850 | const int l = length(); |
duke@435 | 851 | for (int i = 0; i < l; i++) closure->block_do(at(i)); |
duke@435 | 852 | } |
duke@435 | 853 | |
duke@435 | 854 | |
duke@435 | 855 | void BlockList::iterate_backward(BlockClosure* closure) { |
duke@435 | 856 | for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i)); |
duke@435 | 857 | } |
duke@435 | 858 | |
duke@435 | 859 | |
duke@435 | 860 | void BlockList::blocks_do(void f(BlockBegin*)) { |
duke@435 | 861 | for (int i = length() - 1; i >= 0; i--) f(at(i)); |
duke@435 | 862 | } |
duke@435 | 863 | |
duke@435 | 864 | |
iveresov@1939 | 865 | void BlockList::values_do(ValueVisitor* f) { |
duke@435 | 866 | for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f); |
duke@435 | 867 | } |
duke@435 | 868 | |
duke@435 | 869 | |
duke@435 | 870 | #ifndef PRODUCT |
duke@435 | 871 | void BlockList::print(bool cfg_only, bool live_only) { |
duke@435 | 872 | InstructionPrinter ip; |
duke@435 | 873 | for (int i = 0; i < length(); i++) { |
duke@435 | 874 | BlockBegin* block = at(i); |
duke@435 | 875 | if (cfg_only) { |
duke@435 | 876 | ip.print_instr(block); tty->cr(); |
duke@435 | 877 | } else { |
duke@435 | 878 | block->print_block(ip, live_only); |
duke@435 | 879 | } |
duke@435 | 880 | } |
duke@435 | 881 | } |
duke@435 | 882 | #endif // PRODUCT |
duke@435 | 883 | |
duke@435 | 884 | |
duke@435 | 885 | // Implementation of BlockEnd |
duke@435 | 886 | |
duke@435 | 887 | void BlockEnd::set_begin(BlockBegin* begin) { |
duke@435 | 888 | BlockList* sux = NULL; |
duke@435 | 889 | if (begin != NULL) { |
duke@435 | 890 | sux = begin->successors(); |
duke@435 | 891 | } else if (_begin != NULL) { |
duke@435 | 892 | // copy our sux list |
duke@435 | 893 | BlockList* sux = new BlockList(_begin->number_of_sux()); |
duke@435 | 894 | for (int i = 0; i < _begin->number_of_sux(); i++) { |
duke@435 | 895 | sux->append(_begin->sux_at(i)); |
duke@435 | 896 | } |
duke@435 | 897 | } |
duke@435 | 898 | _sux = sux; |
duke@435 | 899 | _begin = begin; |
duke@435 | 900 | } |
duke@435 | 901 | |
duke@435 | 902 | |
duke@435 | 903 | void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) { |
duke@435 | 904 | substitute(*_sux, old_sux, new_sux); |
duke@435 | 905 | } |
duke@435 | 906 | |
duke@435 | 907 | |
duke@435 | 908 | // Implementation of Phi |
duke@435 | 909 | |
duke@435 | 910 | // Normal phi functions take their operands from the last instruction of the |
duke@435 | 911 | // predecessor. Special handling is needed for xhanlder entries because there |
duke@435 | 912 | // the state of arbitrary instructions are needed. |
duke@435 | 913 | |
duke@435 | 914 | Value Phi::operand_at(int i) const { |
duke@435 | 915 | ValueStack* state; |
duke@435 | 916 | if (_block->is_set(BlockBegin::exception_entry_flag)) { |
duke@435 | 917 | state = _block->exception_state_at(i); |
duke@435 | 918 | } else { |
duke@435 | 919 | state = _block->pred_at(i)->end()->state(); |
duke@435 | 920 | } |
duke@435 | 921 | assert(state != NULL, ""); |
duke@435 | 922 | |
duke@435 | 923 | if (is_local()) { |
duke@435 | 924 | return state->local_at(local_index()); |
duke@435 | 925 | } else { |
duke@435 | 926 | return state->stack_at(stack_index()); |
duke@435 | 927 | } |
duke@435 | 928 | } |
duke@435 | 929 | |
duke@435 | 930 | |
duke@435 | 931 | int Phi::operand_count() const { |
duke@435 | 932 | if (_block->is_set(BlockBegin::exception_entry_flag)) { |
duke@435 | 933 | return _block->number_of_exception_states(); |
duke@435 | 934 | } else { |
duke@435 | 935 | return _block->number_of_preds(); |
duke@435 | 936 | } |
duke@435 | 937 | } |
duke@435 | 938 | |
duke@435 | 939 | |
iveresov@2138 | 940 | |
iveresov@2138 | 941 | void ProfileInvoke::state_values_do(ValueVisitor* f) { |
iveresov@2138 | 942 | if (state() != NULL) state()->values_do(f); |
iveresov@2138 | 943 | } |