annotate src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp @ 50458:c63bdf53a1a7

8202399: [C1] LIRGenerator::do_CheckCast needs to exclude is_invokespecial_receiver_check() when using PatchAlot Reviewed-by: kvn Contributed-by: Vladimir Ivanov <vladimir.x.ivanov@oracle.com>
author dholmes
date Mon, 30 Apr 2018 20:29:19 -0400
parents 4bb58f644e4e
children 9010b580d8a9
rev   line source
goetz@42065 1 /*
rraghavan@49862 2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
lucy@46315 3 * Copyright (c) 2016, 2017, SAP SE. All rights reserved.
goetz@42065 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
goetz@42065 5 *
goetz@42065 6 * This code is free software; you can redistribute it and/or modify it
goetz@42065 7 * under the terms of the GNU General Public License version 2 only, as
goetz@42065 8 * published by the Free Software Foundation.
goetz@42065 9 *
goetz@42065 10 * This code is distributed in the hope that it will be useful, but WITHOUT
goetz@42065 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
goetz@42065 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
goetz@42065 13 * version 2 for more details (a copy is included in the LICENSE file that
goetz@42065 14 * accompanied this code).
goetz@42065 15 *
goetz@42065 16 * You should have received a copy of the GNU General Public License version
goetz@42065 17 * 2 along with this work; if not, write to the Free Software Foundation,
goetz@42065 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
goetz@42065 19 *
goetz@42065 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
goetz@42065 21 * or visit www.oracle.com if you need additional information or have any
goetz@42065 22 * questions.
goetz@42065 23 *
goetz@42065 24 */
goetz@42065 25
goetz@42065 26 #include "precompiled.hpp"
goetz@42065 27 #include "c1/c1_Compilation.hpp"
goetz@42065 28 #include "c1/c1_FrameMap.hpp"
goetz@42065 29 #include "c1/c1_Instruction.hpp"
goetz@42065 30 #include "c1/c1_LIRAssembler.hpp"
goetz@42065 31 #include "c1/c1_LIRGenerator.hpp"
goetz@42065 32 #include "c1/c1_Runtime1.hpp"
goetz@42065 33 #include "c1/c1_ValueStack.hpp"
goetz@42065 34 #include "ci/ciArray.hpp"
goetz@42065 35 #include "ci/ciObjArrayKlass.hpp"
goetz@42065 36 #include "ci/ciTypeArrayKlass.hpp"
goetz@42065 37 #include "runtime/sharedRuntime.hpp"
goetz@42065 38 #include "runtime/stubRoutines.hpp"
goetz@42065 39 #include "vmreg_s390.inline.hpp"
goetz@42065 40
goetz@42065 41 #ifdef ASSERT
goetz@42065 42 #define __ gen()->lir(__FILE__, __LINE__)->
goetz@42065 43 #else
goetz@42065 44 #define __ gen()->lir()->
goetz@42065 45 #endif
goetz@42065 46
goetz@42065 47 void LIRItem::load_byte_item() {
goetz@42065 48 // Byte loads use same registers as other loads.
goetz@42065 49 load_item();
goetz@42065 50 }
goetz@42065 51
goetz@42065 52 void LIRItem::load_nonconstant(int bits) {
goetz@42065 53 LIR_Opr r = value()->operand();
goetz@42065 54 if (_gen->can_inline_as_constant(value(), bits)) {
goetz@42065 55 if (!r->is_constant()) {
goetz@42065 56 r = LIR_OprFact::value_type(value()->type());
goetz@42065 57 }
goetz@42065 58 _result = r;
goetz@42065 59 } else {
goetz@42065 60 load_item();
goetz@42065 61 }
goetz@42065 62 }
goetz@42065 63
goetz@42065 64 //--------------------------------------------------------------
goetz@42065 65 // LIRGenerator
goetz@42065 66 //--------------------------------------------------------------
goetz@42065 67
goetz@42065 68 LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::as_oop_opr(Z_EXC_OOP); }
goetz@42065 69 LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::as_opr(Z_EXC_PC); }
goetz@42065 70 LIR_Opr LIRGenerator::divInOpr() { return FrameMap::Z_R11_opr; }
goetz@42065 71 LIR_Opr LIRGenerator::divOutOpr() { return FrameMap::Z_R11_opr; }
goetz@42065 72 LIR_Opr LIRGenerator::remOutOpr() { return FrameMap::Z_R10_opr; }
goetz@42065 73 LIR_Opr LIRGenerator::ldivInOpr() { return FrameMap::Z_R11_long_opr; }
goetz@42065 74 LIR_Opr LIRGenerator::ldivOutOpr() { return FrameMap::Z_R11_long_opr; }
goetz@42065 75 LIR_Opr LIRGenerator::lremOutOpr() { return FrameMap::Z_R10_long_opr; }
goetz@42065 76 LIR_Opr LIRGenerator::syncLockOpr() { return new_register(T_INT); }
goetz@42065 77 LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::Z_R13_opr; }
goetz@42065 78 LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; }
goetz@42065 79
goetz@42065 80 LIR_Opr LIRGenerator::result_register_for (ValueType* type, bool callee) {
goetz@42065 81 LIR_Opr opr;
goetz@42065 82 switch (type->tag()) {
goetz@42065 83 case intTag: opr = FrameMap::Z_R2_opr; break;
goetz@42065 84 case objectTag: opr = FrameMap::Z_R2_oop_opr; break;
goetz@42065 85 case longTag: opr = FrameMap::Z_R2_long_opr; break;
goetz@42065 86 case floatTag: opr = FrameMap::Z_F0_opr; break;
goetz@42065 87 case doubleTag: opr = FrameMap::Z_F0_double_opr; break;
goetz@42065 88
goetz@42065 89 case addressTag:
goetz@42065 90 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
goetz@42065 91 }
goetz@42065 92
goetz@42065 93 assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
goetz@42065 94 return opr;
goetz@42065 95 }
goetz@42065 96
goetz@42065 97 LIR_Opr LIRGenerator::rlock_byte(BasicType type) {
goetz@42065 98 return new_register(T_INT);
goetz@42065 99 }
goetz@42065 100
goetz@42065 101 //--------- Loading items into registers. --------------------------------
goetz@42065 102
goetz@42065 103 // z/Architecture cannot inline all constants.
goetz@42065 104 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
goetz@42065 105 if (v->type()->as_IntConstant() != NULL) {
goetz@42065 106 return Immediate::is_simm16(v->type()->as_IntConstant()->value());
goetz@42065 107 } else if (v->type()->as_LongConstant() != NULL) {
goetz@42065 108 return Immediate::is_simm16(v->type()->as_LongConstant()->value());
goetz@42065 109 } else if (v->type()->as_ObjectConstant() != NULL) {
goetz@42065 110 return v->type()->as_ObjectConstant()->value()->is_null_object();
goetz@42065 111 } else {
goetz@42065 112 return false;
goetz@42065 113 }
goetz@42065 114 }
goetz@42065 115
goetz@42065 116 bool LIRGenerator::can_inline_as_constant(Value i, int bits) const {
goetz@42065 117 if (i->type()->as_IntConstant() != NULL) {
goetz@42065 118 return Assembler::is_simm(i->type()->as_IntConstant()->value(), bits);
goetz@42065 119 } else if (i->type()->as_LongConstant() != NULL) {
goetz@42065 120 return Assembler::is_simm(i->type()->as_LongConstant()->value(), bits);
goetz@42065 121 } else {
goetz@42065 122 return can_store_as_constant(i, as_BasicType(i->type()));
goetz@42065 123 }
goetz@42065 124 }
goetz@42065 125
goetz@42065 126 bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {
goetz@42065 127 if (c->type() == T_INT) {
goetz@42065 128 return Immediate::is_simm20(c->as_jint());
goetz@42065 129 } else if (c->type() == T_LONG) {
goetz@42065 130 return Immediate::is_simm20(c->as_jlong());
goetz@42065 131 }
goetz@42065 132 return false;
goetz@42065 133 }
goetz@42065 134
goetz@42065 135 LIR_Opr LIRGenerator::safepoint_poll_register() {
goetz@42065 136 return new_register(longType);
goetz@42065 137 }
goetz@42065 138
goetz@42065 139 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
goetz@42065 140 int shift, int disp, BasicType type) {
goetz@42065 141 assert(base->is_register(), "must be");
goetz@42065 142 if (index->is_constant()) {
eosterlund@50431 143 intx large_disp = disp;
eosterlund@50431 144 LIR_Const *constant = index->as_constant_ptr();
eosterlund@50431 145 if (constant->type() == T_LONG) {
eosterlund@50431 146 large_disp += constant->as_jlong() << shift;
eosterlund@50431 147 } else {
eosterlund@50431 148 large_disp += (intx)(constant->as_jint()) << shift;
eosterlund@50431 149 }
goetz@42065 150 if (Displacement::is_validDisp(large_disp)) {
goetz@42065 151 return new LIR_Address(base, large_disp, type);
goetz@42065 152 }
goetz@42065 153 // Index is illegal so replace it with the displacement loaded into a register.
goetz@42065 154 index = new_pointer_register();
goetz@42065 155 __ move(LIR_OprFact::intptrConst(large_disp), index);
goetz@42065 156 return new LIR_Address(base, index, type);
goetz@42065 157 } else {
goetz@42065 158 if (shift > 0) {
goetz@42065 159 LIR_Opr tmp = new_pointer_register();
goetz@42065 160 __ shift_left(index, shift, tmp);
goetz@42065 161 index = tmp;
goetz@42065 162 }
goetz@42065 163 return new LIR_Address(base, index, disp, type);
goetz@42065 164 }
goetz@42065 165 }
goetz@42065 166
goetz@42065 167 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,
eosterlund@50431 168 BasicType type) {
goetz@42065 169 int elem_size = type2aelembytes(type);
goetz@42065 170 int shift = exact_log2(elem_size);
goetz@42065 171 int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type);
goetz@42065 172
goetz@42065 173 LIR_Address* addr;
goetz@42065 174 if (index_opr->is_constant()) {
goetz@42065 175 addr = new LIR_Address(array_opr,
goetz@42065 176 offset_in_bytes + (intx)(index_opr->as_jint()) * elem_size, type);
goetz@42065 177 } else {
goetz@42065 178 if (index_opr->type() == T_INT) {
goetz@42065 179 LIR_Opr tmp = new_register(T_LONG);
goetz@42065 180 __ convert(Bytecodes::_i2l, index_opr, tmp);
goetz@42065 181 index_opr = tmp;
goetz@42065 182 }
goetz@42065 183 if (shift > 0) {
goetz@42065 184 __ shift_left(index_opr, shift, index_opr);
goetz@42065 185 }
goetz@42065 186 addr = new LIR_Address(array_opr,
goetz@42065 187 index_opr,
goetz@42065 188 offset_in_bytes, type);
goetz@42065 189 }
eosterlund@50431 190 return addr;
goetz@42065 191 }
goetz@42065 192
goetz@42065 193 LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {
goetz@42065 194 LIR_Opr r = LIR_OprFact::illegalOpr;
goetz@42065 195 if (type == T_LONG) {
goetz@42065 196 r = LIR_OprFact::longConst(x);
goetz@42065 197 } else if (type == T_INT) {
goetz@42065 198 r = LIR_OprFact::intConst(x);
goetz@42065 199 } else {
goetz@42065 200 ShouldNotReachHere();
goetz@42065 201 }
goetz@42065 202 return r;
goetz@42065 203 }
goetz@42065 204
goetz@42065 205 void LIRGenerator::increment_counter(address counter, BasicType type, int step) {
goetz@42065 206 LIR_Opr pointer = new_pointer_register();
goetz@42065 207 __ move(LIR_OprFact::intptrConst(counter), pointer);
goetz@42065 208 LIR_Address* addr = new LIR_Address(pointer, type);
goetz@42065 209 increment_counter(addr, step);
goetz@42065 210 }
goetz@42065 211
goetz@42065 212 void LIRGenerator::increment_counter(LIR_Address* addr, int step) {
goetz@42065 213 __ add((LIR_Opr)addr, LIR_OprFact::intConst(step), (LIR_Opr)addr);
goetz@42065 214 }
goetz@42065 215
goetz@42065 216 void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {
goetz@42065 217 LIR_Opr scratch = FrameMap::Z_R1_opr;
goetz@42065 218 __ load(new LIR_Address(base, disp, T_INT), scratch, info);
goetz@42065 219 __ cmp(condition, scratch, c);
goetz@42065 220 }
goetz@42065 221
goetz@42065 222 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {
goetz@42065 223 __ cmp_reg_mem(condition, reg, new LIR_Address(base, disp, type), info);
goetz@42065 224 }
goetz@42065 225
goetz@42065 226 bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) {
goetz@42065 227 if (tmp->is_valid()) {
goetz@42065 228 if (is_power_of_2(c + 1)) {
goetz@42065 229 __ move(left, tmp);
goetz@42065 230 __ shift_left(left, log2_intptr(c + 1), left);
goetz@42065 231 __ sub(left, tmp, result);
goetz@42065 232 return true;
goetz@42065 233 } else if (is_power_of_2(c - 1)) {
goetz@42065 234 __ move(left, tmp);
goetz@42065 235 __ shift_left(left, log2_intptr(c - 1), left);
goetz@42065 236 __ add(left, tmp, result);
goetz@42065 237 return true;
goetz@42065 238 }
goetz@42065 239 }
goetz@42065 240 return false;
goetz@42065 241 }
goetz@42065 242
goetz@42065 243 void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {
goetz@42065 244 BasicType type = item->type();
goetz@42065 245 __ store(item, new LIR_Address(FrameMap::Z_SP_opr, in_bytes(offset_from_sp), type));
goetz@42065 246 }
goetz@42065 247
goetz@42065 248 //----------------------------------------------------------------------
goetz@42065 249 // visitor functions
goetz@42065 250 //----------------------------------------------------------------------
goetz@42065 251
eosterlund@50431 252 void LIRGenerator::array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci) {
eosterlund@50431 253 LIR_Opr tmp1 = new_register(objectType);
eosterlund@50431 254 LIR_Opr tmp2 = new_register(objectType);
eosterlund@50431 255 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
eosterlund@50431 256 __ store_check(value, array, tmp1, tmp2, tmp3, store_check_info, profiled_method, profiled_bci);
goetz@42065 257 }
goetz@42065 258
goetz@42065 259 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
goetz@42065 260 assert(x->is_pinned(),"");
goetz@42065 261 LIRItem obj(x->obj(), this);
goetz@42065 262 obj.load_item();
goetz@42065 263
goetz@42065 264 set_no_result(x);
goetz@42065 265
goetz@42065 266 // "lock" stores the address of the monitor stack slot, so this is not an oop.
goetz@42065 267 LIR_Opr lock = new_register(T_INT);
goetz@42065 268
goetz@42065 269 CodeEmitInfo* info_for_exception = NULL;
goetz@42065 270 if (x->needs_null_check()) {
goetz@42065 271 info_for_exception = state_for (x);
goetz@42065 272 }
goetz@42065 273 // This CodeEmitInfo must not have the xhandlers because here the
goetz@42065 274 // object is already locked (xhandlers expect object to be unlocked).
goetz@42065 275 CodeEmitInfo* info = state_for (x, x->state(), true);
goetz@42065 276 monitor_enter(obj.result(), lock, syncTempOpr(), LIR_OprFact::illegalOpr,
goetz@42065 277 x->monitor_no(), info_for_exception, info);
goetz@42065 278 }
goetz@42065 279
goetz@42065 280 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
goetz@42065 281 assert(x->is_pinned(),"");
goetz@42065 282
goetz@42065 283 LIRItem obj(x->obj(), this);
goetz@42065 284 obj.dont_load_item();
goetz@42065 285
goetz@42065 286 LIR_Opr lock = new_register(T_INT);
goetz@42065 287 LIR_Opr obj_temp = new_register(T_INT);
goetz@42065 288 set_no_result(x);
goetz@42065 289 monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());
goetz@42065 290 }
goetz@42065 291
goetz@42065 292 // _ineg, _lneg, _fneg, _dneg
goetz@42065 293 void LIRGenerator::do_NegateOp(NegateOp* x) {
goetz@42065 294 LIRItem value(x->x(), this);
goetz@42065 295 value.load_item();
goetz@42065 296 LIR_Opr reg = rlock_result(x);
goetz@42065 297 __ negate(value.result(), reg);
goetz@42065 298 }
goetz@42065 299
goetz@42065 300 // for _fadd, _fmul, _fsub, _fdiv, _frem
goetz@42065 301 // _dadd, _dmul, _dsub, _ddiv, _drem
goetz@42065 302 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {
goetz@42065 303 LIRItem left(x->x(), this);
goetz@42065 304 LIRItem right(x->y(), this);
goetz@42065 305 LIRItem* left_arg = &left;
goetz@42065 306 LIRItem* right_arg = &right;
goetz@42065 307 assert(!left.is_stack(), "can't both be memory operands");
goetz@42065 308 left.load_item();
goetz@42065 309
goetz@42065 310 if (right.is_register() || right.is_constant()) {
goetz@42065 311 right.load_item();
goetz@42065 312 } else {
goetz@42065 313 right.dont_load_item();
goetz@42065 314 }
goetz@42065 315
goetz@42065 316 if ((x->op() == Bytecodes::_frem) || (x->op() == Bytecodes::_drem)) {
goetz@42065 317 address entry;
goetz@42065 318 switch (x->op()) {
goetz@42065 319 case Bytecodes::_frem:
goetz@42065 320 entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem);
goetz@42065 321 break;
goetz@42065 322 case Bytecodes::_drem:
goetz@42065 323 entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem);
goetz@42065 324 break;
goetz@42065 325 default:
goetz@42065 326 ShouldNotReachHere();
goetz@42065 327 }
goetz@42065 328 LIR_Opr result = call_runtime(x->x(), x->y(), entry, x->type(), NULL);
goetz@42065 329 set_result(x, result);
goetz@42065 330 } else {
goetz@42065 331 LIR_Opr reg = rlock(x);
goetz@42065 332 LIR_Opr tmp = LIR_OprFact::illegalOpr;
goetz@42065 333 arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), x->is_strictfp(), tmp);
goetz@42065 334 set_result(x, reg);
goetz@42065 335 }
goetz@42065 336 }
goetz@42065 337
goetz@42065 338 // for _ladd, _lmul, _lsub, _ldiv, _lrem
goetz@42065 339 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {
goetz@42065 340 if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) {
goetz@42065 341 // Use shifts if divisior is a power of 2 otherwise use DSGR instruction.
goetz@42065 342 // Instruction: DSGR R1, R2
goetz@42065 343 // input : R1+1: dividend (R1, R1+1 designate a register pair, R1 must be even)
goetz@42065 344 // R2: divisor
goetz@42065 345 //
goetz@42065 346 // output: R1+1: quotient
goetz@42065 347 // R1: remainder
goetz@42065 348 //
goetz@42065 349 // Register selection: R1: Z_R10
goetz@42065 350 // R1+1: Z_R11
goetz@42065 351 // R2: to be chosen by register allocator (linear scan)
goetz@42065 352
goetz@42065 353 // R1, and R1+1 will be destroyed.
goetz@42065 354
goetz@42065 355 LIRItem right(x->y(), this);
goetz@42065 356 LIRItem left(x->x() , this); // Visit left second, so that the is_register test is valid.
goetz@42065 357
goetz@42065 358 // Call state_for before load_item_force because state_for may
goetz@42065 359 // force the evaluation of other instructions that are needed for
goetz@42065 360 // correct debug info. Otherwise the live range of the fix
goetz@42065 361 // register might be too long.
goetz@42065 362 CodeEmitInfo* info = state_for (x);
goetz@42065 363
goetz@42065 364 LIR_Opr result = rlock_result(x);
goetz@42065 365 LIR_Opr result_reg = result;
goetz@42065 366 LIR_Opr tmp = LIR_OprFact::illegalOpr;
goetz@42065 367 LIR_Opr divisor_opr = right.result();
goetz@42065 368 if (divisor_opr->is_constant() && is_power_of_2(divisor_opr->as_jlong())) {
goetz@42065 369 left.load_item();
goetz@42065 370 right.dont_load_item();
goetz@42065 371 } else {
goetz@42065 372 left.load_item_force(ldivInOpr());
goetz@42065 373 right.load_item();
goetz@42065 374
goetz@42065 375 // DSGR instruction needs register pair.
goetz@42065 376 if (x->op() == Bytecodes::_ldiv) {
goetz@42065 377 result_reg = ldivOutOpr();
goetz@42065 378 tmp = lremOutOpr();
goetz@42065 379 } else {
goetz@42065 380 result_reg = lremOutOpr();
goetz@42065 381 tmp = ldivOutOpr();
goetz@42065 382 }
goetz@42065 383 }
goetz@42065 384
goetz@42065 385 if (!ImplicitDiv0Checks) {
goetz@42065 386 __ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));
goetz@42065 387 __ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info));
goetz@42065 388 // Idiv/irem cannot trap (passing info would generate an assertion).
goetz@42065 389 info = NULL;
goetz@42065 390 }
goetz@42065 391
goetz@42065 392 if (x->op() == Bytecodes::_lrem) {
goetz@42065 393 __ irem(left.result(), right.result(), result_reg, tmp, info);
goetz@42065 394 } else if (x->op() == Bytecodes::_ldiv) {
goetz@42065 395 __ idiv(left.result(), right.result(), result_reg, tmp, info);
goetz@42065 396 } else {
goetz@42065 397 ShouldNotReachHere();
goetz@42065 398 }
goetz@42065 399
goetz@42065 400 if (result_reg != result) {
goetz@42065 401 __ move(result_reg, result);
goetz@42065 402 }
goetz@42065 403 } else {
goetz@42065 404 LIRItem left(x->x(), this);
goetz@42065 405 LIRItem right(x->y(), this);
goetz@42065 406
goetz@42065 407 left.load_item();
goetz@42065 408 right.load_nonconstant(32);
goetz@42065 409 rlock_result(x);
goetz@42065 410 arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);
goetz@42065 411 }
goetz@42065 412 }
goetz@42065 413
goetz@42065 414 // for: _iadd, _imul, _isub, _idiv, _irem
goetz@42065 415 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {
goetz@42065 416 if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {
goetz@42065 417 // Use shifts if divisior is a power of 2 otherwise use DSGFR instruction.
goetz@42065 418 // Instruction: DSGFR R1, R2
goetz@42065 419 // input : R1+1: dividend (R1, R1+1 designate a register pair, R1 must be even)
goetz@42065 420 // R2: divisor
goetz@42065 421 //
goetz@42065 422 // output: R1+1: quotient
goetz@42065 423 // R1: remainder
goetz@42065 424 //
goetz@42065 425 // Register selection: R1: Z_R10
goetz@42065 426 // R1+1: Z_R11
goetz@42065 427 // R2: To be chosen by register allocator (linear scan).
goetz@42065 428
goetz@42065 429 // R1, and R1+1 will be destroyed.
goetz@42065 430
goetz@42065 431 LIRItem right(x->y(), this);
goetz@42065 432 LIRItem left(x->x() , this); // Visit left second, so that the is_register test is valid.
goetz@42065 433
goetz@42065 434 // Call state_for before load_item_force because state_for may
goetz@42065 435 // force the evaluation of other instructions that are needed for
goetz@42065 436 // correct debug info. Otherwise the live range of the fix
goetz@42065 437 // register might be too long.
goetz@42065 438 CodeEmitInfo* info = state_for (x);
goetz@42065 439
goetz@42065 440 LIR_Opr result = rlock_result(x);
goetz@42065 441 LIR_Opr result_reg = result;
goetz@42065 442 LIR_Opr tmp = LIR_OprFact::illegalOpr;
goetz@42065 443 LIR_Opr divisor_opr = right.result();
goetz@42065 444 if (divisor_opr->is_constant() && is_power_of_2(divisor_opr->as_jint())) {
goetz@42065 445 left.load_item();
goetz@42065 446 right.dont_load_item();
goetz@42065 447 } else {
goetz@42065 448 left.load_item_force(divInOpr());
goetz@42065 449 right.load_item();
goetz@42065 450
goetz@42065 451 // DSGFR instruction needs register pair.
goetz@42065 452 if (x->op() == Bytecodes::_idiv) {
goetz@42065 453 result_reg = divOutOpr();
goetz@42065 454 tmp = remOutOpr();
goetz@42065 455 } else {
goetz@42065 456 result_reg = remOutOpr();
goetz@42065 457 tmp = divOutOpr();
goetz@42065 458 }
goetz@42065 459 }
goetz@42065 460
goetz@42065 461 if (!ImplicitDiv0Checks) {
goetz@42065 462 __ cmp(lir_cond_equal, right.result(), LIR_OprFact::intConst(0));
goetz@42065 463 __ branch(lir_cond_equal, T_INT, new DivByZeroStub(info));
goetz@42065 464 // Idiv/irem cannot trap (passing info would generate an assertion).
goetz@42065 465 info = NULL;
goetz@42065 466 }
goetz@42065 467
goetz@42065 468 if (x->op() == Bytecodes::_irem) {
goetz@42065 469 __ irem(left.result(), right.result(), result_reg, tmp, info);
goetz@42065 470 } else if (x->op() == Bytecodes::_idiv) {
goetz@42065 471 __ idiv(left.result(), right.result(), result_reg, tmp, info);
goetz@42065 472 } else {
goetz@42065 473 ShouldNotReachHere();
goetz@42065 474 }
goetz@42065 475
goetz@42065 476 if (result_reg != result) {
goetz@42065 477 __ move(result_reg, result);
goetz@42065 478 }
goetz@42065 479 } else {
goetz@42065 480 LIRItem left(x->x(), this);
goetz@42065 481 LIRItem right(x->y(), this);
goetz@42065 482 LIRItem* left_arg = &left;
goetz@42065 483 LIRItem* right_arg = &right;
goetz@42065 484 if (x->is_commutative() && left.is_stack() && right.is_register()) {
goetz@42065 485 // swap them if left is real stack (or cached) and right is real register(not cached)
goetz@42065 486 left_arg = &right;
goetz@42065 487 right_arg = &left;
goetz@42065 488 }
goetz@42065 489
goetz@42065 490 left_arg->load_item();
goetz@42065 491
goetz@42065 492 // Do not need to load right, as we can handle stack and constants.
goetz@42065 493 if (x->op() == Bytecodes::_imul) {
goetz@42065 494 bool use_tmp = false;
goetz@42065 495 if (right_arg->is_constant()) {
goetz@42065 496 int iconst = right_arg->get_jint_constant();
goetz@42065 497 if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) {
goetz@42065 498 use_tmp = true;
goetz@42065 499 }
goetz@42065 500 }
goetz@42065 501 right_arg->dont_load_item();
goetz@42065 502 LIR_Opr tmp = LIR_OprFact::illegalOpr;
goetz@42065 503 if (use_tmp) {
goetz@42065 504 tmp = new_register(T_INT);
goetz@42065 505 }
goetz@42065 506 rlock_result(x);
goetz@42065 507
goetz@42065 508 arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);
goetz@42065 509 } else {
goetz@42065 510 right_arg->dont_load_item();
goetz@42065 511 rlock_result(x);
goetz@42065 512 LIR_Opr tmp = LIR_OprFact::illegalOpr;
goetz@42065 513 arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);
goetz@42065 514 }
goetz@42065 515 }
goetz@42065 516 }
goetz@42065 517
goetz@42065 518 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {
goetz@42065 519 // If an operand with use count 1 is the left operand, then it is
goetz@42065 520 // likely that no move for 2-operand-LIR-form is necessary.
goetz@42065 521 if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
goetz@42065 522 x->swap_operands();
goetz@42065 523 }
goetz@42065 524
goetz@42065 525 ValueTag tag = x->type()->tag();
goetz@42065 526 assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");
goetz@42065 527 switch (tag) {
goetz@42065 528 case floatTag:
goetz@42065 529 case doubleTag: do_ArithmeticOp_FPU(x); return;
goetz@42065 530 case longTag: do_ArithmeticOp_Long(x); return;
goetz@42065 531 case intTag: do_ArithmeticOp_Int(x); return;
goetz@42065 532 }
goetz@42065 533 ShouldNotReachHere();
goetz@42065 534 }
goetz@42065 535
goetz@42065 536 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr
goetz@42065 537 void LIRGenerator::do_ShiftOp(ShiftOp* x) {
goetz@42065 538 // count must always be in rcx
goetz@42065 539 LIRItem value(x->x(), this);
goetz@42065 540 LIRItem count(x->y(), this);
goetz@42065 541
goetz@42065 542 ValueTag elemType = x->type()->tag();
goetz@42065 543 bool must_load_count = !count.is_constant();
goetz@42065 544 if (must_load_count) {
goetz@42065 545 count.load_item();
goetz@42065 546 } else {
goetz@42065 547 count.dont_load_item();
goetz@42065 548 }
goetz@42065 549 value.load_item();
goetz@42065 550 LIR_Opr reg = rlock_result(x);
goetz@42065 551
goetz@42065 552 shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);
goetz@42065 553 }
goetz@42065 554
goetz@42065 555 // _iand, _land, _ior, _lor, _ixor, _lxor
goetz@42065 556 void LIRGenerator::do_LogicOp(LogicOp* x) {
goetz@42065 557 // IF an operand with use count 1 is the left operand, then it is
goetz@42065 558 // likely that no move for 2-operand-LIR-form is necessary.
goetz@42065 559 if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
goetz@42065 560 x->swap_operands();
goetz@42065 561 }
goetz@42065 562
goetz@42065 563 LIRItem left(x->x(), this);
goetz@42065 564 LIRItem right(x->y(), this);
goetz@42065 565
goetz@42065 566 left.load_item();
goetz@42065 567 right.load_nonconstant(32);
goetz@42065 568 LIR_Opr reg = rlock_result(x);
goetz@42065 569
goetz@42065 570 logic_op(x->op(), reg, left.result(), right.result());
goetz@42065 571 }
goetz@42065 572
goetz@42065 573 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg
goetz@42065 574 void LIRGenerator::do_CompareOp(CompareOp* x) {
goetz@42065 575 LIRItem left(x->x(), this);
goetz@42065 576 LIRItem right(x->y(), this);
goetz@42065 577 left.load_item();
goetz@42065 578 right.load_item();
goetz@42065 579 LIR_Opr reg = rlock_result(x);
goetz@42065 580 if (x->x()->type()->is_float_kind()) {
goetz@42065 581 Bytecodes::Code code = x->op();
goetz@42065 582 __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));
goetz@42065 583 } else if (x->x()->type()->tag() == longTag) {
goetz@42065 584 __ lcmp2int(left.result(), right.result(), reg);
goetz@42065 585 } else {
goetz@42065 586 ShouldNotReachHere();
goetz@42065 587 }
goetz@42065 588 }
goetz@42065 589
eosterlund@50431 590 LIR_Opr LIRGenerator::atomic_cmpxchg(BasicType type, LIR_Opr addr, LIRItem& cmp_value, LIRItem& new_value) {
eosterlund@50431 591 LIR_Opr t1 = LIR_OprFact::illegalOpr;
eosterlund@50431 592 LIR_Opr t2 = LIR_OprFact::illegalOpr;
eosterlund@50431 593 cmp_value.load_item();
eosterlund@50431 594 new_value.load_item();
eosterlund@50431 595 if (type == T_OBJECT) {
eosterlund@50431 596 if (UseCompressedOops) {
eosterlund@50431 597 t1 = new_register(T_OBJECT);
eosterlund@50431 598 t2 = new_register(T_OBJECT);
eosterlund@50431 599 }
eosterlund@50431 600 __ cas_obj(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), t1, t2);
eosterlund@50431 601 } else if (type == T_INT) {
eosterlund@50431 602 __ cas_int(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), t1, t2);
eosterlund@50431 603 } else if (type == T_LONG) {
eosterlund@50431 604 __ cas_long(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), t1, t2);
goetz@42065 605 } else {
goetz@42065 606 ShouldNotReachHere();
goetz@42065 607 }
goetz@42065 608 // Generate conditional move of boolean result.
eosterlund@50431 609 LIR_Opr result = new_register(T_INT);
goetz@42065 610 __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),
eosterlund@50431 611 result, type);
eosterlund@50431 612 return result;
goetz@42065 613 }
goetz@42065 614
eosterlund@50431 615 LIR_Opr LIRGenerator::atomic_xchg(BasicType type, LIR_Opr addr, LIRItem& value) {
eosterlund@50431 616 Unimplemented(); // Currently not supported on this platform.
eosterlund@50431 617 return LIR_OprFact::illegalOpr;
eosterlund@50431 618 }
eosterlund@50431 619
eosterlund@50431 620 LIR_Opr LIRGenerator::atomic_add(BasicType type, LIR_Opr addr, LIRItem& value) {
eosterlund@50431 621 LIR_Opr result = new_register(type);
eosterlund@50431 622 value.load_item();
eosterlund@50431 623 __ xadd(addr, value.result(), result, LIR_OprFact::illegalOpr);
eosterlund@50431 624 return result;
eosterlund@50431 625 }
goetz@42065 626
goetz@42065 627 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {
goetz@42065 628 switch (x->id()) {
goetz@42065 629 case vmIntrinsics::_dabs:
goetz@42065 630 case vmIntrinsics::_dsqrt: {
goetz@42065 631 assert(x->number_of_arguments() == 1, "wrong type");
goetz@42065 632 LIRItem value(x->argument_at(0), this);
goetz@42065 633 value.load_item();
goetz@42065 634 LIR_Opr dst = rlock_result(x);
goetz@42065 635
goetz@42065 636 switch (x->id()) {
goetz@42065 637 case vmIntrinsics::_dsqrt: {
goetz@42065 638 __ sqrt(value.result(), dst, LIR_OprFact::illegalOpr);
goetz@42065 639 break;
goetz@42065 640 }
goetz@42065 641 case vmIntrinsics::_dabs: {
goetz@42065 642 __ abs(value.result(), dst, LIR_OprFact::illegalOpr);
goetz@42065 643 break;
goetz@42065 644 }
goetz@42065 645 }
goetz@42065 646 break;
goetz@42065 647 }
goetz@42065 648 case vmIntrinsics::_dlog10: // fall through
goetz@42065 649 case vmIntrinsics::_dlog: // fall through
goetz@42065 650 case vmIntrinsics::_dsin: // fall through
goetz@42065 651 case vmIntrinsics::_dtan: // fall through
goetz@42065 652 case vmIntrinsics::_dcos: // fall through
goetz@42065 653 case vmIntrinsics::_dexp: {
goetz@42065 654 assert(x->number_of_arguments() == 1, "wrong type");
goetz@42065 655
goetz@42065 656 address runtime_entry = NULL;
goetz@42065 657 switch (x->id()) {
goetz@42065 658 case vmIntrinsics::_dsin:
goetz@42065 659 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
goetz@42065 660 break;
goetz@42065 661 case vmIntrinsics::_dcos:
goetz@42065 662 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
goetz@42065 663 break;
goetz@42065 664 case vmIntrinsics::_dtan:
goetz@42065 665 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
goetz@42065 666 break;
goetz@42065 667 case vmIntrinsics::_dlog:
goetz@42065 668 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);
goetz@42065 669 break;
goetz@42065 670 case vmIntrinsics::_dlog10:
goetz@42065 671 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);
goetz@42065 672 break;
goetz@42065 673 case vmIntrinsics::_dexp:
goetz@42065 674 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);
goetz@42065 675 break;
goetz@42065 676 default:
goetz@42065 677 ShouldNotReachHere();
goetz@42065 678 }
goetz@42065 679
goetz@42065 680 LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL);
goetz@42065 681 set_result(x, result);
goetz@42065 682 break;
goetz@42065 683 }
goetz@42065 684 case vmIntrinsics::_dpow: {
goetz@42065 685 assert(x->number_of_arguments() == 2, "wrong type");
goetz@42065 686 address runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);
goetz@42065 687 LIR_Opr result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_entry, x->type(), NULL);
goetz@42065 688 set_result(x, result);
goetz@42065 689 break;
goetz@42065 690 }
goetz@42065 691 }
goetz@42065 692 }
goetz@42065 693
goetz@42065 694 void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
goetz@42065 695 assert(x->number_of_arguments() == 5, "wrong type");
goetz@42065 696
goetz@42065 697 // Copy stubs possibly call C code, e.g. G1 barriers, so we need to reserve room
goetz@42065 698 // for the C ABI (see frame::z_abi_160).
goetz@42065 699 BasicTypeArray sig; // Empty signature is precise enough.
goetz@42065 700 frame_map()->c_calling_convention(&sig);
goetz@42065 701
goetz@42065 702 // Make all state_for calls early since they can emit code.
goetz@42065 703 CodeEmitInfo* info = state_for (x, x->state());
goetz@42065 704
goetz@42065 705 LIRItem src(x->argument_at(0), this);
goetz@42065 706 LIRItem src_pos(x->argument_at(1), this);
goetz@42065 707 LIRItem dst(x->argument_at(2), this);
goetz@42065 708 LIRItem dst_pos(x->argument_at(3), this);
goetz@42065 709 LIRItem length(x->argument_at(4), this);
goetz@42065 710
goetz@42065 711 // Operands for arraycopy must use fixed registers, otherwise
goetz@42065 712 // LinearScan will fail allocation (because arraycopy always needs a
goetz@42065 713 // call).
goetz@42065 714
goetz@42065 715 src.load_item_force (FrameMap::as_oop_opr(Z_ARG1));
goetz@42065 716 src_pos.load_item_force (FrameMap::as_opr(Z_ARG2));
goetz@42065 717 dst.load_item_force (FrameMap::as_oop_opr(Z_ARG3));
goetz@42065 718 dst_pos.load_item_force (FrameMap::as_opr(Z_ARG4));
goetz@42065 719 length.load_item_force (FrameMap::as_opr(Z_ARG5));
goetz@42065 720
goetz@42065 721 LIR_Opr tmp = FrameMap::as_opr(Z_R7);
goetz@42065 722
goetz@42065 723 set_no_result(x);
goetz@42065 724
goetz@42065 725 int flags;
goetz@42065 726 ciArrayKlass* expected_type;
goetz@42065 727 arraycopy_helper(x, &flags, &expected_type);
goetz@42065 728
goetz@42065 729 __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(),
goetz@42065 730 length.result(), tmp, expected_type, flags, info); // does add_safepoint
goetz@42065 731 }
goetz@42065 732
goetz@42065 733 // _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f
goetz@42065 734 // _i2b, _i2c, _i2s
goetz@42065 735 void LIRGenerator::do_Convert(Convert* x) {
goetz@42065 736 LIRItem value(x->value(), this);
goetz@42065 737
goetz@42065 738 value.load_item();
goetz@42065 739 LIR_Opr reg = rlock_result(x);
goetz@42065 740 __ convert(x->op(), value.result(), reg);
goetz@42065 741 }
goetz@42065 742
goetz@42065 743 void LIRGenerator::do_NewInstance(NewInstance* x) {
goetz@42065 744 print_if_not_loaded(x);
goetz@42065 745
goetz@42065 746 // This instruction can be deoptimized in the slow path : use
goetz@42065 747 // Z_R2 as result register.
goetz@42065 748 const LIR_Opr reg = result_register_for (x->type());
goetz@42065 749
goetz@42065 750 CodeEmitInfo* info = state_for (x, x->state());
goetz@42065 751 LIR_Opr tmp1 = FrameMap::Z_R12_oop_opr;
goetz@42065 752 LIR_Opr tmp2 = FrameMap::Z_R13_oop_opr;
goetz@42065 753 LIR_Opr tmp3 = reg;
goetz@42065 754 LIR_Opr tmp4 = LIR_OprFact::illegalOpr;
goetz@42065 755 LIR_Opr klass_reg = FrameMap::Z_R11_metadata_opr;
goetz@42065 756 new_instance(reg, x->klass(), x->is_unresolved(), tmp1, tmp2, tmp3, tmp4, klass_reg, info);
goetz@42065 757 LIR_Opr result = rlock_result(x);
goetz@42065 758 __ move(reg, result);
goetz@42065 759 }
goetz@42065 760
goetz@42065 761 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
goetz@42065 762 CodeEmitInfo* info = state_for (x, x->state());
goetz@42065 763
goetz@42065 764 LIRItem length(x->length(), this);
goetz@42065 765 length.load_item();
goetz@42065 766
goetz@42065 767 LIR_Opr reg = result_register_for (x->type());
goetz@42065 768 LIR_Opr tmp1 = FrameMap::Z_R12_oop_opr;
goetz@42065 769 LIR_Opr tmp2 = FrameMap::Z_R13_oop_opr;
goetz@42065 770 LIR_Opr tmp3 = reg;
goetz@42065 771 LIR_Opr tmp4 = LIR_OprFact::illegalOpr;
goetz@42065 772 LIR_Opr klass_reg = FrameMap::Z_R11_metadata_opr;
goetz@42065 773 LIR_Opr len = length.result();
goetz@42065 774 BasicType elem_type = x->elt_type();
goetz@42065 775
goetz@42065 776 __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
goetz@42065 777
goetz@42065 778 CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
goetz@42065 779 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);
goetz@42065 780
goetz@42065 781 LIR_Opr result = rlock_result(x);
goetz@42065 782 __ move(reg, result);
goetz@42065 783 }
goetz@42065 784
goetz@42065 785 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
goetz@42065 786 // Evaluate state_for early since it may emit code.
goetz@42065 787 CodeEmitInfo* info = state_for (x, x->state());
goetz@42065 788 // In case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction
goetz@42065 789 // and therefore provide the state before the parameters have been consumed.
goetz@42065 790 CodeEmitInfo* patching_info = NULL;
goetz@42065 791 if (!x->klass()->is_loaded() || PatchALot) {
goetz@42065 792 patching_info = state_for (x, x->state_before());
goetz@42065 793 }
goetz@42065 794
goetz@42065 795 LIRItem length(x->length(), this);
goetz@42065 796 length.load_item();
goetz@42065 797
goetz@42065 798 const LIR_Opr reg = result_register_for (x->type());
goetz@42065 799 LIR_Opr tmp1 = FrameMap::Z_R12_oop_opr;
goetz@42065 800 LIR_Opr tmp2 = FrameMap::Z_R13_oop_opr;
goetz@42065 801 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
goetz@42065 802 LIR_Opr tmp4 = LIR_OprFact::illegalOpr;
goetz@42065 803 LIR_Opr klass_reg = FrameMap::Z_R11_metadata_opr;
goetz@42065 804 LIR_Opr len = length.result();
goetz@42065 805
goetz@42065 806 CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
goetz@42065 807 ciKlass* obj = ciObjArrayKlass::make(x->klass());
goetz@42065 808 if (obj == ciEnv::unloaded_ciobjarrayklass()) {
goetz@42065 809 BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
goetz@42065 810 }
goetz@42065 811 klass2reg_with_patching(klass_reg, obj, patching_info);
goetz@42065 812 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);
goetz@42065 813
goetz@42065 814 LIR_Opr result = rlock_result(x);
goetz@42065 815 __ move(reg, result);
goetz@42065 816 }
goetz@42065 817
goetz@42065 818 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
goetz@42065 819 Values* dims = x->dims();
goetz@42065 820 int i = dims->length();
goetz@42065 821 LIRItemList* items = new LIRItemList(i, i, NULL);
goetz@42065 822 while (i-- > 0) {
goetz@42065 823 LIRItem* size = new LIRItem(dims->at(i), this);
goetz@42065 824 items->at_put(i, size);
goetz@42065 825 }
goetz@42065 826
goetz@42065 827 // Evaluate state_for early since it may emit code.
goetz@42065 828 CodeEmitInfo* patching_info = NULL;
goetz@42065 829 if (!x->klass()->is_loaded() || PatchALot) {
goetz@42065 830 patching_info = state_for (x, x->state_before());
goetz@42065 831
goetz@42065 832 // Cannot re-use same xhandlers for multiple CodeEmitInfos, so
goetz@42065 833 // clone all handlers (NOTE: Usually this is handled transparently
goetz@42065 834 // by the CodeEmitInfo cloning logic in CodeStub constructors but
goetz@42065 835 // is done explicitly here because a stub isn't being used).
goetz@42065 836 x->set_exception_handlers(new XHandlers(x->exception_handlers()));
goetz@42065 837 }
goetz@42065 838 CodeEmitInfo* info = state_for (x, x->state());
goetz@42065 839
goetz@42065 840 i = dims->length();
goetz@42065 841 while (--i >= 0) {
goetz@42065 842 LIRItem* size = items->at(i);
goetz@42065 843 size->load_nonconstant(32);
goetz@42065 844 // FrameMap::_reserved_argument_area_size includes the dimensions varargs, because
goetz@42065 845 // it's initialized to hir()->max_stack() when the FrameMap is created.
goetz@42065 846 store_stack_parameter(size->result(), in_ByteSize(i*sizeof(jint) + FrameMap::first_available_sp_in_frame));
goetz@42065 847 }
goetz@42065 848
goetz@42065 849 LIR_Opr klass_reg = FrameMap::Z_R3_metadata_opr;
goetz@42065 850 klass2reg_with_patching(klass_reg, x->klass(), patching_info);
goetz@42065 851
goetz@42065 852 LIR_Opr rank = FrameMap::Z_R4_opr;
goetz@42065 853 __ move(LIR_OprFact::intConst(x->rank()), rank);
goetz@42065 854 LIR_Opr varargs = FrameMap::Z_R5_opr;
goetz@42065 855 __ leal(LIR_OprFact::address(new LIR_Address(FrameMap::Z_SP_opr, FrameMap::first_available_sp_in_frame, T_INT)),
goetz@42065 856 varargs);
goetz@42065 857 LIR_OprList* args = new LIR_OprList(3);
goetz@42065 858 args->append(klass_reg);
goetz@42065 859 args->append(rank);
goetz@42065 860 args->append(varargs);
goetz@42065 861 LIR_Opr reg = result_register_for (x->type());
goetz@42065 862 __ call_runtime(Runtime1::entry_for (Runtime1::new_multi_array_id),
goetz@42065 863 LIR_OprFact::illegalOpr,
goetz@42065 864 reg, args, info);
goetz@42065 865
goetz@42065 866 LIR_Opr result = rlock_result(x);
goetz@42065 867 __ move(reg, result);
goetz@42065 868 }
goetz@42065 869
goetz@42065 870 void LIRGenerator::do_BlockBegin(BlockBegin* x) {
goetz@42065 871 // Nothing to do.
goetz@42065 872 }
goetz@42065 873
goetz@42065 874 void LIRGenerator::do_CheckCast(CheckCast* x) {
goetz@42065 875 LIRItem obj(x->obj(), this);
goetz@42065 876
goetz@42065 877 CodeEmitInfo* patching_info = NULL;
dholmes@50458 878 if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check() && !x->is_invokespecial_receiver_check())) {
goetz@42065 879 // Must do this before locking the destination register as an oop register,
goetz@42065 880 // and before the obj is loaded (the latter is for deoptimization).
goetz@42065 881 patching_info = state_for (x, x->state_before());
goetz@42065 882 }
goetz@42065 883 obj.load_item();
goetz@42065 884
goetz@42065 885 // info for exceptions
coleenp@44738 886 CodeEmitInfo* info_for_exception =
coleenp@44738 887 (x->needs_exception_state() ? state_for(x) :
coleenp@44738 888 state_for(x, x->state_before(), true /*ignore_xhandler*/));
goetz@42065 889
goetz@42065 890 CodeStub* stub;
goetz@42065 891 if (x->is_incompatible_class_change_check()) {
goetz@42065 892 assert(patching_info == NULL, "can't patch this");
goetz@42065 893 stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);
coleenp@44738 894 } else if (x->is_invokespecial_receiver_check()) {
coleenp@44738 895 assert(patching_info == NULL, "can't patch this");
coleenp@44738 896 stub = new DeoptimizeStub(info_for_exception,
coleenp@44738 897 Deoptimization::Reason_class_check,
coleenp@44738 898 Deoptimization::Action_none);
goetz@42065 899 } else {
goetz@42065 900 stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);
goetz@42065 901 }
goetz@42065 902 LIR_Opr reg = rlock_result(x);
goetz@42065 903 LIR_Opr tmp1 = new_register(objectType);
goetz@42065 904 LIR_Opr tmp2 = new_register(objectType);
goetz@42065 905 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
goetz@42065 906 __ checkcast(reg, obj.result(), x->klass(),
goetz@42065 907 tmp1, tmp2, tmp3,
goetz@42065 908 x->direct_compare(), info_for_exception, patching_info, stub,
goetz@42065 909 x->profiled_method(), x->profiled_bci());
goetz@42065 910 }
goetz@42065 911
goetz@42065 912
goetz@42065 913 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
goetz@42065 914 LIRItem obj(x->obj(), this);
goetz@42065 915 CodeEmitInfo* patching_info = NULL;
goetz@42065 916 if (!x->klass()->is_loaded() || PatchALot) {
goetz@42065 917 patching_info = state_for (x, x->state_before());
goetz@42065 918 }
goetz@42065 919 // Ensure the result register is not the input register because the
goetz@42065 920 // result is initialized before the patching safepoint.
goetz@42065 921 obj.load_item();
goetz@42065 922 LIR_Opr out_reg = rlock_result(x);
goetz@42065 923 LIR_Opr tmp1 = new_register(objectType);
goetz@42065 924 LIR_Opr tmp2 = new_register(objectType);
goetz@42065 925 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
goetz@42065 926 __ instanceof(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3,
goetz@42065 927 x->direct_compare(), patching_info,
goetz@42065 928 x->profiled_method(), x->profiled_bci());
goetz@42065 929 }
goetz@42065 930
goetz@42065 931
goetz@42065 932 void LIRGenerator::do_If (If* x) {
goetz@42065 933 assert(x->number_of_sux() == 2, "inconsistency");
goetz@42065 934 ValueTag tag = x->x()->type()->tag();
goetz@42065 935 bool is_safepoint = x->is_safepoint();
goetz@42065 936
goetz@42065 937 If::Condition cond = x->cond();
goetz@42065 938
goetz@42065 939 LIRItem xitem(x->x(), this);
goetz@42065 940 LIRItem yitem(x->y(), this);
goetz@42065 941 LIRItem* xin = &xitem;
goetz@42065 942 LIRItem* yin = &yitem;
goetz@42065 943
goetz@42065 944 if (tag == longTag) {
goetz@42065 945 // For longs, only conditions "eql", "neq", "lss", "geq" are valid;
goetz@42065 946 // mirror for other conditions.
goetz@42065 947 if (cond == If::gtr || cond == If::leq) {
goetz@42065 948 cond = Instruction::mirror(cond);
goetz@42065 949 xin = &yitem;
goetz@42065 950 yin = &xitem;
goetz@42065 951 }
goetz@42065 952 xin->set_destroys_register();
goetz@42065 953 }
goetz@42065 954 xin->load_item();
goetz@42065 955 // TODO: don't load long constants != 0L
goetz@42065 956 if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {
goetz@42065 957 // inline long zero
goetz@42065 958 yin->dont_load_item();
goetz@42065 959 } else if (tag == longTag || tag == floatTag || tag == doubleTag) {
goetz@42065 960 // Longs cannot handle constants at right side.
goetz@42065 961 yin->load_item();
goetz@42065 962 } else {
goetz@42065 963 yin->dont_load_item();
goetz@42065 964 }
goetz@42065 965
goetz@42065 966 // Add safepoint before generating condition code so it can be recomputed.
goetz@42065 967 if (x->is_safepoint()) {
goetz@42065 968 // Increment backedge counter if needed.
goetz@42065 969 increment_backedge_counter(state_for (x, x->state_before()), x->profiled_bci());
goetz@42065 970 // Use safepoint_poll_register() instead of LIR_OprFact::illegalOpr.
goetz@42065 971 __ safepoint(safepoint_poll_register(), state_for (x, x->state_before()));
goetz@42065 972 }
goetz@42065 973 set_no_result(x);
goetz@42065 974
goetz@42065 975 LIR_Opr left = xin->result();
goetz@42065 976 LIR_Opr right = yin->result();
goetz@42065 977 __ cmp(lir_cond(cond), left, right);
goetz@42065 978 // Generate branch profiling. Profiling code doesn't kill flags.
goetz@42065 979 profile_branch(x, cond);
goetz@42065 980 move_to_phi(x->state());
goetz@42065 981 if (x->x()->type()->is_float_kind()) {
goetz@42065 982 __ branch(lir_cond(cond), right->type(), x->tsux(), x->usux());
goetz@42065 983 } else {
goetz@42065 984 __ branch(lir_cond(cond), right->type(), x->tsux());
goetz@42065 985 }
goetz@42065 986 assert(x->default_sux() == x->fsux(), "wrong destination above");
goetz@42065 987 __ jump(x->default_sux());
goetz@42065 988 }
goetz@42065 989
goetz@42065 990 LIR_Opr LIRGenerator::getThreadPointer() {
goetz@42065 991 return FrameMap::as_pointer_opr(Z_thread);
goetz@42065 992 }
goetz@42065 993
goetz@42065 994 void LIRGenerator::trace_block_entry(BlockBegin* block) {
goetz@42065 995 __ move(LIR_OprFact::intConst(block->block_id()), FrameMap::Z_R2_opr);
goetz@42065 996 LIR_OprList* args = new LIR_OprList(1);
goetz@42065 997 args->append(FrameMap::Z_R2_opr);
goetz@42065 998 address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);
goetz@42065 999 __ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);
goetz@42065 1000 }
goetz@42065 1001
goetz@42065 1002 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,
goetz@42065 1003 CodeEmitInfo* info) {
goetz@42065 1004 __ store(value, address, info);
goetz@42065 1005 }
goetz@42065 1006
goetz@42065 1007 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,
goetz@42065 1008 CodeEmitInfo* info) {
goetz@42065 1009 __ load(address, result, info);
goetz@42065 1010 }
goetz@42065 1011
goetz@42065 1012 void LIRGenerator::do_update_CRC32(Intrinsic* x) {
goetz@42065 1013 assert(UseCRC32Intrinsics, "or should not be here");
goetz@42065 1014 LIR_Opr result = rlock_result(x);
goetz@42065 1015
goetz@42065 1016 switch (x->id()) {
goetz@42065 1017 case vmIntrinsics::_updateCRC32: {
goetz@42065 1018 LIRItem crc(x->argument_at(0), this);
goetz@42065 1019 LIRItem val(x->argument_at(1), this);
goetz@42065 1020 // Registers destroyed by update_crc32.
goetz@42065 1021 crc.set_destroys_register();
goetz@42065 1022 val.set_destroys_register();
goetz@42065 1023 crc.load_item();
goetz@42065 1024 val.load_item();
goetz@42065 1025 __ update_crc32(crc.result(), val.result(), result);
goetz@42065 1026 break;
goetz@42065 1027 }
goetz@42065 1028 case vmIntrinsics::_updateBytesCRC32:
goetz@42065 1029 case vmIntrinsics::_updateByteBufferCRC32: {
goetz@42065 1030 bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);
goetz@42065 1031
goetz@42065 1032 LIRItem crc(x->argument_at(0), this);
goetz@42065 1033 LIRItem buf(x->argument_at(1), this);
goetz@42065 1034 LIRItem off(x->argument_at(2), this);
goetz@42065 1035 LIRItem len(x->argument_at(3), this);
goetz@42065 1036 buf.load_item();
goetz@42065 1037 off.load_nonconstant();
goetz@42065 1038
goetz@42065 1039 LIR_Opr index = off.result();
goetz@42065 1040 int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
goetz@42065 1041 if (off.result()->is_constant()) {
goetz@42065 1042 index = LIR_OprFact::illegalOpr;
goetz@42065 1043 offset += off.result()->as_jint();
goetz@42065 1044 }
goetz@42065 1045 LIR_Opr base_op = buf.result();
goetz@42065 1046
goetz@42065 1047 if (index->is_valid()) {
goetz@42065 1048 LIR_Opr tmp = new_register(T_LONG);
goetz@42065 1049 __ convert(Bytecodes::_i2l, index, tmp);
goetz@42065 1050 index = tmp;
goetz@42065 1051 }
goetz@42065 1052
goetz@42065 1053 LIR_Address* a = new LIR_Address(base_op, index, offset, T_BYTE);
goetz@42065 1054
goetz@42065 1055 BasicTypeList signature(3);
goetz@42065 1056 signature.append(T_INT);
goetz@42065 1057 signature.append(T_ADDRESS);
goetz@42065 1058 signature.append(T_INT);
goetz@42065 1059 CallingConvention* cc = frame_map()->c_calling_convention(&signature);
goetz@42065 1060 const LIR_Opr result_reg = result_register_for (x->type());
goetz@42065 1061
goetz@42065 1062 LIR_Opr arg1 = cc->at(0);
goetz@42065 1063 LIR_Opr arg2 = cc->at(1);
goetz@42065 1064 LIR_Opr arg3 = cc->at(2);
goetz@42065 1065
goetz@42065 1066 crc.load_item_force(arg1); // We skip int->long conversion here, because CRC32 stub doesn't care about high bits.
goetz@42065 1067 __ leal(LIR_OprFact::address(a), arg2);
lucy@46315 1068 len.load_item_force(arg3); // We skip int->long conversion here, because CRC32 stub expects int.
goetz@42065 1069
goetz@42065 1070 __ call_runtime_leaf(StubRoutines::updateBytesCRC32(), LIR_OprFact::illegalOpr, result_reg, cc->args());
goetz@42065 1071 __ move(result_reg, result);
goetz@42065 1072 break;
goetz@42065 1073 }
goetz@42065 1074 default: {
goetz@42065 1075 ShouldNotReachHere();
goetz@42065 1076 }
goetz@42065 1077 }
goetz@42065 1078 }
goetz@42065 1079
goetz@42065 1080 void LIRGenerator::do_update_CRC32C(Intrinsic* x) {
lucy@46315 1081 assert(UseCRC32CIntrinsics, "or should not be here");
lucy@46315 1082 LIR_Opr result = rlock_result(x);
lucy@46315 1083
lucy@46315 1084 switch (x->id()) {
lucy@46315 1085 case vmIntrinsics::_updateBytesCRC32C:
lucy@46315 1086 case vmIntrinsics::_updateDirectByteBufferCRC32C: {
lucy@46315 1087 bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32C);
lucy@46315 1088
lucy@46315 1089 LIRItem crc(x->argument_at(0), this);
lucy@46315 1090 LIRItem buf(x->argument_at(1), this);
lucy@46315 1091 LIRItem off(x->argument_at(2), this);
simonis@46386 1092 LIRItem end(x->argument_at(3), this);
lucy@46315 1093 buf.load_item();
lucy@46315 1094 off.load_nonconstant();
simonis@46386 1095 end.load_nonconstant();
simonis@46386 1096
simonis@46386 1097 // len = end - off
simonis@46386 1098 LIR_Opr len = end.result();
simonis@46386 1099 LIR_Opr tmpA = new_register(T_INT);
simonis@46386 1100 LIR_Opr tmpB = new_register(T_INT);
simonis@46386 1101 __ move(end.result(), tmpA);
simonis@46386 1102 __ move(off.result(), tmpB);
simonis@46386 1103 __ sub(tmpA, tmpB, tmpA);
simonis@46386 1104 len = tmpA;
lucy@46315 1105
lucy@46315 1106 LIR_Opr index = off.result();
lucy@46315 1107 int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
lucy@46315 1108 if (off.result()->is_constant()) {
lucy@46315 1109 index = LIR_OprFact::illegalOpr;
lucy@46315 1110 offset += off.result()->as_jint();
lucy@46315 1111 }
lucy@46315 1112 LIR_Opr base_op = buf.result();
lucy@46315 1113
lucy@46315 1114 if (index->is_valid()) {
lucy@46315 1115 LIR_Opr tmp = new_register(T_LONG);
lucy@46315 1116 __ convert(Bytecodes::_i2l, index, tmp);
lucy@46315 1117 index = tmp;
lucy@46315 1118 }
lucy@46315 1119
lucy@46315 1120 LIR_Address* a = new LIR_Address(base_op, index, offset, T_BYTE);
lucy@46315 1121
lucy@46315 1122 BasicTypeList signature(3);
lucy@46315 1123 signature.append(T_INT);
lucy@46315 1124 signature.append(T_ADDRESS);
lucy@46315 1125 signature.append(T_INT);
lucy@46315 1126 CallingConvention* cc = frame_map()->c_calling_convention(&signature);
lucy@46315 1127 const LIR_Opr result_reg = result_register_for (x->type());
lucy@46315 1128
lucy@46315 1129 LIR_Opr arg1 = cc->at(0);
lucy@46315 1130 LIR_Opr arg2 = cc->at(1);
lucy@46315 1131 LIR_Opr arg3 = cc->at(2);
lucy@46315 1132
lucy@46315 1133 crc.load_item_force(arg1); // We skip int->long conversion here, because CRC32C stub doesn't care about high bits.
lucy@46315 1134 __ leal(LIR_OprFact::address(a), arg2);
simonis@46386 1135 __ move(len, cc->at(2)); // We skip int->long conversion here, because CRC32C stub expects int.
lucy@46315 1136
lucy@46315 1137 __ call_runtime_leaf(StubRoutines::updateBytesCRC32C(), LIR_OprFact::illegalOpr, result_reg, cc->args());
lucy@46315 1138 __ move(result_reg, result);
lucy@46315 1139 break;
lucy@46315 1140 }
lucy@46315 1141 default: {
lucy@46315 1142 ShouldNotReachHere();
lucy@46315 1143 }
lucy@46315 1144 }
goetz@42065 1145 }
goetz@42065 1146
goetz@42065 1147 void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {
mdoerr@42897 1148 assert(x->number_of_arguments() == 3, "wrong type");
mdoerr@42897 1149 assert(UseFMA, "Needs FMA instructions support.");
mdoerr@42897 1150 LIRItem value(x->argument_at(0), this);
mdoerr@42897 1151 LIRItem value1(x->argument_at(1), this);
mdoerr@42897 1152 LIRItem value2(x->argument_at(2), this);
mdoerr@42897 1153
mdoerr@42897 1154 value2.set_destroys_register();
mdoerr@42897 1155
mdoerr@42897 1156 value.load_item();
mdoerr@42897 1157 value1.load_item();
mdoerr@42897 1158 value2.load_item();
mdoerr@42897 1159
mdoerr@42897 1160 LIR_Opr calc_input = value.result();
mdoerr@42897 1161 LIR_Opr calc_input1 = value1.result();
mdoerr@42897 1162 LIR_Opr calc_input2 = value2.result();
mdoerr@42897 1163 LIR_Opr calc_result = rlock_result(x);
mdoerr@42897 1164
mdoerr@42897 1165 switch (x->id()) {
mdoerr@42897 1166 case vmIntrinsics::_fmaD: __ fmad(calc_input, calc_input1, calc_input2, calc_result); break;
mdoerr@42897 1167 case vmIntrinsics::_fmaF: __ fmaf(calc_input, calc_input1, calc_input2, calc_result); break;
mdoerr@42897 1168 default: ShouldNotReachHere();
mdoerr@42897 1169 }
goetz@42065 1170 }
goetz@42065 1171
goetz@42065 1172 void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) {
goetz@42065 1173 fatal("vectorizedMismatch intrinsic is not implemented on this platform");
goetz@42065 1174 }