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;
1502
1503
1504 // LIR_OpTypeCheck
1505 class LIR_OpTypeCheck: public LIR_Op {
1506 friend class LIR_OpVisitState;
1507
1508 private:
1509 LIR_Opr _object;
1510 LIR_Opr _array;
1511 ciKlass* _klass;
1512 LIR_Opr _tmp1;
1513 LIR_Opr _tmp2;
1514 LIR_Opr _tmp3;
1515 CodeEmitInfo* _info_for_patch;
1516 CodeEmitInfo* _info_for_exception;
1517 CodeStub* _stub;
1518 ciMethod* _profiled_method;
1519 int _profiled_bci;
1520 bool _should_profile;
1521 bool _fast_check;
1522
1523 public:
1524 LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1525 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1526 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub);
1527 LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1528 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1529
1530 LIR_Opr object() const { return _object; }
1531 LIR_Opr array() const { assert(code() == lir_store_check, "not valid"); return _array; }
1532 LIR_Opr tmp1() const { return _tmp1; }
1533 LIR_Opr tmp2() const { return _tmp2; }
1534 LIR_Opr tmp3() const { return _tmp3; }
1535 ciKlass* klass() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass; }
1536 bool fast_check() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check; }
1537 CodeEmitInfo* info_for_patch() const { return _info_for_patch; }
1538 CodeEmitInfo* info_for_exception() const { return _info_for_exception; }
1539 CodeStub* stub() const { return _stub; }
1540
1541 // MethodData* profiling
1542 void set_profiled_method(ciMethod *method) { _profiled_method = method; }
1543 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1544 void set_should_profile(bool b) { _should_profile = b; }
1545 ciMethod* profiled_method() const { return _profiled_method; }
1546 int profiled_bci() const { return _profiled_bci; }
1547 bool should_profile() const { return _should_profile; }
1548
1549 virtual bool is_patching() { return _info_for_patch != nullptr; }
1550 virtual void emit_code(LIR_Assembler* masm);
1551 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1552 void print_instr(outputStream* out) const PRODUCT_RETURN;
1553 };
1554
1555 // LIR_Op2
1556 class LIR_Op2: public LIR_Op {
1557 friend class LIR_OpVisitState;
1558
1559 protected:
1560 LIR_Opr _opr1;
1561 LIR_Opr _opr2;
1562 LIR_Opr _tmp1;
1563 LIR_Opr _tmp2;
1564 LIR_Opr _tmp3;
1565 LIR_Opr _tmp4;
1566 LIR_Opr _tmp5;
1567 LIR_Condition _condition;
1568 BasicType _type;
1569
1570 void verify() const;
1571
1572 public:
1573 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1574 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1693 void negate_cond();
1694
1695 virtual void emit_code(LIR_Assembler* masm);
1696 virtual LIR_OpBranch* as_OpBranch() { return this; }
1697 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1698 };
1699
1700 class LIR_OpAllocArray : public LIR_Op {
1701 friend class LIR_OpVisitState;
1702
1703 private:
1704 LIR_Opr _klass;
1705 LIR_Opr _len;
1706 LIR_Opr _tmp1;
1707 LIR_Opr _tmp2;
1708 LIR_Opr _tmp3;
1709 LIR_Opr _tmp4;
1710 CodeStub* _stub;
1711 BasicType _type;
1712 bool _zero_array;
1713
1714 public:
1715 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)
1716 : LIR_Op(lir_alloc_array, result, nullptr)
1717 , _klass(klass)
1718 , _len(len)
1719 , _tmp1(t1)
1720 , _tmp2(t2)
1721 , _tmp3(t3)
1722 , _tmp4(t4)
1723 , _stub(stub)
1724 , _type(type)
1725 , _zero_array(zero_array) {}
1726
1727 LIR_Opr klass() const { return _klass; }
1728 LIR_Opr len() const { return _len; }
1729 LIR_Opr obj() const { return result_opr(); }
1730 LIR_Opr tmp1() const { return _tmp1; }
1731 LIR_Opr tmp2() const { return _tmp2; }
1732 LIR_Opr tmp3() const { return _tmp3; }
1733 LIR_Opr tmp4() const { return _tmp4; }
1734 BasicType type() const { return _type; }
1735 CodeStub* stub() const { return _stub; }
1736 bool zero_array() const { return _zero_array; }
1737
1738 virtual void emit_code(LIR_Assembler* masm);
1739 virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1740 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1741 };
1742
1743
1744 class LIR_Op3: public LIR_Op {
1745 friend class LIR_OpVisitState;
1746
1747 private:
1748 LIR_Opr _opr1;
1749 LIR_Opr _opr2;
1750 LIR_Opr _opr3;
1751 public:
1752 LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1753 : LIR_Op(code, result, info)
1754 , _opr1(opr1)
1755 , _opr2(opr2)
1756 , _opr3(opr3) { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1823
1824 //--------------------------------
1825 class LabelObj: public CompilationResourceObj {
1826 private:
1827 Label _label;
1828 public:
1829 LabelObj() {}
1830 Label* label() { return &_label; }
1831 };
1832
1833
1834 class LIR_OpLock: public LIR_Op {
1835 friend class LIR_OpVisitState;
1836
1837 private:
1838 LIR_Opr _hdr;
1839 LIR_Opr _obj;
1840 LIR_Opr _lock;
1841 LIR_Opr _scratch;
1842 CodeStub* _stub;
1843 public:
1844 LIR_OpLock(LIR_Code code, LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info)
1845 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1846 , _hdr(hdr)
1847 , _obj(obj)
1848 , _lock(lock)
1849 , _scratch(scratch)
1850 , _stub(stub) {}
1851
1852 LIR_Opr hdr_opr() const { return _hdr; }
1853 LIR_Opr obj_opr() const { return _obj; }
1854 LIR_Opr lock_opr() const { return _lock; }
1855 LIR_Opr scratch_opr() const { return _scratch; }
1856 CodeStub* stub() const { return _stub; }
1857
1858 virtual void emit_code(LIR_Assembler* masm);
1859 virtual LIR_OpLock* as_OpLock() { return this; }
1860 void print_instr(outputStream* out) const PRODUCT_RETURN;
1861 };
1862
1863 class LIR_OpLoadKlass: public LIR_Op {
1864 friend class LIR_OpVisitState;
1865
1866 private:
1867 LIR_Opr _obj;
1868 public:
1869 LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1870 : LIR_Op(lir_load_klass, result, info)
1871 , _obj(obj)
1872 {}
1873
1874 LIR_Opr obj() const { return _obj; }
1875
1876 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }
2002 , _obj(obj)
2003 , _tmp(tmp)
2004 , _exact_klass(exact_klass)
2005 , _current_klass(current_klass)
2006 , _not_null(not_null)
2007 , _no_conflict(no_conflict) { }
2008
2009 LIR_Opr mdp() const { return _mdp; }
2010 LIR_Opr obj() const { return _obj; }
2011 LIR_Opr tmp() const { return _tmp; }
2012 ciKlass* exact_klass() const { return _exact_klass; }
2013 intptr_t current_klass() const { return _current_klass; }
2014 bool not_null() const { return _not_null; }
2015 bool no_conflict() const { return _no_conflict; }
2016
2017 virtual void emit_code(LIR_Assembler* masm);
2018 virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2019 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2020 };
2021
2022 class LIR_InsertionBuffer;
2023
2024 //--------------------------------LIR_List---------------------------------------------------
2025 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2026 // The LIR instructions are appended by the LIR_List class itself;
2027 //
2028 // Notes:
2029 // - all offsets are(should be) in bytes
2030 // - local positions are specified with an offset, with offset 0 being local 0
2031
2032 class LIR_List: public CompilationResourceObj {
2033 private:
2034 LIR_OpList _operations;
2035
2036 Compilation* _compilation;
2037 #ifndef PRODUCT
2038 BlockBegin* _block;
2039 #endif
2040 #ifdef ASSERT
2041 const char * _file;
2226 void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2227 void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr) { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2228
2229 void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2230 void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2231
2232 void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2233
2234 void store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2235 void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2236 void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2237 void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2238 void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2239
2240 void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2241 void idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2242 void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2243 void irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2244
2245 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);
2246 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);
2247
2248 // jump is an unconditional branch
2249 void jump(BlockBegin* block) {
2250 append(new LIR_OpBranch(lir_cond_always, block));
2251 }
2252 void jump(CodeStub* stub) {
2253 append(new LIR_OpBranch(lir_cond_always, stub));
2254 }
2255 void branch(LIR_Condition cond, Label* lbl) {
2256 append(new LIR_OpBranch(cond, lbl));
2257 }
2258 // Should not be used for fp comparisons
2259 void branch(LIR_Condition cond, BlockBegin* block) {
2260 append(new LIR_OpBranch(cond, block));
2261 }
2262 // Should not be used for fp comparisons
2263 void branch(LIR_Condition cond, CodeStub* stub) {
2264 append(new LIR_OpBranch(cond, stub));
2265 }
2266 // Should only be used for fp comparisons
2273 void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2274
2275 void shift_left(LIR_Opr value, int count, LIR_Opr dst) { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2276 void shift_right(LIR_Opr value, int count, LIR_Opr dst) { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2277 void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2278
2279 void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_cmp_l2i, left, right, dst)); }
2280 void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2281
2282 void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2283 append(new LIR_OpRTCall(routine, tmp, result, arguments));
2284 }
2285
2286 void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2287 LIR_OprList* arguments, CodeEmitInfo* info) {
2288 append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2289 }
2290
2291 void load_stack_address_monitor(int monitor_ix, LIR_Opr dst) { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2292 void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2293 void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info);
2294
2295 void breakpoint() { append(new LIR_Op0(lir_breakpoint)); }
2296
2297 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)); }
2298
2299 void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2300
2301 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);
2302 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);
2303
2304 void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2305 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2306 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2307 ciMethod* profiled_method, int profiled_bci);
2308 // MethodData* profiling
2309 void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2310 append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2311 }
2312 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) {
2313 append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2314 }
2315
2316 void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2317 void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2318
2319 void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2320
2321 #ifdef ASSERT
2322 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)); }
2323 #endif
2324 };
2325
2326 void print_LIR(BlockList* blocks);
2327
2328 class LIR_InsertionBuffer : public CompilationResourceObj {
2329 private:
2330 LIR_List* _lir; // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2331
2332 // list of insertion points. index and count are stored alternately:
2333 // _index_and_count[i * 2]: the index into lir list where "count" ops should be inserted
2334 // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
|
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;
1526
1527
1528 // LIR_OpTypeCheck
1529 class LIR_OpTypeCheck: public LIR_Op {
1530 friend class LIR_OpVisitState;
1531
1532 private:
1533 LIR_Opr _object;
1534 LIR_Opr _array;
1535 ciKlass* _klass;
1536 LIR_Opr _tmp1;
1537 LIR_Opr _tmp2;
1538 LIR_Opr _tmp3;
1539 CodeEmitInfo* _info_for_patch;
1540 CodeEmitInfo* _info_for_exception;
1541 CodeStub* _stub;
1542 ciMethod* _profiled_method;
1543 int _profiled_bci;
1544 bool _should_profile;
1545 bool _fast_check;
1546 bool _need_null_check;
1547
1548 public:
1549 LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1550 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1551 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub, bool need_null_check = true);
1552 LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1553 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1554
1555 LIR_Opr object() const { return _object; }
1556 LIR_Opr array() const { assert(code() == lir_store_check, "not valid"); return _array; }
1557 LIR_Opr tmp1() const { return _tmp1; }
1558 LIR_Opr tmp2() const { return _tmp2; }
1559 LIR_Opr tmp3() const { return _tmp3; }
1560 ciKlass* klass() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass; }
1561 bool fast_check() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check; }
1562 CodeEmitInfo* info_for_patch() const { return _info_for_patch; }
1563 CodeEmitInfo* info_for_exception() const { return _info_for_exception; }
1564 CodeStub* stub() const { return _stub; }
1565
1566 // MethodData* profiling
1567 void set_profiled_method(ciMethod *method) { _profiled_method = method; }
1568 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1569 void set_should_profile(bool b) { _should_profile = b; }
1570 ciMethod* profiled_method() const { return _profiled_method; }
1571 int profiled_bci() const { return _profiled_bci; }
1572 bool should_profile() const { return _should_profile; }
1573 bool need_null_check() const { return _need_null_check; }
1574 virtual bool is_patching() { return _info_for_patch != nullptr; }
1575 virtual void emit_code(LIR_Assembler* masm);
1576 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1577 void print_instr(outputStream* out) const PRODUCT_RETURN;
1578 };
1579
1580 // LIR_OpFlattenedArrayCheck
1581 class LIR_OpFlattenedArrayCheck: public LIR_Op {
1582 friend class LIR_OpVisitState;
1583
1584 private:
1585 LIR_Opr _array;
1586 LIR_Opr _value;
1587 LIR_Opr _tmp;
1588 CodeStub* _stub;
1589 public:
1590 LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
1591 LIR_Opr array() const { return _array; }
1592 LIR_Opr value() const { return _value; }
1593 LIR_Opr tmp() const { return _tmp; }
1594 CodeStub* stub() const { return _stub; }
1595
1596 virtual void emit_code(LIR_Assembler* masm);
1597 virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return this; }
1598 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1599 };
1600
1601 // LIR_OpNullFreeArrayCheck
1602 class LIR_OpNullFreeArrayCheck: public LIR_Op {
1603 friend class LIR_OpVisitState;
1604
1605 private:
1606 LIR_Opr _array;
1607 LIR_Opr _tmp;
1608 public:
1609 LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp);
1610 LIR_Opr array() const { return _array; }
1611 LIR_Opr tmp() const { return _tmp; }
1612
1613 virtual void emit_code(LIR_Assembler* masm);
1614 virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return this; }
1615 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1616 };
1617
1618 class LIR_OpSubstitutabilityCheck: public LIR_Op {
1619 friend class LIR_OpVisitState;
1620
1621 private:
1622 LIR_Opr _left;
1623 LIR_Opr _right;
1624 LIR_Opr _equal_result;
1625 LIR_Opr _not_equal_result;
1626 LIR_Opr _tmp1;
1627 LIR_Opr _tmp2;
1628 ciKlass* _left_klass;
1629 ciKlass* _right_klass;
1630 LIR_Opr _left_klass_op;
1631 LIR_Opr _right_klass_op;
1632 CodeStub* _stub;
1633 public:
1634 LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1635 LIR_Opr tmp1, LIR_Opr tmp2,
1636 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
1637 CodeEmitInfo* info, CodeStub* stub);
1638
1639 LIR_Opr left() const { return _left; }
1640 LIR_Opr right() const { return _right; }
1641 LIR_Opr equal_result() const { return _equal_result; }
1642 LIR_Opr not_equal_result() const { return _not_equal_result; }
1643 LIR_Opr tmp1() const { return _tmp1; }
1644 LIR_Opr tmp2() const { return _tmp2; }
1645 ciKlass* left_klass() const { return _left_klass; }
1646 ciKlass* right_klass() const { return _right_klass; }
1647 LIR_Opr left_klass_op() const { return _left_klass_op; }
1648 LIR_Opr right_klass_op() const { return _right_klass_op; }
1649 CodeStub* stub() const { return _stub; }
1650
1651 virtual void emit_code(LIR_Assembler* masm);
1652 virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return this; }
1653 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1654 };
1655
1656 // LIR_Op2
1657 class LIR_Op2: public LIR_Op {
1658 friend class LIR_OpVisitState;
1659
1660 protected:
1661 LIR_Opr _opr1;
1662 LIR_Opr _opr2;
1663 LIR_Opr _tmp1;
1664 LIR_Opr _tmp2;
1665 LIR_Opr _tmp3;
1666 LIR_Opr _tmp4;
1667 LIR_Opr _tmp5;
1668 LIR_Condition _condition;
1669 BasicType _type;
1670
1671 void verify() const;
1672
1673 public:
1674 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1675 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1794 void negate_cond();
1795
1796 virtual void emit_code(LIR_Assembler* masm);
1797 virtual LIR_OpBranch* as_OpBranch() { return this; }
1798 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1799 };
1800
1801 class LIR_OpAllocArray : public LIR_Op {
1802 friend class LIR_OpVisitState;
1803
1804 private:
1805 LIR_Opr _klass;
1806 LIR_Opr _len;
1807 LIR_Opr _tmp1;
1808 LIR_Opr _tmp2;
1809 LIR_Opr _tmp3;
1810 LIR_Opr _tmp4;
1811 CodeStub* _stub;
1812 BasicType _type;
1813 bool _zero_array;
1814 bool _always_slow_path;
1815
1816 public:
1817 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)
1818 : LIR_Op(lir_alloc_array, result, nullptr)
1819 , _klass(klass)
1820 , _len(len)
1821 , _tmp1(t1)
1822 , _tmp2(t2)
1823 , _tmp3(t3)
1824 , _tmp4(t4)
1825 , _stub(stub)
1826 , _type(type)
1827 , _zero_array(zero_array)
1828 , _always_slow_path(always_slow_path) {}
1829
1830 LIR_Opr klass() const { return _klass; }
1831 LIR_Opr len() const { return _len; }
1832 LIR_Opr obj() const { return result_opr(); }
1833 LIR_Opr tmp1() const { return _tmp1; }
1834 LIR_Opr tmp2() const { return _tmp2; }
1835 LIR_Opr tmp3() const { return _tmp3; }
1836 LIR_Opr tmp4() const { return _tmp4; }
1837 BasicType type() const { return _type; }
1838 CodeStub* stub() const { return _stub; }
1839 bool zero_array() const { return _zero_array; }
1840 bool always_slow_path() const { return _always_slow_path; }
1841
1842 virtual void emit_code(LIR_Assembler* masm);
1843 virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1844 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1845 };
1846
1847
1848 class LIR_Op3: public LIR_Op {
1849 friend class LIR_OpVisitState;
1850
1851 private:
1852 LIR_Opr _opr1;
1853 LIR_Opr _opr2;
1854 LIR_Opr _opr3;
1855 public:
1856 LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1857 : LIR_Op(code, result, info)
1858 , _opr1(opr1)
1859 , _opr2(opr2)
1860 , _opr3(opr3) { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1927
1928 //--------------------------------
1929 class LabelObj: public CompilationResourceObj {
1930 private:
1931 Label _label;
1932 public:
1933 LabelObj() {}
1934 Label* label() { return &_label; }
1935 };
1936
1937
1938 class LIR_OpLock: public LIR_Op {
1939 friend class LIR_OpVisitState;
1940
1941 private:
1942 LIR_Opr _hdr;
1943 LIR_Opr _obj;
1944 LIR_Opr _lock;
1945 LIR_Opr _scratch;
1946 CodeStub* _stub;
1947 CodeStub* _throw_ie_stub;
1948 public:
1949 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)
1950 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1951 , _hdr(hdr)
1952 , _obj(obj)
1953 , _lock(lock)
1954 , _scratch(scratch)
1955 , _stub(stub)
1956 , _throw_ie_stub(throw_ie_stub) {}
1957
1958 LIR_Opr hdr_opr() const { return _hdr; }
1959 LIR_Opr obj_opr() const { return _obj; }
1960 LIR_Opr lock_opr() const { return _lock; }
1961 LIR_Opr scratch_opr() const { return _scratch; }
1962 CodeStub* stub() const { return _stub; }
1963 CodeStub* throw_ie_stub() const { return _throw_ie_stub; }
1964
1965 virtual void emit_code(LIR_Assembler* masm);
1966 virtual LIR_OpLock* as_OpLock() { return this; }
1967 void print_instr(outputStream* out) const PRODUCT_RETURN;
1968 };
1969
1970 class LIR_OpLoadKlass: public LIR_Op {
1971 friend class LIR_OpVisitState;
1972
1973 private:
1974 LIR_Opr _obj;
1975 public:
1976 LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1977 : LIR_Op(lir_load_klass, result, info)
1978 , _obj(obj)
1979 {}
1980
1981 LIR_Opr obj() const { return _obj; }
1982
1983 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }
2109 , _obj(obj)
2110 , _tmp(tmp)
2111 , _exact_klass(exact_klass)
2112 , _current_klass(current_klass)
2113 , _not_null(not_null)
2114 , _no_conflict(no_conflict) { }
2115
2116 LIR_Opr mdp() const { return _mdp; }
2117 LIR_Opr obj() const { return _obj; }
2118 LIR_Opr tmp() const { return _tmp; }
2119 ciKlass* exact_klass() const { return _exact_klass; }
2120 intptr_t current_klass() const { return _current_klass; }
2121 bool not_null() const { return _not_null; }
2122 bool no_conflict() const { return _no_conflict; }
2123
2124 virtual void emit_code(LIR_Assembler* masm);
2125 virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2126 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2127 };
2128
2129 // LIR_OpProfileInlineType
2130 class LIR_OpProfileInlineType : public LIR_Op {
2131 friend class LIR_OpVisitState;
2132
2133 private:
2134 LIR_Opr _mdp;
2135 LIR_Opr _obj;
2136 int _flag;
2137 LIR_Opr _tmp;
2138 bool _not_null; // true if we know statically that _obj cannot be null
2139
2140 public:
2141 // Destroys recv
2142 LIR_OpProfileInlineType(LIR_Opr mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null)
2143 : LIR_Op(lir_profile_inline_type, LIR_OprFact::illegalOpr, nullptr) // no result, no info
2144 , _mdp(mdp)
2145 , _obj(obj)
2146 , _flag(flag)
2147 , _tmp(tmp)
2148 , _not_null(not_null) { }
2149
2150 LIR_Opr mdp() const { return _mdp; }
2151 LIR_Opr obj() const { return _obj; }
2152 int flag() const { return _flag; }
2153 LIR_Opr tmp() const { return _tmp; }
2154 bool not_null() const { return _not_null; }
2155
2156 virtual void emit_code(LIR_Assembler* masm);
2157 virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return this; }
2158 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2159 };
2160
2161 class LIR_InsertionBuffer;
2162
2163 //--------------------------------LIR_List---------------------------------------------------
2164 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2165 // The LIR instructions are appended by the LIR_List class itself;
2166 //
2167 // Notes:
2168 // - all offsets are(should be) in bytes
2169 // - local positions are specified with an offset, with offset 0 being local 0
2170
2171 class LIR_List: public CompilationResourceObj {
2172 private:
2173 LIR_OpList _operations;
2174
2175 Compilation* _compilation;
2176 #ifndef PRODUCT
2177 BlockBegin* _block;
2178 #endif
2179 #ifdef ASSERT
2180 const char * _file;
2365 void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2366 void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr) { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2367
2368 void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2369 void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2370
2371 void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2372
2373 void store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2374 void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2375 void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2376 void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2377 void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2378
2379 void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2380 void idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2381 void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2382 void irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2383
2384 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);
2385 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);
2386
2387 // jump is an unconditional branch
2388 void jump(BlockBegin* block) {
2389 append(new LIR_OpBranch(lir_cond_always, block));
2390 }
2391 void jump(CodeStub* stub) {
2392 append(new LIR_OpBranch(lir_cond_always, stub));
2393 }
2394 void branch(LIR_Condition cond, Label* lbl) {
2395 append(new LIR_OpBranch(cond, lbl));
2396 }
2397 // Should not be used for fp comparisons
2398 void branch(LIR_Condition cond, BlockBegin* block) {
2399 append(new LIR_OpBranch(cond, block));
2400 }
2401 // Should not be used for fp comparisons
2402 void branch(LIR_Condition cond, CodeStub* stub) {
2403 append(new LIR_OpBranch(cond, stub));
2404 }
2405 // Should only be used for fp comparisons
2412 void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2413
2414 void shift_left(LIR_Opr value, int count, LIR_Opr dst) { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2415 void shift_right(LIR_Opr value, int count, LIR_Opr dst) { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2416 void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2417
2418 void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_cmp_l2i, left, right, dst)); }
2419 void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2420
2421 void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2422 append(new LIR_OpRTCall(routine, tmp, result, arguments));
2423 }
2424
2425 void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2426 LIR_OprList* arguments, CodeEmitInfo* info) {
2427 append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2428 }
2429
2430 void load_stack_address_monitor(int monitor_ix, LIR_Opr dst) { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2431 void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2432 void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub=nullptr);
2433
2434 void breakpoint() { append(new LIR_Op0(lir_breakpoint)); }
2435
2436 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)); }
2437
2438 void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2439
2440 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);
2441 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);
2442 void check_flat_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
2443 void check_null_free_array(LIR_Opr array, LIR_Opr tmp);
2444 void substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
2445 LIR_Opr tmp1, LIR_Opr tmp2,
2446 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
2447 CodeEmitInfo* info, CodeStub* stub);
2448
2449 void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2450 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2451 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2452 ciMethod* profiled_method, int profiled_bci, bool is_null_free);
2453 // MethodData* profiling
2454 void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2455 append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2456 }
2457 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) {
2458 append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2459 }
2460 void profile_inline_type(LIR_Address* mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null) {
2461 append(new LIR_OpProfileInlineType(LIR_OprFact::address(mdp), obj, flag, tmp, not_null));
2462 }
2463
2464 void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2465 void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2466
2467 void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2468
2469 #ifdef ASSERT
2470 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)); }
2471 #endif
2472 };
2473
2474 void print_LIR(BlockList* blocks);
2475
2476 class LIR_InsertionBuffer : public CompilationResourceObj {
2477 private:
2478 LIR_List* _lir; // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2479
2480 // list of insertion points. index and count are stored alternately:
2481 // _index_and_count[i * 2]: the index into lir list where "count" ops should be inserted
2482 // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
|