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