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