src/cpu/x86/vm/c1_LIRGenerator_x86.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7058
2fd0fd493045
parent 6876
710a3c8b516e
child 8604
04d83ba48607
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, 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) {
aoqi@0 198 LIR_Opr r;
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 }
aoqi@0 286 if (needs_store_check) {
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 {
aoqi@0 334 __ move(value.result(), array_addr, null_check_info);
aoqi@0 335 }
aoqi@0 336 }
aoqi@0 337
aoqi@0 338
aoqi@0 339 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
aoqi@0 340 assert(x->is_pinned(),"");
aoqi@0 341 LIRItem obj(x->obj(), this);
aoqi@0 342 obj.load_item();
aoqi@0 343
aoqi@0 344 set_no_result(x);
aoqi@0 345
aoqi@0 346 // "lock" stores the address of the monitor stack slot, so this is not an oop
aoqi@0 347 LIR_Opr lock = new_register(T_INT);
aoqi@0 348 // Need a scratch register for biased locking on x86
aoqi@0 349 LIR_Opr scratch = LIR_OprFact::illegalOpr;
aoqi@0 350 if (UseBiasedLocking) {
aoqi@0 351 scratch = new_register(T_INT);
aoqi@0 352 }
aoqi@0 353
aoqi@0 354 CodeEmitInfo* info_for_exception = NULL;
aoqi@0 355 if (x->needs_null_check()) {
aoqi@0 356 info_for_exception = state_for(x);
aoqi@0 357 }
aoqi@0 358 // this CodeEmitInfo must not have the xhandlers because here the
aoqi@0 359 // object is already locked (xhandlers expect object to be unlocked)
aoqi@0 360 CodeEmitInfo* info = state_for(x, x->state(), true);
aoqi@0 361 monitor_enter(obj.result(), lock, syncTempOpr(), scratch,
aoqi@0 362 x->monitor_no(), info_for_exception, info);
aoqi@0 363 }
aoqi@0 364
aoqi@0 365
aoqi@0 366 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
aoqi@0 367 assert(x->is_pinned(),"");
aoqi@0 368
aoqi@0 369 LIRItem obj(x->obj(), this);
aoqi@0 370 obj.dont_load_item();
aoqi@0 371
aoqi@0 372 LIR_Opr lock = new_register(T_INT);
aoqi@0 373 LIR_Opr obj_temp = new_register(T_INT);
aoqi@0 374 set_no_result(x);
aoqi@0 375 monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());
aoqi@0 376 }
aoqi@0 377
aoqi@0 378
aoqi@0 379 // _ineg, _lneg, _fneg, _dneg
aoqi@0 380 void LIRGenerator::do_NegateOp(NegateOp* x) {
aoqi@0 381 LIRItem value(x->x(), this);
aoqi@0 382 value.set_destroys_register();
aoqi@0 383 value.load_item();
aoqi@0 384 LIR_Opr reg = rlock(x);
aoqi@0 385 __ negate(value.result(), reg);
aoqi@0 386
aoqi@0 387 set_result(x, round_item(reg));
aoqi@0 388 }
aoqi@0 389
aoqi@0 390
aoqi@0 391 // for _fadd, _fmul, _fsub, _fdiv, _frem
aoqi@0 392 // _dadd, _dmul, _dsub, _ddiv, _drem
aoqi@0 393 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {
aoqi@0 394 LIRItem left(x->x(), this);
aoqi@0 395 LIRItem right(x->y(), this);
aoqi@0 396 LIRItem* left_arg = &left;
aoqi@0 397 LIRItem* right_arg = &right;
aoqi@0 398 assert(!left.is_stack() || !right.is_stack(), "can't both be memory operands");
aoqi@0 399 bool must_load_both = (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem);
aoqi@0 400 if (left.is_register() || x->x()->type()->is_constant() || must_load_both) {
aoqi@0 401 left.load_item();
aoqi@0 402 } else {
aoqi@0 403 left.dont_load_item();
aoqi@0 404 }
aoqi@0 405
aoqi@0 406 // do not load right operand if it is a constant. only 0 and 1 are
aoqi@0 407 // loaded because there are special instructions for loading them
aoqi@0 408 // without memory access (not needed for SSE2 instructions)
aoqi@0 409 bool must_load_right = false;
aoqi@0 410 if (right.is_constant()) {
aoqi@0 411 LIR_Const* c = right.result()->as_constant_ptr();
aoqi@0 412 assert(c != NULL, "invalid constant");
aoqi@0 413 assert(c->type() == T_FLOAT || c->type() == T_DOUBLE, "invalid type");
aoqi@0 414
aoqi@0 415 if (c->type() == T_FLOAT) {
aoqi@0 416 must_load_right = UseSSE < 1 && (c->is_one_float() || c->is_zero_float());
aoqi@0 417 } else {
aoqi@0 418 must_load_right = UseSSE < 2 && (c->is_one_double() || c->is_zero_double());
aoqi@0 419 }
aoqi@0 420 }
aoqi@0 421
aoqi@0 422 if (must_load_both) {
aoqi@0 423 // frem and drem destroy also right operand, so move it to a new register
aoqi@0 424 right.set_destroys_register();
aoqi@0 425 right.load_item();
aoqi@0 426 } else if (right.is_register() || must_load_right) {
aoqi@0 427 right.load_item();
aoqi@0 428 } else {
aoqi@0 429 right.dont_load_item();
aoqi@0 430 }
aoqi@0 431 LIR_Opr reg = rlock(x);
aoqi@0 432 LIR_Opr tmp = LIR_OprFact::illegalOpr;
aoqi@0 433 if (x->is_strictfp() && (x->op() == Bytecodes::_dmul || x->op() == Bytecodes::_ddiv)) {
aoqi@0 434 tmp = new_register(T_DOUBLE);
aoqi@0 435 }
aoqi@0 436
aoqi@0 437 if ((UseSSE >= 1 && x->op() == Bytecodes::_frem) || (UseSSE >= 2 && x->op() == Bytecodes::_drem)) {
aoqi@0 438 // special handling for frem and drem: no SSE instruction, so must use FPU with temporary fpu stack slots
aoqi@0 439 LIR_Opr fpu0, fpu1;
aoqi@0 440 if (x->op() == Bytecodes::_frem) {
aoqi@0 441 fpu0 = LIR_OprFact::single_fpu(0);
aoqi@0 442 fpu1 = LIR_OprFact::single_fpu(1);
aoqi@0 443 } else {
aoqi@0 444 fpu0 = LIR_OprFact::double_fpu(0);
aoqi@0 445 fpu1 = LIR_OprFact::double_fpu(1);
aoqi@0 446 }
aoqi@0 447 __ move(right.result(), fpu1); // order of left and right operand is important!
aoqi@0 448 __ move(left.result(), fpu0);
aoqi@0 449 __ rem (fpu0, fpu1, fpu0);
aoqi@0 450 __ move(fpu0, reg);
aoqi@0 451
aoqi@0 452 } else {
aoqi@0 453 arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), x->is_strictfp(), tmp);
aoqi@0 454 }
aoqi@0 455
aoqi@0 456 set_result(x, round_item(reg));
aoqi@0 457 }
aoqi@0 458
aoqi@0 459
aoqi@0 460 // for _ladd, _lmul, _lsub, _ldiv, _lrem
aoqi@0 461 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {
aoqi@0 462 if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem ) {
aoqi@0 463 // long division is implemented as a direct call into the runtime
aoqi@0 464 LIRItem left(x->x(), this);
aoqi@0 465 LIRItem right(x->y(), this);
aoqi@0 466
aoqi@0 467 // the check for division by zero destroys the right operand
aoqi@0 468 right.set_destroys_register();
aoqi@0 469
aoqi@0 470 BasicTypeList signature(2);
aoqi@0 471 signature.append(T_LONG);
aoqi@0 472 signature.append(T_LONG);
aoqi@0 473 CallingConvention* cc = frame_map()->c_calling_convention(&signature);
aoqi@0 474
aoqi@0 475 // check for division by zero (destroys registers of right operand!)
aoqi@0 476 CodeEmitInfo* info = state_for(x);
aoqi@0 477
aoqi@0 478 const LIR_Opr result_reg = result_register_for(x->type());
aoqi@0 479 left.load_item_force(cc->at(1));
aoqi@0 480 right.load_item();
aoqi@0 481
aoqi@0 482 __ move(right.result(), cc->at(0));
aoqi@0 483
aoqi@0 484 __ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));
aoqi@0 485 __ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info));
aoqi@0 486
aoqi@0 487 address entry;
aoqi@0 488 switch (x->op()) {
aoqi@0 489 case Bytecodes::_lrem:
aoqi@0 490 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);
aoqi@0 491 break; // check if dividend is 0 is done elsewhere
aoqi@0 492 case Bytecodes::_ldiv:
aoqi@0 493 entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);
aoqi@0 494 break; // check if dividend is 0 is done elsewhere
aoqi@0 495 case Bytecodes::_lmul:
aoqi@0 496 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul);
aoqi@0 497 break;
aoqi@0 498 default:
aoqi@0 499 ShouldNotReachHere();
aoqi@0 500 }
aoqi@0 501
aoqi@0 502 LIR_Opr result = rlock_result(x);
aoqi@0 503 __ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());
aoqi@0 504 __ move(result_reg, result);
aoqi@0 505 } else if (x->op() == Bytecodes::_lmul) {
aoqi@0 506 // missing test if instr is commutative and if we should swap
aoqi@0 507 LIRItem left(x->x(), this);
aoqi@0 508 LIRItem right(x->y(), this);
aoqi@0 509
aoqi@0 510 // right register is destroyed by the long mul, so it must be
aoqi@0 511 // copied to a new register.
aoqi@0 512 right.set_destroys_register();
aoqi@0 513
aoqi@0 514 left.load_item();
aoqi@0 515 right.load_item();
aoqi@0 516
aoqi@0 517 LIR_Opr reg = FrameMap::long0_opr;
aoqi@0 518 arithmetic_op_long(x->op(), reg, left.result(), right.result(), NULL);
aoqi@0 519 LIR_Opr result = rlock_result(x);
aoqi@0 520 __ move(reg, result);
aoqi@0 521 } else {
aoqi@0 522 // missing test if instr is commutative and if we should swap
aoqi@0 523 LIRItem left(x->x(), this);
aoqi@0 524 LIRItem right(x->y(), this);
aoqi@0 525
aoqi@0 526 left.load_item();
aoqi@0 527 // don't load constants to save register
aoqi@0 528 right.load_nonconstant();
aoqi@0 529 rlock_result(x);
aoqi@0 530 arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);
aoqi@0 531 }
aoqi@0 532 }
aoqi@0 533
aoqi@0 534
aoqi@0 535
aoqi@0 536 // for: _iadd, _imul, _isub, _idiv, _irem
aoqi@0 537 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {
aoqi@0 538 if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {
aoqi@0 539 // The requirements for division and modulo
aoqi@0 540 // input : rax,: dividend min_int
aoqi@0 541 // reg: divisor (may not be rax,/rdx) -1
aoqi@0 542 //
aoqi@0 543 // output: rax,: quotient (= rax, idiv reg) min_int
aoqi@0 544 // rdx: remainder (= rax, irem reg) 0
aoqi@0 545
aoqi@0 546 // rax, and rdx will be destroyed
aoqi@0 547
aoqi@0 548 // Note: does this invalidate the spec ???
aoqi@0 549 LIRItem right(x->y(), this);
aoqi@0 550 LIRItem left(x->x() , this); // visit left second, so that the is_register test is valid
aoqi@0 551
aoqi@0 552 // call state_for before load_item_force because state_for may
aoqi@0 553 // force the evaluation of other instructions that are needed for
aoqi@0 554 // correct debug info. Otherwise the live range of the fix
aoqi@0 555 // register might be too long.
aoqi@0 556 CodeEmitInfo* info = state_for(x);
aoqi@0 557
aoqi@0 558 left.load_item_force(divInOpr());
aoqi@0 559
aoqi@0 560 right.load_item();
aoqi@0 561
aoqi@0 562 LIR_Opr result = rlock_result(x);
aoqi@0 563 LIR_Opr result_reg;
aoqi@0 564 if (x->op() == Bytecodes::_idiv) {
aoqi@0 565 result_reg = divOutOpr();
aoqi@0 566 } else {
aoqi@0 567 result_reg = remOutOpr();
aoqi@0 568 }
aoqi@0 569
aoqi@0 570 if (!ImplicitDiv0Checks) {
aoqi@0 571 __ cmp(lir_cond_equal, right.result(), LIR_OprFact::intConst(0));
aoqi@0 572 __ branch(lir_cond_equal, T_INT, new DivByZeroStub(info));
aoqi@0 573 }
aoqi@0 574 LIR_Opr tmp = FrameMap::rdx_opr; // idiv and irem use rdx in their implementation
aoqi@0 575 if (x->op() == Bytecodes::_irem) {
aoqi@0 576 __ irem(left.result(), right.result(), result_reg, tmp, info);
aoqi@0 577 } else if (x->op() == Bytecodes::_idiv) {
aoqi@0 578 __ idiv(left.result(), right.result(), result_reg, tmp, info);
aoqi@0 579 } else {
aoqi@0 580 ShouldNotReachHere();
aoqi@0 581 }
aoqi@0 582
aoqi@0 583 __ move(result_reg, result);
aoqi@0 584 } else {
aoqi@0 585 // missing test if instr is commutative and if we should swap
aoqi@0 586 LIRItem left(x->x(), this);
aoqi@0 587 LIRItem right(x->y(), this);
aoqi@0 588 LIRItem* left_arg = &left;
aoqi@0 589 LIRItem* right_arg = &right;
aoqi@0 590 if (x->is_commutative() && left.is_stack() && right.is_register()) {
aoqi@0 591 // swap them if left is real stack (or cached) and right is real register(not cached)
aoqi@0 592 left_arg = &right;
aoqi@0 593 right_arg = &left;
aoqi@0 594 }
aoqi@0 595
aoqi@0 596 left_arg->load_item();
aoqi@0 597
aoqi@0 598 // do not need to load right, as we can handle stack and constants
aoqi@0 599 if (x->op() == Bytecodes::_imul ) {
aoqi@0 600 // check if we can use shift instead
aoqi@0 601 bool use_constant = false;
aoqi@0 602 bool use_tmp = false;
aoqi@0 603 if (right_arg->is_constant()) {
aoqi@0 604 int iconst = right_arg->get_jint_constant();
aoqi@0 605 if (iconst > 0) {
aoqi@0 606 if (is_power_of_2(iconst)) {
aoqi@0 607 use_constant = true;
aoqi@0 608 } else if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) {
aoqi@0 609 use_constant = true;
aoqi@0 610 use_tmp = true;
aoqi@0 611 }
aoqi@0 612 }
aoqi@0 613 }
aoqi@0 614 if (use_constant) {
aoqi@0 615 right_arg->dont_load_item();
aoqi@0 616 } else {
aoqi@0 617 right_arg->load_item();
aoqi@0 618 }
aoqi@0 619 LIR_Opr tmp = LIR_OprFact::illegalOpr;
aoqi@0 620 if (use_tmp) {
aoqi@0 621 tmp = new_register(T_INT);
aoqi@0 622 }
aoqi@0 623 rlock_result(x);
aoqi@0 624
aoqi@0 625 arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);
aoqi@0 626 } else {
aoqi@0 627 right_arg->dont_load_item();
aoqi@0 628 rlock_result(x);
aoqi@0 629 LIR_Opr tmp = LIR_OprFact::illegalOpr;
aoqi@0 630 arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);
aoqi@0 631 }
aoqi@0 632 }
aoqi@0 633 }
aoqi@0 634
aoqi@0 635
aoqi@0 636 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {
aoqi@0 637 // when an operand with use count 1 is the left operand, then it is
aoqi@0 638 // likely that no move for 2-operand-LIR-form is necessary
aoqi@0 639 if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
aoqi@0 640 x->swap_operands();
aoqi@0 641 }
aoqi@0 642
aoqi@0 643 ValueTag tag = x->type()->tag();
aoqi@0 644 assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");
aoqi@0 645 switch (tag) {
aoqi@0 646 case floatTag:
aoqi@0 647 case doubleTag: do_ArithmeticOp_FPU(x); return;
aoqi@0 648 case longTag: do_ArithmeticOp_Long(x); return;
aoqi@0 649 case intTag: do_ArithmeticOp_Int(x); return;
aoqi@0 650 }
aoqi@0 651 ShouldNotReachHere();
aoqi@0 652 }
aoqi@0 653
aoqi@0 654
aoqi@0 655 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr
aoqi@0 656 void LIRGenerator::do_ShiftOp(ShiftOp* x) {
aoqi@0 657 // count must always be in rcx
aoqi@0 658 LIRItem value(x->x(), this);
aoqi@0 659 LIRItem count(x->y(), this);
aoqi@0 660
aoqi@0 661 ValueTag elemType = x->type()->tag();
aoqi@0 662 bool must_load_count = !count.is_constant() || elemType == longTag;
aoqi@0 663 if (must_load_count) {
aoqi@0 664 // count for long must be in register
aoqi@0 665 count.load_item_force(shiftCountOpr());
aoqi@0 666 } else {
aoqi@0 667 count.dont_load_item();
aoqi@0 668 }
aoqi@0 669 value.load_item();
aoqi@0 670 LIR_Opr reg = rlock_result(x);
aoqi@0 671
aoqi@0 672 shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);
aoqi@0 673 }
aoqi@0 674
aoqi@0 675
aoqi@0 676 // _iand, _land, _ior, _lor, _ixor, _lxor
aoqi@0 677 void LIRGenerator::do_LogicOp(LogicOp* x) {
aoqi@0 678 // when an operand with use count 1 is the left operand, then it is
aoqi@0 679 // likely that no move for 2-operand-LIR-form is necessary
aoqi@0 680 if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
aoqi@0 681 x->swap_operands();
aoqi@0 682 }
aoqi@0 683
aoqi@0 684 LIRItem left(x->x(), this);
aoqi@0 685 LIRItem right(x->y(), this);
aoqi@0 686
aoqi@0 687 left.load_item();
aoqi@0 688 right.load_nonconstant();
aoqi@0 689 LIR_Opr reg = rlock_result(x);
aoqi@0 690
aoqi@0 691 logic_op(x->op(), reg, left.result(), right.result());
aoqi@0 692 }
aoqi@0 693
aoqi@0 694
aoqi@0 695
aoqi@0 696 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg
aoqi@0 697 void LIRGenerator::do_CompareOp(CompareOp* x) {
aoqi@0 698 LIRItem left(x->x(), this);
aoqi@0 699 LIRItem right(x->y(), this);
aoqi@0 700 ValueTag tag = x->x()->type()->tag();
aoqi@0 701 if (tag == longTag) {
aoqi@0 702 left.set_destroys_register();
aoqi@0 703 }
aoqi@0 704 left.load_item();
aoqi@0 705 right.load_item();
aoqi@0 706 LIR_Opr reg = rlock_result(x);
aoqi@0 707
aoqi@0 708 if (x->x()->type()->is_float_kind()) {
aoqi@0 709 Bytecodes::Code code = x->op();
aoqi@0 710 __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));
aoqi@0 711 } else if (x->x()->type()->tag() == longTag) {
aoqi@0 712 __ lcmp2int(left.result(), right.result(), reg);
aoqi@0 713 } else {
aoqi@0 714 Unimplemented();
aoqi@0 715 }
aoqi@0 716 }
aoqi@0 717
aoqi@0 718
aoqi@0 719 void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {
aoqi@0 720 assert(x->number_of_arguments() == 4, "wrong type");
aoqi@0 721 LIRItem obj (x->argument_at(0), this); // object
aoqi@0 722 LIRItem offset(x->argument_at(1), this); // offset of field
aoqi@0 723 LIRItem cmp (x->argument_at(2), this); // value to compare with field
aoqi@0 724 LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp
aoqi@0 725
aoqi@0 726 assert(obj.type()->tag() == objectTag, "invalid type");
aoqi@0 727
aoqi@0 728 // In 64bit the type can be long, sparc doesn't have this assert
aoqi@0 729 // assert(offset.type()->tag() == intTag, "invalid type");
aoqi@0 730
aoqi@0 731 assert(cmp.type()->tag() == type->tag(), "invalid type");
aoqi@0 732 assert(val.type()->tag() == type->tag(), "invalid type");
aoqi@0 733
aoqi@0 734 // get address of field
aoqi@0 735 obj.load_item();
aoqi@0 736 offset.load_nonconstant();
aoqi@0 737
aoqi@0 738 if (type == objectType) {
aoqi@0 739 cmp.load_item_force(FrameMap::rax_oop_opr);
aoqi@0 740 val.load_item();
aoqi@0 741 } else if (type == intType) {
aoqi@0 742 cmp.load_item_force(FrameMap::rax_opr);
aoqi@0 743 val.load_item();
aoqi@0 744 } else if (type == longType) {
aoqi@0 745 cmp.load_item_force(FrameMap::long0_opr);
aoqi@0 746 val.load_item_force(FrameMap::long1_opr);
aoqi@0 747 } else {
aoqi@0 748 ShouldNotReachHere();
aoqi@0 749 }
aoqi@0 750
aoqi@0 751 LIR_Opr addr = new_pointer_register();
aoqi@0 752 LIR_Address* a;
aoqi@0 753 if(offset.result()->is_constant()) {
aoqi@0 754 #ifdef _LP64
aoqi@0 755 jlong c = offset.result()->as_jlong();
aoqi@0 756 if ((jlong)((jint)c) == c) {
aoqi@0 757 a = new LIR_Address(obj.result(),
aoqi@0 758 (jint)c,
aoqi@0 759 as_BasicType(type));
aoqi@0 760 } else {
aoqi@0 761 LIR_Opr tmp = new_register(T_LONG);
aoqi@0 762 __ move(offset.result(), tmp);
aoqi@0 763 a = new LIR_Address(obj.result(),
aoqi@0 764 tmp,
aoqi@0 765 as_BasicType(type));
aoqi@0 766 }
aoqi@0 767 #else
aoqi@0 768 a = new LIR_Address(obj.result(),
aoqi@0 769 offset.result()->as_jint(),
aoqi@0 770 as_BasicType(type));
aoqi@0 771 #endif
aoqi@0 772 } else {
aoqi@0 773 a = new LIR_Address(obj.result(),
aoqi@0 774 offset.result(),
aoqi@0 775 LIR_Address::times_1,
aoqi@0 776 0,
aoqi@0 777 as_BasicType(type));
aoqi@0 778 }
aoqi@0 779 __ leal(LIR_OprFact::address(a), addr);
aoqi@0 780
aoqi@0 781 if (type == objectType) { // Write-barrier needed for Object fields.
aoqi@0 782 // Do the pre-write barrier, if any.
aoqi@0 783 pre_barrier(addr, LIR_OprFact::illegalOpr /* pre_val */,
aoqi@0 784 true /* do_load */, false /* patch */, NULL);
aoqi@0 785 }
aoqi@0 786
aoqi@0 787 LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience
aoqi@0 788 if (type == objectType)
aoqi@0 789 __ cas_obj(addr, cmp.result(), val.result(), ill, ill);
aoqi@0 790 else if (type == intType)
aoqi@0 791 __ cas_int(addr, cmp.result(), val.result(), ill, ill);
aoqi@0 792 else if (type == longType)
aoqi@0 793 __ cas_long(addr, cmp.result(), val.result(), ill, ill);
aoqi@0 794 else {
aoqi@0 795 ShouldNotReachHere();
aoqi@0 796 }
aoqi@0 797
aoqi@0 798 // generate conditional move of boolean result
aoqi@0 799 LIR_Opr result = rlock_result(x);
aoqi@0 800 __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),
aoqi@0 801 result, as_BasicType(type));
aoqi@0 802 if (type == objectType) { // Write-barrier needed for Object fields.
aoqi@0 803 // Seems to be precise
aoqi@0 804 post_barrier(addr, val.result());
aoqi@0 805 }
aoqi@0 806 }
aoqi@0 807
aoqi@0 808
aoqi@0 809 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {
aoqi@0 810 assert(x->number_of_arguments() == 1 || (x->number_of_arguments() == 2 && x->id() == vmIntrinsics::_dpow), "wrong type");
aoqi@0 811 LIRItem value(x->argument_at(0), this);
aoqi@0 812
aoqi@0 813 bool use_fpu = false;
aoqi@0 814 if (UseSSE >= 2) {
aoqi@0 815 switch(x->id()) {
aoqi@0 816 case vmIntrinsics::_dsin:
aoqi@0 817 case vmIntrinsics::_dcos:
aoqi@0 818 case vmIntrinsics::_dtan:
aoqi@0 819 case vmIntrinsics::_dlog:
aoqi@0 820 case vmIntrinsics::_dlog10:
aoqi@0 821 case vmIntrinsics::_dexp:
aoqi@0 822 case vmIntrinsics::_dpow:
aoqi@0 823 use_fpu = true;
aoqi@0 824 }
aoqi@0 825 } else {
aoqi@0 826 value.set_destroys_register();
aoqi@0 827 }
aoqi@0 828
aoqi@0 829 value.load_item();
aoqi@0 830
aoqi@0 831 LIR_Opr calc_input = value.result();
aoqi@0 832 LIR_Opr calc_input2 = NULL;
aoqi@0 833 if (x->id() == vmIntrinsics::_dpow) {
aoqi@0 834 LIRItem extra_arg(x->argument_at(1), this);
aoqi@0 835 if (UseSSE < 2) {
aoqi@0 836 extra_arg.set_destroys_register();
aoqi@0 837 }
aoqi@0 838 extra_arg.load_item();
aoqi@0 839 calc_input2 = extra_arg.result();
aoqi@0 840 }
aoqi@0 841 LIR_Opr calc_result = rlock_result(x);
aoqi@0 842
aoqi@0 843 // sin, cos, pow and exp need two free fpu stack slots, so register
aoqi@0 844 // two temporary operands
aoqi@0 845 LIR_Opr tmp1 = FrameMap::caller_save_fpu_reg_at(0);
aoqi@0 846 LIR_Opr tmp2 = FrameMap::caller_save_fpu_reg_at(1);
aoqi@0 847
aoqi@0 848 if (use_fpu) {
aoqi@0 849 LIR_Opr tmp = FrameMap::fpu0_double_opr;
aoqi@0 850 int tmp_start = 1;
aoqi@0 851 if (calc_input2 != NULL) {
aoqi@0 852 __ move(calc_input2, tmp);
aoqi@0 853 tmp_start = 2;
aoqi@0 854 calc_input2 = tmp;
aoqi@0 855 }
aoqi@0 856 __ move(calc_input, tmp);
aoqi@0 857
aoqi@0 858 calc_input = tmp;
aoqi@0 859 calc_result = tmp;
aoqi@0 860
aoqi@0 861 tmp1 = FrameMap::caller_save_fpu_reg_at(tmp_start);
aoqi@0 862 tmp2 = FrameMap::caller_save_fpu_reg_at(tmp_start + 1);
aoqi@0 863 }
aoqi@0 864
aoqi@0 865 switch(x->id()) {
aoqi@0 866 case vmIntrinsics::_dabs: __ abs (calc_input, calc_result, LIR_OprFact::illegalOpr); break;
aoqi@0 867 case vmIntrinsics::_dsqrt: __ sqrt (calc_input, calc_result, LIR_OprFact::illegalOpr); break;
aoqi@0 868 case vmIntrinsics::_dsin: __ sin (calc_input, calc_result, tmp1, tmp2); break;
aoqi@0 869 case vmIntrinsics::_dcos: __ cos (calc_input, calc_result, tmp1, tmp2); break;
aoqi@0 870 case vmIntrinsics::_dtan: __ tan (calc_input, calc_result, tmp1, tmp2); break;
aoqi@0 871 case vmIntrinsics::_dlog: __ log (calc_input, calc_result, tmp1); break;
aoqi@0 872 case vmIntrinsics::_dlog10: __ log10(calc_input, calc_result, tmp1); break;
aoqi@0 873 case vmIntrinsics::_dexp: __ exp (calc_input, calc_result, tmp1, tmp2, FrameMap::rax_opr, FrameMap::rcx_opr, FrameMap::rdx_opr); break;
aoqi@0 874 case vmIntrinsics::_dpow: __ pow (calc_input, calc_input2, calc_result, tmp1, tmp2, FrameMap::rax_opr, FrameMap::rcx_opr, FrameMap::rdx_opr); break;
aoqi@0 875 default: ShouldNotReachHere();
aoqi@0 876 }
aoqi@0 877
aoqi@0 878 if (use_fpu) {
aoqi@0 879 __ move(calc_result, x->operand());
aoqi@0 880 }
aoqi@0 881 }
aoqi@0 882
aoqi@0 883
aoqi@0 884 void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
aoqi@0 885 assert(x->number_of_arguments() == 5, "wrong type");
aoqi@0 886
aoqi@0 887 // Make all state_for calls early since they can emit code
aoqi@0 888 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 889
aoqi@0 890 LIRItem src(x->argument_at(0), this);
aoqi@0 891 LIRItem src_pos(x->argument_at(1), this);
aoqi@0 892 LIRItem dst(x->argument_at(2), this);
aoqi@0 893 LIRItem dst_pos(x->argument_at(3), this);
aoqi@0 894 LIRItem length(x->argument_at(4), this);
aoqi@0 895
aoqi@0 896 // operands for arraycopy must use fixed registers, otherwise
aoqi@0 897 // LinearScan will fail allocation (because arraycopy always needs a
aoqi@0 898 // call)
aoqi@0 899
aoqi@0 900 #ifndef _LP64
aoqi@0 901 src.load_item_force (FrameMap::rcx_oop_opr);
aoqi@0 902 src_pos.load_item_force (FrameMap::rdx_opr);
aoqi@0 903 dst.load_item_force (FrameMap::rax_oop_opr);
aoqi@0 904 dst_pos.load_item_force (FrameMap::rbx_opr);
aoqi@0 905 length.load_item_force (FrameMap::rdi_opr);
aoqi@0 906 LIR_Opr tmp = (FrameMap::rsi_opr);
aoqi@0 907 #else
aoqi@0 908
aoqi@0 909 // The java calling convention will give us enough registers
aoqi@0 910 // so that on the stub side the args will be perfect already.
aoqi@0 911 // On the other slow/special case side we call C and the arg
aoqi@0 912 // positions are not similar enough to pick one as the best.
aoqi@0 913 // Also because the java calling convention is a "shifted" version
aoqi@0 914 // of the C convention we can process the java args trivially into C
aoqi@0 915 // args without worry of overwriting during the xfer
aoqi@0 916
aoqi@0 917 src.load_item_force (FrameMap::as_oop_opr(j_rarg0));
aoqi@0 918 src_pos.load_item_force (FrameMap::as_opr(j_rarg1));
aoqi@0 919 dst.load_item_force (FrameMap::as_oop_opr(j_rarg2));
aoqi@0 920 dst_pos.load_item_force (FrameMap::as_opr(j_rarg3));
aoqi@0 921 length.load_item_force (FrameMap::as_opr(j_rarg4));
aoqi@0 922
aoqi@0 923 LIR_Opr tmp = FrameMap::as_opr(j_rarg5);
aoqi@0 924 #endif // LP64
aoqi@0 925
aoqi@0 926 set_no_result(x);
aoqi@0 927
aoqi@0 928 int flags;
aoqi@0 929 ciArrayKlass* expected_type;
aoqi@0 930 arraycopy_helper(x, &flags, &expected_type);
aoqi@0 931
aoqi@0 932 __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), tmp, expected_type, flags, info); // does add_safepoint
aoqi@0 933 }
aoqi@0 934
aoqi@0 935 void LIRGenerator::do_update_CRC32(Intrinsic* x) {
aoqi@0 936 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");
aoqi@0 937 // Make all state_for calls early since they can emit code
aoqi@0 938 LIR_Opr result = rlock_result(x);
aoqi@0 939 int flags = 0;
aoqi@0 940 switch (x->id()) {
aoqi@0 941 case vmIntrinsics::_updateCRC32: {
aoqi@0 942 LIRItem crc(x->argument_at(0), this);
aoqi@0 943 LIRItem val(x->argument_at(1), this);
aoqi@0 944 // val is destroyed by update_crc32
aoqi@0 945 val.set_destroys_register();
aoqi@0 946 crc.load_item();
aoqi@0 947 val.load_item();
aoqi@0 948 __ update_crc32(crc.result(), val.result(), result);
aoqi@0 949 break;
aoqi@0 950 }
aoqi@0 951 case vmIntrinsics::_updateBytesCRC32:
aoqi@0 952 case vmIntrinsics::_updateByteBufferCRC32: {
aoqi@0 953 bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);
aoqi@0 954
aoqi@0 955 LIRItem crc(x->argument_at(0), this);
aoqi@0 956 LIRItem buf(x->argument_at(1), this);
aoqi@0 957 LIRItem off(x->argument_at(2), this);
aoqi@0 958 LIRItem len(x->argument_at(3), this);
aoqi@0 959 buf.load_item();
aoqi@0 960 off.load_nonconstant();
aoqi@0 961
aoqi@0 962 LIR_Opr index = off.result();
aoqi@0 963 int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;
aoqi@0 964 if(off.result()->is_constant()) {
aoqi@0 965 index = LIR_OprFact::illegalOpr;
aoqi@0 966 offset += off.result()->as_jint();
aoqi@0 967 }
aoqi@0 968 LIR_Opr base_op = buf.result();
aoqi@0 969
aoqi@0 970 #ifndef _LP64
aoqi@0 971 if (!is_updateBytes) { // long b raw address
aoqi@0 972 base_op = new_register(T_INT);
aoqi@0 973 __ convert(Bytecodes::_l2i, buf.result(), base_op);
aoqi@0 974 }
aoqi@0 975 #else
aoqi@0 976 if (index->is_valid()) {
aoqi@0 977 LIR_Opr tmp = new_register(T_LONG);
aoqi@0 978 __ convert(Bytecodes::_i2l, index, tmp);
aoqi@0 979 index = tmp;
aoqi@0 980 }
aoqi@0 981 #endif
aoqi@0 982
aoqi@0 983 LIR_Address* a = new LIR_Address(base_op,
aoqi@0 984 index,
aoqi@0 985 LIR_Address::times_1,
aoqi@0 986 offset,
aoqi@0 987 T_BYTE);
aoqi@0 988 BasicTypeList signature(3);
aoqi@0 989 signature.append(T_INT);
aoqi@0 990 signature.append(T_ADDRESS);
aoqi@0 991 signature.append(T_INT);
aoqi@0 992 CallingConvention* cc = frame_map()->c_calling_convention(&signature);
aoqi@0 993 const LIR_Opr result_reg = result_register_for(x->type());
aoqi@0 994
aoqi@0 995 LIR_Opr addr = new_pointer_register();
aoqi@0 996 __ leal(LIR_OprFact::address(a), addr);
aoqi@0 997
aoqi@0 998 crc.load_item_force(cc->at(0));
aoqi@0 999 __ move(addr, cc->at(1));
aoqi@0 1000 len.load_item_force(cc->at(2));
aoqi@0 1001
aoqi@0 1002 __ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());
aoqi@0 1003 __ move(result_reg, result);
aoqi@0 1004
aoqi@0 1005 break;
aoqi@0 1006 }
aoqi@0 1007 default: {
aoqi@0 1008 ShouldNotReachHere();
aoqi@0 1009 }
aoqi@0 1010 }
aoqi@0 1011 }
aoqi@0 1012
aoqi@0 1013 // _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f
aoqi@0 1014 // _i2b, _i2c, _i2s
aoqi@0 1015 LIR_Opr fixed_register_for(BasicType type) {
aoqi@0 1016 switch (type) {
aoqi@0 1017 case T_FLOAT: return FrameMap::fpu0_float_opr;
aoqi@0 1018 case T_DOUBLE: return FrameMap::fpu0_double_opr;
aoqi@0 1019 case T_INT: return FrameMap::rax_opr;
aoqi@0 1020 case T_LONG: return FrameMap::long0_opr;
aoqi@0 1021 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
aoqi@0 1022 }
aoqi@0 1023 }
aoqi@0 1024
aoqi@0 1025 void LIRGenerator::do_Convert(Convert* x) {
aoqi@0 1026 // flags that vary for the different operations and different SSE-settings
aoqi@0 1027 bool fixed_input, fixed_result, round_result, needs_stub;
aoqi@0 1028
aoqi@0 1029 switch (x->op()) {
aoqi@0 1030 case Bytecodes::_i2l: // fall through
aoqi@0 1031 case Bytecodes::_l2i: // fall through
aoqi@0 1032 case Bytecodes::_i2b: // fall through
aoqi@0 1033 case Bytecodes::_i2c: // fall through
aoqi@0 1034 case Bytecodes::_i2s: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;
aoqi@0 1035
aoqi@0 1036 case Bytecodes::_f2d: fixed_input = UseSSE == 1; fixed_result = false; round_result = false; needs_stub = false; break;
aoqi@0 1037 case Bytecodes::_d2f: fixed_input = false; fixed_result = UseSSE == 1; round_result = UseSSE < 1; needs_stub = false; break;
aoqi@0 1038 case Bytecodes::_i2f: fixed_input = false; fixed_result = false; round_result = UseSSE < 1; needs_stub = false; break;
aoqi@0 1039 case Bytecodes::_i2d: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;
aoqi@0 1040 case Bytecodes::_f2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;
aoqi@0 1041 case Bytecodes::_d2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;
aoqi@0 1042 case Bytecodes::_l2f: fixed_input = false; fixed_result = UseSSE >= 1; round_result = UseSSE < 1; needs_stub = false; break;
aoqi@0 1043 case Bytecodes::_l2d: fixed_input = false; fixed_result = UseSSE >= 2; round_result = UseSSE < 2; needs_stub = false; break;
aoqi@0 1044 case Bytecodes::_f2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;
aoqi@0 1045 case Bytecodes::_d2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;
aoqi@0 1046 default: ShouldNotReachHere();
aoqi@0 1047 }
aoqi@0 1048
aoqi@0 1049 LIRItem value(x->value(), this);
aoqi@0 1050 value.load_item();
aoqi@0 1051 LIR_Opr input = value.result();
aoqi@0 1052 LIR_Opr result = rlock(x);
aoqi@0 1053
aoqi@0 1054 // arguments of lir_convert
aoqi@0 1055 LIR_Opr conv_input = input;
aoqi@0 1056 LIR_Opr conv_result = result;
aoqi@0 1057 ConversionStub* stub = NULL;
aoqi@0 1058
aoqi@0 1059 if (fixed_input) {
aoqi@0 1060 conv_input = fixed_register_for(input->type());
aoqi@0 1061 __ move(input, conv_input);
aoqi@0 1062 }
aoqi@0 1063
aoqi@0 1064 assert(fixed_result == false || round_result == false, "cannot set both");
aoqi@0 1065 if (fixed_result) {
aoqi@0 1066 conv_result = fixed_register_for(result->type());
aoqi@0 1067 } else if (round_result) {
aoqi@0 1068 result = new_register(result->type());
aoqi@0 1069 set_vreg_flag(result, must_start_in_memory);
aoqi@0 1070 }
aoqi@0 1071
aoqi@0 1072 if (needs_stub) {
aoqi@0 1073 stub = new ConversionStub(x->op(), conv_input, conv_result);
aoqi@0 1074 }
aoqi@0 1075
aoqi@0 1076 __ convert(x->op(), conv_input, conv_result, stub);
aoqi@0 1077
aoqi@0 1078 if (result != conv_result) {
aoqi@0 1079 __ move(conv_result, result);
aoqi@0 1080 }
aoqi@0 1081
aoqi@0 1082 assert(result->is_virtual(), "result must be virtual register");
aoqi@0 1083 set_result(x, result);
aoqi@0 1084 }
aoqi@0 1085
aoqi@0 1086
aoqi@0 1087 void LIRGenerator::do_NewInstance(NewInstance* x) {
rbackman@7058 1088 print_if_not_loaded(x);
rbackman@7058 1089
aoqi@0 1090 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 1091 LIR_Opr reg = result_register_for(x->type());
rbackman@7058 1092 new_instance(reg, x->klass(), x->is_unresolved(),
aoqi@0 1093 FrameMap::rcx_oop_opr,
aoqi@0 1094 FrameMap::rdi_oop_opr,
aoqi@0 1095 FrameMap::rsi_oop_opr,
aoqi@0 1096 LIR_OprFact::illegalOpr,
aoqi@0 1097 FrameMap::rdx_metadata_opr, info);
aoqi@0 1098 LIR_Opr result = rlock_result(x);
aoqi@0 1099 __ move(reg, result);
aoqi@0 1100 }
aoqi@0 1101
aoqi@0 1102
aoqi@0 1103 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
aoqi@0 1104 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 1105
aoqi@0 1106 LIRItem length(x->length(), this);
aoqi@0 1107 length.load_item_force(FrameMap::rbx_opr);
aoqi@0 1108
aoqi@0 1109 LIR_Opr reg = result_register_for(x->type());
aoqi@0 1110 LIR_Opr tmp1 = FrameMap::rcx_oop_opr;
aoqi@0 1111 LIR_Opr tmp2 = FrameMap::rsi_oop_opr;
aoqi@0 1112 LIR_Opr tmp3 = FrameMap::rdi_oop_opr;
aoqi@0 1113 LIR_Opr tmp4 = reg;
aoqi@0 1114 LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;
aoqi@0 1115 LIR_Opr len = length.result();
aoqi@0 1116 BasicType elem_type = x->elt_type();
aoqi@0 1117
aoqi@0 1118 __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
aoqi@0 1119
aoqi@0 1120 CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
aoqi@0 1121 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);
aoqi@0 1122
aoqi@0 1123 LIR_Opr result = rlock_result(x);
aoqi@0 1124 __ move(reg, result);
aoqi@0 1125 }
aoqi@0 1126
aoqi@0 1127
aoqi@0 1128 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
aoqi@0 1129 LIRItem length(x->length(), this);
aoqi@0 1130 // in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction
aoqi@0 1131 // and therefore provide the state before the parameters have been consumed
aoqi@0 1132 CodeEmitInfo* patching_info = NULL;
aoqi@0 1133 if (!x->klass()->is_loaded() || PatchALot) {
aoqi@0 1134 patching_info = state_for(x, x->state_before());
aoqi@0 1135 }
aoqi@0 1136
aoqi@0 1137 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 1138
aoqi@0 1139 const LIR_Opr reg = result_register_for(x->type());
aoqi@0 1140 LIR_Opr tmp1 = FrameMap::rcx_oop_opr;
aoqi@0 1141 LIR_Opr tmp2 = FrameMap::rsi_oop_opr;
aoqi@0 1142 LIR_Opr tmp3 = FrameMap::rdi_oop_opr;
aoqi@0 1143 LIR_Opr tmp4 = reg;
aoqi@0 1144 LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;
aoqi@0 1145
aoqi@0 1146 length.load_item_force(FrameMap::rbx_opr);
aoqi@0 1147 LIR_Opr len = length.result();
aoqi@0 1148
aoqi@0 1149 CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
aoqi@0 1150 ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());
aoqi@0 1151 if (obj == ciEnv::unloaded_ciobjarrayklass()) {
aoqi@0 1152 BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
aoqi@0 1153 }
aoqi@0 1154 klass2reg_with_patching(klass_reg, obj, patching_info);
aoqi@0 1155 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);
aoqi@0 1156
aoqi@0 1157 LIR_Opr result = rlock_result(x);
aoqi@0 1158 __ move(reg, result);
aoqi@0 1159 }
aoqi@0 1160
aoqi@0 1161
aoqi@0 1162 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
aoqi@0 1163 Values* dims = x->dims();
aoqi@0 1164 int i = dims->length();
aoqi@0 1165 LIRItemList* items = new LIRItemList(dims->length(), NULL);
aoqi@0 1166 while (i-- > 0) {
aoqi@0 1167 LIRItem* size = new LIRItem(dims->at(i), this);
aoqi@0 1168 items->at_put(i, size);
aoqi@0 1169 }
aoqi@0 1170
aoqi@0 1171 // Evaluate state_for early since it may emit code.
aoqi@0 1172 CodeEmitInfo* patching_info = NULL;
aoqi@0 1173 if (!x->klass()->is_loaded() || PatchALot) {
aoqi@0 1174 patching_info = state_for(x, x->state_before());
aoqi@0 1175
aoqi@0 1176 // Cannot re-use same xhandlers for multiple CodeEmitInfos, so
aoqi@0 1177 // clone all handlers (NOTE: Usually this is handled transparently
aoqi@0 1178 // by the CodeEmitInfo cloning logic in CodeStub constructors but
aoqi@0 1179 // is done explicitly here because a stub isn't being used).
aoqi@0 1180 x->set_exception_handlers(new XHandlers(x->exception_handlers()));
aoqi@0 1181 }
aoqi@0 1182 CodeEmitInfo* info = state_for(x, x->state());
aoqi@0 1183
aoqi@0 1184 i = dims->length();
aoqi@0 1185 while (i-- > 0) {
aoqi@0 1186 LIRItem* size = items->at(i);
aoqi@0 1187 size->load_nonconstant();
aoqi@0 1188
aoqi@0 1189 store_stack_parameter(size->result(), in_ByteSize(i*4));
aoqi@0 1190 }
aoqi@0 1191
aoqi@0 1192 LIR_Opr klass_reg = FrameMap::rax_metadata_opr;
aoqi@0 1193 klass2reg_with_patching(klass_reg, x->klass(), patching_info);
aoqi@0 1194
aoqi@0 1195 LIR_Opr rank = FrameMap::rbx_opr;
aoqi@0 1196 __ move(LIR_OprFact::intConst(x->rank()), rank);
aoqi@0 1197 LIR_Opr varargs = FrameMap::rcx_opr;
aoqi@0 1198 __ move(FrameMap::rsp_opr, varargs);
aoqi@0 1199 LIR_OprList* args = new LIR_OprList(3);
aoqi@0 1200 args->append(klass_reg);
aoqi@0 1201 args->append(rank);
aoqi@0 1202 args->append(varargs);
aoqi@0 1203 LIR_Opr reg = result_register_for(x->type());
aoqi@0 1204 __ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),
aoqi@0 1205 LIR_OprFact::illegalOpr,
aoqi@0 1206 reg, args, info);
aoqi@0 1207
aoqi@0 1208 LIR_Opr result = rlock_result(x);
aoqi@0 1209 __ move(reg, result);
aoqi@0 1210 }
aoqi@0 1211
aoqi@0 1212
aoqi@0 1213 void LIRGenerator::do_BlockBegin(BlockBegin* x) {
aoqi@0 1214 // nothing to do for now
aoqi@0 1215 }
aoqi@0 1216
aoqi@0 1217
aoqi@0 1218 void LIRGenerator::do_CheckCast(CheckCast* x) {
aoqi@0 1219 LIRItem obj(x->obj(), this);
aoqi@0 1220
aoqi@0 1221 CodeEmitInfo* patching_info = NULL;
aoqi@0 1222 if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) {
aoqi@0 1223 // must do this before locking the destination register as an oop register,
aoqi@0 1224 // and before the obj is loaded (the latter is for deoptimization)
aoqi@0 1225 patching_info = state_for(x, x->state_before());
aoqi@0 1226 }
aoqi@0 1227 obj.load_item();
aoqi@0 1228
aoqi@0 1229 // info for exceptions
aoqi@0 1230 CodeEmitInfo* info_for_exception = state_for(x);
aoqi@0 1231
aoqi@0 1232 CodeStub* stub;
aoqi@0 1233 if (x->is_incompatible_class_change_check()) {
aoqi@0 1234 assert(patching_info == NULL, "can't patch this");
aoqi@0 1235 stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);
aoqi@0 1236 } else {
aoqi@0 1237 stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);
aoqi@0 1238 }
aoqi@0 1239 LIR_Opr reg = rlock_result(x);
aoqi@0 1240 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
aoqi@0 1241 if (!x->klass()->is_loaded() || UseCompressedClassPointers) {
aoqi@0 1242 tmp3 = new_register(objectType);
aoqi@0 1243 }
aoqi@0 1244 __ checkcast(reg, obj.result(), x->klass(),
aoqi@0 1245 new_register(objectType), new_register(objectType), tmp3,
aoqi@0 1246 x->direct_compare(), info_for_exception, patching_info, stub,
aoqi@0 1247 x->profiled_method(), x->profiled_bci());
aoqi@0 1248 }
aoqi@0 1249
aoqi@0 1250
aoqi@0 1251 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
aoqi@0 1252 LIRItem obj(x->obj(), this);
aoqi@0 1253
aoqi@0 1254 // result and test object may not be in same register
aoqi@0 1255 LIR_Opr reg = rlock_result(x);
aoqi@0 1256 CodeEmitInfo* patching_info = NULL;
aoqi@0 1257 if ((!x->klass()->is_loaded() || PatchALot)) {
aoqi@0 1258 // must do this before locking the destination register as an oop register
aoqi@0 1259 patching_info = state_for(x, x->state_before());
aoqi@0 1260 }
aoqi@0 1261 obj.load_item();
aoqi@0 1262 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
aoqi@0 1263 if (!x->klass()->is_loaded() || UseCompressedClassPointers) {
aoqi@0 1264 tmp3 = new_register(objectType);
aoqi@0 1265 }
aoqi@0 1266 __ instanceof(reg, obj.result(), x->klass(),
aoqi@0 1267 new_register(objectType), new_register(objectType), tmp3,
aoqi@0 1268 x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());
aoqi@0 1269 }
aoqi@0 1270
aoqi@0 1271
aoqi@0 1272 void LIRGenerator::do_If(If* x) {
aoqi@0 1273 assert(x->number_of_sux() == 2, "inconsistency");
aoqi@0 1274 ValueTag tag = x->x()->type()->tag();
aoqi@0 1275 bool is_safepoint = x->is_safepoint();
aoqi@0 1276
aoqi@0 1277 If::Condition cond = x->cond();
aoqi@0 1278
aoqi@0 1279 LIRItem xitem(x->x(), this);
aoqi@0 1280 LIRItem yitem(x->y(), this);
aoqi@0 1281 LIRItem* xin = &xitem;
aoqi@0 1282 LIRItem* yin = &yitem;
aoqi@0 1283
aoqi@0 1284 if (tag == longTag) {
aoqi@0 1285 // for longs, only conditions "eql", "neq", "lss", "geq" are valid;
aoqi@0 1286 // mirror for other conditions
aoqi@0 1287 if (cond == If::gtr || cond == If::leq) {
aoqi@0 1288 cond = Instruction::mirror(cond);
aoqi@0 1289 xin = &yitem;
aoqi@0 1290 yin = &xitem;
aoqi@0 1291 }
aoqi@0 1292 xin->set_destroys_register();
aoqi@0 1293 }
aoqi@0 1294 xin->load_item();
aoqi@0 1295 if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {
aoqi@0 1296 // inline long zero
aoqi@0 1297 yin->dont_load_item();
aoqi@0 1298 } else if (tag == longTag || tag == floatTag || tag == doubleTag) {
aoqi@0 1299 // longs cannot handle constants at right side
aoqi@0 1300 yin->load_item();
aoqi@0 1301 } else {
aoqi@0 1302 yin->dont_load_item();
aoqi@0 1303 }
aoqi@0 1304
aoqi@0 1305 // add safepoint before generating condition code so it can be recomputed
aoqi@0 1306 if (x->is_safepoint()) {
aoqi@0 1307 // increment backedge counter if needed
aoqi@0 1308 increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());
aoqi@0 1309 __ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before()));
aoqi@0 1310 }
aoqi@0 1311 set_no_result(x);
aoqi@0 1312
aoqi@0 1313 LIR_Opr left = xin->result();
aoqi@0 1314 LIR_Opr right = yin->result();
aoqi@0 1315 __ cmp(lir_cond(cond), left, right);
aoqi@0 1316 // Generate branch profiling. Profiling code doesn't kill flags.
aoqi@0 1317 profile_branch(x, cond);
aoqi@0 1318 move_to_phi(x->state());
aoqi@0 1319 if (x->x()->type()->is_float_kind()) {
aoqi@0 1320 __ branch(lir_cond(cond), right->type(), x->tsux(), x->usux());
aoqi@0 1321 } else {
aoqi@0 1322 __ branch(lir_cond(cond), right->type(), x->tsux());
aoqi@0 1323 }
aoqi@0 1324 assert(x->default_sux() == x->fsux(), "wrong destination above");
aoqi@0 1325 __ jump(x->default_sux());
aoqi@0 1326 }
aoqi@0 1327
aoqi@0 1328
aoqi@0 1329 LIR_Opr LIRGenerator::getThreadPointer() {
aoqi@0 1330 #ifdef _LP64
aoqi@0 1331 return FrameMap::as_pointer_opr(r15_thread);
aoqi@0 1332 #else
aoqi@0 1333 LIR_Opr result = new_register(T_INT);
aoqi@0 1334 __ get_thread(result);
aoqi@0 1335 return result;
aoqi@0 1336 #endif //
aoqi@0 1337 }
aoqi@0 1338
aoqi@0 1339 void LIRGenerator::trace_block_entry(BlockBegin* block) {
aoqi@0 1340 store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0));
aoqi@0 1341 LIR_OprList* args = new LIR_OprList();
aoqi@0 1342 address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);
aoqi@0 1343 __ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);
aoqi@0 1344 }
aoqi@0 1345
aoqi@0 1346
aoqi@0 1347 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,
aoqi@0 1348 CodeEmitInfo* info) {
aoqi@0 1349 if (address->type() == T_LONG) {
aoqi@0 1350 address = new LIR_Address(address->base(),
aoqi@0 1351 address->index(), address->scale(),
aoqi@0 1352 address->disp(), T_DOUBLE);
aoqi@0 1353 // Transfer the value atomically by using FP moves. This means
aoqi@0 1354 // the value has to be moved between CPU and FPU registers. It
aoqi@0 1355 // always has to be moved through spill slot since there's no
aoqi@0 1356 // quick way to pack the value into an SSE register.
aoqi@0 1357 LIR_Opr temp_double = new_register(T_DOUBLE);
aoqi@0 1358 LIR_Opr spill = new_register(T_LONG);
aoqi@0 1359 set_vreg_flag(spill, must_start_in_memory);
aoqi@0 1360 __ move(value, spill);
aoqi@0 1361 __ volatile_move(spill, temp_double, T_LONG);
aoqi@0 1362 __ volatile_move(temp_double, LIR_OprFact::address(address), T_LONG, info);
aoqi@0 1363 } else {
aoqi@0 1364 __ store(value, address, info);
aoqi@0 1365 }
aoqi@0 1366 }
aoqi@0 1367
aoqi@0 1368
aoqi@0 1369
aoqi@0 1370 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,
aoqi@0 1371 CodeEmitInfo* info) {
aoqi@0 1372 if (address->type() == T_LONG) {
aoqi@0 1373 address = new LIR_Address(address->base(),
aoqi@0 1374 address->index(), address->scale(),
aoqi@0 1375 address->disp(), T_DOUBLE);
aoqi@0 1376 // Transfer the value atomically by using FP moves. This means
aoqi@0 1377 // the value has to be moved between CPU and FPU registers. In
aoqi@0 1378 // SSE0 and SSE1 mode it has to be moved through spill slot but in
aoqi@0 1379 // SSE2+ mode it can be moved directly.
aoqi@0 1380 LIR_Opr temp_double = new_register(T_DOUBLE);
aoqi@0 1381 __ volatile_move(LIR_OprFact::address(address), temp_double, T_LONG, info);
aoqi@0 1382 __ volatile_move(temp_double, result, T_LONG);
aoqi@0 1383 if (UseSSE < 2) {
aoqi@0 1384 // no spill slot needed in SSE2 mode because xmm->cpu register move is possible
aoqi@0 1385 set_vreg_flag(result, must_start_in_memory);
aoqi@0 1386 }
aoqi@0 1387 } else {
aoqi@0 1388 __ load(address, result, info);
aoqi@0 1389 }
aoqi@0 1390 }
aoqi@0 1391
aoqi@0 1392 void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset,
aoqi@0 1393 BasicType type, bool is_volatile) {
aoqi@0 1394 if (is_volatile && type == T_LONG) {
aoqi@0 1395 LIR_Address* addr = new LIR_Address(src, offset, T_DOUBLE);
aoqi@0 1396 LIR_Opr tmp = new_register(T_DOUBLE);
aoqi@0 1397 __ load(addr, tmp);
aoqi@0 1398 LIR_Opr spill = new_register(T_LONG);
aoqi@0 1399 set_vreg_flag(spill, must_start_in_memory);
aoqi@0 1400 __ move(tmp, spill);
aoqi@0 1401 __ move(spill, dst);
aoqi@0 1402 } else {
aoqi@0 1403 LIR_Address* addr = new LIR_Address(src, offset, type);
aoqi@0 1404 __ load(addr, dst);
aoqi@0 1405 }
aoqi@0 1406 }
aoqi@0 1407
aoqi@0 1408
aoqi@0 1409 void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data,
aoqi@0 1410 BasicType type, bool is_volatile) {
aoqi@0 1411 if (is_volatile && type == T_LONG) {
aoqi@0 1412 LIR_Address* addr = new LIR_Address(src, offset, T_DOUBLE);
aoqi@0 1413 LIR_Opr tmp = new_register(T_DOUBLE);
aoqi@0 1414 LIR_Opr spill = new_register(T_DOUBLE);
aoqi@0 1415 set_vreg_flag(spill, must_start_in_memory);
aoqi@0 1416 __ move(data, spill);
aoqi@0 1417 __ move(spill, tmp);
aoqi@0 1418 __ move(tmp, addr);
aoqi@0 1419 } else {
aoqi@0 1420 LIR_Address* addr = new LIR_Address(src, offset, type);
aoqi@0 1421 bool is_obj = (type == T_ARRAY || type == T_OBJECT);
aoqi@0 1422 if (is_obj) {
aoqi@0 1423 // Do the pre-write barrier, if any.
aoqi@0 1424 pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,
aoqi@0 1425 true /* do_load */, false /* patch */, NULL);
aoqi@0 1426 __ move(data, addr);
aoqi@0 1427 assert(src->is_register(), "must be register");
aoqi@0 1428 // Seems to be a precise address
aoqi@0 1429 post_barrier(LIR_OprFact::address(addr), data);
aoqi@0 1430 } else {
aoqi@0 1431 __ move(data, addr);
aoqi@0 1432 }
aoqi@0 1433 }
aoqi@0 1434 }
aoqi@0 1435
aoqi@0 1436 void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {
aoqi@0 1437 BasicType type = x->basic_type();
aoqi@0 1438 LIRItem src(x->object(), this);
aoqi@0 1439 LIRItem off(x->offset(), this);
aoqi@0 1440 LIRItem value(x->value(), this);
aoqi@0 1441
aoqi@0 1442 src.load_item();
aoqi@0 1443 value.load_item();
aoqi@0 1444 off.load_nonconstant();
aoqi@0 1445
aoqi@0 1446 LIR_Opr dst = rlock_result(x, type);
aoqi@0 1447 LIR_Opr data = value.result();
aoqi@0 1448 bool is_obj = (type == T_ARRAY || type == T_OBJECT);
aoqi@0 1449 LIR_Opr offset = off.result();
aoqi@0 1450
aoqi@0 1451 assert (type == T_INT || (!x->is_add() && is_obj) LP64_ONLY( || type == T_LONG ), "unexpected type");
aoqi@0 1452 LIR_Address* addr;
aoqi@0 1453 if (offset->is_constant()) {
aoqi@0 1454 #ifdef _LP64
aoqi@0 1455 jlong c = offset->as_jlong();
aoqi@0 1456 if ((jlong)((jint)c) == c) {
aoqi@0 1457 addr = new LIR_Address(src.result(), (jint)c, type);
aoqi@0 1458 } else {
aoqi@0 1459 LIR_Opr tmp = new_register(T_LONG);
aoqi@0 1460 __ move(offset, tmp);
aoqi@0 1461 addr = new LIR_Address(src.result(), tmp, type);
aoqi@0 1462 }
aoqi@0 1463 #else
aoqi@0 1464 addr = new LIR_Address(src.result(), offset->as_jint(), type);
aoqi@0 1465 #endif
aoqi@0 1466 } else {
aoqi@0 1467 addr = new LIR_Address(src.result(), offset, type);
aoqi@0 1468 }
aoqi@0 1469
aoqi@0 1470 // Because we want a 2-arg form of xchg and xadd
aoqi@0 1471 __ move(data, dst);
aoqi@0 1472
aoqi@0 1473 if (x->is_add()) {
aoqi@0 1474 __ xadd(LIR_OprFact::address(addr), dst, dst, LIR_OprFact::illegalOpr);
aoqi@0 1475 } else {
aoqi@0 1476 if (is_obj) {
aoqi@0 1477 // Do the pre-write barrier, if any.
aoqi@0 1478 pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,
aoqi@0 1479 true /* do_load */, false /* patch */, NULL);
aoqi@0 1480 }
aoqi@0 1481 __ xchg(LIR_OprFact::address(addr), dst, dst, LIR_OprFact::illegalOpr);
aoqi@0 1482 if (is_obj) {
aoqi@0 1483 // Seems to be a precise address
aoqi@0 1484 post_barrier(LIR_OprFact::address(addr), data);
aoqi@0 1485 }
aoqi@0 1486 }
aoqi@0 1487 }

mercurial