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