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