1 /*
   2  * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "c1/c1_CodeStubs.hpp"
  27 #include "c1/c1_InstructionPrinter.hpp"
  28 #include "c1/c1_LIR.hpp"
  29 #include "c1/c1_LIRAssembler.hpp"
  30 #include "c1/c1_ValueStack.hpp"
  31 #include "ci/ciInlineKlass.hpp"
  32 #include "ci/ciInstance.hpp"
  33 #include "runtime/safepointMechanism.inline.hpp"
  34 #include "runtime/sharedRuntime.hpp"
  35 #include "runtime/vm_version.hpp"
  36 
  37 Register LIR_OprDesc::as_register() const {
  38   return FrameMap::cpu_rnr2reg(cpu_regnr());
  39 }
  40 
  41 Register LIR_OprDesc::as_register_lo() const {
  42   return FrameMap::cpu_rnr2reg(cpu_regnrLo());
  43 }
  44 
  45 Register LIR_OprDesc::as_register_hi() const {
  46   return FrameMap::cpu_rnr2reg(cpu_regnrHi());
  47 }
  48 
  49 LIR_Opr LIR_OprFact::illegalOpr = LIR_OprFact::illegal();
  50 
  51 LIR_Opr LIR_OprFact::value_type(ValueType* type) {
  52   ValueTag tag = type->tag();
  53   switch (tag) {
  54   case metaDataTag : {
  55     ClassConstant* c = type->as_ClassConstant();
  56     if (c != NULL && !c->value()->is_loaded()) {
  57       return LIR_OprFact::metadataConst(NULL);
  58     } else if (c != NULL) {
  59       return LIR_OprFact::metadataConst(c->value()->constant_encoding());
  60     } else {
  61       MethodConstant* m = type->as_MethodConstant();
  62       assert (m != NULL, "not a class or a method?");
  63       return LIR_OprFact::metadataConst(m->value()->constant_encoding());
  64     }
  65   }
  66   case objectTag : {
  67       return LIR_OprFact::oopConst(type->as_ObjectType()->encoding());
  68     }
  69   case addressTag: return LIR_OprFact::addressConst(type->as_AddressConstant()->value());
  70   case intTag    : return LIR_OprFact::intConst(type->as_IntConstant()->value());
  71   case floatTag  : return LIR_OprFact::floatConst(type->as_FloatConstant()->value());
  72   case longTag   : return LIR_OprFact::longConst(type->as_LongConstant()->value());
  73   case doubleTag : return LIR_OprFact::doubleConst(type->as_DoubleConstant()->value());
  74   default: ShouldNotReachHere(); return LIR_OprFact::intConst(-1);
  75   }
  76 }
  77 
  78 
  79 //---------------------------------------------------
  80 
  81 
  82 LIR_Address::Scale LIR_Address::scale(BasicType type) {
  83   int elem_size = type2aelembytes(type);
  84   switch (elem_size) {
  85   case 1: return LIR_Address::times_1;
  86   case 2: return LIR_Address::times_2;
  87   case 4: return LIR_Address::times_4;
  88   case 8: return LIR_Address::times_8;
  89   }
  90   ShouldNotReachHere();
  91   return LIR_Address::times_1;
  92 }
  93 
  94 //---------------------------------------------------
  95 
  96 char LIR_OprDesc::type_char(BasicType t) {
  97   switch (t) {
  98     case T_ARRAY:
  99     case T_INLINE_TYPE:
 100       t = T_OBJECT;
 101     case T_BOOLEAN:
 102     case T_CHAR:
 103     case T_FLOAT:
 104     case T_DOUBLE:
 105     case T_BYTE:
 106     case T_SHORT:
 107     case T_INT:
 108     case T_LONG:
 109     case T_OBJECT:
 110     case T_ADDRESS:
 111     case T_VOID:
 112       return ::type2char(t);
 113     case T_METADATA:
 114       return 'M';
 115     case T_ILLEGAL:
 116       return '?';
 117 
 118     default:
 119       ShouldNotReachHere();
 120       return '?';
 121   }
 122 }
 123 
 124 #ifndef PRODUCT
 125 void LIR_OprDesc::validate_type() const {
 126 
 127 #ifdef ASSERT
 128   if (!is_pointer() && !is_illegal()) {
 129     OprKind kindfield = kind_field(); // Factored out because of compiler bug, see 8002160
 130     switch (as_BasicType(type_field())) {
 131     case T_LONG:
 132       assert((kindfield == cpu_register || kindfield == stack_value) &&
 133              size_field() == double_size, "must match");
 134       break;
 135     case T_FLOAT:
 136       // FP return values can be also in CPU registers on ARM and PPC32 (softfp ABI)
 137       assert((kindfield == fpu_register || kindfield == stack_value
 138              ARM_ONLY(|| kindfield == cpu_register)
 139              PPC32_ONLY(|| kindfield == cpu_register) ) &&
 140              size_field() == single_size, "must match");
 141       break;
 142     case T_DOUBLE:
 143       // FP return values can be also in CPU registers on ARM and PPC32 (softfp ABI)
 144       assert((kindfield == fpu_register || kindfield == stack_value
 145              ARM_ONLY(|| kindfield == cpu_register)
 146              PPC32_ONLY(|| kindfield == cpu_register) ) &&
 147              size_field() == double_size, "must match");
 148       break;
 149     case T_BOOLEAN:
 150     case T_CHAR:
 151     case T_BYTE:
 152     case T_SHORT:
 153     case T_INT:
 154     case T_ADDRESS:
 155     case T_OBJECT:
 156     case T_METADATA:
 157     case T_ARRAY:
 158     case T_INLINE_TYPE:
 159       assert((kindfield == cpu_register || kindfield == stack_value) &&
 160              size_field() == single_size, "must match");
 161       break;
 162 
 163     case T_ILLEGAL:
 164       // XXX TKR also means unknown right now
 165       // assert(is_illegal(), "must match");
 166       break;
 167 
 168     default:
 169       ShouldNotReachHere();
 170     }
 171   }
 172 #endif
 173 
 174 }
 175 #endif // PRODUCT
 176 
 177 
 178 bool LIR_OprDesc::is_oop() const {
 179   if (is_pointer()) {
 180     return pointer()->is_oop_pointer();
 181   } else {
 182     OprType t= type_field();
 183     assert(t != unknown_type, "not set");
 184     return t == object_type;
 185   }
 186 }
 187 
 188 
 189 
 190 void LIR_Op2::verify() const {
 191 #ifdef ASSERT
 192   switch (code()) {
 193     case lir_cmove:
 194     case lir_xchg:
 195       break;
 196 
 197     default:
 198       assert(!result_opr()->is_register() || !result_opr()->is_oop_register(),
 199              "can't produce oops from arith");
 200   }
 201 
 202   if (TwoOperandLIRForm) {
 203 
 204 #ifdef ASSERT
 205     bool threeOperandForm = false;
 206 #ifdef S390
 207     // There are 3 operand shifts on S390 (see LIR_Assembler::shift_op()).
 208     threeOperandForm =
 209       code() == lir_shl ||
 210       ((code() == lir_shr || code() == lir_ushr) && (result_opr()->is_double_cpu() || in_opr1()->type() == T_OBJECT));
 211 #endif
 212 #endif
 213 
 214     switch (code()) {
 215     case lir_add:
 216     case lir_sub:
 217     case lir_mul:
 218     case lir_div:
 219     case lir_rem:
 220     case lir_logic_and:
 221     case lir_logic_or:
 222     case lir_logic_xor:
 223     case lir_shl:
 224     case lir_shr:
 225       assert(in_opr1() == result_opr() || threeOperandForm, "opr1 and result must match");
 226       assert(in_opr1()->is_valid() && in_opr2()->is_valid(), "must be valid");
 227       break;
 228 
 229     // special handling for lir_ushr because of write barriers
 230     case lir_ushr:
 231       assert(in_opr1() == result_opr() || in_opr2()->is_constant() || threeOperandForm, "opr1 and result must match or shift count is constant");
 232       assert(in_opr1()->is_valid() && in_opr2()->is_valid(), "must be valid");
 233       break;
 234 
 235     default:
 236       break;
 237     }
 238   }
 239 #endif
 240 }
 241 
 242 
 243 LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, BlockBegin* block)
 244   : LIR_Op(lir_branch, LIR_OprFact::illegalOpr, (CodeEmitInfo*)NULL)
 245   , _cond(cond)
 246   , _label(block->label())
 247   , _block(block)
 248   , _ublock(NULL)
 249   , _stub(NULL) {
 250 }
 251 
 252 LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, CodeStub* stub) :
 253   LIR_Op(lir_branch, LIR_OprFact::illegalOpr, (CodeEmitInfo*)NULL)
 254   , _cond(cond)
 255   , _label(stub->entry())
 256   , _block(NULL)
 257   , _ublock(NULL)
 258   , _stub(stub) {
 259 }
 260 
 261 LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, BlockBegin* block, BlockBegin* ublock)
 262   : LIR_Op(lir_cond_float_branch, LIR_OprFact::illegalOpr, (CodeEmitInfo*)NULL)
 263   , _cond(cond)
 264   , _label(block->label())
 265   , _block(block)
 266   , _ublock(ublock)
 267   , _stub(NULL)
 268 {
 269 }
 270 
 271 void LIR_OpBranch::change_block(BlockBegin* b) {
 272   assert(_block != NULL, "must have old block");
 273   assert(_block->label() == label(), "must be equal");
 274 
 275   _block = b;
 276   _label = b->label();
 277 }
 278 
 279 void LIR_OpBranch::change_ublock(BlockBegin* b) {
 280   assert(_ublock != NULL, "must have old block");
 281   _ublock = b;
 282 }
 283 
 284 void LIR_OpBranch::negate_cond() {
 285   switch (_cond) {
 286     case lir_cond_equal:        _cond = lir_cond_notEqual;     break;
 287     case lir_cond_notEqual:     _cond = lir_cond_equal;        break;
 288     case lir_cond_less:         _cond = lir_cond_greaterEqual; break;
 289     case lir_cond_lessEqual:    _cond = lir_cond_greater;      break;
 290     case lir_cond_greaterEqual: _cond = lir_cond_less;         break;
 291     case lir_cond_greater:      _cond = lir_cond_lessEqual;    break;
 292     default: ShouldNotReachHere();
 293   }
 294 }
 295 
 296 
 297 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
 298                                  LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
 299                                  bool fast_check, CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch,
 300                                  CodeStub* stub, bool need_null_check)
 301 
 302   : LIR_Op(code, result, NULL)
 303   , _object(object)
 304   , _array(LIR_OprFact::illegalOpr)
 305   , _klass(klass)
 306   , _tmp1(tmp1)
 307   , _tmp2(tmp2)
 308   , _tmp3(tmp3)
 309   , _fast_check(fast_check)
 310   , _info_for_patch(info_for_patch)
 311   , _info_for_exception(info_for_exception)
 312   , _stub(stub)
 313   , _profiled_method(NULL)
 314   , _profiled_bci(-1)
 315   , _should_profile(false)
 316   , _need_null_check(need_null_check)
 317 {
 318   if (code == lir_checkcast) {
 319     assert(info_for_exception != NULL, "checkcast throws exceptions");
 320   } else if (code == lir_instanceof) {
 321     assert(info_for_exception == NULL, "instanceof throws no exceptions");
 322   } else {
 323     ShouldNotReachHere();
 324   }
 325 }
 326 
 327 
 328 
 329 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception)
 330   : LIR_Op(code, LIR_OprFact::illegalOpr, NULL)
 331   , _object(object)
 332   , _array(array)
 333   , _klass(NULL)
 334   , _tmp1(tmp1)
 335   , _tmp2(tmp2)
 336   , _tmp3(tmp3)
 337   , _fast_check(false)
 338   , _info_for_patch(NULL)
 339   , _info_for_exception(info_for_exception)
 340   , _stub(NULL)
 341   , _profiled_method(NULL)
 342   , _profiled_bci(-1)
 343   , _should_profile(false)
 344   , _need_null_check(true)
 345 {
 346   if (code == lir_store_check) {
 347     _stub = new ArrayStoreExceptionStub(object, info_for_exception);
 348     assert(info_for_exception != NULL, "store_check throws exceptions");
 349   } else {
 350     ShouldNotReachHere();
 351   }
 352 }
 353 
 354 LIR_OpFlattenedArrayCheck::LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub)
 355   : LIR_Op(lir_flattened_array_check, LIR_OprFact::illegalOpr, NULL)
 356   , _array(array)
 357   , _value(value)
 358   , _tmp(tmp)
 359   , _stub(stub) {}
 360 
 361 
 362 LIR_OpNullFreeArrayCheck::LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp)
 363   : LIR_Op(lir_null_free_array_check, LIR_OprFact::illegalOpr, NULL)
 364   , _array(array)
 365   , _tmp(tmp) {}
 366 
 367 
 368 LIR_OpSubstitutabilityCheck::LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
 369                                                          LIR_Opr tmp1, LIR_Opr tmp2,
 370                                                          ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
 371                                                          CodeEmitInfo* info, CodeStub* stub)
 372   : LIR_Op(lir_substitutability_check, result, info)
 373   , _left(left)
 374   , _right(right)
 375   , _equal_result(equal_result)
 376   , _not_equal_result(not_equal_result)
 377   , _tmp1(tmp1)
 378   , _tmp2(tmp2)
 379   , _left_klass(left_klass)
 380   , _right_klass(right_klass)
 381   , _left_klass_op(left_klass_op)
 382   , _right_klass_op(right_klass_op)
 383   , _stub(stub) {}
 384 
 385 
 386 LIR_OpArrayCopy::LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length,
 387                                  LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info)
 388   : LIR_Op(lir_arraycopy, LIR_OprFact::illegalOpr, info)
 389   , _src(src)
 390   , _src_pos(src_pos)
 391   , _dst(dst)
 392   , _dst_pos(dst_pos)
 393   , _length(length)
 394   , _tmp(tmp)
 395   , _expected_type(expected_type)
 396   , _flags(flags) {
 397   _stub = new ArrayCopyStub(this);
 398 }
 399 
 400 LIR_OpUpdateCRC32::LIR_OpUpdateCRC32(LIR_Opr crc, LIR_Opr val, LIR_Opr res)
 401   : LIR_Op(lir_updatecrc32, res, NULL)
 402   , _crc(crc)
 403   , _val(val) {
 404 }
 405 
 406 //-------------------verify--------------------------
 407 
 408 void LIR_Op1::verify() const {
 409   switch(code()) {
 410   case lir_move:
 411     assert(in_opr()->is_valid() && result_opr()->is_valid(), "must be");
 412     break;
 413   case lir_null_check:
 414     assert(in_opr()->is_register(), "must be");
 415     break;
 416   case lir_return:
 417     assert(in_opr()->is_register() || in_opr()->is_illegal(), "must be");
 418     break;
 419   default:
 420     break;
 421   }
 422 }
 423 
 424 void LIR_OpRTCall::verify() const {
 425   assert(strcmp(Runtime1::name_for_address(addr()), "<unknown function>") != 0, "unknown function");
 426 }
 427 
 428 //-------------------visits--------------------------
 429 
 430 // complete rework of LIR instruction visitor.
 431 // The virtual call for each instruction type is replaced by a big
 432 // switch that adds the operands for each instruction
 433 
 434 void LIR_OpVisitState::visit(LIR_Op* op) {
 435   // copy information from the LIR_Op
 436   reset();
 437   set_op(op);
 438 
 439   switch (op->code()) {
 440 
 441 // LIR_Op0
 442     case lir_fpop_raw:                 // result and info always invalid
 443     case lir_breakpoint:               // result and info always invalid
 444     case lir_membar:                   // result and info always invalid
 445     case lir_membar_acquire:           // result and info always invalid
 446     case lir_membar_release:           // result and info always invalid
 447     case lir_membar_loadload:          // result and info always invalid
 448     case lir_membar_storestore:        // result and info always invalid
 449     case lir_membar_loadstore:         // result and info always invalid
 450     case lir_membar_storeload:         // result and info always invalid
 451     case lir_check_orig_pc:            // result and info always invalid
 452     case lir_on_spin_wait:
 453     {
 454       assert(op->as_Op0() != NULL, "must be");
 455       assert(op->_info == NULL, "info not used by this instruction");
 456       assert(op->_result->is_illegal(), "not used");
 457       break;
 458     }
 459 
 460     case lir_nop:                      // may have info, result always invalid
 461     case lir_std_entry:                // may have result, info always invalid
 462     case lir_osr_entry:                // may have result, info always invalid
 463     case lir_get_thread:               // may have result, info always invalid
 464     {
 465       assert(op->as_Op0() != NULL, "must be");
 466       if (op->_info != NULL)           do_info(op->_info);
 467       if (op->_result->is_valid())     do_output(op->_result);
 468       break;
 469     }
 470 
 471 
 472 // LIR_OpLabel
 473     case lir_label:                    // result and info always invalid
 474     {
 475       assert(op->as_OpLabel() != NULL, "must be");
 476       assert(op->_info == NULL, "info not used by this instruction");
 477       assert(op->_result->is_illegal(), "not used");
 478       break;
 479     }
 480 
 481 
 482 // LIR_Op1
 483     case lir_fxch:           // input always valid, result and info always invalid
 484     case lir_fld:            // input always valid, result and info always invalid
 485     case lir_push:           // input always valid, result and info always invalid
 486     case lir_pop:            // input always valid, result and info always invalid
 487     case lir_leal:           // input and result always valid, info always invalid
 488     case lir_monaddr:        // input and result always valid, info always invalid
 489     case lir_null_check:     // input and info always valid, result always invalid
 490     case lir_move:           // input and result always valid, may have info
 491     {
 492       assert(op->as_Op1() != NULL, "must be");
 493       LIR_Op1* op1 = (LIR_Op1*)op;
 494 
 495       if (op1->_info)                  do_info(op1->_info);
 496       if (op1->_opr->is_valid())       do_input(op1->_opr);
 497       if (op1->_result->is_valid())    do_output(op1->_result);
 498 
 499       break;
 500     }
 501 
 502     case lir_return:
 503     {
 504       assert(op->as_OpReturn() != NULL, "must be");
 505       LIR_OpReturn* op_ret = (LIR_OpReturn*)op;
 506 
 507       if (op_ret->_info)               do_info(op_ret->_info);
 508       if (op_ret->_opr->is_valid())    do_input(op_ret->_opr);
 509       if (op_ret->_result->is_valid()) do_output(op_ret->_result);
 510       if (op_ret->stub() != NULL)      do_stub(op_ret->stub());
 511 
 512       break;
 513     }
 514 
 515     case lir_safepoint:
 516     {
 517       assert(op->as_Op1() != NULL, "must be");
 518       LIR_Op1* op1 = (LIR_Op1*)op;
 519 
 520       assert(op1->_info != NULL, "");  do_info(op1->_info);
 521       if (op1->_opr->is_valid())       do_temp(op1->_opr); // safepoints on SPARC need temporary register
 522       assert(op1->_result->is_illegal(), "safepoint does not produce value");
 523 
 524       break;
 525     }
 526 
 527 // LIR_OpConvert;
 528     case lir_convert:        // input and result always valid, info always invalid
 529     {
 530       assert(op->as_OpConvert() != NULL, "must be");
 531       LIR_OpConvert* opConvert = (LIR_OpConvert*)op;
 532 
 533       assert(opConvert->_info == NULL, "must be");
 534       if (opConvert->_opr->is_valid())       do_input(opConvert->_opr);
 535       if (opConvert->_result->is_valid())    do_output(opConvert->_result);
 536 #ifdef PPC32
 537       if (opConvert->_tmp1->is_valid())      do_temp(opConvert->_tmp1);
 538       if (opConvert->_tmp2->is_valid())      do_temp(opConvert->_tmp2);
 539 #endif
 540       do_stub(opConvert->_stub);
 541 
 542       break;
 543     }
 544 
 545 // LIR_OpBranch;
 546     case lir_branch:                   // may have info, input and result register always invalid
 547     case lir_cond_float_branch:        // may have info, input and result register always invalid
 548     {
 549       assert(op->as_OpBranch() != NULL, "must be");
 550       LIR_OpBranch* opBranch = (LIR_OpBranch*)op;
 551 
 552       if (opBranch->_info != NULL)     do_info(opBranch->_info);
 553       assert(opBranch->_result->is_illegal(), "not used");
 554       if (opBranch->_stub != NULL)     opBranch->stub()->visit(this);
 555 
 556       break;
 557     }
 558 
 559 
 560 // LIR_OpAllocObj
 561     case lir_alloc_object:
 562     {
 563       assert(op->as_OpAllocObj() != NULL, "must be");
 564       LIR_OpAllocObj* opAllocObj = (LIR_OpAllocObj*)op;
 565 
 566       if (opAllocObj->_info)                     do_info(opAllocObj->_info);
 567       if (opAllocObj->_opr->is_valid()) {        do_input(opAllocObj->_opr);
 568                                                  do_temp(opAllocObj->_opr);
 569                                         }
 570       if (opAllocObj->_tmp1->is_valid())         do_temp(opAllocObj->_tmp1);
 571       if (opAllocObj->_tmp2->is_valid())         do_temp(opAllocObj->_tmp2);
 572       if (opAllocObj->_tmp3->is_valid())         do_temp(opAllocObj->_tmp3);
 573       if (opAllocObj->_tmp4->is_valid())         do_temp(opAllocObj->_tmp4);
 574       if (opAllocObj->_result->is_valid())       do_output(opAllocObj->_result);
 575                                                  do_stub(opAllocObj->_stub);
 576       break;
 577     }
 578 
 579 
 580 // LIR_OpRoundFP;
 581     case lir_roundfp: {
 582       assert(op->as_OpRoundFP() != NULL, "must be");
 583       LIR_OpRoundFP* opRoundFP = (LIR_OpRoundFP*)op;
 584 
 585       assert(op->_info == NULL, "info not used by this instruction");
 586       assert(opRoundFP->_tmp->is_illegal(), "not used");
 587       do_input(opRoundFP->_opr);
 588       do_output(opRoundFP->_result);
 589 
 590       break;
 591     }
 592 
 593 
 594 // LIR_Op2
 595     case lir_cmp:
 596     case lir_cmp_l2i:
 597     case lir_ucmp_fd2i:
 598     case lir_cmp_fd2i:
 599     case lir_add:
 600     case lir_sub:
 601     case lir_rem:
 602     case lir_sqrt:
 603     case lir_abs:
 604     case lir_neg:
 605     case lir_logic_and:
 606     case lir_logic_or:
 607     case lir_logic_xor:
 608     case lir_shl:
 609     case lir_shr:
 610     case lir_ushr:
 611     case lir_xadd:
 612     case lir_xchg:
 613     case lir_assert:
 614     {
 615       assert(op->as_Op2() != NULL, "must be");
 616       LIR_Op2* op2 = (LIR_Op2*)op;
 617       assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() &&
 618              op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");
 619 
 620       if (op2->_info)                     do_info(op2->_info);
 621       if (op2->_opr1->is_valid())         do_input(op2->_opr1);
 622       if (op2->_opr2->is_valid())         do_input(op2->_opr2);
 623       if (op2->_tmp1->is_valid())         do_temp(op2->_tmp1);
 624       if (op2->_result->is_valid())       do_output(op2->_result);
 625       if (op->code() == lir_xchg || op->code() == lir_xadd) {
 626         // on ARM and PPC, return value is loaded first so could
 627         // destroy inputs. On other platforms that implement those
 628         // (x86, sparc), the extra constrainsts are harmless.
 629         if (op2->_opr1->is_valid())       do_temp(op2->_opr1);
 630         if (op2->_opr2->is_valid())       do_temp(op2->_opr2);
 631       }
 632 
 633       break;
 634     }
 635 
 636     // special handling for cmove: right input operand must not be equal
 637     // to the result operand, otherwise the backend fails
 638     case lir_cmove:
 639     {
 640       assert(op->as_Op2() != NULL, "must be");
 641       LIR_Op2* op2 = (LIR_Op2*)op;
 642 
 643       assert(op2->_info == NULL && op2->_tmp1->is_illegal() && op2->_tmp2->is_illegal() &&
 644              op2->_tmp3->is_illegal() && op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");
 645       assert(op2->_opr1->is_valid() && op2->_opr2->is_valid() && op2->_result->is_valid(), "used");
 646 
 647       do_input(op2->_opr1);
 648       do_input(op2->_opr2);
 649       do_temp(op2->_opr2);
 650       do_output(op2->_result);
 651 
 652       break;
 653     }
 654 
 655     // vspecial handling for strict operations: register input operands
 656     // as temp to guarantee that they do not overlap with other
 657     // registers
 658     case lir_mul:
 659     case lir_div:
 660     {
 661       assert(op->as_Op2() != NULL, "must be");
 662       LIR_Op2* op2 = (LIR_Op2*)op;
 663 
 664       assert(op2->_info == NULL, "not used");
 665       assert(op2->_opr1->is_valid(), "used");
 666       assert(op2->_opr2->is_valid(), "used");
 667       assert(op2->_result->is_valid(), "used");
 668       assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() &&
 669              op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");
 670 
 671       do_input(op2->_opr1); do_temp(op2->_opr1);
 672       do_input(op2->_opr2); do_temp(op2->_opr2);
 673       if (op2->_tmp1->is_valid()) do_temp(op2->_tmp1);
 674       do_output(op2->_result);
 675 
 676       break;
 677     }
 678 
 679     case lir_throw: {
 680       assert(op->as_Op2() != NULL, "must be");
 681       LIR_Op2* op2 = (LIR_Op2*)op;
 682 
 683       if (op2->_info)                     do_info(op2->_info);
 684       if (op2->_opr1->is_valid())         do_temp(op2->_opr1);
 685       if (op2->_opr2->is_valid())         do_input(op2->_opr2); // exception object is input parameter
 686       assert(op2->_result->is_illegal(), "no result");
 687       assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() &&
 688              op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used");
 689 
 690       break;
 691     }
 692 
 693     case lir_unwind: {
 694       assert(op->as_Op1() != NULL, "must be");
 695       LIR_Op1* op1 = (LIR_Op1*)op;
 696 
 697       assert(op1->_info == NULL, "no info");
 698       assert(op1->_opr->is_valid(), "exception oop");         do_input(op1->_opr);
 699       assert(op1->_result->is_illegal(), "no result");
 700 
 701       break;
 702     }
 703 
 704 // LIR_Op3
 705     case lir_idiv:
 706     case lir_irem: {
 707       assert(op->as_Op3() != NULL, "must be");
 708       LIR_Op3* op3= (LIR_Op3*)op;
 709 
 710       if (op3->_info)                     do_info(op3->_info);
 711       if (op3->_opr1->is_valid())         do_input(op3->_opr1);
 712 
 713       // second operand is input and temp, so ensure that second operand
 714       // and third operand get not the same register
 715       if (op3->_opr2->is_valid())         do_input(op3->_opr2);
 716       if (op3->_opr2->is_valid())         do_temp(op3->_opr2);
 717       if (op3->_opr3->is_valid())         do_temp(op3->_opr3);
 718 
 719       if (op3->_result->is_valid())       do_output(op3->_result);
 720 
 721       break;
 722     }
 723 
 724     case lir_fmad:
 725     case lir_fmaf: {
 726       assert(op->as_Op3() != NULL, "must be");
 727       LIR_Op3* op3= (LIR_Op3*)op;
 728       assert(op3->_info == NULL, "no info");
 729       do_input(op3->_opr1);
 730       do_input(op3->_opr2);
 731       do_input(op3->_opr3);
 732       do_output(op3->_result);
 733       break;
 734     }
 735 
 736 // LIR_OpJavaCall
 737     case lir_static_call:
 738     case lir_optvirtual_call:
 739     case lir_icvirtual_call:
 740     case lir_dynamic_call: {
 741       LIR_OpJavaCall* opJavaCall = op->as_OpJavaCall();
 742       assert(opJavaCall != NULL, "must be");
 743 
 744       if (opJavaCall->_receiver->is_valid())     do_input(opJavaCall->_receiver);
 745 
 746       // only visit register parameters
 747       int n = opJavaCall->_arguments->length();
 748       for (int i = opJavaCall->_receiver->is_valid() ? 1 : 0; i < n; i++) {
 749         if (!opJavaCall->_arguments->at(i)->is_pointer()) {
 750           do_input(*opJavaCall->_arguments->adr_at(i));
 751         }
 752       }
 753 
 754       if (opJavaCall->_info)                     do_info(opJavaCall->_info);
 755       if (FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr &&
 756           opJavaCall->is_method_handle_invoke()) {
 757         opJavaCall->_method_handle_invoke_SP_save_opr = FrameMap::method_handle_invoke_SP_save_opr();
 758         do_temp(opJavaCall->_method_handle_invoke_SP_save_opr);
 759       }
 760       do_call();
 761       if (opJavaCall->_result->is_valid())       do_output(opJavaCall->_result);
 762 
 763       break;
 764     }
 765 
 766 
 767 // LIR_OpRTCall
 768     case lir_rtcall: {
 769       assert(op->as_OpRTCall() != NULL, "must be");
 770       LIR_OpRTCall* opRTCall = (LIR_OpRTCall*)op;
 771 
 772       // only visit register parameters
 773       int n = opRTCall->_arguments->length();
 774       for (int i = 0; i < n; i++) {
 775         if (!opRTCall->_arguments->at(i)->is_pointer()) {
 776           do_input(*opRTCall->_arguments->adr_at(i));
 777         }
 778       }
 779       if (opRTCall->_info)                     do_info(opRTCall->_info);
 780       if (opRTCall->_tmp->is_valid())          do_temp(opRTCall->_tmp);
 781       do_call();
 782       if (opRTCall->_result->is_valid())       do_output(opRTCall->_result);
 783 
 784       break;
 785     }
 786 
 787 
 788 // LIR_OpArrayCopy
 789     case lir_arraycopy: {
 790       assert(op->as_OpArrayCopy() != NULL, "must be");
 791       LIR_OpArrayCopy* opArrayCopy = (LIR_OpArrayCopy*)op;
 792 
 793       assert(opArrayCopy->_result->is_illegal(), "unused");
 794       assert(opArrayCopy->_src->is_valid(), "used");          do_input(opArrayCopy->_src);     do_temp(opArrayCopy->_src);
 795       assert(opArrayCopy->_src_pos->is_valid(), "used");      do_input(opArrayCopy->_src_pos); do_temp(opArrayCopy->_src_pos);
 796       assert(opArrayCopy->_dst->is_valid(), "used");          do_input(opArrayCopy->_dst);     do_temp(opArrayCopy->_dst);
 797       assert(opArrayCopy->_dst_pos->is_valid(), "used");      do_input(opArrayCopy->_dst_pos); do_temp(opArrayCopy->_dst_pos);
 798       assert(opArrayCopy->_length->is_valid(), "used");       do_input(opArrayCopy->_length);  do_temp(opArrayCopy->_length);
 799       assert(opArrayCopy->_tmp->is_valid(), "used");          do_temp(opArrayCopy->_tmp);
 800       if (opArrayCopy->_info)                     do_info(opArrayCopy->_info);
 801 
 802       // the implementation of arraycopy always has a call into the runtime
 803       do_call();
 804 
 805       break;
 806     }
 807 
 808 
 809 // LIR_OpUpdateCRC32
 810     case lir_updatecrc32: {
 811       assert(op->as_OpUpdateCRC32() != NULL, "must be");
 812       LIR_OpUpdateCRC32* opUp = (LIR_OpUpdateCRC32*)op;
 813 
 814       assert(opUp->_crc->is_valid(), "used");          do_input(opUp->_crc);     do_temp(opUp->_crc);
 815       assert(opUp->_val->is_valid(), "used");          do_input(opUp->_val);     do_temp(opUp->_val);
 816       assert(opUp->_result->is_valid(), "used");       do_output(opUp->_result);
 817       assert(opUp->_info == NULL, "no info for LIR_OpUpdateCRC32");
 818 
 819       break;
 820     }
 821 
 822 
 823 // LIR_OpLock
 824     case lir_lock:
 825     case lir_unlock: {
 826       assert(op->as_OpLock() != NULL, "must be");
 827       LIR_OpLock* opLock = (LIR_OpLock*)op;
 828 
 829       if (opLock->_info)                          do_info(opLock->_info);
 830 
 831       // TODO: check if these operands really have to be temp
 832       // (or if input is sufficient). This may have influence on the oop map!
 833       assert(opLock->_lock->is_valid(), "used");  do_temp(opLock->_lock);
 834       assert(opLock->_hdr->is_valid(),  "used");  do_temp(opLock->_hdr);
 835       assert(opLock->_obj->is_valid(),  "used");  do_temp(opLock->_obj);
 836 
 837       if (opLock->_scratch->is_valid())           do_temp(opLock->_scratch);
 838       assert(opLock->_result->is_illegal(), "unused");
 839 
 840       do_stub(opLock->_stub);
 841       do_stub(opLock->_throw_imse_stub);
 842 
 843       break;
 844     }
 845 
 846 
 847 // LIR_OpDelay
 848     case lir_delay_slot: {
 849       assert(op->as_OpDelay() != NULL, "must be");
 850       LIR_OpDelay* opDelay = (LIR_OpDelay*)op;
 851 
 852       visit(opDelay->delay_op());
 853       break;
 854     }
 855 
 856 // LIR_OpTypeCheck
 857     case lir_instanceof:
 858     case lir_checkcast:
 859     case lir_store_check: {
 860       assert(op->as_OpTypeCheck() != NULL, "must be");
 861       LIR_OpTypeCheck* opTypeCheck = (LIR_OpTypeCheck*)op;
 862 
 863       if (opTypeCheck->_info_for_exception)       do_info(opTypeCheck->_info_for_exception);
 864       if (opTypeCheck->_info_for_patch)           do_info(opTypeCheck->_info_for_patch);
 865       if (opTypeCheck->_object->is_valid())       do_input(opTypeCheck->_object);
 866       if (op->code() == lir_store_check && opTypeCheck->_object->is_valid()) {
 867         do_temp(opTypeCheck->_object);
 868       }
 869       if (opTypeCheck->_array->is_valid())        do_input(opTypeCheck->_array);
 870       if (opTypeCheck->_tmp1->is_valid())         do_temp(opTypeCheck->_tmp1);
 871       if (opTypeCheck->_tmp2->is_valid())         do_temp(opTypeCheck->_tmp2);
 872       if (opTypeCheck->_tmp3->is_valid())         do_temp(opTypeCheck->_tmp3);
 873       if (opTypeCheck->_result->is_valid())       do_output(opTypeCheck->_result);
 874                                                   do_stub(opTypeCheck->_stub);
 875       break;
 876     }
 877 
 878 // LIR_OpFlattenedArrayCheck
 879     case lir_flattened_array_check: {
 880       assert(op->as_OpFlattenedArrayCheck() != NULL, "must be");
 881       LIR_OpFlattenedArrayCheck* opFlattenedArrayCheck = (LIR_OpFlattenedArrayCheck*)op;
 882 
 883       if (opFlattenedArrayCheck->_array->is_valid()) do_input(opFlattenedArrayCheck->_array);
 884       if (opFlattenedArrayCheck->_value->is_valid()) do_input(opFlattenedArrayCheck->_value);
 885       if (opFlattenedArrayCheck->_tmp->is_valid())   do_temp(opFlattenedArrayCheck->_tmp);
 886                                                      do_stub(opFlattenedArrayCheck->_stub);
 887 
 888       break;
 889     }
 890 
 891 // LIR_OpNullFreeArrayCheck
 892     case lir_null_free_array_check: {
 893       assert(op->as_OpNullFreeArrayCheck() != NULL, "must be");
 894       LIR_OpNullFreeArrayCheck* opNullFreeArrayCheck = (LIR_OpNullFreeArrayCheck*)op;
 895 
 896       if (opNullFreeArrayCheck->_array->is_valid()) do_input(opNullFreeArrayCheck->_array);
 897       if (opNullFreeArrayCheck->_tmp->is_valid())   do_temp(opNullFreeArrayCheck->_tmp);
 898       break;
 899     }
 900 
 901 // LIR_OpSubstitutabilityCheck
 902     case lir_substitutability_check: {
 903       assert(op->as_OpSubstitutabilityCheck() != NULL, "must be");
 904       LIR_OpSubstitutabilityCheck* opSubstitutabilityCheck = (LIR_OpSubstitutabilityCheck*)op;
 905                                                                 do_input(opSubstitutabilityCheck->_left);
 906                                                                 do_temp (opSubstitutabilityCheck->_left);
 907                                                                 do_input(opSubstitutabilityCheck->_right);
 908                                                                 do_temp (opSubstitutabilityCheck->_right);
 909                                                                 do_input(opSubstitutabilityCheck->_equal_result);
 910                                                                 do_temp (opSubstitutabilityCheck->_equal_result);
 911                                                                 do_input(opSubstitutabilityCheck->_not_equal_result);
 912                                                                 do_temp (opSubstitutabilityCheck->_not_equal_result);
 913       if (opSubstitutabilityCheck->_tmp1->is_valid())           do_temp(opSubstitutabilityCheck->_tmp1);
 914       if (opSubstitutabilityCheck->_tmp2->is_valid())           do_temp(opSubstitutabilityCheck->_tmp2);
 915       if (opSubstitutabilityCheck->_left_klass_op->is_valid())  do_temp(opSubstitutabilityCheck->_left_klass_op);
 916       if (opSubstitutabilityCheck->_right_klass_op->is_valid()) do_temp(opSubstitutabilityCheck->_right_klass_op);
 917       if (opSubstitutabilityCheck->_result->is_valid())         do_output(opSubstitutabilityCheck->_result);
 918                                                                 do_info(opSubstitutabilityCheck->_info);
 919                                                                 do_stub(opSubstitutabilityCheck->_stub);
 920       break;
 921     }
 922 
 923 // LIR_OpCompareAndSwap
 924     case lir_cas_long:
 925     case lir_cas_obj:
 926     case lir_cas_int: {
 927       assert(op->as_OpCompareAndSwap() != NULL, "must be");
 928       LIR_OpCompareAndSwap* opCompareAndSwap = (LIR_OpCompareAndSwap*)op;
 929 
 930       assert(opCompareAndSwap->_addr->is_valid(),      "used");
 931       assert(opCompareAndSwap->_cmp_value->is_valid(), "used");
 932       assert(opCompareAndSwap->_new_value->is_valid(), "used");
 933       if (opCompareAndSwap->_info)                    do_info(opCompareAndSwap->_info);
 934                                                       do_input(opCompareAndSwap->_addr);
 935                                                       do_temp(opCompareAndSwap->_addr);
 936                                                       do_input(opCompareAndSwap->_cmp_value);
 937                                                       do_temp(opCompareAndSwap->_cmp_value);
 938                                                       do_input(opCompareAndSwap->_new_value);
 939                                                       do_temp(opCompareAndSwap->_new_value);
 940       if (opCompareAndSwap->_tmp1->is_valid())        do_temp(opCompareAndSwap->_tmp1);
 941       if (opCompareAndSwap->_tmp2->is_valid())        do_temp(opCompareAndSwap->_tmp2);
 942       if (opCompareAndSwap->_result->is_valid())      do_output(opCompareAndSwap->_result);
 943 
 944       break;
 945     }
 946 
 947 
 948 // LIR_OpAllocArray;
 949     case lir_alloc_array: {
 950       assert(op->as_OpAllocArray() != NULL, "must be");
 951       LIR_OpAllocArray* opAllocArray = (LIR_OpAllocArray*)op;
 952 
 953       if (opAllocArray->_info)                        do_info(opAllocArray->_info);
 954       if (opAllocArray->_klass->is_valid())           do_input(opAllocArray->_klass); do_temp(opAllocArray->_klass);
 955       if (opAllocArray->_len->is_valid())             do_input(opAllocArray->_len);   do_temp(opAllocArray->_len);
 956       if (opAllocArray->_tmp1->is_valid())            do_temp(opAllocArray->_tmp1);
 957       if (opAllocArray->_tmp2->is_valid())            do_temp(opAllocArray->_tmp2);
 958       if (opAllocArray->_tmp3->is_valid())            do_temp(opAllocArray->_tmp3);
 959       if (opAllocArray->_tmp4->is_valid())            do_temp(opAllocArray->_tmp4);
 960       if (opAllocArray->_result->is_valid())          do_output(opAllocArray->_result);
 961                                                       do_stub(opAllocArray->_stub);
 962       break;
 963     }
 964 
 965 // LIR_OpProfileCall:
 966     case lir_profile_call: {
 967       assert(op->as_OpProfileCall() != NULL, "must be");
 968       LIR_OpProfileCall* opProfileCall = (LIR_OpProfileCall*)op;
 969 
 970       if (opProfileCall->_recv->is_valid())              do_temp(opProfileCall->_recv);
 971       assert(opProfileCall->_mdo->is_valid(), "used");   do_temp(opProfileCall->_mdo);
 972       assert(opProfileCall->_tmp1->is_valid(), "used");  do_temp(opProfileCall->_tmp1);
 973       break;
 974     }
 975 
 976 // LIR_OpProfileType:
 977     case lir_profile_type: {
 978       assert(op->as_OpProfileType() != NULL, "must be");
 979       LIR_OpProfileType* opProfileType = (LIR_OpProfileType*)op;
 980 
 981       do_input(opProfileType->_mdp); do_temp(opProfileType->_mdp);
 982       do_input(opProfileType->_obj);
 983       do_temp(opProfileType->_tmp);
 984       break;
 985     }
 986 
 987     // LIR_OpProfileInlineType:
 988     case lir_profile_inline_type: {
 989       assert(op->as_OpProfileInlineType() != NULL, "must be");
 990       LIR_OpProfileInlineType* opProfileInlineType = (LIR_OpProfileInlineType*)op;
 991 
 992       do_input(opProfileInlineType->_mdp); do_temp(opProfileInlineType->_mdp);
 993       do_input(opProfileInlineType->_obj);
 994       do_temp(opProfileInlineType->_tmp);
 995       break;
 996     }
 997 default:
 998     op->visit(this);
 999   }
1000 }
1001 
1002 void LIR_Op::visit(LIR_OpVisitState* state) {
1003   ShouldNotReachHere();
1004 }
1005 
1006 void LIR_OpVisitState::do_stub(CodeStub* stub) {
1007   if (stub != NULL) {
1008     stub->visit(this);
1009   }
1010 }
1011 
1012 XHandlers* LIR_OpVisitState::all_xhandler() {
1013   XHandlers* result = NULL;
1014 
1015   int i;
1016   for (i = 0; i < info_count(); i++) {
1017     if (info_at(i)->exception_handlers() != NULL) {
1018       result = info_at(i)->exception_handlers();
1019       break;
1020     }
1021   }
1022 
1023 #ifdef ASSERT
1024   for (i = 0; i < info_count(); i++) {
1025     assert(info_at(i)->exception_handlers() == NULL ||
1026            info_at(i)->exception_handlers() == result,
1027            "only one xhandler list allowed per LIR-operation");
1028   }
1029 #endif
1030 
1031   if (result != NULL) {
1032     return result;
1033   } else {
1034     return new XHandlers();
1035   }
1036 
1037   return result;
1038 }
1039 
1040 
1041 #ifdef ASSERT
1042 bool LIR_OpVisitState::no_operands(LIR_Op* op) {
1043   visit(op);
1044 
1045   return opr_count(inputMode) == 0 &&
1046          opr_count(outputMode) == 0 &&
1047          opr_count(tempMode) == 0 &&
1048          info_count() == 0 &&
1049          !has_call() &&
1050          !has_slow_case();
1051 }
1052 #endif
1053 
1054 // LIR_OpReturn
1055 LIR_OpReturn::LIR_OpReturn(LIR_Opr opr) :
1056     LIR_Op1(lir_return, opr, (CodeEmitInfo*)NULL /* info */),
1057     _stub(NULL) {
1058   if (VM_Version::supports_stack_watermark_barrier()) {
1059     _stub = new C1SafepointPollStub();
1060   }
1061 }
1062 
1063 //---------------------------------------------------
1064 
1065 
1066 void LIR_OpJavaCall::emit_code(LIR_Assembler* masm) {
1067   masm->emit_call(this);
1068 }
1069 
1070 bool LIR_OpJavaCall::maybe_return_as_fields(ciInlineKlass** vk_ret) const {
1071   if (InlineTypeReturnedAsFields &&
1072       (method()->signature()->returns_null_free_inline_type() ||
1073        method()->is_method_handle_intrinsic())) {
1074     ciType* return_type = method()->return_type();
1075     if (return_type->is_inlinetype()) {
1076       ciInlineKlass* vk = return_type->as_inline_klass();
1077       if (vk->can_be_returned_as_fields()) {
1078         if (vk_ret != NULL) {
1079           *vk_ret = vk;
1080         }
1081         return true;
1082       }
1083     } else if (return_type->is_instance_klass()) {
1084       // An inline type might be returned from the call but we don't know its
1085       // type. Either we get a buffered inline type (and nothing needs to be done)
1086       // or one of the inlines being returned is the klass of the inline type
1087       // (RAX on x64, with LSB set to 1) and we need to allocate an inline
1088       // type instance of that type and initialize it with other values being
1089       // returned (in other registers).
1090       assert(!return_type->as_instance_klass()->is_loaded() ||
1091              method()->is_method_handle_intrinsic(), "unexpected return type");
1092       return true;
1093     }
1094   }
1095   return false;
1096 }
1097 
1098 void LIR_OpRTCall::emit_code(LIR_Assembler* masm) {
1099   masm->emit_rtcall(this);
1100 }
1101 
1102 void LIR_OpLabel::emit_code(LIR_Assembler* masm) {
1103   masm->emit_opLabel(this);
1104 }
1105 
1106 void LIR_OpArrayCopy::emit_code(LIR_Assembler* masm) {
1107   masm->emit_arraycopy(this);
1108   masm->append_code_stub(stub());
1109 }
1110 
1111 void LIR_OpUpdateCRC32::emit_code(LIR_Assembler* masm) {
1112   masm->emit_updatecrc32(this);
1113 }
1114 
1115 void LIR_Op0::emit_code(LIR_Assembler* masm) {
1116   masm->emit_op0(this);
1117 }
1118 
1119 void LIR_Op1::emit_code(LIR_Assembler* masm) {
1120   masm->emit_op1(this);
1121 }
1122 
1123 void LIR_OpAllocObj::emit_code(LIR_Assembler* masm) {
1124   masm->emit_alloc_obj(this);
1125   masm->append_code_stub(stub());
1126 }
1127 
1128 void LIR_OpBranch::emit_code(LIR_Assembler* masm) {
1129   masm->emit_opBranch(this);
1130   if (stub()) {
1131     masm->append_code_stub(stub());
1132   }
1133 }
1134 
1135 void LIR_OpConvert::emit_code(LIR_Assembler* masm) {
1136   masm->emit_opConvert(this);
1137   if (stub() != NULL) {
1138     masm->append_code_stub(stub());
1139   }
1140 }
1141 
1142 void LIR_Op2::emit_code(LIR_Assembler* masm) {
1143   masm->emit_op2(this);
1144 }
1145 
1146 void LIR_OpAllocArray::emit_code(LIR_Assembler* masm) {
1147   masm->emit_alloc_array(this);
1148   masm->append_code_stub(stub());
1149 }
1150 
1151 void LIR_OpTypeCheck::emit_code(LIR_Assembler* masm) {
1152   masm->emit_opTypeCheck(this);
1153   if (stub()) {
1154     masm->append_code_stub(stub());
1155   }
1156 }
1157 
1158 void LIR_OpFlattenedArrayCheck::emit_code(LIR_Assembler* masm) {
1159   masm->emit_opFlattenedArrayCheck(this);
1160   if (stub() != NULL) {
1161     masm->append_code_stub(stub());
1162   }
1163 }
1164 
1165 void LIR_OpNullFreeArrayCheck::emit_code(LIR_Assembler* masm) {
1166   masm->emit_opNullFreeArrayCheck(this);
1167 }
1168 
1169 void LIR_OpSubstitutabilityCheck::emit_code(LIR_Assembler* masm) {
1170   masm->emit_opSubstitutabilityCheck(this);
1171   if (stub() != NULL) {
1172     masm->append_code_stub(stub());
1173   }
1174 }
1175 
1176 void LIR_OpCompareAndSwap::emit_code(LIR_Assembler* masm) {
1177   masm->emit_compare_and_swap(this);
1178 }
1179 
1180 void LIR_Op3::emit_code(LIR_Assembler* masm) {
1181   masm->emit_op3(this);
1182 }
1183 
1184 void LIR_OpLock::emit_code(LIR_Assembler* masm) {
1185   masm->emit_lock(this);
1186   if (stub()) {
1187     masm->append_code_stub(stub());
1188   }
1189   if (throw_imse_stub()) {
1190     masm->append_code_stub(throw_imse_stub());
1191   }
1192 }
1193 
1194 #ifdef ASSERT
1195 void LIR_OpAssert::emit_code(LIR_Assembler* masm) {
1196   masm->emit_assert(this);
1197 }
1198 #endif
1199 
1200 void LIR_OpDelay::emit_code(LIR_Assembler* masm) {
1201   masm->emit_delay(this);
1202 }
1203 
1204 void LIR_OpProfileCall::emit_code(LIR_Assembler* masm) {
1205   masm->emit_profile_call(this);
1206 }
1207 
1208 void LIR_OpProfileType::emit_code(LIR_Assembler* masm) {
1209   masm->emit_profile_type(this);
1210 }
1211 
1212 void LIR_OpProfileInlineType::emit_code(LIR_Assembler* masm) {
1213   masm->emit_profile_inline_type(this);
1214 }
1215 
1216 // LIR_List
1217 LIR_List::LIR_List(Compilation* compilation, BlockBegin* block)
1218   : _operations(8)
1219   , _compilation(compilation)
1220 #ifndef PRODUCT
1221   , _block(block)
1222 #endif
1223 #ifdef ASSERT
1224   , _file(NULL)
1225   , _line(0)
1226 #endif
1227 { }
1228 
1229 
1230 #ifdef ASSERT
1231 void LIR_List::set_file_and_line(const char * file, int line) {
1232   const char * f = strrchr(file, '/');
1233   if (f == NULL) f = strrchr(file, '\\');
1234   if (f == NULL) {
1235     f = file;
1236   } else {
1237     f++;
1238   }
1239   _file = f;
1240   _line = line;
1241 }
1242 #endif
1243 
1244 
1245 void LIR_List::append(LIR_InsertionBuffer* buffer) {
1246   assert(this == buffer->lir_list(), "wrong lir list");
1247   const int n = _operations.length();
1248 
1249   if (buffer->number_of_ops() > 0) {
1250     // increase size of instructions list
1251     _operations.at_grow(n + buffer->number_of_ops() - 1, NULL);
1252     // insert ops from buffer into instructions list
1253     int op_index = buffer->number_of_ops() - 1;
1254     int ip_index = buffer->number_of_insertion_points() - 1;
1255     int from_index = n - 1;
1256     int to_index = _operations.length() - 1;
1257     for (; ip_index >= 0; ip_index --) {
1258       int index = buffer->index_at(ip_index);
1259       // make room after insertion point
1260       while (index < from_index) {
1261         _operations.at_put(to_index --, _operations.at(from_index --));
1262       }
1263       // insert ops from buffer
1264       for (int i = buffer->count_at(ip_index); i > 0; i --) {
1265         _operations.at_put(to_index --, buffer->op_at(op_index --));
1266       }
1267     }
1268   }
1269 
1270   buffer->finish();
1271 }
1272 
1273 
1274 void LIR_List::oop2reg_patch(jobject o, LIR_Opr reg, CodeEmitInfo* info) {
1275   assert(reg->type() == T_OBJECT, "bad reg");
1276   append(new LIR_Op1(lir_move, LIR_OprFact::oopConst(o),  reg, T_OBJECT, lir_patch_normal, info));
1277 }
1278 
1279 void LIR_List::klass2reg_patch(Metadata* o, LIR_Opr reg, CodeEmitInfo* info) {
1280   assert(reg->type() == T_METADATA, "bad reg");
1281   append(new LIR_Op1(lir_move, LIR_OprFact::metadataConst(o), reg, T_METADATA, lir_patch_normal, info));
1282 }
1283 
1284 void LIR_List::load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info, LIR_PatchCode patch_code) {
1285   append(new LIR_Op1(
1286             lir_move,
1287             LIR_OprFact::address(addr),
1288             src,
1289             addr->type(),
1290             patch_code,
1291             info));
1292 }
1293 
1294 
1295 void LIR_List::volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code) {
1296   append(new LIR_Op1(
1297             lir_move,
1298             LIR_OprFact::address(address),
1299             dst,
1300             address->type(),
1301             patch_code,
1302             info, lir_move_volatile));
1303 }
1304 
1305 void LIR_List::volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) {
1306   append(new LIR_Op1(
1307             lir_move,
1308             LIR_OprFact::address(new LIR_Address(base, offset, type)),
1309             dst,
1310             type,
1311             patch_code,
1312             info, lir_move_volatile));
1313 }
1314 
1315 
1316 void LIR_List::store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) {
1317   append(new LIR_Op1(
1318             lir_move,
1319             LIR_OprFact::intConst(v),
1320             LIR_OprFact::address(new LIR_Address(base, offset_in_bytes, type)),
1321             type,
1322             patch_code,
1323             info));
1324 }
1325 
1326 
1327 void LIR_List::store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) {
1328   append(new LIR_Op1(
1329             lir_move,
1330             LIR_OprFact::oopConst(o),
1331             LIR_OprFact::address(new LIR_Address(base, offset_in_bytes, type)),
1332             type,
1333             patch_code,
1334             info));
1335 }
1336 
1337 
1338 void LIR_List::store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info, LIR_PatchCode patch_code) {
1339   append(new LIR_Op1(
1340             lir_move,
1341             src,
1342             LIR_OprFact::address(addr),
1343             addr->type(),
1344             patch_code,
1345             info));
1346 }
1347 
1348 
1349 void LIR_List::volatile_store_mem_reg(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info, LIR_PatchCode patch_code) {
1350   append(new LIR_Op1(
1351             lir_move,
1352             src,
1353             LIR_OprFact::address(addr),
1354             addr->type(),
1355             patch_code,
1356             info,
1357             lir_move_volatile));
1358 }
1359 
1360 void LIR_List::volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) {
1361   append(new LIR_Op1(
1362             lir_move,
1363             src,
1364             LIR_OprFact::address(new LIR_Address(base, offset, type)),
1365             type,
1366             patch_code,
1367             info, lir_move_volatile));
1368 }
1369 
1370 
1371 void LIR_List::idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) {
1372   append(new LIR_Op3(
1373                     lir_idiv,
1374                     left,
1375                     right,
1376                     tmp,
1377                     res,
1378                     info));
1379 }
1380 
1381 
1382 void LIR_List::idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) {
1383   append(new LIR_Op3(
1384                     lir_idiv,
1385                     left,
1386                     LIR_OprFact::intConst(right),
1387                     tmp,
1388                     res,
1389                     info));
1390 }
1391 
1392 
1393 void LIR_List::irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) {
1394   append(new LIR_Op3(
1395                     lir_irem,
1396                     left,
1397                     right,
1398                     tmp,
1399                     res,
1400                     info));
1401 }
1402 
1403 
1404 void LIR_List::irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) {
1405   append(new LIR_Op3(
1406                     lir_irem,
1407                     left,
1408                     LIR_OprFact::intConst(right),
1409                     tmp,
1410                     res,
1411                     info));
1412 }
1413 
1414 
1415 void LIR_List::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {
1416   append(new LIR_Op2(
1417                     lir_cmp,
1418                     condition,
1419                     LIR_OprFact::address(new LIR_Address(base, disp, T_INT)),
1420                     LIR_OprFact::intConst(c),
1421                     info));
1422 }
1423 
1424 
1425 void LIR_List::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Address* addr, CodeEmitInfo* info) {
1426   append(new LIR_Op2(
1427                     lir_cmp,
1428                     condition,
1429                     reg,
1430                     LIR_OprFact::address(addr),
1431                     info));
1432 }
1433 
1434 void LIR_List::allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4,
1435                                int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub) {
1436   append(new LIR_OpAllocObj(
1437                            klass,
1438                            dst,
1439                            t1,
1440                            t2,
1441                            t3,
1442                            t4,
1443                            header_size,
1444                            object_size,
1445                            init_check,
1446                            stub));
1447 }
1448 
1449 void LIR_List::allocate_array(LIR_Opr dst, LIR_Opr len, LIR_Opr t1,LIR_Opr t2, LIR_Opr t3,LIR_Opr t4, BasicType type, LIR_Opr klass, CodeStub* stub) {
1450   append(new LIR_OpAllocArray(
1451                            klass,
1452                            len,
1453                            dst,
1454                            t1,
1455                            t2,
1456                            t3,
1457                            t4,
1458                            type,
1459                            stub));
1460 }
1461 
1462 void LIR_List::shift_left(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1463  append(new LIR_Op2(
1464                     lir_shl,
1465                     value,
1466                     count,
1467                     dst,
1468                     tmp));
1469 }
1470 
1471 void LIR_List::shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1472  append(new LIR_Op2(
1473                     lir_shr,
1474                     value,
1475                     count,
1476                     dst,
1477                     tmp));
1478 }
1479 
1480 
1481 void LIR_List::unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1482  append(new LIR_Op2(
1483                     lir_ushr,
1484                     value,
1485                     count,
1486                     dst,
1487                     tmp));
1488 }
1489 
1490 void LIR_List::fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less) {
1491   append(new LIR_Op2(is_unordered_less ? lir_ucmp_fd2i : lir_cmp_fd2i,
1492                      left,
1493                      right,
1494                      dst));
1495 }
1496 
1497 void LIR_List::lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_imse_stub) {
1498   append(new LIR_OpLock(
1499                     lir_lock,
1500                     hdr,
1501                     obj,
1502                     lock,
1503                     scratch,
1504                     stub,
1505                     info,
1506                     throw_imse_stub));
1507 }
1508 
1509 void LIR_List::unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub) {
1510   append(new LIR_OpLock(
1511                     lir_unlock,
1512                     hdr,
1513                     obj,
1514                     lock,
1515                     scratch,
1516                     stub,
1517                     NULL));
1518 }
1519 
1520 
1521 void check_LIR() {
1522   // cannot do the proper checking as PRODUCT and other modes return different results
1523   // guarantee(sizeof(LIR_OprDesc) == wordSize, "may not have a v-table");
1524 }
1525 
1526 
1527 
1528 void LIR_List::checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
1529                           LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1530                           CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
1531                           ciMethod* profiled_method, int profiled_bci, bool is_null_free) {
1532   // If klass is non-nullable,  LIRGenerator::do_CheckCast has already performed null-check
1533   // on the object.
1534   bool need_null_check = !is_null_free;
1535   LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_checkcast, result, object, klass,
1536                                            tmp1, tmp2, tmp3, fast_check, info_for_exception, info_for_patch, stub,
1537                                            need_null_check);
1538   if (profiled_method != NULL) {
1539     c->set_profiled_method(profiled_method);
1540     c->set_profiled_bci(profiled_bci);
1541     c->set_should_profile(true);
1542   }
1543   append(c);
1544 }
1545 
1546 void LIR_List::instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci) {
1547   LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_instanceof, result, object, klass, tmp1, tmp2, tmp3, fast_check, NULL, info_for_patch, NULL);
1548   if (profiled_method != NULL) {
1549     c->set_profiled_method(profiled_method);
1550     c->set_profiled_bci(profiled_bci);
1551     c->set_should_profile(true);
1552   }
1553   append(c);
1554 }
1555 
1556 
1557 void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
1558                            CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci) {
1559   // FIXME -- if the types of the array and/or the object are known statically, we can avoid loading the klass
1560   LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception);
1561   if (profiled_method != NULL) {
1562     c->set_profiled_method(profiled_method);
1563     c->set_profiled_bci(profiled_bci);
1564     c->set_should_profile(true);
1565   }
1566   append(c);
1567 }
1568 
1569 void LIR_List::null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null) {
1570   if (deoptimize_on_null) {
1571     // Emit an explicit null check and deoptimize if opr is null
1572     CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check, Deoptimization::Action_none);
1573     cmp(lir_cond_equal, opr, LIR_OprFact::oopConst(NULL));
1574     branch(lir_cond_equal, deopt);
1575   } else {
1576     // Emit an implicit null check
1577     append(new LIR_Op1(lir_null_check, opr, info));
1578   }
1579 }
1580 
1581 void LIR_List::check_flattened_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub) {
1582   LIR_OpFlattenedArrayCheck* c = new LIR_OpFlattenedArrayCheck(array, value, tmp, stub);
1583   append(c);
1584 }
1585 
1586 void LIR_List::check_null_free_array(LIR_Opr array, LIR_Opr tmp) {
1587   LIR_OpNullFreeArrayCheck* c = new LIR_OpNullFreeArrayCheck(array, tmp);
1588   append(c);
1589 }
1590 
1591 void LIR_List::substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1592                                       LIR_Opr tmp1, LIR_Opr tmp2,
1593                                       ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
1594                                       CodeEmitInfo* info, CodeStub* stub) {
1595   LIR_OpSubstitutabilityCheck* c = new LIR_OpSubstitutabilityCheck(result, left, right, equal_result, not_equal_result,
1596                                                                    tmp1, tmp2,
1597                                                                    left_klass, right_klass, left_klass_op, right_klass_op,
1598                                                                    info, stub);
1599   append(c);
1600 }
1601 
1602 void LIR_List::cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1603                         LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1604   append(new LIR_OpCompareAndSwap(lir_cas_long, addr, cmp_value, new_value, t1, t2, result));
1605 }
1606 
1607 void LIR_List::cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1608                        LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1609   append(new LIR_OpCompareAndSwap(lir_cas_obj, addr, cmp_value, new_value, t1, t2, result));
1610 }
1611 
1612 void LIR_List::cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1613                        LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1614   append(new LIR_OpCompareAndSwap(lir_cas_int, addr, cmp_value, new_value, t1, t2, result));
1615 }
1616 
1617 
1618 #ifdef PRODUCT
1619 
1620 void print_LIR(BlockList* blocks) {
1621 }
1622 
1623 #else
1624 // LIR_OprDesc
1625 void LIR_OprDesc::print() const {
1626   print(tty);
1627 }
1628 
1629 void LIR_OprDesc::print(outputStream* out) const {
1630   if (is_illegal()) {
1631     return;
1632   }
1633 
1634   out->print("[");
1635   if (is_pointer()) {
1636     pointer()->print_value_on(out);
1637   } else if (is_single_stack()) {
1638     out->print("stack:%d", single_stack_ix());
1639   } else if (is_double_stack()) {
1640     out->print("dbl_stack:%d",double_stack_ix());
1641   } else if (is_virtual()) {
1642     out->print("R%d", vreg_number());
1643   } else if (is_single_cpu()) {
1644     out->print("%s", as_register()->name());
1645   } else if (is_double_cpu()) {
1646     out->print("%s", as_register_hi()->name());
1647     out->print("%s", as_register_lo()->name());
1648 #if defined(X86)
1649   } else if (is_single_xmm()) {
1650     out->print("%s", as_xmm_float_reg()->name());
1651   } else if (is_double_xmm()) {
1652     out->print("%s", as_xmm_double_reg()->name());
1653   } else if (is_single_fpu()) {
1654     out->print("fpu%d", fpu_regnr());
1655   } else if (is_double_fpu()) {
1656     out->print("fpu%d", fpu_regnrLo());
1657 #elif defined(AARCH64)
1658   } else if (is_single_fpu()) {
1659     out->print("fpu%d", fpu_regnr());
1660   } else if (is_double_fpu()) {
1661     out->print("fpu%d", fpu_regnrLo());
1662 #elif defined(ARM)
1663   } else if (is_single_fpu()) {
1664     out->print("s%d", fpu_regnr());
1665   } else if (is_double_fpu()) {
1666     out->print("d%d", fpu_regnrLo() >> 1);
1667 #else
1668   } else if (is_single_fpu()) {
1669     out->print("%s", as_float_reg()->name());
1670   } else if (is_double_fpu()) {
1671     out->print("%s", as_double_reg()->name());
1672 #endif
1673 
1674   } else if (is_illegal()) {
1675     out->print("-");
1676   } else {
1677     out->print("Unknown Operand");
1678   }
1679   if (!is_illegal()) {
1680     out->print("|%c", type_char());
1681   }
1682   if (is_register() && is_last_use()) {
1683     out->print("(last_use)");
1684   }
1685   out->print("]");
1686 }
1687 
1688 
1689 // LIR_Address
1690 void LIR_Const::print_value_on(outputStream* out) const {
1691   switch (type()) {
1692     case T_ADDRESS:out->print("address:%d",as_jint());          break;
1693     case T_INT:    out->print("int:%d",   as_jint());           break;
1694     case T_LONG:   out->print("lng:" JLONG_FORMAT, as_jlong()); break;
1695     case T_FLOAT:  out->print("flt:%f",   as_jfloat());         break;
1696     case T_DOUBLE: out->print("dbl:%f",   as_jdouble());        break;
1697     case T_OBJECT: out->print("obj:" INTPTR_FORMAT, p2i(as_jobject()));        break;
1698     case T_METADATA: out->print("metadata:" INTPTR_FORMAT, p2i(as_metadata()));break;
1699     default:       out->print("%3d:0x" UINT64_FORMAT_X, type(), (uint64_t)as_jlong()); break;
1700   }
1701 }
1702 
1703 // LIR_Address
1704 void LIR_Address::print_value_on(outputStream* out) const {
1705   out->print("Base:"); _base->print(out);
1706   if (!_index->is_illegal()) {
1707     out->print(" Index:"); _index->print(out);
1708     switch (scale()) {
1709     case times_1: break;
1710     case times_2: out->print(" * 2"); break;
1711     case times_4: out->print(" * 4"); break;
1712     case times_8: out->print(" * 8"); break;
1713     }
1714   }
1715   out->print(" Disp: " INTX_FORMAT, _disp);
1716 }
1717 
1718 // debug output of block header without InstructionPrinter
1719 //       (because phi functions are not necessary for LIR)
1720 static void print_block(BlockBegin* x) {
1721   // print block id
1722   BlockEnd* end = x->end();
1723   tty->print("B%d ", x->block_id());
1724 
1725   // print flags
1726   if (x->is_set(BlockBegin::std_entry_flag))               tty->print("std ");
1727   if (x->is_set(BlockBegin::osr_entry_flag))               tty->print("osr ");
1728   if (x->is_set(BlockBegin::exception_entry_flag))         tty->print("ex ");
1729   if (x->is_set(BlockBegin::subroutine_entry_flag))        tty->print("jsr ");
1730   if (x->is_set(BlockBegin::backward_branch_target_flag))  tty->print("bb ");
1731   if (x->is_set(BlockBegin::linear_scan_loop_header_flag)) tty->print("lh ");
1732   if (x->is_set(BlockBegin::linear_scan_loop_end_flag))    tty->print("le ");
1733 
1734   // print block bci range
1735   tty->print("[%d, %d] ", x->bci(), (end == NULL ? -1 : end->printable_bci()));
1736 
1737   // print predecessors and successors
1738   if (x->number_of_preds() > 0) {
1739     tty->print("preds: ");
1740     for (int i = 0; i < x->number_of_preds(); i ++) {
1741       tty->print("B%d ", x->pred_at(i)->block_id());
1742     }
1743   }
1744 
1745   if (x->number_of_sux() > 0) {
1746     tty->print("sux: ");
1747     for (int i = 0; i < x->number_of_sux(); i ++) {
1748       tty->print("B%d ", x->sux_at(i)->block_id());
1749     }
1750   }
1751 
1752   // print exception handlers
1753   if (x->number_of_exception_handlers() > 0) {
1754     tty->print("xhandler: ");
1755     for (int i = 0; i < x->number_of_exception_handlers();  i++) {
1756       tty->print("B%d ", x->exception_handler_at(i)->block_id());
1757     }
1758   }
1759 
1760   tty->cr();
1761 }
1762 
1763 void print_LIR(BlockList* blocks) {
1764   tty->print_cr("LIR:");
1765   int i;
1766   for (i = 0; i < blocks->length(); i++) {
1767     BlockBegin* bb = blocks->at(i);
1768     print_block(bb);
1769     tty->print("__id_Instruction___________________________________________"); tty->cr();
1770     bb->lir()->print_instructions();
1771   }
1772 }
1773 
1774 void LIR_List::print_instructions() {
1775   for (int i = 0; i < _operations.length(); i++) {
1776     _operations.at(i)->print(); tty->cr();
1777   }
1778   tty->cr();
1779 }
1780 
1781 // LIR_Ops printing routines
1782 // LIR_Op
1783 void LIR_Op::print_on(outputStream* out) const {
1784   if (id() != -1 || PrintCFGToFile) {
1785     out->print("%4d ", id());
1786   } else {
1787     out->print("     ");
1788   }
1789   out->print("%s ", name());
1790   print_instr(out);
1791   if (info() != NULL) out->print(" [bci:%d]", info()->stack()->bci());
1792 #ifdef ASSERT
1793   if (Verbose && _file != NULL) {
1794     out->print(" (%s:%d)", _file, _line);
1795   }
1796 #endif
1797 }
1798 
1799 const char * LIR_Op::name() const {
1800   const char* s = NULL;
1801   switch(code()) {
1802      // LIR_Op0
1803      case lir_membar:                s = "membar";        break;
1804      case lir_membar_acquire:        s = "membar_acquire"; break;
1805      case lir_membar_release:        s = "membar_release"; break;
1806      case lir_membar_loadload:       s = "membar_loadload";   break;
1807      case lir_membar_storestore:     s = "membar_storestore"; break;
1808      case lir_membar_loadstore:      s = "membar_loadstore";  break;
1809      case lir_membar_storeload:      s = "membar_storeload";  break;
1810      case lir_label:                 s = "label";         break;
1811      case lir_nop:                   s = "nop";           break;
1812      case lir_on_spin_wait:          s = "on_spin_wait";  break;
1813      case lir_std_entry:             s = "std_entry";     break;
1814      case lir_osr_entry:             s = "osr_entry";     break;
1815      case lir_fpop_raw:              s = "fpop_raw";      break;
1816      case lir_breakpoint:            s = "breakpoint";    break;
1817      case lir_get_thread:            s = "get_thread";    break;
1818      case lir_check_orig_pc:         s = "check_orig_pc"; break;
1819      // LIR_Op1
1820      case lir_fxch:                  s = "fxch";          break;
1821      case lir_fld:                   s = "fld";           break;
1822      case lir_push:                  s = "push";          break;
1823      case lir_pop:                   s = "pop";           break;
1824      case lir_null_check:            s = "null_check";    break;
1825      case lir_return:                s = "return";        break;
1826      case lir_safepoint:             s = "safepoint";     break;
1827      case lir_leal:                  s = "leal";          break;
1828      case lir_branch:                s = "branch";        break;
1829      case lir_cond_float_branch:     s = "flt_cond_br";   break;
1830      case lir_move:                  s = "move";          break;
1831      case lir_roundfp:               s = "roundfp";       break;
1832      case lir_rtcall:                s = "rtcall";        break;
1833      case lir_throw:                 s = "throw";         break;
1834      case lir_unwind:                s = "unwind";        break;
1835      case lir_convert:               s = "convert";       break;
1836      case lir_alloc_object:          s = "alloc_obj";     break;
1837      case lir_monaddr:               s = "mon_addr";      break;
1838      // LIR_Op2
1839      case lir_cmp:                   s = "cmp";           break;
1840      case lir_cmp_l2i:               s = "cmp_l2i";       break;
1841      case lir_ucmp_fd2i:             s = "ucomp_fd2i";    break;
1842      case lir_cmp_fd2i:              s = "comp_fd2i";     break;
1843      case lir_cmove:                 s = "cmove";         break;
1844      case lir_add:                   s = "add";           break;
1845      case lir_sub:                   s = "sub";           break;
1846      case lir_mul:                   s = "mul";           break;
1847      case lir_div:                   s = "div";           break;
1848      case lir_rem:                   s = "rem";           break;
1849      case lir_abs:                   s = "abs";           break;
1850      case lir_neg:                   s = "neg";           break;
1851      case lir_sqrt:                  s = "sqrt";          break;
1852      case lir_logic_and:             s = "logic_and";     break;
1853      case lir_logic_or:              s = "logic_or";      break;
1854      case lir_logic_xor:             s = "logic_xor";     break;
1855      case lir_shl:                   s = "shift_left";    break;
1856      case lir_shr:                   s = "shift_right";   break;
1857      case lir_ushr:                  s = "ushift_right";  break;
1858      case lir_alloc_array:           s = "alloc_array";   break;
1859      case lir_xadd:                  s = "xadd";          break;
1860      case lir_xchg:                  s = "xchg";          break;
1861      // LIR_Op3
1862      case lir_idiv:                  s = "idiv";          break;
1863      case lir_irem:                  s = "irem";          break;
1864      case lir_fmad:                  s = "fmad";          break;
1865      case lir_fmaf:                  s = "fmaf";          break;
1866      // LIR_OpJavaCall
1867      case lir_static_call:           s = "static";        break;
1868      case lir_optvirtual_call:       s = "optvirtual";    break;
1869      case lir_icvirtual_call:        s = "icvirtual";     break;
1870      case lir_dynamic_call:          s = "dynamic";       break;
1871      // LIR_OpArrayCopy
1872      case lir_arraycopy:             s = "arraycopy";     break;
1873      // LIR_OpUpdateCRC32
1874      case lir_updatecrc32:           s = "updatecrc32";   break;
1875      // LIR_OpLock
1876      case lir_lock:                  s = "lock";          break;
1877      case lir_unlock:                s = "unlock";        break;
1878      // LIR_OpDelay
1879      case lir_delay_slot:            s = "delay";         break;
1880      // LIR_OpTypeCheck
1881      case lir_instanceof:            s = "instanceof";    break;
1882      case lir_checkcast:             s = "checkcast";     break;
1883      case lir_store_check:           s = "store_check";   break;
1884      // LIR_OpFlattenedArrayCheck
1885      case lir_flattened_array_check: s = "flattened_array_check"; break;
1886      // LIR_OpNullFreeArrayCheck
1887      case lir_null_free_array_check: s = "null_free_array_check"; break;
1888      // LIR_OpSubstitutabilityCheck
1889      case lir_substitutability_check: s = "substitutability_check"; break;
1890      // LIR_OpCompareAndSwap
1891      case lir_cas_long:              s = "cas_long";      break;
1892      case lir_cas_obj:               s = "cas_obj";      break;
1893      case lir_cas_int:               s = "cas_int";      break;
1894      // LIR_OpProfileCall
1895      case lir_profile_call:          s = "profile_call";  break;
1896      // LIR_OpProfileType
1897      case lir_profile_type:          s = "profile_type";  break;
1898      // LIR_OpProfileInlineType
1899      case lir_profile_inline_type:   s = "profile_inline_type"; break;
1900      // LIR_OpAssert
1901 #ifdef ASSERT
1902      case lir_assert:                s = "assert";        break;
1903 #endif
1904      case lir_none:                  ShouldNotReachHere();break;
1905     default:                         s = "illegal_op";    break;
1906   }
1907   return s;
1908 }
1909 
1910 // LIR_OpJavaCall
1911 void LIR_OpJavaCall::print_instr(outputStream* out) const {
1912   out->print("call: ");
1913   out->print("[addr: " INTPTR_FORMAT "]", p2i(address()));
1914   if (receiver()->is_valid()) {
1915     out->print(" [recv: ");   receiver()->print(out);   out->print("]");
1916   }
1917   if (result_opr()->is_valid()) {
1918     out->print(" [result: "); result_opr()->print(out); out->print("]");
1919   }
1920 }
1921 
1922 // LIR_OpLabel
1923 void LIR_OpLabel::print_instr(outputStream* out) const {
1924   out->print("[label:" INTPTR_FORMAT "]", p2i(_label));
1925 }
1926 
1927 // LIR_OpArrayCopy
1928 void LIR_OpArrayCopy::print_instr(outputStream* out) const {
1929   src()->print(out);     out->print(" ");
1930   src_pos()->print(out); out->print(" ");
1931   dst()->print(out);     out->print(" ");
1932   dst_pos()->print(out); out->print(" ");
1933   length()->print(out);  out->print(" ");
1934   tmp()->print(out);     out->print(" ");
1935 }
1936 
1937 // LIR_OpUpdateCRC32
1938 void LIR_OpUpdateCRC32::print_instr(outputStream* out) const {
1939   crc()->print(out);     out->print(" ");
1940   val()->print(out);     out->print(" ");
1941   result_opr()->print(out); out->print(" ");
1942 }
1943 
1944 // LIR_OpCompareAndSwap
1945 void LIR_OpCompareAndSwap::print_instr(outputStream* out) const {
1946   addr()->print(out);      out->print(" ");
1947   cmp_value()->print(out); out->print(" ");
1948   new_value()->print(out); out->print(" ");
1949   tmp1()->print(out);      out->print(" ");
1950   tmp2()->print(out);      out->print(" ");
1951 
1952 }
1953 
1954 // LIR_Op0
1955 void LIR_Op0::print_instr(outputStream* out) const {
1956   result_opr()->print(out);
1957 }
1958 
1959 // LIR_Op1
1960 const char * LIR_Op1::name() const {
1961   if (code() == lir_move) {
1962     switch (move_kind()) {
1963     case lir_move_normal:
1964       return "move";
1965     case lir_move_volatile:
1966       return "volatile_move";
1967     case lir_move_wide:
1968       return "wide_move";
1969     default:
1970       ShouldNotReachHere();
1971     return "illegal_op";
1972     }
1973   } else {
1974     return LIR_Op::name();
1975   }
1976 }
1977 
1978 
1979 void LIR_Op1::print_instr(outputStream* out) const {
1980   _opr->print(out);         out->print(" ");
1981   result_opr()->print(out); out->print(" ");
1982   print_patch_code(out, patch_code());
1983 }
1984 
1985 
1986 // LIR_Op1
1987 void LIR_OpRTCall::print_instr(outputStream* out) const {
1988   intx a = (intx)addr();
1989   out->print("%s", Runtime1::name_for_address(addr()));
1990   out->print(" ");
1991   tmp()->print(out);
1992 }
1993 
1994 void LIR_Op1::print_patch_code(outputStream* out, LIR_PatchCode code) {
1995   switch(code) {
1996     case lir_patch_none:                                 break;
1997     case lir_patch_low:    out->print("[patch_low]");    break;
1998     case lir_patch_high:   out->print("[patch_high]");   break;
1999     case lir_patch_normal: out->print("[patch_normal]"); break;
2000     default: ShouldNotReachHere();
2001   }
2002 }
2003 
2004 // LIR_OpBranch
2005 void LIR_OpBranch::print_instr(outputStream* out) const {
2006   print_condition(out, cond());             out->print(" ");
2007   if (block() != NULL) {
2008     out->print("[B%d] ", block()->block_id());
2009   } else if (stub() != NULL) {
2010     out->print("[");
2011     stub()->print_name(out);
2012     out->print(": " INTPTR_FORMAT "]", p2i(stub()));
2013     if (stub()->info() != NULL) out->print(" [bci:%d]", stub()->info()->stack()->bci());
2014   } else {
2015     out->print("[label:" INTPTR_FORMAT "] ", p2i(label()));
2016   }
2017   if (ublock() != NULL) {
2018     out->print("unordered: [B%d] ", ublock()->block_id());
2019   }
2020 }
2021 
2022 void LIR_Op::print_condition(outputStream* out, LIR_Condition cond) {
2023   switch(cond) {
2024     case lir_cond_equal:           out->print("[EQ]");      break;
2025     case lir_cond_notEqual:        out->print("[NE]");      break;
2026     case lir_cond_less:            out->print("[LT]");      break;
2027     case lir_cond_lessEqual:       out->print("[LE]");      break;
2028     case lir_cond_greaterEqual:    out->print("[GE]");      break;
2029     case lir_cond_greater:         out->print("[GT]");      break;
2030     case lir_cond_belowEqual:      out->print("[BE]");      break;
2031     case lir_cond_aboveEqual:      out->print("[AE]");      break;
2032     case lir_cond_always:          out->print("[AL]");      break;
2033     default:                       out->print("[%d]",cond); break;
2034   }
2035 }
2036 
2037 // LIR_OpConvert
2038 void LIR_OpConvert::print_instr(outputStream* out) const {
2039   print_bytecode(out, bytecode());
2040   in_opr()->print(out);                  out->print(" ");
2041   result_opr()->print(out);              out->print(" ");
2042 #ifdef PPC32
2043   if(tmp1()->is_valid()) {
2044     tmp1()->print(out); out->print(" ");
2045     tmp2()->print(out); out->print(" ");
2046   }
2047 #endif
2048 }
2049 
2050 void LIR_OpConvert::print_bytecode(outputStream* out, Bytecodes::Code code) {
2051   switch(code) {
2052     case Bytecodes::_d2f: out->print("[d2f] "); break;
2053     case Bytecodes::_d2i: out->print("[d2i] "); break;
2054     case Bytecodes::_d2l: out->print("[d2l] "); break;
2055     case Bytecodes::_f2d: out->print("[f2d] "); break;
2056     case Bytecodes::_f2i: out->print("[f2i] "); break;
2057     case Bytecodes::_f2l: out->print("[f2l] "); break;
2058     case Bytecodes::_i2b: out->print("[i2b] "); break;
2059     case Bytecodes::_i2c: out->print("[i2c] "); break;
2060     case Bytecodes::_i2d: out->print("[i2d] "); break;
2061     case Bytecodes::_i2f: out->print("[i2f] "); break;
2062     case Bytecodes::_i2l: out->print("[i2l] "); break;
2063     case Bytecodes::_i2s: out->print("[i2s] "); break;
2064     case Bytecodes::_l2i: out->print("[l2i] "); break;
2065     case Bytecodes::_l2f: out->print("[l2f] "); break;
2066     case Bytecodes::_l2d: out->print("[l2d] "); break;
2067     default:
2068       out->print("[?%d]",code);
2069     break;
2070   }
2071 }
2072 
2073 void LIR_OpAllocObj::print_instr(outputStream* out) const {
2074   klass()->print(out);                      out->print(" ");
2075   obj()->print(out);                        out->print(" ");
2076   tmp1()->print(out);                       out->print(" ");
2077   tmp2()->print(out);                       out->print(" ");
2078   tmp3()->print(out);                       out->print(" ");
2079   tmp4()->print(out);                       out->print(" ");
2080   out->print("[hdr:%d]", header_size()); out->print(" ");
2081   out->print("[obj:%d]", object_size()); out->print(" ");
2082   out->print("[lbl:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2083 }
2084 
2085 void LIR_OpRoundFP::print_instr(outputStream* out) const {
2086   _opr->print(out);         out->print(" ");
2087   tmp()->print(out);        out->print(" ");
2088   result_opr()->print(out); out->print(" ");
2089 }
2090 
2091 // LIR_Op2
2092 void LIR_Op2::print_instr(outputStream* out) const {
2093   if (code() == lir_cmove || code() == lir_cmp) {
2094     print_condition(out, condition());         out->print(" ");
2095   }
2096   in_opr1()->print(out);    out->print(" ");
2097   in_opr2()->print(out);    out->print(" ");
2098   if (tmp1_opr()->is_valid()) { tmp1_opr()->print(out);    out->print(" "); }
2099   if (tmp2_opr()->is_valid()) { tmp2_opr()->print(out);    out->print(" "); }
2100   if (tmp3_opr()->is_valid()) { tmp3_opr()->print(out);    out->print(" "); }
2101   if (tmp4_opr()->is_valid()) { tmp4_opr()->print(out);    out->print(" "); }
2102   if (tmp5_opr()->is_valid()) { tmp5_opr()->print(out);    out->print(" "); }
2103   result_opr()->print(out);
2104 }
2105 
2106 void LIR_OpAllocArray::print_instr(outputStream* out) const {
2107   klass()->print(out);                   out->print(" ");
2108   len()->print(out);                     out->print(" ");
2109   obj()->print(out);                     out->print(" ");
2110   tmp1()->print(out);                    out->print(" ");
2111   tmp2()->print(out);                    out->print(" ");
2112   tmp3()->print(out);                    out->print(" ");
2113   tmp4()->print(out);                    out->print(" ");
2114   out->print("[type:0x%x]", type());     out->print(" ");
2115   out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2116 }
2117 
2118 
2119 void LIR_OpTypeCheck::print_instr(outputStream* out) const {
2120   object()->print(out);                  out->print(" ");
2121   if (code() == lir_store_check) {
2122     array()->print(out);                 out->print(" ");
2123   }
2124   if (code() != lir_store_check) {
2125     klass()->print_name_on(out);         out->print(" ");
2126     if (fast_check())                 out->print("fast_check ");
2127   }
2128   tmp1()->print(out);                    out->print(" ");
2129   tmp2()->print(out);                    out->print(" ");
2130   tmp3()->print(out);                    out->print(" ");
2131   result_opr()->print(out);              out->print(" ");
2132   if (info_for_exception() != NULL) out->print(" [bci:%d]", info_for_exception()->stack()->bci());
2133 }
2134 
2135 void LIR_OpFlattenedArrayCheck::print_instr(outputStream* out) const {
2136   array()->print(out);                   out->print(" ");
2137   value()->print(out);                   out->print(" ");
2138   tmp()->print(out);                     out->print(" ");
2139   if (stub() != NULL) {
2140     out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2141   }
2142 }
2143 
2144 void LIR_OpNullFreeArrayCheck::print_instr(outputStream* out) const {
2145   array()->print(out);                   out->print(" ");
2146   tmp()->print(out);                     out->print(" ");
2147 }
2148 
2149 void LIR_OpSubstitutabilityCheck::print_instr(outputStream* out) const {
2150   result_opr()->print(out);              out->print(" ");
2151   left()->print(out);                    out->print(" ");
2152   right()->print(out);                   out->print(" ");
2153   equal_result()->print(out);            out->print(" ");
2154   not_equal_result()->print(out);        out->print(" ");
2155   tmp1()->print(out);                    out->print(" ");
2156   tmp2()->print(out);                    out->print(" ");
2157   if (left_klass() == NULL) {
2158     out->print("unknown ");
2159   } else {
2160     left_klass()->print(out);            out->print(" ");
2161   }
2162   if (right_klass() == NULL) {
2163     out->print("unknown ");
2164   } else {
2165     right_klass()->print(out);           out->print(" ");
2166   }
2167   left_klass_op()->print(out);           out->print(" ");
2168   right_klass_op()->print(out);          out->print(" ");
2169   if (stub() != NULL) {
2170     out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2171   }
2172 }
2173 
2174 // LIR_Op3
2175 void LIR_Op3::print_instr(outputStream* out) const {
2176   in_opr1()->print(out);    out->print(" ");
2177   in_opr2()->print(out);    out->print(" ");
2178   in_opr3()->print(out);    out->print(" ");
2179   result_opr()->print(out);
2180 }
2181 
2182 
2183 void LIR_OpLock::print_instr(outputStream* out) const {
2184   hdr_opr()->print(out);   out->print(" ");
2185   obj_opr()->print(out);   out->print(" ");
2186   lock_opr()->print(out);  out->print(" ");
2187   if (_scratch->is_valid()) {
2188     _scratch->print(out);  out->print(" ");
2189   }
2190   out->print("[lbl:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2191 }
2192 
2193 #ifdef ASSERT
2194 void LIR_OpAssert::print_instr(outputStream* out) const {
2195   print_condition(out, condition()); out->print(" ");
2196   in_opr1()->print(out);             out->print(" ");
2197   in_opr2()->print(out);             out->print(", \"");
2198   out->print("%s", msg());          out->print("\"");
2199 }
2200 #endif
2201 
2202 
2203 void LIR_OpDelay::print_instr(outputStream* out) const {
2204   _op->print_on(out);
2205 }
2206 
2207 
2208 // LIR_OpProfileCall
2209 void LIR_OpProfileCall::print_instr(outputStream* out) const {
2210   profiled_method()->name()->print_symbol_on(out);
2211   out->print(".");
2212   profiled_method()->holder()->name()->print_symbol_on(out);
2213   out->print(" @ %d ", profiled_bci());
2214   mdo()->print(out);           out->print(" ");
2215   recv()->print(out);          out->print(" ");
2216   tmp1()->print(out);          out->print(" ");
2217 }
2218 
2219 // LIR_OpProfileType
2220 void LIR_OpProfileType::print_instr(outputStream* out) const {
2221   out->print("exact = ");
2222   if  (exact_klass() == NULL) {
2223     out->print("unknown");
2224   } else {
2225     exact_klass()->print_name_on(out);
2226   }
2227   out->print(" current = "); ciTypeEntries::print_ciklass(out, current_klass());
2228   out->print(" ");
2229   mdp()->print(out);          out->print(" ");
2230   obj()->print(out);          out->print(" ");
2231   tmp()->print(out);          out->print(" ");
2232 }
2233 
2234 // LIR_OpProfileInlineType
2235 void LIR_OpProfileInlineType::print_instr(outputStream* out) const {
2236   out->print(" flag = %x ", flag());
2237   mdp()->print(out);          out->print(" ");
2238   obj()->print(out);          out->print(" ");
2239   tmp()->print(out);          out->print(" ");
2240 }
2241 
2242 #endif // PRODUCT
2243 
2244 // Implementation of LIR_InsertionBuffer
2245 
2246 void LIR_InsertionBuffer::append(int index, LIR_Op* op) {
2247   assert(_index_and_count.length() % 2 == 0, "must have a count for each index");
2248 
2249   int i = number_of_insertion_points() - 1;
2250   if (i < 0 || index_at(i) < index) {
2251     append_new(index, 1);
2252   } else {
2253     assert(index_at(i) == index, "can append LIR_Ops in ascending order only");
2254     assert(count_at(i) > 0, "check");
2255     set_count_at(i, count_at(i) + 1);
2256   }
2257   _ops.push(op);
2258 
2259   DEBUG_ONLY(verify());
2260 }
2261 
2262 #ifdef ASSERT
2263 void LIR_InsertionBuffer::verify() {
2264   int sum = 0;
2265   int prev_idx = -1;
2266 
2267   for (int i = 0; i < number_of_insertion_points(); i++) {
2268     assert(prev_idx < index_at(i), "index must be ordered ascending");
2269     sum += count_at(i);
2270   }
2271   assert(sum == number_of_ops(), "wrong total sum");
2272 }
2273 #endif