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