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