1 /*
   2  * Copyright (c) 2005, 2017, 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_Compilation.hpp"
  27 #include "c1/c1_FrameMap.hpp"
  28 #include "c1/c1_Instruction.hpp"
  29 #include "c1/c1_LIRAssembler.hpp"
  30 #include "c1/c1_LIRGenerator.hpp"
  31 #include "c1/c1_Runtime1.hpp"
  32 #include "c1/c1_ValueStack.hpp"
  33 #include "ci/ciArray.hpp"
  34 #include "ci/ciObjArrayKlass.hpp"
  35 #include "ci/ciTypeArrayKlass.hpp"
  36 #include "runtime/sharedRuntime.hpp"
  37 #include "runtime/stubRoutines.hpp"
  38 #include "vmreg_sparc.inline.hpp"
  39 
  40 #ifdef ASSERT
  41 #define __ gen()->lir(__FILE__, __LINE__)->
  42 #else
  43 #define __ gen()->lir()->
  44 #endif
  45 
  46 void LIRItem::load_byte_item() {
  47   // byte loads use same registers as other loads
  48   load_item();
  49 }
  50 
  51 
  52 void LIRItem::load_nonconstant() {
  53   LIR_Opr r = value()->operand();
  54   if (_gen->can_inline_as_constant(value())) {
  55     if (!r->is_constant()) {
  56       r = LIR_OprFact::value_type(value()->type());
  57     }
  58     _result = r;
  59   } else {
  60     load_item();
  61   }
  62 }
  63 
  64 
  65 //--------------------------------------------------------------
  66 //               LIRGenerator
  67 //--------------------------------------------------------------
  68 
  69 LIR_Opr LIRGenerator::exceptionOopOpr()              { return FrameMap::Oexception_opr;  }
  70 LIR_Opr LIRGenerator::exceptionPcOpr()               { return FrameMap::Oissuing_pc_opr; }
  71 LIR_Opr LIRGenerator::syncLockOpr()                  { return new_register(T_INT); }
  72 LIR_Opr LIRGenerator::syncTempOpr()                  { return new_register(T_OBJECT); }
  73 LIR_Opr LIRGenerator::getThreadTemp()                { return rlock_callee_saved(T_LONG); }
  74 
  75 LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {
  76   LIR_Opr opr;
  77   switch (type->tag()) {
  78   case intTag:     opr = callee ? FrameMap::I0_opr      : FrameMap::O0_opr;       break;
  79   case objectTag:  opr = callee ? FrameMap::I0_oop_opr  : FrameMap::O0_oop_opr;   break;
  80   case longTag:    opr = callee ? FrameMap::in_long_opr : FrameMap::out_long_opr; break;
  81   case floatTag:   opr = FrameMap::F0_opr;                                        break;
  82   case doubleTag:  opr = FrameMap::F0_double_opr;                                 break;
  83 
  84   case addressTag:
  85   default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
  86   }
  87 
  88   assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
  89   return opr;
  90 }
  91 
  92 LIR_Opr LIRGenerator::rlock_callee_saved(BasicType type) {
  93   LIR_Opr reg = new_register(type);
  94   set_vreg_flag(reg, callee_saved);
  95   return reg;
  96 }
  97 
  98 
  99 LIR_Opr LIRGenerator::rlock_byte(BasicType type) {
 100   return new_register(T_INT);
 101 }
 102 
 103 
 104 
 105 
 106 
 107 //--------- loading items into registers --------------------------------
 108 
 109 // SPARC cannot inline all constants
 110 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
 111   if (v->type()->as_IntConstant() != NULL) {
 112     return v->type()->as_IntConstant()->value() == 0;
 113   } else if (v->type()->as_LongConstant() != NULL) {
 114     return v->type()->as_LongConstant()->value() == 0L;
 115   } else if (v->type()->as_ObjectConstant() != NULL) {
 116     return v->type()->as_ObjectConstant()->value()->is_null_object();
 117   } else {
 118     return false;
 119   }
 120 }
 121 
 122 
 123 // only simm13 constants can be inlined
 124 bool LIRGenerator:: can_inline_as_constant(Value i) const {
 125   if (i->type()->as_IntConstant() != NULL) {
 126     return Assembler::is_simm13(i->type()->as_IntConstant()->value());
 127   } else {
 128     return can_store_as_constant(i, as_BasicType(i->type()));
 129   }
 130 }
 131 
 132 
 133 bool LIRGenerator:: can_inline_as_constant(LIR_Const* c) const {
 134   if (c->type() == T_INT) {
 135     return Assembler::is_simm13(c->as_jint());
 136   }
 137   return false;
 138 }
 139 
 140 
 141 LIR_Opr LIRGenerator::safepoint_poll_register() {
 142   return new_register(T_INT);
 143 }
 144 
 145 
 146 
 147 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
 148                                             int shift, int disp, BasicType type) {
 149   assert(base->is_register(), "must be");
 150   intx large_disp = disp;
 151 
 152   // accumulate fixed displacements
 153   if (index->is_constant()) {
 154     large_disp += (intx)(index->as_constant_ptr()->as_jint()) << shift;
 155     index = LIR_OprFact::illegalOpr;
 156   }
 157 
 158   if (index->is_register()) {
 159     // apply the shift and accumulate the displacement
 160     if (shift > 0) {
 161       LIR_Opr tmp = new_pointer_register();
 162       __ shift_left(index, shift, tmp);
 163       index = tmp;
 164     }
 165     if (large_disp != 0) {
 166       LIR_Opr tmp = new_pointer_register();
 167       if (Assembler::is_simm13(large_disp)) {
 168         __ add(tmp, LIR_OprFact::intptrConst(large_disp), tmp);
 169         index = tmp;
 170       } else {
 171         __ move(LIR_OprFact::intptrConst(large_disp), tmp);
 172         __ add(tmp, index, tmp);
 173         index = tmp;
 174       }
 175       large_disp = 0;
 176     }
 177   } else if (large_disp != 0 && !Assembler::is_simm13(large_disp)) {
 178     // index is illegal so replace it with the displacement loaded into a register
 179     index = new_pointer_register();
 180     __ move(LIR_OprFact::intptrConst(large_disp), index);
 181     large_disp = 0;
 182   }
 183 
 184   // at this point we either have base + index or base + displacement
 185   if (large_disp == 0) {
 186     return new LIR_Address(base, index, type);
 187   } else {
 188     assert(Assembler::is_simm13(large_disp), "must be");
 189     return new LIR_Address(base, large_disp, type);
 190   }
 191 }
 192 
 193 
 194 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,
 195                                               BasicType type, bool needs_card_mark) {
 196   int elem_size = type2aelembytes(type);
 197   int shift = exact_log2(elem_size);
 198 
 199   LIR_Opr base_opr;
 200   intx offset = arrayOopDesc::base_offset_in_bytes(type);
 201 
 202   if (index_opr->is_constant()) {
 203     intx i = index_opr->as_constant_ptr()->as_jint();
 204     intx array_offset = i * elem_size;
 205     if (Assembler::is_simm13(array_offset + offset)) {
 206       base_opr = array_opr;
 207       offset = array_offset + offset;
 208     } else {
 209       base_opr = new_pointer_register();
 210       if (Assembler::is_simm13(array_offset)) {
 211         __ add(array_opr, LIR_OprFact::intptrConst(array_offset), base_opr);
 212       } else {
 213         __ move(LIR_OprFact::intptrConst(array_offset), base_opr);
 214         __ add(base_opr, array_opr, base_opr);
 215       }
 216     }
 217   } else {
 218     if (index_opr->type() == T_INT) {
 219       LIR_Opr tmp = new_register(T_LONG);
 220       __ convert(Bytecodes::_i2l, index_opr, tmp);
 221       index_opr = tmp;
 222     }
 223 
 224     base_opr = new_pointer_register();
 225     assert (index_opr->is_register(), "Must be register");
 226     if (shift > 0) {
 227       __ shift_left(index_opr, shift, base_opr);
 228       __ add(base_opr, array_opr, base_opr);
 229     } else {
 230       __ add(index_opr, array_opr, base_opr);
 231     }
 232   }
 233   if (needs_card_mark) {
 234     LIR_Opr ptr = new_pointer_register();
 235     __ add(base_opr, LIR_OprFact::intptrConst(offset), ptr);
 236     return new LIR_Address(ptr, type);
 237   } else {
 238     return new LIR_Address(base_opr, offset, type);
 239   }
 240 }
 241 
 242 LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {
 243   LIR_Opr r;
 244   if (type == T_LONG) {
 245     r = LIR_OprFact::longConst(x);
 246   } else if (type == T_INT) {
 247     r = LIR_OprFact::intConst(x);
 248   } else {
 249     ShouldNotReachHere();
 250   }
 251   if (!Assembler::is_simm13(x)) {
 252     LIR_Opr tmp = new_register(type);
 253     __ move(r, tmp);
 254     return tmp;
 255   }
 256   return r;
 257 }
 258 
 259 void LIRGenerator::increment_counter(address counter, BasicType type, int step) {
 260   LIR_Opr pointer = new_pointer_register();
 261   __ move(LIR_OprFact::intptrConst(counter), pointer);
 262   LIR_Address* addr = new LIR_Address(pointer, type);
 263   increment_counter(addr, step);
 264 }
 265 
 266 void LIRGenerator::increment_counter(LIR_Address* addr, int step) {
 267   LIR_Opr temp = new_register(addr->type());
 268   __ move(addr, temp);
 269   __ add(temp, load_immediate(step, addr->type()), temp);
 270   __ move(temp, addr);
 271 }
 272 
 273 void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {
 274   LIR_Opr o7opr = FrameMap::O7_opr;
 275   __ load(new LIR_Address(base, disp, T_INT), o7opr, info);
 276   __ cmp(condition, o7opr, c);
 277 }
 278 
 279 
 280 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {
 281   LIR_Opr o7opr = FrameMap::O7_opr;
 282   __ load(new LIR_Address(base, disp, type), o7opr, info);
 283   __ cmp(condition, reg, o7opr);
 284 }
 285 
 286 
 287 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info) {
 288   LIR_Opr o7opr = FrameMap::O7_opr;
 289   __ load(new LIR_Address(base, disp, type), o7opr, info);
 290   __ cmp(condition, reg, o7opr);
 291 }
 292 
 293 
 294 bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) {
 295   assert(left != result, "should be different registers");
 296   if (is_power_of_2(c + 1)) {
 297     __ shift_left(left, log2_intptr(c + 1), result);
 298     __ sub(result, left, result);
 299     return true;
 300   } else if (is_power_of_2(c - 1)) {
 301     __ shift_left(left, log2_intptr(c - 1), result);
 302     __ add(result, left, result);
 303     return true;
 304   }
 305   return false;
 306 }
 307 
 308 
 309 void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {
 310   BasicType t = item->type();
 311   LIR_Opr sp_opr = FrameMap::SP_opr;
 312   if ((t == T_LONG || t == T_DOUBLE) &&
 313       ((in_bytes(offset_from_sp) - STACK_BIAS) % 8 != 0)) {
 314     __ unaligned_move(item, new LIR_Address(sp_opr, in_bytes(offset_from_sp), t));
 315   } else {
 316     __ move(item, new LIR_Address(sp_opr, in_bytes(offset_from_sp), t));
 317   }
 318 }
 319 
 320 //----------------------------------------------------------------------
 321 //             visitor functions
 322 //----------------------------------------------------------------------
 323 
 324 
 325 void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {
 326   assert(x->is_pinned(),"");
 327   bool needs_range_check = x->compute_needs_range_check();
 328   bool use_length = x->length() != NULL;
 329   bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;
 330   bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||
 331                                          !get_jobject_constant(x->value())->is_null_object() ||
 332                                          x->should_profile());
 333 
 334   LIRItem array(x->array(), this);
 335   LIRItem index(x->index(), this);
 336   LIRItem value(x->value(), this);
 337   LIRItem length(this);
 338 
 339   array.load_item();
 340   index.load_nonconstant();
 341 
 342   if (use_length && needs_range_check) {
 343     length.set_instruction(x->length());
 344     length.load_item();
 345   }
 346   if (needs_store_check || x->check_boolean()) {
 347     value.load_item();
 348   } else {
 349     value.load_for_store(x->elt_type());
 350   }
 351 
 352   set_no_result(x);
 353 
 354   // the CodeEmitInfo must be duplicated for each different
 355   // LIR-instruction because spilling can occur anywhere between two
 356   // instructions and so the debug information must be different
 357   CodeEmitInfo* range_check_info = state_for(x);
 358   CodeEmitInfo* null_check_info = NULL;
 359   if (x->needs_null_check()) {
 360     null_check_info = new CodeEmitInfo(range_check_info);
 361   }
 362 
 363   // emit array address setup early so it schedules better
 364   LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store);
 365 
 366   if (GenerateRangeChecks && needs_range_check) {
 367     if (use_length) {
 368       __ cmp(lir_cond_belowEqual, length.result(), index.result());
 369       __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));
 370     } else {
 371       array_range_check(array.result(), index.result(), null_check_info, range_check_info);
 372       // range_check also does the null check
 373       null_check_info = NULL;
 374     }
 375   }
 376 
 377   if (GenerateArrayStoreCheck && needs_store_check) {
 378     LIR_Opr tmp1 = FrameMap::G1_opr;
 379     LIR_Opr tmp2 = FrameMap::G3_opr;
 380     LIR_Opr tmp3 = FrameMap::G5_opr;
 381 
 382     CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);
 383     __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());
 384   }
 385 
 386   if (obj_store) {
 387     // Needs GC write barriers.
 388     pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr /* pre_val */,
 389                 true /* do_load */, false /* patch */, NULL);
 390   }
 391   LIR_Opr result = maybe_mask_boolean(x, array.result(), value.result(), null_check_info);
 392   __ move(result, array_addr, null_check_info);
 393   if (obj_store) {
 394     // Precise card mark
 395     post_barrier(LIR_OprFact::address(array_addr), value.result());
 396   }
 397 }
 398 
 399 
 400 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
 401   assert(x->is_pinned(),"");
 402   LIRItem obj(x->obj(), this);
 403   obj.load_item();
 404 
 405   set_no_result(x);
 406 
 407   LIR_Opr lock    = FrameMap::G1_opr;
 408   LIR_Opr scratch = FrameMap::G3_opr;
 409   LIR_Opr hdr     = FrameMap::G4_opr;
 410 
 411   CodeEmitInfo* info_for_exception = NULL;
 412   if (x->needs_null_check()) {
 413     info_for_exception = state_for(x);
 414   }
 415 
 416   // this CodeEmitInfo must not have the xhandlers because here the
 417   // object is already locked (xhandlers expects object to be unlocked)
 418   CodeEmitInfo* info = state_for(x, x->state(), true);
 419   monitor_enter(obj.result(), lock, hdr, scratch, x->monitor_no(), info_for_exception, info);
 420 }
 421 
 422 
 423 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
 424   assert(x->is_pinned(),"");
 425   LIRItem obj(x->obj(), this);
 426   obj.dont_load_item();
 427 
 428   set_no_result(x);
 429   LIR_Opr lock      = FrameMap::G1_opr;
 430   LIR_Opr hdr       = FrameMap::G3_opr;
 431   LIR_Opr obj_temp  = FrameMap::G4_opr;
 432   monitor_exit(obj_temp, lock, hdr, LIR_OprFact::illegalOpr, x->monitor_no());
 433 }
 434 
 435 
 436 // _ineg, _lneg, _fneg, _dneg
 437 void LIRGenerator::do_NegateOp(NegateOp* x) {
 438   LIRItem value(x->x(), this);
 439   value.load_item();
 440   LIR_Opr reg = rlock_result(x);
 441   __ negate(value.result(), reg);
 442 }
 443 
 444 
 445 
 446 // for  _fadd, _fmul, _fsub, _fdiv, _frem
 447 //      _dadd, _dmul, _dsub, _ddiv, _drem
 448 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {
 449   switch (x->op()) {
 450   case Bytecodes::_fadd:
 451   case Bytecodes::_fmul:
 452   case Bytecodes::_fsub:
 453   case Bytecodes::_fdiv:
 454   case Bytecodes::_dadd:
 455   case Bytecodes::_dmul:
 456   case Bytecodes::_dsub:
 457   case Bytecodes::_ddiv: {
 458     LIRItem left(x->x(), this);
 459     LIRItem right(x->y(), this);
 460     left.load_item();
 461     right.load_item();
 462     rlock_result(x);
 463     arithmetic_op_fpu(x->op(), x->operand(), left.result(), right.result(), x->is_strictfp());
 464   }
 465   break;
 466 
 467   case Bytecodes::_frem:
 468   case Bytecodes::_drem: {
 469     address entry;
 470     switch (x->op()) {
 471     case Bytecodes::_frem:
 472       entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem);
 473       break;
 474     case Bytecodes::_drem:
 475       entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem);
 476       break;
 477     default:
 478       ShouldNotReachHere();
 479     }
 480     LIR_Opr result = call_runtime(x->x(), x->y(), entry, x->type(), NULL);
 481     set_result(x, result);
 482   }
 483   break;
 484 
 485   default: ShouldNotReachHere();
 486   }
 487 }
 488 
 489 
 490 // for  _ladd, _lmul, _lsub, _ldiv, _lrem
 491 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {
 492   switch (x->op()) {
 493   case Bytecodes::_lrem:
 494   case Bytecodes::_lmul:
 495   case Bytecodes::_ldiv: {
 496 
 497     if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) {
 498       LIRItem right(x->y(), this);
 499       right.load_item();
 500 
 501       CodeEmitInfo* info = state_for(x);
 502       LIR_Opr item = right.result();
 503       assert(item->is_register(), "must be");
 504       __ cmp(lir_cond_equal, item, LIR_OprFact::longConst(0));
 505       __ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info));
 506     }
 507 
 508     address entry;
 509     switch (x->op()) {
 510     case Bytecodes::_lrem:
 511       entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);
 512       break; // check if dividend is 0 is done elsewhere
 513     case Bytecodes::_ldiv:
 514       entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);
 515       break; // check if dividend is 0 is done elsewhere
 516     case Bytecodes::_lmul:
 517       entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul);
 518       break;
 519     default:
 520       ShouldNotReachHere();
 521     }
 522 
 523     // order of arguments to runtime call is reversed.
 524     LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL);
 525     set_result(x, result);
 526     break;
 527   }
 528   case Bytecodes::_ladd:
 529   case Bytecodes::_lsub: {
 530     LIRItem left(x->x(), this);
 531     LIRItem right(x->y(), this);
 532     left.load_item();
 533     right.load_item();
 534     rlock_result(x);
 535 
 536     arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);
 537     break;
 538   }
 539   default: ShouldNotReachHere();
 540   }
 541 }
 542 
 543 
 544 // Returns if item is an int constant that can be represented by a simm13
 545 static bool is_simm13(LIR_Opr item) {
 546   if (item->is_constant() && item->type() == T_INT) {
 547     return Assembler::is_simm13(item->as_constant_ptr()->as_jint());
 548   } else {
 549     return false;
 550   }
 551 }
 552 
 553 
 554 // for: _iadd, _imul, _isub, _idiv, _irem
 555 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {
 556   bool is_div_rem = x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem;
 557   LIRItem left(x->x(), this);
 558   LIRItem right(x->y(), this);
 559   // missing test if instr is commutative and if we should swap
 560   right.load_nonconstant();
 561   assert(right.is_constant() || right.is_register(), "wrong state of right");
 562   left.load_item();
 563   rlock_result(x);
 564   if (is_div_rem) {
 565     CodeEmitInfo* info = state_for(x);
 566     LIR_Opr tmp = FrameMap::G1_opr;
 567     if (x->op() == Bytecodes::_irem) {
 568       __ irem(left.result(), right.result(), x->operand(), tmp, info);
 569     } else if (x->op() == Bytecodes::_idiv) {
 570       __ idiv(left.result(), right.result(), x->operand(), tmp, info);
 571     }
 572   } else {
 573     arithmetic_op_int(x->op(), x->operand(), left.result(), right.result(), FrameMap::G1_opr);
 574   }
 575 }
 576 
 577 
 578 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {
 579   ValueTag tag = x->type()->tag();
 580   assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");
 581   switch (tag) {
 582     case floatTag:
 583     case doubleTag:  do_ArithmeticOp_FPU(x);  return;
 584     case longTag:    do_ArithmeticOp_Long(x); return;
 585     case intTag:     do_ArithmeticOp_Int(x);  return;
 586   }
 587   ShouldNotReachHere();
 588 }
 589 
 590 
 591 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr
 592 void LIRGenerator::do_ShiftOp(ShiftOp* x) {
 593   LIRItem value(x->x(), this);
 594   LIRItem count(x->y(), this);
 595   // Long shift destroys count register
 596   if (value.type()->is_long()) {
 597     count.set_destroys_register();
 598   }
 599   value.load_item();
 600   // the old backend doesn't support this
 601   if (count.is_constant() && count.type()->as_IntConstant() != NULL && value.type()->is_int()) {
 602     jint c = count.get_jint_constant() & 0x1f;
 603     assert(c >= 0 && c < 32, "should be small");
 604     count.dont_load_item();
 605   } else {
 606     count.load_item();
 607   }
 608   LIR_Opr reg = rlock_result(x);
 609   shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);
 610 }
 611 
 612 
 613 // _iand, _land, _ior, _lor, _ixor, _lxor
 614 void LIRGenerator::do_LogicOp(LogicOp* x) {
 615   LIRItem left(x->x(), this);
 616   LIRItem right(x->y(), this);
 617 
 618   left.load_item();
 619   right.load_nonconstant();
 620   LIR_Opr reg = rlock_result(x);
 621 
 622   logic_op(x->op(), reg, left.result(), right.result());
 623 }
 624 
 625 
 626 
 627 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg
 628 void LIRGenerator::do_CompareOp(CompareOp* x) {
 629   LIRItem left(x->x(), this);
 630   LIRItem right(x->y(), this);
 631   left.load_item();
 632   right.load_item();
 633   LIR_Opr reg = rlock_result(x);
 634   if (x->x()->type()->is_float_kind()) {
 635     Bytecodes::Code code = x->op();
 636     __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));
 637   } else if (x->x()->type()->tag() == longTag) {
 638     __ lcmp2int(left.result(), right.result(), reg);
 639   } else {
 640     Unimplemented();
 641   }
 642 }
 643 
 644 
 645 void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {
 646   assert(x->number_of_arguments() == 4, "wrong type");
 647   LIRItem obj   (x->argument_at(0), this);  // object
 648   LIRItem offset(x->argument_at(1), this);  // offset of field
 649   LIRItem cmp   (x->argument_at(2), this);  // value to compare with field
 650   LIRItem val   (x->argument_at(3), this);  // replace field with val if matches cmp
 651 
 652   // Use temps to avoid kills
 653   LIR_Opr t1 = FrameMap::G1_opr;
 654   LIR_Opr t2 = FrameMap::G3_opr;
 655   LIR_Opr addr = new_pointer_register();
 656 
 657   // get address of field
 658   obj.load_item();
 659   offset.load_item();
 660   cmp.load_item();
 661   val.load_item();
 662 
 663   __ add(obj.result(), offset.result(), addr);
 664 
 665   if (type == objectType) {  // Write-barrier needed for Object fields.
 666     pre_barrier(addr, LIR_OprFact::illegalOpr /* pre_val */,
 667                 true /* do_load */, false /* patch */, NULL);
 668   }
 669 
 670   if (type == objectType)
 671     __ cas_obj(addr, cmp.result(), val.result(), t1, t2);
 672   else if (type == intType)
 673     __ cas_int(addr, cmp.result(), val.result(), t1, t2);
 674   else if (type == longType)
 675     __ cas_long(addr, cmp.result(), val.result(), t1, t2);
 676   else {
 677     ShouldNotReachHere();
 678   }
 679   // generate conditional move of boolean result
 680   LIR_Opr result = rlock_result(x);
 681   __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),
 682            result, as_BasicType(type));
 683   if (type == objectType) {  // Write-barrier needed for Object fields.
 684     // Precise card mark since could either be object or array
 685     post_barrier(addr, val.result());
 686   }
 687 }
 688 
 689 
 690 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {
 691   switch (x->id()) {
 692     case vmIntrinsics::_dabs:
 693     case vmIntrinsics::_dsqrt: {
 694       assert(x->number_of_arguments() == 1, "wrong type");
 695       LIRItem value(x->argument_at(0), this);
 696       value.load_item();
 697       LIR_Opr dst = rlock_result(x);
 698 
 699       switch (x->id()) {
 700       case vmIntrinsics::_dsqrt: {
 701         __ sqrt(value.result(), dst, LIR_OprFact::illegalOpr);
 702         break;
 703       }
 704       case vmIntrinsics::_dabs: {
 705         __ abs(value.result(), dst, LIR_OprFact::illegalOpr);
 706         break;
 707       }
 708       }
 709       break;
 710     }
 711     case vmIntrinsics::_dlog10: // fall through
 712     case vmIntrinsics::_dlog: // fall through
 713     case vmIntrinsics::_dsin: // fall through
 714     case vmIntrinsics::_dtan: // fall through
 715     case vmIntrinsics::_dcos: // fall through
 716     case vmIntrinsics::_dexp: {
 717       assert(x->number_of_arguments() == 1, "wrong type");
 718 
 719       address runtime_entry = NULL;
 720       switch (x->id()) {
 721       case vmIntrinsics::_dsin:
 722         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
 723         break;
 724       case vmIntrinsics::_dcos:
 725         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
 726         break;
 727       case vmIntrinsics::_dtan:
 728         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
 729         break;
 730       case vmIntrinsics::_dlog:
 731         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);
 732         break;
 733       case vmIntrinsics::_dlog10:
 734         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);
 735         break;
 736       case vmIntrinsics::_dexp:
 737         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);
 738         break;
 739       default:
 740         ShouldNotReachHere();
 741       }
 742 
 743       LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL);
 744       set_result(x, result);
 745       break;
 746     }
 747     case vmIntrinsics::_dpow: {
 748       assert(x->number_of_arguments() == 2, "wrong type");
 749       address runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);
 750       LIR_Opr result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_entry, x->type(), NULL);
 751       set_result(x, result);
 752       break;
 753     }
 754   }
 755 }
 756 
 757 
 758 void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
 759   assert(x->number_of_arguments() == 5, "wrong type");
 760 
 761   // Make all state_for calls early since they can emit code
 762   CodeEmitInfo* info = state_for(x, x->state());
 763 
 764   // Note: spill caller save before setting the item
 765   LIRItem src     (x->argument_at(0), this);
 766   LIRItem src_pos (x->argument_at(1), this);
 767   LIRItem dst     (x->argument_at(2), this);
 768   LIRItem dst_pos (x->argument_at(3), this);
 769   LIRItem length  (x->argument_at(4), this);
 770   // load all values in callee_save_registers, as this makes the
 771   // parameter passing to the fast case simpler
 772   src.load_item_force     (rlock_callee_saved(T_OBJECT));
 773   src_pos.load_item_force (rlock_callee_saved(T_INT));
 774   dst.load_item_force     (rlock_callee_saved(T_OBJECT));
 775   dst_pos.load_item_force (rlock_callee_saved(T_INT));
 776   length.load_item_force  (rlock_callee_saved(T_INT));
 777 
 778   int flags;
 779   ciArrayKlass* expected_type;
 780   arraycopy_helper(x, &flags, &expected_type);
 781 
 782   __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(),
 783                length.result(), rlock_callee_saved(T_INT),
 784                expected_type, flags, info);
 785   set_no_result(x);
 786 }
 787 
 788 void LIRGenerator::do_update_CRC32(Intrinsic* x) {
 789   // Make all state_for calls early since they can emit code
 790   LIR_Opr result = rlock_result(x);
 791   int flags = 0;
 792   switch (x->id()) {
 793     case vmIntrinsics::_updateCRC32: {
 794       LIRItem crc(x->argument_at(0), this);
 795       LIRItem val(x->argument_at(1), this);
 796       // val is destroyed by update_crc32
 797       val.set_destroys_register();
 798       crc.load_item();
 799       val.load_item();
 800       __ update_crc32(crc.result(), val.result(), result);
 801       break;
 802     }
 803     case vmIntrinsics::_updateBytesCRC32:
 804     case vmIntrinsics::_updateByteBufferCRC32: {
 805 
 806       bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);
 807 
 808       LIRItem crc(x->argument_at(0), this);
 809       LIRItem buf(x->argument_at(1), this);
 810       LIRItem off(x->argument_at(2), this);
 811       LIRItem len(x->argument_at(3), this);
 812 
 813       buf.load_item();
 814       off.load_nonconstant();
 815 
 816       LIR_Opr index = off.result();
 817       int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
 818       if(off.result()->is_constant()) {
 819         index = LIR_OprFact::illegalOpr;
 820         offset += off.result()->as_jint();
 821       }
 822 
 823       LIR_Opr base_op = buf.result();
 824 
 825       if (index->is_valid()) {
 826         LIR_Opr tmp = new_register(T_LONG);
 827         __ convert(Bytecodes::_i2l, index, tmp);
 828         index = tmp;
 829         if (index->is_constant()) {
 830           offset += index->as_constant_ptr()->as_jint();
 831           index = LIR_OprFact::illegalOpr;
 832         } else if (index->is_register()) {
 833           LIR_Opr tmp2 = new_register(T_LONG);
 834           LIR_Opr tmp3 = new_register(T_LONG);
 835           __ move(base_op, tmp2);
 836           __ move(index, tmp3);
 837           __ add(tmp2, tmp3, tmp2);
 838           base_op = tmp2;
 839         } else {
 840           ShouldNotReachHere();
 841         }
 842       }
 843 
 844       LIR_Address* a = new LIR_Address(base_op, offset, T_BYTE);
 845 
 846       BasicTypeList signature(3);
 847       signature.append(T_INT);
 848       signature.append(T_ADDRESS);
 849       signature.append(T_INT);
 850       CallingConvention* cc = frame_map()->c_calling_convention(&signature);
 851       const LIR_Opr result_reg = result_register_for(x->type());
 852 
 853       LIR_Opr addr = new_pointer_register();
 854       __ leal(LIR_OprFact::address(a), addr);
 855 
 856       crc.load_item_force(cc->at(0));
 857       __ move(addr, cc->at(1));
 858       len.load_item_force(cc->at(2));
 859 
 860       __ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());
 861       __ move(result_reg, result);
 862 
 863       break;
 864     }
 865     default: {
 866       ShouldNotReachHere();
 867     }
 868   }
 869 }
 870 
 871 void LIRGenerator::do_update_CRC32C(Intrinsic* x) {
 872   // Make all state_for calls early since they can emit code
 873   LIR_Opr result = rlock_result(x);
 874   int flags = 0;
 875   switch (x->id()) {
 876     case vmIntrinsics::_updateBytesCRC32C:
 877     case vmIntrinsics::_updateDirectByteBufferCRC32C: {
 878 
 879       bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32C);
 880       int array_offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
 881 
 882       LIRItem crc(x->argument_at(0), this);
 883       LIRItem buf(x->argument_at(1), this);
 884       LIRItem off(x->argument_at(2), this);
 885       LIRItem end(x->argument_at(3), this);
 886 
 887       buf.load_item();
 888       off.load_nonconstant();
 889       end.load_nonconstant();
 890 
 891       // len = end - off
 892       LIR_Opr len  = end.result();
 893       LIR_Opr tmpA = new_register(T_INT);
 894       LIR_Opr tmpB = new_register(T_INT);
 895       __ move(end.result(), tmpA);
 896       __ move(off.result(), tmpB);
 897       __ sub(tmpA, tmpB, tmpA);
 898       len = tmpA;
 899 
 900       LIR_Opr index = off.result();
 901 
 902       if(off.result()->is_constant()) {
 903         index = LIR_OprFact::illegalOpr;
 904         array_offset += off.result()->as_jint();
 905       }
 906 
 907       LIR_Opr base_op = buf.result();
 908 
 909       if (index->is_valid()) {
 910         LIR_Opr tmp = new_register(T_LONG);
 911         __ convert(Bytecodes::_i2l, index, tmp);
 912         index = tmp;
 913         if (index->is_constant()) {
 914           array_offset += index->as_constant_ptr()->as_jint();
 915           index = LIR_OprFact::illegalOpr;
 916         } else if (index->is_register()) {
 917           LIR_Opr tmp2 = new_register(T_LONG);
 918           LIR_Opr tmp3 = new_register(T_LONG);
 919           __ move(base_op, tmp2);
 920           __ move(index, tmp3);
 921           __ add(tmp2, tmp3, tmp2);
 922           base_op = tmp2;
 923         } else {
 924           ShouldNotReachHere();
 925         }
 926       }
 927 
 928       LIR_Address* a = new LIR_Address(base_op, array_offset, T_BYTE);
 929 
 930       BasicTypeList signature(3);
 931       signature.append(T_INT);
 932       signature.append(T_ADDRESS);
 933       signature.append(T_INT);
 934       CallingConvention* cc = frame_map()->c_calling_convention(&signature);
 935       const LIR_Opr result_reg = result_register_for(x->type());
 936 
 937       LIR_Opr addr = new_pointer_register();
 938       __ leal(LIR_OprFact::address(a), addr);
 939 
 940       crc.load_item_force(cc->at(0));
 941       __ move(addr, cc->at(1));
 942       __ move(len, cc->at(2));
 943 
 944       __ call_runtime_leaf(StubRoutines::updateBytesCRC32C(), getThreadTemp(), result_reg, cc->args());
 945       __ move(result_reg, result);
 946 
 947       break;
 948     }
 949     default: {
 950       ShouldNotReachHere();
 951     }
 952   }
 953 }
 954 
 955 void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {
 956   fatal("FMA intrinsic is not implemented on this platform");
 957 }
 958 
 959 void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) {
 960   fatal("vectorizedMismatch intrinsic is not implemented on this platform");
 961 }
 962 
 963 // _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f
 964 // _i2b, _i2c, _i2s
 965 void LIRGenerator::do_Convert(Convert* x) {
 966 
 967   switch (x->op()) {
 968     case Bytecodes::_f2l:
 969     case Bytecodes::_d2l:
 970     case Bytecodes::_d2i:
 971     case Bytecodes::_l2f:
 972     case Bytecodes::_l2d: {
 973 
 974       address entry;
 975       switch (x->op()) {
 976       case Bytecodes::_l2f:
 977         entry = CAST_FROM_FN_PTR(address, SharedRuntime::l2f);
 978         break;
 979       case Bytecodes::_l2d:
 980         entry = CAST_FROM_FN_PTR(address, SharedRuntime::l2d);
 981         break;
 982       case Bytecodes::_f2l:
 983         entry = CAST_FROM_FN_PTR(address, SharedRuntime::f2l);
 984         break;
 985       case Bytecodes::_d2l:
 986         entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2l);
 987         break;
 988       case Bytecodes::_d2i:
 989         entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2i);
 990         break;
 991       default:
 992         ShouldNotReachHere();
 993       }
 994       LIR_Opr result = call_runtime(x->value(), entry, x->type(), NULL);
 995       set_result(x, result);
 996       break;
 997     }
 998 
 999     case Bytecodes::_i2f:
