1 /*
   2  * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
   4  * Copyright (c) 2015-2018, Azul Systems, Inc. All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  *
  25  */
  26 
  27 #include "precompiled.hpp"
  28 #include "asm/macroAssembler.inline.hpp"
  29 #include "c1/c1_Compilation.hpp"
  30 #include "c1/c1_FrameMap.hpp"
  31 #include "c1/c1_Instruction.hpp"
  32 #include "c1/c1_LIRAssembler.hpp"
  33 #include "c1/c1_LIRGenerator.hpp"
  34 #include "c1/c1_Runtime1.hpp"
  35 #include "c1/c1_ValueStack.hpp"
  36 #include "ci/ciArray.hpp"
  37 #include "ci/ciObjArrayKlass.hpp"
  38 #include "ci/ciTypeArrayKlass.hpp"
  39 #include "runtime/sharedRuntime.hpp"
  40 #include "runtime/stubRoutines.hpp"
  41 #include "vmreg_aarch32.inline.hpp"
  42 #include "vm_version_aarch32.hpp"
  43 
  44 #ifdef ASSERT
  45 #define __ gen()->lir(__FILE__, __LINE__)->
  46 #else
  47 #define __ gen()->lir()->
  48 #endif
  49 
  50 // Item will be loaded into a byte register; Intel only
  51 void LIRItem::load_byte_item() {
  52   load_item();
  53 }
  54 
  55 
  56 void LIRItem::load_nonconstant() {
  57   LIR_Opr r = value()->operand();
  58   if (r->is_constant()) {
  59     _result = r;
  60   } else {
  61     load_item();
  62   }
  63 }
  64 
  65 //--------------------------------------------------------------
  66 //               LIRGenerator
  67 //--------------------------------------------------------------
  68 
  69 
  70 LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::r0_oop_opr; }
  71 LIR_Opr LIRGenerator::exceptionPcOpr()  { return FrameMap::r3_opr; }
  72 LIR_Opr LIRGenerator::divInOpr()        { Unimplemented(); return LIR_OprFact::illegalOpr; }
  73 LIR_Opr LIRGenerator::divOutOpr()       { Unimplemented(); return LIR_OprFact::illegalOpr; }
  74 LIR_Opr LIRGenerator::remOutOpr()       { Unimplemented(); return LIR_OprFact::illegalOpr; }
  75 LIR_Opr LIRGenerator::shiftCountOpr()   { Unimplemented(); return LIR_OprFact::illegalOpr; }
  76 LIR_Opr LIRGenerator::syncLockOpr()     { return new_register(T_INT); }
  77 LIR_Opr LIRGenerator::syncTempOpr()     { return FrameMap::r0_opr; }
  78 LIR_Opr LIRGenerator::getThreadTemp()   { return LIR_OprFact::illegalOpr; }
  79 
  80 
  81 LIR_Opr LIRGenerator::java_result_register_for(ValueType* type, bool callee) {
  82   LIR_Opr opr;
  83   switch (type->tag()) {
  84     case floatTag:
  85         if(hasFPU()) {
  86             opr = FrameMap::fpu0_float_opr;  break;;
  87         }
  88     case doubleTag:
  89         if(hasFPU()) {
  90             opr = FrameMap::fpu0_double_opr;  break;
  91         }
  92     default: opr = result_register_for(type, callee);
  93   }
  94   return opr;
  95 }
  96 LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {
  97   LIR_Opr opr;
  98   switch (type->tag()) {
  99     case floatTag:
 100 #ifdef HARD_FLOAT_CC
 101         opr = FrameMap::fpu0_float_opr;  break;
 102 #endif
 103     case intTag:     opr = FrameMap::r0_opr;          break;
 104     case objectTag:  opr = FrameMap::r0_oop_opr;      break;
 105     case doubleTag:
 106 #ifdef HARD_FLOAT_CC
 107         opr = FrameMap::fpu0_double_opr;  break;
 108 #endif
 109     case longTag:    opr = FrameMap::long0_opr;        break;
 110 
 111     case addressTag:
 112     default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
 113   }
 114 #ifndef HARD_FLOAT_CC
 115   assert(type->is_float_kind() || opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
 116 #else
 117   assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
 118 #endif
 119   return opr;
 120 }
 121 
 122 
 123 LIR_Opr LIRGenerator::rlock_byte(BasicType type) {
 124   LIR_Opr reg = new_register(T_INT);
 125   set_vreg_flag(reg, LIRGenerator::byte_reg);
 126   return reg;
 127 }
 128 
 129 
 130 //--------- loading items into registers --------------------------------
 131 
 132 
 133 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
 134   if (v->type()->as_IntConstant() != NULL) {
 135     return v->type()->as_IntConstant()->value() == 0L;
 136   } else if (v->type()->as_LongConstant() != NULL) {
 137     return v->type()->as_LongConstant()->value() == 0L;
 138   } else if (v->type()->as_ObjectConstant() != NULL) {
 139     return v->type()->as_ObjectConstant()->value()->is_null_object();
 140   } else {
 141     return false;
 142   }
 143 }
 144 
 145 bool LIRGenerator::can_inline_as_constant(Value v) const {
 146   if (v->type()->as_IntConstant() != NULL) {
 147     return Assembler::operand_valid_for_add_sub_immediate(v->type()->as_IntConstant()->value());
 148   } else if (v->type()->as_LongConstant() != NULL) {
 149     return Assembler::operand_valid_for_add_sub_immediate(v->type()->as_LongConstant()->value());
 150   } else if (v->type()->as_ObjectConstant() != NULL) {
 151     return v->type()->as_ObjectConstant()->value()->is_null_object();
 152   } else {
 153     return false;
 154   }
 155 }
 156 
 157 
 158 bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {
 159   switch (c->type()) {
 160   case T_BOOLEAN:
 161   case T_CHAR:
 162   case T_BYTE:
 163   case T_SHORT:
 164   case T_INT:
 165     return Assembler::operand_valid_for_add_sub_immediate(c->as_jint());
 166   case T_LONG:
 167     return Assembler::operand_valid_for_add_sub_immediate(c->as_jlong());
 168   case T_OBJECT:
 169     return c->as_jobject() == (jobject) NULL;
 170   case T_METADATA:
 171     return c->as_metadata() == (Metadata*) NULL;
 172   case T_FLOAT:
 173     if( hasFPU()) {
 174         return Assembler::operand_valid_for_float_immediate(c->as_jfloat());
 175     } else {
 176        return Assembler::operand_valid_for_add_sub_immediate(c->as_jint());
 177     }
 178   case T_DOUBLE:
 179     if( hasFPU()) {
 180         return Assembler::operand_valid_for_float_immediate(c->as_jdouble());
 181     } else {
 182         return Assembler::operand_valid_for_add_sub_immediate(c->as_jlong());
 183     }
 184   }
 185   return false;
 186 }
 187 
 188 LIR_Opr LIRGenerator::safepoint_poll_register() {
 189   return LIR_OprFact::illegalOpr;
 190 }
 191 
 192 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
 193                                             int shift, int disp, BasicType type) {
 194   const Address::InsnDataType insn_type = Address::toInsnDataType(type);
 195   assert(base->is_register(), "must be");
 196 
 197   // accumulate fixed displacements
 198   if (index->is_constant()) {
 199     assert(index->as_constant_ptr()->type() == T_INT, "assumed");
 200     disp += index->as_constant_ptr()->as_jint() << shift;
 201     index = LIR_OprFact::illegalOpr;
 202     shift = 0;
 203   }
 204 
 205   // aarch32 cannot handle natively both index and offset at the same time
 206   // need to calculate effective value
 207   if (index->is_register()) {
 208     if ((disp != 0) &&
 209         Address::shift_ok_for_index(lsl(shift), insn_type) &&
 210         Assembler::operand_valid_for_add_sub_immediate(disp)) {
 211       // add tmp, base, disp
 212       // ldr r, [tmp, index, LSL #shift ]
 213       LIR_Opr tmp = new_pointer_register();
 214       __ add(base, LIR_OprFact::intptrConst(disp), tmp);
 215       base = tmp;
 216       disp = 0;
 217     } else {
 218       assert(shift <= (int) LIR_Address::times_8, "no large shift could be here");
 219       // add tmp, base, index, LSL #shift
 220       // ...
 221       // ldr r, [tmp, ...]
 222       LIR_Opr tmp = new_pointer_register();
 223       __ leal(LIR_OprFact::address(new LIR_Address(base, index, (LIR_Address::Scale) shift, 0, type)), tmp);
 224       base = tmp;
 225       index = LIR_OprFact::illegalOpr;
 226       shift = 0;
 227     }
 228   }
 229 
 230   assert(!index->is_register() || (disp == 0), "should be");
 231 
 232   if (!Address::offset_ok_for_immed(disp, insn_type)) {
 233     assert(!index->is_valid(), "should be");
 234     // here index should be illegal so we can replace it with the displacement
 235     // loaded into a register
 236     // mov tmp, disp
 237     // ldr r, [base, tmp]
 238     index = new_pointer_register();
 239     __ move(LIR_OprFact::intptrConst(disp), index);
 240     disp = 0;
 241   }
 242 
 243   assert(Address::offset_ok_for_immed(disp, Address::toInsnDataType(type)), "must be");
 244   return new LIR_Address(base, index, (LIR_Address::Scale) shift, disp, type);
 245 }
 246 
 247 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,
 248                                               BasicType type) {
 249   int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type);
 250   int elem_size = type2aelembytes(type);
 251   int shift = exact_log2(elem_size);
 252 
 253   LIR_Address* addr = generate_address(array_opr, index_opr, shift, offset_in_bytes, type);
 254 
 255   return addr;
 256 }
 257 
 258 LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {
 259   LIR_Opr r;
 260   if (type == T_LONG) {
 261     r = LIR_OprFact::longConst(x);
 262     if (!Assembler::operand_valid_for_logical_immediate(false, x)) {
 263       LIR_Opr tmp = new_register(type);
 264       __ move(r, tmp);
 265       return tmp;
 266     }
 267   } else if (type == T_INT) {
 268     r = LIR_OprFact::intConst(x);
 269     if (!Assembler::operand_valid_for_logical_immediate(true, x)) {
 270       // This is all rather nasty.  We don't know whether our constant
 271       // is required for a logical or an arithmetic operation, wo we
 272       // don't know what the range of valid values is!!
 273       LIR_Opr tmp = new_register(type);
 274       __ move(r, tmp);
 275       return tmp;
 276     }
 277   } else {
 278     ShouldNotReachHere();
 279     r = LIR_OprFact::illegalOpr; // unreachable
 280   }
 281   return r;
 282 }
 283 
 284 
 285 
 286 void LIRGenerator::increment_counter(address counter, BasicType type, int step) {
 287   LIR_Opr pointer = new_pointer_register();
 288   __ move(LIR_OprFact::intptrConst(counter), pointer);
 289   LIR_Address* addr = new LIR_Address(pointer, type);
 290   increment_counter(addr, step);
 291 }
 292 
 293 
 294 void LIRGenerator::increment_counter(LIR_Address* addr, int step) {
 295   LIR_Opr imm = NULL;
 296   switch(addr->type()) {
 297   case T_INT:
 298     imm = LIR_OprFact::intConst(step);
 299     break;
 300   case T_LONG:
 301     imm = LIR_OprFact::longConst(step);
 302     break;
 303   default:
 304     ShouldNotReachHere();
 305   }
 306   LIR_Opr reg = new_register(addr->type());
 307   __ load(addr, reg);
 308   __ add(reg, imm, reg);
 309   __ store(reg, addr);
 310 }
 311 
 312 void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {
 313   LIR_Opr reg = new_register(T_INT);
 314   __ load(generate_address(base, disp, T_INT), reg, info);
 315   __ cmp(condition, reg, LIR_OprFact::intConst(c));
 316 }
 317 
 318 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {
 319   LIR_Opr reg1 = new_register(T_INT);
 320   __ load(generate_address(base, disp, type), reg1, info);
 321   __ cmp(condition, reg, reg1);
 322 }
 323 
 324 
 325 bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) {
 326 
 327   if (is_power_of_2(c - 1)) {
 328     __ shift_left(left, exact_log2(c - 1), tmp);
 329     __ add(tmp, left, result);
 330     return true;
 331   } else if (is_power_of_2(c + 1)) {
 332     __ shift_left(left, exact_log2(c + 1), tmp);
 333     __ sub(tmp, left, result);
 334     return true;
 335   } else {
 336     return false;
 337   }
 338 }
 339 
 340 void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {
 341   BasicType type = item->type();
 342   __ store(item, new LIR_Address(FrameMap::sp_opr, in_bytes(offset_from_sp), type));
 343 }
 344 
 345 void LIRGenerator::array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci) {
 346     LIR_Opr tmp1 = new_register(objectType);
 347     LIR_Opr tmp2 = new_register(objectType);
 348     LIR_Opr tmp3 = new_register(objectType);
 349     __ store_check(value, array, tmp1, tmp2, tmp3, store_check_info, profiled_method, profiled_bci);
 350 }
 351 
 352 //----------------------------------------------------------------------
 353 //             visitor functions
 354 //----------------------------------------------------------------------
 355 
 356 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
 357   assert(x->is_pinned(),"");
 358   LIRItem obj(x->obj(), this);
 359   obj.load_item();
 360 
 361   set_no_result(x);
 362 
 363   // "lock" stores the address of the monitor stack slot, so this is not an oop
 364   LIR_Opr lock = new_register(T_INT);
 365   // Need a scratch register for biased locking
 366   LIR_Opr scratch = LIR_OprFact::illegalOpr;
 367   if (UseBiasedLocking) {
 368     scratch = new_register(T_INT);
 369   }
 370 
 371   CodeEmitInfo* info_for_exception = NULL;
 372   if (x->needs_null_check()) {
 373     info_for_exception = state_for(x);
 374   }
 375   // this CodeEmitInfo must not have the xhandlers because here the
 376   // object is already locked (xhandlers expect object to be unlocked)
 377   CodeEmitInfo* info = state_for(x, x->state(), true);
 378   monitor_enter(obj.result(), lock, syncTempOpr(), scratch,
 379                         x->monitor_no(), info_for_exception, info);
 380 }
 381 
 382 
 383 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
 384   assert(x->is_pinned(),"");
 385 
 386   LIRItem obj(x->obj(), this);
 387   obj.dont_load_item();
 388 
 389   LIR_Opr lock = new_register(T_INT);
 390   LIR_Opr obj_temp = new_register(T_INT);
 391   set_no_result(x);
 392   monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());
 393 }
 394 
 395 
 396 void LIRGenerator::do_NegateOp(NegateOp* x) {
 397 #ifdef __SOFTFP__
 398   if(x->x()->type()->is_float_kind() && !(hasFPU())) {
 399       address entry;
 400       if (x->x()->type()->is_float()) {
 401           entry = CAST_FROM_FN_PTR(address, SharedRuntime::fneg);
 402       } else {
 403           entry = CAST_FROM_FN_PTR(address, SharedRuntime::dneg);
 404       }
 405       LIR_Opr result = call_runtime(x->x(), entry, x->type(), NULL);
 406       set_result(x, result);
 407   } else
 408 #endif
 409   {
 410   LIRItem from(x->x(), this);
 411   from.load_item();
 412   LIR_Opr result = rlock_result(x);
 413   __ negate (from.result(), result);
 414   }
 415 }
 416 
 417 // for  _fadd, _fmul, _fsub, _fdiv, _frem
 418 //      _dadd, _dmul, _dsub, _ddiv, _drem
 419 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {
 420 
 421   if (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem) {
 422     address entry;
 423     if (x->op() == Bytecodes::_frem) {
 424       entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem);
 425     } else {
 426       entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem);
 427     }
 428     LIR_Opr result = call_runtime(x->x(), x->y(), entry, x->type(), NULL);
 429     set_result(x, result);
 430 
 431     return;
 432   }
 433 
 434   if(hasFPU()) {
 435         LIRItem left(x->x(),  this);
 436         LIRItem right(x->y(), this);
 437         LIRItem* left_arg  = &left;
 438         LIRItem* right_arg = &right;
 439 
 440         // Always load right hand side.
 441         right.load_item();
 442 
 443         if (!left.is_register())
 444           left.load_item();
 445 
 446         LIR_Opr reg = rlock(x);
 447         LIR_Opr tmp = LIR_OprFact::illegalOpr;
 448         if (x->is_strictfp() && (x->op() == Bytecodes::_dmul || x->op() == Bytecodes::_ddiv)) {
 449           tmp = new_register(T_DOUBLE);
 450         }
 451 
 452         arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), NULL);
 453 
 454         set_result(x, round_item(reg));
 455   } else {
 456 #ifdef __SOFTFP__
 457     address entry;
 458 
 459     switch (x->op()) {
 460       case Bytecodes::_fmul:
 461         entry = CAST_FROM_FN_PTR(address, SharedRuntime::fmul);
 462         break;
 463       case Bytecodes::_dmul:
 464         entry = CAST_FROM_FN_PTR(address, SharedRuntime::dmul);
 465         break;
 466       case Bytecodes::_fdiv:
 467         entry = CAST_FROM_FN_PTR(address, SharedRuntime::fdiv);
 468         break;
 469       case Bytecodes::_ddiv:
 470         entry = CAST_FROM_FN_PTR(address, SharedRuntime::ddiv);
 471         break;
 472       case Bytecodes::_fadd:
 473         entry = CAST_FROM_FN_PTR(address, SharedRuntime::fadd);
 474         break;
 475       case Bytecodes::_dadd:
 476         entry = CAST_FROM_FN_PTR(address, SharedRuntime::dadd);
 477         break;
 478       case Bytecodes::_fsub:
 479         entry = CAST_FROM_FN_PTR(address, SharedRuntime::fsub);
 480         break;
 481       case Bytecodes::_dsub:
 482         entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsub);
 483         break;
 484       default:
 485           ShouldNotReachHere();
 486     }
 487     LIR_Opr result = call_runtime(x->x(), x->y(),  entry,  x->type(), NULL);
 488     set_result(x, result);
 489 #else
 490     ShouldNotReachHere();// check your compiler settings
 491 #endif
 492   }
 493 }
 494 
 495 // for  _ladd, _lmul, _lsub, _ldiv, _lrem
 496 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {
 497 
 498   // missing test if instr is commutative and if we should swap
 499   LIRItem left(x->x(), this);
 500   LIRItem right(x->y(), this);
 501 
 502   if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) {
 503 
 504     BasicTypeList signature(2);
 505     signature.append(T_LONG);
 506     signature.append(T_LONG);
 507     CallingConvention* cc = frame_map()->c_calling_convention(&signature);
 508 
 509     // check for division by zero (destroys registers of right operand!)
 510     CodeEmitInfo* info = state_for(x);
 511 
 512     right.load_item();
 513 
 514     __ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));
 515     __ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info));
 516 
 517     const LIR_Opr result_reg = result_register_for(x->type());
 518     left.load_item_force(cc->at(1));
 519     __ move(right.result(), cc->at(0));
 520 
 521     address entry;
 522     switch (x->op()) {
 523     case Bytecodes::_lrem:
 524       entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);
 525       break; // check if dividend is 0 is done elsewhere
 526     case Bytecodes::_ldiv:
 527       entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);
 528       break; // check if dividend is 0 is done elsewhere
 529     default:
 530       ShouldNotReachHere(); return; // unreachable
 531     }
 532 
 533     LIR_Opr result = rlock_result(x);
 534     __ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());
 535     __ move(result_reg, result);
 536   } else {
 537     assert (x->op() == Bytecodes::_lmul || x->op() == Bytecodes::_ladd || x->op() == Bytecodes::_lsub,
 538             "expect lmul, ladd or lsub");
 539     // add, sub, mul
 540     left.load_item();
 541     if (! right.is_register()) {
 542       if (x->op() == Bytecodes::_lmul
 543           || ! right.is_constant()
 544           || ! Assembler::operand_valid_for_add_sub_immediate(right.get_jlong_constant())) {
 545         right.load_item();
 546       } else { // add, sub
 547         assert (x->op() == Bytecodes::_ladd || x->op() == Bytecodes::_lsub, "expect ladd or lsub");
 548         // don't load constants to save register
 549         right.load_nonconstant();
 550       }
 551     }
 552     rlock_result(x);
 553     arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);
 554   }
 555 }
 556 
 557 // for: _iadd, _imul, _isub, _idiv, _irem
 558 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {
 559 
 560   // Test if instr is commutative and if we should swap
 561   LIRItem left(x->x(),  this);
 562   LIRItem right(x->y(), this);
 563   LIRItem* left_arg = &left;
 564   LIRItem* right_arg = &right;
 565   if (x->is_commutative() && left.is_stack() && right.is_register()) {
 566     // swap them if left is real stack (or cached) and right is real register(not cached)
 567     left_arg = &right;
 568     right_arg = &left;
 569   }
 570 
 571   left_arg->load_item();
 572 
 573   // do not need to load right, as we can handle stack and constants
 574   if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {
 575 
 576     right_arg->load_item();
 577     rlock_result(x);
 578 
 579     if (!(VM_Version::features() & FT_HW_DIVIDE)) {
 580       // MacroAssembler::divide32 destroys both operand registers
 581       left_arg->set_destroys_register();
 582       right_arg->set_destroys_register();
 583     }
 584 
 585     CodeEmitInfo* info = state_for(x);
 586     LIR_Opr tmp = new_register(T_INT);
 587     __ cmp(lir_cond_equal, right_arg->result(), LIR_OprFact::intConst(0));
 588     __ branch(lir_cond_equal, T_INT, new DivByZeroStub(info));
 589     info = state_for(x);
 590 
 591     if (x->op() == Bytecodes::_irem) {
 592       __ irem(left_arg->result(), right_arg->result(), x->operand(), tmp, NULL);
 593     } else if (x->op() == Bytecodes::_idiv) {
 594       __ idiv(left_arg->result(), right_arg->result(), x->operand(), tmp, NULL);
 595     }
 596 
 597   } else if (x->op() == Bytecodes::_iadd || x->op() == Bytecodes::_isub) {
 598     if (right.is_constant()
 599         && Assembler::operand_valid_for_add_sub_immediate(right.get_jint_constant())) {
 600       right.load_nonconstant();
 601     } else {
 602       right.load_item();
 603     }
 604     rlock_result(x);
 605     arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), LIR_OprFact::illegalOpr);
 606   } else {
 607     assert (x->op() == Bytecodes::_imul, "expect imul");
 608     if (right.is_constant()) {
 609       jint c = right.get_jint_constant();
 610       if (c > 0 && c < max_jint && (is_power_of_2(c) || is_power_of_2(c - 1) || is_power_of_2(c + 1))) {
 611         right_arg->dont_load_item();
 612       } else {
 613         // Cannot use constant op.
 614         right_arg->load_item();
 615       }
 616     } else {
 617       right.load_item();
 618     }
 619     rlock_result(x);
 620     arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), new_register(T_INT));
 621   }
 622 }
 623 
 624 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {
 625   // when an operand with use count 1 is the left operand, then it is
 626   // likely that no move for 2-operand-LIR-form is necessary
 627   if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
 628     x->swap_operands();
 629   }
 630 
 631   ValueTag tag = x->type()->tag();
 632   assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");
 633   switch (tag) {
 634     case floatTag:
 635     case doubleTag:  do_ArithmeticOp_FPU(x);  return;
 636     case longTag:    do_ArithmeticOp_Long(x); return;
 637     case intTag:     do_ArithmeticOp_Int(x);  return;
 638   }
 639   ShouldNotReachHere();
 640 }
 641 
 642 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr
 643 void LIRGenerator::do_ShiftOp(ShiftOp* x) {
 644 
 645   LIRItem left(x->x(),  this);
 646   LIRItem right(x->y(), this);
 647 
 648   left.load_item();
 649 
 650   rlock_result(x);
 651   if (right.is_constant()) {
 652     right.dont_load_item();
 653 
 654     switch (x->op()) {
 655     case Bytecodes::_ishl: {
 656       int c = right.get_jint_constant() & 0x1f;
 657       __ shift_left(left.result(), c, x->operand());
 658       break;
 659     }
 660     case Bytecodes::_ishr: {
 661       int c = right.get_jint_constant() & 0x1f;
 662       __ shift_right(left.result(), c, x->operand());
 663       break;
 664     }
 665     case Bytecodes::_iushr: {
 666       int c = right.get_jint_constant() & 0x1f;
 667       __ unsigned_shift_right(left.result(), c, x->operand());
 668       break;
 669     }
 670     case Bytecodes::_lshl: {
 671       int c = right.get_jint_constant() & 0x3f;
 672       __ shift_left(left.result(), c, x->operand());
 673       break;
 674     }
 675     case Bytecodes::_lshr: {
 676       int c = right.get_jint_constant() & 0x3f;
 677       __ shift_right(left.result(), c, x->operand());
 678       break;
 679     }
 680     case Bytecodes::_lushr: {
 681       int c = right.get_jint_constant() & 0x3f;
 682       __ unsigned_shift_right(left.result(), c, x->operand());
 683       break;
 684     }
 685     default:
 686       ShouldNotReachHere();
 687     }
 688   } else {
 689     right.load_item();
 690     LIR_Opr tmp = LIR_OprFact::illegalOpr;
 691     if (left.result()->type() == T_LONG)
 692       left.set_destroys_register();
 693     switch (x->op()) {
 694     case Bytecodes::_ishl: {
 695       __ shift_left(left.result(), right.result(), x->operand(), tmp);
 696       break;
 697     }
 698     case Bytecodes::_ishr: {
 699       __ shift_right(left.result(), right.result(), x->operand(), tmp);
 700       break;
 701     }
 702     case Bytecodes::_iushr: {
 703       __ unsigned_shift_right(left.result(), right.result(), x->operand(), tmp);
 704       break;
 705     }
 706     case Bytecodes::_lshl: {
 707       __ shift_left(left.result(), right.result(), x->operand(), tmp);
 708       break;
 709     }
 710     case Bytecodes::_lshr: {
 711       __ shift_right(left.result(), right.result(), x->operand(), tmp);
 712       break;
 713     }
 714     case Bytecodes::_lushr: {
 715       __ unsigned_shift_right(left.result(), right.result(), x->operand(), tmp);
 716       break;
 717     }
 718     default:
 719       ShouldNotReachHere();
 720     }
 721   }
 722 }
 723 
 724 // _iand, _land, _ior, _lor, _ixor, _lxor
 725 void LIRGenerator::do_LogicOp(LogicOp* x) {
 726 
 727   LIRItem left(x->x(),  this);
 728   LIRItem right(x->y(), this);
 729 
 730   left.load_item();
 731 
 732   rlock_result(x);
 733   if (right.is_constant()
 734       && ((right.type()->tag() == intTag
 735            && Assembler::operand_valid_for_logical_immediate(true, right.get_jint_constant()))
 736           || (right.type()->tag() == longTag
 737               && Assembler::operand_valid_for_logical_immediate(false, right.get_jlong_constant()))))  {
 738     right.dont_load_item();
 739   } else {
 740     right.load_item();
 741   }
 742   switch (x->op()) {
 743   case Bytecodes::_iand:
 744   case Bytecodes::_land:
 745     __ logical_and(left.result(), right.result(), x->operand()); break;
 746   case Bytecodes::_ior:
 747   case Bytecodes::_lor:
 748     __ logical_or (left.result(), right.result(), x->operand()); break;
 749   case Bytecodes::_ixor:
 750   case Bytecodes::_lxor:
 751     __ logical_xor(left.result(), right.result(), x->operand()); break;
 752   default: Unimplemented();
 753   }
 754 }
 755 
 756 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg
 757 void LIRGenerator::do_CompareOp(CompareOp* x) {
 758   LIRItem left(x->x(), this);
 759   LIRItem right(x->y(), this);
 760   ValueTag tag = x->x()->type()->tag();
 761   left.load_item();
 762   right.load_item();
 763 
 764   if (x->x()->type()->is_float_kind()) {
 765     Bytecodes::Code code = x->op();
 766     if(hasFPU()) {
 767         LIR_Opr reg = rlock_result(x);
 768         __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));
 769     } else {
 770 #ifdef __SOFTFP__
 771         address entry;
 772         switch (code) {
 773         case Bytecodes::_fcmpl:
 774           entry = CAST_FROM_FN_PTR(address, SharedRuntime::fcmpl);
 775           break;
 776         case Bytecodes::_fcmpg:
 777           entry = CAST_FROM_FN_PTR(address, SharedRuntime::fcmpg);
 778           break;
 779         case Bytecodes::_dcmpl:
 780           entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcmpl);
 781           break;
 782         case Bytecodes::_dcmpg:
 783           entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcmpg);
 784           break;
 785         default:
 786           ShouldNotReachHere();
 787         }
 788 
 789         LIR_Opr result = call_runtime(x->x(), x->y(),  entry,  x->type(), NULL);
 790         set_result(x, result);
 791 #else
 792         ShouldNotReachHere(); // check your compiler settings
 793 #endif
 794     }
 795   } else if (x->x()->type()->tag() == longTag) {
 796     LIR_Opr reg = rlock_result(x);
 797     __ lcmp2int(left.result(), right.result(), reg);
 798   } else {
 799     Unimplemented();
 800   }
 801 }
 802 
 803 LIR_Opr LIRGenerator::atomic_cmpxchg(BasicType type, LIR_Opr addr, LIRItem& cmp_value, LIRItem& new_value) {
 804   LIR_Opr ill = LIR_OprFact::illegalOpr;  // for convenience
 805   new_value.load_item();
 806   cmp_value.load_item();
 807   LIR_Opr result = new_register(T_INT);
 808   if (type == T_OBJECT || type == T_ARRAY) {
 809     __ cas_obj(addr, cmp_value.result(), new_value.result(), ill, ill, result);
 810   } else if (type == T_INT) {
 811     __ cas_int(addr, cmp_value.result(), new_value.result(), ill, ill, result);
 812   } else if (type == T_LONG) {
 813     __ cas_long(addr, cmp_value.result(), new_value.result(), FrameMap::long1_opr, ill, result);
 814   } else {
 815     ShouldNotReachHere();
 816   }
 817   __ logical_xor(result, LIR_OprFact::intConst(1), result);
 818   return result;
 819 }
 820 
 821 LIR_Opr LIRGenerator::atomic_xchg(BasicType type, LIR_Opr addr, LIRItem& value) {
 822   bool is_oop = type == T_OBJECT || type == T_ARRAY;
 823   LIR_Opr result = new_register(type);
 824   value.load_item();
 825   assert(type == T_INT || is_oop, "unexpected type");
 826   LIR_Opr tmp = new_register(T_INT);
 827   __ xchg(addr, value.result(), result, tmp);
 828   return result;
 829 }
 830 
 831 LIR_Opr LIRGenerator::atomic_add(BasicType type, LIR_Opr addr, LIRItem& value) {
 832   LIR_Opr result = new_register(type);
 833   value.load_item();
 834   assert(type == T_INT, "unexpected type");
 835   LIR_Opr tmp = new_register(T_INT);
 836   __ xadd(addr, value.result(), result, tmp);
 837   return result;
 838 }
 839 
 840 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {
 841   switch (x->id()) {
 842     default:
 843         ShouldNotReachHere();
 844         break;
 845     case vmIntrinsics::_dabs:
 846     case vmIntrinsics::_dsqrt:
 847         if(hasFPU()) {
 848             assert(x->number_of_arguments() == 1, "wrong type");
 849             LIRItem value(x->argument_at(0), this);
 850             value.load_item();
 851             LIR_Opr dst = rlock_result(x);
 852 
 853             switch (x->id()) {
 854             case vmIntrinsics::_dsqrt: {
 855               __ sqrt(value.result(), dst, LIR_OprFact::illegalOpr);
 856               break;
 857             }
 858             case vmIntrinsics::_dabs: {
 859               __ abs(value.result(), dst, LIR_OprFact::illegalOpr);
 860               break;
 861             }
 862             }
 863             break;
 864       }// fall through for FPU less cores
 865     case vmIntrinsics::_dlog10: // fall through
 866     case vmIntrinsics::_dlog: // fall through
 867     case vmIntrinsics::_dsin: // fall through
 868     case vmIntrinsics::_dtan: // fall through
 869     case vmIntrinsics::_dcos: // fall through
 870     case vmIntrinsics::_dexp: {
 871       assert(x->number_of_arguments() == 1, "wrong type");
 872 
 873       address runtime_entry = NULL;
 874       switch (x->id()) {
 875 #ifdef __SOFTFP__
 876       case vmIntrinsics::_dabs:
 877         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dabs);
 878         break;
 879       case vmIntrinsics::_dsqrt:
 880         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsqrt);
 881         break;
 882 #endif
 883       case vmIntrinsics::_dsin:
 884         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
 885         break;
 886       case vmIntrinsics::_dcos:
 887         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
 888         break;
 889       case vmIntrinsics::_dtan:
 890         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
 891         break;
 892       case vmIntrinsics::_dlog:
 893         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);
 894         break;
 895       case vmIntrinsics::_dlog10:
 896         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);
 897         break;
 898       case vmIntrinsics::_dexp:
 899         runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);
 900         break;
 901       default:
 902         ShouldNotReachHere();
 903       }
 904       LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL);
 905       set_result(x, result);
 906       break;
 907     }
 908     case vmIntrinsics::_dpow: {
 909       assert(x->number_of_arguments() == 2, "wrong type");
 910       address runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);
 911       LIR_Opr result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_entry, x->type(), NULL);
 912       set_result(x, result);
 913       break;
 914     }
 915   }
 916 }
 917 
 918 
 919 void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
 920   assert(x->number_of_arguments() == 5, "wrong type");
 921 
 922   // Make all state_for calls early since they can emit code
 923   CodeEmitInfo* info = state_for(x, x->state());
 924 
 925   LIRItem src(x->argument_at(0), this);
 926   LIRItem src_pos(x->argument_at(1), this);
 927   LIRItem dst(x->argument_at(2), this);
 928   LIRItem dst_pos(x->argument_at(3), this);
 929   LIRItem length(x->argument_at(4), this);
 930 
 931   // operands for arraycopy must use fixed registers, otherwise
 932   // LinearScan will fail allocation (because arraycopy always needs a
 933   // call)
 934 
 935   // The java calling convention does not give us enough registers
 936   // so we occupy two more: r4 and r5. The fast path code will be able to
 937   // make use of these registers for performance purpose. If going into
 938   // slow path we'll spill extra data to the stack as necessary
 939 
 940   src.load_item_force     (FrameMap::as_oop_opr(j_rarg0));
 941   src_pos.load_item_force (FrameMap::as_opr(j_rarg1));
 942   dst.load_item_force     (FrameMap::as_oop_opr(j_rarg2));
 943   dst_pos.load_item_force (FrameMap::as_opr(j_rarg3));
 944 
 945   length.load_item_force  (FrameMap::as_opr(r4));
 946   LIR_Opr tmp =           FrameMap::as_opr(r5);
 947 
 948   set_no_result(x);
 949 
 950   int flags;
 951   ciArrayKlass* expected_type;
 952   arraycopy_helper(x, &flags, &expected_type);
 953 
 954   __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), tmp, expected_type, flags, info); // does add_safepoint
 955 }
 956 
 957 void LIRGenerator::do_update_CRC32_inner(Intrinsic* x, int is_crc32c) {
 958   assert(!is_crc32c ? UseCRC32Intrinsics : UseCRC32CIntrinsics, "why are we here?");
 959   // Make all state_for calls early since they can emit code
 960   LIR_Opr result = rlock_result(x);
 961   switch (x->id()) {
 962     case vmIntrinsics::_updateCRC32: {
 963       LIRItem crc(x->argument_at(0), this);
 964       LIRItem val(x->argument_at(1), this);
 965       // val is destroyed by update_crc32
 966       val.set_destroys_register();
 967       crc.load_item();
 968       val.load_item();
 969       __ update_crc32(crc.result(), val.result(), result);
 970       break;
 971     }
 972     case vmIntrinsics::_updateBytesCRC32:
 973     case vmIntrinsics::_updateByteBufferCRC32:
 974         assert(!is_crc32c, "why are we here?");
 975     case vmIntrinsics::_updateBytesCRC32C:
 976     case vmIntrinsics::_updateDirectByteBufferCRC32C:
 977     {
 978       if (is_crc32c) {
 979         assert(x->id() == vmIntrinsics::_updateBytesCRC32C ||
 980                x->id() == vmIntrinsics::_updateDirectByteBufferCRC32C, "why are we here?");
 981       }
 982       bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32) ||
 983                             (x->id() == vmIntrinsics::_updateBytesCRC32C);
 984 
 985       LIRItem crc(x->argument_at(0), this);
 986       LIRItem buf(x->argument_at(1), this);
 987       LIRItem off(x->argument_at(2), this);
 988       LIRItem len(x->argument_at(3), this); // length, or end in case of crc32c
 989       buf.load_item();
 990       off.load_nonconstant();
 991 
 992       LIR_Opr index = off.result();
 993       int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
 994       if(off.result()->is_constant()) {
 995         index = LIR_OprFact::illegalOpr;
 996        offset += off.result()->as_jint();
 997       }
 998       LIR_Opr base_op = buf.result();
 999 
1000       if (!is_updateBytes) { // long b raw address
1001          base_op = new_register(T_INT);
1002          __ convert(Bytecodes::_l2i, buf.result(), base_op);
1003       }
1004 
1005       if (offset) {
1006         LIR_Opr tmp = new_pointer_register();
1007         __ add(base_op, LIR_OprFact::intConst(offset), tmp);
1008         base_op = tmp;
1009         offset = 0;
1010       }
1011 
1012       LIR_Address* a = new LIR_Address(base_op,
1013                                        index,
1014                                        offset,
1015                                        T_BYTE);
1016       BasicTypeList signature(3);
1017       signature.append(T_INT);
1018       signature.append(T_ADDRESS);
1019       signature.append(T_INT);
1020       CallingConvention* cc = frame_map()->c_calling_convention(&signature);
1021       const LIR_Opr result_reg = result_register_for(x->type());
1022 
1023       LIR_Opr addr = new_pointer_register();
1024       __ leal(LIR_OprFact::address(a), addr);
1025 
1026       crc.load_item_force(cc->at(0));
1027       __ move(addr, cc->at(1));
1028 
1029       if (!is_crc32c) {
1030         len.load_item_force(cc->at(2));
1031       } else {
1032         __ sub(len.result(), off.result(), cc->at(2));
1033       }
1034 
1035       __ call_runtime_leaf(
1036             !is_crc32c ?
1037                 StubRoutines::updateBytesCRC32() :
1038                 StubRoutines::updateBytesCRC32C(),
1039             getThreadTemp(), result_reg, cc->args());
1040       __ move(result_reg, result);
1041 
1042       break;
1043     }
1044     default: {
1045       ShouldNotReachHere();
1046     }
1047   }
1048 }
1049 
1050 void LIRGenerator::do_update_CRC32(Intrinsic* x) {
1051   do_update_CRC32_inner(x, false);
1052 }
1053 
1054 void LIRGenerator::do_update_CRC32C(Intrinsic* x) {
1055   do_update_CRC32_inner(x, true);
1056 }
1057 
1058 void LIRGenerator::do_aescrypt_block(Intrinsic* x) {
1059   assert(UseAESIntrinsics, "why are we here?");
1060 
1061   // first argument is object itself
1062   LIRItem obj(x->argument_at(0), this);
1063   LIRItem from(x->argument_at(1), this);
1064   LIRItem foff(x->argument_at(2), this);
1065   LIRItem to(x->argument_at(3), this);
1066   LIRItem toff(x->argument_at(4), this);
1067   LIR_Opr addr = new_pointer_register();
1068 
1069   BasicTypeList signature(3);
1070   signature.append(T_ADDRESS);
1071   signature.append(T_ADDRESS);
1072   signature.append(T_ADDRESS);
1073   CallingConvention* cc = frame_map()->c_calling_convention(&signature);
1074 
1075   // From buffer
1076   LIR_Address* a;
1077   if (foff.result()->is_constant()) {
1078     jint c = foff.result()->as_jint();
1079     a = new LIR_Address(from.result(),
1080                         c,
1081                         T_BYTE);
1082   } else {
1083     a = new LIR_Address(from.result(),
1084                         foff.result(),
1085                         LIR_Address::times_1,
1086                         0,
1087                         T_BYTE);
1088   }
1089   __ leal(LIR_OprFact::address(a), addr);
1090   __ add(addr, LIR_OprFact::intConst(arrayOopDesc::base_offset_in_bytes(T_BYTE)), cc->at(0));
1091 
1092   // To buffer
1093   if (toff.result()->is_constant()) {
1094     jint c = toff.result()->as_jint();
1095     a = new LIR_Address(to.result(),
1096                         c,
1097                         T_BYTE);
1098   } else {
1099     a = new LIR_Address(to.result(),
1100                         toff.result(),
1101                         LIR_Address::times_1,
1102                         0,
1103                         T_BYTE);
1104   }
1105   __ leal(LIR_OprFact::address(a), addr);
1106   __ add(addr, LIR_OprFact::intConst(arrayOopDesc::base_offset_in_bytes(T_BYTE)), cc->at(1));
1107 
1108   // Key
1109   LIR_Address* k = new LIR_Address(obj.result(),
1110                         com_sun_crypto_provider_AESCrypt::K_offset(),
1111                         T_OBJECT);
1112 
1113   __ load(k, addr);
1114   __ add(addr, LIR_OprFact::intConst(arrayOopDesc::base_offset_in_bytes(T_BYTE)), cc->at(2));
1115 
1116   set_no_result(x);
1117 
1118   switch (x->id()) {
1119     case vmIntrinsics::_aescrypt_encryptBlock:
1120     {
1121       __ call_runtime_leaf(StubRoutines::aescrypt_encryptBlock(), getThreadTemp(), LIR_OprFact::illegalOpr, cc->args());
1122       break;
1123     }
1124     case vmIntrinsics::_aescrypt_decryptBlock:
1125     {
1126       __ call_runtime_leaf(StubRoutines::aescrypt_decryptBlock(), getThreadTemp(), LIR_OprFact::illegalOpr, cc->args());
1127       break;
1128     }
1129     default:
1130     {
1131       ShouldNotReachHere();
1132     }
1133   }
1134 }
1135 
1136 // This method is called in the C1 Xcom mode
1137 void LIRGenerator::do_aescrypt_cbc(Intrinsic* x) {
1138   assert(UseAESIntrinsics && UseNeon, "why are we here?");
1139 
1140   LIRItem obj(x->argument_at(0), this);
1141   LIRItem from(x->argument_at(1), this);
1142   LIRItem foff(x->argument_at(2), this);
1143   LIRItem flen(x->argument_at(3), this);
1144   LIRItem to(x->argument_at(4), this);
1145   LIRItem toff(x->argument_at(5), this);
1146   LIR_Opr addr = new_pointer_register();
1147 
1148   // force to load len into r4
1149   flen.load_item_force  (FrameMap::as_opr(r4));
1150 
1151   BasicTypeList signature(5);
1152   signature.append(T_ADDRESS);  //from
1153   signature.append(T_ADDRESS);  //to
1154   signature.append(T_ADDRESS);  //key
1155   signature.append(T_ADDRESS);  //rvec
1156   signature.append(T_INT);      //len
1157   CallingConvention* cc = frame_map()->c_calling_convention(&signature);
1158 
1159   // From buffer
1160   LIR_Address* a;
1161   a = new LIR_Address(from.result(),T_OBJECT);
1162   __ leal(LIR_OprFact::address(a), addr);
1163   __ add(addr, LIR_OprFact::intConst(arrayOopDesc::base_offset_in_bytes(T_BYTE)), addr);
1164   __ add(addr, foff.result(), cc->at(0));
1165 
1166   // To buffer
1167   a = new LIR_Address(to.result(),T_OBJECT);
1168   __ leal(LIR_OprFact::address(a), addr);
1169   __ add(addr, LIR_OprFact::intConst(arrayOopDesc::base_offset_in_bytes(T_BYTE)), addr);
1170   __ add(addr, toff.result(), cc->at(1));
1171   // key
1172   a = new LIR_Address(obj.result(),
1173                         com_sun_crypto_provider_FeedbackCipher::embeddedCipher_offset(),
1174                         T_OBJECT);
1175   __ load(a, addr);
1176   __ add(addr, LIR_OprFact::intConst(com_sun_crypto_provider_AESCrypt::K_offset()), addr);
1177   a = new LIR_Address(addr, T_OBJECT);
1178   __ load(a, addr);
1179   __ add(addr, LIR_OprFact::intConst(arrayOopDesc::base_offset_in_bytes(T_BYTE)), cc->at(2));
1180 
1181   // rvec
1182   a = new LIR_Address(obj.result(),
1183                         com_sun_crypto_provider_CipherBlockChaining::r_offset(),
1184                         T_OBJECT);
1185   __ load(a, addr);
1186   __ add(addr, LIR_OprFact::intConst(arrayOopDesc::base_offset_in_bytes(T_BYTE)), cc->at(3));
1187 
1188   //input len
1189   __ move(flen.result(), cc->at(4));
1190 
1191   LIR_Opr result = rlock_result(x);
1192   const LIR_Opr result_reg = result_register_for(x->type());
1193 
1194   switch (x->id()) {
1195     case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
1196     {
1197       __ call_runtime_leaf(StubRoutines::cipherBlockChaining_encryptAESCrypt_special(), getThreadTemp(), result_reg, cc->args());
1198       __ move(result_reg, result);
1199       break;
1200     }
1201     case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
1202     {
1203       __ call_runtime_leaf(StubRoutines::cipherBlockChaining_decryptAESCrypt_special(), getThreadTemp(), result_reg, cc->args());
1204       __ move(result_reg, result);
1205       break;
1206     }
1207     default:
1208     {
1209       ShouldNotReachHere();
1210     }
1211 
1212   }
1213 }
1214 
1215 // This method is called in the C1 Xcom mode
1216 void LIRGenerator::do_sha(Intrinsic* x) {
1217   assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics, "why are we here?");
1218 
1219   // first argument is object itself
1220   LIRItem obj(x->argument_at(0), this);
1221   LIRItem from(x->argument_at(1), this);
1222   LIRItem foff(x->argument_at(2), this);
1223 
1224   BasicTypeList signature(2);
1225   signature.append(T_ADDRESS);
1226   signature.append(T_ADDRESS);
1227   CallingConvention* cc = frame_map()->c_calling_convention(&signature);
1228 
1229   // From buffer
1230   LIR_Address* a;
1231   if (foff.result()->is_constant()) {
1232     jint c = foff.result()->as_jint();
1233     a = new LIR_Address(from.result(),
1234                         c,
1235                         T_BYTE);
1236   } else {
1237     a = new LIR_Address(from.result(),
1238                         foff.result(),
1239                         LIR_Address::times_1,
1240                         0,
1241                         T_BYTE);
1242   }
1243   LIR_Opr addr_from = new_pointer_register();
1244   __ leal(LIR_OprFact::address(a), addr_from);
1245   __ add(addr_from, LIR_OprFact::intConst(arrayOopDesc::base_offset_in_bytes(T_BYTE)), cc->at(0));
1246 
1247 
1248   // State
1249   int state_offset;
1250   int state_data_offset;
1251   address stub_addr;
1252   switch (x->id()) {
1253     case vmIntrinsics::_sha_implCompress:
1254       state_offset = sun_security_provider_SHA2::state_offset();
1255       state_data_offset = arrayOopDesc::base_offset_in_bytes(T_INT);
1256       stub_addr = StubRoutines::sha1_implCompress();
1257       break;
1258     case vmIntrinsics::_sha2_implCompress:
1259       state_offset = sun_security_provider_SHA2::state_offset();
1260       state_data_offset = arrayOopDesc::base_offset_in_bytes(T_INT);
1261       stub_addr = StubRoutines::sha256_implCompress();
1262       break;
1263     case vmIntrinsics::_sha5_implCompress:
1264       state_offset = sun_security_provider_SHA5::state_offset();
1265       state_data_offset = arrayOopDesc::base_offset_in_bytes(T_LONG);
1266       stub_addr = StubRoutines::sha512_implCompress();
1267       break;
1268     default:
1269       ShouldNotReachHere();
1270       return; // unreachable
1271   }
1272 
1273   LIR_Address* state = new LIR_Address(obj.result(), state_offset, T_OBJECT);
1274 
1275   LIR_Opr addr_state = new_pointer_register();
1276   __ load(state, addr_state);
1277   __ add(addr_state, LIR_OprFact::intConst(state_data_offset), cc->at(1));
1278 
1279   set_no_result(x);
1280 
1281   __ call_runtime_leaf(stub_addr, getThreadTemp(), LIR_OprFact::illegalOpr, cc->args());
1282 
1283 }
1284 
1285 void LIRGenerator::do_montgomery_intrinsic(Intrinsic* x) {
1286   bool squaring = x->id() == vmIntrinsics::_montgomerySquare;
1287   int n_arg_idx = squaring ? 1 : 2;
1288   assert(squaring ? UseMontgomerySquareIntrinsic : UseMontgomeryMultiplyIntrinsic, "why are we here?");
1289 
1290   LIRItem a(x->argument_at(0), this);
1291   LIRItem n(x->argument_at(n_arg_idx), this);
1292   LIRItem len(x->argument_at(n_arg_idx+1), this);
1293   LIRItem inv(x->argument_at(n_arg_idx+2), this);
1294   LIRItem product(x->argument_at(n_arg_idx+3), this);
1295 
1296   BasicTypeList signature(squaring ? 5 : 6);
1297   signature.append(T_ADDRESS);
1298   if (!squaring)
1299     signature.append(T_ADDRESS);
1300   signature.append(T_ADDRESS);
1301   signature.append(T_INT);
1302   signature.append(T_LONG);
1303   signature.append(T_ADDRESS);
1304   CallingConvention* cc = frame_map()->c_calling_convention(&signature);
1305 
1306   // A array, c_rarg0
1307   __ leal(LIR_OprFact::address(emit_array_address(a.result(), LIR_OprFact::intConst(0), T_INT)), cc->at(0));
1308   if (!squaring) {
1309     LIRItem b(x->argument_at(1), this);
1310     // B array, c_rarg1
1311     __ leal(LIR_OprFact::address(emit_array_address(b.result(), LIR_OprFact::intConst(0), T_INT)), cc->at(1));
1312   }
1313   // N array, c_rarg2(1)
1314   __ leal(LIR_OprFact::address(emit_array_address(n.result(), LIR_OprFact::intConst(0), T_INT)), cc->at(n_arg_idx));
1315   // len, c_rarg3(2)
1316   assert(cc->at(n_arg_idx+1)->is_cpu_register(), "assumed");
1317   __ move(len.result(), cc->at(n_arg_idx+1));
1318   // inv, stack slot
1319   assert(cc->at(n_arg_idx+2)->is_address(), "assumed");
1320   __ move(inv.result(), cc->at(n_arg_idx+2));
1321   // M array, stack slot
1322   LIR_Opr addr = new_pointer_register();
1323   __ leal(LIR_OprFact::address(emit_array_address(product.result(), LIR_OprFact::intConst(0), T_INT)), addr);
1324   __ move(addr, cc->at(n_arg_idx+3));
1325 
1326   set_result(x, product.result());
1327 
1328   switch (x->id()) {
1329     case vmIntrinsics::_montgomeryMultiply:
1330     {
1331       __ call_runtime_leaf(StubRoutines::montgomeryMultiply(), getThreadTemp(), LIR_OprFact::illegalOpr, cc->args());
1332       break;
1333     }
1334     case vmIntrinsics::_montgomerySquare:
1335     {
1336       __ call_runtime_leaf(StubRoutines::montgomerySquare(), getThreadTemp(), LIR_OprFact::illegalOpr, cc->args());
1337       break;
1338     }
1339     default:
1340     {
1341       ShouldNotReachHere();
1342     }
1343   }
1344 }
1345 
1346 void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {
1347   Unimplemented();
1348 }
1349 
1350 void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) {
1351   fatal("vectorizedMismatch intrinsic is not implemented on this platform");
1352 }
1353 
1354 // _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f
1355 // _i2b, _i2c, _i2s
1356 void LIRGenerator::do_Convert(Convert* x) {
1357     address entry = NULL;
1358   switch (x->op()) {
1359   case Bytecodes::_d2i:
1360   case Bytecodes::_f2i:
1361   case Bytecodes::_i2f:
1362   case Bytecodes::_i2d:
1363   case Bytecodes::_f2d:
1364   case Bytecodes::_d2f:
1365       if(hasFPU()) {
1366           break;
1367       }// fall through for FPU-less cores
1368   case Bytecodes::_d2l:
1369   case Bytecodes::_f2l:
1370   case Bytecodes::_l2d:
1371   case Bytecodes::_l2f: {
1372 
1373     switch (x->op()) {
1374 #ifdef __SOFTFP__
1375     case Bytecodes::_i2f:
1376       entry = CAST_FROM_FN_PTR(address, SharedRuntime::i2f);
1377       break;
1378     case Bytecodes::_i2d:
1379       entry = CAST_FROM_FN_PTR(address, SharedRuntime::i2d);
1380       break;
1381     case Bytecodes::_f2d:
1382       entry = CAST_FROM_FN_PTR(address, SharedRuntime::f2d);
1383       break;
1384     case Bytecodes::_d2f:
1385       entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2f);
1386       break;
1387     case Bytecodes::_d2i:
1388       entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2i);
1389       break;
1390     case Bytecodes::_f2i:
1391       entry = CAST_FROM_FN_PTR(address, SharedRuntime::f2i);
1392       break;
1393 #endif
1394     case Bytecodes::_d2l:
1395       entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2l);
1396       break;
1397     case Bytecodes::_f2l:
1398       entry = CAST_FROM_FN_PTR(address, SharedRuntime::f2l);
1399       break;
1400     case Bytecodes::_l2d:
1401       entry = CAST_FROM_FN_PTR(address, SharedRuntime::l2d);
1402       break;
1403     case Bytecodes::_l2f:
1404       entry = CAST_FROM_FN_PTR(address, SharedRuntime::l2f);
1405       break;
1406     default:
1407       ShouldNotReachHere();
1408     }
1409     LIR_Opr result = call_runtime(x->value(), entry, x->type(), NULL);
1410     set_result(x, result);
1411   }
1412   break;
1413 
1414   default:
1415     break;
1416 }
1417     if(NULL == entry) {
1418     LIRItem value(x->value(), this);
1419     value.load_item();
1420 
1421     if (x->op() == Bytecodes::_f2i || x->op() == Bytecodes::_d2i) {
1422       value.set_destroys_register();
1423     }
1424 
1425     LIR_Opr input = value.result();
1426     LIR_Opr result = rlock(x);
1427 
1428     __ convert(x->op(), input, result);
1429 
1430     assert(result->is_virtual(), "result must be virtual register");
1431     set_result(x, result);
1432   }
1433 }
1434 
1435 void LIRGenerator::do_NewInstance(NewInstance* x) {
1436 #ifndef PRODUCT
1437   if (PrintNotLoaded && !x->klass()->is_loaded()) {
1438     tty->print_cr("   ###class not loaded at new bci %d", x->printable_bci());
1439   }
1440 #endif
1441   CodeEmitInfo* info = state_for(x, x->state());
1442   LIR_Opr reg = result_register_for(x->type());
1443   new_instance(reg, x->klass(), x->is_unresolved(),
1444                        FrameMap::r2_oop_opr,
1445                        FrameMap::r5_oop_opr,
1446                        FrameMap::r4_oop_opr,
1447                        LIR_OprFact::illegalOpr,
1448                        FrameMap::r3_metadata_opr, info);
1449   LIR_Opr result = rlock_result(x);
1450   __ move(reg, result);
1451 }
1452 
1453 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
1454   CodeEmitInfo* info = state_for(x, x->state());
1455 
1456   LIRItem length(x->length(), this);
1457   length.load_item_force(FrameMap::r6_opr);
1458 
1459   LIR_Opr reg = result_register_for(x->type());
1460   LIR_Opr tmp1 = FrameMap::r2_oop_opr;
1461   LIR_Opr tmp2 = FrameMap::r4_oop_opr;
1462   LIR_Opr tmp3 = FrameMap::r5_oop_opr;
1463   LIR_Opr tmp4 = reg;
1464   LIR_Opr klass_reg = FrameMap::r3_metadata_opr;
1465   LIR_Opr len = length.result();
1466   BasicType elem_type = x->elt_type();
1467 
1468   __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
1469 
1470   CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
1471   __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);
1472 
1473   LIR_Opr result = rlock_result(x);
1474   __ move(reg, result);
1475 }
1476 
1477 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
1478   LIRItem length(x->length(), this);
1479   // in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction
1480   // and therefore provide the state before the parameters have been consumed
1481   CodeEmitInfo* patching_info = NULL;
1482   if (!x->klass()->is_loaded() || PatchALot) {
1483     patching_info =  state_for(x, x->state_before());
1484   }
1485 
1486   CodeEmitInfo* info = state_for(x, x->state());
1487 
1488   LIR_Opr reg = result_register_for(x->type());
1489   LIR_Opr tmp1 = FrameMap::r2_oop_opr;
1490   LIR_Opr tmp2 = FrameMap::r4_oop_opr;
1491   LIR_Opr tmp3 = FrameMap::r5_oop_opr;
1492   LIR_Opr tmp4 = reg;
1493   LIR_Opr klass_reg = FrameMap::r3_metadata_opr;
1494 
1495   length.load_item_force(FrameMap::r6_opr);
1496   LIR_Opr len = length.result();
1497 
1498   CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
1499   ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());
1500   if (obj == ciEnv::unloaded_ciobjarrayklass()) {
1501     BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
1502   }
1503   klass2reg_with_patching(klass_reg, obj, patching_info);
1504   __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);
1505 
1506   LIR_Opr result = rlock_result(x);
1507   __ move(reg, result);
1508 }
1509 
1510 
1511 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
1512   Values* dims = x->dims();
1513   int i = dims->length();
1514   LIRItemList* items = new LIRItemList(i, i, NULL);
1515   while (i-- > 0) {
1516     LIRItem* size = new LIRItem(dims->at(i), this);
1517     items->at_put(i, size);
1518   }
1519 
1520   // Evaluate state_for early since it may emit code.
1521   CodeEmitInfo* patching_info = NULL;
1522   if (!x->klass()->is_loaded() || PatchALot) {
1523     patching_info = state_for(x, x->state_before());
1524 
1525     // Cannot re-use same xhandlers for multiple CodeEmitInfos, so
1526     // clone all handlers (NOTE: Usually this is handled transparently
1527     // by the CodeEmitInfo cloning logic in CodeStub constructors but
1528     // is done explicitly here because a stub isn't being used).
1529     x->set_exception_handlers(new XHandlers(x->exception_handlers()));
1530   }
1531   CodeEmitInfo* info = state_for(x, x->state());
1532 
1533   i = dims->length();
1534   while (i-- > 0) {
1535     LIRItem* size = items->at(i);
1536     size->load_item();
1537 
1538     store_stack_parameter(size->result(), in_ByteSize(i*4));
1539   }
1540 
1541   LIR_Opr klass_reg = FrameMap::r1_metadata_opr;
1542   klass2reg_with_patching(klass_reg, x->klass(), patching_info);
1543 
1544   LIR_Opr rank = FrameMap::r2_opr;
1545   __ move(LIR_OprFact::intConst(x->rank()), rank);
1546   LIR_Opr varargs = FrameMap::r3_opr;
1547   __ move(FrameMap::sp_opr, varargs);
1548   LIR_OprList* args = new LIR_OprList(3);
1549   args->append(klass_reg);
1550   args->append(rank);
1551   args->append(varargs);
1552   LIR_Opr reg = result_register_for(x->type());
1553   __ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),
1554                   LIR_OprFact::illegalOpr,
1555                   reg, args, info);
1556 
1557   LIR_Opr result = rlock_result(x);
1558   __ move(reg, result);
1559 }
1560 
1561 void LIRGenerator::do_BlockBegin(BlockBegin* x) {
1562   // nothing to do for now
1563 }
1564 
1565 void LIRGenerator::do_CheckCast(CheckCast* x) {
1566   LIRItem obj(x->obj(), this);
1567 
1568   CodeEmitInfo* patching_info = NULL;
1569   if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check() && !x->is_invokespecial_receiver_check())) {
1570     // must do this before locking the destination register as an oop register,
1571     // and before the obj is loaded (the latter is for deoptimization)
1572     patching_info = state_for(x, x->state_before());
1573   }
1574   obj.load_item();
1575 
1576   // info for exceptions
1577   CodeEmitInfo* info_for_exception =
1578      (x->needs_exception_state() ? state_for(x) :
1579      state_for(x, x->state_before(), true /*ignore_xhandler*/));
1580 
1581   CodeStub* stub;
1582   if (x->is_incompatible_class_change_check()) {
1583     assert(patching_info == NULL, "can't patch this");
1584     stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);
1585   } else if (x->is_invokespecial_receiver_check()) {
1586     assert(patching_info == NULL, "can't patch this");
1587     stub = new DeoptimizeStub(info_for_exception,
1588                               Deoptimization::Reason_class_check,
1589                               Deoptimization::Action_none);
1590   } else {
1591     stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);
1592   }
1593   LIR_Opr reg = rlock_result(x);
1594   LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
1595   if (!x->klass()->is_loaded()) {
1596     tmp3 = new_register(objectType);
1597   }
1598   __ checkcast(reg, obj.result(), x->klass(),
1599                new_register(objectType), new_register(objectType), tmp3,
1600                x->direct_compare(), info_for_exception, patching_info, stub,
1601                x->profiled_method(), x->profiled_bci());
1602 }
1603 
1604 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
1605   LIRItem obj(x->obj(), this);
1606 
1607   // result and test object may not be in same register
1608   LIR_Opr reg = rlock_result(x);
1609   CodeEmitInfo* patching_info = NULL;
1610   if ((!x->klass()->is_loaded() || PatchALot)) {
1611     // must do this before locking the destination register as an oop register
1612     patching_info = state_for(x, x->state_before());
1613   }
1614   obj.load_item();
1615   LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
1616   if (!x->klass()->is_loaded()) {
1617     tmp3 = new_register(objectType);
1618   }
1619   __ instanceof(reg, obj.result(), x->klass(),
1620                 new_register(objectType), new_register(objectType), tmp3,
1621                 x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());
1622 }
1623 
1624 void LIRGenerator::do_If(If* x) {
1625   assert(x->number_of_sux() == 2, "inconsistency");
1626   ValueTag tag = x->x()->type()->tag();
1627 
1628   If::Condition cond = x->cond();
1629 
1630   LIRItem xitem(x->x(), this);
1631   LIRItem yitem(x->y(), this);
1632   LIRItem* xin = &xitem;
1633   LIRItem* yin = &yitem;
1634 
1635   xin->load_item();
1636 
1637   if (yin->is_constant()) {
1638     if (tag == longTag
1639         && Assembler::operand_valid_for_add_sub_immediate(yin->get_jlong_constant())) {
1640       yin->dont_load_item();
1641     } else if (tag == intTag
1642         && Assembler::operand_valid_for_add_sub_immediate(yin->get_jint_constant())) {
1643       yin->dont_load_item();
1644     } else if (tag == addressTag
1645         && Assembler::operand_valid_for_add_sub_immediate(yin->get_address_constant())) {
1646       yin->dont_load_item();
1647     } else if (tag == objectTag && yin->get_jobject_constant()->is_null_object()) {
1648       yin->dont_load_item();
1649     } else {
1650       yin->load_item();
1651     }
1652   } else {
1653     yin->load_item();
1654   }
1655 
1656   set_no_result(x);
1657 
1658   LIR_Opr left = xin->result();
1659   LIR_Opr right = yin->result();
1660   LIR_Condition lir_c = lir_cond(cond);
1661 
1662   // add safepoint before generating condition code so it can be recomputed
1663   if (x->is_safepoint()) {
1664     // increment backedge counter if needed
1665     increment_backedge_counter_conditionally(lir_cond(cond), left, right, state_for(x, x->state_before()),
1666         x->tsux()->bci(), x->fsux()->bci(), x->profiled_bci());
1667     __ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before()));
1668   }
1669 
1670 
1671 #ifdef __SOFTFP__
1672   if(x->x()->type()->is_float_kind() && !(hasFPU())) {// FPU-less cores
1673     address entry;
1674     bool unordered_flag = x->unordered_is_true() != (lir_c == lir_cond_greater || lir_c == lir_cond_lessEqual);
1675     if (x->x()->type()->is_float()) {
1676       entry = CAST_FROM_FN_PTR(address, unordered_flag ? SharedRuntime::fcmpg : SharedRuntime::fcmpl);
1677     } else if (x->x()->type()->is_double()) {
1678       entry = CAST_FROM_FN_PTR(address, unordered_flag ? SharedRuntime::dcmpg : SharedRuntime::dcmpl);
1679     } else {
1680         ShouldNotReachHere();
1681     }
1682 
1683     LIR_Opr fcmp_res = call_runtime(x->x(), x->y(), entry, intType, NULL);
1684     LIR_Opr zero = LIR_OprFact::intConst(0);
1685     __ cmp(lir_c, fcmp_res, zero);
1686   } else
1687 #endif
1688   {
1689   __ cmp(lir_c, left, right);
1690   }
1691 
1692   // Generate branch profiling. Profiling code doesn't kill flags.
1693   profile_branch(x, cond);
1694   move_to_phi(x->state());
1695 
1696   if (x->x()->type()->is_float_kind()) {
1697       if(hasFPU()) {
1698         __ branch(lir_c, right->type(), x->tsux(), x->usux());
1699       } else {
1700         __ branch(lir_c, T_INT, x->tsux());
1701       }
1702   } else
1703   {
1704     __ branch(lir_c, right->type(), x->tsux());
1705   }
1706   assert(x->default_sux() == x->fsux(), "wrong destination above");
1707   __ jump(x->default_sux());
1708 }
1709 
1710 LIR_Opr LIRGenerator::getThreadPointer() {
1711    return FrameMap::as_pointer_opr(rthread);
1712 }
1713 
1714 void LIRGenerator::trace_block_entry(BlockBegin* block) {
1715   __ move(LIR_OprFact::intConst(block->block_id()), FrameMap::r0_opr);
1716   LIR_OprList* args = new LIR_OprList(1);
1717   args->append(FrameMap::r0_opr);
1718   address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);
1719   __ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);
1720 }
1721 
1722 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,
1723                                         CodeEmitInfo* info) {
1724   if (value->is_double_cpu()) {
1725     __ move(value, FrameMap::long0_opr);
1726     __ volatile_store_mem_reg(FrameMap::long0_opr, address, info);
1727   } else {
1728     __ volatile_store_mem_reg(value, address, info);
1729   }
1730 }
1731 
1732 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,
1733                                        CodeEmitInfo* info) {
1734   if (result->is_double_cpu()) {
1735     __ volatile_load_mem_reg(address, FrameMap::long0_opr, info);
1736     __ move(FrameMap::long0_opr, result);
1737   } else {
1738     __ volatile_load_mem_reg(address, result, info);
1739   }
1740 }