src/cpu/x86/vm/c1_LIRGenerator_x86.cpp

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 8415
d109bda16490
parent 7535
7ae4e26cb1e0
child 8856
ac27a9c85bea
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
kevinw@8368 2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "c1/c1_Compilation.hpp"
aoqi@0 27 #include "c1/c1_FrameMap.hpp"
aoqi@0 28 #include "c1/c1_Instruction.hpp"
aoqi@0 29 #include "c1/c1_LIRAssembler.hpp"
aoqi@0 30 #include "c1/c1_LIRGenerator.hpp"
aoqi@0 31 #include "c1/c1_Runtime1.hpp"
aoqi@0 32 #include "c1/c1_ValueStack.hpp"
aoqi@0 33 #include "ci/ciArray.hpp"
aoqi@0 34 #include "ci/ciObjArrayKlass.hpp"
aoqi@0 35 #include "ci/ciTypeArrayKlass.hpp"
aoqi@0 36 #include "runtime/sharedRuntime.hpp"
aoqi@0 37 #include "runtime/stubRoutines.hpp"
aoqi@0 38 #include "vmreg_x86.inline.hpp"
aoqi@0 39
aoqi@0 40 #ifdef ASSERT
aoqi@0 41 #define __ gen()->lir(__FILE__, __LINE__)->
aoqi@0 42 #else
aoqi@0 43 #define __ gen()->lir()->
aoqi@0 44 #endif
aoqi@0 45
aoqi@0 46 // Item will be loaded into a byte register; Intel only
aoqi@0 47 void LIRItem::load_byte_item() {
aoqi@0 48 load_item();
aoqi@0 49 LIR_Opr res = result();
aoqi@0 50
aoqi@0 51 if (!res->is_virtual() || !_gen->is_vreg_flag_set(res, LIRGenerator::byte_reg)) {
aoqi@0 52 // make sure that it is a byte register
aoqi@0 53 assert(!value()->type()->is_float() && !value()->type()->is_double(),
aoqi@0 54 "can't load floats in byte register");
aoqi@0 55 LIR_Opr reg = _gen->rlock_byte(T_BYTE);
aoqi@0 56 __ move(res, reg);
aoqi@0 57
aoqi@0 58 _result = reg;
aoqi@0 59 }
aoqi@0 60 }
aoqi@0 61
aoqi@0 62
aoqi@0 63 void LIRItem::load_nonconstant() {
aoqi@0 64 LIR_Opr r = value()->operand();
aoqi@0 65 if (r->is_constant()) {
aoqi@0 66 _result = r;
aoqi@0 67 } else {
aoqi@0 68 load_item();
aoqi@0 69 }
aoqi@0 70 }
aoqi@0 71
aoqi@0 72 //--------------------------------------------------------------
aoqi@0 73 // LIRGenerator
aoqi@0 74 //--------------------------------------------------------------
aoqi@0 75
aoqi@0 76
aoqi@0 77 LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::rax_oop_opr; }
aoqi@0 78 LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::rdx_opr; }
aoqi@0 79 LIR_Opr LIRGenerator::divInOpr() { return FrameMap::rax_opr; }
aoqi@0 80 LIR_Opr LIRGenerator::divOutOpr() { return FrameMap::rax_opr; }
aoqi@0 81 LIR_Opr LIRGenerator::remOutOpr() { return FrameMap::rdx_opr; }
aoqi@0 82 LIR_Opr LIRGenerator::shiftCountOpr() { return FrameMap::rcx_opr; }
aoqi@0 83 LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::rax_opr; }
aoqi@0 84 LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; }
aoqi@0 85
aoqi@0 86
aoqi@0 87 LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {
aoqi@0 88 LIR_Opr opr;
aoqi@0 89 switch (type->tag()) {
aoqi@0 90 case intTag: opr = FrameMap::rax_opr; break;
aoqi@0 91 case objectTag: opr = FrameMap::rax_oop_opr; break;
aoqi@0 92 case longTag: opr = FrameMap::long0_opr; break;
aoqi@0 93 case floatTag: opr = UseSSE >= 1 ? FrameMap::xmm0_float_opr : FrameMap::fpu0_float_opr; break;
aoqi@0 94 case doubleTag: opr = UseSSE >= 2 ? FrameMap::xmm0_double_opr : FrameMap::fpu0_double_opr; break;
aoqi@0 95
aoqi@0 96 case addressTag:
aoqi@0 97 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
aoqi@0 101 return opr;
aoqi@0 102 }
aoqi@0 103
aoqi@0 104
aoqi@0 105 LIR_Opr LIRGenerator::rlock_byte(BasicType type) {
aoqi@0 106 LIR_Opr reg = new_register(T_INT);
aoqi@0 107 set_vreg_flag(reg, LIRGenerator::byte_reg);
aoqi@0 108 return reg;
aoqi@0 109 }
aoqi@0 110
aoqi@0 111
aoqi@0 112 //--------- loading items into registers --------------------------------
aoqi@0 113
aoqi@0 114
aoqi@0 115 // i486 instructions can inline constants
aoqi@0 116 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
aoqi@0 117 if (type == T_SHORT || type == T_CHAR) {
aoqi@0 118 // there is no immediate move of word values in asembler_i486.?pp
aoqi@0 119 return false;
aoqi@0 120 }
aoqi@0 121 Constant* c = v->as_Constant();
aoqi@0 122 if (c && c->state_before() == NULL) {
aoqi@0 123 // constants of any type can be stored directly, except for
aoqi@0 124 // unloaded object constants.
aoqi@0 125 return true;
aoqi@0 126 }
aoqi@0 127 return false;
aoqi@0 128 }
aoqi@0 129
aoqi@0 130
aoqi@0 131 bool LIRGenerator::can_inline_as_constant(Value v) const {
aoqi@0 132 if (v->type()->tag() == longTag) return false;
aoqi@0 133 return v->type()->tag() != objectTag ||
aoqi@0 134 (v->type()->is_constant() && v->type()->as_ObjectType()->constant_value()->is_null_object());
aoqi@0 135 }
aoqi@0 136
aoqi@0 137
aoqi@0 138 bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {
aoqi@0 139 if (c->type() == T_LONG) return false;
aoqi@0 140 return c->type() != T_OBJECT || c->as_jobject() == NULL;
aoqi@0 141 }
aoqi@0 142
aoqi@0 143
aoqi@0 144 LIR_Opr LIRGenerator::safepoint_poll_register() {
aoqi@0 145 return LIR_OprFact::illegalOpr;
aoqi@0 146 }
aoqi@0 147
aoqi@0 148
aoqi@0 149 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
aoqi@0 150 int shift, int disp, BasicType type) {
aoqi@0 151 assert(base->is_register(), "must be");
aoqi@0 152 if (index->is_constant()) {
aoqi@0 153 return new LIR_Address(base,
aoqi@0 154 (index->as_constant_ptr()->as_jint() << shift) + disp,
aoqi@0 155 type);
aoqi@0 156 } else {
aoqi@0 157 return new LIR_Address(base, index, (LIR_Address::Scale)shift, disp, type);
aoqi@0 158 }
aoqi@0 159 }
aoqi@0 160
aoqi@0 161
aoqi@0 162 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,
aoqi@0 163 BasicType type, bool needs_card_mark) {
aoqi@0 164 int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type);
aoqi@0 165
aoqi@0 166 LIR_Address* addr;
aoqi@0 167 if (index_opr->is_constant()) {
aoqi@0 168 int elem_size = type2aelembytes(type);
aoqi@0 169 addr = new LIR_Address(array_opr,
aoqi@0 170 offset_in_bytes + index_opr->as_jint() * elem_size, type);
aoqi@0 171 } else {
aoqi@0 172 #ifdef _LP64
aoqi@0 173 if (index_opr->type() == T_INT) {
aoqi@0 174 LIR_Opr tmp = new_register(T_LONG);
aoqi@0 175 __ convert(Bytecodes::_i2l, index_opr, tmp);
aoqi@0 176 index_opr = tmp;
aoqi@0 177 }
aoqi@0 178 #endif // _LP64
aoqi@0 179 addr = new LIR_Address(array_opr,
aoqi@0 180 index_opr,
aoqi@0 181 LIR_Address::scale(type),
aoqi@0 182 offset_in_bytes, type);
aoqi@0 183 }
aoqi@0 184 if (needs_card_mark) {
aoqi@0 185 // This store will need a precise card mark, so go ahead and
aoqi@0 186 // compute the full adddres instead of computing once for the
aoqi@0 187 // store and again for the card mark.
aoqi@0 188 LIR_Opr tmp = new_pointer_register();
aoqi@0 189 __ leal(LIR_OprFact::address(addr), tmp);
aoqi@0 190 return new LIR_Address(tmp, type);
aoqi@0 191 } else {
aoqi@0 192 return addr;
aoqi@0 193 }
aoqi@0 194 }
aoqi@0 195
aoqi@0 196
aoqi@0 197 LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {
csahu@8316 198 LIR_Opr r = NULL;
aoqi@0 199 if (type == T_LONG) {
aoqi@0 200 r = LIR_OprFact::longConst(x);
aoqi@0 201 } else if (type == T_INT) {
aoqi@0 202 r = LIR_OprFact::intConst(x);
aoqi@0 203 } else {
aoqi@0 204 ShouldNotReachHere();
aoqi@0 205 }
aoqi@0 206 return r;
aoqi@0 207 }
aoqi@0 208
aoqi@0 209 void LIRGenerator::increment_counter(address counter, BasicType type, int step) {
aoqi@0 210 LIR_Opr pointer = new_pointer_register();
aoqi@0 211 __ move(LIR_OprFact::intptrConst(counter), pointer);
aoqi@0 212 LIR_Address* addr = new LIR_Address(pointer, type);
aoqi@0 213 increment_counter(addr, step);
aoqi@0 214 }
aoqi@0 215
aoqi@0 216
aoqi@0 217 void LIRGenerator::increment_counter(LIR_Address* addr, int step) {
aoqi@0 218 __ add((LIR_Opr)addr, LIR_OprFact::intConst(step), (LIR_Opr)addr);
aoqi@0 219 }
aoqi@0 220
aoqi@0 221 void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {
aoqi@0 222 __ cmp_mem_int(condition, base, disp, c, info);
aoqi@0 223 }
aoqi@0 224
aoqi@0 225
aoqi@0 226 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {
aoqi@0 227 __ cmp_reg_mem(condition, reg, new LIR_Address(base, disp, type), info);
aoqi@0 228 }
aoqi@0 229
aoqi@0 230
aoqi@0 231 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info) {
aoqi@0 232 __ cmp_reg_mem(condition, reg, new LIR_Address(base, disp, type), info);
aoqi@0 233 }
aoqi@0 234
aoqi@0 235
aoqi@0 236 bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) {
aoqi@0 237 if (tmp->is_valid()) {
aoqi@0 238 if (is_power_of_2(c + 1)) {
aoqi@0 239 __ move(left, tmp);
aoqi@0 240 __ shift_left(left, log2_intptr(c + 1), left);
aoqi@0 241 __ sub(left, tmp, result);
aoqi@0 242 return true;
aoqi@0 243 } else if (is_power_of_2(c - 1)) {
aoqi@0 244 __ move(left, tmp);
aoqi@0 245 __ shift_left(left, log2_intptr(c - 1), left);
aoqi@0 246 __ add(left, tmp, result);
aoqi@0 247 return true;
aoqi@0 248 }
aoqi@0 249 }
aoqi@0 250 return false;
aoqi@0 251 }
aoqi@0 252
aoqi@0 253
aoqi@0 254 void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {
aoqi@0 255 BasicType type = item->type();
aoqi@0 256 __ store(item, new LIR_Address(FrameMap::rsp_opr, in_bytes(offset_from_sp), type));
aoqi@0 257 }
aoqi@0 258
aoqi@0 259 //----------------------------------------------------------------------
aoqi@0 260 // visitor functions
aoqi@0 261 //----------------------------------------------------------------------
aoqi@0 262
aoqi@0 263
aoqi@0 264 void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {
aoqi@0 265 assert(x->is_pinned(),"");
aoqi@0 266 bool needs_range_check = x->compute_needs_range_check();
aoqi@0 267 bool use_length = x->length() != NULL;
aoqi@0 268 bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;
aoqi@0 269 bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||
aoqi@0 270 !get_jobject_constant(x->value())->is_null_object() ||
aoqi@0 271 x->should_profile());
aoqi@0 272
aoqi@0 273 LIRItem array(x->array(), this);
aoqi@0 274 LIRItem index(x->index(), this);
aoqi@0 275 LIRItem value(x->value(), this);
aoqi@0 276 LIRItem length(this);
aoqi@0 277
aoqi@0 278 array.load_item();
aoqi@0 279 index.load_nonconstant();
aoqi@0 280
aoqi@0 281 if (use_length && needs_range_check) {
aoqi@0 282 length.set_instruction(x->length());
aoqi@0 283 length.load_item();
aoqi@0 284
aoqi@0 285 }
kevinw@8368 286 if (needs_store_check || x->check_boolean()) {
aoqi@0 287 value.load_item();
aoqi@0 288 } else {
aoqi@0 289 value.load_for_store(x->elt_type());
aoqi@0 290 }
aoqi@0 291
aoqi@0 292 set_no_result(x);
aoqi@0 293
aoqi@0 294 // the CodeEmitInfo must be duplicated for each different
aoqi@0 295 // LIR-instruction because spilling can occur anywhere between two
aoqi@0 296 // instructions and so the debug information must be different
aoqi@0 297 CodeEmitInfo* range_check_info = state_for(x);
aoqi@0 298 CodeEmitInfo* null_check_info = NULL;
aoqi@0 299 if (x->needs_null_check()) {
aoqi@0 300 null_check_info = new CodeEmitInfo(range_check_info);
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 // emit array address setup early so it schedules better
aoqi@0 304 LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store);
aoqi@0 305
aoqi@0 306 if (GenerateRangeChecks && needs_range_check) {
aoqi@0 307 if (use_length) {
aoqi@0 308 __ cmp(lir_cond_belowEqual, length.result(), index.result());
aoqi@0 309 __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result()));
aoqi@0 310 } else {
aoqi@0 311 array_range_check(array.result(), index.result(), null_check_info, range_check_info);
aoqi@0 312 // range_check also does the null check
aoqi@0 313 null_check_info = NULL;
aoqi@0 314 }
aoqi@0 315 }
aoqi@0 316
aoqi@0 317 if (GenerateArrayStoreCheck && needs_store_check) {
aoqi@0 318 LIR_Opr tmp1 = new_register(objectType);
aoqi@0 319 LIR_Opr tmp2 = new_register(objectType);
aoqi@0 320 LIR_Opr tmp3 = new_register(objectType);
aoqi@0 321
aoqi@0 322 CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);
aoqi@0 323 __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());
aoqi@0 324 }
aoqi@0 325
aoqi@0 326 if (obj_store) {
aoqi@0 327 // Needs GC write barriers.
aoqi@0 328 pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr /* pre_val */,
aoqi@0 329 true /* do_load */, false /* patch */, NULL);
aoqi@0 330 __ move(value.result(), array_addr, null_check_info);
aoqi@0 331 // Seems to be a precise
aoqi@0 332 post_barrier(LIR_OprFact::address(array_addr), value.result());
aoqi@0 333 } else {
kevinw@8368 334 LIR_Opr result = maybe_mask_boolean(x, array.result(), value.result(), null_check_info);
kevinw@8368 335 __ move(result, array_addr, null_check_info);
aoqi@0 336 }
aoqi@0 337 }
aoqi@0 338
aoqi@0 339
aoqi@0 340 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
aoqi@0 341 assert(x->is_pinned(),"");
aoqi@0 342 LIRItem obj(x->obj(), this);
aoqi@0 343 obj.load_item();
aoqi@0 344
aoqi@0 345 set_no_result(x);
aoqi@0 346
aoqi@0 347 // "lock" stores the address of the monitor stack slot, so this is not an oop
aoqi@0 348 LIR_Opr lock = new_register(T_INT);
aoqi@0 349 // Need a scratch register for biased locking on x86
aoqi@0 350 LIR_Opr scratch = LIR_OprFact::illegalOpr;
aoqi@0 351 if (UseBiasedLocking) {
aoqi@0 352 scratch = new_register(T_INT);
aoqi@0 353 }
aoqi@0 354
aoqi@0 355 CodeEmitInfo* info_for_exception = NULL;
aoqi@0 356 if (x->needs_null_check()) {
aoqi@0 357 info_for_exception = state_for(x);
aoqi@0 358 }
aoqi@0 359 // this CodeEmitInfo must not have the xhandlers because here the
aoqi@0 360 // object is already locked (xhandlers expect object to be unlocked)
aoqi@0 361 CodeEmitInfo* info = state_for(x, x->state(), true);
aoqi@0 362 monitor_enter(obj.result(), lock, syncTempOpr(), scratch,
aoqi@0 363 x->monitor_no(), info_for_exception, info);
aoqi@0 364 }
aoqi@0 365
aoqi@0 366
aoqi@0 367 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
aoqi@0 368 assert(x->is_pinned(),"");
aoqi@0 369
aoqi@0 370 LIRItem obj(x->obj(), this);
aoqi@0 371 obj.dont_load_item();
aoqi@0 372
aoqi@0 373 LIR_Opr lock = new_register(T_INT);
aoqi@0 374 LIR_Opr obj_temp = new_register(T_INT);
aoqi@0 375 set_no_result(x);
aoqi@0 376 monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());
aoqi@0 377 }
aoqi@0 378
aoqi@0 379
aoqi@0 380 // _ineg, _lneg, _fneg, _dneg
aoqi@0 381 void LIRGenerator::do_NegateOp(NegateOp* x) {
aoqi@0 382 LIRItem value(x->x(), this);
aoqi@0 383 value.set_destroys_register();
aoqi@0 384 value.load_item();
aoqi@0 385 LIR_Opr reg = rlock(x);
aoqi@0 386 __ negate(value.result(), reg);
aoqi@0 387
aoqi@0 388 set_result(x, round_item(reg));
aoqi@0 389 }
aoqi@0 390
aoqi@0 391
aoqi@0 392 // for _fadd, _fmul, _fsub, _fdiv, _frem
aoqi@0 393 // _dadd, _dmul, _dsub, _ddiv, _drem
aoqi@0 394 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {
aoqi@0 395 LIRItem left(x->x(), this);
aoqi@0 396 LIRItem right(x->y(), this);
aoqi@0 397 LIRItem* left_arg = &left;
aoqi@0 398 LIRItem* right_arg = &right;
aoqi@0 399 assert(!left.is_stack() || !right.is_stack(), "can't both be memory operands");
aoqi@0 400 bool must_load_both = (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem);
aoqi@0 401 if (left.is_register() || x->x()->type()->is_constant() || must_load_both) {
aoqi@0 402 left.load_item();
aoqi@0 403 } else {
aoqi@0 404 left.dont_load_item();
aoqi@0 405 }
aoqi@0 406
aoqi@0 407 // do not load right operand if it is a constant. only 0 and 1 are
aoqi@0 408 // loaded because there are special instructions for loading them
aoqi@0 409 // without memory access (not needed for SSE2 instructions)
aoqi@0 410 bool must_load_right = false;
aoqi@0 411 if (right.is_constant()) {
aoqi@0 412 LIR_Const* c = right.result()->as_constant_ptr();
aoqi@0 413 assert(c != NULL, "invalid constant");
aoqi@0 414 assert(c->type() == T_FLOAT || c->type() == T_DOUBLE, "invalid type");
aoqi@0 415
aoqi@0 416 if (c->type() == T_FLOAT) {
aoqi@0 417 must_load_right = UseSSE < 1 && (c->is_one_float() || c->is_zero_float());
aoqi@0 418 } else {
aoqi@0 419 must_load_right = UseSSE < 2 && (c->is_one_double() || c->is_zero_double());
aoqi@0 420 }
aoqi@0 421 }
aoqi@0 422
aoqi@0 423 if (must_load_both) {
aoqi@0 424 // frem and drem destroy also right operand, so move it to a new register
aoqi@0 425 right.set_destroys_register();
aoqi@0 426 right.load_item();
aoqi@0 427 } else if (right.is_register() || must_load_right) {
aoqi@0 428 right.load_item();
aoqi@0 429 } else {
aoqi@0 430 right.dont_load_item();
aoqi@0 431 }
aoqi@0 432 LIR_Opr reg = rlock(x);
aoqi@0 433 LIR_Opr tmp = LIR_OprFact::illegalOpr;
aoqi@0 434 if (x->is_strictfp() && (x->op() == Bytecodes::_dmul || x->op() == Bytecodes::_ddiv)) {
aoqi@0 435 tmp = new_register(T_DOUBLE);
aoqi@0 436 }
aoqi@0 437
aoqi@0 438 if ((UseSSE >= 1 && x->op() == Bytecodes::_frem) || (UseSSE >= 2 && x->op() == Bytecodes::_drem)) {
aoqi@0 439 // special handling for frem and drem: no SSE instruction, so must use FPU with temporary fpu stack slots
aoqi@0 440 LIR_Opr fpu0, fpu1;
aoqi@0 441 if (x->op() == Bytecodes::_frem) {
aoqi@0 442 fpu0 = LIR_OprFact::single_fpu(0);
aoqi@0 443 fpu1 = LIR_OprFact::single_fpu(1);
aoqi@0 444 } else {
aoqi@0 445 fpu0 = LIR_OprFact::double_fpu(0);
aoqi@0 446 fpu1 = LIR_OprFact::double_fpu(1);
aoqi@0 447 }
aoqi@0 448 __ move(right.result(), fpu1); // order of left and right operand is important!
aoqi@0 449 __ move(left.result(), fpu0);
aoqi@0 450 __ rem (fpu0, fpu1, fpu0);
aoqi@0 451 __ move(fpu0, reg);
aoqi@0 452
aoqi@0 453 } else {
aoqi@0 454 arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), x->is_strictfp(), tmp);
aoqi@0 455 }
aoqi@0 456
aoqi@0 457 set_result(x, round_item(reg));
aoqi@0 458 }
aoqi@0 459
aoqi@0 460
aoqi@0 461 // for _ladd, _lmul, _lsub, _ldiv, _lrem
aoqi@0 462 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {
aoqi@0 463 if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem ) {
aoqi@0 464 // long division is implemented as a direct call into the runtime
aoqi@0 465 LIRItem left(x->x(), this);
aoqi@0 466 LIRItem right(x->y(), this);
aoqi@0 467
aoqi@0 468 // the check for division by zero destroys the right operand
aoqi@0 469 right.set_destroys_register();
aoqi@0 470
aoqi@0 471 BasicTypeList signature(2);
aoqi@0 472 signature.append(T_LONG);
aoqi@0 473 signature.append(T_LONG);
aoqi@0 474 CallingConvention* cc = frame_map()->c_calling_convention(&signature);
aoqi@0 475
aoqi@0 476 // check for division by zero (destroys registers of right operand!)
aoqi@0 477 CodeEmitInfo* info = state_for(x);
aoqi@0 478
aoqi@0 479 const LIR_Opr result_reg = result_register_for(x->type());
aoqi@0 480 left.load_item_force(cc->at(1));
aoqi@0 481 right.load_item();
aoqi@0 482
aoqi@0 483 __ move(right.result(), cc->at(0));
aoqi@0 484
aoqi@0 485 __ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));
aoqi@0 486 __ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info));
aoqi@0 487
csahu@8316 488 address entry = NULL;
aoqi@0 489 switch (x->op()) {
aoqi@0 490 case Bytecodes::_lrem:
aoqi@0 491 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);
aoqi@0 492 break; // check if dividend is 0 is done elsewhere
aoqi@0 493 case Bytecodes::_ldiv:
aoqi@0 494 entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);
aoqi@0 495 break; // check if dividend is 0 is done elsewhere
aoqi@0 496 case Bytecodes::_lmul:
aoqi@0 497 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul);
aoqi@0 498 break;
aoqi@0 499 default:
aoqi@0 500 ShouldNotReachHere();
aoqi@0 501 }
aoqi@0 502
aoqi@0 503 LIR_Opr result = rlock_result(x);
aoqi@0 504 __ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());
aoqi@0 505 __ move(result_reg, result);
aoqi@0 506 } else if (x->op() == Bytecodes::_lmul) {
aoqi@0 507 // missing test if instr is commutative and if we should swap
aoqi@0 508 LIRItem left(x->x(), this);
aoqi@0 509 LIRItem right(x->y(), this);
aoqi@0 510
aoqi@0 511 // right register is destroyed by the long mul, so it must be
aoqi@0 512 // copied to a new register.
aoqi@0 513 right.set_destroys_register();
aoqi@0 514
aoqi@0 515 left.load_item();
aoqi@0 516 right.load_item();
aoqi@0 517
aoqi@0 518 LIR_Opr reg = FrameMap::long0_opr;
aoqi@0 519 arithmetic_op_long(x->op(), reg, left.result(), right.result(), NULL);
aoqi@0 520 LIR_Opr result = rlock_result(x);
aoqi@0 521 __ move(reg, result);
aoqi@0 522 } else {
aoqi@0 523 // missing test if instr is commutative and if we should swap
aoqi@0 524 LIRItem left(x->x(), this);
aoqi@0 525 LIRItem right(x->y(), this);
aoqi@0 526
aoqi@0 527 left.load_item();
aoqi@0 528 // don't load constants to save register
aoqi@0 529 right.load_nonconstant();
aoqi@0 530 rlock_result(x);
aoqi@0 531 arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);
aoqi@0 532 }
aoqi@0 533 }
aoqi@0 534
aoqi@0 535
aoqi@0 536
aoqi@0 537 // for: _iadd, _imul, _isub, _idiv, _irem
aoqi@0 538 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {
aoqi@0 539 if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {
aoqi@0 540 // The requirements for division and modulo
aoqi@0 541 // input : rax,: dividend min_int
aoqi@0 542 // reg: divisor (may not be rax,/rdx) -1
aoqi@0 543 //
aoqi@0 544 // output: rax,: quotient (= rax, idiv reg) min_int
aoqi@0 545 // rdx: remainder (= rax, irem reg) 0
aoqi@0 546
aoqi@0 547 // rax, and rdx will be destroyed
aoqi@0 548
aoqi@0 549 // Note: does this invalidate the spec ???
aoqi@0 550 LIRItem right(x->y(), this);
aoqi@0 551 LIRItem left(x->x() , this); // visit left second, so that the is_register test is valid
aoqi@0 552
aoqi@0 553 // call state_for before load_item_force because state_for may
aoqi@0 554 // force the evaluation of other instructions that are needed for
aoqi@0 555 // correct debug info. Otherwise the live range of the fix
aoqi@0 556 // register might be too long.
aoqi@0 557 CodeEmitInfo* info = state_for(x);
aoqi@0 558
aoqi@0 559 left.load_item_force(divInOpr());
aoqi@0 560
aoqi@0 561 right.load_item();
aoqi@0 562
aoqi@0 563 LIR_Opr result = rlock_result(x);
aoqi@0 564 LIR_Opr result_reg;
aoqi@0 565 if (x->op() == Bytecodes::_idiv) {
aoqi@0 566 result_reg = divOutOpr();
aoqi@0 567 } else {
aoqi@0 568 result_reg = remOutOpr();
aoqi@0 569 }
aoqi@0 570
aoqi@0 571 if (!ImplicitDiv0Checks) {
aoqi@0 572 __ cmp(lir_cond_equal, right.result(), LIR_OprFact::intConst(0));
aoqi@0 573 __ branch(lir_cond_equal, T_INT, new DivByZeroStub(info));
aoqi@0 574 }
aoqi@0 575 LIR_Opr tmp = FrameMap::rdx_opr; // idiv and irem use rdx in their implementation
aoqi@0 576 if (x->op() == Bytecodes::_irem) {
aoqi@0 577 __ irem(left.result(), right.result(), result_reg, tmp, info);
aoqi@0 578 } else if (x->op() == Bytecodes::_idiv) {
aoqi@0 579 __ idiv(left.result(), right.result(), result_reg, tmp, info);
aoqi@0 580 } else {
aoqi@0 581 ShouldNotReachHere();
aoqi@0 582 }
aoqi@0 583
aoqi@0 584 __ move(result_reg, result);
aoqi@0 585 } else {
aoqi@0 586 // missing test if instr is commutative and if we should swap
aoqi@0 587 LIRItem left(x->x(), this);
aoqi@0 588 LIRItem right(x->y(), this);
aoqi@0 589 LIRItem* left_arg = &left;
aoqi@0 590 LIRItem* right_arg = &right;
aoqi@0 591 if (x->is_commutative() && left.is_stack() && right.is_register()) {
aoqi@0 592 // swap them if left is real stack (or cached) and right is real register(not cached)
aoqi@0 593 left_arg = &right;
aoqi@0 594 right_arg = &left;
aoqi@0 595 }
aoqi@0 596
aoqi@0 597 left_arg->load_item();
aoqi@0 598
aoqi@0 599 // do not need to load right, as we can handle stack and constants
aoqi@0 600 if (x->op() == Bytecodes::_imul ) {
aoqi@0 601 // check if we can use shift instead
aoqi@0 602 bool use_constant = false;
aoqi@0 603 bool use_tmp = false;
aoqi@0 604 if (right_arg->is_constant()) {
aoqi@0 605 int iconst = right_arg->get_jint_constant();
aoqi@0 606 if (iconst > 0) {
aoqi@0 607 if (is_power_of_2(iconst)) {
aoqi@0 608 use_constant = true;
aoqi@0 609 } else if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) {
aoqi@0 610 use_constant = true;
aoqi@0 611 use_tmp = true;
aoqi@0 612 }
aoqi@0 613 }
aoqi@0 614 }
aoqi@0 615 if (use_constant) {
aoqi@0 616 right_arg->dont_load_item();
aoqi@0 617 } else {
aoqi@0 618 right_arg->load_item();
aoqi@0 619 }
aoqi@0 620 LIR_Opr tmp = LIR_OprFact::illegalOpr;
aoqi@0 621 if (use_tmp) {
aoqi@0 622 tmp = new_register(T_INT);
aoqi@0 623 }
aoqi@0 624 rlock_result(x);
aoqi@0 625
aoqi@0 626 arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);
aoqi@0 627 } else {
aoqi@0 628 right_arg->dont_load_item();
aoqi@0 629 rlock_result(x);
aoqi@0 630 LIR_Opr tmp = LIR_OprFact::illegalOpr;
aoqi@0 631 arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);
aoqi@0 632 }
aoqi@0 633 }
aoqi@0 634 }
aoqi@0 635
aoqi@0 636
aoqi@0 637 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {
aoqi@0 638 // when an operand with use count 1 is the left operand, then it is
aoqi@0 639 // likely that no move for 2-operand-LIR-form is necessary
aoqi@0 640 if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
aoqi@0 641 x->swap_operands();
aoqi@0 642 }
aoqi@0 643
aoqi@0 644 ValueTag tag = x->type()->tag();
aoqi@0 645 assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");
aoqi@0 646 switch (tag) {
aoqi@0 647 case floatTag:
aoqi@0 648 case doubleTag: do_ArithmeticOp_FPU(x); return;
aoqi@0 649 case longTag: do_ArithmeticOp_Long(x); return;
aoqi@0 650 case intTag: do_ArithmeticOp_Int(x); return;
aoqi@0 651 }
aoqi@0 652 ShouldNotReachHere();
aoqi@0 653 }
aoqi@0 654
aoqi@0 655
aoqi@0 656 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr
aoqi@0 657 void LIRGenerator::do_ShiftOp(ShiftOp* x) {
aoqi@0 658 // count must always be in rcx
aoqi@0 659 LIRItem value(x->x(), this);
aoqi@0 660 LIRItem count(x->y(), this);
aoqi@0 661
aoqi@0 662 ValueTag elemType = x->type()->tag();
aoqi@0 663 bool must_load_count = !count.is_constant() || elemType == longTag;
aoqi@0 664 if (must_load_count) {
aoqi@0 665 // count for long must be in register
aoqi@0 666 count.load_item_force(shiftCountOpr());
aoqi@0 667 } else {
aoqi@0 668 count.dont_load_item();
aoqi@0 669 }
aoqi@0 670 value.load_item();
aoqi@0 671 LIR_Opr reg = rlock_result(x);
aoqi@0 672
aoqi@0 673 shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);
aoqi@0 674 }
aoqi@0 675
aoqi@0 676
aoqi@0 677 // _iand, _land, _ior, _lor, _ixor, _lxor
aoqi@0 678 void LIRGenerator::do_LogicOp(LogicOp* x) {
aoqi@0 679 // when an operand with use count 1 is the left operand, then it is
aoqi@0 680 // likely that no move for 2-operand-LIR-form is necessary
aoqi@0 681 if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
aoqi@0 682 x->swap_operands();
aoqi@0 683 }
aoqi@0 684
aoqi@0 685 LIRItem left(x->x(), this);
aoqi@0 686 LIRItem right(x->y(), this);
aoqi@0 687
aoqi@0 688 left.load_item();
aoqi@0 689 right.load_nonconstant();
aoqi@0 690 LIR_Opr reg = rlock_result(x);
aoqi@0 691
aoqi@0 692 logic_op(x->op(), reg, left.result(), right.result());
aoqi@0 693 }
aoqi@0 694
aoqi@0 695
aoqi@0 696
aoqi@0 697 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg
aoqi@0 698 void LIRGenerator::do_CompareOp(CompareOp* x) {
aoqi@0 699 LIRItem left(x->x(), this);
aoqi@0 700 LIRItem right(x->y(), this);
aoqi@0 701 ValueTag tag = x->x()->type()->tag();
aoqi@0 702 if (tag == longTag) {
aoqi@0 703 left.set_destroys_register();
aoqi@0 704 }
aoqi@0 705 left.load_item();
aoqi@0 706 right.load_item();
aoqi@0 707 LIR_Opr reg = rlock_result(x);
aoqi@0 708
aoqi@0 709 if (x->x()->type()->is_float_kind()) {
aoqi@0 710 Bytecodes::Code code = x->op();
aoqi@0 711 __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));
aoqi@0 712 } else if (x->x()->type()->tag() == longTag) {
aoqi@0 713 __ lcmp2int(left.result(), right.result(), reg);
aoqi@0 714 } else {
aoqi@0 715 Unimplemented();
aoqi@0 716 }
aoqi@0 717 }
aoqi@0 718
aoqi@0 719
aoqi@0 720 void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {
aoqi@0 721 assert(x->number_of_arguments() == 4, "wrong type");
aoqi@0 722 LIRItem obj (x->argument_at(0), this); // object
aoqi@0 723 LIRItem offset(x->argument_at(1), this); // offset of field
aoqi@0 724 LIRItem cmp (x->argument_at(2), this); // value to compare with field
aoqi@0 725 LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp
aoqi@0 726
aoqi@0 727 assert(obj.type()->tag() == objectTag, "invalid type");
aoqi@0 728
aoqi@0 729 // In 64bit the type can be long, sparc doesn't have this assert
aoqi@0 730 // assert(offset.type()->tag() == intTag, "invalid type");
aoqi@0 731
aoqi@0 732 assert(cmp.type()->tag() == type->tag(), "invalid type");
aoqi@0 733 assert(val.type()->tag() == type->tag(), "invalid type");
aoqi@0 734
aoqi@0 735 // get address of field
aoqi@0 736 obj.load_item();
aoqi@0 737 offset.load_nonconstant();
aoqi@0 738
aoqi@0 739 if (type == objectType) {
aoqi@0 740 cmp.load_item_force(FrameMap::rax_oop_opr);
aoqi@0 741 val.load_item();
aoqi@0 742 } else if (type == intType) {
aoqi@0 743 cmp.load_item_force(FrameMap::rax_opr);
aoqi@0 744 val.load_item();
aoqi@0 745 } else if (type == longType) {
aoqi@0 746 cmp.load_item_force(FrameMap::long0_opr);
aoqi@0 747 val.load_item_force(FrameMap::long1_opr);
aoqi@0 748 } else {
aoqi@0 749 ShouldNotReachHere();
aoqi@0 750 }
aoqi@0 751
aoqi@0 752 LIR_Opr addr = new_pointer_register();
aoqi@0 753 LIR_Address* a;
aoqi@0 754 if(offset.result()->is_constant()) {
aoqi@0 755 #ifdef _LP64
aoqi@0 756 jlong c = offset.result()->as_jlong();
aoqi@0 757 if ((jlong)((jint)c) == c) {
aoqi@0 758 a = new LIR_Address(obj.result(),
aoqi@0 759 (jint)c,
aoqi@0 760 as_BasicType(type));
aoqi@0 761 } else {
aoqi@0 762 LIR_Opr tmp = new_register(T_LONG);
aoqi@0 763 __ move(offset.result(), tmp);
aoqi@0 764 a = new LIR_Address(obj.result(),
aoqi@0 765 tmp,
aoqi@0 766 as_BasicType(type));
aoqi@0 767 }
aoqi@0 768 #else
aoqi@0 769 a = new LIR_Address(obj.result(),
aoqi@0 770 offset.result()->as_jint(),
aoqi@0 771 as_BasicType(type));
aoqi@0 772 #endif
aoqi@0 773 } else {
aoqi@0 774 a = new LIR_Address(obj.result(),
aoqi@0 775 offset.result(),
aoqi@0 776 LIR_Address::times_1,
aoqi@0 777 0,
aoqi@0 778 as_BasicType(type));
aoqi@0 779 }
aoqi@0 780 __ leal(LIR_OprFact::address(a), addr);
aoqi@0 781
aoqi@0 782 if (type == objectType) { // Write-barrier needed for Object fields.
aoqi@0 783 // Do the pre-write barrier, if any.
aoqi@0 784 pre_barrier(addr, LIR_OprFact::illegalOpr /* pre_val */,
aoqi@0 785 true /* do_load */, false /* patch */, NULL);
aoqi@0 786 }
aoqi@0 787
aoqi@0 788 LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience
aoqi@0 789 if (type == objectType)
aoqi@0 790 __ cas_obj(addr, cmp.result(), val.result(), ill, ill);
aoqi@0 791 else if (type == intType)
aoqi@0 792 __ cas_int(addr, cmp.result(), val.result(), ill, ill);
aoqi@0 793 else if (type == longType)
aoqi@0 794 __ cas_long(addr, cmp.result(), val.result(), ill, ill);
aoqi@0 795 else {
aoqi@0 796 ShouldNotReachHere();
aoqi@0 797 }
aoqi@0 798
aoqi@0 799 // generate conditional move of boolean result
aoqi@0 800 LIR_Opr result = rlock_result(x);
aoqi@0 801 __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),
aoqi@0 802 result, as_BasicType(type));
aoqi@0 803 if (type == objectType) { // Write-barrier needed for Object fields.
aoqi@0 804 // Seems to be precise
aoqi@0 805 post_barrier(addr, val.result());
aoqi@0 806 }
aoqi@0 807 }
aoqi@0 808
aoqi@0 809
aoqi@0 810 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {
aoqi@0 811 assert(x->number_of_arguments() == 1 || (x->number_of_arguments() == 2 && x->id() == vmIntrinsics::_dpow), "wrong type");
aoqi@0 812 LIRItem value(x->argument_at(0), this);
aoqi@0 813
aoqi@0 814 bool use_fpu = false;
aoqi@0 815 if (UseSSE >= 2) {
aoqi@0 816 switch(x->id()) {
aoqi@0 817 case vmIntrinsics::_dsin:
aoqi@0 818 case vmIntrinsics::_dcos:
aoqi@0 819 case vmIntrinsics::_dtan:
aoqi@0 820 case vmIntrinsics::_dlog:
aoqi@0 821 case vmIntrinsics::_dlog10:
aoqi@0 822 case vmIntrinsics::_dexp:
aoqi@0 823 case vmIntrinsics::_dpow:
aoqi@0 824 use_fpu = true;
aoqi@0 825 }
aoqi@0 826 } else {
aoqi@0 827 value.set_destroys_register();
aoqi@0 828 }
aoqi@0 829
aoqi@0 830 value.load_item();
aoqi@0 831
aoqi@0 832 LIR_Opr calc_input = value.result();
aoqi@0 833 LIR_Opr calc_input2 = NULL;
aoqi@0 834 if (x->id() == vmIntrinsics::_dpow) {
aoqi@0 835 LIRItem extra_arg(x->argument_at(1), this);
aoqi@0 836 if (UseSSE < 2) {
aoqi@0 837 extra_arg.set_destroys_register();
aoqi@0 838 }
aoqi@0 839 extra_arg.load_item();
aoqi@0 840 calc_input2 = extra_arg.result();
aoqi@0 841 }
aoqi@0 842 LIR_Opr calc_result = rlock_result(x);
aoqi@0 843
aoqi@0 844 // sin, cos, pow and exp need two free fpu stack slots, so register
aoqi@0 845 // two temporary operands
aoqi@0 846 LIR_Opr tmp1 = FrameMap::caller_save_fpu_reg_at(0);
aoqi@0 847 LIR_Opr tmp2 = FrameMap::caller_save_fpu_reg_at(1);
aoqi@0 848
aoqi@0 849 if (use_fpu) {
aoqi@0 850 LIR_Opr tmp = FrameMap::fpu0_double_opr;
aoqi@0 851 int tmp_start = 1;
aoqi@0 852 if (calc_input2 != NULL) {
aoqi@0 853 __ move(calc_input2, tmp);
aoqi@0 854 tmp_start = 2;
aoqi@0 855 calc_input2 = tmp;
aoqi@0 856 }
aoqi@0 857 __ move(calc_input, tmp);
aoqi@0 858
aoqi@0 859 calc_input = tmp;
aoqi@0 860 calc_result = tmp;
aoqi@0 861
aoqi@0 862 tmp1 = FrameMap::caller_save_fpu_reg_at(tmp_start);
aoqi@0 863 tmp2 = FrameMap::caller_save_fpu_reg_at(tmp_start + 1);
aoqi@0 864 }
aoqi@0 865
aoqi@0 866 switch(x->id()) {
aoqi@0 867 case vmIntrinsics::_dabs: __ abs (calc_input, calc_result, LIR_OprFact::illegalOpr); break;
aoqi@0 868 case vmIntrinsics::_dsqrt: __ sqrt (calc_input, calc_result, LIR_OprFact::illegalOpr); break;
aoqi@0 869 case vmIntrinsics::_dsin: __ sin (calc_input, calc_result, tmp1, tmp2); break;
aoqi@0 870 case vmIntrinsics::_dcos: __ cos (calc_input, calc_result, tmp1, tmp2); break;
aoqi@0 871 case vmIntrinsics::_dtan: __ tan (calc_input, calc_result, tmp1, tmp2); break;
aoqi@0 872 case vmIntrinsics::_dlog: __ log (calc_input, calc_result, tmp1); break;
aoqi@0 873 case vmIntrinsics::_dlog10: __ log10(calc_input, calc_result, tmp1); break;
aoqi@0 874 case vmIntrinsics::_dexp: __ exp (calc_input, calc_result, tmp1, tmp2, FrameMap::rax_opr, FrameMap::rcx_opr, FrameMap::rdx_opr); break;
aoqi@0 875 case vmIntrinsics::_dpow: __ pow (calc_input, calc_input2, calc_result, tmp1, tmp2, FrameMap::rax_opr, FrameMap::rcx_opr, FrameMap::rdx_opr); break;
aoqi@0 876 default: ShouldNotReachHere();
aoqi@0 877 }
aoqi@0 878
aoqi@0 879 if (use_fpu) {
aoqi@0 880 __ move(calc_result, x->operand());
aoqi@0 881 }
aoqi@0 882 }
aoqi@0 883
aoqi@0 884
aoqi@0 885 void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
aoqi@0 886 assert(x->number_of_arguments() == 5, "wrong type");
aoqi@0 887
aoqi@0 888 // Make all state_for calls early since they can emit code
aoqi@0 889 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 890
aoqi@0 891 LIRItem src(x->argument_at(0), this);
aoqi@0 892 LIRItem src_pos(x->argument_at(1), this);
aoqi@0 893 LIRItem dst(x->argument_at(2), this);
aoqi@0 894 LIRItem dst_pos(x->argument_at(3), this);
aoqi@0 895 LIRItem length(x->argument_at(4), this);
aoqi@0 896
aoqi@0 897 // operands for arraycopy must use fixed registers, otherwise
aoqi@0 898 // LinearScan will fail allocation (because arraycopy always needs a
aoqi@0 899 // call)
aoqi@0 900
aoqi@0 901 #ifndef _LP64
aoqi@0 902 src.load_item_force (FrameMap::rcx_oop_opr);
aoqi@0 903 src_pos.load_item_force (FrameMap::rdx_opr);
aoqi@0 904 dst.load_item_force (FrameMap::rax_oop_opr);
aoqi@0 905 dst_pos.load_item_force (FrameMap::rbx_opr);
aoqi@0 906 length.load_item_force (FrameMap::rdi_opr);
aoqi@0 907 LIR_Opr tmp = (FrameMap::rsi_opr);
aoqi@0 908 #else
aoqi@0 909
aoqi@0 910 // The java calling convention will give us enough registers
aoqi@0 911 // so that on the stub side the args will be perfect already.
aoqi@0 912 // On the other slow/special case side we call C and the arg
aoqi@0 913 // positions are not similar enough to pick one as the best.
aoqi@0 914 // Also because the java calling convention is a "shifted" version
aoqi@0 915 // of the C convention we can process the java args trivially into C
aoqi@0 916 // args without worry of overwriting during the xfer
aoqi@0 917
aoqi@0 918 src.load_item_force (FrameMap::as_oop_opr(j_rarg0));
aoqi@0 919 src_pos.load_item_force (FrameMap::as_opr(j_rarg1));
aoqi@0 920 dst.load_item_force (FrameMap::as_oop_opr(j_rarg2));
aoqi@0 921 dst_pos.load_item_force (FrameMap::as_opr(j_rarg3));
aoqi@0 922 length.load_item_force (FrameMap::as_opr(j_rarg4));
aoqi@0 923
aoqi@0 924 LIR_Opr tmp = FrameMap::as_opr(j_rarg5);
aoqi@0 925 #endif // LP64
aoqi@0 926
aoqi@0 927 set_no_result(x);
aoqi@0 928
aoqi@0 929 int flags;
aoqi@0 930 ciArrayKlass* expected_type;
aoqi@0 931 arraycopy_helper(x, &flags, &expected_type);
aoqi@0 932
aoqi@0 933 __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), tmp, expected_type, flags, info); // does add_safepoint
aoqi@0 934 }
aoqi@0 935
aoqi@0 936 void LIRGenerator::do_update_CRC32(Intrinsic* x) {
aoqi@0 937 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");
aoqi@0 938 // Make all state_for calls early since they can emit code
aoqi@0 939 LIR_Opr result = rlock_result(x);
aoqi@0 940 int flags = 0;
aoqi@0 941 switch (x->id()) {
aoqi@0 942 case vmIntrinsics::_updateCRC32: {
aoqi@0 943 LIRItem crc(x->argument_at(0), this);
aoqi@0 944 LIRItem val(x->argument_at(1), this);
aoqi@0 945 // val is destroyed by update_crc32
aoqi@0 946 val.set_destroys_register();
aoqi@0 947 crc.load_item();
aoqi@0 948 val.load_item();
aoqi@0 949 __ update_crc32(crc.result(), val.result(), result);
aoqi@0 950 break;
aoqi@0 951 }
aoqi@0 952 case vmIntrinsics::_updateBytesCRC32:
aoqi@0 953 case vmIntrinsics::_updateByteBufferCRC32: {
aoqi@0 954 bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);
aoqi@0 955
aoqi@0 956 LIRItem crc(x->argument_at(0), this);
aoqi@0 957 LIRItem buf(x->argument_at(1), this);
aoqi@0 958 LIRItem off(x->argument_at(2), this);
aoqi@0 959 LIRItem len(x->argument_at(3), this);
aoqi@0 960 buf.load_item();
aoqi@0 961 off.load_nonconstant();
aoqi@0 962
aoqi@0 963 LIR_Opr index = off.result();
aoqi@0 964 int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
aoqi@0 965 if(off.result()->is_constant()) {
aoqi@0 966 index = LIR_OprFact::illegalOpr;
aoqi@0 967 offset += off.result()->as_jint();
aoqi@0 968 }
aoqi@0 969 LIR_Opr base_op = buf.result();
aoqi@0 970
aoqi@0 971 #ifndef _LP64
aoqi@0 972 if (!is_updateBytes) { // long b raw address
aoqi@0 973 base_op = new_register(T_INT);
aoqi@0 974 __ convert(Bytecodes::_l2i, buf.result(), base_op);
aoqi@0 975 }
aoqi@0 976 #else
aoqi@0 977 if (index->is_valid()) {
aoqi@0 978 LIR_Opr tmp = new_register(T_LONG);
aoqi@0 979 __ convert(Bytecodes::_i2l, index, tmp);
aoqi@0 980 index = tmp;
aoqi@0 981 }
aoqi@0 982 #endif
aoqi@0 983
aoqi@0 984 LIR_Address* a = new LIR_Address(base_op,
aoqi@0 985 index,
aoqi@0 986 LIR_Address::times_1,
aoqi@0 987 offset,
aoqi@0 988 T_BYTE);
aoqi@0 989 BasicTypeList signature(3);
aoqi@0 990 signature.append(T_INT);
aoqi@0 991 signature.append(T_ADDRESS);
aoqi@0 992 signature.append(T_INT);
aoqi@0 993 CallingConvention* cc = frame_map()->c_calling_convention(&signature);
aoqi@0 994 const LIR_Opr result_reg = result_register_for(x->type());
aoqi@0 995
aoqi@0 996 LIR_Opr addr = new_pointer_register();
aoqi@0 997 __ leal(LIR_OprFact::address(a), addr);
aoqi@0 998
aoqi@0 999 crc.load_item_force(cc->at(0));
aoqi@0 1000 __ move(addr, cc->at(1));
aoqi@0 1001 len.load_item_force(cc->at(2));
aoqi@0 1002
aoqi@0 1003 __ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());
aoqi@0 1004 __ move(result_reg, result);
aoqi@0 1005
aoqi@0 1006 break;
aoqi@0 1007 }
aoqi@0 1008 default: {
aoqi@0 1009 ShouldNotReachHere();
aoqi@0 1010 }
aoqi@0 1011 }
aoqi@0 1012 }
aoqi@0 1013
aoqi@0 1014 // _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f
aoqi@0 1015 // _i2b, _i2c, _i2s
aoqi@0 1016 LIR_Opr fixed_register_for(BasicType type) {
aoqi@0 1017 switch (type) {
aoqi@0 1018 case T_FLOAT: return FrameMap::fpu0_float_opr;
aoqi@0 1019 case T_DOUBLE: return FrameMap::fpu0_double_opr;
aoqi@0 1020 case T_INT: return FrameMap::rax_opr;
aoqi@0 1021 case T_LONG: return FrameMap::long0_opr;
aoqi@0 1022 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
aoqi@0 1023 }
aoqi@0 1024 }
aoqi@0 1025
aoqi@0 1026 void LIRGenerator::do_Convert(Convert* x) {
aoqi@0 1027 // flags that vary for the different operations and different SSE-settings
csahu@8316 1028 bool fixed_input = false, fixed_result = false, round_result = false, needs_stub = false;
aoqi@0 1029
aoqi@0 1030 switch (x->op()) {
aoqi@0 1031 case Bytecodes::_i2l: // fall through
aoqi@0 1032 case Bytecodes::_l2i: // fall through
aoqi@0 1033 case Bytecodes::_i2b: // fall through
aoqi@0 1034 case Bytecodes::_i2c: // fall through
aoqi@0 1035 case Bytecodes::_i2s: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;
aoqi@0 1036
aoqi@0 1037 case Bytecodes::_f2d: fixed_input = UseSSE == 1; fixed_result = false; round_result = false; needs_stub = false; break;
aoqi@0 1038 case Bytecodes::_d2f: fixed_input = false; fixed_result = UseSSE == 1; round_result = UseSSE < 1; needs_stub = false; break;
aoqi@0 1039 case Bytecodes::_i2f: fixed_input = false; fixed_result = false; round_result = UseSSE < 1; needs_stub = false; break;
aoqi@0 1040 case Bytecodes::_i2d: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;
aoqi@0 1041 case Bytecodes::_f2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;
aoqi@0 1042 case Bytecodes::_d2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;
aoqi@0 1043 case Bytecodes::_l2f: fixed_input = false; fixed_result = UseSSE >= 1; round_result = UseSSE < 1; needs_stub = false; break;
aoqi@0 1044 case Bytecodes::_l2d: fixed_input = false; fixed_result = UseSSE >= 2; round_result = UseSSE < 2; needs_stub = false; break;
aoqi@0 1045 case Bytecodes::_f2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;
aoqi@0 1046 case Bytecodes::_d2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;
aoqi@0 1047 default: ShouldNotReachHere();
aoqi@0 1048 }
aoqi@0 1049
aoqi@0 1050 LIRItem value(x->value(), this);
aoqi@0 1051 value.load_item();
aoqi@0 1052 LIR_Opr input = value.result();
aoqi@0 1053 LIR_Opr result = rlock(x);
aoqi@0 1054
aoqi@0 1055 // arguments of lir_convert
aoqi@0 1056 LIR_Opr conv_input = input;
aoqi@0 1057 LIR_Opr conv_result = result;
aoqi@0 1058 ConversionStub* stub = NULL;
aoqi@0 1059
aoqi@0 1060 if (fixed_input) {
aoqi@0 1061 conv_input = fixed_register_for(input->type());
aoqi@0 1062 __ move(input, conv_input);
aoqi@0 1063 }
aoqi@0 1064
aoqi@0 1065 assert(fixed_result == false || round_result == false, "cannot set both");
aoqi@0 1066 if (fixed_result) {
aoqi@0 1067 conv_result = fixed_register_for(result->type());
aoqi@0 1068 } else if (round_result) {
aoqi@0 1069 result = new_register(result->type());
aoqi@0 1070 set_vreg_flag(result, must_start_in_memory);
aoqi@0 1071 }
aoqi@0 1072
aoqi@0 1073 if (needs_stub) {
aoqi@0 1074 stub = new ConversionStub(x->op(), conv_input, conv_result);
aoqi@0 1075 }
aoqi@0 1076
aoqi@0 1077 __ convert(x->op(), conv_input, conv_result, stub);
aoqi@0 1078
aoqi@0 1079 if (result != conv_result) {
aoqi@0 1080 __ move(conv_result, result);
aoqi@0 1081 }
aoqi@0 1082
aoqi@0 1083 assert(result->is_virtual(), "result must be virtual register");
aoqi@0 1084 set_result(x, result);
aoqi@0 1085 }
aoqi@0 1086
aoqi@0 1087
aoqi@0 1088 void LIRGenerator::do_NewInstance(NewInstance* x) {
rbackman@7058 1089 print_if_not_loaded(x);
rbackman@7058 1090
aoqi@0 1091 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 1092 LIR_Opr reg = result_register_for(x->type());
rbackman@7058 1093 new_instance(reg, x->klass(), x->is_unresolved(),
aoqi@0 1094 FrameMap::rcx_oop_opr,
aoqi@0 1095 FrameMap::rdi_oop_opr,
aoqi@0 1096 FrameMap::rsi_oop_opr,
aoqi@0 1097 LIR_OprFact::illegalOpr,
aoqi@0 1098 FrameMap::rdx_metadata_opr, info);
aoqi@0 1099 LIR_Opr result = rlock_result(x);
aoqi@0 1100 __ move(reg, result);
aoqi@0 1101 }
aoqi@0 1102
aoqi@0 1103
aoqi@0 1104 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
aoqi@0 1105 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 1106
aoqi@0 1107 LIRItem length(x->length(), this);
aoqi@0 1108 length.load_item_force(FrameMap::rbx_opr);
aoqi@0 1109
aoqi@0 1110 LIR_Opr reg = result_register_for(x->type());
aoqi@0 1111 LIR_Opr tmp1 = FrameMap::rcx_oop_opr;
aoqi@0 1112 LIR_Opr tmp2 = FrameMap::rsi_oop_opr;
aoqi@0 1113 LIR_Opr tmp3 = FrameMap::rdi_oop_opr;
aoqi@0 1114 LIR_Opr tmp4 = reg;
aoqi@0 1115 LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;
aoqi@0 1116 LIR_Opr len = length.result();
aoqi@0 1117 BasicType elem_type = x->elt_type();
aoqi@0 1118
aoqi@0 1119 __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
aoqi@0 1120
aoqi@0 1121 CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
aoqi@0 1122 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);
aoqi@0 1123
aoqi@0 1124 LIR_Opr result = rlock_result(x);
aoqi@0 1125 __ move(reg, result);
aoqi@0 1126 }
aoqi@0 1127
aoqi@0 1128
aoqi@0 1129 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
aoqi@0 1130 LIRItem length(x->length(), this);
aoqi@0 1131 // in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction
aoqi@0 1132 // and therefore provide the state before the parameters have been consumed
aoqi@0 1133 CodeEmitInfo* patching_info = NULL;
aoqi@0 1134 if (!x->klass()->is_loaded() || PatchALot) {
aoqi@0 1135 patching_info = state_for(x, x->state_before());
aoqi@0 1136 }
aoqi@0 1137
aoqi@0 1138 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 1139
aoqi@0 1140 const LIR_Opr reg = result_register_for(x->type());
aoqi@0 1141 LIR_Opr tmp1 = FrameMap::rcx_oop_opr;
aoqi@0 1142 LIR_Opr tmp2 = FrameMap::rsi_oop_opr;
aoqi@0 1143 LIR_Opr tmp3 = FrameMap::rdi_oop_opr;
aoqi@0 1144 LIR_Opr tmp4 = reg;
aoqi@0 1145 LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;
aoqi@0 1146
aoqi@0 1147 length.load_item_force(FrameMap::rbx_opr);
aoqi@0 1148 LIR_Opr len = length.result();
aoqi@0 1149
aoqi@0 1150 CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
aoqi@0 1151 ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());
aoqi@0 1152 if (obj == ciEnv::unloaded_ciobjarrayklass()) {
aoqi@0 1153 BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
aoqi@0 1154 }
aoqi@0 1155 klass2reg_with_patching(klass_reg, obj, patching_info);
aoqi@0 1156 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);
aoqi@0 1157
aoqi@0 1158 LIR_Opr result = rlock_result(x);
aoqi@0 1159 __ move(reg, result);
aoqi@0 1160 }
aoqi@0 1161
aoqi@0 1162
aoqi@0 1163 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
aoqi@0 1164 Values* dims = x->dims();
aoqi@0 1165 int i = dims->length();
aoqi@0 1166 LIRItemList* items = new LIRItemList(dims->length(), NULL);
aoqi@0 1167 while (i-- > 0) {
aoqi@0 1168 LIRItem* size = new LIRItem(dims->at(i), this);
aoqi@0 1169 items->at_put(i, size);
aoqi@0 1170 }
aoqi@0 1171
aoqi@0 1172 // Evaluate state_for early since it may emit code.
aoqi@0 1173 CodeEmitInfo* patching_info = NULL;
aoqi@0 1174 if (!x->klass()->is_loaded() || PatchALot) {
aoqi@0 1175 patching_info = state_for(x, x->state_before());
aoqi@0 1176
aoqi@0 1177 // Cannot re-use same xhandlers for multiple CodeEmitInfos, so
aoqi@0 1178 // clone all handlers (NOTE: Usually this is handled transparently
aoqi@0 1179 // by the CodeEmitInfo cloning logic in CodeStub constructors but
aoqi@0 1180 // is done explicitly here because a stub isn't being used).
aoqi@0 1181 x->set_exception_handlers(new XHandlers(x->exception_handlers()));
aoqi@0 1182 }
aoqi@0 1183 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 1184
aoqi@0 1185 i = dims->length();
aoqi@0 1186 while (i-- > 0) {
aoqi@0 1187 LIRItem* size = items->at(i);
aoqi@0 1188 size->load_nonconstant();
aoqi@0 1189
aoqi@0 1190 store_stack_parameter(size->result(), in_ByteSize(i*4));
aoqi@0 1191 }
aoqi@0 1192
aoqi@0 1193 LIR_Opr klass_reg = FrameMap::rax_metadata_opr;
aoqi@0 1194 klass2reg_with_patching(klass_reg, x->klass(), patching_info);
aoqi@0 1195
aoqi@0 1196 LIR_Opr rank = FrameMap::rbx_opr;
aoqi@0 1197 __ move(LIR_OprFact::intConst(x->rank()), rank);
aoqi@0 1198 LIR_Opr varargs = FrameMap::rcx_opr;
aoqi@0 1199 __ move(FrameMap::rsp_opr, varargs);
aoqi@0 1200 LIR_OprList* args = new LIR_OprList(3);
aoqi@0 1201 args->append(klass_reg);
aoqi@0 1202 args->append(rank);
aoqi@0 1203 args->append(varargs);
aoqi@0 1204 LIR_Opr reg = result_register_for(x->type());
aoqi@0 1205 __ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),
aoqi@0 1206 LIR_OprFact::illegalOpr,
aoqi@0 1207 reg, args, info);
aoqi@0 1208
aoqi@0 1209 LIR_Opr result = rlock_result(x);
aoqi@0 1210 __ move(reg, result);
aoqi@0 1211 }
aoqi@0 1212
aoqi@0 1213
aoqi@0 1214 void LIRGenerator::do_BlockBegin(BlockBegin* x) {
aoqi@0 1215 // nothing to do for now
aoqi@0 1216 }
aoqi@0 1217
aoqi@0 1218
aoqi@0 1219 void LIRGenerator::do_CheckCast(CheckCast* x) {
aoqi@0 1220 LIRItem obj(x->obj(), this);
aoqi@0 1221
aoqi@0 1222 CodeEmitInfo* patching_info = NULL;
aoqi@0 1223 if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) {
aoqi@0 1224 // must do this before locking the destination register as an oop register,
aoqi@0 1225 // and before the obj is loaded (the latter is for deoptimization)
aoqi@0 1226 patching_info = state_for(x, x->state_before());
aoqi@0 1227 }
aoqi@0 1228 obj.load_item();
aoqi@0 1229
aoqi@0 1230 // info for exceptions
aoqi@0 1231 CodeEmitInfo* info_for_exception = state_for(x);
aoqi@0 1232
aoqi@0 1233 CodeStub* stub;
aoqi@0 1234 if (x->is_incompatible_class_change_check()) {
aoqi@0 1235 assert(patching_info == NULL, "can't patch this");
aoqi@0 1236 stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);
aoqi@0 1237 } else {
aoqi@0 1238 stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);
aoqi@0 1239 }
aoqi@0 1240 LIR_Opr reg = rlock_result(x);
aoqi@0 1241 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
aoqi@0 1242 if (!x->klass()->is_loaded() || UseCompressedClassPointers) {
aoqi@0 1243 tmp3 = new_register(objectType);
aoqi@0 1244 }
aoqi@0 1245 __ checkcast(reg, obj.result(), x->klass(),
aoqi@0 1246 new_register(objectType), new_register(objectType), tmp3,
aoqi@0 1247 x->direct_compare(), info_for_exception, patching_info, stub,
aoqi@0 1248 x->profiled_method(), x->profiled_bci());
aoqi@0 1249 }
aoqi@0 1250
aoqi@0 1251
aoqi@0 1252 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
aoqi@0 1253 LIRItem obj(x->obj(), this);
aoqi@0 1254
aoqi@0 1255 // result and test object may not be in same register
aoqi@0 1256 LIR_Opr reg = rlock_result(x);
aoqi@0 1257 CodeEmitInfo* patching_info = NULL;
aoqi@0 1258 if ((!x->klass()->is_loaded() || PatchALot)) {
aoqi@0 1259 // must do this before locking the destination register as an oop register
aoqi@0 1260 patching_info = state_for(x, x->state_before());
aoqi@0 1261 }
aoqi@0 1262 obj.load_item();
aoqi@0 1263 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
aoqi@0 1264 if (!x->klass()->is_loaded() || UseCompressedClassPointers) {
aoqi@0 1265 tmp3 = new_register(objectType);
aoqi@0 1266 }
aoqi@0 1267 __ instanceof(reg, obj.result(), x->klass(),
aoqi@0 1268 new_register(objectType), new_register(objectType), tmp3,
aoqi@0 1269 x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());
aoqi@0 1270 }
aoqi@0 1271
aoqi@0 1272
aoqi@0 1273 void LIRGenerator::do_If(If* x) {
aoqi@0 1274 assert(x->number_of_sux() == 2, "inconsistency");
aoqi@0 1275 ValueTag tag = x->x()->type()->tag();
aoqi@0 1276 bool is_safepoint = x->is_safepoint();
aoqi@0 1277
aoqi@0 1278 If::Condition cond = x->cond();
aoqi@0 1279
aoqi@0 1280 LIRItem xitem(x->x(), this);
aoqi@0 1281 LIRItem yitem(x->y(), this);
aoqi@0 1282 LIRItem* xin = &xitem;
aoqi@0 1283 LIRItem* yin = &yitem;
aoqi@0 1284
aoqi@0 1285 if (tag == longTag) {
aoqi@0 1286 // for longs, only conditions "eql", "neq", "lss", "geq" are valid;
aoqi@0 1287 // mirror for other conditions
aoqi@0 1288 if (cond == If::gtr || cond == If::leq) {
aoqi@0 1289 cond = Instruction::mirror(cond);
aoqi@0 1290 xin = &yitem;
aoqi@0 1291 yin = &xitem;
aoqi@0 1292 }
aoqi@0 1293 xin->set_destroys_register();
aoqi@0 1294 }
aoqi@0 1295 xin->load_item();
aoqi@0 1296 if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {
aoqi@0 1297 // inline long zero
aoqi@0 1298 yin->dont_load_item();
aoqi@0 1299 } else if (tag == longTag || tag == floatTag || tag == doubleTag) {
aoqi@0 1300 // longs cannot handle constants at right side
aoqi@0 1301 yin->load_item();
aoqi@0 1302 } else {
aoqi@0 1303 yin->dont_load_item();
aoqi@0 1304 }
aoqi@0 1305
aoqi@0 1306 // add safepoint before generating condition code so it can be recomputed
aoqi@0 1307 if (x->is_safepoint()) {
aoqi@0 1308 // increment backedge counter if needed
aoqi@0 1309 increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());
aoqi@0 1310 __ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before()));
aoqi@0 1311 }
aoqi@0 1312 set_no_result(x);
aoqi@0 1313
aoqi@0 1314 LIR_Opr left = xin->result();
aoqi@0 1315 LIR_Opr right = yin->result();
aoqi@0 1316 __ cmp(lir_cond(cond), left, right);
aoqi@0 1317 // Generate branch profiling. Profiling code doesn't kill flags.
aoqi@0 1318 profile_branch(x, cond);
aoqi@0 1319 move_to_phi(x->state());
aoqi@0 1320 if (x->x()->type()->is_float_kind()) {
aoqi@0 1321 __ branch(lir_cond(cond), right->type(), x->tsux(), x->usux());
aoqi@0 1322 } else {
aoqi@0 1323 __ branch(lir_cond(cond), right->type(), x->tsux());
aoqi@0 1324 }
aoqi@0 1325 assert(x->default_sux() == x->fsux(), "wrong destination above");
aoqi@0 1326 __ jump(x->default_sux());
aoqi@0 1327 }
aoqi@0 1328
aoqi@0 1329
aoqi@0 1330 LIR_Opr LIRGenerator::getThreadPointer() {
aoqi@0 1331 #ifdef _LP64
aoqi@0 1332 return FrameMap::as_pointer_opr(r15_thread);
aoqi@0 1333 #else
aoqi@0 1334 LIR_Opr result = new_register(T_INT);
aoqi@0 1335 __ get_thread(result);
aoqi@0 1336 return result;
aoqi@0 1337 #endif //
aoqi@0 1338 }
aoqi@0 1339
aoqi@0 1340 void LIRGenerator::trace_block_entry(BlockBegin* block) {
aoqi@0 1341 store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0));
aoqi@0 1342 LIR_OprList* args = new LIR_OprList();
aoqi@0 1343 address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);
aoqi@0 1344 __ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);
aoqi@0 1345 }
aoqi@0 1346
aoqi@0 1347
aoqi@0 1348 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,
aoqi@0 1349 CodeEmitInfo* info) {
aoqi@0 1350 if (address->type() == T_LONG) {
aoqi@0 1351 address = new LIR_Address(address->base(),
aoqi@0 1352 address->index(), address->scale(),
aoqi@0 1353 address->disp(), T_DOUBLE);
aoqi@0 1354 // Transfer the value atomically by using FP moves. This means
aoqi@0 1355 // the value has to be moved between CPU and FPU registers. It
aoqi@0 1356 // always has to be moved through spill slot since there's no
aoqi@0 1357 // quick way to pack the value into an SSE register.
aoqi@0 1358 LIR_Opr temp_double = new_register(T_DOUBLE);
aoqi@0 1359 LIR_Opr spill = new_register(T_LONG);
aoqi@0 1360 set_vreg_flag(spill, must_start_in_memory);
aoqi@0 1361 __ move(value, spill);
aoqi@0 1362 __ volatile_move(spill, temp_double, T_LONG);
aoqi@0 1363 __ volatile_move(temp_double, LIR_OprFact::address(address), T_LONG, info);
aoqi@0 1364 } else {
aoqi@0 1365 __ store(value, address, info);
aoqi@0 1366 }
aoqi@0 1367 }
aoqi@0 1368
aoqi@0 1369
aoqi@0 1370
aoqi@0 1371 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,
aoqi@0 1372 CodeEmitInfo* info) {
aoqi@0 1373 if (address->type() == T_LONG) {
aoqi@0 1374 address = new LIR_Address(address->base(),
aoqi@0 1375 address->index(), address->scale(),
aoqi@0 1376 address->disp(), T_DOUBLE);
aoqi@0 1377 // Transfer the value atomically by using FP moves. This means
aoqi@0 1378 // the value has to be moved between CPU and FPU registers. In
aoqi@0 1379 // SSE0 and SSE1 mode it has to be moved through spill slot but in
aoqi@0 1380 // SSE2+ mode it can be moved directly.
aoqi@0 1381 LIR_Opr temp_double = new_register(T_DOUBLE);
aoqi@0 1382 __ volatile_move(LIR_OprFact::address(address), temp_double, T_LONG, info);
aoqi@0 1383 __ volatile_move(temp_double, result, T_LONG);
aoqi@0 1384 if (UseSSE < 2) {
aoqi@0 1385 // no spill slot needed in SSE2 mode because xmm->cpu register move is possible
aoqi@0 1386 set_vreg_flag(result, must_start_in_memory);
aoqi@0 1387 }
aoqi@0 1388 } else {
aoqi@0 1389 __ load(address, result, info);
aoqi@0 1390 }
aoqi@0 1391 }
aoqi@0 1392
aoqi@0 1393 void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset,
aoqi@0 1394 BasicType type, bool is_volatile) {
aoqi@0 1395 if (is_volatile && type == T_LONG) {
aoqi@0 1396 LIR_Address* addr = new LIR_Address(src, offset, T_DOUBLE);
aoqi@0 1397 LIR_Opr tmp = new_register(T_DOUBLE);
aoqi@0 1398 __ load(addr, tmp);
aoqi@0 1399 LIR_Opr spill = new_register(T_LONG);
aoqi@0 1400 set_vreg_flag(spill, must_start_in_memory);
aoqi@0 1401 __ move(tmp, spill);
aoqi@0 1402 __ move(spill, dst);
aoqi@0 1403 } else {
aoqi@0 1404 LIR_Address* addr = new LIR_Address(src, offset, type);
aoqi@0 1405 __ load(addr, dst);
aoqi@0 1406 }
aoqi@0 1407 }
aoqi@0 1408
aoqi@0 1409
aoqi@0 1410 void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data,
aoqi@0 1411 BasicType type, bool is_volatile) {
aoqi@0 1412 if (is_volatile && type == T_LONG) {
aoqi@0 1413 LIR_Address* addr = new LIR_Address(src, offset, T_DOUBLE);
aoqi@0 1414 LIR_Opr tmp = new_register(T_DOUBLE);
aoqi@0 1415 LIR_Opr spill = new_register(T_DOUBLE);
aoqi@0 1416 set_vreg_flag(spill, must_start_in_memory);
aoqi@0 1417 __ move(data, spill);
aoqi@0 1418 __ move(spill, tmp);
aoqi@0 1419 __ move(tmp, addr);
aoqi@0 1420 } else {
aoqi@0 1421 LIR_Address* addr = new LIR_Address(src, offset, type);
aoqi@0 1422 bool is_obj = (type == T_ARRAY || type == T_OBJECT);
aoqi@0 1423 if (is_obj) {
aoqi@0 1424 // Do the pre-write barrier, if any.
aoqi@0 1425 pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,
aoqi@0 1426 true /* do_load */, false /* patch */, NULL);
aoqi@0 1427 __ move(data, addr);
aoqi@0 1428 assert(src->is_register(), "must be register");
aoqi@0 1429 // Seems to be a precise address
aoqi@0 1430 post_barrier(LIR_OprFact::address(addr), data);
aoqi@0 1431 } else {
aoqi@0 1432 __ move(data, addr);
aoqi@0 1433 }
aoqi@0 1434 }
aoqi@0 1435 }
aoqi@0 1436
aoqi@0 1437 void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {
aoqi@0 1438 BasicType type = x->basic_type();
aoqi@0 1439 LIRItem src(x->object(), this);
aoqi@0 1440 LIRItem off(x->offset(), this);
aoqi@0 1441 LIRItem value(x->value(), this);
aoqi@0 1442
aoqi@0 1443 src.load_item();
aoqi@0 1444 value.load_item();
aoqi@0 1445 off.load_nonconstant();
aoqi@0 1446
aoqi@0 1447 LIR_Opr dst = rlock_result(x, type);
aoqi@0 1448 LIR_Opr data = value.result();
aoqi@0 1449 bool is_obj = (type == T_ARRAY || type == T_OBJECT);
aoqi@0 1450 LIR_Opr offset = off.result();
aoqi@0 1451
aoqi@0 1452 assert (type == T_INT || (!x->is_add() && is_obj) LP64_ONLY( || type == T_LONG ), "unexpected type");
aoqi@0 1453 LIR_Address* addr;
aoqi@0 1454 if (offset->is_constant()) {
aoqi@0 1455 #ifdef _LP64
aoqi@0 1456 jlong c = offset->as_jlong();
aoqi@0 1457 if ((jlong)((jint)c) == c) {
aoqi@0 1458 addr = new LIR_Address(src.result(), (jint)c, type);
aoqi@0 1459 } else {
aoqi@0 1460 LIR_Opr tmp = new_register(T_LONG);
aoqi@0 1461 __ move(offset, tmp);
aoqi@0 1462 addr = new LIR_Address(src.result(), tmp, type);
aoqi@0 1463 }
aoqi@0 1464 #else
aoqi@0 1465 addr = new LIR_Address(src.result(), offset->as_jint(), type);
aoqi@0 1466 #endif
aoqi@0 1467 } else {
aoqi@0 1468 addr = new LIR_Address(src.result(), offset, type);
aoqi@0 1469 }
aoqi@0 1470
aoqi@0 1471 // Because we want a 2-arg form of xchg and xadd
aoqi@0 1472 __ move(data, dst);
aoqi@0 1473
aoqi@0 1474 if (x->is_add()) {
aoqi@0 1475 __ xadd(LIR_OprFact::address(addr), dst, dst, LIR_OprFact::illegalOpr);
aoqi@0 1476 } else {
aoqi@0 1477 if (is_obj) {
aoqi@0 1478 // Do the pre-write barrier, if any.
aoqi@0 1479 pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,
aoqi@0 1480 true /* do_load */, false /* patch */, NULL);
aoqi@0 1481 }
aoqi@0 1482 __ xchg(LIR_OprFact::address(addr), dst, dst, LIR_OprFact::illegalOpr);
aoqi@0 1483 if (is_obj) {
aoqi@0 1484 // Seems to be a precise address
aoqi@0 1485 post_barrier(LIR_OprFact::address(addr), data);
aoqi@0 1486 }
aoqi@0 1487 }
aoqi@0 1488 }

mercurial