1000     case Bytecodes::_i2d: {
1001       LIRItem value(x->value(), this);
1002 
1003       LIR_Opr reg = rlock_result(x);
1004       // To convert an int to double, we need to load the 32-bit int
1005       // from memory into a single precision floating point register
1006       // (even numbered). Then the sparc fitod instruction takes care
1007       // of the conversion. This is a bit ugly, but is the best way to
1008       // get the int value in a single precision floating point register
1009       value.load_item();
1010       LIR_Opr tmp = force_to_spill(value.result(), T_FLOAT);
1011       __ convert(x->op(), tmp, reg);
1012       break;
1013     }
1014     break;
1015 
1016     case Bytecodes::_i2l:
1017     case Bytecodes::_i2b:
1018     case Bytecodes::_i2c:
1019     case Bytecodes::_i2s:
1020     case Bytecodes::_l2i:
1021     case Bytecodes::_f2d:
1022     case Bytecodes::_d2f: { // inline code
1023       LIRItem value(x->value(), this);
1024 
1025       value.load_item();
1026       LIR_Opr reg = rlock_result(x);
1027       __ convert(x->op(), value.result(), reg, false);
1028     }
1029     break;
1030 
1031     case Bytecodes::_f2i: {
1032       LIRItem value (x->value(), this);
1033       value.set_destroys_register();
1034       value.load_item();
1035       LIR_Opr reg = rlock_result(x);
1036       set_vreg_flag(reg, must_start_in_memory);
1037       __ convert(x->op(), value.result(), reg, false);
1038     }
1039     break;
1040 
1041     default: ShouldNotReachHere();
1042   }
1043 }
1044 
1045 
1046 void LIRGenerator::do_NewInstance(NewInstance* x) {
1047   print_if_not_loaded(x);
1048 
1049   // This instruction can be deoptimized in the slow path : use
1050   // O0 as result register.
1051   const LIR_Opr reg = result_register_for(x->type());
1052 
1053   CodeEmitInfo* info = state_for(x, x->state());
1054   LIR_Opr tmp1 = FrameMap::G1_oop_opr;
1055   LIR_Opr tmp2 = FrameMap::G3_oop_opr;
1056   LIR_Opr tmp3 = FrameMap::G4_oop_opr;
1057   LIR_Opr tmp4 = FrameMap::O1_oop_opr;
1058   LIR_Opr klass_reg = FrameMap::G5_metadata_opr;
1059   new_instance(reg, x->klass(), x->is_unresolved(), tmp1, tmp2, tmp3, tmp4, klass_reg, info);
1060   LIR_Opr result = rlock_result(x);
1061   __ move(reg, result);
1062 }
1063 
1064 
1065 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
1066   // Evaluate state_for early since it may emit code
1067   CodeEmitInfo* info = state_for(x, x->state());
1068 
1069   LIRItem length(x->length(), this);
1070   length.load_item();
1071 
1072   LIR_Opr reg = result_register_for(x->type());
1073   LIR_Opr tmp1 = FrameMap::G1_oop_opr;
1074   LIR_Opr tmp2 = FrameMap::G3_oop_opr;
1075   LIR_Opr tmp3 = FrameMap::G4_oop_opr;
1076   LIR_Opr tmp4 = FrameMap::O1_oop_opr;
1077   LIR_Opr klass_reg = FrameMap::G5_metadata_opr;
1078   LIR_Opr len = length.result();
1079   BasicType elem_type = x->elt_type();
1080 
1081   __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
1082 
1083   CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
1084   __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);
1085 
1086   LIR_Opr result = rlock_result(x);
1087   __ move(reg, result);
1088 }
1089 
1090 
1091 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
1092   // Evaluate state_for early since it may emit code.
1093   CodeEmitInfo* info = state_for(x, x->state());
1094   // in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction
1095   // and therefore provide the state before the parameters have been consumed
1096   CodeEmitInfo* patching_info = NULL;
1097   if (!x->klass()->is_loaded() || PatchALot) {
1098     patching_info = state_for(x, x->state_before());
1099   }
1100 
1101   LIRItem length(x->length(), this);
1102   length.load_item();
1103 
1104   const LIR_Opr reg = result_register_for(x->type());
1105   LIR_Opr tmp1 = FrameMap::G1_oop_opr;
1106   LIR_Opr tmp2 = FrameMap::G3_oop_opr;
1107   LIR_Opr tmp3 = FrameMap::G4_oop_opr;
1108   LIR_Opr tmp4 = FrameMap::O1_oop_opr;
1109   LIR_Opr klass_reg = FrameMap::G5_metadata_opr;
1110   LIR_Opr len = length.result();
1111 
1112   CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
1113   ciMetadata* obj = ciObjArrayKlass::make(x->klass());
1114   if (obj == ciEnv::unloaded_ciobjarrayklass()) {
1115     BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
1116   }
1117   klass2reg_with_patching(klass_reg, obj, patching_info);
1118   __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);
1119 
1120   LIR_Opr result = rlock_result(x);
1121   __ move(reg, result);
1122 }
1123 
1124 
1125 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
1126   Values* dims = x->dims();
1127   int i = dims->length();
1128   LIRItemList* items = new LIRItemList(i, i, NULL);
1129   while (i-- > 0) {
1130     LIRItem* size = new LIRItem(dims->at(i), this);
1131     items->at_put(i, size);
1132   }
1133 
1134   // Evaluate state_for early since it may emit code.
1135   CodeEmitInfo* patching_info = NULL;
1136   if (!x->klass()->is_loaded() || PatchALot) {
1137     patching_info = state_for(x, x->state_before());
1138 
1139     // Cannot re-use same xhandlers for multiple CodeEmitInfos, so
1140     // clone all handlers (NOTE: Usually this is handled transparently
1141     // by the CodeEmitInfo cloning logic in CodeStub constructors but
1142     // is done explicitly here because a stub isn't being used).
1143     x->set_exception_handlers(new XHandlers(x->exception_handlers()));
1144   }
1145   CodeEmitInfo* info = state_for(x, x->state());
1146 
1147   i = dims->length();
1148   while (i-- > 0) {
1149     LIRItem* size = items->at(i);
1150     size->load_item();
1151     store_stack_parameter (size->result(),
1152                            in_ByteSize(STACK_BIAS +
1153                                        frame::memory_parameter_word_sp_offset * wordSize +
1154                                        i * sizeof(jint)));
1155   }
1156 
1157   // This instruction can be deoptimized in the slow path : use
1158   // O0 as result register.
1159   const LIR_Opr klass_reg = FrameMap::O0_metadata_opr;
1160   klass2reg_with_patching(klass_reg, x->klass(), patching_info);
1161   LIR_Opr rank = FrameMap::O1_opr;
1162   __ move(LIR_OprFact::intConst(x->rank()), rank);
1163   LIR_Opr varargs = FrameMap::as_pointer_opr(O2);
1164   int offset_from_sp = (frame::memory_parameter_word_sp_offset * wordSize) + STACK_BIAS;
1165   __ add(FrameMap::SP_opr,
1166          LIR_OprFact::intptrConst(offset_from_sp),
1167          varargs);
1168   LIR_OprList* args = new LIR_OprList(3);
1169   args->append(klass_reg);
1170   args->append(rank);
1171   args->append(varargs);
1172   const LIR_Opr reg = result_register_for(x->type());
1173   __ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),
1174                   LIR_OprFact::illegalOpr,
1175                   reg, args, info);
1176 
1177   LIR_Opr result = rlock_result(x);
1178   __ move(reg, result);
1179 }
1180 
1181 
1182 void LIRGenerator::do_BlockBegin(BlockBegin* x) {
1183 }
1184 
1185 
1186 void LIRGenerator::do_CheckCast(CheckCast* x) {
1187   LIRItem obj(x->obj(), this);
1188   CodeEmitInfo* patching_info = NULL;
1189   if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) {
1190     // must do this before locking the destination register as an oop register,
1191     // and before the obj is loaded (so x->obj()->item() is valid for creating a debug info location)
1192     patching_info = state_for(x, x->state_before());
1193   }
1194   obj.load_item();
1195   LIR_Opr out_reg = rlock_result(x);
1196   CodeStub* stub;
1197   CodeEmitInfo* info_for_exception = state_for(x);
1198 
1199   if (x->is_incompatible_class_change_check()) {
1200     assert(patching_info == NULL, "can't patch this");
1201     stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);
1202   } else {
1203     stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);
1204   }
1205   LIR_Opr tmp1 = FrameMap::G1_oop_opr;
1206   LIR_Opr tmp2 = FrameMap::G3_oop_opr;
1207   LIR_Opr tmp3 = FrameMap::G4_oop_opr;
1208   __ checkcast(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3,
1209                x->direct_compare(), info_for_exception, patching_info, stub,
1210                x->profiled_method(), x->profiled_bci());
1211 }
1212 
1213 
1214 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
1215   LIRItem obj(x->obj(), this);
1216   CodeEmitInfo* patching_info = NULL;
1217   if (!x->klass()->is_loaded() || PatchALot) {
1218     patching_info = state_for(x, x->state_before());
1219   }
1220   // ensure the result register is not the input register because the result is initialized before the patching safepoint
1221   obj.load_item();
1222   LIR_Opr out_reg = rlock_result(x);
1223   LIR_Opr tmp1 = FrameMap::G1_oop_opr;
1224   LIR_Opr tmp2 = FrameMap::G3_oop_opr;
1225   LIR_Opr tmp3 = FrameMap::G4_oop_opr;
1226   __ instanceof(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3,
1227                 x->direct_compare(), patching_info,
1228                 x->profiled_method(), x->profiled_bci());
1229 }
1230 
1231 
1232 void LIRGenerator::do_If(If* x) {
1233   assert(x->number_of_sux() == 2, "inconsistency");
1234   ValueTag tag = x->x()->type()->tag();
1235   LIRItem xitem(x->x(), this);
1236   LIRItem yitem(x->y(), this);
1237   LIRItem* xin = &xitem;
1238   LIRItem* yin = &yitem;
1239   If::Condition cond = x->cond();
1240 
1241   if (tag == longTag) {
1242     // for longs, only conditions "eql", "neq", "lss", "geq" are valid;
1243     // mirror for other conditions
1244     if (cond == If::gtr || cond == If::leq) {
1245       // swap inputs
1246       cond = Instruction::mirror(cond);
1247       xin = &yitem;
1248       yin = &xitem;
1249     }
1250     xin->set_destroys_register();
1251   }
1252 
1253   LIR_Opr left = LIR_OprFact::illegalOpr;
1254   LIR_Opr right = LIR_OprFact::illegalOpr;
1255 
1256   xin->load_item();
1257   left = xin->result();
1258 
1259   if (is_simm13(yin->result())) {
1260     // inline int constants which are small enough to be immediate operands
1261     right = LIR_OprFact::value_type(yin->value()->type());
1262   } else if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 &&
1263              (cond == If::eql || cond == If::neq)) {
1264     // inline long zero
1265     right = LIR_OprFact::value_type(yin->value()->type());
1266   } else if (tag == objectTag && yin->is_constant() && (yin->get_jobject_constant()->is_null_object())) {
1267     right = LIR_OprFact::value_type(yin->value()->type());
1268   } else {
1269     yin->load_item();
1270     right = yin->result();
1271   }
1272   set_no_result(x);
1273 
1274   // add safepoint before generating condition code so it can be recomputed
1275   if (x->is_safepoint()) {
1276     // increment backedge counter if needed
1277     increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());
1278     __ safepoint(new_register(T_INT), state_for(x, x->state_before()));
1279   }
1280 
1281   __ cmp(lir_cond(cond), left, right);
1282   // Generate branch profiling. Profiling code doesn't kill flags.
1283   profile_branch(x, cond);
1284   move_to_phi(x->state());
1285   if (x->x()->type()->is_float_kind()) {
1286     __ branch(lir_cond(cond), right->type(), x->tsux(), x->usux());
1287   } else {
1288     __ branch(lir_cond(cond), right->type(), x->tsux());
1289   }
1290   assert(x->default_sux() == x->fsux(), "wrong destination above");
1291   __ jump(x->default_sux());
1292 }
1293 
1294 
1295 LIR_Opr LIRGenerator::getThreadPointer() {
1296   return FrameMap::as_pointer_opr(G2);
1297 }
1298 
1299 
1300 void LIRGenerator::trace_block_entry(BlockBegin* block) {
1301   __ move(LIR_OprFact::intConst(block->block_id()), FrameMap::O0_opr);
1302   LIR_OprList* args = new LIR_OprList(1);
1303   args->append(FrameMap::O0_opr);
1304   address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);
1305   __ call_runtime_leaf(func, rlock_callee_saved(T_INT), LIR_OprFact::illegalOpr, args);
1306 }
1307 
1308 
1309 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,
1310                                         CodeEmitInfo* info) {
1311   __ store(value, address, info);
1312 }
1313 
1314 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,
1315                                        CodeEmitInfo* info) {
1316   __ load(address, result, info);
1317 }
1318 
1319 
1320 void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data,
1321                                      BasicType type, bool is_volatile) {
1322   LIR_Opr base_op = src;
1323   LIR_Opr index_op = offset;
1324 
1325   bool is_obj = (type == T_ARRAY || type == T_OBJECT);
1326     {
1327       if (type == T_BOOLEAN) {
1328         type = T_BYTE;
1329       }
1330       LIR_Address* addr;
1331       if (type == T_ARRAY || type == T_OBJECT) {
1332         LIR_Opr tmp = new_pointer_register();
1333         __ add(base_op, index_op, tmp);
1334         addr = new LIR_Address(tmp, type);
1335       } else {
1336         addr = new LIR_Address(base_op, index_op, type);
1337       }
1338 
1339       if (is_obj) {
1340         pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,
1341                     true /* do_load */, false /* patch */, NULL);
1342         // _bs->c1_write_barrier_pre(this, LIR_OprFact::address(addr));
1343       }
1344       __ move(data, addr);
1345       if (is_obj) {
1346         // This address is precise
1347         post_barrier(LIR_OprFact::address(addr), data);
1348       }
1349     }
1350 }
1351 
1352 
1353 void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset,
1354                                      BasicType type, bool is_volatile) {
1355     {
1356     LIR_Address* addr = new LIR_Address(src, offset, type);
1357     __ load(addr, dst);
1358   }
1359 }
1360 
1361 void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {
1362   BasicType type = x->basic_type();
1363   LIRItem src(x->object(), this);
1364   LIRItem off(x->offset(), this);
1365   LIRItem value(x->value(), this);
1366 
1367   src.load_item();
1368   value.load_item();
1369   off.load_nonconstant();
1370 
1371   LIR_Opr dst = rlock_result(x, type);
1372   LIR_Opr data = value.result();
1373   bool is_obj = (type == T_ARRAY || type == T_OBJECT);
1374   LIR_Opr offset = off.result();
1375 
1376   // Because we want a 2-arg form of xchg
1377   __ move(data, dst);
1378 
1379   assert (!x->is_add() && (type == T_INT || (is_obj && UseCompressedOops)), "unexpected type"); 
1380   LIR_Address* addr;
1381   if (offset->is_constant()) {
1382 
1383     jlong l = offset->as_jlong();
1384     assert((jlong)((jint)l) == l, "offset too large for constant");
1385     jint c = (jint)l;
1386     addr = new LIR_Address(src.result(), c, type);
1387   } else {
1388     addr = new LIR_Address(src.result(), offset, type);
1389   }
1390 
1391   LIR_Opr tmp = LIR_OprFact::illegalOpr;
1392   LIR_Opr ptr = LIR_OprFact::illegalOpr;
1393 
1394   if (is_obj) {
1395     // Do the pre-write barrier, if any.
1396     // barriers on sparc don't work with a base + index address
1397     tmp = FrameMap::G3_opr;
1398     ptr = new_pointer_register();
1399     __ add(src.result(), off.result(), ptr);
1400     pre_barrier(ptr, LIR_OprFact::illegalOpr /* pre_val */,
1401                 true /* do_load */, false /* patch */, NULL);
1402   }
1403   __ xchg(LIR_OprFact::address(addr), dst, dst, tmp);
1404   if (is_obj) {
1405     // Seems to be a precise address
1406     post_barrier(ptr, data);
1407   }
1408 }