880 class LIR_Op0;
881 class LIR_OpLabel;
882 class LIR_Op1;
883 class LIR_OpBranch;
884 class LIR_OpConvert;
885 class LIR_OpAllocObj;
886 class LIR_OpReturn;
887 class LIR_OpRoundFP;
888 class LIR_Op2;
889 class LIR_OpDelay;
890 class LIR_Op3;
891 class LIR_OpAllocArray;
892 class LIR_Op4;
893 class LIR_OpCall;
894 class LIR_OpJavaCall;
895 class LIR_OpRTCall;
896 class LIR_OpArrayCopy;
897 class LIR_OpUpdateCRC32;
898 class LIR_OpLock;
899 class LIR_OpTypeCheck;
900 class LIR_OpCompareAndSwap;
901 class LIR_OpLoadKlass;
902 class LIR_OpProfileCall;
903 class LIR_OpProfileType;
904 #ifdef ASSERT
905 class LIR_OpAssert;
906 #endif
907
908 // LIR operation codes
909 enum LIR_Code {
910 lir_none
911 , begin_op0
912 , lir_label
913 , lir_nop
914 , lir_std_entry
915 , lir_osr_entry
916 , lir_fpop_raw
917 , lir_breakpoint
918 , lir_rtcall
919 , lir_membar
920 , lir_membar_acquire
921 , lir_membar_release
922 , lir_membar_loadload
923 , lir_membar_storestore
924 , lir_membar_loadstore
925 , lir_membar_storeload
926 , lir_get_thread
927 , lir_on_spin_wait
928 , end_op0
929 , begin_op1
930 , lir_fxch
931 , lir_fld
932 , lir_push
933 , lir_pop
934 , lir_null_check
935 , lir_return
936 , lir_leal
937 , lir_move
938 , lir_convert
939 , lir_alloc_object
940 , lir_monaddr
941 , lir_roundfp
942 , lir_sqrt
943 , lir_abs
944 , lir_neg
945 , lir_f2hf
946 , lir_hf2f
947 , lir_safepoint
987 , lir_dynamic_call
988 , end_opJavaCall
989 , begin_opArrayCopy
990 , lir_arraycopy
991 , end_opArrayCopy
992 , begin_opUpdateCRC32
993 , lir_updatecrc32
994 , end_opUpdateCRC32
995 , begin_opLock
996 , lir_lock
997 , lir_unlock
998 , end_opLock
999 , begin_delay_slot
1000 , lir_delay_slot
1001 , end_delay_slot
1002 , begin_opTypeCheck
1003 , lir_instanceof
1004 , lir_checkcast
1005 , lir_store_check
1006 , end_opTypeCheck
1007 , begin_opCompareAndSwap
1008 , lir_cas_long
1009 , lir_cas_obj
1010 , lir_cas_int
1011 , end_opCompareAndSwap
1012 , begin_opMDOProfile
1013 , lir_profile_call
1014 , lir_profile_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
1143 virtual LIR_OpCall* as_OpCall() { return nullptr; }
1144 virtual LIR_OpJavaCall* as_OpJavaCall() { return nullptr; }
1145 virtual LIR_OpLabel* as_OpLabel() { return nullptr; }
1146 virtual LIR_OpDelay* as_OpDelay() { return nullptr; }
1147 virtual LIR_OpLock* as_OpLock() { return nullptr; }
1148 virtual LIR_OpAllocArray* as_OpAllocArray() { return nullptr; }
1149 virtual LIR_OpAllocObj* as_OpAllocObj() { return nullptr; }
1150 virtual LIR_OpRoundFP* as_OpRoundFP() { return nullptr; }
1151 virtual LIR_OpBranch* as_OpBranch() { return nullptr; }
1152 virtual LIR_OpReturn* as_OpReturn() { return nullptr; }
1153 virtual LIR_OpRTCall* as_OpRTCall() { return nullptr; }
1154 virtual LIR_OpConvert* as_OpConvert() { return nullptr; }
1155 virtual LIR_Op0* as_Op0() { return nullptr; }
1156 virtual LIR_Op1* as_Op1() { return nullptr; }
1157 virtual LIR_Op2* as_Op2() { return nullptr; }
1158 virtual LIR_Op3* as_Op3() { return nullptr; }
1159 virtual LIR_Op4* as_Op4() { return nullptr; }
1160 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return nullptr; }
1161 virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return nullptr; }
1162 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return nullptr; }
1163 virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return nullptr; }
1164 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return nullptr; }
1165 virtual LIR_OpProfileCall* as_OpProfileCall() { return nullptr; }
1166 virtual LIR_OpProfileType* as_OpProfileType() { return nullptr; }
1167 #ifdef ASSERT
1168 virtual LIR_OpAssert* as_OpAssert() { return nullptr; }
1169 #endif
1170
1171 virtual void verify() const {}
1172 };
1173
1174 // for calls
1175 class LIR_OpCall: public LIR_Op {
1176 friend class LIR_OpVisitState;
1177
1178 protected:
1179 address _addr;
1180 LIR_OprList* _arguments;
1181 protected:
1182 LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1183 LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1184 : LIR_Op(code, result, info)
1185 , _addr(addr)
1186 , _arguments(arguments) {}
1219 LIR_OprList* arguments, CodeEmitInfo* info)
1220 : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1221 , _method(method)
1222 , _receiver(receiver)
1223 , _method_handle_invoke_SP_save_opr(LIR_OprFact::illegalOpr)
1224 { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1225
1226 LIR_Opr receiver() const { return _receiver; }
1227 ciMethod* method() const { return _method; }
1228
1229 // JSR 292 support.
1230 bool is_invokedynamic() const { return code() == lir_dynamic_call; }
1231 bool is_method_handle_invoke() const {
1232 return method()->is_compiled_lambda_form() || // Java-generated lambda form
1233 method()->is_method_handle_intrinsic(); // JVM-generated MH intrinsic
1234 }
1235
1236 virtual void emit_code(LIR_Assembler* masm);
1237 virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1238 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1239 };
1240
1241 // --------------------------------------------------
1242 // LIR_OpLabel
1243 // --------------------------------------------------
1244 // Location where a branch can continue
1245 class LIR_OpLabel: public LIR_Op {
1246 friend class LIR_OpVisitState;
1247
1248 private:
1249 Label* _label;
1250 public:
1251 LIR_OpLabel(Label* lbl)
1252 : LIR_Op(lir_label, LIR_OprFact::illegalOpr, nullptr)
1253 , _label(lbl) {}
1254 Label* label() const { return _label; }
1255
1256 virtual void emit_code(LIR_Assembler* masm);
1257 virtual LIR_OpLabel* as_OpLabel() { return this; }
1258 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1270 LIR_Opr _dst_pos;
1271 LIR_Opr _length;
1272 LIR_Opr _tmp;
1273 ciArrayKlass* _expected_type;
1274 int _flags;
1275
1276 public:
1277 enum Flags {
1278 src_null_check = 1 << 0,
1279 dst_null_check = 1 << 1,
1280 src_pos_positive_check = 1 << 2,
1281 dst_pos_positive_check = 1 << 3,
1282 length_positive_check = 1 << 4,
1283 src_range_check = 1 << 5,
1284 dst_range_check = 1 << 6,
1285 type_check = 1 << 7,
1286 overlapping = 1 << 8,
1287 unaligned = 1 << 9,
1288 src_objarray = 1 << 10,
1289 dst_objarray = 1 << 11,
1290 all_flags = (1 << 12) - 1
1291 };
1292
1293 LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1294 ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1295
1296 LIR_Opr src() const { return _src; }
1297 LIR_Opr src_pos() const { return _src_pos; }
1298 LIR_Opr dst() const { return _dst; }
1299 LIR_Opr dst_pos() const { return _dst_pos; }
1300 LIR_Opr length() const { return _length; }
1301 LIR_Opr tmp() const { return _tmp; }
1302 int flags() const { return _flags; }
1303 ciArrayKlass* expected_type() const { return _expected_type; }
1304 ArrayCopyStub* stub() const { return _stub; }
1305
1306 virtual void emit_code(LIR_Assembler* masm);
1307 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1308 void print_instr(outputStream* out) const PRODUCT_RETURN;
1309 };
1310
1545 };
1546
1547 // LIR_OpTypeCheck
1548 class LIR_OpTypeCheck: public LIR_Op {
1549 friend class LIR_OpVisitState;
1550
1551 private:
1552 LIR_Opr _object;
1553 LIR_Opr _array;
1554 ciKlass* _klass;
1555 LIR_Opr _tmp1;
1556 LIR_Opr _tmp2;
1557 LIR_Opr _tmp3;
1558 CodeEmitInfo* _info_for_patch;
1559 CodeEmitInfo* _info_for_exception;
1560 CodeStub* _stub;
1561 ciMethod* _profiled_method;
1562 int _profiled_bci;
1563 bool _should_profile;
1564 bool _fast_check;
1565
1566 public:
1567 LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1568 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1569 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub);
1570 LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1571 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1572
1573 LIR_Opr object() const { return _object; }
1574 LIR_Opr array() const { assert(code() == lir_store_check, "not valid"); return _array; }
1575 LIR_Opr tmp1() const { return _tmp1; }
1576 LIR_Opr tmp2() const { return _tmp2; }
1577 LIR_Opr tmp3() const { return _tmp3; }
1578 ciKlass* klass() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass; }
1579 bool fast_check() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check; }
1580 CodeEmitInfo* info_for_patch() const { return _info_for_patch; }
1581 CodeEmitInfo* info_for_exception() const { return _info_for_exception; }
1582 CodeStub* stub() const { return _stub; }
1583
1584 // MethodData* profiling
1585 void set_profiled_method(ciMethod *method) { _profiled_method = method; }
1586 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1587 void set_should_profile(bool b) { _should_profile = b; }
1588 ciMethod* profiled_method() const { return _profiled_method; }
1589 int profiled_bci() const { return _profiled_bci; }
1590 bool should_profile() const { return _should_profile; }
1591
1592 virtual bool is_patching() { return _info_for_patch != nullptr; }
1593 virtual void emit_code(LIR_Assembler* masm);
1594 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1595 void print_instr(outputStream* out) const PRODUCT_RETURN;
1596 };
1597
1598 // LIR_Op2
1599 class LIR_Op2: public LIR_Op {
1600 friend class LIR_OpVisitState;
1601
1602 protected:
1603 LIR_Opr _opr1;
1604 LIR_Opr _opr2;
1605 LIR_Opr _tmp1;
1606 LIR_Opr _tmp2;
1607 LIR_Opr _tmp3;
1608 LIR_Opr _tmp4;
1609 LIR_Opr _tmp5;
1610 LIR_Condition _condition;
1611 BasicType _type;
1612
1613 void verify() const;
1614
1615 public:
1616 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1617 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1736 void negate_cond();
1737
1738 virtual void emit_code(LIR_Assembler* masm);
1739 virtual LIR_OpBranch* as_OpBranch() { return this; }
1740 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1741 };
1742
1743 class LIR_OpAllocArray : public LIR_Op {
1744 friend class LIR_OpVisitState;
1745
1746 private:
1747 LIR_Opr _klass;
1748 LIR_Opr _len;
1749 LIR_Opr _tmp1;
1750 LIR_Opr _tmp2;
1751 LIR_Opr _tmp3;
1752 LIR_Opr _tmp4;
1753 CodeStub* _stub;
1754 BasicType _type;
1755 bool _zero_array;
1756
1757 public:
1758 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)
1759 : LIR_Op(lir_alloc_array, result, nullptr)
1760 , _klass(klass)
1761 , _len(len)
1762 , _tmp1(t1)
1763 , _tmp2(t2)
1764 , _tmp3(t3)
1765 , _tmp4(t4)
1766 , _stub(stub)
1767 , _type(type)
1768 , _zero_array(zero_array) {}
1769
1770 LIR_Opr klass() const { return _klass; }
1771 LIR_Opr len() const { return _len; }
1772 LIR_Opr obj() const { return result_opr(); }
1773 LIR_Opr tmp1() const { return _tmp1; }
1774 LIR_Opr tmp2() const { return _tmp2; }
1775 LIR_Opr tmp3() const { return _tmp3; }
1776 LIR_Opr tmp4() const { return _tmp4; }
1777 BasicType type() const { return _type; }
1778 CodeStub* stub() const { return _stub; }
1779 bool zero_array() const { return _zero_array; }
1780
1781 virtual void emit_code(LIR_Assembler* masm);
1782 virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1783 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1784 };
1785
1786
1787 class LIR_Op3: public LIR_Op {
1788 friend class LIR_OpVisitState;
1789
1790 private:
1791 LIR_Opr _opr1;
1792 LIR_Opr _opr2;
1793 LIR_Opr _opr3;
1794 public:
1795 LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1796 : LIR_Op(code, result, info)
1797 , _opr1(opr1)
1798 , _opr2(opr2)
1799 , _opr3(opr3) { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1866
1867 //--------------------------------
1868 class LabelObj: public CompilationResourceObj {
1869 private:
1870 Label _label;
1871 public:
1872 LabelObj() {}
1873 Label* label() { return &_label; }
1874 };
1875
1876
1877 class LIR_OpLock: public LIR_Op {
1878 friend class LIR_OpVisitState;
1879
1880 private:
1881 LIR_Opr _hdr;
1882 LIR_Opr _obj;
1883 LIR_Opr _lock;
1884 LIR_Opr _scratch;
1885 CodeStub* _stub;
1886 public:
1887 LIR_OpLock(LIR_Code code, LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info)
1888 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1889 , _hdr(hdr)
1890 , _obj(obj)
1891 , _lock(lock)
1892 , _scratch(scratch)
1893 , _stub(stub) {}
1894
1895 LIR_Opr hdr_opr() const { return _hdr; }
1896 LIR_Opr obj_opr() const { return _obj; }
1897 LIR_Opr lock_opr() const { return _lock; }
1898 LIR_Opr scratch_opr() const { return _scratch; }
1899 CodeStub* stub() const { return _stub; }
1900
1901 virtual void emit_code(LIR_Assembler* masm);
1902 virtual LIR_OpLock* as_OpLock() { return this; }
1903 void print_instr(outputStream* out) const PRODUCT_RETURN;
1904 };
1905
1906 class LIR_OpLoadKlass: public LIR_Op {
1907 friend class LIR_OpVisitState;
1908
1909 private:
1910 LIR_Opr _obj;
1911 public:
1912 LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1913 : LIR_Op(lir_load_klass, result, info)
1914 , _obj(obj)
1915 {}
1916
1917 LIR_Opr obj() const { return _obj; }
1918
1919 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }
2064 , _obj(obj)
2065 , _tmp(tmp)
2066 , _exact_klass(exact_klass)
2067 , _current_klass(current_klass)
2068 , _not_null(not_null)
2069 , _no_conflict(no_conflict) { }
2070
2071 LIR_Opr mdp() const { return _mdp; }
2072 LIR_Opr obj() const { return _obj; }
2073 LIR_Opr tmp() const { return _tmp; }
2074 ciKlass* exact_klass() const { return _exact_klass; }
2075 intptr_t current_klass() const { return _current_klass; }
2076 bool not_null() const { return _not_null; }
2077 bool no_conflict() const { return _no_conflict; }
2078
2079 virtual void emit_code(LIR_Assembler* masm);
2080 virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2081 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2082 };
2083
2084 class LIR_InsertionBuffer;
2085
2086 //--------------------------------LIR_List---------------------------------------------------
2087 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2088 // The LIR instructions are appended by the LIR_List class itself;
2089 //
2090 // Notes:
2091 // - all offsets are(should be) in bytes
2092 // - local positions are specified with an offset, with offset 0 being local 0
2093
2094 class LIR_List: public CompilationResourceObj {
2095 private:
2096 LIR_OpList _operations;
2097
2098 Compilation* _compilation;
2099 #ifndef PRODUCT
2100 BlockBegin* _block;
2101 #endif
2102 #ifdef ASSERT
2103 const char * _file;
2289 void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2290 void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr) { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2291
2292 void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2293 void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2294
2295 void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2296
2297 void store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2298 void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2299 void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2300 void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2301 void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2302
2303 void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2304 void idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2305 void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2306 void irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2307
2308 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);
2309 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);
2310
2311 // jump is an unconditional branch
2312 void jump(BlockBegin* block) {
2313 append(new LIR_OpBranch(lir_cond_always, block));
2314 }
2315 void jump(CodeStub* stub) {
2316 append(new LIR_OpBranch(lir_cond_always, stub));
2317 }
2318 void branch(LIR_Condition cond, Label* lbl) {
2319 append(new LIR_OpBranch(cond, lbl));
2320 }
2321 // Should not be used for fp comparisons
2322 void branch(LIR_Condition cond, BlockBegin* block) {
2323 append(new LIR_OpBranch(cond, block));
2324 }
2325 // Should not be used for fp comparisons
2326 void branch(LIR_Condition cond, CodeStub* stub) {
2327 append(new LIR_OpBranch(cond, stub));
2328 }
2329 // Should only be used for fp comparisons
2336 void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2337
2338 void shift_left(LIR_Opr value, int count, LIR_Opr dst) { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2339 void shift_right(LIR_Opr value, int count, LIR_Opr dst) { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2340 void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2341
2342 void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_cmp_l2i, left, right, dst)); }
2343 void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2344
2345 void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2346 append(new LIR_OpRTCall(routine, tmp, result, arguments));
2347 }
2348
2349 void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2350 LIR_OprList* arguments, CodeEmitInfo* info) {
2351 append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2352 }
2353
2354 void load_stack_address_monitor(int monitor_ix, LIR_Opr dst) { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2355 void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2356 void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info);
2357
2358 void breakpoint() { append(new LIR_Op0(lir_breakpoint)); }
2359
2360 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)); }
2361
2362 void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2363
2364 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);
2365 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);
2366
2367 void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2368 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2369 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2370 ciMethod* profiled_method, int profiled_bci);
2371 // MethodData* profiling
2372 void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2373 append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2374 }
2375 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) {
2376 append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2377 }
2378
2379 void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2380 void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2381
2382 void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2383
2384 #ifdef ASSERT
2385 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)); }
2386 #endif
2387 };
2388
2389 void print_LIR(BlockList* blocks);
2390
2391 class LIR_InsertionBuffer : public CompilationResourceObj {
2392 private:
2393 LIR_List* _lir; // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2394
2395 // list of insertion points. index and count are stored alternately:
2396 // _index_and_count[i * 2]: the index into lir list where "count" ops should be inserted
2397 // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
|
880 class LIR_Op0;
881 class LIR_OpLabel;
882 class LIR_Op1;
883 class LIR_OpBranch;
884 class LIR_OpConvert;
885 class LIR_OpAllocObj;
886 class LIR_OpReturn;
887 class LIR_OpRoundFP;
888 class LIR_Op2;
889 class LIR_OpDelay;
890 class LIR_Op3;
891 class LIR_OpAllocArray;
892 class LIR_Op4;
893 class LIR_OpCall;
894 class LIR_OpJavaCall;
895 class LIR_OpRTCall;
896 class LIR_OpArrayCopy;
897 class LIR_OpUpdateCRC32;
898 class LIR_OpLock;
899 class LIR_OpTypeCheck;
900 class LIR_OpFlattenedArrayCheck;
901 class LIR_OpNullFreeArrayCheck;
902 class LIR_OpSubstitutabilityCheck;
903 class LIR_OpCompareAndSwap;
904 class LIR_OpLoadKlass;
905 class LIR_OpProfileCall;
906 class LIR_OpProfileType;
907 class LIR_OpProfileInlineType;
908 #ifdef ASSERT
909 class LIR_OpAssert;
910 #endif
911
912 // LIR operation codes
913 enum LIR_Code {
914 lir_none
915 , begin_op0
916 , lir_label
917 , lir_nop
918 , lir_std_entry
919 , lir_osr_entry
920 , lir_fpop_raw
921 , lir_breakpoint
922 , lir_rtcall
923 , lir_membar
924 , lir_membar_acquire
925 , lir_membar_release
926 , lir_membar_loadload
927 , lir_membar_storestore
928 , lir_membar_loadstore
929 , lir_membar_storeload
930 , lir_get_thread
931 , lir_on_spin_wait
932 , lir_check_orig_pc
933 , end_op0
934 , begin_op1
935 , lir_fxch
936 , lir_fld
937 , lir_push
938 , lir_pop
939 , lir_null_check
940 , lir_return
941 , lir_leal
942 , lir_move
943 , lir_convert
944 , lir_alloc_object
945 , lir_monaddr
946 , lir_roundfp
947 , lir_sqrt
948 , lir_abs
949 , lir_neg
950 , lir_f2hf
951 , lir_hf2f
952 , lir_safepoint
992 , lir_dynamic_call
993 , end_opJavaCall
994 , begin_opArrayCopy
995 , lir_arraycopy
996 , end_opArrayCopy
997 , begin_opUpdateCRC32
998 , lir_updatecrc32
999 , end_opUpdateCRC32
1000 , begin_opLock
1001 , lir_lock
1002 , lir_unlock
1003 , end_opLock
1004 , begin_delay_slot
1005 , lir_delay_slot
1006 , end_delay_slot
1007 , begin_opTypeCheck
1008 , lir_instanceof
1009 , lir_checkcast
1010 , lir_store_check
1011 , end_opTypeCheck
1012 , begin_opFlattenedArrayCheck
1013 , lir_flat_array_check
1014 , end_opFlattenedArrayCheck
1015 , begin_opNullFreeArrayCheck
1016 , lir_null_free_array_check
1017 , end_opNullFreeArrayCheck
1018 , begin_opSubstitutabilityCheck
1019 , lir_substitutability_check
1020 , end_opSubstitutabilityCheck
1021 , begin_opCompareAndSwap
1022 , lir_cas_long
1023 , lir_cas_obj
1024 , lir_cas_int
1025 , end_opCompareAndSwap
1026 , begin_opMDOProfile
1027 , lir_profile_call
1028 , lir_profile_type
1029 , lir_profile_inline_type
1030 , end_opMDOProfile
1031 , begin_opAssert
1032 , lir_assert
1033 , end_opAssert
1034 #if INCLUDE_ZGC
1035 , begin_opXLoadBarrierTest
1036 , lir_xloadbarrier_test
1037 , end_opXLoadBarrierTest
1038 #endif
1039 };
1040
1041
1042 enum LIR_Condition {
1043 lir_cond_equal
1044 , lir_cond_notEqual
1045 , lir_cond_less
1046 , lir_cond_lessEqual
1047 , lir_cond_greaterEqual
1048 , lir_cond_greater
1049 , lir_cond_belowEqual
1158 virtual LIR_OpCall* as_OpCall() { return nullptr; }
1159 virtual LIR_OpJavaCall* as_OpJavaCall() { return nullptr; }
1160 virtual LIR_OpLabel* as_OpLabel() { return nullptr; }
1161 virtual LIR_OpDelay* as_OpDelay() { return nullptr; }
1162 virtual LIR_OpLock* as_OpLock() { return nullptr; }
1163 virtual LIR_OpAllocArray* as_OpAllocArray() { return nullptr; }
1164 virtual LIR_OpAllocObj* as_OpAllocObj() { return nullptr; }
1165 virtual LIR_OpRoundFP* as_OpRoundFP() { return nullptr; }
1166 virtual LIR_OpBranch* as_OpBranch() { return nullptr; }
1167 virtual LIR_OpReturn* as_OpReturn() { return nullptr; }
1168 virtual LIR_OpRTCall* as_OpRTCall() { return nullptr; }
1169 virtual LIR_OpConvert* as_OpConvert() { return nullptr; }
1170 virtual LIR_Op0* as_Op0() { return nullptr; }
1171 virtual LIR_Op1* as_Op1() { return nullptr; }
1172 virtual LIR_Op2* as_Op2() { return nullptr; }
1173 virtual LIR_Op3* as_Op3() { return nullptr; }
1174 virtual LIR_Op4* as_Op4() { return nullptr; }
1175 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return nullptr; }
1176 virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return nullptr; }
1177 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return nullptr; }
1178 virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return nullptr; }
1179 virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return nullptr; }
1180 virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return nullptr; }
1181 virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return nullptr; }
1182 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return nullptr; }
1183 virtual LIR_OpProfileCall* as_OpProfileCall() { return nullptr; }
1184 virtual LIR_OpProfileType* as_OpProfileType() { return nullptr; }
1185 virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return nullptr; }
1186 #ifdef ASSERT
1187 virtual LIR_OpAssert* as_OpAssert() { return nullptr; }
1188 #endif
1189
1190 virtual void verify() const {}
1191 };
1192
1193 // for calls
1194 class LIR_OpCall: public LIR_Op {
1195 friend class LIR_OpVisitState;
1196
1197 protected:
1198 address _addr;
1199 LIR_OprList* _arguments;
1200 protected:
1201 LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1202 LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1203 : LIR_Op(code, result, info)
1204 , _addr(addr)
1205 , _arguments(arguments) {}
1238 LIR_OprList* arguments, CodeEmitInfo* info)
1239 : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1240 , _method(method)
1241 , _receiver(receiver)
1242 , _method_handle_invoke_SP_save_opr(LIR_OprFact::illegalOpr)
1243 { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1244
1245 LIR_Opr receiver() const { return _receiver; }
1246 ciMethod* method() const { return _method; }
1247
1248 // JSR 292 support.
1249 bool is_invokedynamic() const { return code() == lir_dynamic_call; }
1250 bool is_method_handle_invoke() const {
1251 return method()->is_compiled_lambda_form() || // Java-generated lambda form
1252 method()->is_method_handle_intrinsic(); // JVM-generated MH intrinsic
1253 }
1254
1255 virtual void emit_code(LIR_Assembler* masm);
1256 virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1257 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1258
1259 bool maybe_return_as_fields(ciInlineKlass** vk = nullptr) const;
1260 };
1261
1262 // --------------------------------------------------
1263 // LIR_OpLabel
1264 // --------------------------------------------------
1265 // Location where a branch can continue
1266 class LIR_OpLabel: public LIR_Op {
1267 friend class LIR_OpVisitState;
1268
1269 private:
1270 Label* _label;
1271 public:
1272 LIR_OpLabel(Label* lbl)
1273 : LIR_Op(lir_label, LIR_OprFact::illegalOpr, nullptr)
1274 , _label(lbl) {}
1275 Label* label() const { return _label; }
1276
1277 virtual void emit_code(LIR_Assembler* masm);
1278 virtual LIR_OpLabel* as_OpLabel() { return this; }
1279 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1291 LIR_Opr _dst_pos;
1292 LIR_Opr _length;
1293 LIR_Opr _tmp;
1294 ciArrayKlass* _expected_type;
1295 int _flags;
1296
1297 public:
1298 enum Flags {
1299 src_null_check = 1 << 0,
1300 dst_null_check = 1 << 1,
1301 src_pos_positive_check = 1 << 2,
1302 dst_pos_positive_check = 1 << 3,
1303 length_positive_check = 1 << 4,
1304 src_range_check = 1 << 5,
1305 dst_range_check = 1 << 6,
1306 type_check = 1 << 7,
1307 overlapping = 1 << 8,
1308 unaligned = 1 << 9,
1309 src_objarray = 1 << 10,
1310 dst_objarray = 1 << 11,
1311 always_slow_path = 1 << 12,
1312 src_inlinetype_check = 1 << 13,
1313 dst_inlinetype_check = 1 << 14,
1314 all_flags = (1 << 15) - 1
1315 };
1316
1317 LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1318 ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1319
1320 LIR_Opr src() const { return _src; }
1321 LIR_Opr src_pos() const { return _src_pos; }
1322 LIR_Opr dst() const { return _dst; }
1323 LIR_Opr dst_pos() const { return _dst_pos; }
1324 LIR_Opr length() const { return _length; }
1325 LIR_Opr tmp() const { return _tmp; }
1326 int flags() const { return _flags; }
1327 ciArrayKlass* expected_type() const { return _expected_type; }
1328 ArrayCopyStub* stub() const { return _stub; }
1329
1330 virtual void emit_code(LIR_Assembler* masm);
1331 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1332 void print_instr(outputStream* out) const PRODUCT_RETURN;
1333 };
1334
1569 };
1570
1571 // LIR_OpTypeCheck
1572 class LIR_OpTypeCheck: public LIR_Op {
1573 friend class LIR_OpVisitState;
1574
1575 private:
1576 LIR_Opr _object;
1577 LIR_Opr _array;
1578 ciKlass* _klass;
1579 LIR_Opr _tmp1;
1580 LIR_Opr _tmp2;
1581 LIR_Opr _tmp3;
1582 CodeEmitInfo* _info_for_patch;
1583 CodeEmitInfo* _info_for_exception;
1584 CodeStub* _stub;
1585 ciMethod* _profiled_method;
1586 int _profiled_bci;
1587 bool _should_profile;
1588 bool _fast_check;
1589 bool _need_null_check;
1590
1591 public:
1592 LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1593 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1594 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub, bool need_null_check = true);
1595 LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1596 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1597
1598 LIR_Opr object() const { return _object; }
1599 LIR_Opr array() const { assert(code() == lir_store_check, "not valid"); return _array; }
1600 LIR_Opr tmp1() const { return _tmp1; }
1601 LIR_Opr tmp2() const { return _tmp2; }
1602 LIR_Opr tmp3() const { return _tmp3; }
1603 ciKlass* klass() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass; }
1604 bool fast_check() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check; }
1605 CodeEmitInfo* info_for_patch() const { return _info_for_patch; }
1606 CodeEmitInfo* info_for_exception() const { return _info_for_exception; }
1607 CodeStub* stub() const { return _stub; }
1608
1609 // MethodData* profiling
1610 void set_profiled_method(ciMethod *method) { _profiled_method = method; }
1611 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1612 void set_should_profile(bool b) { _should_profile = b; }
1613 ciMethod* profiled_method() const { return _profiled_method; }
1614 int profiled_bci() const { return _profiled_bci; }
1615 bool should_profile() const { return _should_profile; }
1616 bool need_null_check() const { return _need_null_check; }
1617 virtual bool is_patching() { return _info_for_patch != nullptr; }
1618 virtual void emit_code(LIR_Assembler* masm);
1619 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1620 void print_instr(outputStream* out) const PRODUCT_RETURN;
1621 };
1622
1623 // LIR_OpFlattenedArrayCheck
1624 class LIR_OpFlattenedArrayCheck: public LIR_Op {
1625 friend class LIR_OpVisitState;
1626
1627 private:
1628 LIR_Opr _array;
1629 LIR_Opr _value;
1630 LIR_Opr _tmp;
1631 CodeStub* _stub;
1632 public:
1633 LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
1634 LIR_Opr array() const { return _array; }
1635 LIR_Opr value() const { return _value; }
1636 LIR_Opr tmp() const { return _tmp; }
1637 CodeStub* stub() const { return _stub; }
1638
1639 virtual void emit_code(LIR_Assembler* masm);
1640 virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return this; }
1641 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1642 };
1643
1644 // LIR_OpNullFreeArrayCheck
1645 class LIR_OpNullFreeArrayCheck: public LIR_Op {
1646 friend class LIR_OpVisitState;
1647
1648 private:
1649 LIR_Opr _array;
1650 LIR_Opr _tmp;
1651 public:
1652 LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp);
1653 LIR_Opr array() const { return _array; }
1654 LIR_Opr tmp() const { return _tmp; }
1655
1656 virtual void emit_code(LIR_Assembler* masm);
1657 virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return this; }
1658 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1659 };
1660
1661 class LIR_OpSubstitutabilityCheck: public LIR_Op {
1662 friend class LIR_OpVisitState;
1663
1664 private:
1665 LIR_Opr _left;
1666 LIR_Opr _right;
1667 LIR_Opr _equal_result;
1668 LIR_Opr _not_equal_result;
1669 LIR_Opr _tmp1;
1670 LIR_Opr _tmp2;
1671 ciKlass* _left_klass;
1672 ciKlass* _right_klass;
1673 LIR_Opr _left_klass_op;
1674 LIR_Opr _right_klass_op;
1675 CodeStub* _stub;
1676 public:
1677 LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1678 LIR_Opr tmp1, LIR_Opr tmp2,
1679 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
1680 CodeEmitInfo* info, CodeStub* stub);
1681
1682 LIR_Opr left() const { return _left; }
1683 LIR_Opr right() const { return _right; }
1684 LIR_Opr equal_result() const { return _equal_result; }
1685 LIR_Opr not_equal_result() const { return _not_equal_result; }
1686 LIR_Opr tmp1() const { return _tmp1; }
1687 LIR_Opr tmp2() const { return _tmp2; }
1688 ciKlass* left_klass() const { return _left_klass; }
1689 ciKlass* right_klass() const { return _right_klass; }
1690 LIR_Opr left_klass_op() const { return _left_klass_op; }
1691 LIR_Opr right_klass_op() const { return _right_klass_op; }
1692 CodeStub* stub() const { return _stub; }
1693
1694 virtual void emit_code(LIR_Assembler* masm);
1695 virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return this; }
1696 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1697 };
1698
1699 // LIR_Op2
1700 class LIR_Op2: public LIR_Op {
1701 friend class LIR_OpVisitState;
1702
1703 protected:
1704 LIR_Opr _opr1;
1705 LIR_Opr _opr2;
1706 LIR_Opr _tmp1;
1707 LIR_Opr _tmp2;
1708 LIR_Opr _tmp3;
1709 LIR_Opr _tmp4;
1710 LIR_Opr _tmp5;
1711 LIR_Condition _condition;
1712 BasicType _type;
1713
1714 void verify() const;
1715
1716 public:
1717 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1718 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1837 void negate_cond();
1838
1839 virtual void emit_code(LIR_Assembler* masm);
1840 virtual LIR_OpBranch* as_OpBranch() { return this; }
1841 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1842 };
1843
1844 class LIR_OpAllocArray : public LIR_Op {
1845 friend class LIR_OpVisitState;
1846
1847 private:
1848 LIR_Opr _klass;
1849 LIR_Opr _len;
1850 LIR_Opr _tmp1;
1851 LIR_Opr _tmp2;
1852 LIR_Opr _tmp3;
1853 LIR_Opr _tmp4;
1854 CodeStub* _stub;
1855 BasicType _type;
1856 bool _zero_array;
1857 bool _is_null_free;
1858
1859 public:
1860 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 is_null_free)
1861 : LIR_Op(lir_alloc_array, result, nullptr)
1862 , _klass(klass)
1863 , _len(len)
1864 , _tmp1(t1)
1865 , _tmp2(t2)
1866 , _tmp3(t3)
1867 , _tmp4(t4)
1868 , _stub(stub)
1869 , _type(type)
1870 , _zero_array(zero_array)
1871 , _is_null_free(is_null_free) {}
1872
1873 LIR_Opr klass() const { return _klass; }
1874 LIR_Opr len() const { return _len; }
1875 LIR_Opr obj() const { return result_opr(); }
1876 LIR_Opr tmp1() const { return _tmp1; }
1877 LIR_Opr tmp2() const { return _tmp2; }
1878 LIR_Opr tmp3() const { return _tmp3; }
1879 LIR_Opr tmp4() const { return _tmp4; }
1880 BasicType type() const { return _type; }
1881 CodeStub* stub() const { return _stub; }
1882 bool zero_array() const { return _zero_array; }
1883 bool is_null_free() const { return _is_null_free;}
1884
1885 virtual void emit_code(LIR_Assembler* masm);
1886 virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1887 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1888 };
1889
1890
1891 class LIR_Op3: public LIR_Op {
1892 friend class LIR_OpVisitState;
1893
1894 private:
1895 LIR_Opr _opr1;
1896 LIR_Opr _opr2;
1897 LIR_Opr _opr3;
1898 public:
1899 LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1900 : LIR_Op(code, result, info)
1901 , _opr1(opr1)
1902 , _opr2(opr2)
1903 , _opr3(opr3) { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1970
1971 //--------------------------------
1972 class LabelObj: public CompilationResourceObj {
1973 private:
1974 Label _label;
1975 public:
1976 LabelObj() {}
1977 Label* label() { return &_label; }
1978 };
1979
1980
1981 class LIR_OpLock: public LIR_Op {
1982 friend class LIR_OpVisitState;
1983
1984 private:
1985 LIR_Opr _hdr;
1986 LIR_Opr _obj;
1987 LIR_Opr _lock;
1988 LIR_Opr _scratch;
1989 CodeStub* _stub;
1990 CodeStub* _throw_ie_stub;
1991 public:
1992 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)
1993 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1994 , _hdr(hdr)
1995 , _obj(obj)
1996 , _lock(lock)
1997 , _scratch(scratch)
1998 , _stub(stub)
1999 , _throw_ie_stub(throw_ie_stub) {}
2000
2001 LIR_Opr hdr_opr() const { return _hdr; }
2002 LIR_Opr obj_opr() const { return _obj; }
2003 LIR_Opr lock_opr() const { return _lock; }
2004 LIR_Opr scratch_opr() const { return _scratch; }
2005 CodeStub* stub() const { return _stub; }
2006 CodeStub* throw_ie_stub() const { return _throw_ie_stub; }
2007
2008 virtual void emit_code(LIR_Assembler* masm);
2009 virtual LIR_OpLock* as_OpLock() { return this; }
2010 void print_instr(outputStream* out) const PRODUCT_RETURN;
2011 };
2012
2013 class LIR_OpLoadKlass: public LIR_Op {
2014 friend class LIR_OpVisitState;
2015
2016 private:
2017 LIR_Opr _obj;
2018 public:
2019 LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
2020 : LIR_Op(lir_load_klass, result, info)
2021 , _obj(obj)
2022 {}
2023
2024 LIR_Opr obj() const { return _obj; }
2025
2026 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }
2171 , _obj(obj)
2172 , _tmp(tmp)
2173 , _exact_klass(exact_klass)
2174 , _current_klass(current_klass)
2175 , _not_null(not_null)
2176 , _no_conflict(no_conflict) { }
2177
2178 LIR_Opr mdp() const { return _mdp; }
2179 LIR_Opr obj() const { return _obj; }
2180 LIR_Opr tmp() const { return _tmp; }
2181 ciKlass* exact_klass() const { return _exact_klass; }
2182 intptr_t current_klass() const { return _current_klass; }
2183 bool not_null() const { return _not_null; }
2184 bool no_conflict() const { return _no_conflict; }
2185
2186 virtual void emit_code(LIR_Assembler* masm);
2187 virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2188 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2189 };
2190
2191 // LIR_OpProfileInlineType
2192 class LIR_OpProfileInlineType : public LIR_Op {
2193 friend class LIR_OpVisitState;
2194
2195 private:
2196 LIR_Opr _mdp;
2197 LIR_Opr _obj;
2198 int _flag;
2199 LIR_Opr _tmp;
2200 bool _not_null; // true if we know statically that _obj cannot be null
2201
2202 public:
2203 // Destroys recv
2204 LIR_OpProfileInlineType(LIR_Opr mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null)
2205 : LIR_Op(lir_profile_inline_type, LIR_OprFact::illegalOpr, nullptr) // no result, no info
2206 , _mdp(mdp)
2207 , _obj(obj)
2208 , _flag(flag)
2209 , _tmp(tmp)
2210 , _not_null(not_null) { }
2211
2212 LIR_Opr mdp() const { return _mdp; }
2213 LIR_Opr obj() const { return _obj; }
2214 int flag() const { return _flag; }
2215 LIR_Opr tmp() const { return _tmp; }
2216 bool not_null() const { return _not_null; }
2217
2218 virtual void emit_code(LIR_Assembler* masm);
2219 virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return this; }
2220 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2221 };
2222
2223 class LIR_InsertionBuffer;
2224
2225 //--------------------------------LIR_List---------------------------------------------------
2226 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2227 // The LIR instructions are appended by the LIR_List class itself;
2228 //
2229 // Notes:
2230 // - all offsets are(should be) in bytes
2231 // - local positions are specified with an offset, with offset 0 being local 0
2232
2233 class LIR_List: public CompilationResourceObj {
2234 private:
2235 LIR_OpList _operations;
2236
2237 Compilation* _compilation;
2238 #ifndef PRODUCT
2239 BlockBegin* _block;
2240 #endif
2241 #ifdef ASSERT
2242 const char * _file;
2428 void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2429 void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr) { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2430
2431 void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2432 void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2433
2434 void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2435
2436 void store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2437 void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2438 void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2439 void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2440 void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2441
2442 void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2443 void idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2444 void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2445 void irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2446
2447 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);
2448 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 is_null_free = false);
2449
2450 // jump is an unconditional branch
2451 void jump(BlockBegin* block) {
2452 append(new LIR_OpBranch(lir_cond_always, block));
2453 }
2454 void jump(CodeStub* stub) {
2455 append(new LIR_OpBranch(lir_cond_always, stub));
2456 }
2457 void branch(LIR_Condition cond, Label* lbl) {
2458 append(new LIR_OpBranch(cond, lbl));
2459 }
2460 // Should not be used for fp comparisons
2461 void branch(LIR_Condition cond, BlockBegin* block) {
2462 append(new LIR_OpBranch(cond, block));
2463 }
2464 // Should not be used for fp comparisons
2465 void branch(LIR_Condition cond, CodeStub* stub) {
2466 append(new LIR_OpBranch(cond, stub));
2467 }
2468 // Should only be used for fp comparisons
2475 void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2476
2477 void shift_left(LIR_Opr value, int count, LIR_Opr dst) { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2478 void shift_right(LIR_Opr value, int count, LIR_Opr dst) { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2479 void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2480
2481 void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_cmp_l2i, left, right, dst)); }
2482 void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2483
2484 void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2485 append(new LIR_OpRTCall(routine, tmp, result, arguments));
2486 }
2487
2488 void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2489 LIR_OprList* arguments, CodeEmitInfo* info) {
2490 append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2491 }
2492
2493 void load_stack_address_monitor(int monitor_ix, LIR_Opr dst) { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2494 void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2495 void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub=nullptr);
2496
2497 void breakpoint() { append(new LIR_Op0(lir_breakpoint)); }
2498
2499 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)); }
2500
2501 void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2502
2503 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);
2504 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);
2505 void check_flat_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
2506 void check_null_free_array(LIR_Opr array, LIR_Opr tmp);
2507 void substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
2508 LIR_Opr tmp1, LIR_Opr tmp2,
2509 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
2510 CodeEmitInfo* info, CodeStub* stub);
2511
2512 void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2513 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2514 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2515 ciMethod* profiled_method, int profiled_bci, bool is_null_free);
2516 // MethodData* profiling
2517 void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2518 append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2519 }
2520 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) {
2521 append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2522 }
2523 void profile_inline_type(LIR_Address* mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null) {
2524 append(new LIR_OpProfileInlineType(LIR_OprFact::address(mdp), obj, flag, tmp, not_null));
2525 }
2526
2527 void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2528 void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2529
2530 void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2531
2532 #ifdef ASSERT
2533 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)); }
2534 #endif
2535 };
2536
2537 void print_LIR(BlockList* blocks);
2538
2539 class LIR_InsertionBuffer : public CompilationResourceObj {
2540 private:
2541 LIR_List* _lir; // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2542
2543 // list of insertion points. index and count are stored alternately:
2544 // _index_and_count[i * 2]: the index into lir list where "count" ops should be inserted
2545 // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
|