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 "c1/c1_CodeStubs.hpp"
26 #include "c1/c1_InstructionPrinter.hpp"
27 #include "c1/c1_LIR.hpp"
28 #include "c1/c1_LIRAssembler.hpp"
29 #include "c1/c1_ValueStack.hpp"
30 #include "ci/ciInstance.hpp"
31 #include "runtime/safepointMechanism.inline.hpp"
32 #include "runtime/sharedRuntime.hpp"
33 #include "runtime/vm_version.hpp"
34
35 Register LIR_Opr::as_register() const {
36 return FrameMap::cpu_rnr2reg(cpu_regnr());
37 }
38
39 Register LIR_Opr::as_register_lo() const {
40 return FrameMap::cpu_rnr2reg(cpu_regnrLo());
41 }
42
43 Register LIR_Opr::as_register_hi() const {
44 return FrameMap::cpu_rnr2reg(cpu_regnrHi());
45 }
46
47 LIR_Opr LIR_OprFact::illegalOpr = LIR_OprFact::illegal();
48 LIR_Opr LIR_OprFact::nullOpr = LIR_Opr();
49
269 assert(_ublock != nullptr, "must have old block");
270 _ublock = b;
271 }
272
273 void LIR_OpBranch::negate_cond() {
274 switch (cond()) {
275 case lir_cond_equal: set_cond(lir_cond_notEqual); break;
276 case lir_cond_notEqual: set_cond(lir_cond_equal); break;
277 case lir_cond_less: set_cond(lir_cond_greaterEqual); break;
278 case lir_cond_lessEqual: set_cond(lir_cond_greater); break;
279 case lir_cond_greaterEqual: set_cond(lir_cond_less); break;
280 case lir_cond_greater: set_cond(lir_cond_lessEqual); break;
281 default: ShouldNotReachHere();
282 }
283 }
284
285
286 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
287 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
288 bool fast_check, CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch,
289 CodeStub* stub)
290
291 : LIR_Op(code, result, nullptr)
292 , _object(object)
293 , _array(LIR_OprFact::illegalOpr)
294 , _klass(klass)
295 , _tmp1(tmp1)
296 , _tmp2(tmp2)
297 , _tmp3(tmp3)
298 , _info_for_patch(info_for_patch)
299 , _info_for_exception(info_for_exception)
300 , _stub(stub)
301 , _profiled_method(nullptr)
302 , _profiled_bci(-1)
303 , _should_profile(false)
304 , _fast_check(fast_check)
305 {
306 if (code == lir_checkcast) {
307 assert(info_for_exception != nullptr, "checkcast throws exceptions");
308 } else if (code == lir_instanceof) {
309 assert(info_for_exception == nullptr, "instanceof throws no exceptions");
310 } else {
311 ShouldNotReachHere();
312 }
313 }
314
315
316
317 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)
318 : LIR_Op(code, LIR_OprFact::illegalOpr, nullptr)
319 , _object(object)
320 , _array(array)
321 , _klass(nullptr)
322 , _tmp1(tmp1)
323 , _tmp2(tmp2)
324 , _tmp3(tmp3)
325 , _info_for_patch(nullptr)
326 , _info_for_exception(info_for_exception)
327 , _stub(nullptr)
328 , _profiled_method(nullptr)
329 , _profiled_bci(-1)
330 , _should_profile(false)
331 , _fast_check(false)
332 {
333 if (code == lir_store_check) {
334 _stub = new ArrayStoreExceptionStub(object, info_for_exception);
335 assert(info_for_exception != nullptr, "store_check throws exceptions");
336 } else {
337 ShouldNotReachHere();
338 }
339 }
340
341
342 LIR_OpArrayCopy::LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length,
343 LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info)
344 : LIR_Op(lir_arraycopy, LIR_OprFact::illegalOpr, info)
345 , _src(src)
346 , _src_pos(src_pos)
347 , _dst(dst)
348 , _dst_pos(dst_pos)
349 , _length(length)
350 , _tmp(tmp)
351 , _expected_type(expected_type)
352 , _flags(flags) {
353 #if defined(X86) || defined(AARCH64) || defined(S390) || defined(RISCV64) || defined(PPC64)
354 if (expected_type != nullptr &&
355 ((flags & ~LIR_OpArrayCopy::get_initial_copy_flags()) == 0)) {
356 _stub = nullptr;
357 } else {
358 _stub = new ArrayCopyStub(this);
359 }
360 #else
395 // complete rework of LIR instruction visitor.
396 // The virtual call for each instruction type is replaced by a big
397 // switch that adds the operands for each instruction
398
399 void LIR_OpVisitState::visit(LIR_Op* op) {
400 // copy information from the LIR_Op
401 reset();
402 set_op(op);
403
404 switch (op->code()) {
405
406 // LIR_Op0
407 case lir_breakpoint: // result and info always invalid
408 case lir_membar: // result and info always invalid
409 case lir_membar_acquire: // result and info always invalid
410 case lir_membar_release: // result and info always invalid
411 case lir_membar_loadload: // result and info always invalid
412 case lir_membar_storestore: // result and info always invalid
413 case lir_membar_loadstore: // result and info always invalid
414 case lir_membar_storeload: // result and info always invalid
415 case lir_on_spin_wait:
416 {
417 assert(op->as_Op0() != nullptr, "must be");
418 assert(op->_info == nullptr, "info not used by this instruction");
419 assert(op->_result->is_illegal(), "not used");
420 break;
421 }
422
423 case lir_nop: // may have info, result always invalid
424 case lir_std_entry: // may have result, info always invalid
425 case lir_osr_entry: // may have result, info always invalid
426 case lir_get_thread: // may have result, info always invalid
427 {
428 assert(op->as_Op0() != nullptr, "must be");
429 if (op->_info != nullptr) do_info(op->_info);
430 if (op->_result->is_valid()) do_output(op->_result);
431 break;
432 }
433
434
773
774
775 // LIR_OpLock
776 case lir_lock:
777 case lir_unlock: {
778 assert(op->as_OpLock() != nullptr, "must be");
779 LIR_OpLock* opLock = (LIR_OpLock*)op;
780
781 if (opLock->_info) do_info(opLock->_info);
782
783 // TODO: check if these operands really have to be temp
784 // (or if input is sufficient). This may have influence on the oop map!
785 assert(opLock->_lock->is_valid(), "used"); do_temp(opLock->_lock);
786 assert(opLock->_hdr->is_valid(), "used"); do_temp(opLock->_hdr);
787 assert(opLock->_obj->is_valid(), "used"); do_temp(opLock->_obj);
788
789 if (opLock->_scratch->is_valid()) do_temp(opLock->_scratch);
790 assert(opLock->_result->is_illegal(), "unused");
791
792 do_stub(opLock->_stub);
793
794 break;
795 }
796
797
798 // LIR_OpTypeCheck
799 case lir_instanceof:
800 case lir_checkcast:
801 case lir_store_check: {
802 assert(op->as_OpTypeCheck() != nullptr, "must be");
803 LIR_OpTypeCheck* opTypeCheck = (LIR_OpTypeCheck*)op;
804
805 if (opTypeCheck->_info_for_exception) do_info(opTypeCheck->_info_for_exception);
806 if (opTypeCheck->_info_for_patch) do_info(opTypeCheck->_info_for_patch);
807 if (opTypeCheck->_object->is_valid()) do_input(opTypeCheck->_object);
808 if (op->code() == lir_store_check && opTypeCheck->_object->is_valid()) {
809 do_temp(opTypeCheck->_object);
810 }
811 if (opTypeCheck->_array->is_valid()) do_input(opTypeCheck->_array);
812 if (opTypeCheck->_tmp1->is_valid()) do_temp(opTypeCheck->_tmp1);
813 if (opTypeCheck->_tmp2->is_valid()) do_temp(opTypeCheck->_tmp2);
814 if (opTypeCheck->_tmp3->is_valid()) do_temp(opTypeCheck->_tmp3);
815 if (opTypeCheck->_result->is_valid()) do_output(opTypeCheck->_result);
816 if (opTypeCheck->_stub != nullptr) do_stub(opTypeCheck->_stub);
817 break;
818 }
819
820 // LIR_OpCompareAndSwap
821 case lir_cas_long:
822 case lir_cas_obj:
823 case lir_cas_int: {
824 assert(op->as_OpCompareAndSwap() != nullptr, "must be");
825 LIR_OpCompareAndSwap* opCmpAndSwap = (LIR_OpCompareAndSwap*)op;
826
827 if (opCmpAndSwap->_info) do_info(opCmpAndSwap->_info);
828 assert(opCmpAndSwap->_addr->is_valid(), "used"); do_input(opCmpAndSwap->_addr);
829 do_temp(opCmpAndSwap->_addr);
830 assert(opCmpAndSwap->_cmp_value->is_valid(), "used"); do_input(opCmpAndSwap->_cmp_value);
831 do_temp(opCmpAndSwap->_cmp_value);
832 assert(opCmpAndSwap->_new_value->is_valid(), "used"); do_input(opCmpAndSwap->_new_value);
833 do_temp(opCmpAndSwap->_new_value);
834 if (opCmpAndSwap->_tmp1->is_valid()) do_temp(opCmpAndSwap->_tmp1);
835 if (opCmpAndSwap->_tmp2->is_valid()) do_temp(opCmpAndSwap->_tmp2);
836 if (opCmpAndSwap->_result->is_valid()) do_output(opCmpAndSwap->_result);
837
838 break;
839 }
877 case lir_profile_call: {
878 assert(op->as_OpProfileCall() != nullptr, "must be");
879 LIR_OpProfileCall* opProfileCall = (LIR_OpProfileCall*)op;
880
881 if (opProfileCall->_recv->is_valid()) do_temp(opProfileCall->_recv);
882 assert(opProfileCall->_mdo->is_valid(), "used"); do_temp(opProfileCall->_mdo);
883 assert(opProfileCall->_tmp1->is_valid(), "used"); do_temp(opProfileCall->_tmp1);
884 break;
885 }
886
887 // LIR_OpProfileType:
888 case lir_profile_type: {
889 assert(op->as_OpProfileType() != nullptr, "must be");
890 LIR_OpProfileType* opProfileType = (LIR_OpProfileType*)op;
891
892 do_input(opProfileType->_mdp); do_temp(opProfileType->_mdp);
893 do_input(opProfileType->_obj);
894 do_temp(opProfileType->_tmp);
895 break;
896 }
897 default:
898 op->visit(this);
899 }
900 }
901
902 void LIR_Op::visit(LIR_OpVisitState* state) {
903 ShouldNotReachHere();
904 }
905
906 void LIR_OpVisitState::do_stub(CodeStub* stub) {
907 if (stub != nullptr) {
908 stub->visit(this);
909 }
910 }
911
912 XHandlers* LIR_OpVisitState::all_xhandler() {
913 XHandlers* result = nullptr;
914
915 int i;
916 for (i = 0; i < info_count(); i++) {
917 if (info_at(i)->exception_handlers() != nullptr) {
950 !has_slow_case();
951 }
952 #endif
953
954 // LIR_OpReturn
955 LIR_OpReturn::LIR_OpReturn(LIR_Opr opr) :
956 LIR_Op1(lir_return, opr, (CodeEmitInfo*)nullptr /* info */),
957 _stub(nullptr) {
958 if (VM_Version::supports_stack_watermark_barrier()) {
959 _stub = new C1SafepointPollStub();
960 }
961 }
962
963 //---------------------------------------------------
964
965
966 void LIR_OpJavaCall::emit_code(LIR_Assembler* masm) {
967 masm->emit_call(this);
968 }
969
970 void LIR_OpRTCall::emit_code(LIR_Assembler* masm) {
971 masm->emit_rtcall(this);
972 }
973
974 void LIR_OpLabel::emit_code(LIR_Assembler* masm) {
975 masm->emit_opLabel(this);
976 }
977
978 void LIR_OpArrayCopy::emit_code(LIR_Assembler* masm) {
979 masm->emit_arraycopy(this);
980 ArrayCopyStub* code_stub = stub();
981 if (code_stub != nullptr) {
982 masm->append_code_stub(code_stub);
983 }
984 }
985
986 void LIR_OpUpdateCRC32::emit_code(LIR_Assembler* masm) {
987 masm->emit_updatecrc32(this);
988 }
989
1013 masm->append_code_stub(stub());
1014 }
1015 }
1016
1017 void LIR_Op2::emit_code(LIR_Assembler* masm) {
1018 masm->emit_op2(this);
1019 }
1020
1021 void LIR_OpAllocArray::emit_code(LIR_Assembler* masm) {
1022 masm->emit_alloc_array(this);
1023 masm->append_code_stub(stub());
1024 }
1025
1026 void LIR_OpTypeCheck::emit_code(LIR_Assembler* masm) {
1027 masm->emit_opTypeCheck(this);
1028 if (stub()) {
1029 masm->append_code_stub(stub());
1030 }
1031 }
1032
1033 void LIR_OpCompareAndSwap::emit_code(LIR_Assembler* masm) {
1034 masm->emit_compare_and_swap(this);
1035 }
1036
1037 void LIR_Op3::emit_code(LIR_Assembler* masm) {
1038 masm->emit_op3(this);
1039 }
1040
1041 void LIR_Op4::emit_code(LIR_Assembler* masm) {
1042 masm->emit_op4(this);
1043 }
1044
1045 void LIR_OpLock::emit_code(LIR_Assembler* masm) {
1046 masm->emit_lock(this);
1047 if (stub()) {
1048 masm->append_code_stub(stub());
1049 }
1050 }
1051
1052 void LIR_OpLoadKlass::emit_code(LIR_Assembler* masm) {
1053 masm->emit_load_klass(this);
1054 }
1055
1056 #ifdef ASSERT
1057 void LIR_OpAssert::emit_code(LIR_Assembler* masm) {
1058 masm->emit_assert(this);
1059 }
1060 #endif
1061
1062 void LIR_OpProfileCall::emit_code(LIR_Assembler* masm) {
1063 masm->emit_profile_call(this);
1064 }
1065
1066 void LIR_OpProfileType::emit_code(LIR_Assembler* masm) {
1067 masm->emit_profile_type(this);
1068 }
1069
1070 // LIR_List
1071 LIR_List::LIR_List(Compilation* compilation, BlockBegin* block)
1072 : _operations(8)
1073 , _compilation(compilation)
1074 #ifndef PRODUCT
1075 , _block(block)
1076 #endif
1077 #ifdef ASSERT
1078 , _file(nullptr)
1079 , _line(0)
1080 #endif
1081 #ifdef RISCV
1082 , _cmp_opr1(LIR_OprFact::illegalOpr)
1083 , _cmp_opr2(LIR_OprFact::illegalOpr)
1084 #endif
1085 { }
1086
1087
1088 #ifdef ASSERT
1089 void LIR_List::set_file_and_line(const char * file, int line) {
1325 reg,
1326 LIR_OprFact::address(addr),
1327 info));
1328 }
1329
1330 void LIR_List::allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4,
1331 int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub) {
1332 append(new LIR_OpAllocObj(
1333 klass,
1334 dst,
1335 t1,
1336 t2,
1337 t3,
1338 t4,
1339 header_size,
1340 object_size,
1341 init_check,
1342 stub));
1343 }
1344
1345 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 zero_array) {
1346 append(new LIR_OpAllocArray(
1347 klass,
1348 len,
1349 dst,
1350 t1,
1351 t2,
1352 t3,
1353 t4,
1354 type,
1355 stub,
1356 zero_array));
1357 }
1358
1359 void LIR_List::shift_left(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1360 append(new LIR_Op2(
1361 lir_shl,
1362 value,
1363 count,
1364 dst,
1365 tmp));
1366 }
1367
1368 void LIR_List::shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1369 append(new LIR_Op2(
1370 lir_shr,
1371 value,
1372 count,
1373 dst,
1374 tmp));
1375 }
1376
1377
1378 void LIR_List::unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1379 append(new LIR_Op2(
1380 lir_ushr,
1381 value,
1382 count,
1383 dst,
1384 tmp));
1385 }
1386
1387 void LIR_List::fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less) {
1388 append(new LIR_Op2(is_unordered_less ? lir_ucmp_fd2i : lir_cmp_fd2i,
1389 left,
1390 right,
1391 dst));
1392 }
1393
1394 void LIR_List::lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info) {
1395 append(new LIR_OpLock(
1396 lir_lock,
1397 hdr,
1398 obj,
1399 lock,
1400 scratch,
1401 stub,
1402 info));
1403 }
1404
1405 void LIR_List::unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub) {
1406 append(new LIR_OpLock(
1407 lir_unlock,
1408 hdr,
1409 obj,
1410 lock,
1411 scratch,
1412 stub,
1413 nullptr));
1414 }
1415
1416
1417 void check_LIR() {
1418 // cannot do the proper checking as PRODUCT and other modes return different results
1419 // guarantee(sizeof(LIR_Opr) == wordSize, "may not have a v-table");
1420 }
1421
1422
1423
1424 void LIR_List::checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
1425 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1426 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
1427 ciMethod* profiled_method, int profiled_bci) {
1428 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_checkcast, result, object, klass,
1429 tmp1, tmp2, tmp3, fast_check, info_for_exception, info_for_patch, stub);
1430 if (profiled_method != nullptr && TypeProfileCasts) {
1431 c->set_profiled_method(profiled_method);
1432 c->set_profiled_bci(profiled_bci);
1433 c->set_should_profile(true);
1434 }
1435 append(c);
1436 }
1437
1438 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) {
1439 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_instanceof, result, object, klass, tmp1, tmp2, tmp3, fast_check, nullptr, info_for_patch, nullptr);
1440 if (profiled_method != nullptr && TypeProfileCasts) {
1441 c->set_profiled_method(profiled_method);
1442 c->set_profiled_bci(profiled_bci);
1443 c->set_should_profile(true);
1444 }
1445 append(c);
1446 }
1447
1448
1449 void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
1450 CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci) {
1451 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception);
1452 if (profiled_method != nullptr && TypeProfileCasts) {
1453 c->set_profiled_method(profiled_method);
1454 c->set_profiled_bci(profiled_bci);
1455 c->set_should_profile(true);
1456 }
1457 append(c);
1458 }
1459
1460 void LIR_List::null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null) {
1461 if (deoptimize_on_null) {
1462 // Emit an explicit null check and deoptimize if opr is null
1463 CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check, Deoptimization::Action_none);
1464 cmp(lir_cond_equal, opr, LIR_OprFact::oopConst(nullptr));
1465 branch(lir_cond_equal, deopt);
1466 } else {
1467 // Emit an implicit null check
1468 append(new LIR_Op1(lir_null_check, opr, info));
1469 }
1470 }
1471
1472 void LIR_List::cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1473 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1474 append(new LIR_OpCompareAndSwap(lir_cas_long, addr, cmp_value, new_value, t1, t2, result));
1475 }
1476
1477 void LIR_List::cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1478 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1479 append(new LIR_OpCompareAndSwap(lir_cas_obj, addr, cmp_value, new_value, t1, t2, result));
1480 }
1481
1482 void LIR_List::cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1483 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1484 append(new LIR_OpCompareAndSwap(lir_cas_int, addr, cmp_value, new_value, t1, t2, result));
1485 }
1486
1487
1488 #ifdef PRODUCT
1489
1490 void print_LIR(BlockList* blocks) {
1491 }
1667 }
1668
1669 const char * LIR_Op::name() const {
1670 const char* s = nullptr;
1671 switch(code()) {
1672 // LIR_Op0
1673 case lir_membar: s = "membar"; break;
1674 case lir_membar_acquire: s = "membar_acquire"; break;
1675 case lir_membar_release: s = "membar_release"; break;
1676 case lir_membar_loadload: s = "membar_loadload"; break;
1677 case lir_membar_storestore: s = "membar_storestore"; break;
1678 case lir_membar_loadstore: s = "membar_loadstore"; break;
1679 case lir_membar_storeload: s = "membar_storeload"; break;
1680 case lir_label: s = "label"; break;
1681 case lir_nop: s = "nop"; break;
1682 case lir_on_spin_wait: s = "on_spin_wait"; break;
1683 case lir_std_entry: s = "std_entry"; break;
1684 case lir_osr_entry: s = "osr_entry"; break;
1685 case lir_breakpoint: s = "breakpoint"; break;
1686 case lir_get_thread: s = "get_thread"; break;
1687 // LIR_Op1
1688 case lir_push: s = "push"; break;
1689 case lir_pop: s = "pop"; break;
1690 case lir_null_check: s = "null_check"; break;
1691 case lir_return: s = "return"; break;
1692 case lir_safepoint: s = "safepoint"; break;
1693 case lir_leal: s = "leal"; break;
1694 case lir_branch: s = "branch"; break;
1695 case lir_cond_float_branch: s = "flt_cond_br"; break;
1696 case lir_move: s = "move"; break;
1697 case lir_abs: s = "abs"; break;
1698 case lir_neg: s = "neg"; break;
1699 case lir_sqrt: s = "sqrt"; break;
1700 case lir_f2hf: s = "f2hf"; break;
1701 case lir_hf2f: s = "hf2f"; break;
1702 case lir_rtcall: s = "rtcall"; break;
1703 case lir_throw: s = "throw"; break;
1704 case lir_unwind: s = "unwind"; break;
1705 case lir_convert: s = "convert"; break;
1706 case lir_alloc_object: s = "alloc_obj"; break;
1730 case lir_fmad: s = "fmad"; break;
1731 case lir_fmaf: s = "fmaf"; break;
1732 // LIR_Op4
1733 case lir_cmove: s = "cmove"; break;
1734 // LIR_OpJavaCall
1735 case lir_static_call: s = "static"; break;
1736 case lir_optvirtual_call: s = "optvirtual"; break;
1737 case lir_icvirtual_call: s = "icvirtual"; break;
1738 case lir_dynamic_call: s = "dynamic"; break;
1739 // LIR_OpArrayCopy
1740 case lir_arraycopy: s = "arraycopy"; break;
1741 // LIR_OpUpdateCRC32
1742 case lir_updatecrc32: s = "updatecrc32"; break;
1743 // LIR_OpLock
1744 case lir_lock: s = "lock"; break;
1745 case lir_unlock: s = "unlock"; break;
1746 // LIR_OpTypeCheck
1747 case lir_instanceof: s = "instanceof"; break;
1748 case lir_checkcast: s = "checkcast"; break;
1749 case lir_store_check: s = "store_check"; break;
1750 // LIR_OpCompareAndSwap
1751 case lir_cas_long: s = "cas_long"; break;
1752 case lir_cas_obj: s = "cas_obj"; break;
1753 case lir_cas_int: s = "cas_int"; break;
1754 // LIR_OpProfileCall
1755 case lir_profile_call: s = "profile_call"; break;
1756 // LIR_OpProfileType
1757 case lir_profile_type: s = "profile_type"; break;
1758 // LIR_OpAssert
1759 #ifdef ASSERT
1760 case lir_assert: s = "assert"; break;
1761 #endif
1762 case lir_none: ShouldNotReachHere();break;
1763 default: s = "illegal_op"; break;
1764 }
1765 return s;
1766 }
1767
1768 // LIR_OpJavaCall
1769 void LIR_OpJavaCall::print_instr(outputStream* out) const {
1770 out->print("call: ");
1771 out->print("[addr: " INTPTR_FORMAT "]", p2i(address()));
1772 if (receiver()->is_valid()) {
1773 out->print(" [recv: "); receiver()->print(out); out->print("]");
1774 }
1775 if (result_opr()->is_valid()) {
1776 out->print(" [result: "); result_opr()->print(out); out->print("]");
1777 }
1963 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
1964 }
1965
1966
1967 void LIR_OpTypeCheck::print_instr(outputStream* out) const {
1968 object()->print(out); out->print(" ");
1969 if (code() == lir_store_check) {
1970 array()->print(out); out->print(" ");
1971 }
1972 if (code() != lir_store_check) {
1973 klass()->print_name_on(out); out->print(" ");
1974 if (fast_check()) out->print("fast_check ");
1975 }
1976 tmp1()->print(out); out->print(" ");
1977 tmp2()->print(out); out->print(" ");
1978 tmp3()->print(out); out->print(" ");
1979 result_opr()->print(out); out->print(" ");
1980 if (info_for_exception() != nullptr) out->print(" [bci:%d]", info_for_exception()->stack()->bci());
1981 }
1982
1983
1984 // LIR_Op3
1985 void LIR_Op3::print_instr(outputStream* out) const {
1986 in_opr1()->print(out); out->print(" ");
1987 in_opr2()->print(out); out->print(" ");
1988 in_opr3()->print(out); out->print(" ");
1989 result_opr()->print(out);
1990 }
1991
1992 // LIR_Op4
1993 void LIR_Op4::print_instr(outputStream* out) const {
1994 print_condition(out, condition()); out->print(" ");
1995 in_opr1()->print(out); out->print(" ");
1996 in_opr2()->print(out); out->print(" ");
1997 in_opr3()->print(out); out->print(" ");
1998 in_opr4()->print(out); out->print(" ");
1999 result_opr()->print(out);
2000 }
2001
2002 void LIR_OpLock::print_instr(outputStream* out) const {
2033 mdo()->print(out); out->print(" ");
2034 recv()->print(out); out->print(" ");
2035 tmp1()->print(out); out->print(" ");
2036 }
2037
2038 // LIR_OpProfileType
2039 void LIR_OpProfileType::print_instr(outputStream* out) const {
2040 out->print("exact = ");
2041 if (exact_klass() == nullptr) {
2042 out->print("unknown");
2043 } else {
2044 exact_klass()->print_name_on(out);
2045 }
2046 out->print(" current = "); ciTypeEntries::print_ciklass(out, current_klass());
2047 out->print(" ");
2048 mdp()->print(out); out->print(" ");
2049 obj()->print(out); out->print(" ");
2050 tmp()->print(out); out->print(" ");
2051 }
2052
2053 #endif // PRODUCT
2054
2055 // Implementation of LIR_InsertionBuffer
2056
2057 void LIR_InsertionBuffer::append(int index, LIR_Op* op) {
2058 assert(_index_and_count.length() % 2 == 0, "must have a count for each index");
2059
2060 int i = number_of_insertion_points() - 1;
2061 if (i < 0 || index_at(i) < index) {
2062 append_new(index, 1);
2063 } else {
2064 assert(index_at(i) == index, "can append LIR_Ops in ascending order only");
2065 assert(count_at(i) > 0, "check");
2066 set_count_at(i, count_at(i) + 1);
2067 }
2068 _ops.push(op);
2069
2070 DEBUG_ONLY(verify());
2071 }
2072
|
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 "c1/c1_CodeStubs.hpp"
26 #include "c1/c1_InstructionPrinter.hpp"
27 #include "c1/c1_LIR.hpp"
28 #include "c1/c1_LIRAssembler.hpp"
29 #include "c1/c1_ValueStack.hpp"
30 #include "ci/ciInlineKlass.hpp"
31 #include "ci/ciInstance.hpp"
32 #include "runtime/safepointMechanism.inline.hpp"
33 #include "runtime/sharedRuntime.hpp"
34 #include "runtime/vm_version.hpp"
35
36 Register LIR_Opr::as_register() const {
37 return FrameMap::cpu_rnr2reg(cpu_regnr());
38 }
39
40 Register LIR_Opr::as_register_lo() const {
41 return FrameMap::cpu_rnr2reg(cpu_regnrLo());
42 }
43
44 Register LIR_Opr::as_register_hi() const {
45 return FrameMap::cpu_rnr2reg(cpu_regnrHi());
46 }
47
48 LIR_Opr LIR_OprFact::illegalOpr = LIR_OprFact::illegal();
49 LIR_Opr LIR_OprFact::nullOpr = LIR_Opr();
50
270 assert(_ublock != nullptr, "must have old block");
271 _ublock = b;
272 }
273
274 void LIR_OpBranch::negate_cond() {
275 switch (cond()) {
276 case lir_cond_equal: set_cond(lir_cond_notEqual); break;
277 case lir_cond_notEqual: set_cond(lir_cond_equal); break;
278 case lir_cond_less: set_cond(lir_cond_greaterEqual); break;
279 case lir_cond_lessEqual: set_cond(lir_cond_greater); break;
280 case lir_cond_greaterEqual: set_cond(lir_cond_less); break;
281 case lir_cond_greater: set_cond(lir_cond_lessEqual); break;
282 default: ShouldNotReachHere();
283 }
284 }
285
286
287 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
288 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
289 bool fast_check, CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch,
290 CodeStub* stub, bool need_null_check)
291
292 : LIR_Op(code, result, nullptr)
293 , _object(object)
294 , _array(LIR_OprFact::illegalOpr)
295 , _klass(klass)
296 , _tmp1(tmp1)
297 , _tmp2(tmp2)
298 , _tmp3(tmp3)
299 , _info_for_patch(info_for_patch)
300 , _info_for_exception(info_for_exception)
301 , _stub(stub)
302 , _profiled_method(nullptr)
303 , _profiled_bci(-1)
304 , _should_profile(false)
305 , _fast_check(fast_check)
306 , _need_null_check(need_null_check)
307 {
308 if (code == lir_checkcast) {
309 assert(info_for_exception != nullptr, "checkcast throws exceptions");
310 } else if (code == lir_instanceof) {
311 assert(info_for_exception == nullptr, "instanceof throws no exceptions");
312 } else {
313 ShouldNotReachHere();
314 }
315 }
316
317
318
319 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)
320 : LIR_Op(code, LIR_OprFact::illegalOpr, nullptr)
321 , _object(object)
322 , _array(array)
323 , _klass(nullptr)
324 , _tmp1(tmp1)
325 , _tmp2(tmp2)
326 , _tmp3(tmp3)
327 , _info_for_patch(nullptr)
328 , _info_for_exception(info_for_exception)
329 , _stub(nullptr)
330 , _profiled_method(nullptr)
331 , _profiled_bci(-1)
332 , _should_profile(false)
333 , _fast_check(false)
334 , _need_null_check(true)
335 {
336 if (code == lir_store_check) {
337 _stub = new ArrayStoreExceptionStub(object, info_for_exception);
338 assert(info_for_exception != nullptr, "store_check throws exceptions");
339 } else {
340 ShouldNotReachHere();
341 }
342 }
343
344 LIR_OpFlattenedArrayCheck::LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub)
345 : LIR_Op(lir_flat_array_check, LIR_OprFact::illegalOpr, nullptr)
346 , _array(array)
347 , _value(value)
348 , _tmp(tmp)
349 , _stub(stub) {}
350
351
352 LIR_OpNullFreeArrayCheck::LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp)
353 : LIR_Op(lir_null_free_array_check, LIR_OprFact::illegalOpr, nullptr)
354 , _array(array)
355 , _tmp(tmp) {}
356
357
358 LIR_OpSubstitutabilityCheck::LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
359 LIR_Opr tmp1, LIR_Opr tmp2,
360 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
361 CodeEmitInfo* info, CodeStub* stub)
362 : LIR_Op(lir_substitutability_check, result, info)
363 , _left(left)
364 , _right(right)
365 , _equal_result(equal_result)
366 , _not_equal_result(not_equal_result)
367 , _tmp1(tmp1)
368 , _tmp2(tmp2)
369 , _left_klass(left_klass)
370 , _right_klass(right_klass)
371 , _left_klass_op(left_klass_op)
372 , _right_klass_op(right_klass_op)
373 , _stub(stub) {}
374
375
376 LIR_OpArrayCopy::LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length,
377 LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info)
378 : LIR_Op(lir_arraycopy, LIR_OprFact::illegalOpr, info)
379 , _src(src)
380 , _src_pos(src_pos)
381 , _dst(dst)
382 , _dst_pos(dst_pos)
383 , _length(length)
384 , _tmp(tmp)
385 , _expected_type(expected_type)
386 , _flags(flags) {
387 #if defined(X86) || defined(AARCH64) || defined(S390) || defined(RISCV64) || defined(PPC64)
388 if (expected_type != nullptr &&
389 ((flags & ~LIR_OpArrayCopy::get_initial_copy_flags()) == 0)) {
390 _stub = nullptr;
391 } else {
392 _stub = new ArrayCopyStub(this);
393 }
394 #else
429 // complete rework of LIR instruction visitor.
430 // The virtual call for each instruction type is replaced by a big
431 // switch that adds the operands for each instruction
432
433 void LIR_OpVisitState::visit(LIR_Op* op) {
434 // copy information from the LIR_Op
435 reset();
436 set_op(op);
437
438 switch (op->code()) {
439
440 // LIR_Op0
441 case lir_breakpoint: // result and info always invalid
442 case lir_membar: // result and info always invalid
443 case lir_membar_acquire: // result and info always invalid
444 case lir_membar_release: // result and info always invalid
445 case lir_membar_loadload: // result and info always invalid
446 case lir_membar_storestore: // result and info always invalid
447 case lir_membar_loadstore: // result and info always invalid
448 case lir_membar_storeload: // result and info always invalid
449 case lir_check_orig_pc: // result and info always invalid
450 case lir_on_spin_wait:
451 {
452 assert(op->as_Op0() != nullptr, "must be");
453 assert(op->_info == nullptr, "info not used by this instruction");
454 assert(op->_result->is_illegal(), "not used");
455 break;
456 }
457
458 case lir_nop: // may have info, result always invalid
459 case lir_std_entry: // may have result, info always invalid
460 case lir_osr_entry: // may have result, info always invalid
461 case lir_get_thread: // may have result, info always invalid
462 {
463 assert(op->as_Op0() != nullptr, "must be");
464 if (op->_info != nullptr) do_info(op->_info);
465 if (op->_result->is_valid()) do_output(op->_result);
466 break;
467 }
468
469
808
809
810 // LIR_OpLock
811 case lir_lock:
812 case lir_unlock: {
813 assert(op->as_OpLock() != nullptr, "must be");
814 LIR_OpLock* opLock = (LIR_OpLock*)op;
815
816 if (opLock->_info) do_info(opLock->_info);
817
818 // TODO: check if these operands really have to be temp
819 // (or if input is sufficient). This may have influence on the oop map!
820 assert(opLock->_lock->is_valid(), "used"); do_temp(opLock->_lock);
821 assert(opLock->_hdr->is_valid(), "used"); do_temp(opLock->_hdr);
822 assert(opLock->_obj->is_valid(), "used"); do_temp(opLock->_obj);
823
824 if (opLock->_scratch->is_valid()) do_temp(opLock->_scratch);
825 assert(opLock->_result->is_illegal(), "unused");
826
827 do_stub(opLock->_stub);
828 do_stub(opLock->_throw_ie_stub);
829
830 break;
831 }
832
833
834 // LIR_OpTypeCheck
835 case lir_instanceof:
836 case lir_checkcast:
837 case lir_store_check: {
838 assert(op->as_OpTypeCheck() != nullptr, "must be");
839 LIR_OpTypeCheck* opTypeCheck = (LIR_OpTypeCheck*)op;
840
841 if (opTypeCheck->_info_for_exception) do_info(opTypeCheck->_info_for_exception);
842 if (opTypeCheck->_info_for_patch) do_info(opTypeCheck->_info_for_patch);
843 if (opTypeCheck->_object->is_valid()) do_input(opTypeCheck->_object);
844 if (op->code() == lir_store_check && opTypeCheck->_object->is_valid()) {
845 do_temp(opTypeCheck->_object);
846 }
847 if (opTypeCheck->_array->is_valid()) do_input(opTypeCheck->_array);
848 if (opTypeCheck->_tmp1->is_valid()) do_temp(opTypeCheck->_tmp1);
849 if (opTypeCheck->_tmp2->is_valid()) do_temp(opTypeCheck->_tmp2);
850 if (opTypeCheck->_tmp3->is_valid()) do_temp(opTypeCheck->_tmp3);
851 if (opTypeCheck->_result->is_valid()) do_output(opTypeCheck->_result);
852 if (opTypeCheck->_stub != nullptr) do_stub(opTypeCheck->_stub);
853 break;
854 }
855
856 // LIR_OpFlattenedArrayCheck
857 case lir_flat_array_check: {
858 assert(op->as_OpFlattenedArrayCheck() != nullptr, "must be");
859 LIR_OpFlattenedArrayCheck* opFlattenedArrayCheck = (LIR_OpFlattenedArrayCheck*)op;
860
861 if (opFlattenedArrayCheck->_array->is_valid()) do_input(opFlattenedArrayCheck->_array);
862 if (opFlattenedArrayCheck->_value->is_valid()) do_input(opFlattenedArrayCheck->_value);
863 if (opFlattenedArrayCheck->_tmp->is_valid()) do_temp(opFlattenedArrayCheck->_tmp);
864
865 do_stub(opFlattenedArrayCheck->_stub);
866
867 break;
868 }
869
870 // LIR_OpNullFreeArrayCheck
871 case lir_null_free_array_check: {
872 assert(op->as_OpNullFreeArrayCheck() != nullptr, "must be");
873 LIR_OpNullFreeArrayCheck* opNullFreeArrayCheck = (LIR_OpNullFreeArrayCheck*)op;
874
875 if (opNullFreeArrayCheck->_array->is_valid()) do_input(opNullFreeArrayCheck->_array);
876 if (opNullFreeArrayCheck->_tmp->is_valid()) do_temp(opNullFreeArrayCheck->_tmp);
877 break;
878 }
879
880 // LIR_OpSubstitutabilityCheck
881 case lir_substitutability_check: {
882 assert(op->as_OpSubstitutabilityCheck() != nullptr, "must be");
883 LIR_OpSubstitutabilityCheck* opSubstitutabilityCheck = (LIR_OpSubstitutabilityCheck*)op;
884 do_input(opSubstitutabilityCheck->_left);
885 do_temp (opSubstitutabilityCheck->_left);
886 do_input(opSubstitutabilityCheck->_right);
887 do_temp (opSubstitutabilityCheck->_right);
888 do_input(opSubstitutabilityCheck->_equal_result);
889 do_temp (opSubstitutabilityCheck->_equal_result);
890 do_input(opSubstitutabilityCheck->_not_equal_result);
891 do_temp (opSubstitutabilityCheck->_not_equal_result);
892 if (opSubstitutabilityCheck->_tmp1->is_valid()) do_temp(opSubstitutabilityCheck->_tmp1);
893 if (opSubstitutabilityCheck->_tmp2->is_valid()) do_temp(opSubstitutabilityCheck->_tmp2);
894 if (opSubstitutabilityCheck->_left_klass_op->is_valid()) do_temp(opSubstitutabilityCheck->_left_klass_op);
895 if (opSubstitutabilityCheck->_right_klass_op->is_valid()) do_temp(opSubstitutabilityCheck->_right_klass_op);
896 if (opSubstitutabilityCheck->_result->is_valid()) do_output(opSubstitutabilityCheck->_result);
897
898 do_info(opSubstitutabilityCheck->_info);
899 do_stub(opSubstitutabilityCheck->_stub);
900 break;
901 }
902
903 // LIR_OpCompareAndSwap
904 case lir_cas_long:
905 case lir_cas_obj:
906 case lir_cas_int: {
907 assert(op->as_OpCompareAndSwap() != nullptr, "must be");
908 LIR_OpCompareAndSwap* opCmpAndSwap = (LIR_OpCompareAndSwap*)op;
909
910 if (opCmpAndSwap->_info) do_info(opCmpAndSwap->_info);
911 assert(opCmpAndSwap->_addr->is_valid(), "used"); do_input(opCmpAndSwap->_addr);
912 do_temp(opCmpAndSwap->_addr);
913 assert(opCmpAndSwap->_cmp_value->is_valid(), "used"); do_input(opCmpAndSwap->_cmp_value);
914 do_temp(opCmpAndSwap->_cmp_value);
915 assert(opCmpAndSwap->_new_value->is_valid(), "used"); do_input(opCmpAndSwap->_new_value);
916 do_temp(opCmpAndSwap->_new_value);
917 if (opCmpAndSwap->_tmp1->is_valid()) do_temp(opCmpAndSwap->_tmp1);
918 if (opCmpAndSwap->_tmp2->is_valid()) do_temp(opCmpAndSwap->_tmp2);
919 if (opCmpAndSwap->_result->is_valid()) do_output(opCmpAndSwap->_result);
920
921 break;
922 }
960 case lir_profile_call: {
961 assert(op->as_OpProfileCall() != nullptr, "must be");
962 LIR_OpProfileCall* opProfileCall = (LIR_OpProfileCall*)op;
963
964 if (opProfileCall->_recv->is_valid()) do_temp(opProfileCall->_recv);
965 assert(opProfileCall->_mdo->is_valid(), "used"); do_temp(opProfileCall->_mdo);
966 assert(opProfileCall->_tmp1->is_valid(), "used"); do_temp(opProfileCall->_tmp1);
967 break;
968 }
969
970 // LIR_OpProfileType:
971 case lir_profile_type: {
972 assert(op->as_OpProfileType() != nullptr, "must be");
973 LIR_OpProfileType* opProfileType = (LIR_OpProfileType*)op;
974
975 do_input(opProfileType->_mdp); do_temp(opProfileType->_mdp);
976 do_input(opProfileType->_obj);
977 do_temp(opProfileType->_tmp);
978 break;
979 }
980
981 // LIR_OpProfileInlineType:
982 case lir_profile_inline_type: {
983 assert(op->as_OpProfileInlineType() != nullptr, "must be");
984 LIR_OpProfileInlineType* opProfileInlineType = (LIR_OpProfileInlineType*)op;
985
986 do_input(opProfileInlineType->_mdp); do_temp(opProfileInlineType->_mdp);
987 do_input(opProfileInlineType->_obj);
988 do_temp(opProfileInlineType->_tmp);
989 break;
990 }
991 default:
992 op->visit(this);
993 }
994 }
995
996 void LIR_Op::visit(LIR_OpVisitState* state) {
997 ShouldNotReachHere();
998 }
999
1000 void LIR_OpVisitState::do_stub(CodeStub* stub) {
1001 if (stub != nullptr) {
1002 stub->visit(this);
1003 }
1004 }
1005
1006 XHandlers* LIR_OpVisitState::all_xhandler() {
1007 XHandlers* result = nullptr;
1008
1009 int i;
1010 for (i = 0; i < info_count(); i++) {
1011 if (info_at(i)->exception_handlers() != nullptr) {
1044 !has_slow_case();
1045 }
1046 #endif
1047
1048 // LIR_OpReturn
1049 LIR_OpReturn::LIR_OpReturn(LIR_Opr opr) :
1050 LIR_Op1(lir_return, opr, (CodeEmitInfo*)nullptr /* info */),
1051 _stub(nullptr) {
1052 if (VM_Version::supports_stack_watermark_barrier()) {
1053 _stub = new C1SafepointPollStub();
1054 }
1055 }
1056
1057 //---------------------------------------------------
1058
1059
1060 void LIR_OpJavaCall::emit_code(LIR_Assembler* masm) {
1061 masm->emit_call(this);
1062 }
1063
1064 bool LIR_OpJavaCall::maybe_return_as_fields(ciInlineKlass** vk_ret) const {
1065 ciType* return_type = method()->return_type();
1066 if (InlineTypeReturnedAsFields) {
1067 if (return_type->is_inlinetype()) {
1068 ciInlineKlass* vk = return_type->as_inline_klass();
1069 if (vk->can_be_returned_as_fields()) {
1070 if (vk_ret != nullptr) {
1071 *vk_ret = vk;
1072 }
1073 return true;
1074 }
1075 } else if (return_type->is_instance_klass() &&
1076 (method()->is_method_handle_intrinsic() || !return_type->is_loaded() ||
1077 StressCallingConvention)) {
1078 // An inline type might be returned from the call but we don't know its type.
1079 // This can happen with method handle intrinsics or when the return type is
1080 // not loaded (method holder is not loaded or preload attribute is missing).
1081 // If an inline type is returned, we either get an oop to a buffer and nothing
1082 // needs to be done or one of the values being returned is the klass of the
1083 // inline type (RAX on x64, with LSB set to 1) and we need to allocate an inline
1084 // type instance of that type and initialize it with the fields values being
1085 // returned in other registers.
1086 return true;
1087 }
1088 }
1089 return false;
1090 }
1091
1092 void LIR_OpRTCall::emit_code(LIR_Assembler* masm) {
1093 masm->emit_rtcall(this);
1094 }
1095
1096 void LIR_OpLabel::emit_code(LIR_Assembler* masm) {
1097 masm->emit_opLabel(this);
1098 }
1099
1100 void LIR_OpArrayCopy::emit_code(LIR_Assembler* masm) {
1101 masm->emit_arraycopy(this);
1102 ArrayCopyStub* code_stub = stub();
1103 if (code_stub != nullptr) {
1104 masm->append_code_stub(code_stub);
1105 }
1106 }
1107
1108 void LIR_OpUpdateCRC32::emit_code(LIR_Assembler* masm) {
1109 masm->emit_updatecrc32(this);
1110 }
1111
1135 masm->append_code_stub(stub());
1136 }
1137 }
1138
1139 void LIR_Op2::emit_code(LIR_Assembler* masm) {
1140 masm->emit_op2(this);
1141 }
1142
1143 void LIR_OpAllocArray::emit_code(LIR_Assembler* masm) {
1144 masm->emit_alloc_array(this);
1145 masm->append_code_stub(stub());
1146 }
1147
1148 void LIR_OpTypeCheck::emit_code(LIR_Assembler* masm) {
1149 masm->emit_opTypeCheck(this);
1150 if (stub()) {
1151 masm->append_code_stub(stub());
1152 }
1153 }
1154
1155 void LIR_OpFlattenedArrayCheck::emit_code(LIR_Assembler* masm) {
1156 masm->emit_opFlattenedArrayCheck(this);
1157 if (stub() != nullptr) {
1158 masm->append_code_stub(stub());
1159 }
1160 }
1161
1162 void LIR_OpNullFreeArrayCheck::emit_code(LIR_Assembler* masm) {
1163 masm->emit_opNullFreeArrayCheck(this);
1164 }
1165
1166 void LIR_OpSubstitutabilityCheck::emit_code(LIR_Assembler* masm) {
1167 masm->emit_opSubstitutabilityCheck(this);
1168 if (stub() != nullptr) {
1169 masm->append_code_stub(stub());
1170 }
1171 }
1172
1173 void LIR_OpCompareAndSwap::emit_code(LIR_Assembler* masm) {
1174 masm->emit_compare_and_swap(this);
1175 }
1176
1177 void LIR_Op3::emit_code(LIR_Assembler* masm) {
1178 masm->emit_op3(this);
1179 }
1180
1181 void LIR_Op4::emit_code(LIR_Assembler* masm) {
1182 masm->emit_op4(this);
1183 }
1184
1185 void LIR_OpLock::emit_code(LIR_Assembler* masm) {
1186 masm->emit_lock(this);
1187 if (stub()) {
1188 masm->append_code_stub(stub());
1189 }
1190 if (throw_ie_stub()) {
1191 masm->append_code_stub(throw_ie_stub());
1192 }
1193 }
1194
1195 void LIR_OpLoadKlass::emit_code(LIR_Assembler* masm) {
1196 masm->emit_load_klass(this);
1197 }
1198
1199 #ifdef ASSERT
1200 void LIR_OpAssert::emit_code(LIR_Assembler* masm) {
1201 masm->emit_assert(this);
1202 }
1203 #endif
1204
1205 void LIR_OpProfileCall::emit_code(LIR_Assembler* masm) {
1206 masm->emit_profile_call(this);
1207 }
1208
1209 void LIR_OpProfileType::emit_code(LIR_Assembler* masm) {
1210 masm->emit_profile_type(this);
1211 }
1212
1213 void LIR_OpProfileInlineType::emit_code(LIR_Assembler* masm) {
1214 masm->emit_profile_inline_type(this);
1215 }
1216
1217 // LIR_List
1218 LIR_List::LIR_List(Compilation* compilation, BlockBegin* block)
1219 : _operations(8)
1220 , _compilation(compilation)
1221 #ifndef PRODUCT
1222 , _block(block)
1223 #endif
1224 #ifdef ASSERT
1225 , _file(nullptr)
1226 , _line(0)
1227 #endif
1228 #ifdef RISCV
1229 , _cmp_opr1(LIR_OprFact::illegalOpr)
1230 , _cmp_opr2(LIR_OprFact::illegalOpr)
1231 #endif
1232 { }
1233
1234
1235 #ifdef ASSERT
1236 void LIR_List::set_file_and_line(const char * file, int line) {
1472 reg,
1473 LIR_OprFact::address(addr),
1474 info));
1475 }
1476
1477 void LIR_List::allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4,
1478 int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub) {
1479 append(new LIR_OpAllocObj(
1480 klass,
1481 dst,
1482 t1,
1483 t2,
1484 t3,
1485 t4,
1486 header_size,
1487 object_size,
1488 init_check,
1489 stub));
1490 }
1491
1492 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 zero_array, bool always_slow_path) {
1493 append(new LIR_OpAllocArray(
1494 klass,
1495 len,
1496 dst,
1497 t1,
1498 t2,
1499 t3,
1500 t4,
1501 type,
1502 stub,
1503 zero_array,
1504 always_slow_path));
1505 }
1506
1507 void LIR_List::shift_left(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1508 append(new LIR_Op2(
1509 lir_shl,
1510 value,
1511 count,
1512 dst,
1513 tmp));
1514 }
1515
1516 void LIR_List::shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1517 append(new LIR_Op2(
1518 lir_shr,
1519 value,
1520 count,
1521 dst,
1522 tmp));
1523 }
1524
1525
1526 void LIR_List::unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1527 append(new LIR_Op2(
1528 lir_ushr,
1529 value,
1530 count,
1531 dst,
1532 tmp));
1533 }
1534
1535 void LIR_List::fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less) {
1536 append(new LIR_Op2(is_unordered_less ? lir_ucmp_fd2i : lir_cmp_fd2i,
1537 left,
1538 right,
1539 dst));
1540 }
1541
1542 void LIR_List::lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub) {
1543 append(new LIR_OpLock(
1544 lir_lock,
1545 hdr,
1546 obj,
1547 lock,
1548 scratch,
1549 stub,
1550 info,
1551 throw_ie_stub));
1552 }
1553
1554 void LIR_List::unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub) {
1555 append(new LIR_OpLock(
1556 lir_unlock,
1557 hdr,
1558 obj,
1559 lock,
1560 scratch,
1561 stub,
1562 nullptr));
1563 }
1564
1565
1566 void check_LIR() {
1567 // cannot do the proper checking as PRODUCT and other modes return different results
1568 // guarantee(sizeof(LIR_Opr) == wordSize, "may not have a v-table");
1569 }
1570
1571
1572
1573 void LIR_List::checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
1574 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1575 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
1576 ciMethod* profiled_method, int profiled_bci, bool is_null_free) {
1577 // If klass is non-nullable, LIRGenerator::do_CheckCast has already performed null-check
1578 // on the object.
1579 bool need_null_check = !is_null_free;
1580 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_checkcast, result, object, klass,
1581 tmp1, tmp2, tmp3, fast_check, info_for_exception, info_for_patch, stub,
1582 need_null_check);
1583 if (profiled_method != nullptr && TypeProfileCasts) {
1584 c->set_profiled_method(profiled_method);
1585 c->set_profiled_bci(profiled_bci);
1586 c->set_should_profile(true);
1587 }
1588 append(c);
1589 }
1590
1591 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) {
1592 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_instanceof, result, object, klass, tmp1, tmp2, tmp3, fast_check, nullptr, info_for_patch, nullptr);
1593 if (profiled_method != nullptr && TypeProfileCasts) {
1594 c->set_profiled_method(profiled_method);
1595 c->set_profiled_bci(profiled_bci);
1596 c->set_should_profile(true);
1597 }
1598 append(c);
1599 }
1600
1601
1602 void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
1603 CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci) {
1604 // FIXME -- if the types of the array and/or the object are known statically, we can avoid loading the klass
1605 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception);
1606 if (profiled_method != nullptr && TypeProfileCasts) {
1607 c->set_profiled_method(profiled_method);
1608 c->set_profiled_bci(profiled_bci);
1609 c->set_should_profile(true);
1610 }
1611 append(c);
1612 }
1613
1614 void LIR_List::null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null) {
1615 if (deoptimize_on_null) {
1616 // Emit an explicit null check and deoptimize if opr is null
1617 CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check, Deoptimization::Action_none);
1618 cmp(lir_cond_equal, opr, LIR_OprFact::oopConst(nullptr));
1619 branch(lir_cond_equal, deopt);
1620 } else {
1621 // Emit an implicit null check
1622 append(new LIR_Op1(lir_null_check, opr, info));
1623 }
1624 }
1625
1626 void LIR_List::check_flat_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub) {
1627 LIR_OpFlattenedArrayCheck* c = new LIR_OpFlattenedArrayCheck(array, value, tmp, stub);
1628 append(c);
1629 }
1630
1631 void LIR_List::check_null_free_array(LIR_Opr array, LIR_Opr tmp) {
1632 LIR_OpNullFreeArrayCheck* c = new LIR_OpNullFreeArrayCheck(array, tmp);
1633 append(c);
1634 }
1635
1636 void LIR_List::substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1637 LIR_Opr tmp1, LIR_Opr tmp2,
1638 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
1639 CodeEmitInfo* info, CodeStub* stub) {
1640 LIR_OpSubstitutabilityCheck* c = new LIR_OpSubstitutabilityCheck(result, left, right, equal_result, not_equal_result,
1641 tmp1, tmp2,
1642 left_klass, right_klass, left_klass_op, right_klass_op,
1643 info, stub);
1644 append(c);
1645 }
1646
1647 void LIR_List::cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1648 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1649 append(new LIR_OpCompareAndSwap(lir_cas_long, addr, cmp_value, new_value, t1, t2, result));
1650 }
1651
1652 void LIR_List::cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1653 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1654 append(new LIR_OpCompareAndSwap(lir_cas_obj, addr, cmp_value, new_value, t1, t2, result));
1655 }
1656
1657 void LIR_List::cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1658 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1659 append(new LIR_OpCompareAndSwap(lir_cas_int, addr, cmp_value, new_value, t1, t2, result));
1660 }
1661
1662
1663 #ifdef PRODUCT
1664
1665 void print_LIR(BlockList* blocks) {
1666 }
1842 }
1843
1844 const char * LIR_Op::name() const {
1845 const char* s = nullptr;
1846 switch(code()) {
1847 // LIR_Op0
1848 case lir_membar: s = "membar"; break;
1849 case lir_membar_acquire: s = "membar_acquire"; break;
1850 case lir_membar_release: s = "membar_release"; break;
1851 case lir_membar_loadload: s = "membar_loadload"; break;
1852 case lir_membar_storestore: s = "membar_storestore"; break;
1853 case lir_membar_loadstore: s = "membar_loadstore"; break;
1854 case lir_membar_storeload: s = "membar_storeload"; break;
1855 case lir_label: s = "label"; break;
1856 case lir_nop: s = "nop"; break;
1857 case lir_on_spin_wait: s = "on_spin_wait"; break;
1858 case lir_std_entry: s = "std_entry"; break;
1859 case lir_osr_entry: s = "osr_entry"; break;
1860 case lir_breakpoint: s = "breakpoint"; break;
1861 case lir_get_thread: s = "get_thread"; break;
1862 case lir_check_orig_pc: s = "check_orig_pc"; break;
1863 // LIR_Op1
1864 case lir_push: s = "push"; break;
1865 case lir_pop: s = "pop"; break;
1866 case lir_null_check: s = "null_check"; break;
1867 case lir_return: s = "return"; break;
1868 case lir_safepoint: s = "safepoint"; break;
1869 case lir_leal: s = "leal"; break;
1870 case lir_branch: s = "branch"; break;
1871 case lir_cond_float_branch: s = "flt_cond_br"; break;
1872 case lir_move: s = "move"; break;
1873 case lir_abs: s = "abs"; break;
1874 case lir_neg: s = "neg"; break;
1875 case lir_sqrt: s = "sqrt"; break;
1876 case lir_f2hf: s = "f2hf"; break;
1877 case lir_hf2f: s = "hf2f"; break;
1878 case lir_rtcall: s = "rtcall"; break;
1879 case lir_throw: s = "throw"; break;
1880 case lir_unwind: s = "unwind"; break;
1881 case lir_convert: s = "convert"; break;
1882 case lir_alloc_object: s = "alloc_obj"; break;
1906 case lir_fmad: s = "fmad"; break;
1907 case lir_fmaf: s = "fmaf"; break;
1908 // LIR_Op4
1909 case lir_cmove: s = "cmove"; break;
1910 // LIR_OpJavaCall
1911 case lir_static_call: s = "static"; break;
1912 case lir_optvirtual_call: s = "optvirtual"; break;
1913 case lir_icvirtual_call: s = "icvirtual"; break;
1914 case lir_dynamic_call: s = "dynamic"; break;
1915 // LIR_OpArrayCopy
1916 case lir_arraycopy: s = "arraycopy"; break;
1917 // LIR_OpUpdateCRC32
1918 case lir_updatecrc32: s = "updatecrc32"; break;
1919 // LIR_OpLock
1920 case lir_lock: s = "lock"; break;
1921 case lir_unlock: s = "unlock"; break;
1922 // LIR_OpTypeCheck
1923 case lir_instanceof: s = "instanceof"; break;
1924 case lir_checkcast: s = "checkcast"; break;
1925 case lir_store_check: s = "store_check"; break;
1926 // LIR_OpFlattenedArrayCheck
1927 case lir_flat_array_check: s = "flat_array_check"; break;
1928 // LIR_OpNullFreeArrayCheck
1929 case lir_null_free_array_check: s = "null_free_array_check"; break;
1930 // LIR_OpSubstitutabilityCheck
1931 case lir_substitutability_check: s = "substitutability_check"; break;
1932 // LIR_OpCompareAndSwap
1933 case lir_cas_long: s = "cas_long"; break;
1934 case lir_cas_obj: s = "cas_obj"; break;
1935 case lir_cas_int: s = "cas_int"; break;
1936 // LIR_OpProfileCall
1937 case lir_profile_call: s = "profile_call"; break;
1938 // LIR_OpProfileType
1939 case lir_profile_type: s = "profile_type"; break;
1940 // LIR_OpProfileInlineType
1941 case lir_profile_inline_type: s = "profile_inline_type"; break;
1942 // LIR_OpAssert
1943 #ifdef ASSERT
1944 case lir_assert: s = "assert"; break;
1945 #endif
1946 case lir_none: ShouldNotReachHere();break;
1947 default: s = "illegal_op"; break;
1948 }
1949 return s;
1950 }
1951
1952 // LIR_OpJavaCall
1953 void LIR_OpJavaCall::print_instr(outputStream* out) const {
1954 out->print("call: ");
1955 out->print("[addr: " INTPTR_FORMAT "]", p2i(address()));
1956 if (receiver()->is_valid()) {
1957 out->print(" [recv: "); receiver()->print(out); out->print("]");
1958 }
1959 if (result_opr()->is_valid()) {
1960 out->print(" [result: "); result_opr()->print(out); out->print("]");
1961 }
2147 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2148 }
2149
2150
2151 void LIR_OpTypeCheck::print_instr(outputStream* out) const {
2152 object()->print(out); out->print(" ");
2153 if (code() == lir_store_check) {
2154 array()->print(out); out->print(" ");
2155 }
2156 if (code() != lir_store_check) {
2157 klass()->print_name_on(out); out->print(" ");
2158 if (fast_check()) out->print("fast_check ");
2159 }
2160 tmp1()->print(out); out->print(" ");
2161 tmp2()->print(out); out->print(" ");
2162 tmp3()->print(out); out->print(" ");
2163 result_opr()->print(out); out->print(" ");
2164 if (info_for_exception() != nullptr) out->print(" [bci:%d]", info_for_exception()->stack()->bci());
2165 }
2166
2167 void LIR_OpFlattenedArrayCheck::print_instr(outputStream* out) const {
2168 array()->print(out); out->print(" ");
2169 value()->print(out); out->print(" ");
2170 tmp()->print(out); out->print(" ");
2171 if (stub() != nullptr) {
2172 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2173 }
2174 }
2175
2176 void LIR_OpNullFreeArrayCheck::print_instr(outputStream* out) const {
2177 array()->print(out); out->print(" ");
2178 tmp()->print(out); out->print(" ");
2179 }
2180
2181 void LIR_OpSubstitutabilityCheck::print_instr(outputStream* out) const {
2182 result_opr()->print(out); out->print(" ");
2183 left()->print(out); out->print(" ");
2184 right()->print(out); out->print(" ");
2185 equal_result()->print(out); out->print(" ");
2186 not_equal_result()->print(out); out->print(" ");
2187 tmp1()->print(out); out->print(" ");
2188 tmp2()->print(out); out->print(" ");
2189 if (left_klass() == nullptr) {
2190 out->print("unknown ");
2191 } else {
2192 left_klass()->print(out); out->print(" ");
2193 }
2194 if (right_klass() == nullptr) {
2195 out->print("unknown ");
2196 } else {
2197 right_klass()->print(out); out->print(" ");
2198 }
2199 left_klass_op()->print(out); out->print(" ");
2200 right_klass_op()->print(out); out->print(" ");
2201 if (stub() != nullptr) {
2202 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2203 }
2204 }
2205
2206 // LIR_Op3
2207 void LIR_Op3::print_instr(outputStream* out) const {
2208 in_opr1()->print(out); out->print(" ");
2209 in_opr2()->print(out); out->print(" ");
2210 in_opr3()->print(out); out->print(" ");
2211 result_opr()->print(out);
2212 }
2213
2214 // LIR_Op4
2215 void LIR_Op4::print_instr(outputStream* out) const {
2216 print_condition(out, condition()); out->print(" ");
2217 in_opr1()->print(out); out->print(" ");
2218 in_opr2()->print(out); out->print(" ");
2219 in_opr3()->print(out); out->print(" ");
2220 in_opr4()->print(out); out->print(" ");
2221 result_opr()->print(out);
2222 }
2223
2224 void LIR_OpLock::print_instr(outputStream* out) const {
2255 mdo()->print(out); out->print(" ");
2256 recv()->print(out); out->print(" ");
2257 tmp1()->print(out); out->print(" ");
2258 }
2259
2260 // LIR_OpProfileType
2261 void LIR_OpProfileType::print_instr(outputStream* out) const {
2262 out->print("exact = ");
2263 if (exact_klass() == nullptr) {
2264 out->print("unknown");
2265 } else {
2266 exact_klass()->print_name_on(out);
2267 }
2268 out->print(" current = "); ciTypeEntries::print_ciklass(out, current_klass());
2269 out->print(" ");
2270 mdp()->print(out); out->print(" ");
2271 obj()->print(out); out->print(" ");
2272 tmp()->print(out); out->print(" ");
2273 }
2274
2275 // LIR_OpProfileInlineType
2276 void LIR_OpProfileInlineType::print_instr(outputStream* out) const {
2277 out->print(" flag = %x ", flag());
2278 mdp()->print(out); out->print(" ");
2279 obj()->print(out); out->print(" ");
2280 tmp()->print(out); out->print(" ");
2281 }
2282
2283 #endif // PRODUCT
2284
2285 // Implementation of LIR_InsertionBuffer
2286
2287 void LIR_InsertionBuffer::append(int index, LIR_Op* op) {
2288 assert(_index_and_count.length() % 2 == 0, "must have a count for each index");
2289
2290 int i = number_of_insertion_points() - 1;
2291 if (i < 0 || index_at(i) < index) {
2292 append_new(index, 1);
2293 } else {
2294 assert(index_at(i) == index, "can append LIR_Ops in ascending order only");
2295 assert(count_at(i) > 0, "check");
2296 set_count_at(i, count_at(i) + 1);
2297 }
2298 _ops.push(op);
2299
2300 DEBUG_ONLY(verify());
2301 }
2302
|