1 /* 2 * Copyright (c) 2000, 2023, 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 "c1/c1_CodeStubs.hpp" 27 #include "c1/c1_InstructionPrinter.hpp" 28 #include "c1/c1_LIR.hpp" 29 #include "c1/c1_LIRAssembler.hpp" 30 #include "c1/c1_ValueStack.hpp" 31 #include "ci/ciInlineKlass.hpp" 32 #include "ci/ciInstance.hpp" 33 #include "runtime/safepointMechanism.inline.hpp" 34 #include "runtime/sharedRuntime.hpp" 35 #include "runtime/vm_version.hpp" 36 37 Register LIR_Opr::as_register() const { 38 return FrameMap::cpu_rnr2reg(cpu_regnr()); 39 } 40 41 Register LIR_Opr::as_register_lo() const { 42 return FrameMap::cpu_rnr2reg(cpu_regnrLo()); 43 } 44 45 Register LIR_Opr::as_register_hi() const { 46 return FrameMap::cpu_rnr2reg(cpu_regnrHi()); 47 } 48 49 LIR_Opr LIR_OprFact::illegalOpr = LIR_OprFact::illegal(); 50 LIR_Opr LIR_OprFact::nullOpr = LIR_Opr(); 51 52 LIR_Opr LIR_OprFact::value_type(ValueType* type) { 53 ValueTag tag = type->tag(); 54 switch (tag) { 55 case metaDataTag : { 56 ClassConstant* c = type->as_ClassConstant(); 57 if (c != nullptr && !c->value()->is_loaded()) { 58 return LIR_OprFact::metadataConst(nullptr); 59 } else if (c != nullptr) { 60 return LIR_OprFact::metadataConst(c->value()->constant_encoding()); 61 } else { 62 MethodConstant* m = type->as_MethodConstant(); 63 assert (m != nullptr, "not a class or a method?"); 64 return LIR_OprFact::metadataConst(m->value()->constant_encoding()); 65 } 66 } 67 case objectTag : { 68 return LIR_OprFact::oopConst(type->as_ObjectType()->encoding()); 69 } 70 case addressTag: return LIR_OprFact::addressConst(type->as_AddressConstant()->value()); 71 case intTag : return LIR_OprFact::intConst(type->as_IntConstant()->value()); 72 case floatTag : return LIR_OprFact::floatConst(type->as_FloatConstant()->value()); 73 case longTag : return LIR_OprFact::longConst(type->as_LongConstant()->value()); 74 case doubleTag : return LIR_OprFact::doubleConst(type->as_DoubleConstant()->value()); 75 default: ShouldNotReachHere(); return LIR_OprFact::intConst(-1); 76 } 77 } 78 79 80 //--------------------------------------------------- 81 82 83 LIR_Address::Scale LIR_Address::scale(BasicType type) { 84 int elem_size = type2aelembytes(type); 85 switch (elem_size) { 86 case 1: return LIR_Address::times_1; 87 case 2: return LIR_Address::times_2; 88 case 4: return LIR_Address::times_4; 89 case 8: return LIR_Address::times_8; 90 } 91 ShouldNotReachHere(); 92 return LIR_Address::times_1; 93 } 94 95 //--------------------------------------------------- 96 97 char LIR_Opr::type_char(BasicType t) { 98 switch (t) { 99 case T_ARRAY: 100 t = T_OBJECT; 101 case T_BOOLEAN: 102 case T_CHAR: 103 case T_FLOAT: 104 case T_DOUBLE: 105 case T_BYTE: 106 case T_SHORT: 107 case T_INT: 108 case T_LONG: 109 case T_OBJECT: 110 case T_ADDRESS: 111 case T_VOID: 112 return ::type2char(t); 113 case T_METADATA: 114 return 'M'; 115 case T_ILLEGAL: 116 return '?'; 117 118 default: 119 ShouldNotReachHere(); 120 return '?'; 121 } 122 } 123 124 #ifndef PRODUCT 125 void LIR_Opr::validate_type() const { 126 127 #ifdef ASSERT 128 if (!is_pointer() && !is_illegal()) { 129 OprKind kindfield = kind_field(); // Factored out because of compiler bug, see 8002160 130 switch (as_BasicType(type_field())) { 131 case T_LONG: 132 assert((kindfield == cpu_register || kindfield == stack_value) && 133 size_field() == double_size, "must match"); 134 break; 135 case T_FLOAT: 136 // FP return values can be also in CPU registers on ARM (softfp ABI) 137 assert((kindfield == fpu_register || kindfield == stack_value 138 ARM_ONLY(|| kindfield == cpu_register) ) && 139 size_field() == single_size, "must match"); 140 break; 141 case T_DOUBLE: 142 // FP return values can be also in CPU registers on ARM (softfp ABI) 143 assert((kindfield == fpu_register || kindfield == stack_value 144 ARM_ONLY(|| kindfield == cpu_register) ) && 145 size_field() == double_size, "must match"); 146 break; 147 case T_BOOLEAN: 148 case T_CHAR: 149 case T_BYTE: 150 case T_SHORT: 151 case T_INT: 152 case T_ADDRESS: 153 case T_OBJECT: 154 case T_METADATA: 155 case T_ARRAY: 156 assert((kindfield == cpu_register || kindfield == stack_value) && 157 size_field() == single_size, "must match"); 158 break; 159 160 case T_ILLEGAL: 161 // XXX TKR also means unknown right now 162 // assert(is_illegal(), "must match"); 163 break; 164 165 default: 166 ShouldNotReachHere(); 167 } 168 } 169 #endif 170 171 } 172 #endif // PRODUCT 173 174 175 bool LIR_Opr::is_oop() const { 176 if (is_pointer()) { 177 return pointer()->is_oop_pointer(); 178 } else { 179 OprType t= type_field(); 180 assert(t != unknown_type, "not set"); 181 return t == object_type; 182 } 183 } 184 185 186 187 void LIR_Op2::verify() const { 188 #ifdef ASSERT 189 switch (code()) { 190 case lir_xchg: 191 break; 192 193 default: 194 assert(!result_opr()->is_register() || !result_opr()->is_oop_register(), 195 "can't produce oops from arith"); 196 } 197 198 if (two_operand_lir_form) { 199 200 #ifdef ASSERT 201 bool threeOperandForm = false; 202 #ifdef S390 203 // There are 3 operand shifts on S390 (see LIR_Assembler::shift_op()). 204 threeOperandForm = 205 code() == lir_shl || 206 ((code() == lir_shr || code() == lir_ushr) && (result_opr()->is_double_cpu() || in_opr1()->type() == T_OBJECT)); 207 #endif 208 #endif 209 210 switch (code()) { 211 case lir_add: 212 case lir_sub: 213 case lir_mul: 214 case lir_div: 215 case lir_rem: 216 case lir_logic_and: 217 case lir_logic_or: 218 case lir_logic_xor: 219 case lir_shl: 220 case lir_shr: 221 assert(in_opr1() == result_opr() || threeOperandForm, "opr1 and result must match"); 222 assert(in_opr1()->is_valid() && in_opr2()->is_valid(), "must be valid"); 223 break; 224 225 // special handling for lir_ushr because of write barriers 226 case lir_ushr: 227 assert(in_opr1() == result_opr() || in_opr2()->is_constant() || threeOperandForm, "opr1 and result must match or shift count is constant"); 228 assert(in_opr1()->is_valid() && in_opr2()->is_valid(), "must be valid"); 229 break; 230 231 default: 232 break; 233 } 234 } 235 #endif 236 } 237 238 239 LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, BlockBegin* block) 240 : LIR_Op2(lir_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*)nullptr) 241 , _label(block->label()) 242 , _block(block) 243 , _ublock(nullptr) 244 , _stub(nullptr) { 245 } 246 247 LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, CodeStub* stub) : 248 LIR_Op2(lir_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*)nullptr) 249 , _label(stub->entry()) 250 , _block(nullptr) 251 , _ublock(nullptr) 252 , _stub(stub) { 253 } 254 255 LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, BlockBegin* block, BlockBegin* ublock) 256 : LIR_Op2(lir_cond_float_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*)nullptr) 257 , _label(block->label()) 258 , _block(block) 259 , _ublock(ublock) 260 , _stub(nullptr) 261 { 262 } 263 264 void LIR_OpBranch::change_block(BlockBegin* b) { 265 assert(_block != nullptr, "must have old block"); 266 assert(_block->label() == label(), "must be equal"); 267 268 _block = b; 269 _label = b->label(); 270 } 271 272 void LIR_OpBranch::change_ublock(BlockBegin* b) { 273 assert(_ublock != nullptr, "must have old block"); 274 _ublock = b; 275 } 276 277 void LIR_OpBranch::negate_cond() { 278 switch (cond()) { 279 case lir_cond_equal: set_cond(lir_cond_notEqual); break; 280 case lir_cond_notEqual: set_cond(lir_cond_equal); break; 281 case lir_cond_less: set_cond(lir_cond_greaterEqual); break; 282 case lir_cond_lessEqual: set_cond(lir_cond_greater); break; 283 case lir_cond_greaterEqual: set_cond(lir_cond_less); break; 284 case lir_cond_greater: set_cond(lir_cond_lessEqual); break; 285 default: ShouldNotReachHere(); 286 } 287 } 288 289 290 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass, 291 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, 292 bool fast_check, CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, 293 CodeStub* stub, bool need_null_check) 294 295 : LIR_Op(code, result, nullptr) 296 , _object(object) 297 , _array(LIR_OprFact::illegalOpr) 298 , _klass(klass) 299 , _tmp1(tmp1) 300 , _tmp2(tmp2) 301 , _tmp3(tmp3) 302 , _fast_check(fast_check) 303 , _info_for_patch(info_for_patch) 304 , _info_for_exception(info_for_exception) 305 , _stub(stub) 306 , _profiled_method(nullptr) 307 , _profiled_bci(-1) 308 , _should_profile(false) 309 , _need_null_check(need_null_check) 310 { 311 if (code == lir_checkcast) { 312 assert(info_for_exception != nullptr, "checkcast throws exceptions"); 313 } else if (code == lir_instanceof) { 314 assert(info_for_exception == nullptr, "instanceof throws no exceptions"); 315 } else { 316 ShouldNotReachHere(); 317 } 318 } 319 320 321 322 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception) 323 : LIR_Op(code, LIR_OprFact::illegalOpr, nullptr) 324 , _object(object) 325 , _array(array) 326 , _klass(nullptr) 327 , _tmp1(tmp1) 328 , _tmp2(tmp2) 329 , _tmp3(tmp3) 330 , _fast_check(false) 331 , _info_for_patch(nullptr) 332 , _info_for_exception(info_for_exception) 333 , _stub(nullptr) 334 , _profiled_method(nullptr) 335 , _profiled_bci(-1) 336 , _should_profile(false) 337 , _need_null_check(true) 338 { 339 if (code == lir_store_check) { 340 _stub = new ArrayStoreExceptionStub(object, info_for_exception); 341 assert(info_for_exception != nullptr, "store_check throws exceptions"); 342 } else { 343 ShouldNotReachHere(); 344 } 345 } 346 347 LIR_OpFlattenedArrayCheck::LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub) 348 : LIR_Op(lir_flat_array_check, LIR_OprFact::illegalOpr, nullptr) 349 , _array(array) 350 , _value(value) 351 , _tmp(tmp) 352 , _stub(stub) {} 353 354 355 LIR_OpNullFreeArrayCheck::LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp) 356 : LIR_Op(lir_null_free_array_check, LIR_OprFact::illegalOpr, nullptr) 357 , _array(array) 358 , _tmp(tmp) {} 359 360 361 LIR_OpSubstitutabilityCheck::LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result, 362 LIR_Opr tmp1, LIR_Opr tmp2, 363 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op, 364 CodeEmitInfo* info, CodeStub* stub) 365 : LIR_Op(lir_substitutability_check, result, info) 366 , _left(left) 367 , _right(right) 368 , _equal_result(equal_result) 369 , _not_equal_result(not_equal_result) 370 , _tmp1(tmp1) 371 , _tmp2(tmp2) 372 , _left_klass(left_klass) 373 , _right_klass(right_klass) 374 , _left_klass_op(left_klass_op) 375 , _right_klass_op(right_klass_op) 376 , _stub(stub) {} 377 378 379 LIR_OpArrayCopy::LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, 380 LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info) 381 : LIR_Op(lir_arraycopy, LIR_OprFact::illegalOpr, info) 382 , _src(src) 383 , _src_pos(src_pos) 384 , _dst(dst) 385 , _dst_pos(dst_pos) 386 , _length(length) 387 , _tmp(tmp) 388 , _expected_type(expected_type) 389 , _flags(flags) { 390 _stub = new ArrayCopyStub(this); 391 } 392 393 LIR_OpUpdateCRC32::LIR_OpUpdateCRC32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) 394 : LIR_Op(lir_updatecrc32, res, nullptr) 395 , _crc(crc) 396 , _val(val) { 397 } 398 399 //-------------------verify-------------------------- 400 401 void LIR_Op1::verify() const { 402 switch(code()) { 403 case lir_move: 404 assert(in_opr()->is_valid() && result_opr()->is_valid(), "must be"); 405 break; 406 case lir_null_check: 407 assert(in_opr()->is_register(), "must be"); 408 break; 409 case lir_return: 410 assert(in_opr()->is_register() || in_opr()->is_illegal(), "must be"); 411 break; 412 default: 413 break; 414 } 415 } 416 417 void LIR_OpRTCall::verify() const { 418 assert(strcmp(Runtime1::name_for_address(addr()), "<unknown function>") != 0, "unknown function"); 419 } 420 421 //-------------------visits-------------------------- 422 423 // complete rework of LIR instruction visitor. 424 // The virtual call for each instruction type is replaced by a big 425 // switch that adds the operands for each instruction 426 427 void LIR_OpVisitState::visit(LIR_Op* op) { 428 // copy information from the LIR_Op 429 reset(); 430 set_op(op); 431 432 switch (op->code()) { 433 434 // LIR_Op0 435 case lir_fpop_raw: // result and info always invalid 436 case lir_breakpoint: // result and info always invalid 437 case lir_membar: // result and info always invalid 438 case lir_membar_acquire: // result and info always invalid 439 case lir_membar_release: // result and info always invalid 440 case lir_membar_loadload: // result and info always invalid 441 case lir_membar_storestore: // result and info always invalid 442 case lir_membar_loadstore: // result and info always invalid 443 case lir_membar_storeload: // result and info always invalid 444 case lir_check_orig_pc: // result and info always invalid 445 case lir_on_spin_wait: 446 { 447 assert(op->as_Op0() != nullptr, "must be"); 448 assert(op->_info == nullptr, "info not used by this instruction"); 449 assert(op->_result->is_illegal(), "not used"); 450 break; 451 } 452 453 case lir_nop: // may have info, result always invalid 454 case lir_std_entry: // may have result, info always invalid 455 case lir_osr_entry: // may have result, info always invalid 456 case lir_get_thread: // may have result, info always invalid 457 { 458 assert(op->as_Op0() != nullptr, "must be"); 459 if (op->_info != nullptr) do_info(op->_info); 460 if (op->_result->is_valid()) do_output(op->_result); 461 break; 462 } 463 464 465 // LIR_OpLabel 466 case lir_label: // result and info always invalid 467 { 468 assert(op->as_OpLabel() != nullptr, "must be"); 469 assert(op->_info == nullptr, "info not used by this instruction"); 470 assert(op->_result->is_illegal(), "not used"); 471 break; 472 } 473 474 475 // LIR_Op1 476 case lir_fxch: // input always valid, result and info always invalid 477 case lir_fld: // input always valid, result and info always invalid 478 case lir_push: // input always valid, result and info always invalid 479 case lir_pop: // input always valid, result and info always invalid 480 case lir_leal: // input and result always valid, info always invalid 481 case lir_monaddr: // input and result always valid, info always invalid 482 case lir_null_check: // input and info always valid, result always invalid 483 case lir_move: // input and result always valid, may have info 484 { 485 assert(op->as_Op1() != nullptr, "must be"); 486 LIR_Op1* op1 = (LIR_Op1*)op; 487 488 if (op1->_info) do_info(op1->_info); 489 if (op1->_opr->is_valid()) do_input(op1->_opr); 490 if (op1->_result->is_valid()) do_output(op1->_result); 491 492 break; 493 } 494 495 case lir_return: 496 { 497 assert(op->as_OpReturn() != nullptr, "must be"); 498 LIR_OpReturn* op_ret = (LIR_OpReturn*)op; 499 500 if (op_ret->_info) do_info(op_ret->_info); 501 if (op_ret->_opr->is_valid()) do_input(op_ret->_opr); 502 if (op_ret->_result->is_valid()) do_output(op_ret->_result); 503 if (op_ret->stub() != nullptr) do_stub(op_ret->stub()); 504 505 break; 506 } 507 508 case lir_safepoint: 509 { 510 assert(op->as_Op1() != nullptr, "must be"); 511 LIR_Op1* op1 = (LIR_Op1*)op; 512 513 assert(op1->_info != nullptr, ""); do_info(op1->_info); 514 if (op1->_opr->is_valid()) do_temp(op1->_opr); // safepoints on SPARC need temporary register 515 assert(op1->_result->is_illegal(), "safepoint does not produce value"); 516 517 break; 518 } 519 520 // LIR_OpConvert; 521 case lir_convert: // input and result always valid, info always invalid 522 { 523 assert(op->as_OpConvert() != nullptr, "must be"); 524 LIR_OpConvert* opConvert = (LIR_OpConvert*)op; 525 526 assert(opConvert->_info == nullptr, "must be"); 527 if (opConvert->_opr->is_valid()) do_input(opConvert->_opr); 528 if (opConvert->_result->is_valid()) do_output(opConvert->_result); 529 do_stub(opConvert->_stub); 530 531 break; 532 } 533 534 // LIR_OpBranch; 535 case lir_branch: // may have info, input and result register always invalid 536 case lir_cond_float_branch: // may have info, input and result register always invalid 537 { 538 assert(op->as_OpBranch() != nullptr, "must be"); 539 LIR_OpBranch* opBranch = (LIR_OpBranch*)op; 540 541 assert(opBranch->_tmp1->is_illegal() && opBranch->_tmp2->is_illegal() && 542 opBranch->_tmp3->is_illegal() && opBranch->_tmp4->is_illegal() && 543 opBranch->_tmp5->is_illegal(), "not used"); 544 545 if (opBranch->_opr1->is_valid()) do_input(opBranch->_opr1); 546 if (opBranch->_opr2->is_valid()) do_input(opBranch->_opr2); 547 548 if (opBranch->_info != nullptr) do_info(opBranch->_info); 549 assert(opBranch->_result->is_illegal(), "not used"); 550 if (opBranch->_stub != nullptr) opBranch->stub()->visit(this); 551 552 break; 553 } 554 555 556 // LIR_OpAllocObj 557 case lir_alloc_object: 558 { 559 assert(op->as_OpAllocObj() != nullptr, "must be"); 560 LIR_OpAllocObj* opAllocObj = (LIR_OpAllocObj*)op; 561 562 if (opAllocObj->_info) do_info(opAllocObj->_info); 563 if (opAllocObj->_opr->is_valid()) { do_input(opAllocObj->_opr); 564 do_temp(opAllocObj->_opr); 565 } 566 if (opAllocObj->_tmp1->is_valid()) do_temp(opAllocObj->_tmp1); 567 if (opAllocObj->_tmp2->is_valid()) do_temp(opAllocObj->_tmp2); 568 if (opAllocObj->_tmp3->is_valid()) do_temp(opAllocObj->_tmp3); 569 if (opAllocObj->_tmp4->is_valid()) do_temp(opAllocObj->_tmp4); 570 if (opAllocObj->_result->is_valid()) do_output(opAllocObj->_result); 571 if (opAllocObj->_stub != nullptr) do_stub(opAllocObj->_stub); 572 break; 573 } 574 575 576 // LIR_OpRoundFP; 577 case lir_roundfp: { 578 assert(op->as_OpRoundFP() != nullptr, "must be"); 579 LIR_OpRoundFP* opRoundFP = (LIR_OpRoundFP*)op; 580 581 assert(op->_info == nullptr, "info not used by this instruction"); 582 assert(opRoundFP->_tmp->is_illegal(), "not used"); 583 do_input(opRoundFP->_opr); 584 do_output(opRoundFP->_result); 585 586 break; 587 } 588 589 590 // LIR_Op2 591 case lir_cmp: 592 case lir_cmp_l2i: 593 case lir_ucmp_fd2i: 594 case lir_cmp_fd2i: 595 case lir_add: 596 case lir_sub: 597 case lir_rem: 598 case lir_sqrt: 599 case lir_abs: 600 case lir_neg: 601 case lir_f2hf: 602 case lir_hf2f: 603 case lir_logic_and: 604 case lir_logic_or: 605 case lir_logic_xor: 606 case lir_shl: 607 case lir_shr: 608 case lir_ushr: 609 case lir_xadd: 610 case lir_xchg: 611 case lir_assert: 612 { 613 assert(op->as_Op2() != nullptr, "must be"); 614 LIR_Op2* op2 = (LIR_Op2*)op; 615 assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() && 616 op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used"); 617 618 if (op2->_info) do_info(op2->_info); 619 if (op2->_opr1->is_valid()) do_input(op2->_opr1); 620 if (op2->_opr2->is_valid()) do_input(op2->_opr2); 621 if (op2->_tmp1->is_valid()) do_temp(op2->_tmp1); 622 if (op2->_result->is_valid()) do_output(op2->_result); 623 if (op->code() == lir_xchg || op->code() == lir_xadd) { 624 // on ARM and PPC, return value is loaded first so could 625 // destroy inputs. On other platforms that implement those 626 // (x86, sparc), the extra constrainsts are harmless. 627 if (op2->_opr1->is_valid()) do_temp(op2->_opr1); 628 if (op2->_opr2->is_valid()) do_temp(op2->_opr2); 629 } 630 631 break; 632 } 633 634 // special handling for cmove: right input operand must not be equal 635 // to the result operand, otherwise the backend fails 636 case lir_cmove: 637 { 638 assert(op->as_Op4() != nullptr, "must be"); 639 LIR_Op4* op4 = (LIR_Op4*)op; 640 641 assert(op4->_info == nullptr && op4->_tmp1->is_illegal() && op4->_tmp2->is_illegal() && 642 op4->_tmp3->is_illegal() && op4->_tmp4->is_illegal() && op4->_tmp5->is_illegal(), "not used"); 643 assert(op4->_opr1->is_valid() && op4->_opr2->is_valid() && op4->_result->is_valid(), "used"); 644 645 do_input(op4->_opr1); 646 do_input(op4->_opr2); 647 if (op4->_opr3->is_valid()) do_input(op4->_opr3); 648 if (op4->_opr4->is_valid()) do_input(op4->_opr4); 649 do_temp(op4->_opr2); 650 do_output(op4->_result); 651 652 break; 653 } 654 655 // vspecial handling for strict operations: register input operands 656 // as temp to guarantee that they do not overlap with other 657 // registers 658 case lir_mul: 659 case lir_div: 660 { 661 assert(op->as_Op2() != nullptr, "must be"); 662 LIR_Op2* op2 = (LIR_Op2*)op; 663 664 assert(op2->_info == nullptr, "not used"); 665 assert(op2->_opr1->is_valid(), "used"); 666 assert(op2->_opr2->is_valid(), "used"); 667 assert(op2->_result->is_valid(), "used"); 668 assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() && 669 op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used"); 670 671 do_input(op2->_opr1); do_temp(op2->_opr1); 672 do_input(op2->_opr2); do_temp(op2->_opr2); 673 if (op2->_tmp1->is_valid()) do_temp(op2->_tmp1); 674 do_output(op2->_result); 675 676 break; 677 } 678 679 case lir_throw: { 680 assert(op->as_Op2() != nullptr, "must be"); 681 LIR_Op2* op2 = (LIR_Op2*)op; 682 683 if (op2->_info) do_info(op2->_info); 684 if (op2->_opr1->is_valid()) do_temp(op2->_opr1); 685 if (op2->_opr2->is_valid()) do_input(op2->_opr2); // exception object is input parameter 686 assert(op2->_result->is_illegal(), "no result"); 687 assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() && 688 op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used"); 689 690 break; 691 } 692 693 case lir_unwind: { 694 assert(op->as_Op1() != nullptr, "must be"); 695 LIR_Op1* op1 = (LIR_Op1*)op; 696 697 assert(op1->_info == nullptr, "no info"); 698 assert(op1->_opr->is_valid(), "exception oop"); do_input(op1->_opr); 699 assert(op1->_result->is_illegal(), "no result"); 700 701 break; 702 } 703 704 // LIR_Op3 705 case lir_idiv: 706 case lir_irem: { 707 assert(op->as_Op3() != nullptr, "must be"); 708 LIR_Op3* op3= (LIR_Op3*)op; 709 710 if (op3->_info) do_info(op3->_info); 711 if (op3->_opr1->is_valid()) do_input(op3->_opr1); 712 713 // second operand is input and temp, so ensure that second operand 714 // and third operand get not the same register 715 if (op3->_opr2->is_valid()) do_input(op3->_opr2); 716 if (op3->_opr2->is_valid()) do_temp(op3->_opr2); 717 if (op3->_opr3->is_valid()) do_temp(op3->_opr3); 718 719 if (op3->_result->is_valid()) do_output(op3->_result); 720 721 break; 722 } 723 724 case lir_fmad: 725 case lir_fmaf: { 726 assert(op->as_Op3() != nullptr, "must be"); 727 LIR_Op3* op3= (LIR_Op3*)op; 728 assert(op3->_info == nullptr, "no info"); 729 do_input(op3->_opr1); 730 do_input(op3->_opr2); 731 do_input(op3->_opr3); 732 do_output(op3->_result); 733 break; 734 } 735 736 // LIR_OpJavaCall 737 case lir_static_call: 738 case lir_optvirtual_call: 739 case lir_icvirtual_call: 740 case lir_dynamic_call: { 741 LIR_OpJavaCall* opJavaCall = op->as_OpJavaCall(); 742 assert(opJavaCall != nullptr, "must be"); 743 744 if (opJavaCall->_receiver->is_valid()) do_input(opJavaCall->_receiver); 745 746 // only visit register parameters 747 int n = opJavaCall->_arguments->length(); 748 for (int i = opJavaCall->_receiver->is_valid() ? 1 : 0; i < n; i++) { 749 if (!opJavaCall->_arguments->at(i)->is_pointer()) { 750 do_input(*opJavaCall->_arguments->adr_at(i)); 751 } 752 } 753 754 if (opJavaCall->_info) do_info(opJavaCall->_info); 755 if (FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr && 756 opJavaCall->is_method_handle_invoke()) { 757 opJavaCall->_method_handle_invoke_SP_save_opr = FrameMap::method_handle_invoke_SP_save_opr(); 758 do_temp(opJavaCall->_method_handle_invoke_SP_save_opr); 759 } 760 do_call(); 761 if (opJavaCall->_result->is_valid()) do_output(opJavaCall->_result); 762 763 break; 764 } 765 766 767 // LIR_OpRTCall 768 case lir_rtcall: { 769 assert(op->as_OpRTCall() != nullptr, "must be"); 770 LIR_OpRTCall* opRTCall = (LIR_OpRTCall*)op; 771 772 // only visit register parameters 773 int n = opRTCall->_arguments->length(); 774 for (int i = 0; i < n; i++) { 775 if (!opRTCall->_arguments->at(i)->is_pointer()) { 776 do_input(*opRTCall->_arguments->adr_at(i)); 777 } 778 } 779 if (opRTCall->_info) do_info(opRTCall->_info); 780 if (opRTCall->_tmp->is_valid()) do_temp(opRTCall->_tmp); 781 do_call(); 782 if (opRTCall->_result->is_valid()) do_output(opRTCall->_result); 783 784 break; 785 } 786 787 788 // LIR_OpArrayCopy 789 case lir_arraycopy: { 790 assert(op->as_OpArrayCopy() != nullptr, "must be"); 791 LIR_OpArrayCopy* opArrayCopy = (LIR_OpArrayCopy*)op; 792 793 assert(opArrayCopy->_result->is_illegal(), "unused"); 794 assert(opArrayCopy->_src->is_valid(), "used"); do_input(opArrayCopy->_src); do_temp(opArrayCopy->_src); 795 assert(opArrayCopy->_src_pos->is_valid(), "used"); do_input(opArrayCopy->_src_pos); do_temp(opArrayCopy->_src_pos); 796 assert(opArrayCopy->_dst->is_valid(), "used"); do_input(opArrayCopy->_dst); do_temp(opArrayCopy->_dst); 797 assert(opArrayCopy->_dst_pos->is_valid(), "used"); do_input(opArrayCopy->_dst_pos); do_temp(opArrayCopy->_dst_pos); 798 assert(opArrayCopy->_length->is_valid(), "used"); do_input(opArrayCopy->_length); do_temp(opArrayCopy->_length); 799 assert(opArrayCopy->_tmp->is_valid(), "used"); do_temp(opArrayCopy->_tmp); 800 if (opArrayCopy->_info) do_info(opArrayCopy->_info); 801 802 // the implementation of arraycopy always has a call into the runtime 803 do_call(); 804 805 break; 806 } 807 808 809 // LIR_OpUpdateCRC32 810 case lir_updatecrc32: { 811 assert(op->as_OpUpdateCRC32() != nullptr, "must be"); 812 LIR_OpUpdateCRC32* opUp = (LIR_OpUpdateCRC32*)op; 813 814 assert(opUp->_crc->is_valid(), "used"); do_input(opUp->_crc); do_temp(opUp->_crc); 815 assert(opUp->_val->is_valid(), "used"); do_input(opUp->_val); do_temp(opUp->_val); 816 assert(opUp->_result->is_valid(), "used"); do_output(opUp->_result); 817 assert(opUp->_info == nullptr, "no info for LIR_OpUpdateCRC32"); 818 819 break; 820 } 821 822 823 // LIR_OpLock 824 case lir_lock: 825 case lir_unlock: { 826 assert(op->as_OpLock() != nullptr, "must be"); 827 LIR_OpLock* opLock = (LIR_OpLock*)op; 828 829 if (opLock->_info) do_info(opLock->_info); 830 831 // TODO: check if these operands really have to be temp 832 // (or if input is sufficient). This may have influence on the oop map! 833 assert(opLock->_lock->is_valid(), "used"); do_temp(opLock->_lock); 834 assert(opLock->_hdr->is_valid(), "used"); do_temp(opLock->_hdr); 835 assert(opLock->_obj->is_valid(), "used"); do_temp(opLock->_obj); 836 837 if (opLock->_scratch->is_valid()) do_temp(opLock->_scratch); 838 assert(opLock->_result->is_illegal(), "unused"); 839 840 do_stub(opLock->_stub); 841 do_stub(opLock->_throw_imse_stub); 842 843 break; 844 } 845 846 847 // LIR_OpDelay 848 case lir_delay_slot: { 849 assert(op->as_OpDelay() != nullptr, "must be"); 850 LIR_OpDelay* opDelay = (LIR_OpDelay*)op; 851 852 visit(opDelay->delay_op()); 853 break; 854 } 855 856 // LIR_OpTypeCheck 857 case lir_instanceof: 858 case lir_checkcast: 859 case lir_store_check: { 860 assert(op->as_OpTypeCheck() != nullptr, "must be"); 861 LIR_OpTypeCheck* opTypeCheck = (LIR_OpTypeCheck*)op; 862 863 if (opTypeCheck->_info_for_exception) do_info(opTypeCheck->_info_for_exception); 864 if (opTypeCheck->_info_for_patch) do_info(opTypeCheck->_info_for_patch); 865 if (opTypeCheck->_object->is_valid()) do_input(opTypeCheck->_object); 866 if (op->code() == lir_store_check && opTypeCheck->_object->is_valid()) { 867 do_temp(opTypeCheck->_object); 868 } 869 if (opTypeCheck->_array->is_valid()) do_input(opTypeCheck->_array); 870 if (opTypeCheck->_tmp1->is_valid()) do_temp(opTypeCheck->_tmp1); 871 if (opTypeCheck->_tmp2->is_valid()) do_temp(opTypeCheck->_tmp2); 872 if (opTypeCheck->_tmp3->is_valid()) do_temp(opTypeCheck->_tmp3); 873 if (opTypeCheck->_result->is_valid()) do_output(opTypeCheck->_result); 874 if (opTypeCheck->_stub != nullptr) do_stub(opTypeCheck->_stub); 875 break; 876 } 877 878 // LIR_OpFlattenedArrayCheck 879 case lir_flat_array_check: { 880 assert(op->as_OpFlattenedArrayCheck() != nullptr, "must be"); 881 LIR_OpFlattenedArrayCheck* opFlattenedArrayCheck = (LIR_OpFlattenedArrayCheck*)op; 882 883 if (opFlattenedArrayCheck->_array->is_valid()) do_input(opFlattenedArrayCheck->_array); 884 if (opFlattenedArrayCheck->_value->is_valid()) do_input(opFlattenedArrayCheck->_value); 885 if (opFlattenedArrayCheck->_tmp->is_valid()) do_temp(opFlattenedArrayCheck->_tmp); 886 887 do_stub(opFlattenedArrayCheck->_stub); 888 889 break; 890 } 891 892 // LIR_OpNullFreeArrayCheck 893 case lir_null_free_array_check: { 894 assert(op->as_OpNullFreeArrayCheck() != nullptr, "must be"); 895 LIR_OpNullFreeArrayCheck* opNullFreeArrayCheck = (LIR_OpNullFreeArrayCheck*)op; 896 897 if (opNullFreeArrayCheck->_array->is_valid()) do_input(opNullFreeArrayCheck->_array); 898 if (opNullFreeArrayCheck->_tmp->is_valid()) do_temp(opNullFreeArrayCheck->_tmp); 899 break; 900 } 901 902 // LIR_OpSubstitutabilityCheck 903 case lir_substitutability_check: { 904 assert(op->as_OpSubstitutabilityCheck() != nullptr, "must be"); 905 LIR_OpSubstitutabilityCheck* opSubstitutabilityCheck = (LIR_OpSubstitutabilityCheck*)op; 906 do_input(opSubstitutabilityCheck->_left); 907 do_temp (opSubstitutabilityCheck->_left); 908 do_input(opSubstitutabilityCheck->_right); 909 do_temp (opSubstitutabilityCheck->_right); 910 do_input(opSubstitutabilityCheck->_equal_result); 911 do_temp (opSubstitutabilityCheck->_equal_result); 912 do_input(opSubstitutabilityCheck->_not_equal_result); 913 do_temp (opSubstitutabilityCheck->_not_equal_result); 914 if (opSubstitutabilityCheck->_tmp1->is_valid()) do_temp(opSubstitutabilityCheck->_tmp1); 915 if (opSubstitutabilityCheck->_tmp2->is_valid()) do_temp(opSubstitutabilityCheck->_tmp2); 916 if (opSubstitutabilityCheck->_left_klass_op->is_valid()) do_temp(opSubstitutabilityCheck->_left_klass_op); 917 if (opSubstitutabilityCheck->_right_klass_op->is_valid()) do_temp(opSubstitutabilityCheck->_right_klass_op); 918 if (opSubstitutabilityCheck->_result->is_valid()) do_output(opSubstitutabilityCheck->_result); 919 920 do_info(opSubstitutabilityCheck->_info); 921 do_stub(opSubstitutabilityCheck->_stub); 922 break; 923 } 924 925 // LIR_OpCompareAndSwap 926 case lir_cas_long: 927 case lir_cas_obj: 928 case lir_cas_int: { 929 assert(op->as_OpCompareAndSwap() != nullptr, "must be"); 930 LIR_OpCompareAndSwap* opCmpAndSwap = (LIR_OpCompareAndSwap*)op; 931 932 if (opCmpAndSwap->_info) do_info(opCmpAndSwap->_info); 933 assert(opCmpAndSwap->_addr->is_valid(), "used"); do_input(opCmpAndSwap->_addr); 934 do_temp(opCmpAndSwap->_addr); 935 assert(opCmpAndSwap->_cmp_value->is_valid(), "used"); do_input(opCmpAndSwap->_cmp_value); 936 do_temp(opCmpAndSwap->_cmp_value); 937 assert(opCmpAndSwap->_new_value->is_valid(), "used"); do_input(opCmpAndSwap->_new_value); 938 do_temp(opCmpAndSwap->_new_value); 939 if (opCmpAndSwap->_tmp1->is_valid()) do_temp(opCmpAndSwap->_tmp1); 940 if (opCmpAndSwap->_tmp2->is_valid()) do_temp(opCmpAndSwap->_tmp2); 941 if (opCmpAndSwap->_result->is_valid()) do_output(opCmpAndSwap->_result); 942 943 break; 944 } 945 946 947 // LIR_OpAllocArray; 948 case lir_alloc_array: { 949 assert(op->as_OpAllocArray() != nullptr, "must be"); 950 LIR_OpAllocArray* opAllocArray = (LIR_OpAllocArray*)op; 951 952 if (opAllocArray->_info) do_info(opAllocArray->_info); 953 if (opAllocArray->_klass->is_valid()) { do_input(opAllocArray->_klass); 954 do_temp(opAllocArray->_klass); 955 } 956 if (opAllocArray->_len->is_valid()) { do_input(opAllocArray->_len); 957 do_temp(opAllocArray->_len); 958 } 959 if (opAllocArray->_tmp1->is_valid()) do_temp(opAllocArray->_tmp1); 960 if (opAllocArray->_tmp2->is_valid()) do_temp(opAllocArray->_tmp2); 961 if (opAllocArray->_tmp3->is_valid()) do_temp(opAllocArray->_tmp3); 962 if (opAllocArray->_tmp4->is_valid()) do_temp(opAllocArray->_tmp4); 963 if (opAllocArray->_result->is_valid()) do_output(opAllocArray->_result); 964 if (opAllocArray->_stub != nullptr) do_stub(opAllocArray->_stub); 965 break; 966 } 967 968 // LIR_OpLoadKlass 969 case lir_load_klass: 970 { 971 LIR_OpLoadKlass* opLoadKlass = op->as_OpLoadKlass(); 972 assert(opLoadKlass != nullptr, "must be"); 973 974 do_input(opLoadKlass->_obj); 975 do_output(opLoadKlass->_result); 976 if (opLoadKlass->_info) do_info(opLoadKlass->_info); 977 break; 978 } 979 980 981 // LIR_OpProfileCall: 982 case lir_profile_call: { 983 assert(op->as_OpProfileCall() != nullptr, "must be"); 984 LIR_OpProfileCall* opProfileCall = (LIR_OpProfileCall*)op; 985 986 if (opProfileCall->_recv->is_valid()) do_temp(opProfileCall->_recv); 987 assert(opProfileCall->_mdo->is_valid(), "used"); do_temp(opProfileCall->_mdo); 988 assert(opProfileCall->_tmp1->is_valid(), "used"); do_temp(opProfileCall->_tmp1); 989 break; 990 } 991 992 // LIR_OpProfileType: 993 case lir_profile_type: { 994 assert(op->as_OpProfileType() != nullptr, "must be"); 995 LIR_OpProfileType* opProfileType = (LIR_OpProfileType*)op; 996 997 do_input(opProfileType->_mdp); do_temp(opProfileType->_mdp); 998 do_input(opProfileType->_obj); 999 do_temp(opProfileType->_tmp); 1000 break; 1001 } 1002 1003 // LIR_OpProfileInlineType: 1004 case lir_profile_inline_type: { 1005 assert(op->as_OpProfileInlineType() != nullptr, "must be"); 1006 LIR_OpProfileInlineType* opProfileInlineType = (LIR_OpProfileInlineType*)op; 1007 1008 do_input(opProfileInlineType->_mdp); do_temp(opProfileInlineType->_mdp); 1009 do_input(opProfileInlineType->_obj); 1010 do_temp(opProfileInlineType->_tmp); 1011 break; 1012 } 1013 default: 1014 op->visit(this); 1015 } 1016 } 1017 1018 void LIR_Op::visit(LIR_OpVisitState* state) { 1019 ShouldNotReachHere(); 1020 } 1021 1022 void LIR_OpVisitState::do_stub(CodeStub* stub) { 1023 if (stub != nullptr) { 1024 stub->visit(this); 1025 } 1026 } 1027 1028 XHandlers* LIR_OpVisitState::all_xhandler() { 1029 XHandlers* result = nullptr; 1030 1031 int i; 1032 for (i = 0; i < info_count(); i++) { 1033 if (info_at(i)->exception_handlers() != nullptr) { 1034 result = info_at(i)->exception_handlers(); 1035 break; 1036 } 1037 } 1038 1039 #ifdef ASSERT 1040 for (i = 0; i < info_count(); i++) { 1041 assert(info_at(i)->exception_handlers() == nullptr || 1042 info_at(i)->exception_handlers() == result, 1043 "only one xhandler list allowed per LIR-operation"); 1044 } 1045 #endif 1046 1047 if (result != nullptr) { 1048 return result; 1049 } else { 1050 return new XHandlers(); 1051 } 1052 1053 return result; 1054 } 1055 1056 1057 #ifdef ASSERT 1058 bool LIR_OpVisitState::no_operands(LIR_Op* op) { 1059 visit(op); 1060 1061 return opr_count(inputMode) == 0 && 1062 opr_count(outputMode) == 0 && 1063 opr_count(tempMode) == 0 && 1064 info_count() == 0 && 1065 !has_call() && 1066 !has_slow_case(); 1067 } 1068 #endif 1069 1070 // LIR_OpReturn 1071 LIR_OpReturn::LIR_OpReturn(LIR_Opr opr) : 1072 LIR_Op1(lir_return, opr, (CodeEmitInfo*)nullptr /* info */), 1073 _stub(nullptr) { 1074 if (VM_Version::supports_stack_watermark_barrier()) { 1075 _stub = new C1SafepointPollStub(); 1076 } 1077 } 1078 1079 //--------------------------------------------------- 1080 1081 1082 void LIR_OpJavaCall::emit_code(LIR_Assembler* masm) { 1083 masm->emit_call(this); 1084 } 1085 1086 bool LIR_OpJavaCall::maybe_return_as_fields(ciInlineKlass** vk_ret) const { 1087 ciType* return_type = method()->return_type(); 1088 if (InlineTypeReturnedAsFields) { 1089 if (return_type->is_inlinetype()) { 1090 ciInlineKlass* vk = return_type->as_inline_klass(); 1091 if (vk->can_be_returned_as_fields()) { 1092 if (vk_ret != nullptr) { 1093 *vk_ret = vk; 1094 } 1095 return true; 1096 } 1097 } else if (return_type->is_instance_klass() && 1098 (method()->is_method_handle_intrinsic() || !return_type->is_loaded() || 1099 StressCallingConvention)) { 1100 // An inline type might be returned from the call but we don't know its type. 1101 // This can happen with method handle intrinsics or when the return type is 1102 // not loaded (method holder is not loaded or preload attribute is missing). 1103 // If an inline type is returned, we either get an oop to a buffer and nothing 1104 // needs to be done or one of the values being returned is the klass of the 1105 // inline type (RAX on x64, with LSB set to 1) and we need to allocate an inline 1106 // type instance of that type and initialize it with the fields values being 1107 // returned in other registers. 1108 return true; 1109 } 1110 } 1111 return false; 1112 } 1113 1114 void LIR_OpRTCall::emit_code(LIR_Assembler* masm) { 1115 masm->emit_rtcall(this); 1116 } 1117 1118 void LIR_OpLabel::emit_code(LIR_Assembler* masm) { 1119 masm->emit_opLabel(this); 1120 } 1121 1122 void LIR_OpArrayCopy::emit_code(LIR_Assembler* masm) { 1123 masm->emit_arraycopy(this); 1124 masm->append_code_stub(stub()); 1125 } 1126 1127 void LIR_OpUpdateCRC32::emit_code(LIR_Assembler* masm) { 1128 masm->emit_updatecrc32(this); 1129 } 1130 1131 void LIR_Op0::emit_code(LIR_Assembler* masm) { 1132 masm->emit_op0(this); 1133 } 1134 1135 void LIR_Op1::emit_code(LIR_Assembler* masm) { 1136 masm->emit_op1(this); 1137 } 1138 1139 void LIR_OpAllocObj::emit_code(LIR_Assembler* masm) { 1140 masm->emit_alloc_obj(this); 1141 masm->append_code_stub(stub()); 1142 } 1143 1144 void LIR_OpBranch::emit_code(LIR_Assembler* masm) { 1145 masm->emit_opBranch(this); 1146 if (stub()) { 1147 masm->append_code_stub(stub()); 1148 } 1149 } 1150 1151 void LIR_OpConvert::emit_code(LIR_Assembler* masm) { 1152 masm->emit_opConvert(this); 1153 if (stub() != nullptr) { 1154 masm->append_code_stub(stub()); 1155 } 1156 } 1157 1158 void LIR_Op2::emit_code(LIR_Assembler* masm) { 1159 masm->emit_op2(this); 1160 } 1161 1162 void LIR_OpAllocArray::emit_code(LIR_Assembler* masm) { 1163 masm->emit_alloc_array(this); 1164 masm->append_code_stub(stub()); 1165 } 1166 1167 void LIR_OpTypeCheck::emit_code(LIR_Assembler* masm) { 1168 masm->emit_opTypeCheck(this); 1169 if (stub()) { 1170 masm->append_code_stub(stub()); 1171 } 1172 } 1173 1174 void LIR_OpFlattenedArrayCheck::emit_code(LIR_Assembler* masm) { 1175 masm->emit_opFlattenedArrayCheck(this); 1176 if (stub() != nullptr) { 1177 masm->append_code_stub(stub()); 1178 } 1179 } 1180 1181 void LIR_OpNullFreeArrayCheck::emit_code(LIR_Assembler* masm) { 1182 masm->emit_opNullFreeArrayCheck(this); 1183 } 1184 1185 void LIR_OpSubstitutabilityCheck::emit_code(LIR_Assembler* masm) { 1186 masm->emit_opSubstitutabilityCheck(this); 1187 if (stub() != nullptr) { 1188 masm->append_code_stub(stub()); 1189 } 1190 } 1191 1192 void LIR_OpCompareAndSwap::emit_code(LIR_Assembler* masm) { 1193 masm->emit_compare_and_swap(this); 1194 } 1195 1196 void LIR_Op3::emit_code(LIR_Assembler* masm) { 1197 masm->emit_op3(this); 1198 } 1199 1200 void LIR_Op4::emit_code(LIR_Assembler* masm) { 1201 masm->emit_op4(this); 1202 } 1203 1204 void LIR_OpLock::emit_code(LIR_Assembler* masm) { 1205 masm->emit_lock(this); 1206 if (stub()) { 1207 masm->append_code_stub(stub()); 1208 } 1209 if (throw_imse_stub()) { 1210 masm->append_code_stub(throw_imse_stub()); 1211 } 1212 } 1213 1214 void LIR_OpLoadKlass::emit_code(LIR_Assembler* masm) { 1215 masm->emit_load_klass(this); 1216 } 1217 1218 #ifdef ASSERT 1219 void LIR_OpAssert::emit_code(LIR_Assembler* masm) { 1220 masm->emit_assert(this); 1221 } 1222 #endif 1223 1224 void LIR_OpDelay::emit_code(LIR_Assembler* masm) { 1225 masm->emit_delay(this); 1226 } 1227 1228 void LIR_OpProfileCall::emit_code(LIR_Assembler* masm) { 1229 masm->emit_profile_call(this); 1230 } 1231 1232 void LIR_OpProfileType::emit_code(LIR_Assembler* masm) { 1233 masm->emit_profile_type(this); 1234 } 1235 1236 void LIR_OpProfileInlineType::emit_code(LIR_Assembler* masm) { 1237 masm->emit_profile_inline_type(this); 1238 } 1239 1240 // LIR_List 1241 LIR_List::LIR_List(Compilation* compilation, BlockBegin* block) 1242 : _operations(8) 1243 , _compilation(compilation) 1244 #ifndef PRODUCT 1245 , _block(block) 1246 #endif 1247 #ifdef ASSERT 1248 , _file(nullptr) 1249 , _line(0) 1250 #endif 1251 #ifdef RISCV 1252 , _cmp_opr1(LIR_OprFact::illegalOpr) 1253 , _cmp_opr2(LIR_OprFact::illegalOpr) 1254 #endif 1255 { } 1256 1257 1258 #ifdef ASSERT 1259 void LIR_List::set_file_and_line(const char * file, int line) { 1260 const char * f = strrchr(file, '/'); 1261 if (f == nullptr) f = strrchr(file, '\\'); 1262 if (f == nullptr) { 1263 f = file; 1264 } else { 1265 f++; 1266 } 1267 _file = f; 1268 _line = line; 1269 } 1270 #endif 1271 1272 #ifdef RISCV 1273 void LIR_List::set_cmp_oprs(LIR_Op* op) { 1274 switch (op->code()) { 1275 case lir_cmp: 1276 _cmp_opr1 = op->as_Op2()->in_opr1(); 1277 _cmp_opr2 = op->as_Op2()->in_opr2(); 1278 break; 1279 case lir_branch: // fall through 1280 case lir_cond_float_branch: 1281 assert(op->as_OpBranch()->cond() == lir_cond_always || 1282 (_cmp_opr1 != LIR_OprFact::illegalOpr && _cmp_opr2 != LIR_OprFact::illegalOpr), 1283 "conditional branches must have legal operands"); 1284 if (op->as_OpBranch()->cond() != lir_cond_always) { 1285 op->as_Op2()->set_in_opr1(_cmp_opr1); 1286 op->as_Op2()->set_in_opr2(_cmp_opr2); 1287 } 1288 break; 1289 case lir_cmove: 1290 op->as_Op4()->set_in_opr3(_cmp_opr1); 1291 op->as_Op4()->set_in_opr4(_cmp_opr2); 1292 break; 1293 case lir_cas_long: 1294 case lir_cas_obj: 1295 case lir_cas_int: 1296 _cmp_opr1 = op->as_OpCompareAndSwap()->result_opr(); 1297 _cmp_opr2 = LIR_OprFact::intConst(0); 1298 break; 1299 #if INCLUDE_ZGC 1300 case lir_xloadbarrier_test: 1301 _cmp_opr1 = FrameMap::as_opr(t1); 1302 _cmp_opr2 = LIR_OprFact::intConst(0); 1303 break; 1304 #endif 1305 default: 1306 break; 1307 } 1308 } 1309 #endif 1310 1311 void LIR_List::append(LIR_InsertionBuffer* buffer) { 1312 assert(this == buffer->lir_list(), "wrong lir list"); 1313 const int n = _operations.length(); 1314 1315 if (buffer->number_of_ops() > 0) { 1316 // increase size of instructions list 1317 _operations.at_grow(n + buffer->number_of_ops() - 1, nullptr); 1318 // insert ops from buffer into instructions list 1319 int op_index = buffer->number_of_ops() - 1; 1320 int ip_index = buffer->number_of_insertion_points() - 1; 1321 int from_index = n - 1; 1322 int to_index = _operations.length() - 1; 1323 for (; ip_index >= 0; ip_index --) { 1324 int index = buffer->index_at(ip_index); 1325 // make room after insertion point 1326 while (index < from_index) { 1327 _operations.at_put(to_index --, _operations.at(from_index --)); 1328 } 1329 // insert ops from buffer 1330 for (int i = buffer->count_at(ip_index); i > 0; i --) { 1331 _operations.at_put(to_index --, buffer->op_at(op_index --)); 1332 } 1333 } 1334 } 1335 1336 buffer->finish(); 1337 } 1338 1339 1340 void LIR_List::oop2reg_patch(jobject o, LIR_Opr reg, CodeEmitInfo* info) { 1341 assert(reg->type() == T_OBJECT, "bad reg"); 1342 append(new LIR_Op1(lir_move, LIR_OprFact::oopConst(o), reg, T_OBJECT, lir_patch_normal, info)); 1343 } 1344 1345 void LIR_List::klass2reg_patch(Metadata* o, LIR_Opr reg, CodeEmitInfo* info) { 1346 assert(reg->type() == T_METADATA, "bad reg"); 1347 append(new LIR_Op1(lir_move, LIR_OprFact::metadataConst(o), reg, T_METADATA, lir_patch_normal, info)); 1348 } 1349 1350 void LIR_List::load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1351 append(new LIR_Op1( 1352 lir_move, 1353 LIR_OprFact::address(addr), 1354 src, 1355 addr->type(), 1356 patch_code, 1357 info)); 1358 } 1359 1360 1361 void LIR_List::volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1362 append(new LIR_Op1( 1363 lir_move, 1364 LIR_OprFact::address(address), 1365 dst, 1366 address->type(), 1367 patch_code, 1368 info, lir_move_volatile)); 1369 } 1370 1371 void LIR_List::volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1372 append(new LIR_Op1( 1373 lir_move, 1374 LIR_OprFact::address(new LIR_Address(base, offset, type)), 1375 dst, 1376 type, 1377 patch_code, 1378 info, lir_move_volatile)); 1379 } 1380 1381 1382 void LIR_List::store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1383 append(new LIR_Op1( 1384 lir_move, 1385 LIR_OprFact::intConst(v), 1386 LIR_OprFact::address(new LIR_Address(base, offset_in_bytes, type)), 1387 type, 1388 patch_code, 1389 info)); 1390 } 1391 1392 1393 void LIR_List::store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1394 append(new LIR_Op1( 1395 lir_move, 1396 LIR_OprFact::oopConst(o), 1397 LIR_OprFact::address(new LIR_Address(base, offset_in_bytes, type)), 1398 type, 1399 patch_code, 1400 info)); 1401 } 1402 1403 1404 void LIR_List::store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1405 append(new LIR_Op1( 1406 lir_move, 1407 src, 1408 LIR_OprFact::address(addr), 1409 addr->type(), 1410 patch_code, 1411 info)); 1412 } 1413 1414 1415 void LIR_List::volatile_store_mem_reg(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1416 append(new LIR_Op1( 1417 lir_move, 1418 src, 1419 LIR_OprFact::address(addr), 1420 addr->type(), 1421 patch_code, 1422 info, 1423 lir_move_volatile)); 1424 } 1425 1426 void LIR_List::volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1427 append(new LIR_Op1( 1428 lir_move, 1429 src, 1430 LIR_OprFact::address(new LIR_Address(base, offset, type)), 1431 type, 1432 patch_code, 1433 info, lir_move_volatile)); 1434 } 1435 1436 1437 void LIR_List::idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) { 1438 append(new LIR_Op3( 1439 lir_idiv, 1440 left, 1441 right, 1442 tmp, 1443 res, 1444 info)); 1445 } 1446 1447 1448 void LIR_List::idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) { 1449 append(new LIR_Op3( 1450 lir_idiv, 1451 left, 1452 LIR_OprFact::intConst(right), 1453 tmp, 1454 res, 1455 info)); 1456 } 1457 1458 1459 void LIR_List::irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) { 1460 append(new LIR_Op3( 1461 lir_irem, 1462 left, 1463 right, 1464 tmp, 1465 res, 1466 info)); 1467 } 1468 1469 1470 void LIR_List::irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) { 1471 append(new LIR_Op3( 1472 lir_irem, 1473 left, 1474 LIR_OprFact::intConst(right), 1475 tmp, 1476 res, 1477 info)); 1478 } 1479 1480 1481 void LIR_List::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) { 1482 append(new LIR_Op2( 1483 lir_cmp, 1484 condition, 1485 LIR_OprFact::address(new LIR_Address(base, disp, T_INT)), 1486 LIR_OprFact::intConst(c), 1487 info)); 1488 } 1489 1490 1491 void LIR_List::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Address* addr, CodeEmitInfo* info) { 1492 append(new LIR_Op2( 1493 lir_cmp, 1494 condition, 1495 reg, 1496 LIR_OprFact::address(addr), 1497 info)); 1498 } 1499 1500 void LIR_List::allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, 1501 int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub) { 1502 append(new LIR_OpAllocObj( 1503 klass, 1504 dst, 1505 t1, 1506 t2, 1507 t3, 1508 t4, 1509 header_size, 1510 object_size, 1511 init_check, 1512 stub)); 1513 } 1514 1515 void LIR_List::allocate_array(LIR_Opr dst, LIR_Opr len, LIR_Opr t1,LIR_Opr t2, LIR_Opr t3,LIR_Opr t4, BasicType type, LIR_Opr klass, CodeStub* stub, bool is_null_free) { 1516 append(new LIR_OpAllocArray( 1517 klass, 1518 len, 1519 dst, 1520 t1, 1521 t2, 1522 t3, 1523 t4, 1524 type, 1525 stub, 1526 is_null_free)); 1527 } 1528 1529 void LIR_List::shift_left(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) { 1530 append(new LIR_Op2( 1531 lir_shl, 1532 value, 1533 count, 1534 dst, 1535 tmp)); 1536 } 1537 1538 void LIR_List::shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) { 1539 append(new LIR_Op2( 1540 lir_shr, 1541 value, 1542 count, 1543 dst, 1544 tmp)); 1545 } 1546 1547 1548 void LIR_List::unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) { 1549 append(new LIR_Op2( 1550 lir_ushr, 1551 value, 1552 count, 1553 dst, 1554 tmp)); 1555 } 1556 1557 void LIR_List::fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less) { 1558 append(new LIR_Op2(is_unordered_less ? lir_ucmp_fd2i : lir_cmp_fd2i, 1559 left, 1560 right, 1561 dst)); 1562 } 1563 1564 void LIR_List::lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_imse_stub) { 1565 append(new LIR_OpLock( 1566 lir_lock, 1567 hdr, 1568 obj, 1569 lock, 1570 scratch, 1571 stub, 1572 info, 1573 throw_imse_stub)); 1574 } 1575 1576 void LIR_List::unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub) { 1577 append(new LIR_OpLock( 1578 lir_unlock, 1579 hdr, 1580 obj, 1581 lock, 1582 scratch, 1583 stub, 1584 nullptr)); 1585 } 1586 1587 1588 void check_LIR() { 1589 // cannot do the proper checking as PRODUCT and other modes return different results 1590 // guarantee(sizeof(LIR_Opr) == wordSize, "may not have a v-table"); 1591 } 1592 1593 1594 1595 void LIR_List::checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass, 1596 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, 1597 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub, 1598 ciMethod* profiled_method, int profiled_bci, bool is_null_free) { 1599 // If klass is non-nullable, LIRGenerator::do_CheckCast has already performed null-check 1600 // on the object. 1601 bool need_null_check = !is_null_free; 1602 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_checkcast, result, object, klass, 1603 tmp1, tmp2, tmp3, fast_check, info_for_exception, info_for_patch, stub, 1604 need_null_check); 1605 if (profiled_method != nullptr) { 1606 c->set_profiled_method(profiled_method); 1607 c->set_profiled_bci(profiled_bci); 1608 c->set_should_profile(true); 1609 } 1610 append(c); 1611 } 1612 1613 void LIR_List::instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci) { 1614 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_instanceof, result, object, klass, tmp1, tmp2, tmp3, fast_check, nullptr, info_for_patch, nullptr); 1615 if (profiled_method != nullptr) { 1616 c->set_profiled_method(profiled_method); 1617 c->set_profiled_bci(profiled_bci); 1618 c->set_should_profile(true); 1619 } 1620 append(c); 1621 } 1622 1623 1624 void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, 1625 CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci) { 1626 // FIXME -- if the types of the array and/or the object are known statically, we can avoid loading the klass 1627 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception); 1628 if (profiled_method != nullptr) { 1629 c->set_profiled_method(profiled_method); 1630 c->set_profiled_bci(profiled_bci); 1631 c->set_should_profile(true); 1632 } 1633 append(c); 1634 } 1635 1636 void LIR_List::null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null) { 1637 if (deoptimize_on_null) { 1638 // Emit an explicit null check and deoptimize if opr is null 1639 CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check, Deoptimization::Action_none); 1640 cmp(lir_cond_equal, opr, LIR_OprFact::oopConst(nullptr)); 1641 branch(lir_cond_equal, deopt); 1642 } else { 1643 // Emit an implicit null check 1644 append(new LIR_Op1(lir_null_check, opr, info)); 1645 } 1646 } 1647 1648 void LIR_List::check_flat_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub) { 1649 LIR_OpFlattenedArrayCheck* c = new LIR_OpFlattenedArrayCheck(array, value, tmp, stub); 1650 append(c); 1651 } 1652 1653 void LIR_List::check_null_free_array(LIR_Opr array, LIR_Opr tmp) { 1654 LIR_OpNullFreeArrayCheck* c = new LIR_OpNullFreeArrayCheck(array, tmp); 1655 append(c); 1656 } 1657 1658 void LIR_List::substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result, 1659 LIR_Opr tmp1, LIR_Opr tmp2, 1660 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op, 1661 CodeEmitInfo* info, CodeStub* stub) { 1662 LIR_OpSubstitutabilityCheck* c = new LIR_OpSubstitutabilityCheck(result, left, right, equal_result, not_equal_result, 1663 tmp1, tmp2, 1664 left_klass, right_klass, left_klass_op, right_klass_op, 1665 info, stub); 1666 append(c); 1667 } 1668 1669 void LIR_List::cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value, 1670 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) { 1671 append(new LIR_OpCompareAndSwap(lir_cas_long, addr, cmp_value, new_value, t1, t2, result)); 1672 } 1673 1674 void LIR_List::cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value, 1675 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) { 1676 append(new LIR_OpCompareAndSwap(lir_cas_obj, addr, cmp_value, new_value, t1, t2, result)); 1677 } 1678 1679 void LIR_List::cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value, 1680 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) { 1681 append(new LIR_OpCompareAndSwap(lir_cas_int, addr, cmp_value, new_value, t1, t2, result)); 1682 } 1683 1684 1685 #ifdef PRODUCT 1686 1687 void print_LIR(BlockList* blocks) { 1688 } 1689 1690 #else 1691 // LIR_Opr 1692 void LIR_Opr::print() const { 1693 print(tty); 1694 } 1695 1696 void LIR_Opr::print(outputStream* out) const { 1697 if (is_illegal()) { 1698 return; 1699 } 1700 1701 out->print("["); 1702 if (is_pointer()) { 1703 pointer()->print_value_on(out); 1704 } else if (is_single_stack()) { 1705 out->print("stack:%d", single_stack_ix()); 1706 } else if (is_double_stack()) { 1707 out->print("dbl_stack:%d",double_stack_ix()); 1708 } else if (is_virtual()) { 1709 out->print("R%d", vreg_number()); 1710 } else if (is_single_cpu()) { 1711 out->print("%s", as_register()->name()); 1712 } else if (is_double_cpu()) { 1713 out->print("%s", as_register_hi()->name()); 1714 out->print("%s", as_register_lo()->name()); 1715 #if defined(X86) 1716 } else if (is_single_xmm()) { 1717 out->print("%s", as_xmm_float_reg()->name()); 1718 } else if (is_double_xmm()) { 1719 out->print("%s", as_xmm_double_reg()->name()); 1720 } else if (is_single_fpu()) { 1721 out->print("fpu%d", fpu_regnr()); 1722 } else if (is_double_fpu()) { 1723 out->print("fpu%d", fpu_regnrLo()); 1724 #elif defined(AARCH64) 1725 } else if (is_single_fpu()) { 1726 out->print("fpu%d", fpu_regnr()); 1727 } else if (is_double_fpu()) { 1728 out->print("fpu%d", fpu_regnrLo()); 1729 #elif defined(ARM) 1730 } else if (is_single_fpu()) { 1731 out->print("s%d", fpu_regnr()); 1732 } else if (is_double_fpu()) { 1733 out->print("d%d", fpu_regnrLo() >> 1); 1734 #else 1735 } else if (is_single_fpu()) { 1736 out->print("%s", as_float_reg()->name()); 1737 } else if (is_double_fpu()) { 1738 out->print("%s", as_double_reg()->name()); 1739 #endif 1740 1741 } else if (is_illegal()) { 1742 out->print("-"); 1743 } else { 1744 out->print("Unknown Operand"); 1745 } 1746 if (!is_illegal()) { 1747 out->print("|%c", type_char()); 1748 } 1749 if (is_register() && is_last_use()) { 1750 out->print("(last_use)"); 1751 } 1752 out->print("]"); 1753 } 1754 1755 1756 // LIR_Address 1757 void LIR_Const::print_value_on(outputStream* out) const { 1758 switch (type()) { 1759 case T_ADDRESS:out->print("address:%d",as_jint()); break; 1760 case T_INT: out->print("int:%d", as_jint()); break; 1761 case T_LONG: out->print("lng:" JLONG_FORMAT, as_jlong()); break; 1762 case T_FLOAT: out->print("flt:%f", as_jfloat()); break; 1763 case T_DOUBLE: out->print("dbl:%f", as_jdouble()); break; 1764 case T_OBJECT: out->print("obj:" INTPTR_FORMAT, p2i(as_jobject())); break; 1765 case T_METADATA: out->print("metadata:" INTPTR_FORMAT, p2i(as_metadata()));break; 1766 default: out->print("%3d:" UINT64_FORMAT_X, type(), (uint64_t)as_jlong()); break; 1767 } 1768 } 1769 1770 // LIR_Address 1771 void LIR_Address::print_value_on(outputStream* out) const { 1772 out->print("Base:"); _base->print(out); 1773 if (!_index->is_illegal()) { 1774 out->print(" Index:"); _index->print(out); 1775 switch (scale()) { 1776 case times_1: break; 1777 case times_2: out->print(" * 2"); break; 1778 case times_4: out->print(" * 4"); break; 1779 case times_8: out->print(" * 8"); break; 1780 } 1781 } 1782 out->print(" Disp: " INTX_FORMAT, _disp); 1783 } 1784 1785 // debug output of block header without InstructionPrinter 1786 // (because phi functions are not necessary for LIR) 1787 static void print_block(BlockBegin* x) { 1788 // print block id 1789 BlockEnd* end = x->end(); 1790 tty->print("B%d ", x->block_id()); 1791 1792 // print flags 1793 if (x->is_set(BlockBegin::std_entry_flag)) tty->print("std "); 1794 if (x->is_set(BlockBegin::osr_entry_flag)) tty->print("osr "); 1795 if (x->is_set(BlockBegin::exception_entry_flag)) tty->print("ex "); 1796 if (x->is_set(BlockBegin::subroutine_entry_flag)) tty->print("jsr "); 1797 if (x->is_set(BlockBegin::backward_branch_target_flag)) tty->print("bb "); 1798 if (x->is_set(BlockBegin::linear_scan_loop_header_flag)) tty->print("lh "); 1799 if (x->is_set(BlockBegin::linear_scan_loop_end_flag)) tty->print("le "); 1800 1801 // print block bci range 1802 tty->print("[%d, %d] ", x->bci(), (end == nullptr ? -1 : end->printable_bci())); 1803 1804 // print predecessors and successors 1805 if (x->number_of_preds() > 0) { 1806 tty->print("preds: "); 1807 for (int i = 0; i < x->number_of_preds(); i ++) { 1808 tty->print("B%d ", x->pred_at(i)->block_id()); 1809 } 1810 } 1811 1812 if (end != nullptr && x->number_of_sux() > 0) { 1813 tty->print("sux: "); 1814 for (int i = 0; i < x->number_of_sux(); i ++) { 1815 tty->print("B%d ", x->sux_at(i)->block_id()); 1816 } 1817 } 1818 1819 // print exception handlers 1820 if (x->number_of_exception_handlers() > 0) { 1821 tty->print("xhandler: "); 1822 for (int i = 0; i < x->number_of_exception_handlers(); i++) { 1823 tty->print("B%d ", x->exception_handler_at(i)->block_id()); 1824 } 1825 } 1826 1827 tty->cr(); 1828 } 1829 1830 void print_LIR(BlockList* blocks) { 1831 tty->print_cr("LIR:"); 1832 int i; 1833 for (i = 0; i < blocks->length(); i++) { 1834 BlockBegin* bb = blocks->at(i); 1835 print_block(bb); 1836 tty->print("__id_Instruction___________________________________________"); tty->cr(); 1837 bb->lir()->print_instructions(); 1838 } 1839 } 1840 1841 void LIR_List::print_instructions() { 1842 for (int i = 0; i < _operations.length(); i++) { 1843 _operations.at(i)->print(); tty->cr(); 1844 } 1845 tty->cr(); 1846 } 1847 1848 // LIR_Ops printing routines 1849 // LIR_Op 1850 void LIR_Op::print_on(outputStream* out) const { 1851 if (id() != -1 || PrintCFGToFile) { 1852 out->print("%4d ", id()); 1853 } else { 1854 out->print(" "); 1855 } 1856 out->print("%s ", name()); 1857 print_instr(out); 1858 if (info() != nullptr) out->print(" [bci:%d]", info()->stack()->bci()); 1859 #ifdef ASSERT 1860 if (Verbose && _file != nullptr) { 1861 out->print(" (%s:%d)", _file, _line); 1862 } 1863 #endif 1864 } 1865 1866 const char * LIR_Op::name() const { 1867 const char* s = nullptr; 1868 switch(code()) { 1869 // LIR_Op0 1870 case lir_membar: s = "membar"; break; 1871 case lir_membar_acquire: s = "membar_acquire"; break; 1872 case lir_membar_release: s = "membar_release"; break; 1873 case lir_membar_loadload: s = "membar_loadload"; break; 1874 case lir_membar_storestore: s = "membar_storestore"; break; 1875 case lir_membar_loadstore: s = "membar_loadstore"; break; 1876 case lir_membar_storeload: s = "membar_storeload"; break; 1877 case lir_label: s = "label"; break; 1878 case lir_nop: s = "nop"; break; 1879 case lir_on_spin_wait: s = "on_spin_wait"; break; 1880 case lir_std_entry: s = "std_entry"; break; 1881 case lir_osr_entry: s = "osr_entry"; break; 1882 case lir_fpop_raw: s = "fpop_raw"; break; 1883 case lir_breakpoint: s = "breakpoint"; break; 1884 case lir_get_thread: s = "get_thread"; break; 1885 case lir_check_orig_pc: s = "check_orig_pc"; break; 1886 // LIR_Op1 1887 case lir_fxch: s = "fxch"; break; 1888 case lir_fld: s = "fld"; break; 1889 case lir_push: s = "push"; break; 1890 case lir_pop: s = "pop"; break; 1891 case lir_null_check: s = "null_check"; break; 1892 case lir_return: s = "return"; break; 1893 case lir_safepoint: s = "safepoint"; break; 1894 case lir_leal: s = "leal"; break; 1895 case lir_branch: s = "branch"; break; 1896 case lir_cond_float_branch: s = "flt_cond_br"; break; 1897 case lir_move: s = "move"; break; 1898 case lir_roundfp: s = "roundfp"; break; 1899 case lir_rtcall: s = "rtcall"; break; 1900 case lir_throw: s = "throw"; break; 1901 case lir_unwind: s = "unwind"; break; 1902 case lir_convert: s = "convert"; break; 1903 case lir_alloc_object: s = "alloc_obj"; break; 1904 case lir_monaddr: s = "mon_addr"; break; 1905 // LIR_Op2 1906 case lir_cmp: s = "cmp"; break; 1907 case lir_cmp_l2i: s = "cmp_l2i"; break; 1908 case lir_ucmp_fd2i: s = "ucomp_fd2i"; break; 1909 case lir_cmp_fd2i: s = "comp_fd2i"; break; 1910 case lir_add: s = "add"; break; 1911 case lir_sub: s = "sub"; break; 1912 case lir_mul: s = "mul"; break; 1913 case lir_div: s = "div"; break; 1914 case lir_rem: s = "rem"; break; 1915 case lir_abs: s = "abs"; break; 1916 case lir_neg: s = "neg"; break; 1917 case lir_sqrt: s = "sqrt"; break; 1918 case lir_f2hf: s = "f2hf"; break; 1919 case lir_hf2f: s = "hf2f"; break; 1920 case lir_logic_and: s = "logic_and"; break; 1921 case lir_logic_or: s = "logic_or"; break; 1922 case lir_logic_xor: s = "logic_xor"; break; 1923 case lir_shl: s = "shift_left"; break; 1924 case lir_shr: s = "shift_right"; break; 1925 case lir_ushr: s = "ushift_right"; break; 1926 case lir_alloc_array: s = "alloc_array"; break; 1927 case lir_xadd: s = "xadd"; break; 1928 case lir_xchg: s = "xchg"; break; 1929 // LIR_Op3 1930 case lir_idiv: s = "idiv"; break; 1931 case lir_irem: s = "irem"; break; 1932 case lir_fmad: s = "fmad"; break; 1933 case lir_fmaf: s = "fmaf"; break; 1934 // LIR_Op4 1935 case lir_cmove: s = "cmove"; break; 1936 // LIR_OpJavaCall 1937 case lir_static_call: s = "static"; break; 1938 case lir_optvirtual_call: s = "optvirtual"; break; 1939 case lir_icvirtual_call: s = "icvirtual"; break; 1940 case lir_dynamic_call: s = "dynamic"; break; 1941 // LIR_OpArrayCopy 1942 case lir_arraycopy: s = "arraycopy"; break; 1943 // LIR_OpUpdateCRC32 1944 case lir_updatecrc32: s = "updatecrc32"; break; 1945 // LIR_OpLock 1946 case lir_lock: s = "lock"; break; 1947 case lir_unlock: s = "unlock"; break; 1948 // LIR_OpDelay 1949 case lir_delay_slot: s = "delay"; break; 1950 // LIR_OpTypeCheck 1951 case lir_instanceof: s = "instanceof"; break; 1952 case lir_checkcast: s = "checkcast"; break; 1953 case lir_store_check: s = "store_check"; break; 1954 // LIR_OpFlattenedArrayCheck 1955 case lir_flat_array_check: s = "flat_array_check"; break; 1956 // LIR_OpNullFreeArrayCheck 1957 case lir_null_free_array_check: s = "null_free_array_check"; break; 1958 // LIR_OpSubstitutabilityCheck 1959 case lir_substitutability_check: s = "substitutability_check"; break; 1960 // LIR_OpCompareAndSwap 1961 case lir_cas_long: s = "cas_long"; break; 1962 case lir_cas_obj: s = "cas_obj"; break; 1963 case lir_cas_int: s = "cas_int"; break; 1964 // LIR_OpProfileCall 1965 case lir_profile_call: s = "profile_call"; break; 1966 // LIR_OpProfileType 1967 case lir_profile_type: s = "profile_type"; break; 1968 // LIR_OpProfileInlineType 1969 case lir_profile_inline_type: s = "profile_inline_type"; break; 1970 // LIR_OpAssert 1971 #ifdef ASSERT 1972 case lir_assert: s = "assert"; break; 1973 #endif 1974 case lir_none: ShouldNotReachHere();break; 1975 default: s = "illegal_op"; break; 1976 } 1977 return s; 1978 } 1979 1980 // LIR_OpJavaCall 1981 void LIR_OpJavaCall::print_instr(outputStream* out) const { 1982 out->print("call: "); 1983 out->print("[addr: " INTPTR_FORMAT "]", p2i(address())); 1984 if (receiver()->is_valid()) { 1985 out->print(" [recv: "); receiver()->print(out); out->print("]"); 1986 } 1987 if (result_opr()->is_valid()) { 1988 out->print(" [result: "); result_opr()->print(out); out->print("]"); 1989 } 1990 } 1991 1992 // LIR_OpLabel 1993 void LIR_OpLabel::print_instr(outputStream* out) const { 1994 out->print("[label:" INTPTR_FORMAT "]", p2i(_label)); 1995 } 1996 1997 // LIR_OpArrayCopy 1998 void LIR_OpArrayCopy::print_instr(outputStream* out) const { 1999 src()->print(out); out->print(" "); 2000 src_pos()->print(out); out->print(" "); 2001 dst()->print(out); out->print(" "); 2002 dst_pos()->print(out); out->print(" "); 2003 length()->print(out); out->print(" "); 2004 tmp()->print(out); out->print(" "); 2005 } 2006 2007 // LIR_OpUpdateCRC32 2008 void LIR_OpUpdateCRC32::print_instr(outputStream* out) const { 2009 crc()->print(out); out->print(" "); 2010 val()->print(out); out->print(" "); 2011 result_opr()->print(out); out->print(" "); 2012 } 2013 2014 // LIR_OpCompareAndSwap 2015 void LIR_OpCompareAndSwap::print_instr(outputStream* out) const { 2016 addr()->print(out); out->print(" "); 2017 cmp_value()->print(out); out->print(" "); 2018 new_value()->print(out); out->print(" "); 2019 tmp1()->print(out); out->print(" "); 2020 tmp2()->print(out); out->print(" "); 2021 2022 } 2023 2024 // LIR_Op0 2025 void LIR_Op0::print_instr(outputStream* out) const { 2026 result_opr()->print(out); 2027 } 2028 2029 // LIR_Op1 2030 const char * LIR_Op1::name() const { 2031 if (code() == lir_move) { 2032 switch (move_kind()) { 2033 case lir_move_normal: 2034 return "move"; 2035 case lir_move_volatile: 2036 return "volatile_move"; 2037 case lir_move_wide: 2038 return "wide_move"; 2039 default: 2040 ShouldNotReachHere(); 2041 return "illegal_op"; 2042 } 2043 } else { 2044 return LIR_Op::name(); 2045 } 2046 } 2047 2048 2049 void LIR_Op1::print_instr(outputStream* out) const { 2050 _opr->print(out); out->print(" "); 2051 result_opr()->print(out); out->print(" "); 2052 print_patch_code(out, patch_code()); 2053 } 2054 2055 2056 // LIR_Op1 2057 void LIR_OpRTCall::print_instr(outputStream* out) const { 2058 intx a = (intx)addr(); 2059 out->print("%s", Runtime1::name_for_address(addr())); 2060 out->print(" "); 2061 tmp()->print(out); 2062 } 2063 2064 void LIR_Op1::print_patch_code(outputStream* out, LIR_PatchCode code) { 2065 switch(code) { 2066 case lir_patch_none: break; 2067 case lir_patch_low: out->print("[patch_low]"); break; 2068 case lir_patch_high: out->print("[patch_high]"); break; 2069 case lir_patch_normal: out->print("[patch_normal]"); break; 2070 default: ShouldNotReachHere(); 2071 } 2072 } 2073 2074 // LIR_OpBranch 2075 void LIR_OpBranch::print_instr(outputStream* out) const { 2076 print_condition(out, cond()); out->print(" "); 2077 in_opr1()->print(out); out->print(" "); 2078 in_opr2()->print(out); out->print(" "); 2079 if (block() != nullptr) { 2080 out->print("[B%d] ", block()->block_id()); 2081 } else if (stub() != nullptr) { 2082 out->print("["); 2083 stub()->print_name(out); 2084 out->print(": " INTPTR_FORMAT "]", p2i(stub())); 2085 if (stub()->info() != nullptr) out->print(" [bci:%d]", stub()->info()->stack()->bci()); 2086 } else { 2087 out->print("[label:" INTPTR_FORMAT "] ", p2i(label())); 2088 } 2089 if (ublock() != nullptr) { 2090 out->print("unordered: [B%d] ", ublock()->block_id()); 2091 } 2092 } 2093 2094 void LIR_Op::print_condition(outputStream* out, LIR_Condition cond) { 2095 switch(cond) { 2096 case lir_cond_equal: out->print("[EQ]"); break; 2097 case lir_cond_notEqual: out->print("[NE]"); break; 2098 case lir_cond_less: out->print("[LT]"); break; 2099 case lir_cond_lessEqual: out->print("[LE]"); break; 2100 case lir_cond_greaterEqual: out->print("[GE]"); break; 2101 case lir_cond_greater: out->print("[GT]"); break; 2102 case lir_cond_belowEqual: out->print("[BE]"); break; 2103 case lir_cond_aboveEqual: out->print("[AE]"); break; 2104 case lir_cond_always: out->print("[AL]"); break; 2105 default: out->print("[%d]",cond); break; 2106 } 2107 } 2108 2109 // LIR_OpConvert 2110 void LIR_OpConvert::print_instr(outputStream* out) const { 2111 print_bytecode(out, bytecode()); 2112 in_opr()->print(out); out->print(" "); 2113 result_opr()->print(out); out->print(" "); 2114 } 2115 2116 void LIR_OpConvert::print_bytecode(outputStream* out, Bytecodes::Code code) { 2117 switch(code) { 2118 case Bytecodes::_d2f: out->print("[d2f] "); break; 2119 case Bytecodes::_d2i: out->print("[d2i] "); break; 2120 case Bytecodes::_d2l: out->print("[d2l] "); break; 2121 case Bytecodes::_f2d: out->print("[f2d] "); break; 2122 case Bytecodes::_f2i: out->print("[f2i] "); break; 2123 case Bytecodes::_f2l: out->print("[f2l] "); break; 2124 case Bytecodes::_i2b: out->print("[i2b] "); break; 2125 case Bytecodes::_i2c: out->print("[i2c] "); break; 2126 case Bytecodes::_i2d: out->print("[i2d] "); break; 2127 case Bytecodes::_i2f: out->print("[i2f] "); break; 2128 case Bytecodes::_i2l: out->print("[i2l] "); break; 2129 case Bytecodes::_i2s: out->print("[i2s] "); break; 2130 case Bytecodes::_l2i: out->print("[l2i] "); break; 2131 case Bytecodes::_l2f: out->print("[l2f] "); break; 2132 case Bytecodes::_l2d: out->print("[l2d] "); break; 2133 default: 2134 out->print("[?%d]",code); 2135 break; 2136 } 2137 } 2138 2139 void LIR_OpAllocObj::print_instr(outputStream* out) const { 2140 klass()->print(out); out->print(" "); 2141 obj()->print(out); out->print(" "); 2142 tmp1()->print(out); out->print(" "); 2143 tmp2()->print(out); out->print(" "); 2144 tmp3()->print(out); out->print(" "); 2145 tmp4()->print(out); out->print(" "); 2146 out->print("[hdr:%d]", header_size()); out->print(" "); 2147 out->print("[obj:%d]", object_size()); out->print(" "); 2148 out->print("[lbl:" INTPTR_FORMAT "]", p2i(stub()->entry())); 2149 } 2150 2151 void LIR_OpRoundFP::print_instr(outputStream* out) const { 2152 _opr->print(out); out->print(" "); 2153 tmp()->print(out); out->print(" "); 2154 result_opr()->print(out); out->print(" "); 2155 } 2156 2157 // LIR_Op2 2158 void LIR_Op2::print_instr(outputStream* out) const { 2159 if (code() == lir_cmp || code() == lir_branch || code() == lir_cond_float_branch) { 2160 print_condition(out, condition()); out->print(" "); 2161 } 2162 in_opr1()->print(out); out->print(" "); 2163 in_opr2()->print(out); out->print(" "); 2164 if (tmp1_opr()->is_valid()) { tmp1_opr()->print(out); out->print(" "); } 2165 if (tmp2_opr()->is_valid()) { tmp2_opr()->print(out); out->print(" "); } 2166 if (tmp3_opr()->is_valid()) { tmp3_opr()->print(out); out->print(" "); } 2167 if (tmp4_opr()->is_valid()) { tmp4_opr()->print(out); out->print(" "); } 2168 if (tmp5_opr()->is_valid()) { tmp5_opr()->print(out); out->print(" "); } 2169 result_opr()->print(out); 2170 } 2171 2172 void LIR_OpAllocArray::print_instr(outputStream* out) const { 2173 klass()->print(out); out->print(" "); 2174 len()->print(out); out->print(" "); 2175 obj()->print(out); out->print(" "); 2176 tmp1()->print(out); out->print(" "); 2177 tmp2()->print(out); out->print(" "); 2178 tmp3()->print(out); out->print(" "); 2179 tmp4()->print(out); out->print(" "); 2180 out->print("[type:0x%x]", type()); out->print(" "); 2181 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry())); 2182 } 2183 2184 2185 void LIR_OpTypeCheck::print_instr(outputStream* out) const { 2186 object()->print(out); out->print(" "); 2187 if (code() == lir_store_check) { 2188 array()->print(out); out->print(" "); 2189 } 2190 if (code() != lir_store_check) { 2191 klass()->print_name_on(out); out->print(" "); 2192 if (fast_check()) out->print("fast_check "); 2193 } 2194 tmp1()->print(out); out->print(" "); 2195 tmp2()->print(out); out->print(" "); 2196 tmp3()->print(out); out->print(" "); 2197 result_opr()->print(out); out->print(" "); 2198 if (info_for_exception() != nullptr) out->print(" [bci:%d]", info_for_exception()->stack()->bci()); 2199 } 2200 2201 void LIR_OpFlattenedArrayCheck::print_instr(outputStream* out) const { 2202 array()->print(out); out->print(" "); 2203 value()->print(out); out->print(" "); 2204 tmp()->print(out); out->print(" "); 2205 if (stub() != nullptr) { 2206 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry())); 2207 } 2208 } 2209 2210 void LIR_OpNullFreeArrayCheck::print_instr(outputStream* out) const { 2211 array()->print(out); out->print(" "); 2212 tmp()->print(out); out->print(" "); 2213 } 2214 2215 void LIR_OpSubstitutabilityCheck::print_instr(outputStream* out) const { 2216 result_opr()->print(out); out->print(" "); 2217 left()->print(out); out->print(" "); 2218 right()->print(out); out->print(" "); 2219 equal_result()->print(out); out->print(" "); 2220 not_equal_result()->print(out); out->print(" "); 2221 tmp1()->print(out); out->print(" "); 2222 tmp2()->print(out); out->print(" "); 2223 if (left_klass() == nullptr) { 2224 out->print("unknown "); 2225 } else { 2226 left_klass()->print(out); out->print(" "); 2227 } 2228 if (right_klass() == nullptr) { 2229 out->print("unknown "); 2230 } else { 2231 right_klass()->print(out); out->print(" "); 2232 } 2233 left_klass_op()->print(out); out->print(" "); 2234 right_klass_op()->print(out); out->print(" "); 2235 if (stub() != nullptr) { 2236 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry())); 2237 } 2238 } 2239 2240 // LIR_Op3 2241 void LIR_Op3::print_instr(outputStream* out) const { 2242 in_opr1()->print(out); out->print(" "); 2243 in_opr2()->print(out); out->print(" "); 2244 in_opr3()->print(out); out->print(" "); 2245 result_opr()->print(out); 2246 } 2247 2248 // LIR_Op4 2249 void LIR_Op4::print_instr(outputStream* out) const { 2250 print_condition(out, condition()); out->print(" "); 2251 in_opr1()->print(out); out->print(" "); 2252 in_opr2()->print(out); out->print(" "); 2253 in_opr3()->print(out); out->print(" "); 2254 in_opr4()->print(out); out->print(" "); 2255 result_opr()->print(out); 2256 } 2257 2258 void LIR_OpLock::print_instr(outputStream* out) const { 2259 hdr_opr()->print(out); out->print(" "); 2260 obj_opr()->print(out); out->print(" "); 2261 lock_opr()->print(out); out->print(" "); 2262 if (_scratch->is_valid()) { 2263 _scratch->print(out); out->print(" "); 2264 } 2265 out->print("[lbl:" INTPTR_FORMAT "]", p2i(stub()->entry())); 2266 } 2267 2268 void LIR_OpLoadKlass::print_instr(outputStream* out) const { 2269 obj()->print(out); out->print(" "); 2270 result_opr()->print(out); out->print(" "); 2271 } 2272 2273 #ifdef ASSERT 2274 void LIR_OpAssert::print_instr(outputStream* out) const { 2275 print_condition(out, condition()); out->print(" "); 2276 in_opr1()->print(out); out->print(" "); 2277 in_opr2()->print(out); out->print(", \""); 2278 out->print("%s", msg()); out->print("\""); 2279 } 2280 #endif 2281 2282 2283 void LIR_OpDelay::print_instr(outputStream* out) const { 2284 _op->print_on(out); 2285 } 2286 2287 2288 // LIR_OpProfileCall 2289 void LIR_OpProfileCall::print_instr(outputStream* out) const { 2290 profiled_method()->name()->print_symbol_on(out); 2291 out->print("."); 2292 profiled_method()->holder()->name()->print_symbol_on(out); 2293 out->print(" @ %d ", profiled_bci()); 2294 mdo()->print(out); out->print(" "); 2295 recv()->print(out); out->print(" "); 2296 tmp1()->print(out); out->print(" "); 2297 } 2298 2299 // LIR_OpProfileType 2300 void LIR_OpProfileType::print_instr(outputStream* out) const { 2301 out->print("exact = "); 2302 if (exact_klass() == nullptr) { 2303 out->print("unknown"); 2304 } else { 2305 exact_klass()->print_name_on(out); 2306 } 2307 out->print(" current = "); ciTypeEntries::print_ciklass(out, current_klass()); 2308 out->print(" "); 2309 mdp()->print(out); out->print(" "); 2310 obj()->print(out); out->print(" "); 2311 tmp()->print(out); out->print(" "); 2312 } 2313 2314 // LIR_OpProfileInlineType 2315 void LIR_OpProfileInlineType::print_instr(outputStream* out) const { 2316 out->print(" flag = %x ", flag()); 2317 mdp()->print(out); out->print(" "); 2318 obj()->print(out); out->print(" "); 2319 tmp()->print(out); out->print(" "); 2320 } 2321 2322 #endif // PRODUCT 2323 2324 // Implementation of LIR_InsertionBuffer 2325 2326 void LIR_InsertionBuffer::append(int index, LIR_Op* op) { 2327 assert(_index_and_count.length() % 2 == 0, "must have a count for each index"); 2328 2329 int i = number_of_insertion_points() - 1; 2330 if (i < 0 || index_at(i) < index) { 2331 append_new(index, 1); 2332 } else { 2333 assert(index_at(i) == index, "can append LIR_Ops in ascending order only"); 2334 assert(count_at(i) > 0, "check"); 2335 set_count_at(i, count_at(i) + 1); 2336 } 2337 _ops.push(op); 2338 2339 DEBUG_ONLY(verify()); 2340 } 2341 2342 #ifdef ASSERT 2343 void LIR_InsertionBuffer::verify() { 2344 int sum = 0; 2345 int prev_idx = -1; 2346 2347 for (int i = 0; i < number_of_insertion_points(); i++) { 2348 assert(prev_idx < index_at(i), "index must be ordered ascending"); 2349 sum += count_at(i); 2350 } 2351 assert(sum == number_of_ops(), "wrong total sum"); 2352 } 2353 #endif