1 /*
2 * Copyright (c) 2000, 2025, 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 *
872 //
873 class LIR_Op;
874 class LIR_Op0;
875 class LIR_OpLabel;
876 class LIR_Op1;
877 class LIR_OpBranch;
878 class LIR_OpConvert;
879 class LIR_OpAllocObj;
880 class LIR_OpReturn;
881 class LIR_Op2;
882 class LIR_Op3;
883 class LIR_OpAllocArray;
884 class LIR_Op4;
885 class LIR_OpCall;
886 class LIR_OpJavaCall;
887 class LIR_OpRTCall;
888 class LIR_OpArrayCopy;
889 class LIR_OpUpdateCRC32;
890 class LIR_OpLock;
891 class LIR_OpTypeCheck;
892 class LIR_OpCompareAndSwap;
893 class LIR_OpLoadKlass;
894 class LIR_OpProfileCall;
895 class LIR_OpProfileType;
896 #ifdef ASSERT
897 class LIR_OpAssert;
898 #endif
899
900 // LIR operation codes
901 enum LIR_Code {
902 lir_none
903 , begin_op0
904 , lir_label
905 , lir_nop
906 , lir_std_entry
907 , lir_osr_entry
908 , lir_breakpoint
909 , lir_rtcall
910 , lir_membar
911 , lir_membar_acquire
912 , lir_membar_release
913 , lir_membar_loadload
914 , lir_membar_storestore
915 , lir_membar_loadstore
916 , lir_membar_storeload
917 , lir_get_thread
918 , lir_on_spin_wait
919 , end_op0
920 , begin_op1
921 , lir_push
922 , lir_pop
923 , lir_null_check
924 , lir_return
925 , lir_leal
926 , lir_move
927 , lir_convert
928 , lir_alloc_object
929 , lir_monaddr
930 , lir_sqrt
931 , lir_abs
932 , lir_neg
933 , lir_f2hf
934 , lir_hf2f
935 , lir_safepoint
936 , lir_unwind
937 , lir_load_klass
938 , end_op1
972 , lir_static_call
973 , lir_optvirtual_call
974 , lir_icvirtual_call
975 , lir_dynamic_call
976 , end_opJavaCall
977 , begin_opArrayCopy
978 , lir_arraycopy
979 , end_opArrayCopy
980 , begin_opUpdateCRC32
981 , lir_updatecrc32
982 , end_opUpdateCRC32
983 , begin_opLock
984 , lir_lock
985 , lir_unlock
986 , end_opLock
987 , begin_opTypeCheck
988 , lir_instanceof
989 , lir_checkcast
990 , lir_store_check
991 , end_opTypeCheck
992 , begin_opCompareAndSwap
993 , lir_cas_long
994 , lir_cas_obj
995 , lir_cas_int
996 , end_opCompareAndSwap
997 , begin_opMDOProfile
998 , lir_profile_call
999 , lir_profile_type
1000 , end_opMDOProfile
1001 , begin_opAssert
1002 , lir_assert
1003 , end_opAssert
1004 #if INCLUDE_ZGC
1005 , begin_opXLoadBarrierTest
1006 , lir_xloadbarrier_test
1007 , end_opXLoadBarrierTest
1008 #endif
1009 };
1010
1011
1012 enum LIR_Condition {
1013 lir_cond_equal
1014 , lir_cond_notEqual
1015 , lir_cond_less
1016 , lir_cond_lessEqual
1017 , lir_cond_greaterEqual
1018 , lir_cond_greater
1019 , lir_cond_belowEqual
1118
1119 virtual bool is_patching() { return false; }
1120 virtual LIR_OpCall* as_OpCall() { return nullptr; }
1121 virtual LIR_OpJavaCall* as_OpJavaCall() { return nullptr; }
1122 virtual LIR_OpLabel* as_OpLabel() { return nullptr; }
1123 virtual LIR_OpLock* as_OpLock() { return nullptr; }
1124 virtual LIR_OpAllocArray* as_OpAllocArray() { return nullptr; }
1125 virtual LIR_OpAllocObj* as_OpAllocObj() { return nullptr; }
1126 virtual LIR_OpBranch* as_OpBranch() { return nullptr; }
1127 virtual LIR_OpReturn* as_OpReturn() { return nullptr; }
1128 virtual LIR_OpRTCall* as_OpRTCall() { return nullptr; }
1129 virtual LIR_OpConvert* as_OpConvert() { return nullptr; }
1130 virtual LIR_Op0* as_Op0() { return nullptr; }
1131 virtual LIR_Op1* as_Op1() { return nullptr; }
1132 virtual LIR_Op2* as_Op2() { return nullptr; }
1133 virtual LIR_Op3* as_Op3() { return nullptr; }
1134 virtual LIR_Op4* as_Op4() { return nullptr; }
1135 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return nullptr; }
1136 virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return nullptr; }
1137 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return nullptr; }
1138 virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return nullptr; }
1139 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return nullptr; }
1140 virtual LIR_OpProfileCall* as_OpProfileCall() { return nullptr; }
1141 virtual LIR_OpProfileType* as_OpProfileType() { return nullptr; }
1142 #ifdef ASSERT
1143 virtual LIR_OpAssert* as_OpAssert() { return nullptr; }
1144 #endif
1145
1146 virtual void verify() const {}
1147 };
1148
1149 // for calls
1150 class LIR_OpCall: public LIR_Op {
1151 friend class LIR_OpVisitState;
1152
1153 protected:
1154 address _addr;
1155 LIR_OprList* _arguments;
1156 protected:
1157 LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1158 LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1159 : LIR_Op(code, result, info)
1160 , _addr(addr)
1161 , _arguments(arguments) {}
1191 LIR_Opr receiver, LIR_Opr result, intptr_t vtable_offset,
1192 LIR_OprList* arguments, CodeEmitInfo* info)
1193 : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1194 , _method(method)
1195 , _receiver(receiver)
1196 { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1197
1198 LIR_Opr receiver() const { return _receiver; }
1199 ciMethod* method() const { return _method; }
1200
1201 // JSR 292 support.
1202 bool is_invokedynamic() const { return code() == lir_dynamic_call; }
1203 bool is_method_handle_invoke() const {
1204 return method()->is_compiled_lambda_form() || // Java-generated lambda form
1205 method()->is_method_handle_intrinsic(); // JVM-generated MH intrinsic
1206 }
1207
1208 virtual void emit_code(LIR_Assembler* masm);
1209 virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1210 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1211 };
1212
1213 // --------------------------------------------------
1214 // LIR_OpLabel
1215 // --------------------------------------------------
1216 // Location where a branch can continue
1217 class LIR_OpLabel: public LIR_Op {
1218 friend class LIR_OpVisitState;
1219
1220 private:
1221 Label* _label;
1222 public:
1223 LIR_OpLabel(Label* lbl)
1224 : LIR_Op(lir_label, LIR_OprFact::illegalOpr, nullptr)
1225 , _label(lbl) {}
1226 Label* label() const { return _label; }
1227
1228 virtual void emit_code(LIR_Assembler* masm);
1229 virtual LIR_OpLabel* as_OpLabel() { return this; }
1230 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1242 LIR_Opr _dst_pos;
1243 LIR_Opr _length;
1244 LIR_Opr _tmp;
1245 ciArrayKlass* _expected_type;
1246 int _flags;
1247
1248 public:
1249 enum Flags {
1250 src_null_check = 1 << 0,
1251 dst_null_check = 1 << 1,
1252 src_pos_positive_check = 1 << 2,
1253 dst_pos_positive_check = 1 << 3,
1254 length_positive_check = 1 << 4,
1255 src_range_check = 1 << 5,
1256 dst_range_check = 1 << 6,
1257 type_check = 1 << 7,
1258 overlapping = 1 << 8,
1259 unaligned = 1 << 9,
1260 src_objarray = 1 << 10,
1261 dst_objarray = 1 << 11,
1262 all_flags = (1 << 12) - 1
1263 };
1264
1265 LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1266 ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1267
1268 LIR_Opr src() const { return _src; }
1269 LIR_Opr src_pos() const { return _src_pos; }
1270 LIR_Opr dst() const { return _dst; }
1271 LIR_Opr dst_pos() const { return _dst_pos; }
1272 LIR_Opr length() const { return _length; }
1273 LIR_Opr tmp() const { return _tmp; }
1274 int flags() const { return _flags; }
1275 ciArrayKlass* expected_type() const { return _expected_type; }
1276 ArrayCopyStub* stub() const { return _stub; }
1277 static int get_initial_copy_flags() { return LIR_OpArrayCopy::unaligned |
1278 LIR_OpArrayCopy::overlapping; }
1279
1280 virtual void emit_code(LIR_Assembler* masm);
1281 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1282 void print_instr(outputStream* out) const PRODUCT_RETURN;
1497
1498
1499 // LIR_OpTypeCheck
1500 class LIR_OpTypeCheck: public LIR_Op {
1501 friend class LIR_OpVisitState;
1502
1503 private:
1504 LIR_Opr _object;
1505 LIR_Opr _array;
1506 ciKlass* _klass;
1507 LIR_Opr _tmp1;
1508 LIR_Opr _tmp2;
1509 LIR_Opr _tmp3;
1510 CodeEmitInfo* _info_for_patch;
1511 CodeEmitInfo* _info_for_exception;
1512 CodeStub* _stub;
1513 ciMethod* _profiled_method;
1514 int _profiled_bci;
1515 bool _should_profile;
1516 bool _fast_check;
1517
1518 public:
1519 LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1520 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1521 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub);
1522 LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1523 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1524
1525 LIR_Opr object() const { return _object; }
1526 LIR_Opr array() const { assert(code() == lir_store_check, "not valid"); return _array; }
1527 LIR_Opr tmp1() const { return _tmp1; }
1528 LIR_Opr tmp2() const { return _tmp2; }
1529 LIR_Opr tmp3() const { return _tmp3; }
1530 ciKlass* klass() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass; }
1531 bool fast_check() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check; }
1532 CodeEmitInfo* info_for_patch() const { return _info_for_patch; }
1533 CodeEmitInfo* info_for_exception() const { return _info_for_exception; }
1534 CodeStub* stub() const { return _stub; }
1535
1536 // MethodData* profiling
1537 void set_profiled_method(ciMethod *method) { _profiled_method = method; }
1538 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1539 void set_should_profile(bool b) { _should_profile = b; }
1540 ciMethod* profiled_method() const { return _profiled_method; }
1541 int profiled_bci() const { return _profiled_bci; }
1542 bool should_profile() const { return _should_profile; }
1543
1544 virtual bool is_patching() { return _info_for_patch != nullptr; }
1545 virtual void emit_code(LIR_Assembler* masm);
1546 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1547 void print_instr(outputStream* out) const PRODUCT_RETURN;
1548 };
1549
1550 // LIR_Op2
1551 class LIR_Op2: public LIR_Op {
1552 friend class LIR_OpVisitState;
1553
1554 protected:
1555 LIR_Opr _opr1;
1556 LIR_Opr _opr2;
1557 LIR_Opr _tmp1;
1558 LIR_Opr _tmp2;
1559 LIR_Opr _tmp3;
1560 LIR_Opr _tmp4;
1561 LIR_Opr _tmp5;
1562 LIR_Condition _condition;
1563 BasicType _type;
1564
1565 void verify() const;
1566
1567 public:
1568 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1569 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1688 void negate_cond();
1689
1690 virtual void emit_code(LIR_Assembler* masm);
1691 virtual LIR_OpBranch* as_OpBranch() { return this; }
1692 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1693 };
1694
1695 class LIR_OpAllocArray : public LIR_Op {
1696 friend class LIR_OpVisitState;
1697
1698 private:
1699 LIR_Opr _klass;
1700 LIR_Opr _len;
1701 LIR_Opr _tmp1;
1702 LIR_Opr _tmp2;
1703 LIR_Opr _tmp3;
1704 LIR_Opr _tmp4;
1705 CodeStub* _stub;
1706 BasicType _type;
1707 bool _zero_array;
1708
1709 public:
1710 LIR_OpAllocArray(LIR_Opr klass, LIR_Opr len, LIR_Opr result, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, BasicType type, CodeStub* stub, bool zero_array)
1711 : LIR_Op(lir_alloc_array, result, nullptr)
1712 , _klass(klass)
1713 , _len(len)
1714 , _tmp1(t1)
1715 , _tmp2(t2)
1716 , _tmp3(t3)
1717 , _tmp4(t4)
1718 , _stub(stub)
1719 , _type(type)
1720 , _zero_array(zero_array) {}
1721
1722 LIR_Opr klass() const { return _klass; }
1723 LIR_Opr len() const { return _len; }
1724 LIR_Opr obj() const { return result_opr(); }
1725 LIR_Opr tmp1() const { return _tmp1; }
1726 LIR_Opr tmp2() const { return _tmp2; }
1727 LIR_Opr tmp3() const { return _tmp3; }
1728 LIR_Opr tmp4() const { return _tmp4; }
1729 BasicType type() const { return _type; }
1730 CodeStub* stub() const { return _stub; }
1731 bool zero_array() const { return _zero_array; }
1732
1733 virtual void emit_code(LIR_Assembler* masm);
1734 virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1735 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1736 };
1737
1738
1739 class LIR_Op3: public LIR_Op {
1740 friend class LIR_OpVisitState;
1741
1742 private:
1743 LIR_Opr _opr1;
1744 LIR_Opr _opr2;
1745 LIR_Opr _opr3;
1746 public:
1747 LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1748 : LIR_Op(code, result, info)
1749 , _opr1(opr1)
1750 , _opr2(opr2)
1751 , _opr3(opr3) { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1818
1819 //--------------------------------
1820 class LabelObj: public CompilationResourceObj {
1821 private:
1822 Label _label;
1823 public:
1824 LabelObj() {}
1825 Label* label() { return &_label; }
1826 };
1827
1828
1829 class LIR_OpLock: public LIR_Op {
1830 friend class LIR_OpVisitState;
1831
1832 private:
1833 LIR_Opr _hdr;
1834 LIR_Opr _obj;
1835 LIR_Opr _lock;
1836 LIR_Opr _scratch;
1837 CodeStub* _stub;
1838 public:
1839 LIR_OpLock(LIR_Code code, LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info)
1840 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1841 , _hdr(hdr)
1842 , _obj(obj)
1843 , _lock(lock)
1844 , _scratch(scratch)
1845 , _stub(stub) {}
1846
1847 LIR_Opr hdr_opr() const { return _hdr; }
1848 LIR_Opr obj_opr() const { return _obj; }
1849 LIR_Opr lock_opr() const { return _lock; }
1850 LIR_Opr scratch_opr() const { return _scratch; }
1851 CodeStub* stub() const { return _stub; }
1852
1853 virtual void emit_code(LIR_Assembler* masm);
1854 virtual LIR_OpLock* as_OpLock() { return this; }
1855 void print_instr(outputStream* out) const PRODUCT_RETURN;
1856 };
1857
1858 class LIR_OpLoadKlass: public LIR_Op {
1859 friend class LIR_OpVisitState;
1860
1861 private:
1862 LIR_Opr _obj;
1863 public:
1864 LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1865 : LIR_Op(lir_load_klass, result, info)
1866 , _obj(obj)
1867 {}
1868
1869 LIR_Opr obj() const { return _obj; }
1870
1871 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }
1997 , _obj(obj)
1998 , _tmp(tmp)
1999 , _exact_klass(exact_klass)
2000 , _current_klass(current_klass)
2001 , _not_null(not_null)
2002 , _no_conflict(no_conflict) { }
2003
2004 LIR_Opr mdp() const { return _mdp; }
2005 LIR_Opr obj() const { return _obj; }
2006 LIR_Opr tmp() const { return _tmp; }
2007 ciKlass* exact_klass() const { return _exact_klass; }
2008 intptr_t current_klass() const { return _current_klass; }
2009 bool not_null() const { return _not_null; }
2010 bool no_conflict() const { return _no_conflict; }
2011
2012 virtual void emit_code(LIR_Assembler* masm);
2013 virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2014 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2015 };
2016
2017 class LIR_InsertionBuffer;
2018
2019 //--------------------------------LIR_List---------------------------------------------------
2020 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2021 // The LIR instructions are appended by the LIR_List class itself;
2022 //
2023 // Notes:
2024 // - all offsets are(should be) in bytes
2025 // - local positions are specified with an offset, with offset 0 being local 0
2026
2027 class LIR_List: public CompilationResourceObj {
2028 private:
2029 LIR_OpList _operations;
2030
2031 Compilation* _compilation;
2032 #ifndef PRODUCT
2033 BlockBegin* _block;
2034 #endif
2035 #ifdef ASSERT
2036 const char * _file;
2221 void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2222 void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr) { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2223
2224 void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2225 void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2226
2227 void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2228
2229 void store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2230 void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2231 void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2232 void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2233 void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2234
2235 void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2236 void idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2237 void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2238 void irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2239
2240 void allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub);
2241 void 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 = true);
2242
2243 // jump is an unconditional branch
2244 void jump(BlockBegin* block) {
2245 append(new LIR_OpBranch(lir_cond_always, block));
2246 }
2247 void jump(CodeStub* stub) {
2248 append(new LIR_OpBranch(lir_cond_always, stub));
2249 }
2250 void branch(LIR_Condition cond, Label* lbl) {
2251 append(new LIR_OpBranch(cond, lbl));
2252 }
2253 // Should not be used for fp comparisons
2254 void branch(LIR_Condition cond, BlockBegin* block) {
2255 append(new LIR_OpBranch(cond, block));
2256 }
2257 // Should not be used for fp comparisons
2258 void branch(LIR_Condition cond, CodeStub* stub) {
2259 append(new LIR_OpBranch(cond, stub));
2260 }
2261 // Should only be used for fp comparisons
2268 void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2269
2270 void shift_left(LIR_Opr value, int count, LIR_Opr dst) { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2271 void shift_right(LIR_Opr value, int count, LIR_Opr dst) { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2272 void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2273
2274 void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_cmp_l2i, left, right, dst)); }
2275 void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2276
2277 void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2278 append(new LIR_OpRTCall(routine, tmp, result, arguments));
2279 }
2280
2281 void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2282 LIR_OprList* arguments, CodeEmitInfo* info) {
2283 append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2284 }
2285
2286 void load_stack_address_monitor(int monitor_ix, LIR_Opr dst) { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2287 void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2288 void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info);
2289
2290 void breakpoint() { append(new LIR_Op0(lir_breakpoint)); }
2291
2292 void arraycopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info) { append(new LIR_OpArrayCopy(src, src_pos, dst, dst_pos, length, tmp, expected_type, flags, info)); }
2293
2294 void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2295
2296 void 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);
2297 void store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci);
2298
2299 void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2300 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2301 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2302 ciMethod* profiled_method, int profiled_bci);
2303 // MethodData* profiling
2304 void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2305 append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2306 }
2307 void profile_type(LIR_Address* mdp, LIR_Opr obj, ciKlass* exact_klass, intptr_t current_klass, LIR_Opr tmp, bool not_null, bool no_conflict) {
2308 append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2309 }
2310
2311 void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2312 void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2313
2314 void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2315
2316 #ifdef ASSERT
2317 void lir_assert(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, const char* msg, bool halt) { append(new LIR_OpAssert(condition, opr1, opr2, msg, halt)); }
2318 #endif
2319 };
2320
2321 void print_LIR(BlockList* blocks);
2322
2323 class LIR_InsertionBuffer : public CompilationResourceObj {
2324 private:
2325 LIR_List* _lir; // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2326
2327 // list of insertion points. index and count are stored alternately:
2328 // _index_and_count[i * 2]: the index into lir list where "count" ops should be inserted
2329 // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
|
1 /*
2 * Copyright (c) 2000, 2026, 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 *
872 //
873 class LIR_Op;
874 class LIR_Op0;
875 class LIR_OpLabel;
876 class LIR_Op1;
877 class LIR_OpBranch;
878 class LIR_OpConvert;
879 class LIR_OpAllocObj;
880 class LIR_OpReturn;
881 class LIR_Op2;
882 class LIR_Op3;
883 class LIR_OpAllocArray;
884 class LIR_Op4;
885 class LIR_OpCall;
886 class LIR_OpJavaCall;
887 class LIR_OpRTCall;
888 class LIR_OpArrayCopy;
889 class LIR_OpUpdateCRC32;
890 class LIR_OpLock;
891 class LIR_OpTypeCheck;
892 class LIR_OpFlattenedArrayCheck;
893 class LIR_OpNullFreeArrayCheck;
894 class LIR_OpSubstitutabilityCheck;
895 class LIR_OpCompareAndSwap;
896 class LIR_OpLoadKlass;
897 class LIR_OpProfileCall;
898 class LIR_OpProfileType;
899 class LIR_OpProfileInlineType;
900 #ifdef ASSERT
901 class LIR_OpAssert;
902 #endif
903
904 // LIR operation codes
905 enum LIR_Code {
906 lir_none
907 , begin_op0
908 , lir_label
909 , lir_nop
910 , lir_std_entry
911 , lir_osr_entry
912 , lir_breakpoint
913 , lir_rtcall
914 , lir_membar
915 , lir_membar_acquire
916 , lir_membar_release
917 , lir_membar_loadload
918 , lir_membar_storestore
919 , lir_membar_loadstore
920 , lir_membar_storeload
921 , lir_get_thread
922 , lir_on_spin_wait
923 , lir_check_orig_pc
924 , end_op0
925 , begin_op1
926 , lir_push
927 , lir_pop
928 , lir_null_check
929 , lir_return
930 , lir_leal
931 , lir_move
932 , lir_convert
933 , lir_alloc_object
934 , lir_monaddr
935 , lir_sqrt
936 , lir_abs
937 , lir_neg
938 , lir_f2hf
939 , lir_hf2f
940 , lir_safepoint
941 , lir_unwind
942 , lir_load_klass
943 , end_op1
977 , lir_static_call
978 , lir_optvirtual_call
979 , lir_icvirtual_call
980 , lir_dynamic_call
981 , end_opJavaCall
982 , begin_opArrayCopy
983 , lir_arraycopy
984 , end_opArrayCopy
985 , begin_opUpdateCRC32
986 , lir_updatecrc32
987 , end_opUpdateCRC32
988 , begin_opLock
989 , lir_lock
990 , lir_unlock
991 , end_opLock
992 , begin_opTypeCheck
993 , lir_instanceof
994 , lir_checkcast
995 , lir_store_check
996 , end_opTypeCheck
997 , begin_opFlattenedArrayCheck
998 , lir_flat_array_check
999 , end_opFlattenedArrayCheck
1000 , begin_opNullFreeArrayCheck
1001 , lir_null_free_array_check
1002 , end_opNullFreeArrayCheck
1003 , begin_opSubstitutabilityCheck
1004 , lir_substitutability_check
1005 , end_opSubstitutabilityCheck
1006 , begin_opCompareAndSwap
1007 , lir_cas_long
1008 , lir_cas_obj
1009 , lir_cas_int
1010 , end_opCompareAndSwap
1011 , begin_opMDOProfile
1012 , lir_profile_call
1013 , lir_profile_type
1014 , lir_profile_inline_type
1015 , end_opMDOProfile
1016 , begin_opAssert
1017 , lir_assert
1018 , end_opAssert
1019 #if INCLUDE_ZGC
1020 , begin_opXLoadBarrierTest
1021 , lir_xloadbarrier_test
1022 , end_opXLoadBarrierTest
1023 #endif
1024 };
1025
1026
1027 enum LIR_Condition {
1028 lir_cond_equal
1029 , lir_cond_notEqual
1030 , lir_cond_less
1031 , lir_cond_lessEqual
1032 , lir_cond_greaterEqual
1033 , lir_cond_greater
1034 , lir_cond_belowEqual
1133
1134 virtual bool is_patching() { return false; }
1135 virtual LIR_OpCall* as_OpCall() { return nullptr; }
1136 virtual LIR_OpJavaCall* as_OpJavaCall() { return nullptr; }
1137 virtual LIR_OpLabel* as_OpLabel() { return nullptr; }
1138 virtual LIR_OpLock* as_OpLock() { return nullptr; }
1139 virtual LIR_OpAllocArray* as_OpAllocArray() { return nullptr; }
1140 virtual LIR_OpAllocObj* as_OpAllocObj() { return nullptr; }
1141 virtual LIR_OpBranch* as_OpBranch() { return nullptr; }
1142 virtual LIR_OpReturn* as_OpReturn() { return nullptr; }
1143 virtual LIR_OpRTCall* as_OpRTCall() { return nullptr; }
1144 virtual LIR_OpConvert* as_OpConvert() { return nullptr; }
1145 virtual LIR_Op0* as_Op0() { return nullptr; }
1146 virtual LIR_Op1* as_Op1() { return nullptr; }
1147 virtual LIR_Op2* as_Op2() { return nullptr; }
1148 virtual LIR_Op3* as_Op3() { return nullptr; }
1149 virtual LIR_Op4* as_Op4() { return nullptr; }
1150 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return nullptr; }
1151 virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return nullptr; }
1152 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return nullptr; }
1153 virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return nullptr; }
1154 virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return nullptr; }
1155 virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return nullptr; }
1156 virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return nullptr; }
1157 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return nullptr; }
1158 virtual LIR_OpProfileCall* as_OpProfileCall() { return nullptr; }
1159 virtual LIR_OpProfileType* as_OpProfileType() { return nullptr; }
1160 virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return nullptr; }
1161 #ifdef ASSERT
1162 virtual LIR_OpAssert* as_OpAssert() { return nullptr; }
1163 #endif
1164
1165 virtual void verify() const {}
1166 };
1167
1168 // for calls
1169 class LIR_OpCall: public LIR_Op {
1170 friend class LIR_OpVisitState;
1171
1172 protected:
1173 address _addr;
1174 LIR_OprList* _arguments;
1175 protected:
1176 LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1177 LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1178 : LIR_Op(code, result, info)
1179 , _addr(addr)
1180 , _arguments(arguments) {}
1210 LIR_Opr receiver, LIR_Opr result, intptr_t vtable_offset,
1211 LIR_OprList* arguments, CodeEmitInfo* info)
1212 : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1213 , _method(method)
1214 , _receiver(receiver)
1215 { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1216
1217 LIR_Opr receiver() const { return _receiver; }
1218 ciMethod* method() const { return _method; }
1219
1220 // JSR 292 support.
1221 bool is_invokedynamic() const { return code() == lir_dynamic_call; }
1222 bool is_method_handle_invoke() const {
1223 return method()->is_compiled_lambda_form() || // Java-generated lambda form
1224 method()->is_method_handle_intrinsic(); // JVM-generated MH intrinsic
1225 }
1226
1227 virtual void emit_code(LIR_Assembler* masm);
1228 virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1229 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1230
1231 bool maybe_return_as_fields(ciInlineKlass** vk = nullptr) const;
1232 };
1233
1234 // --------------------------------------------------
1235 // LIR_OpLabel
1236 // --------------------------------------------------
1237 // Location where a branch can continue
1238 class LIR_OpLabel: public LIR_Op {
1239 friend class LIR_OpVisitState;
1240
1241 private:
1242 Label* _label;
1243 public:
1244 LIR_OpLabel(Label* lbl)
1245 : LIR_Op(lir_label, LIR_OprFact::illegalOpr, nullptr)
1246 , _label(lbl) {}
1247 Label* label() const { return _label; }
1248
1249 virtual void emit_code(LIR_Assembler* masm);
1250 virtual LIR_OpLabel* as_OpLabel() { return this; }
1251 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1263 LIR_Opr _dst_pos;
1264 LIR_Opr _length;
1265 LIR_Opr _tmp;
1266 ciArrayKlass* _expected_type;
1267 int _flags;
1268
1269 public:
1270 enum Flags {
1271 src_null_check = 1 << 0,
1272 dst_null_check = 1 << 1,
1273 src_pos_positive_check = 1 << 2,
1274 dst_pos_positive_check = 1 << 3,
1275 length_positive_check = 1 << 4,
1276 src_range_check = 1 << 5,
1277 dst_range_check = 1 << 6,
1278 type_check = 1 << 7,
1279 overlapping = 1 << 8,
1280 unaligned = 1 << 9,
1281 src_objarray = 1 << 10,
1282 dst_objarray = 1 << 11,
1283 always_slow_path = 1 << 12,
1284 src_inlinetype_check = 1 << 13,
1285 dst_inlinetype_check = 1 << 14,
1286 all_flags = (1 << 15) - 1
1287 };
1288
1289 LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1290 ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1291
1292 LIR_Opr src() const { return _src; }
1293 LIR_Opr src_pos() const { return _src_pos; }
1294 LIR_Opr dst() const { return _dst; }
1295 LIR_Opr dst_pos() const { return _dst_pos; }
1296 LIR_Opr length() const { return _length; }
1297 LIR_Opr tmp() const { return _tmp; }
1298 int flags() const { return _flags; }
1299 ciArrayKlass* expected_type() const { return _expected_type; }
1300 ArrayCopyStub* stub() const { return _stub; }
1301 static int get_initial_copy_flags() { return LIR_OpArrayCopy::unaligned |
1302 LIR_OpArrayCopy::overlapping; }
1303
1304 virtual void emit_code(LIR_Assembler* masm);
1305 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1306 void print_instr(outputStream* out) const PRODUCT_RETURN;
1521
1522
1523 // LIR_OpTypeCheck
1524 class LIR_OpTypeCheck: public LIR_Op {
1525 friend class LIR_OpVisitState;
1526
1527 private:
1528 LIR_Opr _object;
1529 LIR_Opr _array;
1530 ciKlass* _klass;
1531 LIR_Opr _tmp1;
1532 LIR_Opr _tmp2;
1533 LIR_Opr _tmp3;
1534 CodeEmitInfo* _info_for_patch;
1535 CodeEmitInfo* _info_for_exception;
1536 CodeStub* _stub;
1537 ciMethod* _profiled_method;
1538 int _profiled_bci;
1539 bool _should_profile;
1540 bool _fast_check;
1541 bool _need_null_check;
1542
1543 public:
1544 LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1545 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1546 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub, bool need_null_check = true);
1547 LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1548 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1549
1550 LIR_Opr object() const { return _object; }
1551 LIR_Opr array() const { assert(code() == lir_store_check, "not valid"); return _array; }
1552 LIR_Opr tmp1() const { return _tmp1; }
1553 LIR_Opr tmp2() const { return _tmp2; }
1554 LIR_Opr tmp3() const { return _tmp3; }
1555 ciKlass* klass() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass; }
1556 bool fast_check() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check; }
1557 CodeEmitInfo* info_for_patch() const { return _info_for_patch; }
1558 CodeEmitInfo* info_for_exception() const { return _info_for_exception; }
1559 CodeStub* stub() const { return _stub; }
1560
1561 // MethodData* profiling
1562 void set_profiled_method(ciMethod *method) { _profiled_method = method; }
1563 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1564 void set_should_profile(bool b) { _should_profile = b; }
1565 ciMethod* profiled_method() const { return _profiled_method; }
1566 int profiled_bci() const { return _profiled_bci; }
1567 bool should_profile() const { return _should_profile; }
1568 bool need_null_check() const { return _need_null_check; }
1569 virtual bool is_patching() { return _info_for_patch != nullptr; }
1570 virtual void emit_code(LIR_Assembler* masm);
1571 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1572 void print_instr(outputStream* out) const PRODUCT_RETURN;
1573 };
1574
1575 // LIR_OpFlattenedArrayCheck
1576 class LIR_OpFlattenedArrayCheck: public LIR_Op {
1577 friend class LIR_OpVisitState;
1578
1579 private:
1580 LIR_Opr _array;
1581 LIR_Opr _value;
1582 LIR_Opr _tmp;
1583 CodeStub* _stub;
1584 public:
1585 LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
1586 LIR_Opr array() const { return _array; }
1587 LIR_Opr value() const { return _value; }
1588 LIR_Opr tmp() const { return _tmp; }
1589 CodeStub* stub() const { return _stub; }
1590
1591 virtual void emit_code(LIR_Assembler* masm);
1592 virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return this; }
1593 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1594 };
1595
1596 // LIR_OpNullFreeArrayCheck
1597 class LIR_OpNullFreeArrayCheck: public LIR_Op {
1598 friend class LIR_OpVisitState;
1599
1600 private:
1601 LIR_Opr _array;
1602 LIR_Opr _tmp;
1603 public:
1604 LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp);
1605 LIR_Opr array() const { return _array; }
1606 LIR_Opr tmp() const { return _tmp; }
1607
1608 virtual void emit_code(LIR_Assembler* masm);
1609 virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return this; }
1610 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1611 };
1612
1613 class LIR_OpSubstitutabilityCheck: public LIR_Op {
1614 friend class LIR_OpVisitState;
1615
1616 private:
1617 LIR_Opr _left;
1618 LIR_Opr _right;
1619 LIR_Opr _equal_result;
1620 LIR_Opr _not_equal_result;
1621 ciKlass* _left_klass;
1622 ciKlass* _right_klass;
1623 LIR_Opr _tmp1;
1624 LIR_Opr _tmp2;
1625 CodeStub* _stub;
1626 public:
1627 LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1628 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr tmp1, LIR_Opr tmp2,
1629 CodeEmitInfo* info, CodeStub* stub);
1630
1631 LIR_Opr left() const { return _left; }
1632 LIR_Opr right() const { return _right; }
1633 LIR_Opr equal_result() const { return _equal_result; }
1634 LIR_Opr not_equal_result() const { return _not_equal_result; }
1635 ciKlass* left_klass() const { return _left_klass; }
1636 ciKlass* right_klass() const { return _right_klass; }
1637 LIR_Opr tmp1() const { return _tmp1; }
1638 LIR_Opr tmp2() const { return _tmp2; }
1639 CodeStub* stub() const { return _stub; }
1640
1641 virtual void emit_code(LIR_Assembler* masm);
1642 virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return this; }
1643 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1644 };
1645
1646 // LIR_Op2
1647 class LIR_Op2: public LIR_Op {
1648 friend class LIR_OpVisitState;
1649
1650 protected:
1651 LIR_Opr _opr1;
1652 LIR_Opr _opr2;
1653 LIR_Opr _tmp1;
1654 LIR_Opr _tmp2;
1655 LIR_Opr _tmp3;
1656 LIR_Opr _tmp4;
1657 LIR_Opr _tmp5;
1658 LIR_Condition _condition;
1659 BasicType _type;
1660
1661 void verify() const;
1662
1663 public:
1664 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1665 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1784 void negate_cond();
1785
1786 virtual void emit_code(LIR_Assembler* masm);
1787 virtual LIR_OpBranch* as_OpBranch() { return this; }
1788 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1789 };
1790
1791 class LIR_OpAllocArray : public LIR_Op {
1792 friend class LIR_OpVisitState;
1793
1794 private:
1795 LIR_Opr _klass;
1796 LIR_Opr _len;
1797 LIR_Opr _tmp1;
1798 LIR_Opr _tmp2;
1799 LIR_Opr _tmp3;
1800 LIR_Opr _tmp4;
1801 CodeStub* _stub;
1802 BasicType _type;
1803 bool _zero_array;
1804 bool _always_slow_path;
1805
1806 public:
1807 LIR_OpAllocArray(LIR_Opr klass, LIR_Opr len, LIR_Opr result, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, BasicType type, CodeStub* stub, bool zero_array, bool always_slow_path)
1808 : LIR_Op(lir_alloc_array, result, nullptr)
1809 , _klass(klass)
1810 , _len(len)
1811 , _tmp1(t1)
1812 , _tmp2(t2)
1813 , _tmp3(t3)
1814 , _tmp4(t4)
1815 , _stub(stub)
1816 , _type(type)
1817 , _zero_array(zero_array)
1818 , _always_slow_path(always_slow_path) {}
1819
1820 LIR_Opr klass() const { return _klass; }
1821 LIR_Opr len() const { return _len; }
1822 LIR_Opr obj() const { return result_opr(); }
1823 LIR_Opr tmp1() const { return _tmp1; }
1824 LIR_Opr tmp2() const { return _tmp2; }
1825 LIR_Opr tmp3() const { return _tmp3; }
1826 LIR_Opr tmp4() const { return _tmp4; }
1827 BasicType type() const { return _type; }
1828 CodeStub* stub() const { return _stub; }
1829 bool zero_array() const { return _zero_array; }
1830 bool always_slow_path() const { return _always_slow_path; }
1831
1832 virtual void emit_code(LIR_Assembler* masm);
1833 virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1834 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1835 };
1836
1837
1838 class LIR_Op3: public LIR_Op {
1839 friend class LIR_OpVisitState;
1840
1841 private:
1842 LIR_Opr _opr1;
1843 LIR_Opr _opr2;
1844 LIR_Opr _opr3;
1845 public:
1846 LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1847 : LIR_Op(code, result, info)
1848 , _opr1(opr1)
1849 , _opr2(opr2)
1850 , _opr3(opr3) { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1917
1918 //--------------------------------
1919 class LabelObj: public CompilationResourceObj {
1920 private:
1921 Label _label;
1922 public:
1923 LabelObj() {}
1924 Label* label() { return &_label; }
1925 };
1926
1927
1928 class LIR_OpLock: public LIR_Op {
1929 friend class LIR_OpVisitState;
1930
1931 private:
1932 LIR_Opr _hdr;
1933 LIR_Opr _obj;
1934 LIR_Opr _lock;
1935 LIR_Opr _scratch;
1936 CodeStub* _stub;
1937 CodeStub* _throw_ie_stub;
1938 public:
1939 LIR_OpLock(LIR_Code code, LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub=nullptr)
1940 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1941 , _hdr(hdr)
1942 , _obj(obj)
1943 , _lock(lock)
1944 , _scratch(scratch)
1945 , _stub(stub)
1946 , _throw_ie_stub(throw_ie_stub) {}
1947
1948 LIR_Opr hdr_opr() const { return _hdr; }
1949 LIR_Opr obj_opr() const { return _obj; }
1950 LIR_Opr lock_opr() const { return _lock; }
1951 LIR_Opr scratch_opr() const { return _scratch; }
1952 CodeStub* stub() const { return _stub; }
1953 CodeStub* throw_ie_stub() const { return _throw_ie_stub; }
1954
1955 virtual void emit_code(LIR_Assembler* masm);
1956 virtual LIR_OpLock* as_OpLock() { return this; }
1957 void print_instr(outputStream* out) const PRODUCT_RETURN;
1958 };
1959
1960 class LIR_OpLoadKlass: public LIR_Op {
1961 friend class LIR_OpVisitState;
1962
1963 private:
1964 LIR_Opr _obj;
1965 public:
1966 LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1967 : LIR_Op(lir_load_klass, result, info)
1968 , _obj(obj)
1969 {}
1970
1971 LIR_Opr obj() const { return _obj; }
1972
1973 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }
2099 , _obj(obj)
2100 , _tmp(tmp)
2101 , _exact_klass(exact_klass)
2102 , _current_klass(current_klass)
2103 , _not_null(not_null)
2104 , _no_conflict(no_conflict) { }
2105
2106 LIR_Opr mdp() const { return _mdp; }
2107 LIR_Opr obj() const { return _obj; }
2108 LIR_Opr tmp() const { return _tmp; }
2109 ciKlass* exact_klass() const { return _exact_klass; }
2110 intptr_t current_klass() const { return _current_klass; }
2111 bool not_null() const { return _not_null; }
2112 bool no_conflict() const { return _no_conflict; }
2113
2114 virtual void emit_code(LIR_Assembler* masm);
2115 virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2116 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2117 };
2118
2119 // LIR_OpProfileInlineType
2120 class LIR_OpProfileInlineType : public LIR_Op {
2121 friend class LIR_OpVisitState;
2122
2123 private:
2124 LIR_Opr _mdp;
2125 LIR_Opr _obj;
2126 int _flag;
2127 LIR_Opr _tmp;
2128 bool _not_null; // true if we know statically that _obj cannot be null
2129
2130 public:
2131 // Destroys recv
2132 LIR_OpProfileInlineType(LIR_Opr mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null)
2133 : LIR_Op(lir_profile_inline_type, LIR_OprFact::illegalOpr, nullptr) // no result, no info
2134 , _mdp(mdp)
2135 , _obj(obj)
2136 , _flag(flag)
2137 , _tmp(tmp)
2138 , _not_null(not_null) { }
2139
2140 LIR_Opr mdp() const { return _mdp; }
2141 LIR_Opr obj() const { return _obj; }
2142 int flag() const { return _flag; }
2143 LIR_Opr tmp() const { return _tmp; }
2144 bool not_null() const { return _not_null; }
2145
2146 virtual void emit_code(LIR_Assembler* masm);
2147 virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return this; }
2148 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2149 };
2150
2151 class LIR_InsertionBuffer;
2152
2153 //--------------------------------LIR_List---------------------------------------------------
2154 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2155 // The LIR instructions are appended by the LIR_List class itself;
2156 //
2157 // Notes:
2158 // - all offsets are(should be) in bytes
2159 // - local positions are specified with an offset, with offset 0 being local 0
2160
2161 class LIR_List: public CompilationResourceObj {
2162 private:
2163 LIR_OpList _operations;
2164
2165 Compilation* _compilation;
2166 #ifndef PRODUCT
2167 BlockBegin* _block;
2168 #endif
2169 #ifdef ASSERT
2170 const char * _file;
2355 void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2356 void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr) { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2357
2358 void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2359 void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2360
2361 void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2362
2363 void store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2364 void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2365 void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2366 void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2367 void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2368
2369 void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2370 void idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2371 void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2372 void irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2373
2374 void allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub);
2375 void 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 = true, bool always_slow_path = false);
2376
2377 // jump is an unconditional branch
2378 void jump(BlockBegin* block) {
2379 append(new LIR_OpBranch(lir_cond_always, block));
2380 }
2381 void jump(CodeStub* stub) {
2382 append(new LIR_OpBranch(lir_cond_always, stub));
2383 }
2384 void branch(LIR_Condition cond, Label* lbl) {
2385 append(new LIR_OpBranch(cond, lbl));
2386 }
2387 // Should not be used for fp comparisons
2388 void branch(LIR_Condition cond, BlockBegin* block) {
2389 append(new LIR_OpBranch(cond, block));
2390 }
2391 // Should not be used for fp comparisons
2392 void branch(LIR_Condition cond, CodeStub* stub) {
2393 append(new LIR_OpBranch(cond, stub));
2394 }
2395 // Should only be used for fp comparisons
2402 void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2403
2404 void shift_left(LIR_Opr value, int count, LIR_Opr dst) { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2405 void shift_right(LIR_Opr value, int count, LIR_Opr dst) { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2406 void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2407
2408 void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_cmp_l2i, left, right, dst)); }
2409 void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2410
2411 void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2412 append(new LIR_OpRTCall(routine, tmp, result, arguments));
2413 }
2414
2415 void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2416 LIR_OprList* arguments, CodeEmitInfo* info) {
2417 append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2418 }
2419
2420 void load_stack_address_monitor(int monitor_ix, LIR_Opr dst) { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2421 void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2422 void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub=nullptr);
2423
2424 void breakpoint() { append(new LIR_Op0(lir_breakpoint)); }
2425
2426 void arraycopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info) { append(new LIR_OpArrayCopy(src, src_pos, dst, dst_pos, length, tmp, expected_type, flags, info)); }
2427
2428 void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2429
2430 void 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);
2431 void store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci);
2432 void check_flat_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
2433 void check_null_free_array(LIR_Opr array, LIR_Opr tmp);
2434 void substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
2435 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr tmp1, LIR_Opr tmp2,
2436 CodeEmitInfo* info, CodeStub* stub);
2437
2438 void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2439 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2440 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2441 ciMethod* profiled_method, int profiled_bci, bool is_null_free);
2442 // MethodData* profiling
2443 void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2444 append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2445 }
2446 void profile_type(LIR_Address* mdp, LIR_Opr obj, ciKlass* exact_klass, intptr_t current_klass, LIR_Opr tmp, bool not_null, bool no_conflict) {
2447 append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2448 }
2449 void profile_inline_type(LIR_Address* mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null) {
2450 append(new LIR_OpProfileInlineType(LIR_OprFact::address(mdp), obj, flag, tmp, not_null));
2451 }
2452
2453 void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2454 void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2455
2456 void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2457
2458 #ifdef ASSERT
2459 void lir_assert(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, const char* msg, bool halt) { append(new LIR_OpAssert(condition, opr1, opr2, msg, halt)); }
2460 #endif
2461 };
2462
2463 void print_LIR(BlockList* blocks);
2464
2465 class LIR_InsertionBuffer : public CompilationResourceObj {
2466 private:
2467 LIR_List* _lir; // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2468
2469 // list of insertion points. index and count are stored alternately:
2470 // _index_and_count[i * 2]: the index into lir list where "count" ops should be inserted
2471 // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
|