annotate src/hotspot/cpu/sparc/c1_LIRGenerator_sparc.cpp @ 53643:7d3cde494494

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