< prev index next >

src/hotspot/share/c1/c1_LIR.hpp

Print this page

   1 /*
   2  * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *

 872 //
 873 class  LIR_Op;
 874 class    LIR_Op0;
 875 class      LIR_OpLabel;
 876 class    LIR_Op1;
 877 class      LIR_OpBranch;
 878 class      LIR_OpConvert;
 879 class      LIR_OpAllocObj;
 880 class      LIR_OpReturn;
 881 class    LIR_Op2;
 882 class    LIR_Op3;
 883 class      LIR_OpAllocArray;
 884 class    LIR_Op4;
 885 class    LIR_OpCall;
 886 class      LIR_OpJavaCall;
 887 class      LIR_OpRTCall;
 888 class    LIR_OpArrayCopy;
 889 class    LIR_OpUpdateCRC32;
 890 class    LIR_OpLock;
 891 class    LIR_OpTypeCheck;



 892 class    LIR_OpCompareAndSwap;
 893 class    LIR_OpLoadKlass;
 894 class    LIR_OpProfileCall;
 895 class    LIR_OpProfileType;

 896 #ifdef ASSERT
 897 class    LIR_OpAssert;
 898 #endif
 899 
 900 // LIR operation codes
 901 enum LIR_Code {
 902     lir_none
 903   , begin_op0
 904       , lir_label
 905       , lir_nop
 906       , lir_std_entry
 907       , lir_osr_entry
 908       , lir_breakpoint
 909       , lir_rtcall
 910       , lir_membar
 911       , lir_membar_acquire
 912       , lir_membar_release
 913       , lir_membar_loadload
 914       , lir_membar_storestore
 915       , lir_membar_loadstore
 916       , lir_membar_storeload
 917       , lir_get_thread
 918       , lir_on_spin_wait

 919   , end_op0
 920   , begin_op1
 921       , lir_push
 922       , lir_pop
 923       , lir_null_check
 924       , lir_return
 925       , lir_leal
 926       , lir_move
 927       , lir_convert
 928       , lir_alloc_object
 929       , lir_monaddr
 930       , lir_sqrt
 931       , lir_abs
 932       , lir_neg
 933       , lir_f2hf
 934       , lir_hf2f
 935       , lir_safepoint
 936       , lir_unwind
 937       , lir_load_klass
 938   , end_op1

 972       , lir_static_call
 973       , lir_optvirtual_call
 974       , lir_icvirtual_call
 975       , lir_dynamic_call
 976   , end_opJavaCall
 977   , begin_opArrayCopy
 978       , lir_arraycopy
 979   , end_opArrayCopy
 980   , begin_opUpdateCRC32
 981       , lir_updatecrc32
 982   , end_opUpdateCRC32
 983   , begin_opLock
 984     , lir_lock
 985     , lir_unlock
 986   , end_opLock
 987   , begin_opTypeCheck
 988     , lir_instanceof
 989     , lir_checkcast
 990     , lir_store_check
 991   , end_opTypeCheck









 992   , begin_opCompareAndSwap
 993     , lir_cas_long
 994     , lir_cas_obj
 995     , lir_cas_int
 996   , end_opCompareAndSwap
 997   , begin_opMDOProfile
 998     , lir_profile_call
 999     , lir_profile_type

1000   , end_opMDOProfile
1001   , begin_opAssert
1002     , lir_assert
1003   , end_opAssert
1004 #if INCLUDE_ZGC
1005   , begin_opXLoadBarrierTest
1006     , lir_xloadbarrier_test
1007   , end_opXLoadBarrierTest
1008 #endif
1009 };
1010 
1011 
1012 enum LIR_Condition {
1013     lir_cond_equal
1014   , lir_cond_notEqual
1015   , lir_cond_less
1016   , lir_cond_lessEqual
1017   , lir_cond_greaterEqual
1018   , lir_cond_greater
1019   , lir_cond_belowEqual

1118 
1119   virtual bool is_patching() { return false; }
1120   virtual LIR_OpCall* as_OpCall() { return nullptr; }
1121   virtual LIR_OpJavaCall* as_OpJavaCall() { return nullptr; }
1122   virtual LIR_OpLabel* as_OpLabel() { return nullptr; }
1123   virtual LIR_OpLock* as_OpLock() { return nullptr; }
1124   virtual LIR_OpAllocArray* as_OpAllocArray() { return nullptr; }
1125   virtual LIR_OpAllocObj* as_OpAllocObj() { return nullptr; }
1126   virtual LIR_OpBranch* as_OpBranch() { return nullptr; }
1127   virtual LIR_OpReturn* as_OpReturn() { return nullptr; }
1128   virtual LIR_OpRTCall* as_OpRTCall() { return nullptr; }
1129   virtual LIR_OpConvert* as_OpConvert() { return nullptr; }
1130   virtual LIR_Op0* as_Op0() { return nullptr; }
1131   virtual LIR_Op1* as_Op1() { return nullptr; }
1132   virtual LIR_Op2* as_Op2() { return nullptr; }
1133   virtual LIR_Op3* as_Op3() { return nullptr; }
1134   virtual LIR_Op4* as_Op4() { return nullptr; }
1135   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return nullptr; }
1136   virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return nullptr; }
1137   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return nullptr; }



1138   virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return nullptr; }
1139   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return nullptr; }
1140   virtual LIR_OpProfileCall* as_OpProfileCall() { return nullptr; }
1141   virtual LIR_OpProfileType* as_OpProfileType() { return nullptr; }

1142 #ifdef ASSERT
1143   virtual LIR_OpAssert* as_OpAssert() { return nullptr; }
1144 #endif
1145 
1146   virtual void verify() const {}
1147 };
1148 
1149 // for calls
1150 class LIR_OpCall: public LIR_Op {
1151  friend class LIR_OpVisitState;
1152 
1153  protected:
1154   address      _addr;
1155   LIR_OprList* _arguments;
1156  protected:
1157   LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1158              LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1159     : LIR_Op(code, result, info)
1160     , _addr(addr)
1161     , _arguments(arguments) {}

1191                  LIR_Opr receiver, LIR_Opr result, intptr_t vtable_offset,
1192                  LIR_OprList* arguments, CodeEmitInfo* info)
1193   : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1194   , _method(method)
1195   , _receiver(receiver)
1196   { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1197 
1198   LIR_Opr receiver() const                       { return _receiver; }
1199   ciMethod* method() const                       { return _method;   }
1200 
1201   // JSR 292 support.
1202   bool is_invokedynamic() const                  { return code() == lir_dynamic_call; }
1203   bool is_method_handle_invoke() const {
1204     return method()->is_compiled_lambda_form() ||   // Java-generated lambda form
1205            method()->is_method_handle_intrinsic();  // JVM-generated MH intrinsic
1206   }
1207 
1208   virtual void emit_code(LIR_Assembler* masm);
1209   virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1210   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;


1211 };
1212 
1213 // --------------------------------------------------
1214 // LIR_OpLabel
1215 // --------------------------------------------------
1216 // Location where a branch can continue
1217 class LIR_OpLabel: public LIR_Op {
1218  friend class LIR_OpVisitState;
1219 
1220  private:
1221   Label* _label;
1222  public:
1223   LIR_OpLabel(Label* lbl)
1224    : LIR_Op(lir_label, LIR_OprFact::illegalOpr, nullptr)
1225    , _label(lbl)                                 {}
1226   Label* label() const                           { return _label; }
1227 
1228   virtual void emit_code(LIR_Assembler* masm);
1229   virtual LIR_OpLabel* as_OpLabel() { return this; }
1230   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;

1242   LIR_Opr   _dst_pos;
1243   LIR_Opr   _length;
1244   LIR_Opr   _tmp;
1245   ciArrayKlass* _expected_type;
1246   int       _flags;
1247 
1248 public:
1249   enum Flags {
1250     src_null_check         = 1 << 0,
1251     dst_null_check         = 1 << 1,
1252     src_pos_positive_check = 1 << 2,
1253     dst_pos_positive_check = 1 << 3,
1254     length_positive_check  = 1 << 4,
1255     src_range_check        = 1 << 5,
1256     dst_range_check        = 1 << 6,
1257     type_check             = 1 << 7,
1258     overlapping            = 1 << 8,
1259     unaligned              = 1 << 9,
1260     src_objarray           = 1 << 10,
1261     dst_objarray           = 1 << 11,
1262     all_flags              = (1 << 12) - 1



1263   };
1264 
1265   LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1266                   ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1267 
1268   LIR_Opr src() const                            { return _src; }
1269   LIR_Opr src_pos() const                        { return _src_pos; }
1270   LIR_Opr dst() const                            { return _dst; }
1271   LIR_Opr dst_pos() const                        { return _dst_pos; }
1272   LIR_Opr length() const                         { return _length; }
1273   LIR_Opr tmp() const                            { return _tmp; }
1274   int flags() const                              { return _flags; }
1275   ciArrayKlass* expected_type() const            { return _expected_type; }
1276   ArrayCopyStub* stub() const                    { return _stub; }
1277   static int get_initial_copy_flags()            { return LIR_OpArrayCopy::unaligned |
1278                                                           LIR_OpArrayCopy::overlapping; }
1279 
1280   virtual void emit_code(LIR_Assembler* masm);
1281   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1282   void print_instr(outputStream* out) const PRODUCT_RETURN;

1497 
1498 
1499 // LIR_OpTypeCheck
1500 class LIR_OpTypeCheck: public LIR_Op {
1501  friend class LIR_OpVisitState;
1502 
1503  private:
1504   LIR_Opr       _object;
1505   LIR_Opr       _array;
1506   ciKlass*      _klass;
1507   LIR_Opr       _tmp1;
1508   LIR_Opr       _tmp2;
1509   LIR_Opr       _tmp3;
1510   CodeEmitInfo* _info_for_patch;
1511   CodeEmitInfo* _info_for_exception;
1512   CodeStub*     _stub;
1513   ciMethod*     _profiled_method;
1514   int           _profiled_bci;
1515   bool          _should_profile;
1516   bool          _fast_check;

1517 
1518 public:
1519   LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1520                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1521                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub);
1522   LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1523                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1524 
1525   LIR_Opr object() const                         { return _object;         }
1526   LIR_Opr array() const                          { assert(code() == lir_store_check, "not valid"); return _array;         }
1527   LIR_Opr tmp1() const                           { return _tmp1;           }
1528   LIR_Opr tmp2() const                           { return _tmp2;           }
1529   LIR_Opr tmp3() const                           { return _tmp3;           }
1530   ciKlass* klass() const                         { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass;          }
1531   bool fast_check() const                        { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check;     }
1532   CodeEmitInfo* info_for_patch() const           { return _info_for_patch;  }
1533   CodeEmitInfo* info_for_exception() const       { return _info_for_exception; }
1534   CodeStub* stub() const                         { return _stub;           }
1535 
1536   // MethodData* profiling
1537   void set_profiled_method(ciMethod *method)     { _profiled_method = method; }
1538   void set_profiled_bci(int bci)                 { _profiled_bci = bci;       }
1539   void set_should_profile(bool b)                { _should_profile = b;       }
1540   ciMethod* profiled_method() const              { return _profiled_method;   }
1541   int       profiled_bci() const                 { return _profiled_bci;      }
1542   bool      should_profile() const               { return _should_profile;    }
1543 
1544   virtual bool is_patching() { return _info_for_patch != nullptr; }
1545   virtual void emit_code(LIR_Assembler* masm);
1546   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1547   void print_instr(outputStream* out) const PRODUCT_RETURN;
1548 };
1549 





































































1550 // LIR_Op2
1551 class LIR_Op2: public LIR_Op {
1552  friend class LIR_OpVisitState;
1553 
1554  protected:
1555   LIR_Opr   _opr1;
1556   LIR_Opr   _opr2;
1557   LIR_Opr   _tmp1;
1558   LIR_Opr   _tmp2;
1559   LIR_Opr   _tmp3;
1560   LIR_Opr   _tmp4;
1561   LIR_Opr   _tmp5;
1562   LIR_Condition _condition;
1563   BasicType _type;
1564 
1565   void verify() const;
1566 
1567  public:
1568   LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1569     : LIR_Op(code, LIR_OprFact::illegalOpr, info)

1688   void          negate_cond();
1689 
1690   virtual void emit_code(LIR_Assembler* masm);
1691   virtual LIR_OpBranch* as_OpBranch() { return this; }
1692   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1693 };
1694 
1695 class LIR_OpAllocArray : public LIR_Op {
1696  friend class LIR_OpVisitState;
1697 
1698  private:
1699   LIR_Opr   _klass;
1700   LIR_Opr   _len;
1701   LIR_Opr   _tmp1;
1702   LIR_Opr   _tmp2;
1703   LIR_Opr   _tmp3;
1704   LIR_Opr   _tmp4;
1705   CodeStub* _stub;
1706   BasicType _type;
1707   bool      _zero_array;

1708 
1709  public:
1710   LIR_OpAllocArray(LIR_Opr klass, LIR_Opr len, LIR_Opr result, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, BasicType type, CodeStub* stub, bool zero_array)
1711     : LIR_Op(lir_alloc_array, result, nullptr)
1712     , _klass(klass)
1713     , _len(len)
1714     , _tmp1(t1)
1715     , _tmp2(t2)
1716     , _tmp3(t3)
1717     , _tmp4(t4)
1718     , _stub(stub)
1719     , _type(type)
1720     , _zero_array(zero_array) {}

1721 
1722   LIR_Opr   klass()   const                      { return _klass;       }
1723   LIR_Opr   len()     const                      { return _len;         }
1724   LIR_Opr   obj()     const                      { return result_opr(); }
1725   LIR_Opr   tmp1()    const                      { return _tmp1;        }
1726   LIR_Opr   tmp2()    const                      { return _tmp2;        }
1727   LIR_Opr   tmp3()    const                      { return _tmp3;        }
1728   LIR_Opr   tmp4()    const                      { return _tmp4;        }
1729   BasicType type()    const                      { return _type;        }
1730   CodeStub* stub()    const                      { return _stub;        }
1731   bool zero_array()   const                      { return _zero_array;  }

1732 
1733   virtual void emit_code(LIR_Assembler* masm);
1734   virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1735   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1736 };
1737 
1738 
1739 class LIR_Op3: public LIR_Op {
1740  friend class LIR_OpVisitState;
1741 
1742  private:
1743   LIR_Opr _opr1;
1744   LIR_Opr _opr2;
1745   LIR_Opr _opr3;
1746  public:
1747   LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1748     : LIR_Op(code, result, info)
1749     , _opr1(opr1)
1750     , _opr2(opr2)
1751     , _opr3(opr3)                                { assert(is_in_range(code, begin_op3, end_op3), "code check"); }

1818 
1819 //--------------------------------
1820 class LabelObj: public CompilationResourceObj {
1821  private:
1822   Label _label;
1823  public:
1824   LabelObj()                                     {}
1825   Label* label()                                 { return &_label; }
1826 };
1827 
1828 
1829 class LIR_OpLock: public LIR_Op {
1830  friend class LIR_OpVisitState;
1831 
1832  private:
1833   LIR_Opr _hdr;
1834   LIR_Opr _obj;
1835   LIR_Opr _lock;
1836   LIR_Opr _scratch;
1837   CodeStub* _stub;

1838  public:
1839   LIR_OpLock(LIR_Code code, LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info)
1840     : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1841     , _hdr(hdr)
1842     , _obj(obj)
1843     , _lock(lock)
1844     , _scratch(scratch)
1845     , _stub(stub)                      {}

1846 
1847   LIR_Opr hdr_opr() const                        { return _hdr; }
1848   LIR_Opr obj_opr() const                        { return _obj; }
1849   LIR_Opr lock_opr() const                       { return _lock; }
1850   LIR_Opr scratch_opr() const                    { return _scratch; }
1851   CodeStub* stub() const                         { return _stub; }

1852 
1853   virtual void emit_code(LIR_Assembler* masm);
1854   virtual LIR_OpLock* as_OpLock() { return this; }
1855   void print_instr(outputStream* out) const PRODUCT_RETURN;
1856 };
1857 
1858 class LIR_OpLoadKlass: public LIR_Op {
1859   friend class LIR_OpVisitState;
1860 
1861  private:
1862   LIR_Opr _obj;
1863  public:
1864   LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1865     : LIR_Op(lir_load_klass, result, info)
1866     , _obj(obj)
1867     {}
1868 
1869   LIR_Opr obj()        const { return _obj;  }
1870 
1871   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }

1997     , _obj(obj)
1998     , _tmp(tmp)
1999     , _exact_klass(exact_klass)
2000     , _current_klass(current_klass)
2001     , _not_null(not_null)
2002     , _no_conflict(no_conflict) { }
2003 
2004   LIR_Opr      mdp()              const             { return _mdp;              }
2005   LIR_Opr      obj()              const             { return _obj;              }
2006   LIR_Opr      tmp()              const             { return _tmp;              }
2007   ciKlass*     exact_klass()      const             { return _exact_klass;      }
2008   intptr_t     current_klass()    const             { return _current_klass;    }
2009   bool         not_null()         const             { return _not_null;         }
2010   bool         no_conflict()      const             { return _no_conflict;      }
2011 
2012   virtual void emit_code(LIR_Assembler* masm);
2013   virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2014   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2015 };
2016 
































2017 class LIR_InsertionBuffer;
2018 
2019 //--------------------------------LIR_List---------------------------------------------------
2020 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2021 // The LIR instructions are appended by the LIR_List class itself;
2022 //
2023 // Notes:
2024 // - all offsets are(should be) in bytes
2025 // - local positions are specified with an offset, with offset 0 being local 0
2026 
2027 class LIR_List: public CompilationResourceObj {
2028  private:
2029   LIR_OpList  _operations;
2030 
2031   Compilation*  _compilation;
2032 #ifndef PRODUCT
2033   BlockBegin*   _block;
2034 #endif
2035 #ifdef ASSERT
2036   const char *  _file;

2221   void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2222   void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr)      { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2223 
2224   void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2225   void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2226 
2227   void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2228 
2229   void store_mem_int(jint v,    LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2230   void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2231   void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2232   void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2233   void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2234 
2235   void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2236   void idiv(LIR_Opr left, int   right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2237   void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2238   void irem(LIR_Opr left, int   right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2239 
2240   void allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub);
2241   void allocate_array(LIR_Opr dst, LIR_Opr len, LIR_Opr t1,LIR_Opr t2, LIR_Opr t3,LIR_Opr t4, BasicType type, LIR_Opr klass, CodeStub* stub, bool zero_array = true);
2242 
2243   // jump is an unconditional branch
2244   void jump(BlockBegin* block) {
2245     append(new LIR_OpBranch(lir_cond_always, block));
2246   }
2247   void jump(CodeStub* stub) {
2248     append(new LIR_OpBranch(lir_cond_always, stub));
2249   }
2250   void branch(LIR_Condition cond, Label* lbl) {
2251     append(new LIR_OpBranch(cond, lbl));
2252   }
2253   // Should not be used for fp comparisons
2254   void branch(LIR_Condition cond, BlockBegin* block) {
2255     append(new LIR_OpBranch(cond, block));
2256   }
2257   // Should not be used for fp comparisons
2258   void branch(LIR_Condition cond, CodeStub* stub) {
2259     append(new LIR_OpBranch(cond, stub));
2260   }
2261   // Should only be used for fp comparisons

2268   void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2269 
2270   void shift_left(LIR_Opr value, int count, LIR_Opr dst)       { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2271   void shift_right(LIR_Opr value, int count, LIR_Opr dst)      { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2272   void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2273 
2274   void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst)        { append(new LIR_Op2(lir_cmp_l2i,  left, right, dst)); }
2275   void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2276 
2277   void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2278     append(new LIR_OpRTCall(routine, tmp, result, arguments));
2279   }
2280 
2281   void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2282                     LIR_OprList* arguments, CodeEmitInfo* info) {
2283     append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2284   }
2285 
2286   void load_stack_address_monitor(int monitor_ix, LIR_Opr dst)  { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2287   void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2288   void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info);
2289 
2290   void breakpoint()                                                  { append(new LIR_Op0(lir_breakpoint)); }
2291 
2292   void arraycopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info) { append(new LIR_OpArrayCopy(src, src_pos, dst, dst_pos, length, tmp, expected_type, flags, info)); }
2293 
2294   void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res)  { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2295 
2296   void instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci);
2297   void store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci);





2298 
2299   void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2300                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2301                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2302                   ciMethod* profiled_method, int profiled_bci);
2303   // MethodData* profiling
2304   void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2305     append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2306   }
2307   void profile_type(LIR_Address* mdp, LIR_Opr obj, ciKlass* exact_klass, intptr_t current_klass, LIR_Opr tmp, bool not_null, bool no_conflict) {
2308     append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2309   }



2310 
2311   void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2312   void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2313 
2314   void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2315 
2316 #ifdef ASSERT
2317   void lir_assert(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, const char* msg, bool halt) { append(new LIR_OpAssert(condition, opr1, opr2, msg, halt)); }
2318 #endif
2319 };
2320 
2321 void print_LIR(BlockList* blocks);
2322 
2323 class LIR_InsertionBuffer : public CompilationResourceObj {
2324  private:
2325   LIR_List*   _lir;   // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2326 
2327   // list of insertion points. index and count are stored alternately:
2328   // _index_and_count[i * 2]:     the index into lir list where "count" ops should be inserted
2329   // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index

   1 /*
   2  * Copyright (c) 2000, 2026, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *

 872 //
 873 class  LIR_Op;
 874 class    LIR_Op0;
 875 class      LIR_OpLabel;
 876 class    LIR_Op1;
 877 class      LIR_OpBranch;
 878 class      LIR_OpConvert;
 879 class      LIR_OpAllocObj;
 880 class      LIR_OpReturn;
 881 class    LIR_Op2;
 882 class    LIR_Op3;
 883 class      LIR_OpAllocArray;
 884 class    LIR_Op4;
 885 class    LIR_OpCall;
 886 class      LIR_OpJavaCall;
 887 class      LIR_OpRTCall;
 888 class    LIR_OpArrayCopy;
 889 class    LIR_OpUpdateCRC32;
 890 class    LIR_OpLock;
 891 class    LIR_OpTypeCheck;
 892 class    LIR_OpFlattenedArrayCheck;
 893 class    LIR_OpNullFreeArrayCheck;
 894 class    LIR_OpSubstitutabilityCheck;
 895 class    LIR_OpCompareAndSwap;
 896 class    LIR_OpLoadKlass;
 897 class    LIR_OpProfileCall;
 898 class    LIR_OpProfileType;
 899 class    LIR_OpProfileInlineType;
 900 #ifdef ASSERT
 901 class    LIR_OpAssert;
 902 #endif
 903 
 904 // LIR operation codes
 905 enum LIR_Code {
 906     lir_none
 907   , begin_op0
 908       , lir_label
 909       , lir_nop
 910       , lir_std_entry
 911       , lir_osr_entry
 912       , lir_breakpoint
 913       , lir_rtcall
 914       , lir_membar
 915       , lir_membar_acquire
 916       , lir_membar_release
 917       , lir_membar_loadload
 918       , lir_membar_storestore
 919       , lir_membar_loadstore
 920       , lir_membar_storeload
 921       , lir_get_thread
 922       , lir_on_spin_wait
 923       , lir_check_orig_pc
 924   , end_op0
 925   , begin_op1
 926       , lir_push
 927       , lir_pop
 928       , lir_null_check
 929       , lir_return
 930       , lir_leal
 931       , lir_move
 932       , lir_convert
 933       , lir_alloc_object
 934       , lir_monaddr
 935       , lir_sqrt
 936       , lir_abs
 937       , lir_neg
 938       , lir_f2hf
 939       , lir_hf2f
 940       , lir_safepoint
 941       , lir_unwind
 942       , lir_load_klass
 943   , end_op1

 977       , lir_static_call
 978       , lir_optvirtual_call
 979       , lir_icvirtual_call
 980       , lir_dynamic_call
 981   , end_opJavaCall
 982   , begin_opArrayCopy
 983       , lir_arraycopy
 984   , end_opArrayCopy
 985   , begin_opUpdateCRC32
 986       , lir_updatecrc32
 987   , end_opUpdateCRC32
 988   , begin_opLock
 989     , lir_lock
 990     , lir_unlock
 991   , end_opLock
 992   , begin_opTypeCheck
 993     , lir_instanceof
 994     , lir_checkcast
 995     , lir_store_check
 996   , end_opTypeCheck
 997   , begin_opFlattenedArrayCheck
 998     , lir_flat_array_check
 999   , end_opFlattenedArrayCheck
1000   , begin_opNullFreeArrayCheck
1001     , lir_null_free_array_check
1002   , end_opNullFreeArrayCheck
1003   , begin_opSubstitutabilityCheck
1004     , lir_substitutability_check
1005   , end_opSubstitutabilityCheck
1006   , begin_opCompareAndSwap
1007     , lir_cas_long
1008     , lir_cas_obj
1009     , lir_cas_int
1010   , end_opCompareAndSwap
1011   , begin_opMDOProfile
1012     , lir_profile_call
1013     , lir_profile_type
1014     , lir_profile_inline_type
1015   , end_opMDOProfile
1016   , begin_opAssert
1017     , lir_assert
1018   , end_opAssert
1019 #if INCLUDE_ZGC
1020   , begin_opXLoadBarrierTest
1021     , lir_xloadbarrier_test
1022   , end_opXLoadBarrierTest
1023 #endif
1024 };
1025 
1026 
1027 enum LIR_Condition {
1028     lir_cond_equal
1029   , lir_cond_notEqual
1030   , lir_cond_less
1031   , lir_cond_lessEqual
1032   , lir_cond_greaterEqual
1033   , lir_cond_greater
1034   , lir_cond_belowEqual

1133 
1134   virtual bool is_patching() { return false; }
1135   virtual LIR_OpCall* as_OpCall() { return nullptr; }
1136   virtual LIR_OpJavaCall* as_OpJavaCall() { return nullptr; }
1137   virtual LIR_OpLabel* as_OpLabel() { return nullptr; }
1138   virtual LIR_OpLock* as_OpLock() { return nullptr; }
1139   virtual LIR_OpAllocArray* as_OpAllocArray() { return nullptr; }
1140   virtual LIR_OpAllocObj* as_OpAllocObj() { return nullptr; }
1141   virtual LIR_OpBranch* as_OpBranch() { return nullptr; }
1142   virtual LIR_OpReturn* as_OpReturn() { return nullptr; }
1143   virtual LIR_OpRTCall* as_OpRTCall() { return nullptr; }
1144   virtual LIR_OpConvert* as_OpConvert() { return nullptr; }
1145   virtual LIR_Op0* as_Op0() { return nullptr; }
1146   virtual LIR_Op1* as_Op1() { return nullptr; }
1147   virtual LIR_Op2* as_Op2() { return nullptr; }
1148   virtual LIR_Op3* as_Op3() { return nullptr; }
1149   virtual LIR_Op4* as_Op4() { return nullptr; }
1150   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return nullptr; }
1151   virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return nullptr; }
1152   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return nullptr; }
1153   virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return nullptr; }
1154   virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return nullptr; }
1155   virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return nullptr; }
1156   virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return nullptr; }
1157   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return nullptr; }
1158   virtual LIR_OpProfileCall* as_OpProfileCall() { return nullptr; }
1159   virtual LIR_OpProfileType* as_OpProfileType() { return nullptr; }
1160   virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return nullptr; }
1161 #ifdef ASSERT
1162   virtual LIR_OpAssert* as_OpAssert() { return nullptr; }
1163 #endif
1164 
1165   virtual void verify() const {}
1166 };
1167 
1168 // for calls
1169 class LIR_OpCall: public LIR_Op {
1170  friend class LIR_OpVisitState;
1171 
1172  protected:
1173   address      _addr;
1174   LIR_OprList* _arguments;
1175  protected:
1176   LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1177              LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1178     : LIR_Op(code, result, info)
1179     , _addr(addr)
1180     , _arguments(arguments) {}

1210                  LIR_Opr receiver, LIR_Opr result, intptr_t vtable_offset,
1211                  LIR_OprList* arguments, CodeEmitInfo* info)
1212   : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1213   , _method(method)
1214   , _receiver(receiver)
1215   { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1216 
1217   LIR_Opr receiver() const                       { return _receiver; }
1218   ciMethod* method() const                       { return _method;   }
1219 
1220   // JSR 292 support.
1221   bool is_invokedynamic() const                  { return code() == lir_dynamic_call; }
1222   bool is_method_handle_invoke() const {
1223     return method()->is_compiled_lambda_form() ||   // Java-generated lambda form
1224            method()->is_method_handle_intrinsic();  // JVM-generated MH intrinsic
1225   }
1226 
1227   virtual void emit_code(LIR_Assembler* masm);
1228   virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1229   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1230 
1231   bool maybe_return_as_fields(ciInlineKlass** vk = nullptr) const;
1232 };
1233 
1234 // --------------------------------------------------
1235 // LIR_OpLabel
1236 // --------------------------------------------------
1237 // Location where a branch can continue
1238 class LIR_OpLabel: public LIR_Op {
1239  friend class LIR_OpVisitState;
1240 
1241  private:
1242   Label* _label;
1243  public:
1244   LIR_OpLabel(Label* lbl)
1245    : LIR_Op(lir_label, LIR_OprFact::illegalOpr, nullptr)
1246    , _label(lbl)                                 {}
1247   Label* label() const                           { return _label; }
1248 
1249   virtual void emit_code(LIR_Assembler* masm);
1250   virtual LIR_OpLabel* as_OpLabel() { return this; }
1251   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;

1263   LIR_Opr   _dst_pos;
1264   LIR_Opr   _length;
1265   LIR_Opr   _tmp;
1266   ciArrayKlass* _expected_type;
1267   int       _flags;
1268 
1269 public:
1270   enum Flags {
1271     src_null_check         = 1 << 0,
1272     dst_null_check         = 1 << 1,
1273     src_pos_positive_check = 1 << 2,
1274     dst_pos_positive_check = 1 << 3,
1275     length_positive_check  = 1 << 4,
1276     src_range_check        = 1 << 5,
1277     dst_range_check        = 1 << 6,
1278     type_check             = 1 << 7,
1279     overlapping            = 1 << 8,
1280     unaligned              = 1 << 9,
1281     src_objarray           = 1 << 10,
1282     dst_objarray           = 1 << 11,
1283     always_slow_path       = 1 << 12,
1284     src_inlinetype_check   = 1 << 13,
1285     dst_inlinetype_check   = 1 << 14,
1286     all_flags              = (1 << 15) - 1
1287   };
1288 
1289   LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1290                   ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1291 
1292   LIR_Opr src() const                            { return _src; }
1293   LIR_Opr src_pos() const                        { return _src_pos; }
1294   LIR_Opr dst() const                            { return _dst; }
1295   LIR_Opr dst_pos() const                        { return _dst_pos; }
1296   LIR_Opr length() const                         { return _length; }
1297   LIR_Opr tmp() const                            { return _tmp; }
1298   int flags() const                              { return _flags; }
1299   ciArrayKlass* expected_type() const            { return _expected_type; }
1300   ArrayCopyStub* stub() const                    { return _stub; }
1301   static int get_initial_copy_flags()            { return LIR_OpArrayCopy::unaligned |
1302                                                           LIR_OpArrayCopy::overlapping; }
1303 
1304   virtual void emit_code(LIR_Assembler* masm);
1305   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1306   void print_instr(outputStream* out) const PRODUCT_RETURN;

1521 
1522 
1523 // LIR_OpTypeCheck
1524 class LIR_OpTypeCheck: public LIR_Op {
1525  friend class LIR_OpVisitState;
1526 
1527  private:
1528   LIR_Opr       _object;
1529   LIR_Opr       _array;
1530   ciKlass*      _klass;
1531   LIR_Opr       _tmp1;
1532   LIR_Opr       _tmp2;
1533   LIR_Opr       _tmp3;
1534   CodeEmitInfo* _info_for_patch;
1535   CodeEmitInfo* _info_for_exception;
1536   CodeStub*     _stub;
1537   ciMethod*     _profiled_method;
1538   int           _profiled_bci;
1539   bool          _should_profile;
1540   bool          _fast_check;
1541   bool          _need_null_check;
1542 
1543 public:
1544   LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1545                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1546                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub, bool need_null_check = true);
1547   LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1548                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1549 
1550   LIR_Opr object() const                         { return _object;         }
1551   LIR_Opr array() const                          { assert(code() == lir_store_check, "not valid"); return _array;         }
1552   LIR_Opr tmp1() const                           { return _tmp1;           }
1553   LIR_Opr tmp2() const                           { return _tmp2;           }
1554   LIR_Opr tmp3() const                           { return _tmp3;           }
1555   ciKlass* klass() const                         { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass;          }
1556   bool fast_check() const                        { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check;     }
1557   CodeEmitInfo* info_for_patch() const           { return _info_for_patch;  }
1558   CodeEmitInfo* info_for_exception() const       { return _info_for_exception; }
1559   CodeStub* stub() const                         { return _stub;           }
1560 
1561   // MethodData* profiling
1562   void set_profiled_method(ciMethod *method)     { _profiled_method = method; }
1563   void set_profiled_bci(int bci)                 { _profiled_bci = bci;       }
1564   void set_should_profile(bool b)                { _should_profile = b;       }
1565   ciMethod* profiled_method() const              { return _profiled_method;   }
1566   int       profiled_bci() const                 { return _profiled_bci;      }
1567   bool      should_profile() const               { return _should_profile;    }
1568   bool      need_null_check() const              { return _need_null_check;   }
1569   virtual bool is_patching() { return _info_for_patch != nullptr; }
1570   virtual void emit_code(LIR_Assembler* masm);
1571   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1572   void print_instr(outputStream* out) const PRODUCT_RETURN;
1573 };
1574 
1575 // LIR_OpFlattenedArrayCheck
1576 class LIR_OpFlattenedArrayCheck: public LIR_Op {
1577  friend class LIR_OpVisitState;
1578 
1579  private:
1580   LIR_Opr       _array;
1581   LIR_Opr       _tmp;
1582   CodeStub*     _stub;
1583 public:
1584   LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr tmp, CodeStub* stub);
1585   LIR_Opr array() const                          { return _array;         }
1586   LIR_Opr tmp() const                            { return _tmp;           }
1587   CodeStub* stub() const                         { return _stub;          }
1588 
1589   virtual void emit_code(LIR_Assembler* masm);
1590   virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return this; }
1591   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1592 };
1593 
1594 // LIR_OpNullFreeArrayCheck
1595 class LIR_OpNullFreeArrayCheck: public LIR_Op {
1596  friend class LIR_OpVisitState;
1597 
1598  private:
1599   LIR_Opr       _array;
1600   LIR_Opr       _tmp;
1601 public:
1602   LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp);
1603   LIR_Opr array() const                          { return _array;         }
1604   LIR_Opr tmp() const                            { return _tmp;           }
1605 
1606   virtual void emit_code(LIR_Assembler* masm);
1607   virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return this; }
1608   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1609 };
1610 
1611 class LIR_OpSubstitutabilityCheck: public LIR_Op {
1612  friend class LIR_OpVisitState;
1613 
1614  private:
1615   LIR_Opr       _left;
1616   LIR_Opr       _right;
1617   LIR_Opr       _equal_result;
1618   LIR_Opr       _not_equal_result;
1619   ciKlass*      _left_klass;
1620   ciKlass*      _right_klass;
1621   LIR_Opr       _tmp1;
1622   LIR_Opr       _tmp2;
1623   CodeStub*     _stub;
1624 public:
1625   LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1626                               ciKlass* left_klass, ciKlass* right_klass, LIR_Opr tmp1, LIR_Opr tmp2,
1627                               CodeEmitInfo* info, CodeStub* stub);
1628 
1629   LIR_Opr left() const             { return _left; }
1630   LIR_Opr right() const            { return _right; }
1631   LIR_Opr equal_result() const     { return _equal_result; }
1632   LIR_Opr not_equal_result() const { return _not_equal_result; }
1633   ciKlass* left_klass() const      { return _left_klass; }
1634   ciKlass* right_klass() const     { return _right_klass; }
1635   LIR_Opr tmp1() const             { return _tmp1; }
1636   LIR_Opr tmp2() const             { return _tmp2; }
1637   CodeStub* stub() const           { return _stub; }
1638 
1639   virtual void emit_code(LIR_Assembler* masm);
1640   virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return this; }
1641   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1642 };
1643 
1644 // LIR_Op2
1645 class LIR_Op2: public LIR_Op {
1646  friend class LIR_OpVisitState;
1647 
1648  protected:
1649   LIR_Opr   _opr1;
1650   LIR_Opr   _opr2;
1651   LIR_Opr   _tmp1;
1652   LIR_Opr   _tmp2;
1653   LIR_Opr   _tmp3;
1654   LIR_Opr   _tmp4;
1655   LIR_Opr   _tmp5;
1656   LIR_Condition _condition;
1657   BasicType _type;
1658 
1659   void verify() const;
1660 
1661  public:
1662   LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1663     : LIR_Op(code, LIR_OprFact::illegalOpr, info)

1782   void          negate_cond();
1783 
1784   virtual void emit_code(LIR_Assembler* masm);
1785   virtual LIR_OpBranch* as_OpBranch() { return this; }
1786   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1787 };
1788 
1789 class LIR_OpAllocArray : public LIR_Op {
1790  friend class LIR_OpVisitState;
1791 
1792  private:
1793   LIR_Opr   _klass;
1794   LIR_Opr   _len;
1795   LIR_Opr   _tmp1;
1796   LIR_Opr   _tmp2;
1797   LIR_Opr   _tmp3;
1798   LIR_Opr   _tmp4;
1799   CodeStub* _stub;
1800   BasicType _type;
1801   bool      _zero_array;
1802   bool      _always_slow_path;
1803 
1804  public:
1805   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)
1806     : LIR_Op(lir_alloc_array, result, nullptr)
1807     , _klass(klass)
1808     , _len(len)
1809     , _tmp1(t1)
1810     , _tmp2(t2)
1811     , _tmp3(t3)
1812     , _tmp4(t4)
1813     , _stub(stub)
1814     , _type(type)
1815     , _zero_array(zero_array)
1816     , _always_slow_path(always_slow_path) {}
1817 
1818   LIR_Opr   klass()   const                      { return _klass;       }
1819   LIR_Opr   len()     const                      { return _len;         }
1820   LIR_Opr   obj()     const                      { return result_opr(); }
1821   LIR_Opr   tmp1()    const                      { return _tmp1;        }
1822   LIR_Opr   tmp2()    const                      { return _tmp2;        }
1823   LIR_Opr   tmp3()    const                      { return _tmp3;        }
1824   LIR_Opr   tmp4()    const                      { return _tmp4;        }
1825   BasicType type()    const                      { return _type;        }
1826   CodeStub* stub()    const                      { return _stub;        }
1827   bool      zero_array() const                   { return _zero_array;  }
1828   bool      always_slow_path() const             { return _always_slow_path; }
1829 
1830   virtual void emit_code(LIR_Assembler* masm);
1831   virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1832   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1833 };
1834 
1835 
1836 class LIR_Op3: public LIR_Op {
1837  friend class LIR_OpVisitState;
1838 
1839  private:
1840   LIR_Opr _opr1;
1841   LIR_Opr _opr2;
1842   LIR_Opr _opr3;
1843  public:
1844   LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1845     : LIR_Op(code, result, info)
1846     , _opr1(opr1)
1847     , _opr2(opr2)
1848     , _opr3(opr3)                                { assert(is_in_range(code, begin_op3, end_op3), "code check"); }

1915 
1916 //--------------------------------
1917 class LabelObj: public CompilationResourceObj {
1918  private:
1919   Label _label;
1920  public:
1921   LabelObj()                                     {}
1922   Label* label()                                 { return &_label; }
1923 };
1924 
1925 
1926 class LIR_OpLock: public LIR_Op {
1927  friend class LIR_OpVisitState;
1928 
1929  private:
1930   LIR_Opr _hdr;
1931   LIR_Opr _obj;
1932   LIR_Opr _lock;
1933   LIR_Opr _scratch;
1934   CodeStub* _stub;
1935   CodeStub* _throw_ie_stub;
1936  public:
1937   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)
1938     : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1939     , _hdr(hdr)
1940     , _obj(obj)
1941     , _lock(lock)
1942     , _scratch(scratch)
1943     , _stub(stub)
1944     , _throw_ie_stub(throw_ie_stub)                    {}
1945 
1946   LIR_Opr hdr_opr() const                        { return _hdr; }
1947   LIR_Opr obj_opr() const                        { return _obj; }
1948   LIR_Opr lock_opr() const                       { return _lock; }
1949   LIR_Opr scratch_opr() const                    { return _scratch; }
1950   CodeStub* stub() const                         { return _stub; }
1951   CodeStub* throw_ie_stub() const                { return _throw_ie_stub; }
1952 
1953   virtual void emit_code(LIR_Assembler* masm);
1954   virtual LIR_OpLock* as_OpLock() { return this; }
1955   void print_instr(outputStream* out) const PRODUCT_RETURN;
1956 };
1957 
1958 class LIR_OpLoadKlass: public LIR_Op {
1959   friend class LIR_OpVisitState;
1960 
1961  private:
1962   LIR_Opr _obj;
1963  public:
1964   LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1965     : LIR_Op(lir_load_klass, result, info)
1966     , _obj(obj)
1967     {}
1968 
1969   LIR_Opr obj()        const { return _obj;  }
1970 
1971   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }

2097     , _obj(obj)
2098     , _tmp(tmp)
2099     , _exact_klass(exact_klass)
2100     , _current_klass(current_klass)
2101     , _not_null(not_null)
2102     , _no_conflict(no_conflict) { }
2103 
2104   LIR_Opr      mdp()              const             { return _mdp;              }
2105   LIR_Opr      obj()              const             { return _obj;              }
2106   LIR_Opr      tmp()              const             { return _tmp;              }
2107   ciKlass*     exact_klass()      const             { return _exact_klass;      }
2108   intptr_t     current_klass()    const             { return _current_klass;    }
2109   bool         not_null()         const             { return _not_null;         }
2110   bool         no_conflict()      const             { return _no_conflict;      }
2111 
2112   virtual void emit_code(LIR_Assembler* masm);
2113   virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2114   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2115 };
2116 
2117 // LIR_OpProfileInlineType
2118 class LIR_OpProfileInlineType : public LIR_Op {
2119  friend class LIR_OpVisitState;
2120 
2121  private:
2122   LIR_Opr      _mdp;
2123   LIR_Opr      _obj;
2124   int          _flag;
2125   LIR_Opr      _tmp;
2126   bool         _not_null;      // true if we know statically that _obj cannot be null
2127 
2128  public:
2129   // Destroys recv
2130   LIR_OpProfileInlineType(LIR_Opr mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null)
2131     : LIR_Op(lir_profile_inline_type, LIR_OprFact::illegalOpr, nullptr)  // no result, no info
2132     , _mdp(mdp)
2133     , _obj(obj)
2134     , _flag(flag)
2135     , _tmp(tmp)
2136     , _not_null(not_null) { }
2137 
2138   LIR_Opr      mdp()              const             { return _mdp;              }
2139   LIR_Opr      obj()              const             { return _obj;              }
2140   int          flag()             const             { return _flag;             }
2141   LIR_Opr      tmp()              const             { return _tmp;              }
2142   bool         not_null()         const             { return _not_null;         }
2143 
2144   virtual void emit_code(LIR_Assembler* masm);
2145   virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return this; }
2146   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2147 };
2148 
2149 class LIR_InsertionBuffer;
2150 
2151 //--------------------------------LIR_List---------------------------------------------------
2152 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2153 // The LIR instructions are appended by the LIR_List class itself;
2154 //
2155 // Notes:
2156 // - all offsets are(should be) in bytes
2157 // - local positions are specified with an offset, with offset 0 being local 0
2158 
2159 class LIR_List: public CompilationResourceObj {
2160  private:
2161   LIR_OpList  _operations;
2162 
2163   Compilation*  _compilation;
2164 #ifndef PRODUCT
2165   BlockBegin*   _block;
2166 #endif
2167 #ifdef ASSERT
2168   const char *  _file;

2353   void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2354   void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr)      { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2355 
2356   void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2357   void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2358 
2359   void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2360 
2361   void store_mem_int(jint v,    LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2362   void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2363   void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2364   void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2365   void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2366 
2367   void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2368   void idiv(LIR_Opr left, int   right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2369   void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2370   void irem(LIR_Opr left, int   right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2371 
2372   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);
2373   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);
2374 
2375   // jump is an unconditional branch
2376   void jump(BlockBegin* block) {
2377     append(new LIR_OpBranch(lir_cond_always, block));
2378   }
2379   void jump(CodeStub* stub) {
2380     append(new LIR_OpBranch(lir_cond_always, stub));
2381   }
2382   void branch(LIR_Condition cond, Label* lbl) {
2383     append(new LIR_OpBranch(cond, lbl));
2384   }
2385   // Should not be used for fp comparisons
2386   void branch(LIR_Condition cond, BlockBegin* block) {
2387     append(new LIR_OpBranch(cond, block));
2388   }
2389   // Should not be used for fp comparisons
2390   void branch(LIR_Condition cond, CodeStub* stub) {
2391     append(new LIR_OpBranch(cond, stub));
2392   }
2393   // Should only be used for fp comparisons

2400   void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2401 
2402   void shift_left(LIR_Opr value, int count, LIR_Opr dst)       { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2403   void shift_right(LIR_Opr value, int count, LIR_Opr dst)      { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2404   void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2405 
2406   void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst)        { append(new LIR_Op2(lir_cmp_l2i,  left, right, dst)); }
2407   void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2408 
2409   void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2410     append(new LIR_OpRTCall(routine, tmp, result, arguments));
2411   }
2412 
2413   void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2414                     LIR_OprList* arguments, CodeEmitInfo* info) {
2415     append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2416   }
2417 
2418   void load_stack_address_monitor(int monitor_ix, LIR_Opr dst)  { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2419   void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2420   void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub=nullptr);
2421 
2422   void breakpoint()                                                  { append(new LIR_Op0(lir_breakpoint)); }
2423 
2424   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)); }
2425 
2426   void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res)  { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2427 
2428   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);
2429   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);
2430   void check_flat_array(LIR_Opr array, LIR_Opr tmp, CodeStub* stub);
2431   void check_null_free_array(LIR_Opr array, LIR_Opr tmp);
2432   void substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
2433                               ciKlass* left_klass, ciKlass* right_klass, LIR_Opr tmp1, LIR_Opr tmp2,
2434                               CodeEmitInfo* info, CodeStub* stub);
2435 
2436   void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2437                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2438                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2439                   ciMethod* profiled_method, int profiled_bci, bool is_null_free);
2440   // MethodData* profiling
2441   void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2442     append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2443   }
2444   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) {
2445     append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2446   }
2447   void profile_inline_type(LIR_Address* mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null) {
2448     append(new LIR_OpProfileInlineType(LIR_OprFact::address(mdp), obj, flag, tmp, not_null));
2449   }
2450 
2451   void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2452   void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2453 
2454   void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2455 
2456 #ifdef ASSERT
2457   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)); }
2458 #endif
2459 };
2460 
2461 void print_LIR(BlockList* blocks);
2462 
2463 class LIR_InsertionBuffer : public CompilationResourceObj {
2464  private:
2465   LIR_List*   _lir;   // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2466 
2467   // list of insertion points. index and count are stored alternately:
2468   // _index_and_count[i * 2]:     the index into lir list where "count" ops should be inserted
2469   // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
< prev index next >