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_OpDelay;
883 class LIR_Op3;
884 class LIR_OpAllocArray;
885 class LIR_Op4;
886 class LIR_OpCall;
887 class LIR_OpJavaCall;
888 class LIR_OpRTCall;
889 class LIR_OpArrayCopy;
890 class LIR_OpUpdateCRC32;
891 class LIR_OpLock;
892 class LIR_OpTypeCheck;
893 class LIR_OpCompareAndSwap;
894 class LIR_OpLoadKlass;
895 class LIR_OpProfileCall;
896 class LIR_OpProfileType;
897 #ifdef ASSERT
898 class LIR_OpAssert;
899 #endif
900
901 // LIR operation codes
902 enum LIR_Code {
903 lir_none
904 , begin_op0
905 , lir_label
906 , lir_nop
907 , lir_std_entry
908 , lir_osr_entry
909 , lir_breakpoint
910 , lir_rtcall
911 , lir_membar
912 , lir_membar_acquire
913 , lir_membar_release
914 , lir_membar_loadload
915 , lir_membar_storestore
916 , lir_membar_loadstore
917 , lir_membar_storeload
918 , lir_get_thread
919 , lir_on_spin_wait
920 , end_op0
921 , begin_op1
922 , lir_push
923 , lir_pop
924 , lir_null_check
925 , lir_return
926 , lir_leal
927 , lir_move
928 , lir_convert
929 , lir_alloc_object
930 , lir_monaddr
931 , lir_sqrt
932 , lir_abs
933 , lir_neg
934 , lir_f2hf
935 , lir_hf2f
936 , lir_safepoint
937 , lir_unwind
938 , lir_load_klass
939 , end_op1
976 , lir_dynamic_call
977 , end_opJavaCall
978 , begin_opArrayCopy
979 , lir_arraycopy
980 , end_opArrayCopy
981 , begin_opUpdateCRC32
982 , lir_updatecrc32
983 , end_opUpdateCRC32
984 , begin_opLock
985 , lir_lock
986 , lir_unlock
987 , end_opLock
988 , begin_delay_slot
989 , lir_delay_slot
990 , end_delay_slot
991 , begin_opTypeCheck
992 , lir_instanceof
993 , lir_checkcast
994 , lir_store_check
995 , end_opTypeCheck
996 , begin_opCompareAndSwap
997 , lir_cas_long
998 , lir_cas_obj
999 , lir_cas_int
1000 , end_opCompareAndSwap
1001 , begin_opMDOProfile
1002 , lir_profile_call
1003 , lir_profile_type
1004 , end_opMDOProfile
1005 , begin_opAssert
1006 , lir_assert
1007 , end_opAssert
1008 #if INCLUDE_ZGC
1009 , begin_opXLoadBarrierTest
1010 , lir_xloadbarrier_test
1011 , end_opXLoadBarrierTest
1012 #endif
1013 };
1014
1015
1016 enum LIR_Condition {
1017 lir_cond_equal
1018 , lir_cond_notEqual
1019 , lir_cond_less
1020 , lir_cond_lessEqual
1021 , lir_cond_greaterEqual
1022 , lir_cond_greater
1023 , lir_cond_belowEqual
1123 virtual bool is_patching() { return false; }
1124 virtual LIR_OpCall* as_OpCall() { return nullptr; }
1125 virtual LIR_OpJavaCall* as_OpJavaCall() { return nullptr; }
1126 virtual LIR_OpLabel* as_OpLabel() { return nullptr; }
1127 virtual LIR_OpDelay* as_OpDelay() { return nullptr; }
1128 virtual LIR_OpLock* as_OpLock() { return nullptr; }
1129 virtual LIR_OpAllocArray* as_OpAllocArray() { return nullptr; }
1130 virtual LIR_OpAllocObj* as_OpAllocObj() { return nullptr; }
1131 virtual LIR_OpBranch* as_OpBranch() { return nullptr; }
1132 virtual LIR_OpReturn* as_OpReturn() { return nullptr; }
1133 virtual LIR_OpRTCall* as_OpRTCall() { return nullptr; }
1134 virtual LIR_OpConvert* as_OpConvert() { return nullptr; }
1135 virtual LIR_Op0* as_Op0() { return nullptr; }
1136 virtual LIR_Op1* as_Op1() { return nullptr; }
1137 virtual LIR_Op2* as_Op2() { return nullptr; }
1138 virtual LIR_Op3* as_Op3() { return nullptr; }
1139 virtual LIR_Op4* as_Op4() { return nullptr; }
1140 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return nullptr; }
1141 virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return nullptr; }
1142 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return nullptr; }
1143 virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return nullptr; }
1144 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return nullptr; }
1145 virtual LIR_OpProfileCall* as_OpProfileCall() { return nullptr; }
1146 virtual LIR_OpProfileType* as_OpProfileType() { return nullptr; }
1147 #ifdef ASSERT
1148 virtual LIR_OpAssert* as_OpAssert() { return nullptr; }
1149 #endif
1150
1151 virtual void verify() const {}
1152 };
1153
1154 // for calls
1155 class LIR_OpCall: public LIR_Op {
1156 friend class LIR_OpVisitState;
1157
1158 protected:
1159 address _addr;
1160 LIR_OprList* _arguments;
1161 protected:
1162 LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1163 LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1164 : LIR_Op(code, result, info)
1165 , _addr(addr)
1166 , _arguments(arguments) {}
1199 LIR_OprList* arguments, CodeEmitInfo* info)
1200 : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1201 , _method(method)
1202 , _receiver(receiver)
1203 , _method_handle_invoke_SP_save_opr(LIR_OprFact::illegalOpr)
1204 { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1205
1206 LIR_Opr receiver() const { return _receiver; }
1207 ciMethod* method() const { return _method; }
1208
1209 // JSR 292 support.
1210 bool is_invokedynamic() const { return code() == lir_dynamic_call; }
1211 bool is_method_handle_invoke() const {
1212 return method()->is_compiled_lambda_form() || // Java-generated lambda form
1213 method()->is_method_handle_intrinsic(); // JVM-generated MH intrinsic
1214 }
1215
1216 virtual void emit_code(LIR_Assembler* masm);
1217 virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1218 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1219 };
1220
1221 // --------------------------------------------------
1222 // LIR_OpLabel
1223 // --------------------------------------------------
1224 // Location where a branch can continue
1225 class LIR_OpLabel: public LIR_Op {
1226 friend class LIR_OpVisitState;
1227
1228 private:
1229 Label* _label;
1230 public:
1231 LIR_OpLabel(Label* lbl)
1232 : LIR_Op(lir_label, LIR_OprFact::illegalOpr, nullptr)
1233 , _label(lbl) {}
1234 Label* label() const { return _label; }
1235
1236 virtual void emit_code(LIR_Assembler* masm);
1237 virtual LIR_OpLabel* as_OpLabel() { return this; }
1238 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1250 LIR_Opr _dst_pos;
1251 LIR_Opr _length;
1252 LIR_Opr _tmp;
1253 ciArrayKlass* _expected_type;
1254 int _flags;
1255
1256 public:
1257 enum Flags {
1258 src_null_check = 1 << 0,
1259 dst_null_check = 1 << 1,
1260 src_pos_positive_check = 1 << 2,
1261 dst_pos_positive_check = 1 << 3,
1262 length_positive_check = 1 << 4,
1263 src_range_check = 1 << 5,
1264 dst_range_check = 1 << 6,
1265 type_check = 1 << 7,
1266 overlapping = 1 << 8,
1267 unaligned = 1 << 9,
1268 src_objarray = 1 << 10,
1269 dst_objarray = 1 << 11,
1270 all_flags = (1 << 12) - 1
1271 };
1272
1273 LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1274 ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1275
1276 LIR_Opr src() const { return _src; }
1277 LIR_Opr src_pos() const { return _src_pos; }
1278 LIR_Opr dst() const { return _dst; }
1279 LIR_Opr dst_pos() const { return _dst_pos; }
1280 LIR_Opr length() const { return _length; }
1281 LIR_Opr tmp() const { return _tmp; }
1282 int flags() const { return _flags; }
1283 ciArrayKlass* expected_type() const { return _expected_type; }
1284 ArrayCopyStub* stub() const { return _stub; }
1285
1286 virtual void emit_code(LIR_Assembler* masm);
1287 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1288 void print_instr(outputStream* out) const PRODUCT_RETURN;
1289 };
1290
1508
1509
1510 // LIR_OpTypeCheck
1511 class LIR_OpTypeCheck: public LIR_Op {
1512 friend class LIR_OpVisitState;
1513
1514 private:
1515 LIR_Opr _object;
1516 LIR_Opr _array;
1517 ciKlass* _klass;
1518 LIR_Opr _tmp1;
1519 LIR_Opr _tmp2;
1520 LIR_Opr _tmp3;
1521 CodeEmitInfo* _info_for_patch;
1522 CodeEmitInfo* _info_for_exception;
1523 CodeStub* _stub;
1524 ciMethod* _profiled_method;
1525 int _profiled_bci;
1526 bool _should_profile;
1527 bool _fast_check;
1528
1529 public:
1530 LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1531 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1532 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub);
1533 LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1534 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1535
1536 LIR_Opr object() const { return _object; }
1537 LIR_Opr array() const { assert(code() == lir_store_check, "not valid"); return _array; }
1538 LIR_Opr tmp1() const { return _tmp1; }
1539 LIR_Opr tmp2() const { return _tmp2; }
1540 LIR_Opr tmp3() const { return _tmp3; }
1541 ciKlass* klass() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass; }
1542 bool fast_check() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check; }
1543 CodeEmitInfo* info_for_patch() const { return _info_for_patch; }
1544 CodeEmitInfo* info_for_exception() const { return _info_for_exception; }
1545 CodeStub* stub() const { return _stub; }
1546
1547 // MethodData* profiling
1548 void set_profiled_method(ciMethod *method) { _profiled_method = method; }
1549 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1550 void set_should_profile(bool b) { _should_profile = b; }
1551 ciMethod* profiled_method() const { return _profiled_method; }
1552 int profiled_bci() const { return _profiled_bci; }
1553 bool should_profile() const { return _should_profile; }
1554
1555 virtual bool is_patching() { return _info_for_patch != nullptr; }
1556 virtual void emit_code(LIR_Assembler* masm);
1557 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1558 void print_instr(outputStream* out) const PRODUCT_RETURN;
1559 };
1560
1561 // LIR_Op2
1562 class LIR_Op2: public LIR_Op {
1563 friend class LIR_OpVisitState;
1564
1565 protected:
1566 LIR_Opr _opr1;
1567 LIR_Opr _opr2;
1568 LIR_Opr _tmp1;
1569 LIR_Opr _tmp2;
1570 LIR_Opr _tmp3;
1571 LIR_Opr _tmp4;
1572 LIR_Opr _tmp5;
1573 LIR_Condition _condition;
1574 BasicType _type;
1575
1576 void verify() const;
1577
1578 public:
1579 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1580 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1699 void negate_cond();
1700
1701 virtual void emit_code(LIR_Assembler* masm);
1702 virtual LIR_OpBranch* as_OpBranch() { return this; }
1703 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1704 };
1705
1706 class LIR_OpAllocArray : public LIR_Op {
1707 friend class LIR_OpVisitState;
1708
1709 private:
1710 LIR_Opr _klass;
1711 LIR_Opr _len;
1712 LIR_Opr _tmp1;
1713 LIR_Opr _tmp2;
1714 LIR_Opr _tmp3;
1715 LIR_Opr _tmp4;
1716 CodeStub* _stub;
1717 BasicType _type;
1718 bool _zero_array;
1719
1720 public:
1721 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)
1722 : LIR_Op(lir_alloc_array, result, nullptr)
1723 , _klass(klass)
1724 , _len(len)
1725 , _tmp1(t1)
1726 , _tmp2(t2)
1727 , _tmp3(t3)
1728 , _tmp4(t4)
1729 , _stub(stub)
1730 , _type(type)
1731 , _zero_array(zero_array) {}
1732
1733 LIR_Opr klass() const { return _klass; }
1734 LIR_Opr len() const { return _len; }
1735 LIR_Opr obj() const { return result_opr(); }
1736 LIR_Opr tmp1() const { return _tmp1; }
1737 LIR_Opr tmp2() const { return _tmp2; }
1738 LIR_Opr tmp3() const { return _tmp3; }
1739 LIR_Opr tmp4() const { return _tmp4; }
1740 BasicType type() const { return _type; }
1741 CodeStub* stub() const { return _stub; }
1742 bool zero_array() const { return _zero_array; }
1743
1744 virtual void emit_code(LIR_Assembler* masm);
1745 virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1746 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1747 };
1748
1749
1750 class LIR_Op3: public LIR_Op {
1751 friend class LIR_OpVisitState;
1752
1753 private:
1754 LIR_Opr _opr1;
1755 LIR_Opr _opr2;
1756 LIR_Opr _opr3;
1757 public:
1758 LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1759 : LIR_Op(code, result, info)
1760 , _opr1(opr1)
1761 , _opr2(opr2)
1762 , _opr3(opr3) { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1829
1830 //--------------------------------
1831 class LabelObj: public CompilationResourceObj {
1832 private:
1833 Label _label;
1834 public:
1835 LabelObj() {}
1836 Label* label() { return &_label; }
1837 };
1838
1839
1840 class LIR_OpLock: public LIR_Op {
1841 friend class LIR_OpVisitState;
1842
1843 private:
1844 LIR_Opr _hdr;
1845 LIR_Opr _obj;
1846 LIR_Opr _lock;
1847 LIR_Opr _scratch;
1848 CodeStub* _stub;
1849 public:
1850 LIR_OpLock(LIR_Code code, LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info)
1851 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1852 , _hdr(hdr)
1853 , _obj(obj)
1854 , _lock(lock)
1855 , _scratch(scratch)
1856 , _stub(stub) {}
1857
1858 LIR_Opr hdr_opr() const { return _hdr; }
1859 LIR_Opr obj_opr() const { return _obj; }
1860 LIR_Opr lock_opr() const { return _lock; }
1861 LIR_Opr scratch_opr() const { return _scratch; }
1862 CodeStub* stub() const { return _stub; }
1863
1864 virtual void emit_code(LIR_Assembler* masm);
1865 virtual LIR_OpLock* as_OpLock() { return this; }
1866 void print_instr(outputStream* out) const PRODUCT_RETURN;
1867 };
1868
1869 class LIR_OpLoadKlass: public LIR_Op {
1870 friend class LIR_OpVisitState;
1871
1872 private:
1873 LIR_Opr _obj;
1874 public:
1875 LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1876 : LIR_Op(lir_load_klass, result, info)
1877 , _obj(obj)
1878 {}
1879
1880 LIR_Opr obj() const { return _obj; }
1881
1882 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }
2027 , _obj(obj)
2028 , _tmp(tmp)
2029 , _exact_klass(exact_klass)
2030 , _current_klass(current_klass)
2031 , _not_null(not_null)
2032 , _no_conflict(no_conflict) { }
2033
2034 LIR_Opr mdp() const { return _mdp; }
2035 LIR_Opr obj() const { return _obj; }
2036 LIR_Opr tmp() const { return _tmp; }
2037 ciKlass* exact_klass() const { return _exact_klass; }
2038 intptr_t current_klass() const { return _current_klass; }
2039 bool not_null() const { return _not_null; }
2040 bool no_conflict() const { return _no_conflict; }
2041
2042 virtual void emit_code(LIR_Assembler* masm);
2043 virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2044 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2045 };
2046
2047 class LIR_InsertionBuffer;
2048
2049 //--------------------------------LIR_List---------------------------------------------------
2050 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2051 // The LIR instructions are appended by the LIR_List class itself;
2052 //
2053 // Notes:
2054 // - all offsets are(should be) in bytes
2055 // - local positions are specified with an offset, with offset 0 being local 0
2056
2057 class LIR_List: public CompilationResourceObj {
2058 private:
2059 LIR_OpList _operations;
2060
2061 Compilation* _compilation;
2062 #ifndef PRODUCT
2063 BlockBegin* _block;
2064 #endif
2065 #ifdef ASSERT
2066 const char * _file;
2251 void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2252 void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr) { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2253
2254 void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2255 void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2256
2257 void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2258
2259 void store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2260 void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2261 void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2262 void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2263 void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2264
2265 void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2266 void idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2267 void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2268 void irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2269
2270 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);
2271 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);
2272
2273 // jump is an unconditional branch
2274 void jump(BlockBegin* block) {
2275 append(new LIR_OpBranch(lir_cond_always, block));
2276 }
2277 void jump(CodeStub* stub) {
2278 append(new LIR_OpBranch(lir_cond_always, stub));
2279 }
2280 void branch(LIR_Condition cond, Label* lbl) {
2281 append(new LIR_OpBranch(cond, lbl));
2282 }
2283 // Should not be used for fp comparisons
2284 void branch(LIR_Condition cond, BlockBegin* block) {
2285 append(new LIR_OpBranch(cond, block));
2286 }
2287 // Should not be used for fp comparisons
2288 void branch(LIR_Condition cond, CodeStub* stub) {
2289 append(new LIR_OpBranch(cond, stub));
2290 }
2291 // Should only be used for fp comparisons
2298 void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2299
2300 void shift_left(LIR_Opr value, int count, LIR_Opr dst) { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2301 void shift_right(LIR_Opr value, int count, LIR_Opr dst) { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2302 void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2303
2304 void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_cmp_l2i, left, right, dst)); }
2305 void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2306
2307 void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2308 append(new LIR_OpRTCall(routine, tmp, result, arguments));
2309 }
2310
2311 void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2312 LIR_OprList* arguments, CodeEmitInfo* info) {
2313 append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2314 }
2315
2316 void load_stack_address_monitor(int monitor_ix, LIR_Opr dst) { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2317 void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2318 void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info);
2319
2320 void breakpoint() { append(new LIR_Op0(lir_breakpoint)); }
2321
2322 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)); }
2323
2324 void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2325
2326 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);
2327 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);
2328
2329 void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2330 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2331 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2332 ciMethod* profiled_method, int profiled_bci);
2333 // MethodData* profiling
2334 void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2335 append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2336 }
2337 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) {
2338 append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2339 }
2340
2341 void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2342 void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2343
2344 void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2345
2346 #ifdef ASSERT
2347 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)); }
2348 #endif
2349 };
2350
2351 void print_LIR(BlockList* blocks);
2352
2353 class LIR_InsertionBuffer : public CompilationResourceObj {
2354 private:
2355 LIR_List* _lir; // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2356
2357 // list of insertion points. index and count are stored alternately:
2358 // _index_and_count[i * 2]: the index into lir list where "count" ops should be inserted
2359 // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
|
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_OpDelay;
883 class LIR_Op3;
884 class LIR_OpAllocArray;
885 class LIR_Op4;
886 class LIR_OpCall;
887 class LIR_OpJavaCall;
888 class LIR_OpRTCall;
889 class LIR_OpArrayCopy;
890 class LIR_OpUpdateCRC32;
891 class LIR_OpLock;
892 class LIR_OpTypeCheck;
893 class LIR_OpFlattenedArrayCheck;
894 class LIR_OpNullFreeArrayCheck;
895 class LIR_OpSubstitutabilityCheck;
896 class LIR_OpCompareAndSwap;
897 class LIR_OpLoadKlass;
898 class LIR_OpProfileCall;
899 class LIR_OpProfileType;
900 class LIR_OpProfileInlineType;
901 #ifdef ASSERT
902 class LIR_OpAssert;
903 #endif
904
905 // LIR operation codes
906 enum LIR_Code {
907 lir_none
908 , begin_op0
909 , lir_label
910 , lir_nop
911 , lir_std_entry
912 , lir_osr_entry
913 , lir_breakpoint
914 , lir_rtcall
915 , lir_membar
916 , lir_membar_acquire
917 , lir_membar_release
918 , lir_membar_loadload
919 , lir_membar_storestore
920 , lir_membar_loadstore
921 , lir_membar_storeload
922 , lir_get_thread
923 , lir_on_spin_wait
924 , lir_check_orig_pc
925 , end_op0
926 , begin_op1
927 , lir_push
928 , lir_pop
929 , lir_null_check
930 , lir_return
931 , lir_leal
932 , lir_move
933 , lir_convert
934 , lir_alloc_object
935 , lir_monaddr
936 , lir_sqrt
937 , lir_abs
938 , lir_neg
939 , lir_f2hf
940 , lir_hf2f
941 , lir_safepoint
942 , lir_unwind
943 , lir_load_klass
944 , end_op1
981 , lir_dynamic_call
982 , end_opJavaCall
983 , begin_opArrayCopy
984 , lir_arraycopy
985 , end_opArrayCopy
986 , begin_opUpdateCRC32
987 , lir_updatecrc32
988 , end_opUpdateCRC32
989 , begin_opLock
990 , lir_lock
991 , lir_unlock
992 , end_opLock
993 , begin_delay_slot
994 , lir_delay_slot
995 , end_delay_slot
996 , begin_opTypeCheck
997 , lir_instanceof
998 , lir_checkcast
999 , lir_store_check
1000 , end_opTypeCheck
1001 , begin_opFlattenedArrayCheck
1002 , lir_flat_array_check
1003 , end_opFlattenedArrayCheck
1004 , begin_opNullFreeArrayCheck
1005 , lir_null_free_array_check
1006 , end_opNullFreeArrayCheck
1007 , begin_opSubstitutabilityCheck
1008 , lir_substitutability_check
1009 , end_opSubstitutabilityCheck
1010 , begin_opCompareAndSwap
1011 , lir_cas_long
1012 , lir_cas_obj
1013 , lir_cas_int
1014 , end_opCompareAndSwap
1015 , begin_opMDOProfile
1016 , lir_profile_call
1017 , lir_profile_type
1018 , lir_profile_inline_type
1019 , end_opMDOProfile
1020 , begin_opAssert
1021 , lir_assert
1022 , end_opAssert
1023 #if INCLUDE_ZGC
1024 , begin_opXLoadBarrierTest
1025 , lir_xloadbarrier_test
1026 , end_opXLoadBarrierTest
1027 #endif
1028 };
1029
1030
1031 enum LIR_Condition {
1032 lir_cond_equal
1033 , lir_cond_notEqual
1034 , lir_cond_less
1035 , lir_cond_lessEqual
1036 , lir_cond_greaterEqual
1037 , lir_cond_greater
1038 , lir_cond_belowEqual
1138 virtual bool is_patching() { return false; }
1139 virtual LIR_OpCall* as_OpCall() { return nullptr; }
1140 virtual LIR_OpJavaCall* as_OpJavaCall() { return nullptr; }
1141 virtual LIR_OpLabel* as_OpLabel() { return nullptr; }
1142 virtual LIR_OpDelay* as_OpDelay() { return nullptr; }
1143 virtual LIR_OpLock* as_OpLock() { return nullptr; }
1144 virtual LIR_OpAllocArray* as_OpAllocArray() { return nullptr; }
1145 virtual LIR_OpAllocObj* as_OpAllocObj() { return nullptr; }
1146 virtual LIR_OpBranch* as_OpBranch() { return nullptr; }
1147 virtual LIR_OpReturn* as_OpReturn() { return nullptr; }
1148 virtual LIR_OpRTCall* as_OpRTCall() { return nullptr; }
1149 virtual LIR_OpConvert* as_OpConvert() { return nullptr; }
1150 virtual LIR_Op0* as_Op0() { return nullptr; }
1151 virtual LIR_Op1* as_Op1() { return nullptr; }
1152 virtual LIR_Op2* as_Op2() { return nullptr; }
1153 virtual LIR_Op3* as_Op3() { return nullptr; }
1154 virtual LIR_Op4* as_Op4() { return nullptr; }
1155 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return nullptr; }
1156 virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return nullptr; }
1157 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return nullptr; }
1158 virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return nullptr; }
1159 virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return nullptr; }
1160 virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return nullptr; }
1161 virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return nullptr; }
1162 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return nullptr; }
1163 virtual LIR_OpProfileCall* as_OpProfileCall() { return nullptr; }
1164 virtual LIR_OpProfileType* as_OpProfileType() { return nullptr; }
1165 virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return nullptr; }
1166 #ifdef ASSERT
1167 virtual LIR_OpAssert* as_OpAssert() { return nullptr; }
1168 #endif
1169
1170 virtual void verify() const {}
1171 };
1172
1173 // for calls
1174 class LIR_OpCall: public LIR_Op {
1175 friend class LIR_OpVisitState;
1176
1177 protected:
1178 address _addr;
1179 LIR_OprList* _arguments;
1180 protected:
1181 LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1182 LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1183 : LIR_Op(code, result, info)
1184 , _addr(addr)
1185 , _arguments(arguments) {}
1218 LIR_OprList* arguments, CodeEmitInfo* info)
1219 : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1220 , _method(method)
1221 , _receiver(receiver)
1222 , _method_handle_invoke_SP_save_opr(LIR_OprFact::illegalOpr)
1223 { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1224
1225 LIR_Opr receiver() const { return _receiver; }
1226 ciMethod* method() const { return _method; }
1227
1228 // JSR 292 support.
1229 bool is_invokedynamic() const { return code() == lir_dynamic_call; }
1230 bool is_method_handle_invoke() const {
1231 return method()->is_compiled_lambda_form() || // Java-generated lambda form
1232 method()->is_method_handle_intrinsic(); // JVM-generated MH intrinsic
1233 }
1234
1235 virtual void emit_code(LIR_Assembler* masm);
1236 virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1237 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1238
1239 bool maybe_return_as_fields(ciInlineKlass** vk = nullptr) const;
1240 };
1241
1242 // --------------------------------------------------
1243 // LIR_OpLabel
1244 // --------------------------------------------------
1245 // Location where a branch can continue
1246 class LIR_OpLabel: public LIR_Op {
1247 friend class LIR_OpVisitState;
1248
1249 private:
1250 Label* _label;
1251 public:
1252 LIR_OpLabel(Label* lbl)
1253 : LIR_Op(lir_label, LIR_OprFact::illegalOpr, nullptr)
1254 , _label(lbl) {}
1255 Label* label() const { return _label; }
1256
1257 virtual void emit_code(LIR_Assembler* masm);
1258 virtual LIR_OpLabel* as_OpLabel() { return this; }
1259 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1271 LIR_Opr _dst_pos;
1272 LIR_Opr _length;
1273 LIR_Opr _tmp;
1274 ciArrayKlass* _expected_type;
1275 int _flags;
1276
1277 public:
1278 enum Flags {
1279 src_null_check = 1 << 0,
1280 dst_null_check = 1 << 1,
1281 src_pos_positive_check = 1 << 2,
1282 dst_pos_positive_check = 1 << 3,
1283 length_positive_check = 1 << 4,
1284 src_range_check = 1 << 5,
1285 dst_range_check = 1 << 6,
1286 type_check = 1 << 7,
1287 overlapping = 1 << 8,
1288 unaligned = 1 << 9,
1289 src_objarray = 1 << 10,
1290 dst_objarray = 1 << 11,
1291 always_slow_path = 1 << 12,
1292 src_inlinetype_check = 1 << 13,
1293 dst_inlinetype_check = 1 << 14,
1294 all_flags = (1 << 15) - 1
1295 };
1296
1297 LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1298 ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1299
1300 LIR_Opr src() const { return _src; }
1301 LIR_Opr src_pos() const { return _src_pos; }
1302 LIR_Opr dst() const { return _dst; }
1303 LIR_Opr dst_pos() const { return _dst_pos; }
1304 LIR_Opr length() const { return _length; }
1305 LIR_Opr tmp() const { return _tmp; }
1306 int flags() const { return _flags; }
1307 ciArrayKlass* expected_type() const { return _expected_type; }
1308 ArrayCopyStub* stub() const { return _stub; }
1309
1310 virtual void emit_code(LIR_Assembler* masm);
1311 virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1312 void print_instr(outputStream* out) const PRODUCT_RETURN;
1313 };
1314
1532
1533
1534 // LIR_OpTypeCheck
1535 class LIR_OpTypeCheck: public LIR_Op {
1536 friend class LIR_OpVisitState;
1537
1538 private:
1539 LIR_Opr _object;
1540 LIR_Opr _array;
1541 ciKlass* _klass;
1542 LIR_Opr _tmp1;
1543 LIR_Opr _tmp2;
1544 LIR_Opr _tmp3;
1545 CodeEmitInfo* _info_for_patch;
1546 CodeEmitInfo* _info_for_exception;
1547 CodeStub* _stub;
1548 ciMethod* _profiled_method;
1549 int _profiled_bci;
1550 bool _should_profile;
1551 bool _fast_check;
1552 bool _need_null_check;
1553
1554 public:
1555 LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1556 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1557 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub, bool need_null_check = true);
1558 LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1559 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1560
1561 LIR_Opr object() const { return _object; }
1562 LIR_Opr array() const { assert(code() == lir_store_check, "not valid"); return _array; }
1563 LIR_Opr tmp1() const { return _tmp1; }
1564 LIR_Opr tmp2() const { return _tmp2; }
1565 LIR_Opr tmp3() const { return _tmp3; }
1566 ciKlass* klass() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass; }
1567 bool fast_check() const { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check; }
1568 CodeEmitInfo* info_for_patch() const { return _info_for_patch; }
1569 CodeEmitInfo* info_for_exception() const { return _info_for_exception; }
1570 CodeStub* stub() const { return _stub; }
1571
1572 // MethodData* profiling
1573 void set_profiled_method(ciMethod *method) { _profiled_method = method; }
1574 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1575 void set_should_profile(bool b) { _should_profile = b; }
1576 ciMethod* profiled_method() const { return _profiled_method; }
1577 int profiled_bci() const { return _profiled_bci; }
1578 bool should_profile() const { return _should_profile; }
1579 bool need_null_check() const { return _need_null_check; }
1580 virtual bool is_patching() { return _info_for_patch != nullptr; }
1581 virtual void emit_code(LIR_Assembler* masm);
1582 virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1583 void print_instr(outputStream* out) const PRODUCT_RETURN;
1584 };
1585
1586 // LIR_OpFlattenedArrayCheck
1587 class LIR_OpFlattenedArrayCheck: public LIR_Op {
1588 friend class LIR_OpVisitState;
1589
1590 private:
1591 LIR_Opr _array;
1592 LIR_Opr _value;
1593 LIR_Opr _tmp;
1594 CodeStub* _stub;
1595 public:
1596 LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
1597 LIR_Opr array() const { return _array; }
1598 LIR_Opr value() const { return _value; }
1599 LIR_Opr tmp() const { return _tmp; }
1600 CodeStub* stub() const { return _stub; }
1601
1602 virtual void emit_code(LIR_Assembler* masm);
1603 virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return this; }
1604 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1605 };
1606
1607 // LIR_OpNullFreeArrayCheck
1608 class LIR_OpNullFreeArrayCheck: public LIR_Op {
1609 friend class LIR_OpVisitState;
1610
1611 private:
1612 LIR_Opr _array;
1613 LIR_Opr _tmp;
1614 public:
1615 LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp);
1616 LIR_Opr array() const { return _array; }
1617 LIR_Opr tmp() const { return _tmp; }
1618
1619 virtual void emit_code(LIR_Assembler* masm);
1620 virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return this; }
1621 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1622 };
1623
1624 class LIR_OpSubstitutabilityCheck: public LIR_Op {
1625 friend class LIR_OpVisitState;
1626
1627 private:
1628 LIR_Opr _left;
1629 LIR_Opr _right;
1630 LIR_Opr _equal_result;
1631 LIR_Opr _not_equal_result;
1632 LIR_Opr _tmp1;
1633 LIR_Opr _tmp2;
1634 ciKlass* _left_klass;
1635 ciKlass* _right_klass;
1636 LIR_Opr _left_klass_op;
1637 LIR_Opr _right_klass_op;
1638 CodeStub* _stub;
1639 public:
1640 LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1641 LIR_Opr tmp1, LIR_Opr tmp2,
1642 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
1643 CodeEmitInfo* info, CodeStub* stub);
1644
1645 LIR_Opr left() const { return _left; }
1646 LIR_Opr right() const { return _right; }
1647 LIR_Opr equal_result() const { return _equal_result; }
1648 LIR_Opr not_equal_result() const { return _not_equal_result; }
1649 LIR_Opr tmp1() const { return _tmp1; }
1650 LIR_Opr tmp2() const { return _tmp2; }
1651 ciKlass* left_klass() const { return _left_klass; }
1652 ciKlass* right_klass() const { return _right_klass; }
1653 LIR_Opr left_klass_op() const { return _left_klass_op; }
1654 LIR_Opr right_klass_op() const { return _right_klass_op; }
1655 CodeStub* stub() const { return _stub; }
1656
1657 virtual void emit_code(LIR_Assembler* masm);
1658 virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return this; }
1659 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1660 };
1661
1662 // LIR_Op2
1663 class LIR_Op2: public LIR_Op {
1664 friend class LIR_OpVisitState;
1665
1666 protected:
1667 LIR_Opr _opr1;
1668 LIR_Opr _opr2;
1669 LIR_Opr _tmp1;
1670 LIR_Opr _tmp2;
1671 LIR_Opr _tmp3;
1672 LIR_Opr _tmp4;
1673 LIR_Opr _tmp5;
1674 LIR_Condition _condition;
1675 BasicType _type;
1676
1677 void verify() const;
1678
1679 public:
1680 LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1681 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1800 void negate_cond();
1801
1802 virtual void emit_code(LIR_Assembler* masm);
1803 virtual LIR_OpBranch* as_OpBranch() { return this; }
1804 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1805 };
1806
1807 class LIR_OpAllocArray : public LIR_Op {
1808 friend class LIR_OpVisitState;
1809
1810 private:
1811 LIR_Opr _klass;
1812 LIR_Opr _len;
1813 LIR_Opr _tmp1;
1814 LIR_Opr _tmp2;
1815 LIR_Opr _tmp3;
1816 LIR_Opr _tmp4;
1817 CodeStub* _stub;
1818 BasicType _type;
1819 bool _zero_array;
1820 bool _is_null_free;
1821
1822 public:
1823 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)
1824 : LIR_Op(lir_alloc_array, result, nullptr)
1825 , _klass(klass)
1826 , _len(len)
1827 , _tmp1(t1)
1828 , _tmp2(t2)
1829 , _tmp3(t3)
1830 , _tmp4(t4)
1831 , _stub(stub)
1832 , _type(type)
1833 , _zero_array(zero_array)
1834 , _is_null_free(is_null_free) {}
1835
1836 LIR_Opr klass() const { return _klass; }
1837 LIR_Opr len() const { return _len; }
1838 LIR_Opr obj() const { return result_opr(); }
1839 LIR_Opr tmp1() const { return _tmp1; }
1840 LIR_Opr tmp2() const { return _tmp2; }
1841 LIR_Opr tmp3() const { return _tmp3; }
1842 LIR_Opr tmp4() const { return _tmp4; }
1843 BasicType type() const { return _type; }
1844 CodeStub* stub() const { return _stub; }
1845 bool zero_array() const { return _zero_array; }
1846 bool is_null_free() const { return _is_null_free;}
1847
1848 virtual void emit_code(LIR_Assembler* masm);
1849 virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1850 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1851 };
1852
1853
1854 class LIR_Op3: public LIR_Op {
1855 friend class LIR_OpVisitState;
1856
1857 private:
1858 LIR_Opr _opr1;
1859 LIR_Opr _opr2;
1860 LIR_Opr _opr3;
1861 public:
1862 LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1863 : LIR_Op(code, result, info)
1864 , _opr1(opr1)
1865 , _opr2(opr2)
1866 , _opr3(opr3) { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1933
1934 //--------------------------------
1935 class LabelObj: public CompilationResourceObj {
1936 private:
1937 Label _label;
1938 public:
1939 LabelObj() {}
1940 Label* label() { return &_label; }
1941 };
1942
1943
1944 class LIR_OpLock: public LIR_Op {
1945 friend class LIR_OpVisitState;
1946
1947 private:
1948 LIR_Opr _hdr;
1949 LIR_Opr _obj;
1950 LIR_Opr _lock;
1951 LIR_Opr _scratch;
1952 CodeStub* _stub;
1953 CodeStub* _throw_ie_stub;
1954 public:
1955 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)
1956 : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1957 , _hdr(hdr)
1958 , _obj(obj)
1959 , _lock(lock)
1960 , _scratch(scratch)
1961 , _stub(stub)
1962 , _throw_ie_stub(throw_ie_stub) {}
1963
1964 LIR_Opr hdr_opr() const { return _hdr; }
1965 LIR_Opr obj_opr() const { return _obj; }
1966 LIR_Opr lock_opr() const { return _lock; }
1967 LIR_Opr scratch_opr() const { return _scratch; }
1968 CodeStub* stub() const { return _stub; }
1969 CodeStub* throw_ie_stub() const { return _throw_ie_stub; }
1970
1971 virtual void emit_code(LIR_Assembler* masm);
1972 virtual LIR_OpLock* as_OpLock() { return this; }
1973 void print_instr(outputStream* out) const PRODUCT_RETURN;
1974 };
1975
1976 class LIR_OpLoadKlass: public LIR_Op {
1977 friend class LIR_OpVisitState;
1978
1979 private:
1980 LIR_Opr _obj;
1981 public:
1982 LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1983 : LIR_Op(lir_load_klass, result, info)
1984 , _obj(obj)
1985 {}
1986
1987 LIR_Opr obj() const { return _obj; }
1988
1989 virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }
2134 , _obj(obj)
2135 , _tmp(tmp)
2136 , _exact_klass(exact_klass)
2137 , _current_klass(current_klass)
2138 , _not_null(not_null)
2139 , _no_conflict(no_conflict) { }
2140
2141 LIR_Opr mdp() const { return _mdp; }
2142 LIR_Opr obj() const { return _obj; }
2143 LIR_Opr tmp() const { return _tmp; }
2144 ciKlass* exact_klass() const { return _exact_klass; }
2145 intptr_t current_klass() const { return _current_klass; }
2146 bool not_null() const { return _not_null; }
2147 bool no_conflict() const { return _no_conflict; }
2148
2149 virtual void emit_code(LIR_Assembler* masm);
2150 virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2151 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2152 };
2153
2154 // LIR_OpProfileInlineType
2155 class LIR_OpProfileInlineType : public LIR_Op {
2156 friend class LIR_OpVisitState;
2157
2158 private:
2159 LIR_Opr _mdp;
2160 LIR_Opr _obj;
2161 int _flag;
2162 LIR_Opr _tmp;
2163 bool _not_null; // true if we know statically that _obj cannot be null
2164
2165 public:
2166 // Destroys recv
2167 LIR_OpProfileInlineType(LIR_Opr mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null)
2168 : LIR_Op(lir_profile_inline_type, LIR_OprFact::illegalOpr, nullptr) // no result, no info
2169 , _mdp(mdp)
2170 , _obj(obj)
2171 , _flag(flag)
2172 , _tmp(tmp)
2173 , _not_null(not_null) { }
2174
2175 LIR_Opr mdp() const { return _mdp; }
2176 LIR_Opr obj() const { return _obj; }
2177 int flag() const { return _flag; }
2178 LIR_Opr tmp() const { return _tmp; }
2179 bool not_null() const { return _not_null; }
2180
2181 virtual void emit_code(LIR_Assembler* masm);
2182 virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return this; }
2183 virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2184 };
2185
2186 class LIR_InsertionBuffer;
2187
2188 //--------------------------------LIR_List---------------------------------------------------
2189 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2190 // The LIR instructions are appended by the LIR_List class itself;
2191 //
2192 // Notes:
2193 // - all offsets are(should be) in bytes
2194 // - local positions are specified with an offset, with offset 0 being local 0
2195
2196 class LIR_List: public CompilationResourceObj {
2197 private:
2198 LIR_OpList _operations;
2199
2200 Compilation* _compilation;
2201 #ifndef PRODUCT
2202 BlockBegin* _block;
2203 #endif
2204 #ifdef ASSERT
2205 const char * _file;
2390 void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2391 void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr) { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2392
2393 void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2394 void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2395
2396 void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2397
2398 void store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2399 void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2400 void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2401 void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2402 void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2403
2404 void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2405 void idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2406 void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2407 void irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2408
2409 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);
2410 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);
2411
2412 // jump is an unconditional branch
2413 void jump(BlockBegin* block) {
2414 append(new LIR_OpBranch(lir_cond_always, block));
2415 }
2416 void jump(CodeStub* stub) {
2417 append(new LIR_OpBranch(lir_cond_always, stub));
2418 }
2419 void branch(LIR_Condition cond, Label* lbl) {
2420 append(new LIR_OpBranch(cond, lbl));
2421 }
2422 // Should not be used for fp comparisons
2423 void branch(LIR_Condition cond, BlockBegin* block) {
2424 append(new LIR_OpBranch(cond, block));
2425 }
2426 // Should not be used for fp comparisons
2427 void branch(LIR_Condition cond, CodeStub* stub) {
2428 append(new LIR_OpBranch(cond, stub));
2429 }
2430 // Should only be used for fp comparisons
2437 void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2438
2439 void shift_left(LIR_Opr value, int count, LIR_Opr dst) { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2440 void shift_right(LIR_Opr value, int count, LIR_Opr dst) { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2441 void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2442
2443 void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_cmp_l2i, left, right, dst)); }
2444 void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2445
2446 void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2447 append(new LIR_OpRTCall(routine, tmp, result, arguments));
2448 }
2449
2450 void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2451 LIR_OprList* arguments, CodeEmitInfo* info) {
2452 append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2453 }
2454
2455 void load_stack_address_monitor(int monitor_ix, LIR_Opr dst) { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2456 void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2457 void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub=nullptr);
2458
2459 void breakpoint() { append(new LIR_Op0(lir_breakpoint)); }
2460
2461 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)); }
2462
2463 void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2464
2465 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);
2466 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);
2467 void check_flat_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
2468 void check_null_free_array(LIR_Opr array, LIR_Opr tmp);
2469 void substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
2470 LIR_Opr tmp1, LIR_Opr tmp2,
2471 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
2472 CodeEmitInfo* info, CodeStub* stub);
2473
2474 void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2475 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2476 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2477 ciMethod* profiled_method, int profiled_bci, bool is_null_free);
2478 // MethodData* profiling
2479 void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2480 append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2481 }
2482 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) {
2483 append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2484 }
2485 void profile_inline_type(LIR_Address* mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null) {
2486 append(new LIR_OpProfileInlineType(LIR_OprFact::address(mdp), obj, flag, tmp, not_null));
2487 }
2488
2489 void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2490 void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2491
2492 void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2493
2494 #ifdef ASSERT
2495 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)); }
2496 #endif
2497 };
2498
2499 void print_LIR(BlockList* blocks);
2500
2501 class LIR_InsertionBuffer : public CompilationResourceObj {
2502 private:
2503 LIR_List* _lir; // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2504
2505 // list of insertion points. index and count are stored alternately:
2506 // _index_and_count[i * 2]: the index into lir list where "count" ops should be inserted
2507 // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
|