1 /* 2 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "asm/macroAssembler.inline.hpp" 27 #include "c1/c1_Compilation.hpp" 28 #include "c1/c1_FrameMap.hpp" 29 #include "c1/c1_Instruction.hpp" 30 #include "c1/c1_LIRAssembler.hpp" 31 #include "c1/c1_LIRGenerator.hpp" 32 #include "c1/c1_Runtime1.hpp" 33 #include "c1/c1_ValueStack.hpp" 34 #include "ci/ciArray.hpp" 35 #include "ci/ciObjArrayKlass.hpp" 36 #include "ci/ciTypeArrayKlass.hpp" 37 #include "ci/ciUtilities.hpp" 38 #include "gc/shared/c1/barrierSetC1.hpp" 39 #include "gc/shared/cardTable.hpp" 40 #include "gc/shared/cardTableBarrierSet.hpp" 41 #include "runtime/sharedRuntime.hpp" 42 #include "runtime/stubRoutines.hpp" 43 #include "vmreg_arm.inline.hpp" 44 45 #ifdef ASSERT 46 #define __ gen()->lir(__FILE__, __LINE__)-> 47 #else 48 #define __ gen()->lir()-> 49 #endif 50 51 void LIRItem::load_byte_item() { 52 load_item(); 53 } 54 55 void LIRItem::load_nonconstant() { 56 LIR_Opr r = value()->operand(); 57 if (_gen->can_inline_as_constant(value())) { 58 if (!r->is_constant()) { 59 r = LIR_OprFact::value_type(value()->type()); 60 } 61 _result = r; 62 } else { 63 load_item(); 64 } 65 } 66 67 //-------------------------------------------------------------- 68 // LIRGenerator 69 //-------------------------------------------------------------- 70 71 72 LIR_Opr LIRGenerator::exceptionOopOpr() { 73 return FrameMap::Exception_oop_opr; 74 } 75 76 LIR_Opr LIRGenerator::exceptionPcOpr() { 77 return FrameMap::Exception_pc_opr; 78 } 79 80 LIR_Opr LIRGenerator::syncLockOpr() { 81 return new_register(T_INT); 82 } 83 84 LIR_Opr LIRGenerator::syncTempOpr() { 85 return new_register(T_OBJECT); 86 } 87 88 LIR_Opr LIRGenerator::getThreadTemp() { 89 return LIR_OprFact::illegalOpr; 90 } 91 92 LIR_Opr LIRGenerator::atomicLockOpr() { 93 return LIR_OprFact::illegalOpr; 94 } 95 96 LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) { 97 LIR_Opr opr; 98 switch (type->tag()) { 99 case intTag: opr = FrameMap::Int_result_opr; break; 100 case objectTag: opr = FrameMap::Object_result_opr; break; 101 case longTag: opr = FrameMap::Long_result_opr; break; 102 case floatTag: opr = FrameMap::Float_result_opr; break; 103 case doubleTag: opr = FrameMap::Double_result_opr; break; 104 case addressTag: 105 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr; 106 } 107 assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch"); 108 return opr; 109 } 110 111 112 LIR_Opr LIRGenerator::rlock_byte(BasicType type) { 113 return new_register(T_INT); 114 } 115 116 117 //--------- loading items into registers -------------------------------- 118 119 120 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const { 121 return false; 122 } 123 124 125 bool LIRGenerator::can_inline_as_constant(Value v) const { 126 if (v->type()->as_IntConstant() != NULL) { 127 return Assembler::is_arith_imm_in_range(v->type()->as_IntConstant()->value()); 128 } else if (v->type()->as_ObjectConstant() != NULL) { 129 return v->type()->as_ObjectConstant()->value()->is_null_object(); 130 } else if (v->type()->as_FloatConstant() != NULL) { 131 return v->type()->as_FloatConstant()->value() == 0.0f; 132 } else if (v->type()->as_DoubleConstant() != NULL) { 133 return v->type()->as_DoubleConstant()->value() == 0.0; 134 } 135 return false; 136 } 137 138 139 bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const { 140 ShouldNotCallThis(); // Not used on ARM 141 return false; 142 } 143 144 145 146 147 LIR_Opr LIRGenerator::safepoint_poll_register() { 148 return LIR_OprFact::illegalOpr; 149 } 150 151 152 static LIR_Opr make_constant(BasicType type, jlong c) { 153 switch (type) { 154 case T_ADDRESS: 155 case T_OBJECT: return LIR_OprFact::intptrConst(c); 156 case T_LONG: return LIR_OprFact::longConst(c); 157 case T_INT: return LIR_OprFact::intConst(c); 158 default: ShouldNotReachHere(); 159 return LIR_OprFact::intConst(-1); 160 } 161 } 162 163 164 165 void LIRGenerator::add_large_constant(LIR_Opr src, int c, LIR_Opr dest) { 166 assert(c != 0, "must be"); 167 // Find first non-zero bit 168 int shift = 0; 169 while ((c & (3 << shift)) == 0) { 170 shift += 2; 171 } 172 // Add the least significant part of the constant 173 int mask = 0xff << shift; 174 __ add(src, LIR_OprFact::intConst(c & mask), dest); 175 // Add up to 3 other parts of the constant; 176 // each of them can be represented as rotated_imm 177 if (c & (mask << 8)) { 178 __ add(dest, LIR_OprFact::intConst(c & (mask << 8)), dest); 179 } 180 if (c & (mask << 16)) { 181 __ add(dest, LIR_OprFact::intConst(c & (mask << 16)), dest); 182 } 183 if (c & (mask << 24)) { 184 __ add(dest, LIR_OprFact::intConst(c & (mask << 24)), dest); 185 } 186 } 187 188 static LIR_Address* make_address(LIR_Opr base, LIR_Opr index, LIR_Address::Scale scale, BasicType type) { 189 return new LIR_Address(base, index, scale, 0, type); 190 } 191 192 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index, 193 int shift, int disp, BasicType type) { 194 assert(base->is_register(), "must be"); 195 196 if (index->is_constant()) { 197 disp += index->as_constant_ptr()->as_jint() << shift; 198 index = LIR_OprFact::illegalOpr; 199 } 200 201 if (base->type() == T_LONG) { 202 LIR_Opr tmp = new_register(T_INT); 203 __ convert(Bytecodes::_l2i, base, tmp); 204 base = tmp; 205 } 206 if (index != LIR_OprFact::illegalOpr && index->type() == T_LONG) { 207 LIR_Opr tmp = new_register(T_INT); 208 __ convert(Bytecodes::_l2i, index, tmp); 209 index = tmp; 210 } 211 // At this point base and index should be all ints and not constants 212 assert(base->is_single_cpu() && !base->is_constant(), "base should be an non-constant int"); 213 assert(index->is_illegal() || (index->type() == T_INT && !index->is_constant()), "index should be an non-constant int"); 214 215 int max_disp; 216 bool disp_is_in_range; 217 bool embedded_shift; 218 219 switch (type) { 220 case T_BYTE: 221 case T_SHORT: 222 case T_CHAR: 223 max_disp = 256; // ldrh, ldrsb encoding has 8-bit offset 224 embedded_shift = false; 225 break; 226 case T_FLOAT: 227 case T_DOUBLE: 228 max_disp = 1024; // flds, fldd have 8-bit offset multiplied by 4 229 embedded_shift = false; 230 break; 231 case T_LONG: 232 max_disp = 4096; 233 embedded_shift = false; 234 break; 235 default: 236 max_disp = 4096; // ldr, ldrb allow 12-bit offset 237 embedded_shift = true; 238 } 239 240 disp_is_in_range = (-max_disp < disp && disp < max_disp); 241 242 if (index->is_register()) { 243 LIR_Opr tmp = new_pointer_register(); 244 if (!disp_is_in_range) { 245 add_large_constant(base, disp, tmp); 246 base = tmp; 247 disp = 0; 248 } 249 LIR_Address* addr = make_address(base, index, (LIR_Address::Scale)shift, type); 250 if (disp == 0 && embedded_shift) { 251 // can use ldr/str instruction with register index 252 return addr; 253 } else { 254 LIR_Opr tmp = new_pointer_register(); 255 __ add(base, LIR_OprFact::address(addr), tmp); // add with shifted/extended register 256 return new LIR_Address(tmp, disp, type); 257 } 258 } 259 260 // If the displacement is too large to be inlined into LDR instruction, 261 // generate large constant with additional sequence of ADD instructions 262 int excess_disp = disp & ~(max_disp - 1); 263 if (excess_disp != 0) { 264 LIR_Opr tmp = new_pointer_register(); 265 add_large_constant(base, excess_disp, tmp); 266 base = tmp; 267 } 268 return new LIR_Address(base, disp & (max_disp - 1), type); 269 } 270 271 272 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type) { 273 int base_offset = arrayOopDesc::base_offset_in_bytes(type); 274 int elem_size = type2aelembytes(type); 275 276 if (index_opr->is_constant()) { 277 int offset = base_offset + index_opr->as_constant_ptr()->as_jint() * elem_size; 278 return generate_address(array_opr, offset, type); 279 } else { 280 assert(index_opr->is_register(), "must be"); 281 int scale = exact_log2(elem_size); 282 return generate_address(array_opr, index_opr, scale, base_offset, type); 283 } 284 } 285 286 287 LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) { 288 assert(type == T_LONG || type == T_INT, "should be"); 289 LIR_Opr r = make_constant(type, x); 290 bool imm_in_range = AsmOperand::is_rotated_imm(x); 291 if (!imm_in_range) { 292 LIR_Opr tmp = new_register(type); 293 __ move(r, tmp); 294 return tmp; 295 } 296 return r; 297 } 298 299 300 void LIRGenerator::increment_counter(address counter, BasicType type, int step) { 301 LIR_Opr pointer = new_pointer_register(); 302 __ move(LIR_OprFact::intptrConst(counter), pointer); 303 LIR_Address* addr = new LIR_Address(pointer, type); 304 increment_counter(addr, step); 305 } 306 307 308 void LIRGenerator::increment_counter(LIR_Address* addr, int step) { 309 LIR_Opr temp = new_register(addr->type()); 310 __ move(addr, temp); 311 __ add(temp, make_constant(addr->type(), step), temp); 312 __ move(temp, addr); 313 } 314 315 316 void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) { 317 __ load(new LIR_Address(base, disp, T_INT), FrameMap::LR_opr, info); 318 __ cmp(condition, FrameMap::LR_opr, c); 319 } 320 321 322 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) { 323 __ load(new LIR_Address(base, disp, type), FrameMap::LR_opr, info); 324 __ cmp(condition, reg, FrameMap::LR_opr); 325 } 326 327 328 bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) { 329 assert(left != result, "should be different registers"); 330 if (is_power_of_2(c + 1)) { 331 LIR_Address::Scale scale = (LIR_Address::Scale) log2_intptr(c + 1); 332 LIR_Address* addr = new LIR_Address(left, left, scale, 0, T_INT); 333 __ sub(LIR_OprFact::address(addr), left, result); // rsb with shifted register 334 return true; 335 } else if (is_power_of_2(c - 1)) { 336 LIR_Address::Scale scale = (LIR_Address::Scale) log2_intptr(c - 1); 337 LIR_Address* addr = new LIR_Address(left, left, scale, 0, T_INT); 338 __ add(left, LIR_OprFact::address(addr), result); // add with shifted register 339 return true; 340 } 341 return false; 342 } 343 344 345 void LIRGenerator::store_stack_parameter(LIR_Opr item, ByteSize offset_from_sp) { 346 assert(item->type() == T_INT, "other types are not expected"); 347 __ store(item, new LIR_Address(FrameMap::SP_opr, in_bytes(offset_from_sp), item->type())); 348 } 349 350 void LIRGenerator::set_card(LIR_Opr value, LIR_Address* card_addr) { 351 assert(CardTable::dirty_card_val() == 0, 352 "Cannot use the register containing the card table base address directly"); 353 if((ci_card_table_address_as<intx>() & 0xff) == 0) { 354 // If the card table base address is aligned to 256 bytes, we can use the register 355 // that contains the card_table_base_address. 356 __ move(value, card_addr); 357 } else { 358 // Otherwise we need to create a register containing that value. 359 LIR_Opr tmp_zero = new_register(T_INT); 360 __ move(LIR_OprFact::intConst(CardTable::dirty_card_val()), tmp_zero); 361 __ move(tmp_zero, card_addr); 362 } 363 } 364 365 void LIRGenerator::CardTableBarrierSet_post_barrier_helper(LIR_OprDesc* addr, LIR_Const* card_table_base) { 366 assert(addr->is_register(), "must be a register at this point"); 367 368 CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(BarrierSet::barrier_set()); 369 CardTable* ct = ctbs->card_table(); 370 371 LIR_Opr tmp = FrameMap::LR_ptr_opr; 372 373 bool load_card_table_base_const = VM_Version::supports_movw(); 374 if (load_card_table_base_const) { 375 __ move((LIR_Opr)card_table_base, tmp); 376 } else { 377 __ move(new LIR_Address(FrameMap::Rthread_opr, in_bytes(JavaThread::card_table_base_offset()), T_ADDRESS), tmp); 378 } 379 380 // Use unsigned type T_BOOLEAN here rather than (signed) T_BYTE since signed load 381 // byte instruction does not support the addressing mode we need. 382 LIR_Address* card_addr = new LIR_Address(tmp, addr, (LIR_Address::Scale) -CardTable::card_shift, 0, T_BOOLEAN); 383 if (UseCondCardMark) { 384 if (ct->scanned_concurrently()) { 385 __ membar_storeload(); 386 } 387 LIR_Opr cur_value = new_register(T_INT); 388 __ move(card_addr, cur_value); 389 390 LabelObj* L_already_dirty = new LabelObj(); 391 __ cmp(lir_cond_equal, cur_value, LIR_OprFact::intConst(CardTable::dirty_card_val())); 392 __ branch(lir_cond_equal, T_BYTE, L_already_dirty->label()); 393 set_card(tmp, card_addr); 394 __ branch_destination(L_already_dirty->label()); 395 } else { 396 if (ct->scanned_concurrently()) { 397 __ membar_storestore(); 398 } 399 set_card(tmp, card_addr); 400 } 401 } 402 403 void LIRGenerator::array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci) { 404 LIR_Opr tmp1 = FrameMap::R0_oop_opr; 405 LIR_Opr tmp2 = FrameMap::R1_oop_opr; 406 LIR_Opr tmp3 = LIR_OprFact::illegalOpr; 407 __ store_check(value, array, tmp1, tmp2, tmp3, store_check_info, profiled_method, profiled_bci); 408 } 409 410 //---------------------------------------------------------------------- 411 // visitor functions 412 //---------------------------------------------------------------------- 413 414 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) { 415 assert(x->is_pinned(),""); 416 LIRItem obj(x->obj(), this); 417 obj.load_item(); 418 set_no_result(x); 419 420 LIR_Opr lock = new_pointer_register(); 421 LIR_Opr hdr = new_pointer_register(); 422 423 // Need a scratch register for biased locking on arm 424 LIR_Opr scratch = LIR_OprFact::illegalOpr; 425 if(UseBiasedLocking) { 426 scratch = new_pointer_register(); 427 } else { 428 scratch = atomicLockOpr(); 429 } 430 431 CodeEmitInfo* info_for_exception = NULL; 432 if (x->needs_null_check()) { 433 info_for_exception = state_for(x); 434 } 435 436 CodeEmitInfo* info = state_for(x, x->state(), true); 437 monitor_enter(obj.result(), lock, hdr, scratch, 438 x->monitor_no(), info_for_exception, info); 439 } 440 441 442 void LIRGenerator::do_MonitorExit(MonitorExit* x) { 443 assert(x->is_pinned(),""); 444 LIRItem obj(x->obj(), this); 445 obj.dont_load_item(); 446 set_no_result(x); 447 448 LIR_Opr obj_temp = new_pointer_register(); 449 LIR_Opr lock = new_pointer_register(); 450 LIR_Opr hdr = new_pointer_register(); 451 452 monitor_exit(obj_temp, lock, hdr, atomicLockOpr(), x->monitor_no()); 453 } 454 455 456 // _ineg, _lneg, _fneg, _dneg 457 void LIRGenerator::do_NegateOp(NegateOp* x) { 458 #ifdef __SOFTFP__ 459 address runtime_func = NULL; 460 ValueTag tag = x->type()->tag(); 461 if (tag == floatTag) { 462 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::fneg); 463 } else if (tag == doubleTag) { 464 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dneg); 465 } 466 if (runtime_func != NULL) { 467 set_result(x, call_runtime(x->x(), runtime_func, x->type(), NULL)); 468 return; 469 } 470 #endif // __SOFTFP__ 471 LIRItem value(x->x(), this); 472 value.load_item(); 473 LIR_Opr reg = rlock_result(x); 474 __ negate(value.result(), reg); 475 } 476 477 478 // for _fadd, _fmul, _fsub, _fdiv, _frem 479 // _dadd, _dmul, _dsub, _ddiv, _drem 480 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) { 481 address runtime_func; 482 switch (x->op()) { 483 case Bytecodes::_frem: 484 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::frem); 485 break; 486 case Bytecodes::_drem: 487 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::drem); 488 break; 489 #ifdef __SOFTFP__ 490 // Call function compiled with -msoft-float. 491 492 // __aeabi_XXXX_extlib: Optional wrapper around SoftFloat-3e 493 // for calculation accuracy improvement. See CR 6757269, JDK-8215902. 494 495 case Bytecodes::_fadd: 496 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_fadd_extlib); 497 break; 498 case Bytecodes::_fmul: 499 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_fmul); 500 break; 501 case Bytecodes::_fsub: 502 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_fsub_extlib); 503 break; 504 case Bytecodes::_fdiv: 505 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_fdiv); 506 break; 507 case Bytecodes::_dadd: 508 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_dadd_extlib); 509 break; 510 case Bytecodes::_dmul: 511 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_dmul); 512 break; 513 case Bytecodes::_dsub: 514 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_dsub_extlib); 515 break; 516 case Bytecodes::_ddiv: 517 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_ddiv); 518 break; 519 default: 520 ShouldNotReachHere(); 521 #else // __SOFTFP__ 522 default: { 523 LIRItem left(x->x(), this); 524 LIRItem right(x->y(), this); 525 left.load_item(); 526 right.load_item(); 527 rlock_result(x); 528 arithmetic_op_fpu(x->op(), x->operand(), left.result(), right.result(), x->is_strictfp()); 529 return; 530 } 531 #endif // __SOFTFP__ 532 } 533 534 LIR_Opr result = call_runtime(x->x(), x->y(), runtime_func, x->type(), NULL); 535 set_result(x, result); 536 } 537 538 539 void LIRGenerator::make_div_by_zero_check(LIR_Opr right_arg, BasicType type, CodeEmitInfo* info) { 540 assert(right_arg->is_register(), "must be"); 541 __ cmp(lir_cond_equal, right_arg, make_constant(type, 0)); 542 __ branch(lir_cond_equal, type, new DivByZeroStub(info)); 543 } 544 545 546 // for _ladd, _lmul, _lsub, _ldiv, _lrem 547 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) { 548 CodeEmitInfo* info = NULL; 549 if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) { 550 info = state_for(x); 551 } 552 553 switch (x->op()) { 554 case Bytecodes::_ldiv: 555 case Bytecodes::_lrem: { 556 LIRItem right(x->y(), this); 557 right.load_item(); 558 make_div_by_zero_check(right.result(), T_LONG, info); 559 } 560 // Fall through 561 case Bytecodes::_lmul: { 562 address entry; 563 switch (x->op()) { 564 case Bytecodes::_lrem: 565 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem); 566 break; 567 case Bytecodes::_ldiv: 568 entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv); 569 break; 570 case Bytecodes::_lmul: 571 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul); 572 break; 573 default: 574 ShouldNotReachHere(); 575 return; 576 } 577 LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL); 578 set_result(x, result); 579 break; 580 } 581 case Bytecodes::_ladd: 582 case Bytecodes::_lsub: { 583 LIRItem left(x->x(), this); 584 LIRItem right(x->y(), this); 585 left.load_item(); 586 right.load_item(); 587 rlock_result(x); 588 arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL); 589 break; 590 } 591 default: 592 ShouldNotReachHere(); 593 } 594 } 595 596 597 // for: _iadd, _imul, _isub, _idiv, _irem 598 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) { 599 bool is_div_rem = x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem; 600 LIRItem left(x->x(), this); 601 LIRItem right(x->y(), this); 602 LIRItem* left_arg = &left; 603 LIRItem* right_arg = &right; 604 605 // Test if instr is commutative and if we should swap 606 if (x->is_commutative() && left.is_constant()) { 607 left_arg = &right; 608 right_arg = &left; 609 } 610 611 if (is_div_rem) { 612 CodeEmitInfo* info = state_for(x); 613 if (x->op() == Bytecodes::_idiv && right_arg->is_constant() && is_power_of_2(right_arg->get_jint_constant())) { 614 left_arg->load_item(); 615 right_arg->dont_load_item(); 616 LIR_Opr tmp = LIR_OprFact::illegalOpr; 617 LIR_Opr result = rlock_result(x); 618 __ idiv(left_arg->result(), right_arg->result(), result, tmp, info); 619 } else { 620 left_arg->load_item_force(FrameMap::R0_opr); 621 right_arg->load_item_force(FrameMap::R2_opr); 622 LIR_Opr tmp = FrameMap::R1_opr; 623 LIR_Opr result = rlock_result(x); 624 LIR_Opr out_reg; 625 if (x->op() == Bytecodes::_irem) { 626 out_reg = FrameMap::R0_opr; 627 __ irem(left_arg->result(), right_arg->result(), out_reg, tmp, info); 628 } else { // (x->op() == Bytecodes::_idiv) 629 out_reg = FrameMap::R1_opr; 630 __ idiv(left_arg->result(), right_arg->result(), out_reg, tmp, info); 631 } 632 __ move(out_reg, result); 633 } 634 635 636 } else { 637 left_arg->load_item(); 638 if (x->op() == Bytecodes::_imul && right_arg->is_constant()) { 639 jint c = right_arg->get_jint_constant(); 640 if (c > 0 && c < max_jint && (is_power_of_2(c) || is_power_of_2(c - 1) || is_power_of_2(c + 1))) { 641 right_arg->dont_load_item(); 642 } else { 643 right_arg->load_item(); 644 } 645 } else { 646 right_arg->load_nonconstant(); 647 } 648 rlock_result(x); 649 assert(right_arg->is_constant() || right_arg->is_register(), "wrong state of right"); 650 arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), NULL); 651 } 652 } 653 654 655 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) { 656 ValueTag tag = x->type()->tag(); 657 assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters"); 658 switch (tag) { 659 case floatTag: 660 case doubleTag: do_ArithmeticOp_FPU(x); return; 661 case longTag: do_ArithmeticOp_Long(x); return; 662 case intTag: do_ArithmeticOp_Int(x); return; 663 default: ShouldNotReachHere(); return; 664 } 665 } 666 667 668 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr 669 void LIRGenerator::do_ShiftOp(ShiftOp* x) { 670 LIRItem value(x->x(), this); 671 LIRItem count(x->y(), this); 672 673 if (value.type()->is_long()) { 674 count.set_destroys_register(); 675 } 676 677 if (count.is_constant()) { 678 assert(count.type()->as_IntConstant() != NULL, "should be"); 679 count.dont_load_item(); 680 } else { 681 count.load_item(); 682 } 683 value.load_item(); 684 685 LIR_Opr res = rlock_result(x); 686 shift_op(x->op(), res, value.result(), count.result(), LIR_OprFact::illegalOpr); 687 } 688 689 690 // _iand, _land, _ior, _lor, _ixor, _lxor 691 void LIRGenerator::do_LogicOp(LogicOp* x) { 692 LIRItem left(x->x(), this); 693 LIRItem right(x->y(), this); 694 695 left.load_item(); 696 697 right.load_nonconstant(); 698 699 logic_op(x->op(), rlock_result(x), left.result(), right.result()); 700 } 701 702 703 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg 704 void LIRGenerator::do_CompareOp(CompareOp* x) { 705 #ifdef __SOFTFP__ 706 address runtime_func; 707 switch (x->op()) { 708 case Bytecodes::_fcmpl: 709 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::fcmpl); 710 break; 711 case Bytecodes::_fcmpg: 712 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::fcmpg); 713 break; 714 case Bytecodes::_dcmpl: 715 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dcmpl); 716 break; 717 case Bytecodes::_dcmpg: 718 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dcmpg); 719 break; 720 case Bytecodes::_lcmp: { 721 LIRItem left(x->x(), this); 722 LIRItem right(x->y(), this); 723 left.load_item(); 724 right.load_nonconstant(); 725 LIR_Opr reg = rlock_result(x); 726 __ lcmp2int(left.result(), right.result(), reg); 727 return; 728 } 729 default: 730 ShouldNotReachHere(); 731 } 732 LIR_Opr result = call_runtime(x->x(), x->y(), runtime_func, x->type(), NULL); 733 set_result(x, result); 734 #else // __SOFTFP__ 735 LIRItem left(x->x(), this); 736 LIRItem right(x->y(), this); 737 left.load_item(); 738 739 right.load_nonconstant(); 740 741 LIR_Opr reg = rlock_result(x); 742 743 if (x->x()->type()->is_float_kind()) { 744 Bytecodes::Code code = x->op(); 745 __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl)); 746 } else if (x->x()->type()->tag() == longTag) { 747 __ lcmp2int(left.result(), right.result(), reg); 748 } else { 749 ShouldNotReachHere(); 750 } 751 #endif // __SOFTFP__ 752 } 753 754 LIR_Opr LIRGenerator::atomic_cmpxchg(BasicType type, LIR_Opr addr, LIRItem& cmp_value, LIRItem& new_value) { 755 LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience 756 LIR_Opr tmp1 = LIR_OprFact::illegalOpr; 757 LIR_Opr tmp2 = LIR_OprFact::illegalOpr; 758 new_value.load_item(); 759 cmp_value.load_item(); 760 LIR_Opr result = new_register(T_INT); 761 if (type == T_OBJECT || type == T_ARRAY) { 762 __ cas_obj(addr, cmp_value.result(), new_value.result(), new_register(T_INT), new_register(T_INT), result); 763 } else if (type == T_INT) { 764 __ cas_int(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), tmp1, tmp1, result); 765 } else if (type == T_LONG) { 766 tmp1 = new_register(T_LONG); 767 __ cas_long(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), tmp1, tmp2, result); 768 } else { 769 ShouldNotReachHere(); 770 } 771 return result; 772 } 773 774 LIR_Opr LIRGenerator::atomic_xchg(BasicType type, LIR_Opr addr, LIRItem& value) { 775 bool is_oop = type == T_OBJECT || type == T_ARRAY; 776 LIR_Opr result = new_register(type); 777 value.load_item(); 778 assert(type == T_INT || is_oop LP64_ONLY( || type == T_LONG ), "unexpected type"); 779 LIR_Opr tmp = (UseCompressedOops && is_oop) ? new_pointer_register() : LIR_OprFact::illegalOpr; 780 __ xchg(addr, value.result(), result, tmp); 781 return result; 782 } 783 784 LIR_Opr LIRGenerator::atomic_add(BasicType type, LIR_Opr addr, LIRItem& value) { 785 LIR_Opr result = new_register(type); 786 value.load_item(); 787 assert(type == T_INT LP64_ONLY( || type == T_LONG), "unexpected type"); 788 LIR_Opr tmp = new_register(type); 789 __ xadd(addr, value.result(), result, tmp); 790 return result; 791 } 792 793 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) { 794 address runtime_func; 795 switch (x->id()) { 796 case vmIntrinsics::_dabs: { 797 #ifdef __SOFTFP__ 798 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dabs); 799 break; 800 #else 801 assert(x->number_of_arguments() == 1, "wrong type"); 802 LIRItem value(x->argument_at(0), this); 803 value.load_item(); 804 __ abs(value.result(), rlock_result(x), LIR_OprFact::illegalOpr); 805 return; 806 #endif // __SOFTFP__ 807 } 808 case vmIntrinsics::_dsqrt: { 809 #ifdef __SOFTFP__ 810 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dsqrt); 811 break; 812 #else 813 assert(x->number_of_arguments() == 1, "wrong type"); 814 LIRItem value(x->argument_at(0), this); 815 value.load_item(); 816 __ sqrt(value.result(), rlock_result(x), LIR_OprFact::illegalOpr); 817 return; 818 #endif // __SOFTFP__ 819 } 820 case vmIntrinsics::_dsin: 821 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dsin); 822 break; 823 case vmIntrinsics::_dcos: 824 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dcos); 825 break; 826 case vmIntrinsics::_dtan: 827 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dtan); 828 break; 829 case vmIntrinsics::_dlog: 830 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dlog); 831 break; 832 case vmIntrinsics::_dlog10: 833 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10); 834 break; 835 case vmIntrinsics::_dexp: 836 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dexp); 837 break; 838 case vmIntrinsics::_dpow: 839 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dpow); 840 break; 841 default: 842 ShouldNotReachHere(); 843 return; 844 } 845 846 LIR_Opr result; 847 if (x->number_of_arguments() == 1) { 848 result = call_runtime(x->argument_at(0), runtime_func, x->type(), NULL); 849 } else { 850 assert(x->number_of_arguments() == 2 && x->id() == vmIntrinsics::_dpow, "unexpected intrinsic"); 851 result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_func, x->type(), NULL); 852 } 853 set_result(x, result); 854 } 855 856 void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) { 857 fatal("FMA intrinsic is not implemented on this platform"); 858 } 859 860 void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) { 861 fatal("vectorizedMismatch intrinsic is not implemented on this platform"); 862 } 863 864 void LIRGenerator::do_ArrayCopy(Intrinsic* x) { 865 CodeEmitInfo* info = state_for(x, x->state()); 866 assert(x->number_of_arguments() == 5, "wrong type"); 867 LIRItem src(x->argument_at(0), this); 868 LIRItem src_pos(x->argument_at(1), this); 869 LIRItem dst(x->argument_at(2), this); 870 LIRItem dst_pos(x->argument_at(3), this); 871 LIRItem length(x->argument_at(4), this); 872 873 // We put arguments into the same registers which are used for a Java call. 874 // Note: we used fixed registers for all arguments because all registers 875 // are caller-saved, so register allocator treats them all as used. 876 src.load_item_force (FrameMap::R0_oop_opr); 877 src_pos.load_item_force(FrameMap::R1_opr); 878 dst.load_item_force (FrameMap::R2_oop_opr); 879 dst_pos.load_item_force(FrameMap::R3_opr); 880 length.load_item_force (FrameMap::R4_opr); 881 LIR_Opr tmp = (FrameMap::R5_opr); 882 set_no_result(x); 883 884 int flags; 885 ciArrayKlass* expected_type; 886 arraycopy_helper(x, &flags, &expected_type); 887 __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), 888 tmp, expected_type, flags, info); 889 } 890 891 void LIRGenerator::do_update_CRC32(Intrinsic* x) { 892 fatal("CRC32 intrinsic is not implemented on this platform"); 893 } 894 895 void LIRGenerator::do_update_CRC32C(Intrinsic* x) { 896 Unimplemented(); 897 } 898 899 void LIRGenerator::do_Convert(Convert* x) { 900 address runtime_func; 901 switch (x->op()) { 902 case Bytecodes::_l2f: 903 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::l2f); 904 break; 905 case Bytecodes::_l2d: 906 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::l2d); 907 break; 908 case Bytecodes::_f2l: 909 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::f2l); 910 break; 911 case Bytecodes::_d2l: 912 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::d2l); 913 break; 914 #ifdef __SOFTFP__ 915 case Bytecodes::_f2d: 916 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_f2d); 917 break; 918 case Bytecodes::_d2f: 919 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_d2f); 920 break; 921 case Bytecodes::_i2f: 922 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_i2f); 923 break; 924 case Bytecodes::_i2d: 925 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_i2d); 926 break; 927 case Bytecodes::_f2i: 928 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_f2iz); 929 break; 930 case Bytecodes::_d2i: 931 // This is implemented in hard float in assembler on arm but a call 932 // on other platforms. 933 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::d2i); 934 break; 935 #endif // __SOFTFP__ 936 default: { 937 LIRItem value(x->value(), this); 938 value.load_item(); 939 LIR_Opr reg = rlock_result(x); 940 __ convert(x->op(), value.result(), reg, NULL); 941 return; 942 } 943 } 944 945 LIR_Opr result = call_runtime(x->value(), runtime_func, x->type(), NULL); 946 set_result(x, result); 947 } 948 949 950 void LIRGenerator::do_NewInstance(NewInstance* x) { 951 print_if_not_loaded(x); 952 953 CodeEmitInfo* info = state_for(x, x->state()); 954 LIR_Opr reg = result_register_for(x->type()); // R0 is required by runtime call in NewInstanceStub::emit_code 955 LIR_Opr klass_reg = FrameMap::R1_metadata_opr; // R1 is required by runtime call in NewInstanceStub::emit_code 956 LIR_Opr tmp1 = new_register(objectType); 957 LIR_Opr tmp2 = new_register(objectType); 958 LIR_Opr tmp3 = FrameMap::LR_oop_opr; 959 960 new_instance(reg, x->klass(), x->is_unresolved(), tmp1, tmp2, tmp3, 961 LIR_OprFact::illegalOpr, klass_reg, info); 962 963 LIR_Opr result = rlock_result(x); 964 __ move(reg, result); 965 } 966 967 968 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) { 969 // Evaluate state_for() first, because it can emit code 970 // with the same fixed registers that are used here (R1, R2) 971 CodeEmitInfo* info = state_for(x, x->state()); 972 LIRItem length(x->length(), this); 973 974 length.load_item_force(FrameMap::R2_opr); // R2 is required by runtime call in NewTypeArrayStub::emit_code 975 LIR_Opr len = length.result(); 976 977 LIR_Opr reg = result_register_for(x->type()); // R0 is required by runtime call in NewTypeArrayStub::emit_code 978 LIR_Opr klass_reg = FrameMap::R1_metadata_opr; // R1 is required by runtime call in NewTypeArrayStub::emit_code 979 980 LIR_Opr tmp1 = new_register(objectType); 981 LIR_Opr tmp2 = new_register(objectType); 982 LIR_Opr tmp3 = FrameMap::LR_oop_opr; 983 LIR_Opr tmp4 = LIR_OprFact::illegalOpr; 984 985 BasicType elem_type = x->elt_type(); 986 __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg); 987 988 CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info); 989 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path); 990 991 LIR_Opr result = rlock_result(x); 992 __ move(reg, result); 993 } 994 995 996 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) { 997 // Evaluate state_for() first, because it can emit code 998 // with the same fixed registers that are used here (R1, R2) 999 CodeEmitInfo* info = state_for(x, x->state()); 1000 LIRItem length(x->length(), this); 1001 1002 length.load_item_force(FrameMap::R2_opr); // R2 is required by runtime call in NewObjectArrayStub::emit_code 1003 LIR_Opr len = length.result(); 1004 1005 CodeEmitInfo* patching_info = NULL; 1006 if (!x->klass()->is_loaded() || PatchALot) { 1007 patching_info = state_for(x, x->state_before()); 1008 } 1009 1010 LIR_Opr reg = result_register_for(x->type()); // R0 is required by runtime call in NewObjectArrayStub::emit_code 1011 LIR_Opr klass_reg = FrameMap::R1_metadata_opr; // R1 is required by runtime call in NewObjectArrayStub::emit_code 1012 1013 LIR_Opr tmp1 = new_register(objectType); 1014 LIR_Opr tmp2 = new_register(objectType); 1015 LIR_Opr tmp3 = FrameMap::LR_oop_opr; 1016 LIR_Opr tmp4 = LIR_OprFact::illegalOpr; 1017 1018 CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info); 1019 ciMetadata* obj = ciObjArrayKlass::make(x->klass()); 1020 if (obj == ciEnv::unloaded_ciobjarrayklass()) { 1021 BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error"); 1022 } 1023 klass2reg_with_patching(klass_reg, obj, patching_info); 1024 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path); 1025 1026 LIR_Opr result = rlock_result(x); 1027 __ move(reg, result); 1028 } 1029 1030 1031 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) { 1032 Values* dims = x->dims(); 1033 int i = dims->length(); 1034 LIRItemList* items = new LIRItemList(i, i, NULL); 1035 while (i-- > 0) { 1036 LIRItem* size = new LIRItem(dims->at(i), this); 1037 items->at_put(i, size); 1038 } 1039 1040 // Need to get the info before, as the items may become invalid through item_free 1041 CodeEmitInfo* patching_info = NULL; 1042 if (!x->klass()->is_loaded() || PatchALot) { 1043 patching_info = state_for(x, x->state_before()); 1044 1045 // Cannot re-use same xhandlers for multiple CodeEmitInfos, so 1046 // clone all handlers (NOTE: Usually this is handled transparently 1047 // by the CodeEmitInfo cloning logic in CodeStub constructors but 1048 // is done explicitly here because a stub isn't being used). 1049 x->set_exception_handlers(new XHandlers(x->exception_handlers())); 1050 } 1051 1052 i = dims->length(); 1053 while (i-- > 0) { 1054 LIRItem* size = items->at(i); 1055 size->load_item(); 1056 LIR_Opr sz = size->result(); 1057 assert(sz->type() == T_INT, "should be"); 1058 store_stack_parameter(sz, in_ByteSize(i * BytesPerInt)); 1059 } 1060 1061 CodeEmitInfo* info = state_for(x, x->state()); 1062 LIR_Opr klass_reg = FrameMap::R0_metadata_opr; 1063 klass2reg_with_patching(klass_reg, x->klass(), patching_info); 1064 1065 LIR_Opr rank = FrameMap::R2_opr; 1066 __ move(LIR_OprFact::intConst(x->rank()), rank); 1067 LIR_Opr varargs = FrameMap::SP_opr; 1068 LIR_OprList* args = new LIR_OprList(3); 1069 args->append(klass_reg); 1070 args->append(rank); 1071 args->append(varargs); 1072 LIR_Opr reg = result_register_for(x->type()); 1073 __ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id), 1074 LIR_OprFact::illegalOpr, reg, args, info); 1075 1076 LIR_Opr result = rlock_result(x); 1077 __ move(reg, result); 1078 } 1079 1080 1081 void LIRGenerator::do_BlockBegin(BlockBegin* x) { 1082 // nothing to do for now 1083 } 1084 1085 1086 void LIRGenerator::do_CheckCast(CheckCast* x) { 1087 LIRItem obj(x->obj(), this); 1088 CodeEmitInfo* patching_info = NULL; 1089 if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check() && !x->is_invokespecial_receiver_check())) { 1090 patching_info = state_for(x, x->state_before()); 1091 } 1092 1093 obj.load_item(); 1094 1095 CodeEmitInfo* info_for_exception = 1096 (x->needs_exception_state() ? state_for(x) : 1097 state_for(x, x->state_before(), true /*ignore_xhandler*/)); 1098 1099 CodeStub* stub; 1100 if (x->is_incompatible_class_change_check()) { 1101 assert(patching_info == NULL, "can't patch this"); 1102 stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, 1103 LIR_OprFact::illegalOpr, info_for_exception); 1104 } else if (x->is_invokespecial_receiver_check()) { 1105 assert(patching_info == NULL, "can't patch this"); 1106 stub = new DeoptimizeStub(info_for_exception, 1107 Deoptimization::Reason_class_check, 1108 Deoptimization::Action_none); 1109 } else { 1110 stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, 1111 LIR_OprFact::illegalOpr, info_for_exception); 1112 } 1113 1114 LIR_Opr out_reg = rlock_result(x); 1115 LIR_Opr tmp1 = FrameMap::R0_oop_opr; 1116 LIR_Opr tmp2 = FrameMap::R1_oop_opr; 1117 LIR_Opr tmp3 = LIR_OprFact::illegalOpr; 1118 1119 __ checkcast(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3, x->direct_compare(), 1120 info_for_exception, patching_info, stub, x->profiled_method(), x->profiled_bci()); 1121 } 1122 1123 1124 void LIRGenerator::do_InstanceOf(InstanceOf* x) { 1125 LIRItem obj(x->obj(), this); 1126 CodeEmitInfo* patching_info = NULL; 1127 if (!x->klass()->is_loaded() || PatchALot) { 1128 patching_info = state_for(x, x->state_before()); 1129 } 1130 1131 obj.load_item(); 1132 LIR_Opr out_reg = rlock_result(x); 1133 LIR_Opr tmp1 = FrameMap::R0_oop_opr; 1134 LIR_Opr tmp2 = FrameMap::R1_oop_opr; 1135 LIR_Opr tmp3 = LIR_OprFact::illegalOpr; 1136 1137 __ instanceof(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3, 1138 x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci()); 1139 } 1140 1141 1142 #ifdef __SOFTFP__ 1143 // Turn operator if (f <op> g) into runtime call: 1144 // call _aeabi_fcmp<op>(f, g) 1145 // cmp(eq, 1) 1146 // branch(eq, true path). 1147 void LIRGenerator::do_soft_float_compare(If* x) { 1148 assert(x->number_of_sux() == 2, "inconsistency"); 1149 ValueTag tag = x->x()->type()->tag(); 1150 If::Condition cond = x->cond(); 1151 address runtime_func; 1152 // unordered comparison gets the wrong answer because aeabi functions 1153 // return false. 1154 bool unordered_is_true = x->unordered_is_true(); 1155 // reverse of condition for ne 1156 bool compare_to_zero = false; 1157 switch (lir_cond(cond)) { 1158 case lir_cond_notEqual: 1159 compare_to_zero = true; // fall through 1160 case lir_cond_equal: 1161 runtime_func = tag == floatTag ? 1162 CAST_FROM_FN_PTR(address, __aeabi_fcmpeq): 1163 CAST_FROM_FN_PTR(address, __aeabi_dcmpeq); 1164 break; 1165 case lir_cond_less: 1166 if (unordered_is_true) { 1167 runtime_func = tag == floatTag ? 1168 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_fcmplt): 1169 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_dcmplt); 1170 } else { 1171 runtime_func = tag == floatTag ? 1172 CAST_FROM_FN_PTR(address, __aeabi_fcmplt): 1173 CAST_FROM_FN_PTR(address, __aeabi_dcmplt); 1174 } 1175 break; 1176 case lir_cond_lessEqual: 1177 if (unordered_is_true) { 1178 runtime_func = tag == floatTag ? 1179 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_fcmple): 1180 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_dcmple); 1181 } else { 1182 runtime_func = tag == floatTag ? 1183 CAST_FROM_FN_PTR(address, __aeabi_fcmple): 1184 CAST_FROM_FN_PTR(address, __aeabi_dcmple); 1185 } 1186 break; 1187 case lir_cond_greaterEqual: 1188 if (unordered_is_true) { 1189 runtime_func = tag == floatTag ? 1190 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_fcmpge): 1191 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_dcmpge); 1192 } else { 1193 runtime_func = tag == floatTag ? 1194 CAST_FROM_FN_PTR(address, __aeabi_fcmpge): 1195 CAST_FROM_FN_PTR(address, __aeabi_dcmpge); 1196 } 1197 break; 1198 case lir_cond_greater: 1199 if (unordered_is_true) { 1200 runtime_func = tag == floatTag ? 1201 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_fcmpgt): 1202 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_dcmpgt); 1203 } else { 1204 runtime_func = tag == floatTag ? 1205 CAST_FROM_FN_PTR(address, __aeabi_fcmpgt): 1206 CAST_FROM_FN_PTR(address, __aeabi_dcmpgt); 1207 } 1208 break; 1209 case lir_cond_aboveEqual: 1210 case lir_cond_belowEqual: 1211 ShouldNotReachHere(); // We're not going to get these. 1212 default: 1213 assert(lir_cond(cond) == lir_cond_always, "must be"); 1214 ShouldNotReachHere(); 1215 } 1216 set_no_result(x); 1217 1218 // add safepoint before generating condition code so it can be recomputed 1219 if (x->is_safepoint()) { 1220 increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci()); 1221 __ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before())); 1222 } 1223 // Call float compare function, returns (1,0) if true or false. 1224 LIR_Opr result = call_runtime(x->x(), x->y(), runtime_func, intType, NULL); 1225 __ cmp(lir_cond_equal, result, 1226 compare_to_zero ? 1227 LIR_OprFact::intConst(0) : LIR_OprFact::intConst(1)); 1228 profile_branch(x, cond); 1229 move_to_phi(x->state()); 1230 __ branch(lir_cond_equal, T_INT, x->tsux()); 1231 } 1232 #endif // __SOFTFP__ 1233 1234 void LIRGenerator::do_If(If* x) { 1235 assert(x->number_of_sux() == 2, "inconsistency"); 1236 ValueTag tag = x->x()->type()->tag(); 1237 1238 #ifdef __SOFTFP__ 1239 if (tag == floatTag || tag == doubleTag) { 1240 do_soft_float_compare(x); 1241 assert(x->default_sux() == x->fsux(), "wrong destination above"); 1242 __ jump(x->default_sux()); 1243 return; 1244 } 1245 #endif // __SOFTFP__ 1246 1247 LIRItem xitem(x->x(), this); 1248 LIRItem yitem(x->y(), this); 1249 LIRItem* xin = &xitem; 1250 LIRItem* yin = &yitem; 1251 If::Condition cond = x->cond(); 1252 1253 if (tag == longTag) { 1254 if (cond == If::gtr || cond == If::leq) { 1255 cond = Instruction::mirror(cond); 1256 xin = &yitem; 1257 yin = &xitem; 1258 } 1259 xin->set_destroys_register(); 1260 } 1261 1262 xin->load_item(); 1263 LIR_Opr left = xin->result(); 1264 LIR_Opr right; 1265 1266 if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && 1267 (cond == If::eql || cond == If::neq)) { 1268 // inline long zero 1269 right = LIR_OprFact::value_type(yin->value()->type()); 1270 } else { 1271 yin->load_nonconstant(); 1272 right = yin->result(); 1273 } 1274 1275 set_no_result(x); 1276 1277 // add safepoint before generating condition code so it can be recomputed 1278 if (x->is_safepoint()) { 1279 increment_backedge_counter_conditionally(lir_cond(cond), left, right, state_for(x, x->state_before()), 1280 x->tsux()->bci(), x->fsux()->bci(), x->profiled_bci()); 1281 __ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before())); 1282 } 1283 1284 __ cmp(lir_cond(cond), left, right); 1285 profile_branch(x, cond); 1286 move_to_phi(x->state()); 1287 if (x->x()->type()->is_float_kind()) { 1288 __ branch(lir_cond(cond), right->type(), x->tsux(), x->usux()); 1289 } else { 1290 __ branch(lir_cond(cond), right->type(), x->tsux()); 1291 } 1292 assert(x->default_sux() == x->fsux(), "wrong destination above"); 1293 __ jump(x->default_sux()); 1294 } 1295 1296 1297 LIR_Opr LIRGenerator::getThreadPointer() { 1298 return FrameMap::Rthread_opr; 1299 } 1300 1301 void LIRGenerator::trace_block_entry(BlockBegin* block) { 1302 __ move(LIR_OprFact::intConst(block->block_id()), FrameMap::R0_opr); 1303 LIR_OprList* args = new LIR_OprList(1); 1304 args->append(FrameMap::R0_opr); 1305 address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry); 1306 __ call_runtime_leaf(func, getThreadTemp(), LIR_OprFact::illegalOpr, args); 1307 } 1308 1309 1310 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address, 1311 CodeEmitInfo* info) { 1312 if (value->is_double_cpu()) { 1313 assert(address->index()->is_illegal(), "should have a constant displacement"); 1314 LIR_Opr tmp = new_pointer_register(); 1315 add_large_constant(address->base(), address->disp(), tmp); 1316 __ volatile_store_mem_reg(value, new LIR_Address(tmp, (intx)0, address->type()), info); 1317 return; 1318 } 1319 __ store(value, address, info, lir_patch_none); 1320 } 1321 1322 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result, 1323 CodeEmitInfo* info) { 1324 if (result->is_double_cpu()) { 1325 assert(address->index()->is_illegal(), "should have a constant displacement"); 1326 LIR_Opr tmp = new_pointer_register(); 1327 add_large_constant(address->base(), address->disp(), tmp); 1328 __ volatile_load_mem_reg(new LIR_Address(tmp, (intx)0, address->type()), result, info); 1329 return; 1330 } 1331 __ load(address, result, info, lir_patch_none); 1332 }