1 /*
   2  * Copyright (c) 2000, 2024, 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  *
  23  */
  24 
  25 #ifndef SHARE_C1_C1_LIR_HPP
  26 #define SHARE_C1_C1_LIR_HPP
  27 
  28 #include "c1/c1_Defs.hpp"
  29 #include "c1/c1_ValueType.hpp"
  30 #include "oops/method.hpp"
  31 #include "utilities/globalDefinitions.hpp"
  32 #include "utilities/macros.hpp"
  33 
  34 class BlockBegin;
  35 class BlockList;
  36 class LIR_Assembler;
  37 class CodeEmitInfo;
  38 class CodeStub;
  39 class CodeStubList;
  40 class C1SafepointPollStub;
  41 class ArrayCopyStub;
  42 class LIR_Op;
  43 class ciType;
  44 class ValueType;
  45 class LIR_OpVisitState;
  46 class FpuStackSim;
  47 
  48 //---------------------------------------------------------------------
  49 //                 LIR Operands
  50 //    LIR_OprPtr
  51 //      LIR_Const
  52 //      LIR_Address
  53 //---------------------------------------------------------------------
  54 class LIR_OprPtr;
  55 class LIR_Const;
  56 class LIR_Address;
  57 class LIR_OprVisitor;
  58 class LIR_Opr;
  59 
  60 typedef int          RegNr;
  61 
  62 typedef GrowableArray<LIR_Opr> LIR_OprList;
  63 typedef GrowableArray<LIR_Op*> LIR_OpArray;
  64 typedef GrowableArray<LIR_Op*> LIR_OpList;
  65 
  66 // define LIR_OprPtr early so LIR_Opr can refer to it
  67 class LIR_OprPtr: public CompilationResourceObj {
  68  public:
  69   bool is_oop_pointer() const                    { return (type() == T_OBJECT); }
  70   bool is_float_kind() const                     { BasicType t = type(); return (t == T_FLOAT) || (t == T_DOUBLE); }
  71 
  72   virtual LIR_Const*  as_constant()              { return nullptr; }
  73   virtual LIR_Address* as_address()              { return nullptr; }
  74   virtual BasicType type() const                 = 0;
  75   virtual void print_value_on(outputStream* out) const = 0;
  76 };
  77 
  78 
  79 
  80 // LIR constants
  81 class LIR_Const: public LIR_OprPtr {
  82  private:
  83   JavaValue _value;
  84 
  85   void type_check(BasicType t) const   { assert(type() == t, "type check"); }
  86   void type_check(BasicType t1, BasicType t2) const   { assert(type() == t1 || type() == t2, "type check"); }
  87   void type_check(BasicType t1, BasicType t2, BasicType t3) const   { assert(type() == t1 || type() == t2 || type() == t3, "type check"); }
  88 
  89  public:
  90   LIR_Const(jint i, bool is_address=false)       { _value.set_type(is_address?T_ADDRESS:T_INT); _value.set_jint(i); }
  91   LIR_Const(jlong l)                             { _value.set_type(T_LONG);    _value.set_jlong(l); }
  92   LIR_Const(jfloat f)                            { _value.set_type(T_FLOAT);   _value.set_jfloat(f); }
  93   LIR_Const(jdouble d)                           { _value.set_type(T_DOUBLE);  _value.set_jdouble(d); }
  94   LIR_Const(jobject o)                           { _value.set_type(T_OBJECT);  _value.set_jobject(o); }
  95   LIR_Const(void* p) {
  96 #ifdef _LP64
  97     assert(sizeof(jlong) >= sizeof(p), "too small");;
  98     _value.set_type(T_LONG);    _value.set_jlong((jlong)p);
  99 #else
 100     assert(sizeof(jint) >= sizeof(p), "too small");;
 101     _value.set_type(T_INT);     _value.set_jint((jint)p);
 102 #endif
 103   }
 104   LIR_Const(Metadata* m) {
 105     _value.set_type(T_METADATA);
 106 #ifdef _LP64
 107     _value.set_jlong((jlong)m);
 108 #else
 109     _value.set_jint((jint)m);
 110 #endif // _LP64
 111   }
 112 
 113   virtual BasicType type()       const { return _value.get_type(); }
 114   virtual LIR_Const* as_constant()     { return this; }
 115 
 116   jint      as_jint()    const         { type_check(T_INT, T_ADDRESS); return _value.get_jint(); }
 117   jlong     as_jlong()   const         { type_check(T_LONG  ); return _value.get_jlong(); }
 118   jfloat    as_jfloat()  const         { type_check(T_FLOAT ); return _value.get_jfloat(); }
 119   jdouble   as_jdouble() const         { type_check(T_DOUBLE); return _value.get_jdouble(); }
 120   jobject   as_jobject() const         { type_check(T_OBJECT); return _value.get_jobject(); }
 121   jint      as_jint_lo() const         { type_check(T_LONG  ); return low(_value.get_jlong()); }
 122   jint      as_jint_hi() const         { type_check(T_LONG  ); return high(_value.get_jlong()); }
 123 
 124 #ifdef _LP64
 125   address   as_pointer() const         { type_check(T_LONG  ); return (address)_value.get_jlong(); }
 126   Metadata* as_metadata() const        { type_check(T_METADATA); return (Metadata*)_value.get_jlong(); }
 127 #else
 128   address   as_pointer() const         { type_check(T_INT   ); return (address)_value.get_jint(); }
 129   Metadata* as_metadata() const        { type_check(T_METADATA); return (Metadata*)_value.get_jint(); }
 130 #endif
 131 
 132 
 133   jint      as_jint_bits() const       { type_check(T_FLOAT, T_INT, T_ADDRESS); return _value.get_jint(); }
 134   jint      as_jint_lo_bits() const    {
 135     if (type() == T_DOUBLE) {
 136       return low(jlong_cast(_value.get_jdouble()));
 137     } else {
 138       return as_jint_lo();
 139     }
 140   }
 141   jint      as_jint_hi_bits() const    {
 142     if (type() == T_DOUBLE) {
 143       return high(jlong_cast(_value.get_jdouble()));
 144     } else {
 145       return as_jint_hi();
 146     }
 147   }
 148   jlong      as_jlong_bits() const    {
 149     if (type() == T_DOUBLE) {
 150       return jlong_cast(_value.get_jdouble());
 151     } else {
 152       return as_jlong();
 153     }
 154   }
 155 
 156   virtual void print_value_on(outputStream* out) const PRODUCT_RETURN;
 157 
 158 
 159   bool is_zero_float() {
 160     jfloat f = as_jfloat();
 161     jfloat ok = 0.0f;
 162     return jint_cast(f) == jint_cast(ok);
 163   }
 164 
 165   bool is_one_float() {
 166     jfloat f = as_jfloat();
 167     return !g_isnan(f) && g_isfinite(f) && f == 1.0;
 168   }
 169 
 170   bool is_zero_double() {
 171     jdouble d = as_jdouble();
 172     jdouble ok = 0.0;
 173     return jlong_cast(d) == jlong_cast(ok);
 174   }
 175 
 176   bool is_one_double() {
 177     jdouble d = as_jdouble();
 178     return !g_isnan(d) && g_isfinite(d) && d == 1.0;
 179   }
 180 };
 181 
 182 
 183 //---------------------LIR Operand descriptor------------------------------------
 184 //
 185 // The class LIR_Opr represents a LIR instruction operand;
 186 // it can be a register (ALU/FPU), stack location or a constant;
 187 // Constants and addresses are represented as resource area allocated
 188 // structures (see above), and pointers are stored in the _value field (cast to
 189 // an intptr_t).
 190 // Registers and stack locations are represented inline as integers.
 191 // (see value function).
 192 
 193 // Previously, this class was derived from CompilationResourceObj.
 194 // However, deriving from any of the "Obj" types in allocation.hpp seems
 195 // detrimental, since in some build modes it would add a vtable to this class,
 196 // which make it no longer be a 1-word trivially-copyable wrapper object,
 197 // which is the entire point of it.
 198 
 199 class LIR_Opr {
 200  public:
 201   // value structure:
 202   //          data        other-non-data opr-type opr-kind
 203   // +-------------------+--------------+-------+-----+
 204   // [max...............................|6 5 4 3|2 1 0]
 205   //                                                 ^
 206   //                                           is_pointer bit
 207   //
 208   // lowest bit cleared, means it is a structure pointer
 209   // we need 4 bits to represent types
 210 
 211  private:
 212   friend class LIR_OprFact;
 213 
 214   intptr_t _value;
 215   // Conversion
 216   intptr_t value() const                         { return _value; }
 217 
 218   bool check_value_mask(intptr_t mask, intptr_t masked_value) const {
 219     return (value() & mask) == masked_value;
 220   }
 221 
 222   enum OprKind {
 223       pointer_value      = 0
 224     , stack_value        = 1
 225     , cpu_register       = 3
 226     , fpu_register       = 5
 227     , illegal_value      = 7
 228   };
 229 
 230   enum OprBits {
 231       pointer_bits   = 1
 232     , kind_bits      = 3
 233     , type_bits      = 4
 234     , size_bits      = 2
 235     , destroys_bits  = 1
 236     , virtual_bits   = 1
 237     , is_xmm_bits    = 1
 238     , last_use_bits  = 1
 239     , is_fpu_stack_offset_bits = 1        // used in assertion checking on x86 for FPU stack slot allocation
 240     , non_data_bits  = kind_bits + type_bits + size_bits + destroys_bits + virtual_bits
 241                        + is_xmm_bits + last_use_bits + is_fpu_stack_offset_bits
 242     , data_bits      = BitsPerInt - non_data_bits
 243     , reg_bits       = data_bits / 2      // for two registers in one value encoding
 244   };
 245 
 246   enum OprShift : uintptr_t {
 247       kind_shift     = 0
 248     , type_shift     = kind_shift     + kind_bits
 249     , size_shift     = type_shift     + type_bits
 250     , destroys_shift = size_shift     + size_bits
 251     , last_use_shift = destroys_shift + destroys_bits
 252     , is_fpu_stack_offset_shift = last_use_shift + last_use_bits
 253     , virtual_shift  = is_fpu_stack_offset_shift + is_fpu_stack_offset_bits
 254     , is_xmm_shift   = virtual_shift + virtual_bits
 255     , data_shift     = is_xmm_shift + is_xmm_bits
 256     , reg1_shift = data_shift
 257     , reg2_shift = data_shift + reg_bits
 258 
 259   };
 260 
 261   enum OprSize {
 262       single_size = 0 << size_shift
 263     , double_size = 1 << size_shift
 264   };
 265 
 266   enum OprMask {
 267       kind_mask      = right_n_bits(kind_bits)
 268     , type_mask      = right_n_bits(type_bits) << type_shift
 269     , size_mask      = right_n_bits(size_bits) << size_shift
 270     , last_use_mask  = right_n_bits(last_use_bits) << last_use_shift
 271     , is_fpu_stack_offset_mask = right_n_bits(is_fpu_stack_offset_bits) << is_fpu_stack_offset_shift
 272     , virtual_mask   = right_n_bits(virtual_bits) << virtual_shift
 273     , is_xmm_mask    = right_n_bits(is_xmm_bits) << is_xmm_shift
 274     , pointer_mask   = right_n_bits(pointer_bits)
 275     , lower_reg_mask = right_n_bits(reg_bits)
 276     , no_type_mask   = (int)(~(type_mask | last_use_mask | is_fpu_stack_offset_mask))
 277   };
 278 
 279   uint32_t data() const                          { return (uint32_t)value() >> data_shift; }
 280   int lo_reg_half() const                        { return data() & lower_reg_mask; }
 281   int hi_reg_half() const                        { return (data() >> reg_bits) & lower_reg_mask; }
 282   OprKind kind_field() const                     { return (OprKind)(value() & kind_mask); }
 283   OprSize size_field() const                     { return (OprSize)(value() & size_mask); }
 284 
 285   static char type_char(BasicType t);
 286 
 287  public:
 288   LIR_Opr() : _value(0) {}
 289   LIR_Opr(intptr_t val) : _value(val) {}
 290   LIR_Opr(LIR_OprPtr *val) : _value(reinterpret_cast<intptr_t>(val)) {}
 291   bool operator==(const LIR_Opr &other) const { return _value == other._value; }
 292   bool operator!=(const LIR_Opr &other) const { return _value != other._value; }
 293   explicit operator bool() const { return _value != 0; }
 294 
 295   // UGLY HACK: make this value object look like a pointer (to itself). This
 296   // operator overload should be removed, and all callers updated from
 297   // `opr->fn()` to `opr.fn()`.
 298   const LIR_Opr* operator->() const { return this; }
 299   LIR_Opr* operator->() { return this; }
 300 
 301   enum {
 302     vreg_base = ConcreteRegisterImpl::number_of_registers,
 303     data_max = (1 << data_bits) - 1,      // max unsigned value for data bit field
 304     vreg_limit =  10000,                  // choose a reasonable limit,
 305     vreg_max = MIN2(vreg_limit, data_max) // and make sure if fits in the bit field
 306   };
 307 
 308   static inline LIR_Opr illegalOpr();
 309   static inline LIR_Opr nullOpr();
 310 
 311   enum OprType {
 312       unknown_type  = 0 << type_shift    // means: not set (catch uninitialized types)
 313     , int_type      = 1 << type_shift
 314     , long_type     = 2 << type_shift
 315     , object_type   = 3 << type_shift
 316     , address_type  = 4 << type_shift
 317     , float_type    = 5 << type_shift
 318     , double_type   = 6 << type_shift
 319     , metadata_type = 7 << type_shift
 320   };
 321   friend OprType as_OprType(BasicType t);
 322   friend BasicType as_BasicType(OprType t);
 323 
 324   OprType type_field_valid() const               { assert(is_register() || is_stack(), "should not be called otherwise"); return (OprType)(value() & type_mask); }
 325   OprType type_field() const                     { return is_illegal() ? unknown_type : (OprType)(value() & type_mask); }
 326 
 327   static OprSize size_for(BasicType t) {
 328     switch (t) {
 329       case T_LONG:
 330       case T_DOUBLE:
 331         return double_size;
 332         break;
 333 
 334       case T_FLOAT:
 335       case T_BOOLEAN:
 336       case T_CHAR:
 337       case T_BYTE:
 338       case T_SHORT:
 339       case T_INT:
 340       case T_ADDRESS:
 341       case T_OBJECT:
 342       case T_ARRAY:
 343       case T_METADATA:
 344         return single_size;
 345         break;
 346 
 347       default:
 348         ShouldNotReachHere();
 349         return single_size;
 350       }
 351   }
 352 
 353 
 354   void validate_type() const PRODUCT_RETURN;
 355 
 356   BasicType type() const {
 357     if (is_pointer()) {
 358       return pointer()->type();
 359     }
 360     return as_BasicType(type_field());
 361   }
 362 
 363 
 364   ValueType* value_type() const                  { return as_ValueType(type()); }
 365 
 366   char type_char() const                         { return type_char((is_pointer()) ? pointer()->type() : type()); }
 367 
 368   bool is_equal(LIR_Opr opr) const         { return *this == opr; }
 369   // checks whether types are same
 370   bool is_same_type(LIR_Opr opr) const     {
 371     assert(type_field() != unknown_type &&
 372            opr->type_field() != unknown_type, "shouldn't see unknown_type");
 373     return type_field() == opr->type_field();
 374   }
 375   bool is_same_register(LIR_Opr opr) {
 376     return (is_register() && opr->is_register() &&
 377             kind_field() == opr->kind_field() &&
 378             (value() & no_type_mask) == (opr->value() & no_type_mask));
 379   }
 380 
 381   bool is_pointer() const      { return check_value_mask(pointer_mask, pointer_value); }
 382   bool is_illegal() const      { return kind_field() == illegal_value; }
 383   bool is_valid() const        { return kind_field() != illegal_value; }
 384 
 385   bool is_register() const     { return is_cpu_register() || is_fpu_register(); }
 386   bool is_virtual() const      { return is_virtual_cpu()  || is_virtual_fpu();  }
 387 
 388   bool is_constant() const     { return is_pointer() && pointer()->as_constant() != nullptr; }
 389   bool is_address() const      { return is_pointer() && pointer()->as_address() != nullptr; }
 390 
 391   bool is_float_kind() const   { return is_pointer() ? pointer()->is_float_kind() : (kind_field() == fpu_register); }
 392   bool is_oop() const;
 393 
 394   // semantic for fpu- and xmm-registers:
 395   // * is_float and is_double return true for xmm_registers
 396   //   (so is_single_fpu and is_single_xmm are true)
 397   // * So you must always check for is_???_xmm prior to is_???_fpu to
 398   //   distinguish between fpu- and xmm-registers
 399 
 400   bool is_stack() const        { validate_type(); return check_value_mask(kind_mask,                stack_value);                 }
 401   bool is_single_stack() const { validate_type(); return check_value_mask(kind_mask | size_mask,    stack_value  | single_size);  }
 402   bool is_double_stack() const { validate_type(); return check_value_mask(kind_mask | size_mask,    stack_value  | double_size);  }
 403 
 404   bool is_cpu_register() const { validate_type(); return check_value_mask(kind_mask,                cpu_register);                }
 405   bool is_virtual_cpu() const  { validate_type(); return check_value_mask(kind_mask | virtual_mask, cpu_register | virtual_mask); }
 406   bool is_fixed_cpu() const    { validate_type(); return check_value_mask(kind_mask | virtual_mask, cpu_register);                }
 407   bool is_single_cpu() const   { validate_type(); return check_value_mask(kind_mask | size_mask,    cpu_register | single_size);  }
 408   bool is_double_cpu() const   { validate_type(); return check_value_mask(kind_mask | size_mask,    cpu_register | double_size);  }
 409 
 410   bool is_fpu_register() const { validate_type(); return check_value_mask(kind_mask,                fpu_register);                }
 411   bool is_virtual_fpu() const  { validate_type(); return check_value_mask(kind_mask | virtual_mask, fpu_register | virtual_mask); }
 412   bool is_fixed_fpu() const    { validate_type(); return check_value_mask(kind_mask | virtual_mask, fpu_register);                }
 413   bool is_single_fpu() const   { validate_type(); return check_value_mask(kind_mask | size_mask,    fpu_register | single_size);  }
 414   bool is_double_fpu() const   { validate_type(); return check_value_mask(kind_mask | size_mask,    fpu_register | double_size);  }
 415 
 416   bool is_xmm_register() const { validate_type(); return check_value_mask(kind_mask | is_xmm_mask,             fpu_register | is_xmm_mask); }
 417   bool is_single_xmm() const   { validate_type(); return check_value_mask(kind_mask | size_mask | is_xmm_mask, fpu_register | single_size | is_xmm_mask); }
 418   bool is_double_xmm() const   { validate_type(); return check_value_mask(kind_mask | size_mask | is_xmm_mask, fpu_register | double_size | is_xmm_mask); }
 419 
 420   // fast accessor functions for special bits that do not work for pointers
 421   // (in this functions, the check for is_pointer() is omitted)
 422   bool is_single_word() const      { assert(is_register() || is_stack(), "type check"); return check_value_mask(size_mask, single_size); }
 423   bool is_double_word() const      { assert(is_register() || is_stack(), "type check"); return check_value_mask(size_mask, double_size); }
 424   bool is_virtual_register() const { assert(is_register(),               "type check"); return check_value_mask(virtual_mask, virtual_mask); }
 425   bool is_oop_register() const     { assert(is_register() || is_stack(), "type check"); return type_field_valid() == object_type; }
 426   BasicType type_register() const  { assert(is_register() || is_stack(), "type check"); return as_BasicType(type_field_valid());  }
 427 
 428   bool is_last_use() const         { assert(is_register(), "only works for registers"); return (value() & last_use_mask) != 0; }
 429   bool is_fpu_stack_offset() const { assert(is_register(), "only works for registers"); return (value() & is_fpu_stack_offset_mask) != 0; }
 430   LIR_Opr make_last_use()          { assert(is_register(), "only works for registers"); return (LIR_Opr)(value() | last_use_mask); }
 431   LIR_Opr make_fpu_stack_offset()  { assert(is_register(), "only works for registers"); return (LIR_Opr)(value() | is_fpu_stack_offset_mask); }
 432 
 433 
 434   int single_stack_ix() const  { assert(is_single_stack() && !is_virtual(), "type check"); return (int)data(); }
 435   int double_stack_ix() const  { assert(is_double_stack() && !is_virtual(), "type check"); return (int)data(); }
 436   RegNr cpu_regnr() const      { assert(is_single_cpu()   && !is_virtual(), "type check"); return (RegNr)data(); }
 437   RegNr cpu_regnrLo() const    { assert(is_double_cpu()   && !is_virtual(), "type check"); return (RegNr)lo_reg_half(); }
 438   RegNr cpu_regnrHi() const    { assert(is_double_cpu()   && !is_virtual(), "type check"); return (RegNr)hi_reg_half(); }
 439   RegNr fpu_regnr() const      { assert(is_single_fpu()   && !is_virtual(), "type check"); return (RegNr)data(); }
 440   RegNr fpu_regnrLo() const    { assert(is_double_fpu()   && !is_virtual(), "type check"); return (RegNr)lo_reg_half(); }
 441   RegNr fpu_regnrHi() const    { assert(is_double_fpu()   && !is_virtual(), "type check"); return (RegNr)hi_reg_half(); }
 442   RegNr xmm_regnr() const      { assert(is_single_xmm()   && !is_virtual(), "type check"); return (RegNr)data(); }
 443   RegNr xmm_regnrLo() const    { assert(is_double_xmm()   && !is_virtual(), "type check"); return (RegNr)lo_reg_half(); }
 444   RegNr xmm_regnrHi() const    { assert(is_double_xmm()   && !is_virtual(), "type check"); return (RegNr)hi_reg_half(); }
 445   int   vreg_number() const    { assert(is_virtual(),                       "type check"); return (RegNr)data(); }
 446 
 447   LIR_OprPtr* pointer() const { assert(_value != 0 && is_pointer(), "nullness and type check"); return (LIR_OprPtr*)_value; }
 448   LIR_Const* as_constant_ptr() const             { return pointer()->as_constant(); }
 449   LIR_Address* as_address_ptr() const            { return pointer()->as_address(); }
 450 
 451   Register as_register()    const;
 452   Register as_register_lo() const;
 453   Register as_register_hi() const;
 454 
 455   Register as_pointer_register() {
 456 #ifdef _LP64
 457     if (is_double_cpu()) {
 458       assert(as_register_lo() == as_register_hi(), "should be a single register");
 459       return as_register_lo();
 460     }
 461 #endif
 462     return as_register();
 463   }
 464 
 465   FloatRegister as_float_reg   () const;
 466   FloatRegister as_double_reg  () const;
 467 #ifdef X86
 468   XMMRegister as_xmm_float_reg () const;
 469   XMMRegister as_xmm_double_reg() const;
 470   // for compatibility with RInfo
 471   int fpu() const { return lo_reg_half(); }
 472 #endif
 473 
 474   jint      as_jint()    const { return as_constant_ptr()->as_jint(); }
 475   jlong     as_jlong()   const { return as_constant_ptr()->as_jlong(); }
 476   jfloat    as_jfloat()  const { return as_constant_ptr()->as_jfloat(); }
 477   jdouble   as_jdouble() const { return as_constant_ptr()->as_jdouble(); }
 478   jobject   as_jobject() const { return as_constant_ptr()->as_jobject(); }
 479 
 480   void print() const PRODUCT_RETURN;
 481   void print(outputStream* out) const PRODUCT_RETURN;
 482 };
 483 
 484 inline LIR_Opr::OprType as_OprType(BasicType type) {
 485   switch (type) {
 486   case T_INT:      return LIR_Opr::int_type;
 487   case T_LONG:     return LIR_Opr::long_type;
 488   case T_FLOAT:    return LIR_Opr::float_type;
 489   case T_DOUBLE:   return LIR_Opr::double_type;
 490   case T_OBJECT:
 491   case T_ARRAY:    return LIR_Opr::object_type;
 492   case T_ADDRESS:  return LIR_Opr::address_type;
 493   case T_METADATA: return LIR_Opr::metadata_type;
 494   case T_ILLEGAL:  // fall through
 495   default: ShouldNotReachHere(); return LIR_Opr::unknown_type;
 496   }
 497 }
 498 
 499 inline BasicType as_BasicType(LIR_Opr::OprType t) {
 500   switch (t) {
 501   case LIR_Opr::int_type:     return T_INT;
 502   case LIR_Opr::long_type:    return T_LONG;
 503   case LIR_Opr::float_type:   return T_FLOAT;
 504   case LIR_Opr::double_type:  return T_DOUBLE;
 505   case LIR_Opr::object_type:  return T_OBJECT;
 506   case LIR_Opr::address_type: return T_ADDRESS;
 507   case LIR_Opr::metadata_type:return T_METADATA;
 508   case LIR_Opr::unknown_type: // fall through
 509   default: ShouldNotReachHere();  return T_ILLEGAL;
 510   }
 511 }
 512 
 513 
 514 // LIR_Address
 515 class LIR_Address: public LIR_OprPtr {
 516  friend class LIR_OpVisitState;
 517 
 518  public:
 519   // NOTE: currently these must be the log2 of the scale factor (and
 520   // must also be equivalent to the ScaleFactor enum in
 521   // assembler_i486.hpp)
 522   enum Scale {
 523     times_1  =  0,
 524     times_2  =  1,
 525     times_4  =  2,
 526     times_8  =  3
 527   };
 528 
 529  private:
 530   LIR_Opr   _base;
 531   LIR_Opr   _index;
 532   intx      _disp;
 533   Scale     _scale;
 534   BasicType _type;
 535 
 536  public:
 537   LIR_Address(LIR_Opr base, LIR_Opr index, BasicType type):
 538        _base(base)
 539      , _index(index)
 540      , _disp(0)
 541      , _scale(times_1)
 542      , _type(type) { verify(); }
 543 
 544   LIR_Address(LIR_Opr base, intx disp, BasicType type):
 545        _base(base)
 546      , _index(LIR_Opr::illegalOpr())
 547      , _disp(disp)
 548      , _scale(times_1)
 549      , _type(type) { verify(); }
 550 
 551   LIR_Address(LIR_Opr base, BasicType type):
 552        _base(base)
 553      , _index(LIR_Opr::illegalOpr())
 554      , _disp(0)
 555      , _scale(times_1)
 556      , _type(type) { verify(); }
 557 
 558   LIR_Address(LIR_Opr base, LIR_Opr index, intx disp, BasicType type):
 559        _base(base)
 560      , _index(index)
 561      , _disp(disp)
 562      , _scale(times_1)
 563      , _type(type) { verify(); }
 564 
 565   LIR_Address(LIR_Opr base, LIR_Opr index, Scale scale, intx disp, BasicType type):
 566        _base(base)
 567      , _index(index)
 568      , _disp(disp)
 569      , _scale(scale)
 570      , _type(type) { verify(); }
 571 
 572   LIR_Opr base()  const                          { return _base;  }
 573   LIR_Opr index() const                          { return _index; }
 574   Scale   scale() const                          { return _scale; }
 575   intx    disp()  const                          { return _disp;  }
 576 
 577   bool equals(LIR_Address* other) const          { return base() == other->base() && index() == other->index() && disp() == other->disp() && scale() == other->scale(); }
 578 
 579   virtual LIR_Address* as_address()              { return this;   }
 580   virtual BasicType type() const                 { return _type; }
 581   virtual void print_value_on(outputStream* out) const PRODUCT_RETURN;
 582 
 583   void verify() const PRODUCT_RETURN;
 584 
 585   static Scale scale(BasicType type);
 586 };
 587 
 588 
 589 // operand factory
 590 class LIR_OprFact: public AllStatic {
 591  public:
 592 
 593   static LIR_Opr illegalOpr;
 594   static LIR_Opr nullOpr;
 595 
 596   static LIR_Opr single_cpu(int reg) {
 597     return (LIR_Opr)(intptr_t)((reg  << LIR_Opr::reg1_shift) |
 598                                LIR_Opr::int_type             |
 599                                LIR_Opr::cpu_register         |
 600                                LIR_Opr::single_size);
 601   }
 602   static LIR_Opr single_cpu_oop(int reg) {
 603     return (LIR_Opr)(intptr_t)((reg  << LIR_Opr::reg1_shift) |
 604                                LIR_Opr::object_type          |
 605                                LIR_Opr::cpu_register         |
 606                                LIR_Opr::single_size);
 607   }
 608   static LIR_Opr single_cpu_address(int reg) {
 609     return (LIR_Opr)(intptr_t)((reg  << LIR_Opr::reg1_shift) |
 610                                LIR_Opr::address_type         |
 611                                LIR_Opr::cpu_register         |
 612                                LIR_Opr::single_size);
 613   }
 614   static LIR_Opr single_cpu_metadata(int reg) {
 615     return (LIR_Opr)(intptr_t)((reg  << LIR_Opr::reg1_shift) |
 616                                LIR_Opr::metadata_type        |
 617                                LIR_Opr::cpu_register         |
 618                                LIR_Opr::single_size);
 619   }
 620   static LIR_Opr double_cpu(int reg1, int reg2) {
 621     LP64_ONLY(assert(reg1 == reg2, "must be identical"));
 622     return (LIR_Opr)(intptr_t)((reg1 << LIR_Opr::reg1_shift) |
 623                                (reg2 << LIR_Opr::reg2_shift) |
 624                                LIR_Opr::long_type            |
 625                                LIR_Opr::cpu_register         |
 626                                LIR_Opr::double_size);
 627   }
 628 
 629   static LIR_Opr single_fpu(int reg) {
 630     return (LIR_Opr)(intptr_t)((reg  << LIR_Opr::reg1_shift) |
 631                                LIR_Opr::float_type           |
 632                                LIR_Opr::fpu_register         |
 633                                LIR_Opr::single_size);
 634   }
 635 
 636   // Platform dependent.
 637   static LIR_Opr double_fpu(int reg1, int reg2 = -1 /*fnoreg*/);
 638 
 639 #ifdef ARM32
 640   static LIR_Opr single_softfp(int reg) {
 641     return (LIR_Opr)(intptr_t)((reg  << LIR_Opr::reg1_shift) |
 642                                LIR_Opr::float_type           |
 643                                LIR_Opr::cpu_register         |
 644                                LIR_Opr::single_size);
 645   }
 646   static LIR_Opr double_softfp(int reg1, int reg2) {
 647     return (LIR_Opr)(intptr_t)((reg1 << LIR_Opr::reg1_shift) |
 648                                (reg2 << LIR_Opr::reg2_shift) |
 649                                LIR_Opr::double_type          |
 650                                LIR_Opr::cpu_register         |
 651                                LIR_Opr::double_size);
 652   }
 653 #endif // ARM32
 654 
 655 #if defined(X86)
 656   static LIR_Opr single_xmm(int reg) {
 657     return (LIR_Opr)(intptr_t)((reg << LIR_Opr::reg1_shift) |
 658                                LIR_Opr::float_type          |
 659                                LIR_Opr::fpu_register        |
 660                                LIR_Opr::single_size         |
 661                                LIR_Opr::is_xmm_mask);
 662   }
 663   static LIR_Opr double_xmm(int reg) {
 664     return (LIR_Opr)(intptr_t)((reg << LIR_Opr::reg1_shift) |
 665                                (reg << LIR_Opr::reg2_shift) |
 666                                LIR_Opr::double_type         |
 667                                LIR_Opr::fpu_register        |
 668                                LIR_Opr::double_size         |
 669                                LIR_Opr::is_xmm_mask);
 670   }
 671 #endif // X86
 672 
 673   static LIR_Opr virtual_register(int index, BasicType type) {
 674     if (index > LIR_Opr::vreg_max) {
 675       // Running out of virtual registers. Caller should bailout.
 676       return illegalOpr;
 677     }
 678 
 679     LIR_Opr res;
 680     switch (type) {
 681       case T_OBJECT: // fall through
 682       case T_ARRAY:
 683         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift)  |
 684                                             LIR_Opr::object_type  |
 685                                             LIR_Opr::cpu_register |
 686                                             LIR_Opr::single_size  |
 687                                             LIR_Opr::virtual_mask);
 688         break;
 689 
 690       case T_METADATA:
 691         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift)  |
 692                                             LIR_Opr::metadata_type|
 693                                             LIR_Opr::cpu_register |
 694                                             LIR_Opr::single_size  |
 695                                             LIR_Opr::virtual_mask);
 696         break;
 697 
 698       case T_INT:
 699         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 700                                   LIR_Opr::int_type              |
 701                                   LIR_Opr::cpu_register          |
 702                                   LIR_Opr::single_size           |
 703                                   LIR_Opr::virtual_mask);
 704         break;
 705 
 706       case T_ADDRESS:
 707         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 708                                   LIR_Opr::address_type          |
 709                                   LIR_Opr::cpu_register          |
 710                                   LIR_Opr::single_size           |
 711                                   LIR_Opr::virtual_mask);
 712         break;
 713 
 714       case T_LONG:
 715         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 716                                   LIR_Opr::long_type             |
 717                                   LIR_Opr::cpu_register          |
 718                                   LIR_Opr::double_size           |
 719                                   LIR_Opr::virtual_mask);
 720         break;
 721 
 722 #ifdef __SOFTFP__
 723       case T_FLOAT:
 724         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 725                                   LIR_Opr::float_type  |
 726                                   LIR_Opr::cpu_register |
 727                                   LIR_Opr::single_size |
 728                                   LIR_Opr::virtual_mask);
 729         break;
 730       case T_DOUBLE:
 731         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 732                                   LIR_Opr::double_type |
 733                                   LIR_Opr::cpu_register |
 734                                   LIR_Opr::double_size |
 735                                   LIR_Opr::virtual_mask);
 736         break;
 737 #else // __SOFTFP__
 738       case T_FLOAT:
 739         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 740                                   LIR_Opr::float_type           |
 741                                   LIR_Opr::fpu_register         |
 742                                   LIR_Opr::single_size          |
 743                                   LIR_Opr::virtual_mask);
 744         break;
 745 
 746       case
 747         T_DOUBLE: res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 748                                             LIR_Opr::double_type           |
 749                                             LIR_Opr::fpu_register          |
 750                                             LIR_Opr::double_size           |
 751                                             LIR_Opr::virtual_mask);
 752         break;
 753 #endif // __SOFTFP__
 754       default:       ShouldNotReachHere(); res = illegalOpr;
 755     }
 756 
 757 #ifdef ASSERT
 758     res->validate_type();
 759     assert(res->vreg_number() == index, "conversion check");
 760     assert(index >= LIR_Opr::vreg_base, "must start at vreg_base");
 761 
 762     // old-style calculation; check if old and new method are equal
 763     LIR_Opr::OprType t = as_OprType(type);
 764 #ifdef __SOFTFP__
 765     LIR_Opr old_res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 766                                t |
 767                                LIR_Opr::cpu_register |
 768                                LIR_Opr::size_for(type) | LIR_Opr::virtual_mask);
 769 #else // __SOFTFP__
 770     LIR_Opr old_res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) | t |
 771                                           ((type == T_FLOAT || type == T_DOUBLE) ?  LIR_Opr::fpu_register : LIR_Opr::cpu_register) |
 772                                LIR_Opr::size_for(type) | LIR_Opr::virtual_mask);
 773     assert(res == old_res, "old and new method not equal");
 774 #endif // __SOFTFP__
 775 #endif // ASSERT
 776 
 777     return res;
 778   }
 779 
 780   // 'index' is computed by FrameMap::local_stack_pos(index); do not use other parameters as
 781   // the index is platform independent; a double stack using indices 2 and 3 has always
 782   // index 2.
 783   static LIR_Opr stack(int index, BasicType type) {
 784     LIR_Opr res;
 785     switch (type) {
 786       case T_OBJECT: // fall through
 787       case T_ARRAY:
 788         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 789                                   LIR_Opr::object_type           |
 790                                   LIR_Opr::stack_value           |
 791                                   LIR_Opr::single_size);
 792         break;
 793 
 794       case T_METADATA:
 795         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 796                                   LIR_Opr::metadata_type         |
 797                                   LIR_Opr::stack_value           |
 798                                   LIR_Opr::single_size);
 799         break;
 800       case T_INT:
 801         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 802                                   LIR_Opr::int_type              |
 803                                   LIR_Opr::stack_value           |
 804                                   LIR_Opr::single_size);
 805         break;
 806 
 807       case T_ADDRESS:
 808         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 809                                   LIR_Opr::address_type          |
 810                                   LIR_Opr::stack_value           |
 811                                   LIR_Opr::single_size);
 812         break;
 813 
 814       case T_LONG:
 815         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 816                                   LIR_Opr::long_type             |
 817                                   LIR_Opr::stack_value           |
 818                                   LIR_Opr::double_size);
 819         break;
 820 
 821       case T_FLOAT:
 822         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 823                                   LIR_Opr::float_type            |
 824                                   LIR_Opr::stack_value           |
 825                                   LIR_Opr::single_size);
 826         break;
 827       case T_DOUBLE:
 828         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 829                                   LIR_Opr::double_type           |
 830                                   LIR_Opr::stack_value           |
 831                                   LIR_Opr::double_size);
 832         break;
 833 
 834       default:       ShouldNotReachHere(); res = illegalOpr;
 835     }
 836 
 837 #ifdef ASSERT
 838     assert(index >= 0, "index must be positive");
 839     assert(index == (int)res->data(), "conversion check");
 840 
 841     LIR_Opr old_res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 842                                           LIR_Opr::stack_value           |
 843                                           as_OprType(type)                   |
 844                                           LIR_Opr::size_for(type));
 845     assert(res == old_res, "old and new method not equal");
 846 #endif
 847 
 848     return res;
 849   }
 850 
 851   static LIR_Opr intConst(jint i)                { return (LIR_Opr)(new LIR_Const(i)); }
 852   static LIR_Opr longConst(jlong l)              { return (LIR_Opr)(new LIR_Const(l)); }
 853   static LIR_Opr floatConst(jfloat f)            { return (LIR_Opr)(new LIR_Const(f)); }
 854   static LIR_Opr doubleConst(jdouble d)          { return (LIR_Opr)(new LIR_Const(d)); }
 855   static LIR_Opr oopConst(jobject o)             { return (LIR_Opr)(new LIR_Const(o)); }
 856   static LIR_Opr address(LIR_Address* a)         { return (LIR_Opr)a; }
 857   static LIR_Opr intptrConst(void* p)            { return (LIR_Opr)(new LIR_Const(p)); }
 858   static LIR_Opr intptrConst(intptr_t v)         { return (LIR_Opr)(new LIR_Const((void*)v)); }
 859   static LIR_Opr illegal()                       { return (LIR_Opr)-1; }
 860   static LIR_Opr addressConst(jint i)            { return (LIR_Opr)(new LIR_Const(i, true)); }
 861   static LIR_Opr metadataConst(Metadata* m)      { return (LIR_Opr)(new LIR_Const(m)); }
 862 
 863   static LIR_Opr value_type(ValueType* type);
 864 };
 865 
 866 
 867 //-------------------------------------------------------------------------------
 868 //                   LIR Instructions
 869 //-------------------------------------------------------------------------------
 870 //
 871 // Note:
 872 //  - every instruction has a result operand
 873 //  - every instruction has an CodeEmitInfo operand (can be revisited later)
 874 //  - every instruction has a LIR_OpCode operand
 875 //  - LIR_OpN, means an instruction that has N input operands
 876 //
 877 // class hierarchy:
 878 //
 879 class  LIR_Op;
 880 class    LIR_Op0;
 881 class      LIR_OpLabel;
 882 class    LIR_Op1;
 883 class      LIR_OpBranch;
 884 class      LIR_OpConvert;
 885 class      LIR_OpAllocObj;
 886 class      LIR_OpReturn;
 887 class      LIR_OpRoundFP;
 888 class    LIR_Op2;
 889 class    LIR_OpDelay;
 890 class    LIR_Op3;
 891 class      LIR_OpAllocArray;
 892 class    LIR_Op4;
 893 class    LIR_OpCall;
 894 class      LIR_OpJavaCall;
 895 class      LIR_OpRTCall;
 896 class    LIR_OpArrayCopy;
 897 class    LIR_OpUpdateCRC32;
 898 class    LIR_OpLock;
 899 class    LIR_OpTypeCheck;
 900 class    LIR_OpFlattenedArrayCheck;
 901 class    LIR_OpNullFreeArrayCheck;
 902 class    LIR_OpSubstitutabilityCheck;
 903 class    LIR_OpCompareAndSwap;
 904 class    LIR_OpLoadKlass;
 905 class    LIR_OpProfileCall;
 906 class    LIR_OpProfileType;
 907 class    LIR_OpProfileInlineType;
 908 #ifdef ASSERT
 909 class    LIR_OpAssert;
 910 #endif
 911 
 912 // LIR operation codes
 913 enum LIR_Code {
 914     lir_none
 915   , begin_op0
 916       , lir_label
 917       , lir_nop
 918       , lir_std_entry
 919       , lir_osr_entry
 920       , lir_fpop_raw
 921       , lir_breakpoint
 922       , lir_rtcall
 923       , lir_membar
 924       , lir_membar_acquire
 925       , lir_membar_release
 926       , lir_membar_loadload
 927       , lir_membar_storestore
 928       , lir_membar_loadstore
 929       , lir_membar_storeload
 930       , lir_get_thread
 931       , lir_on_spin_wait
 932       , lir_check_orig_pc
 933   , end_op0
 934   , begin_op1
 935       , lir_fxch
 936       , lir_fld
 937       , lir_push
 938       , lir_pop
 939       , lir_null_check
 940       , lir_return
 941       , lir_leal
 942       , lir_move
 943       , lir_convert
 944       , lir_alloc_object
 945       , lir_monaddr
 946       , lir_roundfp
 947       , lir_safepoint
 948       , lir_unwind
 949       , lir_load_klass
 950   , end_op1
 951   , begin_op2
 952       , lir_branch
 953       , lir_cond_float_branch
 954       , lir_cmp
 955       , lir_cmp_l2i
 956       , lir_ucmp_fd2i
 957       , lir_cmp_fd2i
 958       , lir_add
 959       , lir_sub
 960       , lir_mul
 961       , lir_div
 962       , lir_rem
 963       , lir_sqrt
 964       , lir_abs
 965       , lir_neg
 966       , lir_tan
 967       , lir_f2hf
 968       , lir_hf2f
 969       , lir_log10
 970       , lir_logic_and
 971       , lir_logic_or
 972       , lir_logic_xor
 973       , lir_shl
 974       , lir_shr
 975       , lir_ushr
 976       , lir_alloc_array
 977       , lir_throw
 978       , lir_xadd
 979       , lir_xchg
 980   , end_op2
 981   , begin_op3
 982       , lir_idiv
 983       , lir_irem
 984       , lir_fmad
 985       , lir_fmaf
 986   , end_op3
 987   , begin_op4
 988       , lir_cmove
 989   , end_op4
 990   , begin_opJavaCall
 991       , lir_static_call
 992       , lir_optvirtual_call
 993       , lir_icvirtual_call
 994       , lir_dynamic_call
 995   , end_opJavaCall
 996   , begin_opArrayCopy
 997       , lir_arraycopy
 998   , end_opArrayCopy
 999   , begin_opUpdateCRC32
1000       , lir_updatecrc32
1001   , end_opUpdateCRC32
1002   , begin_opLock
1003     , lir_lock
1004     , lir_unlock
1005   , end_opLock
1006   , begin_delay_slot
1007     , lir_delay_slot
1008   , end_delay_slot
1009   , begin_opTypeCheck
1010     , lir_instanceof
1011     , lir_checkcast
1012     , lir_store_check
1013   , end_opTypeCheck
1014   , begin_opFlattenedArrayCheck
1015     , lir_flat_array_check
1016   , end_opFlattenedArrayCheck
1017   , begin_opNullFreeArrayCheck
1018     , lir_null_free_array_check
1019   , end_opNullFreeArrayCheck
1020   , begin_opSubstitutabilityCheck
1021     , lir_substitutability_check
1022   , end_opSubstitutabilityCheck
1023   , begin_opCompareAndSwap
1024     , lir_cas_long
1025     , lir_cas_obj
1026     , lir_cas_int
1027   , end_opCompareAndSwap
1028   , begin_opMDOProfile
1029     , lir_profile_call
1030     , lir_profile_type
1031     , lir_profile_inline_type
1032   , end_opMDOProfile
1033   , begin_opAssert
1034     , lir_assert
1035   , end_opAssert
1036 #ifdef INCLUDE_ZGC
1037   , begin_opXLoadBarrierTest
1038     , lir_xloadbarrier_test
1039   , end_opXLoadBarrierTest
1040 #endif
1041 };
1042 
1043 
1044 enum LIR_Condition {
1045     lir_cond_equal
1046   , lir_cond_notEqual
1047   , lir_cond_less
1048   , lir_cond_lessEqual
1049   , lir_cond_greaterEqual
1050   , lir_cond_greater
1051   , lir_cond_belowEqual
1052   , lir_cond_aboveEqual
1053   , lir_cond_always
1054   , lir_cond_unknown = -1
1055 };
1056 
1057 
1058 enum LIR_PatchCode {
1059   lir_patch_none,
1060   lir_patch_low,
1061   lir_patch_high,
1062   lir_patch_normal
1063 };
1064 
1065 
1066 enum LIR_MoveKind {
1067   lir_move_normal,
1068   lir_move_volatile,
1069   lir_move_wide,
1070   lir_move_max_flag
1071 };
1072 
1073 
1074 // --------------------------------------------------
1075 // LIR_Op
1076 // --------------------------------------------------
1077 class LIR_Op: public CompilationResourceObj {
1078  friend class LIR_OpVisitState;
1079 
1080 #ifdef ASSERT
1081  private:
1082   const char *  _file;
1083   int           _line;
1084 #endif
1085 
1086  protected:
1087   LIR_Opr       _result;
1088   unsigned short _code;
1089   unsigned short _flags;
1090   CodeEmitInfo* _info;
1091   int           _id;     // value id for register allocation
1092   int           _fpu_pop_count;
1093   Instruction*  _source; // for debugging
1094 
1095   static void print_condition(outputStream* out, LIR_Condition cond) PRODUCT_RETURN;
1096 
1097  protected:
1098   static bool is_in_range(LIR_Code test, LIR_Code start, LIR_Code end)  { return start < test && test < end; }
1099 
1100  public:
1101   LIR_Op()
1102     :
1103 #ifdef ASSERT
1104       _file(nullptr)
1105     , _line(0),
1106 #endif
1107       _result(LIR_OprFact::illegalOpr)
1108     , _code(lir_none)
1109     , _flags(0)
1110     , _info(nullptr)
1111     , _id(-1)
1112     , _fpu_pop_count(0)
1113     , _source(nullptr) {}
1114 
1115   LIR_Op(LIR_Code code, LIR_Opr result, CodeEmitInfo* info)
1116     :
1117 #ifdef ASSERT
1118       _file(nullptr)
1119     , _line(0),
1120 #endif
1121       _result(result)
1122     , _code(code)
1123     , _flags(0)
1124     , _info(info)
1125     , _id(-1)
1126     , _fpu_pop_count(0)
1127     , _source(nullptr) {}
1128 
1129   CodeEmitInfo* info() const                  { return _info;   }
1130   LIR_Code code()      const                  { return (LIR_Code)_code;   }
1131   LIR_Opr result_opr() const                  { return _result; }
1132   void    set_result_opr(LIR_Opr opr)         { _result = opr;  }
1133 
1134 #ifdef ASSERT
1135   void set_file_and_line(const char * file, int line) {
1136     _file = file;
1137     _line = line;
1138   }
1139 #endif
1140 
1141   virtual const char * name() const PRODUCT_RETURN_NULL;
1142   virtual void visit(LIR_OpVisitState* state);
1143 
1144   int id()             const                  { return _id;     }
1145   void set_id(int id)                         { _id = id; }
1146 
1147   // FPU stack simulation helpers -- only used on Intel
1148   void set_fpu_pop_count(int count)           { assert(count >= 0 && count <= 1, "currently only 0 and 1 are valid"); _fpu_pop_count = count; }
1149   int  fpu_pop_count() const                  { return _fpu_pop_count; }
1150   bool pop_fpu_stack()                        { return _fpu_pop_count > 0; }
1151 
1152   Instruction* source() const                 { return _source; }
1153   void set_source(Instruction* ins)           { _source = ins; }
1154 
1155   virtual void emit_code(LIR_Assembler* masm) = 0;
1156   virtual void print_instr(outputStream* out) const   = 0;
1157   virtual void print_on(outputStream* st) const PRODUCT_RETURN;
1158 
1159   virtual bool is_patching() { return false; }
1160   virtual LIR_OpCall* as_OpCall() { return nullptr; }
1161   virtual LIR_OpJavaCall* as_OpJavaCall() { return nullptr; }
1162   virtual LIR_OpLabel* as_OpLabel() { return nullptr; }
1163   virtual LIR_OpDelay* as_OpDelay() { return nullptr; }
1164   virtual LIR_OpLock* as_OpLock() { return nullptr; }
1165   virtual LIR_OpAllocArray* as_OpAllocArray() { return nullptr; }
1166   virtual LIR_OpAllocObj* as_OpAllocObj() { return nullptr; }
1167   virtual LIR_OpRoundFP* as_OpRoundFP() { return nullptr; }
1168   virtual LIR_OpBranch* as_OpBranch() { return nullptr; }
1169   virtual LIR_OpReturn* as_OpReturn() { return nullptr; }
1170   virtual LIR_OpRTCall* as_OpRTCall() { return nullptr; }
1171   virtual LIR_OpConvert* as_OpConvert() { return nullptr; }
1172   virtual LIR_Op0* as_Op0() { return nullptr; }
1173   virtual LIR_Op1* as_Op1() { return nullptr; }
1174   virtual LIR_Op2* as_Op2() { return nullptr; }
1175   virtual LIR_Op3* as_Op3() { return nullptr; }
1176   virtual LIR_Op4* as_Op4() { return nullptr; }
1177   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return nullptr; }
1178   virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return nullptr; }
1179   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return nullptr; }
1180   virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return nullptr; }
1181   virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return nullptr; }
1182   virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return nullptr; }
1183   virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return nullptr; }
1184   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return nullptr; }
1185   virtual LIR_OpProfileCall* as_OpProfileCall() { return nullptr; }
1186   virtual LIR_OpProfileType* as_OpProfileType() { return nullptr; }
1187   virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return nullptr; }
1188 #ifdef ASSERT
1189   virtual LIR_OpAssert* as_OpAssert() { return nullptr; }
1190 #endif
1191 
1192   virtual void verify() const {}
1193 };
1194 
1195 // for calls
1196 class LIR_OpCall: public LIR_Op {
1197  friend class LIR_OpVisitState;
1198 
1199  protected:
1200   address      _addr;
1201   LIR_OprList* _arguments;
1202  protected:
1203   LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1204              LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1205     : LIR_Op(code, result, info)
1206     , _addr(addr)
1207     , _arguments(arguments) {}
1208 
1209  public:
1210   address addr() const                           { return _addr; }
1211   const LIR_OprList* arguments() const           { return _arguments; }
1212   virtual LIR_OpCall* as_OpCall()                { return this; }
1213 };
1214 
1215 
1216 // --------------------------------------------------
1217 // LIR_OpJavaCall
1218 // --------------------------------------------------
1219 class LIR_OpJavaCall: public LIR_OpCall {
1220  friend class LIR_OpVisitState;
1221 
1222  private:
1223   ciMethod* _method;
1224   LIR_Opr   _receiver;
1225   LIR_Opr   _method_handle_invoke_SP_save_opr;  // Used in LIR_OpVisitState::visit to store the reference to FrameMap::method_handle_invoke_SP_save_opr.
1226 
1227  public:
1228   LIR_OpJavaCall(LIR_Code code, ciMethod* method,
1229                  LIR_Opr receiver, LIR_Opr result,
1230                  address addr, LIR_OprList* arguments,
1231                  CodeEmitInfo* info)
1232   : LIR_OpCall(code, addr, result, arguments, info)
1233   , _method(method)
1234   , _receiver(receiver)
1235   , _method_handle_invoke_SP_save_opr(LIR_OprFact::illegalOpr)
1236   { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1237 
1238   LIR_OpJavaCall(LIR_Code code, ciMethod* method,
1239                  LIR_Opr receiver, LIR_Opr result, intptr_t vtable_offset,
1240                  LIR_OprList* arguments, CodeEmitInfo* info)
1241   : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1242   , _method(method)
1243   , _receiver(receiver)
1244   , _method_handle_invoke_SP_save_opr(LIR_OprFact::illegalOpr)
1245   { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1246 
1247   LIR_Opr receiver() const                       { return _receiver; }
1248   ciMethod* method() const                       { return _method;   }
1249 
1250   // JSR 292 support.
1251   bool is_invokedynamic() const                  { return code() == lir_dynamic_call; }
1252   bool is_method_handle_invoke() const {
1253     return method()->is_compiled_lambda_form() ||   // Java-generated lambda form
1254            method()->is_method_handle_intrinsic();  // JVM-generated MH intrinsic
1255   }
1256 
1257   virtual void emit_code(LIR_Assembler* masm);
1258   virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1259   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1260 
1261   bool maybe_return_as_fields(ciInlineKlass** vk = nullptr) const;
1262 };
1263 
1264 // --------------------------------------------------
1265 // LIR_OpLabel
1266 // --------------------------------------------------
1267 // Location where a branch can continue
1268 class LIR_OpLabel: public LIR_Op {
1269  friend class LIR_OpVisitState;
1270 
1271  private:
1272   Label* _label;
1273  public:
1274   LIR_OpLabel(Label* lbl)
1275    : LIR_Op(lir_label, LIR_OprFact::illegalOpr, nullptr)
1276    , _label(lbl)                                 {}
1277   Label* label() const                           { return _label; }
1278 
1279   virtual void emit_code(LIR_Assembler* masm);
1280   virtual LIR_OpLabel* as_OpLabel() { return this; }
1281   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1282 };
1283 
1284 // LIR_OpArrayCopy
1285 class LIR_OpArrayCopy: public LIR_Op {
1286  friend class LIR_OpVisitState;
1287 
1288  private:
1289   ArrayCopyStub*  _stub;
1290   LIR_Opr   _src;
1291   LIR_Opr   _src_pos;
1292   LIR_Opr   _dst;
1293   LIR_Opr   _dst_pos;
1294   LIR_Opr   _length;
1295   LIR_Opr   _tmp;
1296   ciArrayKlass* _expected_type;
1297   int       _flags;
1298 
1299 public:
1300   enum Flags {
1301     src_null_check         = 1 << 0,
1302     dst_null_check         = 1 << 1,
1303     src_pos_positive_check = 1 << 2,
1304     dst_pos_positive_check = 1 << 3,
1305     length_positive_check  = 1 << 4,
1306     src_range_check        = 1 << 5,
1307     dst_range_check        = 1 << 6,
1308     type_check             = 1 << 7,
1309     overlapping            = 1 << 8,
1310     unaligned              = 1 << 9,
1311     src_objarray           = 1 << 10,
1312     dst_objarray           = 1 << 11,
1313     always_slow_path       = 1 << 12,
1314     src_inlinetype_check   = 1 << 13,
1315     dst_inlinetype_check   = 1 << 14,
1316     all_flags              = (1 << 15) - 1
1317   };
1318 
1319   LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1320                   ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1321 
1322   LIR_Opr src() const                            { return _src; }
1323   LIR_Opr src_pos() const                        { return _src_pos; }
1324   LIR_Opr dst() const                            { return _dst; }
1325   LIR_Opr dst_pos() const                        { return _dst_pos; }
1326   LIR_Opr length() const                         { return _length; }
1327   LIR_Opr tmp() const                            { return _tmp; }
1328   int flags() const                              { return _flags; }
1329   ciArrayKlass* expected_type() const            { return _expected_type; }
1330   ArrayCopyStub* stub() const                    { return _stub; }
1331 
1332   virtual void emit_code(LIR_Assembler* masm);
1333   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1334   void print_instr(outputStream* out) const PRODUCT_RETURN;
1335 };
1336 
1337 // LIR_OpUpdateCRC32
1338 class LIR_OpUpdateCRC32: public LIR_Op {
1339   friend class LIR_OpVisitState;
1340 
1341 private:
1342   LIR_Opr   _crc;
1343   LIR_Opr   _val;
1344 
1345 public:
1346 
1347   LIR_OpUpdateCRC32(LIR_Opr crc, LIR_Opr val, LIR_Opr res);
1348 
1349   LIR_Opr crc() const                            { return _crc; }
1350   LIR_Opr val() const                            { return _val; }
1351 
1352   virtual void emit_code(LIR_Assembler* masm);
1353   virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32()  { return this; }
1354   void print_instr(outputStream* out) const PRODUCT_RETURN;
1355 };
1356 
1357 // --------------------------------------------------
1358 // LIR_Op0
1359 // --------------------------------------------------
1360 class LIR_Op0: public LIR_Op {
1361  friend class LIR_OpVisitState;
1362 
1363  public:
1364   LIR_Op0(LIR_Code code)
1365    : LIR_Op(code, LIR_OprFact::illegalOpr, nullptr)  { assert(is_in_range(code, begin_op0, end_op0), "code check"); }
1366   LIR_Op0(LIR_Code code, LIR_Opr result, CodeEmitInfo* info = nullptr)
1367    : LIR_Op(code, result, info)  { assert(is_in_range(code, begin_op0, end_op0), "code check"); }
1368 
1369   virtual void emit_code(LIR_Assembler* masm);
1370   virtual LIR_Op0* as_Op0() { return this; }
1371   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1372 };
1373 
1374 
1375 // --------------------------------------------------
1376 // LIR_Op1
1377 // --------------------------------------------------
1378 
1379 class LIR_Op1: public LIR_Op {
1380  friend class LIR_OpVisitState;
1381 
1382  protected:
1383   LIR_Opr         _opr;   // input operand
1384   BasicType       _type;  // Operand types
1385   LIR_PatchCode   _patch; // only required with patchin (NEEDS_CLEANUP: do we want a special instruction for patching?)
1386 
1387   static void print_patch_code(outputStream* out, LIR_PatchCode code);
1388 
1389   void set_kind(LIR_MoveKind kind) {
1390     assert(code() == lir_move, "must be");
1391     _flags = kind;
1392   }
1393 
1394  public:
1395   LIR_Op1(LIR_Code code, LIR_Opr opr, LIR_Opr result = LIR_OprFact::illegalOpr, BasicType type = T_ILLEGAL, LIR_PatchCode patch = lir_patch_none, CodeEmitInfo* info = nullptr)
1396     : LIR_Op(code, result, info)
1397     , _opr(opr)
1398     , _type(type)
1399     , _patch(patch)                    { assert(is_in_range(code, begin_op1, end_op1), "code check"); }
1400 
1401   LIR_Op1(LIR_Code code, LIR_Opr opr, LIR_Opr result, BasicType type, LIR_PatchCode patch, CodeEmitInfo* info, LIR_MoveKind kind)
1402     : LIR_Op(code, result, info)
1403     , _opr(opr)
1404     , _type(type)
1405     , _patch(patch)                    {
1406     assert(code == lir_move, "must be");
1407     set_kind(kind);
1408   }
1409 
1410   LIR_Op1(LIR_Code code, LIR_Opr opr, CodeEmitInfo* info)
1411     : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1412     , _opr(opr)
1413     , _type(T_ILLEGAL)
1414     , _patch(lir_patch_none)           { assert(is_in_range(code, begin_op1, end_op1), "code check"); }
1415 
1416   LIR_Opr in_opr()           const               { return _opr;   }
1417   LIR_PatchCode patch_code() const               { return _patch; }
1418   BasicType type()           const               { return _type;  }
1419 
1420   LIR_MoveKind move_kind() const {
1421     assert(code() == lir_move, "must be");
1422     return (LIR_MoveKind)_flags;
1423   }
1424 
1425   virtual bool is_patching() { return _patch != lir_patch_none; }
1426   virtual void emit_code(LIR_Assembler* masm);
1427   virtual LIR_Op1* as_Op1() { return this; }
1428   virtual const char * name() const PRODUCT_RETURN_NULL;
1429 
1430   void set_in_opr(LIR_Opr opr) { _opr = opr; }
1431 
1432   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1433   virtual void verify() const;
1434 };
1435 
1436 
1437 // for runtime calls
1438 class LIR_OpRTCall: public LIR_OpCall {
1439  friend class LIR_OpVisitState;
1440 
1441  private:
1442   LIR_Opr _tmp;
1443  public:
1444   LIR_OpRTCall(address addr, LIR_Opr tmp,
1445                LIR_Opr result, LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1446     : LIR_OpCall(lir_rtcall, addr, result, arguments, info)
1447     , _tmp(tmp) {}
1448 
1449   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1450   virtual void emit_code(LIR_Assembler* masm);
1451   virtual LIR_OpRTCall* as_OpRTCall() { return this; }
1452 
1453   LIR_Opr tmp() const                            { return _tmp; }
1454 
1455   virtual void verify() const;
1456 };
1457 
1458 
1459 
1460 class LIR_OpReturn: public LIR_Op1 {
1461  friend class LIR_OpVisitState;
1462 
1463  private:
1464   C1SafepointPollStub* _stub;
1465 
1466  public:
1467   LIR_OpReturn(LIR_Opr opr);
1468 
1469   C1SafepointPollStub* stub() const { return _stub; }
1470   virtual LIR_OpReturn* as_OpReturn() { return this; }
1471 };
1472 
1473 class ConversionStub;
1474 
1475 class LIR_OpConvert: public LIR_Op1 {
1476  friend class LIR_OpVisitState;
1477 
1478  private:
1479    Bytecodes::Code _bytecode;
1480    ConversionStub* _stub;
1481 
1482  public:
1483    LIR_OpConvert(Bytecodes::Code code, LIR_Opr opr, LIR_Opr result, ConversionStub* stub)
1484      : LIR_Op1(lir_convert, opr, result)
1485      , _bytecode(code)
1486      , _stub(stub)                               {}
1487 
1488   Bytecodes::Code bytecode() const               { return _bytecode; }
1489   ConversionStub* stub() const                   { return _stub; }
1490 
1491   virtual void emit_code(LIR_Assembler* masm);
1492   virtual LIR_OpConvert* as_OpConvert() { return this; }
1493   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1494 
1495   static void print_bytecode(outputStream* out, Bytecodes::Code code) PRODUCT_RETURN;
1496 };
1497 
1498 
1499 // LIR_OpAllocObj
1500 class LIR_OpAllocObj : public LIR_Op1 {
1501  friend class LIR_OpVisitState;
1502 
1503  private:
1504   LIR_Opr _tmp1;
1505   LIR_Opr _tmp2;
1506   LIR_Opr _tmp3;
1507   LIR_Opr _tmp4;
1508   int     _hdr_size;
1509   int     _obj_size;
1510   CodeStub* _stub;
1511   bool    _init_check;
1512 
1513  public:
1514   LIR_OpAllocObj(LIR_Opr klass, LIR_Opr result,
1515                  LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4,
1516                  int hdr_size, int obj_size, bool init_check, CodeStub* stub)
1517     : LIR_Op1(lir_alloc_object, klass, result)
1518     , _tmp1(t1)
1519     , _tmp2(t2)
1520     , _tmp3(t3)
1521     , _tmp4(t4)
1522     , _hdr_size(hdr_size)
1523     , _obj_size(obj_size)
1524     , _stub(stub)
1525     , _init_check(init_check)                    { }
1526 
1527   LIR_Opr klass()        const                   { return in_opr();     }
1528   LIR_Opr obj()          const                   { return result_opr(); }
1529   LIR_Opr tmp1()         const                   { return _tmp1;        }
1530   LIR_Opr tmp2()         const                   { return _tmp2;        }
1531   LIR_Opr tmp3()         const                   { return _tmp3;        }
1532   LIR_Opr tmp4()         const                   { return _tmp4;        }
1533   int     header_size()  const                   { return _hdr_size;    }
1534   int     object_size()  const                   { return _obj_size;    }
1535   bool    init_check()   const                   { return _init_check;  }
1536   CodeStub* stub()       const                   { return _stub;        }
1537 
1538   virtual void emit_code(LIR_Assembler* masm);
1539   virtual LIR_OpAllocObj * as_OpAllocObj () { return this; }
1540   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1541 };
1542 
1543 
1544 // LIR_OpRoundFP
1545 class LIR_OpRoundFP : public LIR_Op1 {
1546  friend class LIR_OpVisitState;
1547 
1548  private:
1549   LIR_Opr _tmp;
1550 
1551  public:
1552   LIR_OpRoundFP(LIR_Opr reg, LIR_Opr stack_loc_temp, LIR_Opr result)
1553     : LIR_Op1(lir_roundfp, reg, result)
1554     , _tmp(stack_loc_temp) {}
1555 
1556   LIR_Opr tmp() const                            { return _tmp; }
1557   virtual LIR_OpRoundFP* as_OpRoundFP()          { return this; }
1558   void print_instr(outputStream* out) const PRODUCT_RETURN;
1559 };
1560 
1561 // LIR_OpTypeCheck
1562 class LIR_OpTypeCheck: public LIR_Op {
1563  friend class LIR_OpVisitState;
1564 
1565  private:
1566   LIR_Opr       _object;
1567   LIR_Opr       _array;
1568   ciKlass*      _klass;
1569   LIR_Opr       _tmp1;
1570   LIR_Opr       _tmp2;
1571   LIR_Opr       _tmp3;
1572   CodeEmitInfo* _info_for_patch;
1573   CodeEmitInfo* _info_for_exception;
1574   CodeStub*     _stub;
1575   ciMethod*     _profiled_method;
1576   int           _profiled_bci;
1577   bool          _should_profile;
1578   bool          _fast_check;
1579   bool          _need_null_check;
1580 
1581 public:
1582   LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1583                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1584                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub, bool need_null_check = true);
1585   LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1586                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1587 
1588   LIR_Opr object() const                         { return _object;         }
1589   LIR_Opr array() const                          { assert(code() == lir_store_check, "not valid"); return _array;         }
1590   LIR_Opr tmp1() const                           { return _tmp1;           }
1591   LIR_Opr tmp2() const                           { return _tmp2;           }
1592   LIR_Opr tmp3() const                           { return _tmp3;           }
1593   ciKlass* klass() const                         { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass;          }
1594   bool fast_check() const                        { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check;     }
1595   CodeEmitInfo* info_for_patch() const           { return _info_for_patch;  }
1596   CodeEmitInfo* info_for_exception() const       { return _info_for_exception; }
1597   CodeStub* stub() const                         { return _stub;           }
1598 
1599   // MethodData* profiling
1600   void set_profiled_method(ciMethod *method)     { _profiled_method = method; }
1601   void set_profiled_bci(int bci)                 { _profiled_bci = bci;       }
1602   void set_should_profile(bool b)                { _should_profile = b;       }
1603   ciMethod* profiled_method() const              { return _profiled_method;   }
1604   int       profiled_bci() const                 { return _profiled_bci;      }
1605   bool      should_profile() const               { return _should_profile;    }
1606   bool      need_null_check() const              { return _need_null_check;   }
1607   virtual bool is_patching() { return _info_for_patch != nullptr; }
1608   virtual void emit_code(LIR_Assembler* masm);
1609   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1610   void print_instr(outputStream* out) const PRODUCT_RETURN;
1611 };
1612 
1613 // LIR_OpFlattenedArrayCheck
1614 class LIR_OpFlattenedArrayCheck: public LIR_Op {
1615  friend class LIR_OpVisitState;
1616 
1617  private:
1618   LIR_Opr       _array;
1619   LIR_Opr       _value;
1620   LIR_Opr       _tmp;
1621   CodeStub*     _stub;
1622 public:
1623   LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
1624   LIR_Opr array() const                          { return _array;         }
1625   LIR_Opr value() const                          { return _value;         }
1626   LIR_Opr tmp() const                            { return _tmp;           }
1627   CodeStub* stub() const                         { return _stub;          }
1628 
1629   virtual void emit_code(LIR_Assembler* masm);
1630   virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return this; }
1631   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1632 };
1633 
1634 // LIR_OpNullFreeArrayCheck
1635 class LIR_OpNullFreeArrayCheck: public LIR_Op {
1636  friend class LIR_OpVisitState;
1637 
1638  private:
1639   LIR_Opr       _array;
1640   LIR_Opr       _tmp;
1641 public:
1642   LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp);
1643   LIR_Opr array() const                          { return _array;         }
1644   LIR_Opr tmp() const                            { return _tmp;           }
1645 
1646   virtual void emit_code(LIR_Assembler* masm);
1647   virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return this; }
1648   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1649 };
1650 
1651 class LIR_OpSubstitutabilityCheck: public LIR_Op {
1652  friend class LIR_OpVisitState;
1653 
1654  private:
1655   LIR_Opr       _left;
1656   LIR_Opr       _right;
1657   LIR_Opr       _equal_result;
1658   LIR_Opr       _not_equal_result;
1659   LIR_Opr       _tmp1;
1660   LIR_Opr       _tmp2;
1661   ciKlass*      _left_klass;
1662   ciKlass*      _right_klass;
1663   LIR_Opr       _left_klass_op;
1664   LIR_Opr       _right_klass_op;
1665   CodeStub*     _stub;
1666 public:
1667   LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1668                               LIR_Opr tmp1, LIR_Opr tmp2,
1669                               ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
1670                               CodeEmitInfo* info, CodeStub* stub);
1671 
1672   LIR_Opr left() const             { return _left; }
1673   LIR_Opr right() const            { return _right; }
1674   LIR_Opr equal_result() const     { return _equal_result; }
1675   LIR_Opr not_equal_result() const { return _not_equal_result; }
1676   LIR_Opr tmp1() const             { return _tmp1; }
1677   LIR_Opr tmp2() const             { return _tmp2; }
1678   ciKlass* left_klass() const      { return _left_klass; }
1679   ciKlass* right_klass() const     { return _right_klass; }
1680   LIR_Opr left_klass_op() const    { return _left_klass_op; }
1681   LIR_Opr right_klass_op() const   { return _right_klass_op; }
1682   CodeStub* stub() const           { return _stub; }
1683 
1684   virtual void emit_code(LIR_Assembler* masm);
1685   virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return this; }
1686   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1687 };
1688 
1689 // LIR_Op2
1690 class LIR_Op2: public LIR_Op {
1691  friend class LIR_OpVisitState;
1692 
1693   int  _fpu_stack_size; // for sin/cos implementation on Intel
1694 
1695  protected:
1696   LIR_Opr   _opr1;
1697   LIR_Opr   _opr2;
1698   LIR_Opr   _tmp1;
1699   LIR_Opr   _tmp2;
1700   LIR_Opr   _tmp3;
1701   LIR_Opr   _tmp4;
1702   LIR_Opr   _tmp5;
1703   LIR_Condition _condition;
1704   BasicType _type;
1705 
1706   void verify() const;
1707 
1708  public:
1709   LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1710     : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1711     , _fpu_stack_size(0)
1712     , _opr1(opr1)
1713     , _opr2(opr2)
1714     , _tmp1(LIR_OprFact::illegalOpr)
1715     , _tmp2(LIR_OprFact::illegalOpr)
1716     , _tmp3(LIR_OprFact::illegalOpr)
1717     , _tmp4(LIR_OprFact::illegalOpr)
1718     , _tmp5(LIR_OprFact::illegalOpr)
1719     , _condition(condition)
1720     , _type(type) {
1721     assert(code == lir_cmp || code == lir_branch || code == lir_cond_float_branch || code == lir_assert, "code check");
1722   }
1723 
1724   LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result, BasicType type)
1725     : LIR_Op(code, result, nullptr)
1726     , _fpu_stack_size(0)
1727     , _opr1(opr1)
1728     , _opr2(opr2)
1729     , _tmp1(LIR_OprFact::illegalOpr)
1730     , _tmp2(LIR_OprFact::illegalOpr)
1731     , _tmp3(LIR_OprFact::illegalOpr)
1732     , _tmp4(LIR_OprFact::illegalOpr)
1733     , _tmp5(LIR_OprFact::illegalOpr)
1734     , _condition(condition)
1735     , _type(type) {
1736     assert(code == lir_cmove, "code check");
1737     assert(type != T_ILLEGAL, "cmove should have type");
1738   }
1739 
1740   LIR_Op2(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result = LIR_OprFact::illegalOpr,
1741           CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1742     : LIR_Op(code, result, info)
1743     , _fpu_stack_size(0)
1744     , _opr1(opr1)
1745     , _opr2(opr2)
1746     , _tmp1(LIR_OprFact::illegalOpr)
1747     , _tmp2(LIR_OprFact::illegalOpr)
1748     , _tmp3(LIR_OprFact::illegalOpr)
1749     , _tmp4(LIR_OprFact::illegalOpr)
1750     , _tmp5(LIR_OprFact::illegalOpr)
1751     , _condition(lir_cond_unknown)
1752     , _type(type) {
1753     assert(code != lir_cmp && code != lir_branch && code != lir_cond_float_branch && is_in_range(code, begin_op2, end_op2), "code check");
1754   }
1755 
1756   LIR_Op2(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result, LIR_Opr tmp1, LIR_Opr tmp2 = LIR_OprFact::illegalOpr,
1757           LIR_Opr tmp3 = LIR_OprFact::illegalOpr, LIR_Opr tmp4 = LIR_OprFact::illegalOpr, LIR_Opr tmp5 = LIR_OprFact::illegalOpr)
1758     : LIR_Op(code, result, nullptr)
1759     , _fpu_stack_size(0)
1760     , _opr1(opr1)
1761     , _opr2(opr2)
1762     , _tmp1(tmp1)
1763     , _tmp2(tmp2)
1764     , _tmp3(tmp3)
1765     , _tmp4(tmp4)
1766     , _tmp5(tmp5)
1767     , _condition(lir_cond_unknown)
1768     , _type(T_ILLEGAL)    {
1769     assert(code != lir_cmp && code != lir_branch && code != lir_cond_float_branch && is_in_range(code, begin_op2, end_op2), "code check");
1770   }
1771 
1772   LIR_Opr in_opr1() const                        { return _opr1; }
1773   LIR_Opr in_opr2() const                        { return _opr2; }
1774   BasicType type()  const                        { return _type; }
1775   LIR_Opr tmp1_opr() const                       { return _tmp1; }
1776   LIR_Opr tmp2_opr() const                       { return _tmp2; }
1777   LIR_Opr tmp3_opr() const                       { return _tmp3; }
1778   LIR_Opr tmp4_opr() const                       { return _tmp4; }
1779   LIR_Opr tmp5_opr() const                       { return _tmp5; }
1780   LIR_Condition condition() const  {
1781     assert(code() == lir_cmp || code() == lir_branch || code() == lir_cond_float_branch || code() == lir_assert, "only valid for branch and assert"); return _condition;
1782   }
1783   void set_condition(LIR_Condition condition) {
1784     assert(code() == lir_cmp || code() == lir_branch || code() == lir_cond_float_branch, "only valid for branch"); _condition = condition;
1785   }
1786 
1787   void set_fpu_stack_size(int size)              { _fpu_stack_size = size; }
1788   int  fpu_stack_size() const                    { return _fpu_stack_size; }
1789 
1790   void set_in_opr1(LIR_Opr opr)                  { _opr1 = opr; }
1791   void set_in_opr2(LIR_Opr opr)                  { _opr2 = opr; }
1792 
1793   virtual void emit_code(LIR_Assembler* masm);
1794   virtual LIR_Op2* as_Op2() { return this; }
1795   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1796 };
1797 
1798 class LIR_OpBranch: public LIR_Op2 {
1799  friend class LIR_OpVisitState;
1800 
1801  private:
1802   Label*        _label;
1803   BlockBegin*   _block;  // if this is a branch to a block, this is the block
1804   BlockBegin*   _ublock; // if this is a float-branch, this is the unordered block
1805   CodeStub*     _stub;   // if this is a branch to a stub, this is the stub
1806 
1807  public:
1808   LIR_OpBranch(LIR_Condition cond, Label* lbl)
1809     : LIR_Op2(lir_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*) nullptr)
1810     , _label(lbl)
1811     , _block(nullptr)
1812     , _ublock(nullptr)
1813     , _stub(nullptr) { }
1814 
1815   LIR_OpBranch(LIR_Condition cond, BlockBegin* block);
1816   LIR_OpBranch(LIR_Condition cond, CodeStub* stub);
1817 
1818   // for unordered comparisons
1819   LIR_OpBranch(LIR_Condition cond, BlockBegin* block, BlockBegin* ublock);
1820 
1821   LIR_Condition cond() const {
1822     return condition();
1823   }
1824 
1825   void set_cond(LIR_Condition cond) {
1826     set_condition(cond);
1827   }
1828 
1829   Label*        label()       const              { return _label;       }
1830   BlockBegin*   block()       const              { return _block;       }
1831   BlockBegin*   ublock()      const              { return _ublock;      }
1832   CodeStub*     stub()        const              { return _stub;        }
1833 
1834   void          change_block(BlockBegin* b);
1835   void          change_ublock(BlockBegin* b);
1836   void          negate_cond();
1837 
1838   virtual void emit_code(LIR_Assembler* masm);
1839   virtual LIR_OpBranch* as_OpBranch() { return this; }
1840   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1841 };
1842 
1843 class LIR_OpAllocArray : public LIR_Op {
1844  friend class LIR_OpVisitState;
1845 
1846  private:
1847   LIR_Opr   _klass;
1848   LIR_Opr   _len;
1849   LIR_Opr   _tmp1;
1850   LIR_Opr   _tmp2;
1851   LIR_Opr   _tmp3;
1852   LIR_Opr   _tmp4;
1853   CodeStub* _stub;
1854   BasicType _type;
1855   bool      _zero_array;
1856   bool      _is_null_free;
1857 
1858  public:
1859   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)
1860     : LIR_Op(lir_alloc_array, result, nullptr)
1861     , _klass(klass)
1862     , _len(len)
1863     , _tmp1(t1)
1864     , _tmp2(t2)
1865     , _tmp3(t3)
1866     , _tmp4(t4)
1867     , _stub(stub)
1868     , _type(type)
1869     , _zero_array(zero_array)
1870     , _is_null_free(is_null_free) {}
1871 
1872   LIR_Opr   klass()   const                      { return _klass;       }
1873   LIR_Opr   len()     const                      { return _len;         }
1874   LIR_Opr   obj()     const                      { return result_opr(); }
1875   LIR_Opr   tmp1()    const                      { return _tmp1;        }
1876   LIR_Opr   tmp2()    const                      { return _tmp2;        }
1877   LIR_Opr   tmp3()    const                      { return _tmp3;        }
1878   LIR_Opr   tmp4()    const                      { return _tmp4;        }
1879   BasicType type()    const                      { return _type;        }
1880   CodeStub* stub()    const                      { return _stub;        }
1881   bool      zero_array()   const                 { return _zero_array;  }
1882   bool      is_null_free() const                 { return _is_null_free;}
1883 
1884   virtual void emit_code(LIR_Assembler* masm);
1885   virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1886   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1887 };
1888 
1889 
1890 class LIR_Op3: public LIR_Op {
1891  friend class LIR_OpVisitState;
1892 
1893  private:
1894   LIR_Opr _opr1;
1895   LIR_Opr _opr2;
1896   LIR_Opr _opr3;
1897  public:
1898   LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1899     : LIR_Op(code, result, info)
1900     , _opr1(opr1)
1901     , _opr2(opr2)
1902     , _opr3(opr3)                                { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1903   LIR_Opr in_opr1() const                        { return _opr1; }
1904   LIR_Opr in_opr2() const                        { return _opr2; }
1905   LIR_Opr in_opr3() const                        { return _opr3; }
1906 
1907   virtual void emit_code(LIR_Assembler* masm);
1908   virtual LIR_Op3* as_Op3() { return this; }
1909   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1910 };
1911 
1912 class LIR_Op4: public LIR_Op {
1913   friend class LIR_OpVisitState;
1914  protected:
1915   LIR_Opr   _opr1;
1916   LIR_Opr   _opr2;
1917   LIR_Opr   _opr3;
1918   LIR_Opr   _opr4;
1919   LIR_Opr   _tmp1;
1920   LIR_Opr   _tmp2;
1921   LIR_Opr   _tmp3;
1922   LIR_Opr   _tmp4;
1923   LIR_Opr   _tmp5;
1924   LIR_Condition _condition;
1925   BasicType _type;
1926 
1927  public:
1928   LIR_Op4(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr opr4,
1929           LIR_Opr result, BasicType type)
1930     : LIR_Op(code, result, nullptr)
1931     , _opr1(opr1)
1932     , _opr2(opr2)
1933     , _opr3(opr3)
1934     , _opr4(opr4)
1935     , _tmp1(LIR_OprFact::illegalOpr)
1936     , _tmp2(LIR_OprFact::illegalOpr)
1937     , _tmp3(LIR_OprFact::illegalOpr)
1938     , _tmp4(LIR_OprFact::illegalOpr)
1939     , _tmp5(LIR_OprFact::illegalOpr)
1940     , _condition(condition)
1941     , _type(type) {
1942     assert(code == lir_cmove, "code check");
1943     assert(type != T_ILLEGAL, "cmove should have type");
1944   }
1945 
1946   LIR_Opr in_opr1() const                        { return _opr1; }
1947   LIR_Opr in_opr2() const                        { return _opr2; }
1948   LIR_Opr in_opr3() const                        { return _opr3; }
1949   LIR_Opr in_opr4() const                        { return _opr4; }
1950   BasicType type()  const                        { return _type; }
1951   LIR_Opr tmp1_opr() const                       { return _tmp1; }
1952   LIR_Opr tmp2_opr() const                       { return _tmp2; }
1953   LIR_Opr tmp3_opr() const                       { return _tmp3; }
1954   LIR_Opr tmp4_opr() const                       { return _tmp4; }
1955   LIR_Opr tmp5_opr() const                       { return _tmp5; }
1956 
1957   LIR_Condition condition() const                { return _condition; }
1958   void set_condition(LIR_Condition condition)    { _condition = condition; }
1959 
1960   void set_in_opr1(LIR_Opr opr)                  { _opr1 = opr; }
1961   void set_in_opr2(LIR_Opr opr)                  { _opr2 = opr; }
1962   void set_in_opr3(LIR_Opr opr)                  { _opr3 = opr; }
1963   void set_in_opr4(LIR_Opr opr)                  { _opr4 = opr; }
1964   virtual void emit_code(LIR_Assembler* masm);
1965   virtual LIR_Op4* as_Op4() { return this; }
1966 
1967   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1968 };
1969 
1970 //--------------------------------
1971 class LabelObj: public CompilationResourceObj {
1972  private:
1973   Label _label;
1974  public:
1975   LabelObj()                                     {}
1976   Label* label()                                 { return &_label; }
1977 };
1978 
1979 
1980 class LIR_OpLock: public LIR_Op {
1981  friend class LIR_OpVisitState;
1982 
1983  private:
1984   LIR_Opr _hdr;
1985   LIR_Opr _obj;
1986   LIR_Opr _lock;
1987   LIR_Opr _scratch;
1988   CodeStub* _stub;
1989   CodeStub* _throw_ie_stub;
1990  public:
1991   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)
1992     : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1993     , _hdr(hdr)
1994     , _obj(obj)
1995     , _lock(lock)
1996     , _scratch(scratch)
1997     , _stub(stub)
1998     , _throw_ie_stub(throw_ie_stub)                    {}
1999 
2000   LIR_Opr hdr_opr() const                        { return _hdr; }
2001   LIR_Opr obj_opr() const                        { return _obj; }
2002   LIR_Opr lock_opr() const                       { return _lock; }
2003   LIR_Opr scratch_opr() const                    { return _scratch; }
2004   CodeStub* stub() const                         { return _stub; }
2005   CodeStub* throw_ie_stub() const                { return _throw_ie_stub; }
2006 
2007   virtual void emit_code(LIR_Assembler* masm);
2008   virtual LIR_OpLock* as_OpLock() { return this; }
2009   void print_instr(outputStream* out) const PRODUCT_RETURN;
2010 };
2011 
2012 class LIR_OpLoadKlass: public LIR_Op {
2013   friend class LIR_OpVisitState;
2014 
2015  private:
2016   LIR_Opr _obj;
2017  public:
2018   LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
2019     : LIR_Op(lir_load_klass, result, info)
2020     , _obj(obj)
2021     {}
2022 
2023   LIR_Opr obj()        const { return _obj;  }
2024 
2025   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }
2026   virtual void emit_code(LIR_Assembler* masm);
2027   void print_instr(outputStream* out) const PRODUCT_RETURN;
2028 };
2029 
2030 class LIR_OpDelay: public LIR_Op {
2031  friend class LIR_OpVisitState;
2032 
2033  private:
2034   LIR_Op* _op;
2035 
2036  public:
2037   LIR_OpDelay(LIR_Op* op, CodeEmitInfo* info):
2038     LIR_Op(lir_delay_slot, LIR_OprFact::illegalOpr, info),
2039     _op(op) {
2040     assert(op->code() == lir_nop, "should be filling with nops");
2041   }
2042   virtual void emit_code(LIR_Assembler* masm);
2043   virtual LIR_OpDelay* as_OpDelay() { return this; }
2044   void print_instr(outputStream* out) const PRODUCT_RETURN;
2045   LIR_Op* delay_op() const { return _op; }
2046   CodeEmitInfo* call_info() const { return info(); }
2047 };
2048 
2049 #ifdef ASSERT
2050 // LIR_OpAssert
2051 class LIR_OpAssert : public LIR_Op2 {
2052  friend class LIR_OpVisitState;
2053 
2054  private:
2055   const char* _msg;
2056   bool        _halt;
2057 
2058  public:
2059   LIR_OpAssert(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, const char* msg, bool halt)
2060     : LIR_Op2(lir_assert, condition, opr1, opr2)
2061     , _msg(msg)
2062     , _halt(halt) {
2063   }
2064 
2065   const char* msg() const                        { return _msg; }
2066   bool        halt() const                       { return _halt; }
2067 
2068   virtual void emit_code(LIR_Assembler* masm);
2069   virtual LIR_OpAssert* as_OpAssert()            { return this; }
2070   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2071 };
2072 #endif
2073 
2074 // LIR_OpCompareAndSwap
2075 class LIR_OpCompareAndSwap : public LIR_Op {
2076  friend class LIR_OpVisitState;
2077 
2078  private:
2079   LIR_Opr _addr;
2080   LIR_Opr _cmp_value;
2081   LIR_Opr _new_value;
2082   LIR_Opr _tmp1;
2083   LIR_Opr _tmp2;
2084 
2085  public:
2086   LIR_OpCompareAndSwap(LIR_Code code, LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2087                        LIR_Opr t1, LIR_Opr t2, LIR_Opr result)
2088     : LIR_Op(code, result, nullptr)  // no result, no info
2089     , _addr(addr)
2090     , _cmp_value(cmp_value)
2091     , _new_value(new_value)
2092     , _tmp1(t1)
2093     , _tmp2(t2)                                  { }
2094 
2095   LIR_Opr addr()        const                    { return _addr;  }
2096   LIR_Opr cmp_value()   const                    { return _cmp_value; }
2097   LIR_Opr new_value()   const                    { return _new_value; }
2098   LIR_Opr tmp1()        const                    { return _tmp1;      }
2099   LIR_Opr tmp2()        const                    { return _tmp2;      }
2100 
2101   virtual void emit_code(LIR_Assembler* masm);
2102   virtual LIR_OpCompareAndSwap * as_OpCompareAndSwap () { return this; }
2103   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2104 };
2105 
2106 // LIR_OpProfileCall
2107 class LIR_OpProfileCall : public LIR_Op {
2108  friend class LIR_OpVisitState;
2109 
2110  private:
2111   ciMethod* _profiled_method;
2112   int       _profiled_bci;
2113   ciMethod* _profiled_callee;
2114   LIR_Opr   _mdo;
2115   LIR_Opr   _recv;
2116   LIR_Opr   _tmp1;
2117   ciKlass*  _known_holder;
2118 
2119  public:
2120   // Destroys recv
2121   LIR_OpProfileCall(ciMethod* profiled_method, int profiled_bci, ciMethod* profiled_callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* known_holder)
2122     : LIR_Op(lir_profile_call, LIR_OprFact::illegalOpr, nullptr)  // no result, no info
2123     , _profiled_method(profiled_method)
2124     , _profiled_bci(profiled_bci)
2125     , _profiled_callee(profiled_callee)
2126     , _mdo(mdo)
2127     , _recv(recv)
2128     , _tmp1(t1)
2129     , _known_holder(known_holder)                { }
2130 
2131   ciMethod* profiled_method() const              { return _profiled_method;  }
2132   int       profiled_bci()    const              { return _profiled_bci;     }
2133   ciMethod* profiled_callee() const              { return _profiled_callee;  }
2134   LIR_Opr   mdo()             const              { return _mdo;              }
2135   LIR_Opr   recv()            const              { return _recv;             }
2136   LIR_Opr   tmp1()            const              { return _tmp1;             }
2137   ciKlass*  known_holder()    const              { return _known_holder;     }
2138 
2139   virtual void emit_code(LIR_Assembler* masm);
2140   virtual LIR_OpProfileCall* as_OpProfileCall() { return this; }
2141   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2142   bool should_profile_receiver_type() const {
2143     bool callee_is_static = _profiled_callee->is_loaded() && _profiled_callee->is_static();
2144     bool callee_is_private = _profiled_callee->is_loaded() && _profiled_callee->is_private();
2145     Bytecodes::Code bc = _profiled_method->java_code_at_bci(_profiled_bci);
2146     bool call_is_virtual = (bc == Bytecodes::_invokevirtual && !callee_is_private) || bc == Bytecodes::_invokeinterface;
2147     return C1ProfileVirtualCalls && call_is_virtual && !callee_is_static;
2148   }
2149 };
2150 
2151 // LIR_OpProfileType
2152 class LIR_OpProfileType : public LIR_Op {
2153  friend class LIR_OpVisitState;
2154 
2155  private:
2156   LIR_Opr      _mdp;
2157   LIR_Opr      _obj;
2158   LIR_Opr      _tmp;
2159   ciKlass*     _exact_klass;   // non null if we know the klass statically (no need to load it from _obj)
2160   intptr_t     _current_klass; // what the profiling currently reports
2161   bool         _not_null;      // true if we know statically that _obj cannot be null
2162   bool         _no_conflict;   // true if we're profling parameters, _exact_klass is not null and we know
2163                                // _exact_klass it the only possible type for this parameter in any context.
2164 
2165  public:
2166   // Destroys recv
2167   LIR_OpProfileType(LIR_Opr mdp, LIR_Opr obj, ciKlass* exact_klass, intptr_t current_klass, LIR_Opr tmp, bool not_null, bool no_conflict)
2168     : LIR_Op(lir_profile_type, LIR_OprFact::illegalOpr, nullptr)  // no result, no info
2169     , _mdp(mdp)
2170     , _obj(obj)
2171     , _tmp(tmp)
2172     , _exact_klass(exact_klass)
2173     , _current_klass(current_klass)
2174     , _not_null(not_null)
2175     , _no_conflict(no_conflict) { }
2176 
2177   LIR_Opr      mdp()              const             { return _mdp;              }
2178   LIR_Opr      obj()              const             { return _obj;              }
2179   LIR_Opr      tmp()              const             { return _tmp;              }
2180   ciKlass*     exact_klass()      const             { return _exact_klass;      }
2181   intptr_t     current_klass()    const             { return _current_klass;    }
2182   bool         not_null()         const             { return _not_null;         }
2183   bool         no_conflict()      const             { return _no_conflict;      }
2184 
2185   virtual void emit_code(LIR_Assembler* masm);
2186   virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2187   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2188 };
2189 
2190 // LIR_OpProfileInlineType
2191 class LIR_OpProfileInlineType : public LIR_Op {
2192  friend class LIR_OpVisitState;
2193 
2194  private:
2195   LIR_Opr      _mdp;
2196   LIR_Opr      _obj;
2197   int          _flag;
2198   LIR_Opr      _tmp;
2199   bool         _not_null;      // true if we know statically that _obj cannot be null
2200 
2201  public:
2202   // Destroys recv
2203   LIR_OpProfileInlineType(LIR_Opr mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null)
2204     : LIR_Op(lir_profile_inline_type, LIR_OprFact::illegalOpr, nullptr)  // no result, no info
2205     , _mdp(mdp)
2206     , _obj(obj)
2207     , _flag(flag)
2208     , _tmp(tmp)
2209     , _not_null(not_null) { }
2210 
2211   LIR_Opr      mdp()              const             { return _mdp;              }
2212   LIR_Opr      obj()              const             { return _obj;              }
2213   int          flag()             const             { return _flag;             }
2214   LIR_Opr      tmp()              const             { return _tmp;              }
2215   bool         not_null()         const             { return _not_null;         }
2216 
2217   virtual void emit_code(LIR_Assembler* masm);
2218   virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return this; }
2219   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2220 };
2221 
2222 class LIR_InsertionBuffer;
2223 
2224 //--------------------------------LIR_List---------------------------------------------------
2225 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2226 // The LIR instructions are appended by the LIR_List class itself;
2227 //
2228 // Notes:
2229 // - all offsets are(should be) in bytes
2230 // - local positions are specified with an offset, with offset 0 being local 0
2231 
2232 class LIR_List: public CompilationResourceObj {
2233  private:
2234   LIR_OpList  _operations;
2235 
2236   Compilation*  _compilation;
2237 #ifndef PRODUCT
2238   BlockBegin*   _block;
2239 #endif
2240 #ifdef ASSERT
2241   const char *  _file;
2242   int           _line;
2243 #endif
2244 #ifdef RISCV
2245   LIR_Opr       _cmp_opr1;
2246   LIR_Opr       _cmp_opr2;
2247 #endif
2248 
2249  public:
2250   void append(LIR_Op* op) {
2251     if (op->source() == nullptr)
2252       op->set_source(_compilation->current_instruction());
2253 #ifndef PRODUCT
2254     if (PrintIRWithLIR) {
2255       _compilation->maybe_print_current_instruction();
2256       op->print(); tty->cr();
2257     }
2258 #endif // PRODUCT
2259 
2260 #ifdef RISCV
2261     set_cmp_oprs(op);
2262     // lir_cmp set cmp oprs only on riscv
2263     if (op->code() == lir_cmp) return;
2264 #endif
2265 
2266     _operations.append(op);
2267 
2268 #ifdef ASSERT
2269     op->verify();
2270     op->set_file_and_line(_file, _line);
2271     _file = nullptr;
2272     _line = 0;
2273 #endif
2274   }
2275 
2276   LIR_List(Compilation* compilation, BlockBegin* block = nullptr);
2277 
2278 #ifdef ASSERT
2279   void set_file_and_line(const char * file, int line);
2280 #endif
2281 
2282 #ifdef RISCV
2283   void set_cmp_oprs(LIR_Op* op);
2284 #endif
2285 
2286   //---------- accessors ---------------
2287   LIR_OpList* instructions_list()                { return &_operations; }
2288   int         length() const                     { return _operations.length(); }
2289   LIR_Op*     at(int i) const                    { return _operations.at(i); }
2290 
2291   NOT_PRODUCT(BlockBegin* block() const          { return _block; });
2292 
2293   // insert LIR_Ops in buffer to right places in LIR_List
2294   void append(LIR_InsertionBuffer* buffer);
2295 
2296   //---------- mutators ---------------
2297   void insert_before(int i, LIR_List* op_list)   { _operations.insert_before(i, op_list->instructions_list()); }
2298   void insert_before(int i, LIR_Op* op)          { _operations.insert_before(i, op); }
2299   void remove_at(int i)                          { _operations.remove_at(i); }
2300 
2301   //---------- printing -------------
2302   void print_instructions() PRODUCT_RETURN;
2303 
2304 
2305   //---------- instructions -------------
2306   void call_opt_virtual(ciMethod* method, LIR_Opr receiver, LIR_Opr result,
2307                         address dest, LIR_OprList* arguments,
2308                         CodeEmitInfo* info) {
2309     append(new LIR_OpJavaCall(lir_optvirtual_call, method, receiver, result, dest, arguments, info));
2310   }
2311   void call_static(ciMethod* method, LIR_Opr result,
2312                    address dest, LIR_OprList* arguments, CodeEmitInfo* info) {
2313     append(new LIR_OpJavaCall(lir_static_call, method, LIR_OprFact::illegalOpr, result, dest, arguments, info));
2314   }
2315   void call_icvirtual(ciMethod* method, LIR_Opr receiver, LIR_Opr result,
2316                       address dest, LIR_OprList* arguments, CodeEmitInfo* info) {
2317     append(new LIR_OpJavaCall(lir_icvirtual_call, method, receiver, result, dest, arguments, info));
2318   }
2319   void call_dynamic(ciMethod* method, LIR_Opr receiver, LIR_Opr result,
2320                     address dest, LIR_OprList* arguments, CodeEmitInfo* info) {
2321     append(new LIR_OpJavaCall(lir_dynamic_call, method, receiver, result, dest, arguments, info));
2322   }
2323 
2324   void get_thread(LIR_Opr result)                { append(new LIR_Op0(lir_get_thread, result)); }
2325   void membar()                                  { append(new LIR_Op0(lir_membar)); }
2326   void membar_acquire()                          { append(new LIR_Op0(lir_membar_acquire)); }
2327   void membar_release()                          { append(new LIR_Op0(lir_membar_release)); }
2328   void membar_loadload()                         { append(new LIR_Op0(lir_membar_loadload)); }
2329   void membar_storestore()                       { append(new LIR_Op0(lir_membar_storestore)); }
2330   void membar_loadstore()                        { append(new LIR_Op0(lir_membar_loadstore)); }
2331   void membar_storeload()                        { append(new LIR_Op0(lir_membar_storeload)); }
2332 
2333   void nop()                                     { append(new LIR_Op0(lir_nop)); }
2334 
2335   void std_entry(LIR_Opr receiver)               { append(new LIR_Op0(lir_std_entry, receiver)); }
2336   void osr_entry(LIR_Opr osrPointer)             { append(new LIR_Op0(lir_osr_entry, osrPointer)); }
2337 
2338   void on_spin_wait()                            { append(new LIR_Op0(lir_on_spin_wait)); }
2339 
2340   void branch_destination(Label* lbl)            { append(new LIR_OpLabel(lbl)); }
2341 
2342   void leal(LIR_Opr from, LIR_Opr result_reg, LIR_PatchCode patch_code = lir_patch_none, CodeEmitInfo* info = nullptr) { append(new LIR_Op1(lir_leal, from, result_reg, T_ILLEGAL, patch_code, info)); }
2343 
2344   // result is a stack location for old backend and vreg for UseLinearScan
2345   // stack_loc_temp is an illegal register for old backend
2346   void roundfp(LIR_Opr reg, LIR_Opr stack_loc_temp, LIR_Opr result) { append(new LIR_OpRoundFP(reg, stack_loc_temp, result)); }
2347   void move(LIR_Opr src, LIR_Opr dst, CodeEmitInfo* info = nullptr) { append(new LIR_Op1(lir_move, src, dst, dst->type(), lir_patch_none, info)); }
2348   void move(LIR_Address* src, LIR_Opr dst, CodeEmitInfo* info = nullptr) { append(new LIR_Op1(lir_move, LIR_OprFact::address(src), dst, src->type(), lir_patch_none, info)); }
2349   void move(LIR_Opr src, LIR_Address* dst, CodeEmitInfo* info = nullptr) { append(new LIR_Op1(lir_move, src, LIR_OprFact::address(dst), dst->type(), lir_patch_none, info)); }
2350   void move_wide(LIR_Address* src, LIR_Opr dst, CodeEmitInfo* info = nullptr) {
2351     if (UseCompressedOops) {
2352       append(new LIR_Op1(lir_move, LIR_OprFact::address(src), dst, src->type(), lir_patch_none, info, lir_move_wide));
2353     } else {
2354       move(src, dst, info);
2355     }
2356   }
2357   void move_wide(LIR_Opr src, LIR_Address* dst, CodeEmitInfo* info = nullptr) {
2358     if (UseCompressedOops) {
2359       append(new LIR_Op1(lir_move, src, LIR_OprFact::address(dst), dst->type(), lir_patch_none, info, lir_move_wide));
2360     } else {
2361       move(src, dst, info);
2362     }
2363   }
2364   void volatile_move(LIR_Opr src, LIR_Opr dst, BasicType type, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none) { append(new LIR_Op1(lir_move, src, dst, type, patch_code, info, lir_move_volatile)); }
2365 
2366   void oop2reg  (jobject o, LIR_Opr reg)         { assert(reg->type() == T_OBJECT, "bad reg"); append(new LIR_Op1(lir_move, LIR_OprFact::oopConst(o),    reg));   }
2367   void oop2reg_patch(jobject o, LIR_Opr reg, CodeEmitInfo* info);
2368 
2369   void metadata2reg  (Metadata* o, LIR_Opr reg)  { assert(reg->type() == T_METADATA, "bad reg"); append(new LIR_Op1(lir_move, LIR_OprFact::metadataConst(o), reg));   }
2370   void klass2reg_patch(Metadata* o, LIR_Opr reg, CodeEmitInfo* info);
2371 
2372   void safepoint(LIR_Opr tmp, CodeEmitInfo* info)  { append(new LIR_Op1(lir_safepoint, tmp, info)); }
2373   void return_op(LIR_Opr result)                   { append(new LIR_OpReturn(result)); }
2374 
2375   void convert(Bytecodes::Code code, LIR_Opr left, LIR_Opr dst, ConversionStub* stub = nullptr/*, bool is_32bit = false*/) { append(new LIR_OpConvert(code, left, dst, stub)); }
2376 
2377   void logical_and (LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_logic_and,  left, right, dst)); }
2378   void logical_or  (LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_logic_or,   left, right, dst)); }
2379   void logical_xor (LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_logic_xor,  left, right, dst)); }
2380 
2381   void null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null = false);
2382   void throw_exception(LIR_Opr exceptionPC, LIR_Opr exceptionOop, CodeEmitInfo* info) {
2383     append(new LIR_Op2(lir_throw, exceptionPC, exceptionOop, LIR_OprFact::illegalOpr, info));
2384   }
2385   void unwind_exception(LIR_Opr exceptionOop) {
2386     append(new LIR_Op1(lir_unwind, exceptionOop));
2387   }
2388 
2389   void push(LIR_Opr opr)                                   { append(new LIR_Op1(lir_push, opr)); }
2390   void pop(LIR_Opr reg)                                    { append(new LIR_Op1(lir_pop,  reg)); }
2391 
2392   void cmp(LIR_Condition condition, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = nullptr) {
2393     append(new LIR_Op2(lir_cmp, condition, left, right, info));
2394   }
2395   void cmp(LIR_Condition condition, LIR_Opr left, int right, CodeEmitInfo* info = nullptr) {
2396     cmp(condition, left, LIR_OprFact::intConst(right), info);
2397   }
2398 
2399   void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
2400   void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Address* addr, CodeEmitInfo* info);
2401 
2402   void cmove(LIR_Condition condition, LIR_Opr src1, LIR_Opr src2, LIR_Opr dst, BasicType type,
2403              LIR_Opr cmp_opr1 = LIR_OprFact::illegalOpr, LIR_Opr cmp_opr2 = LIR_OprFact::illegalOpr) {
2404     append(new LIR_Op4(lir_cmove, condition, src1, src2, cmp_opr1, cmp_opr2, dst, type));
2405   }
2406 
2407   void cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2408                 LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2409   void cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2410                LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2411   void cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2412                LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2413 
2414   void abs (LIR_Opr from, LIR_Opr to, LIR_Opr tmp)                { append(new LIR_Op2(lir_abs , from, tmp, to)); }
2415   void negate(LIR_Opr from, LIR_Opr to, LIR_Opr tmp = LIR_OprFact::illegalOpr)              { append(new LIR_Op2(lir_neg, from, tmp, to)); }
2416   void sqrt(LIR_Opr from, LIR_Opr to, LIR_Opr tmp)                { append(new LIR_Op2(lir_sqrt, from, tmp, to)); }
2417   void fmad(LIR_Opr from, LIR_Opr from1, LIR_Opr from2, LIR_Opr to) { append(new LIR_Op3(lir_fmad, from, from1, from2, to)); }
2418   void fmaf(LIR_Opr from, LIR_Opr from1, LIR_Opr from2, LIR_Opr to) { append(new LIR_Op3(lir_fmaf, from, from1, from2, to)); }
2419   void log10 (LIR_Opr from, LIR_Opr to, LIR_Opr tmp)              { append(new LIR_Op2(lir_log10, from, LIR_OprFact::illegalOpr, to, tmp)); }
2420   void tan (LIR_Opr from, LIR_Opr to, LIR_Opr tmp1, LIR_Opr tmp2) { append(new LIR_Op2(lir_tan , from, tmp1, to, tmp2)); }
2421   void f2hf(LIR_Opr from, LIR_Opr to, LIR_Opr tmp)                { append(new LIR_Op2(lir_f2hf, from, tmp, to)); }
2422   void hf2f(LIR_Opr from, LIR_Opr to, LIR_Opr tmp)                { append(new LIR_Op2(lir_hf2f, from, tmp, to)); }
2423 
2424   void add (LIR_Opr left, LIR_Opr right, LIR_Opr res)      { append(new LIR_Op2(lir_add, left, right, res)); }
2425   void sub (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr) { append(new LIR_Op2(lir_sub, left, right, res, info)); }
2426   void mul (LIR_Opr left, LIR_Opr right, LIR_Opr res) { append(new LIR_Op2(lir_mul, left, right, res)); }
2427   void mul (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_mul, left, right, res, tmp)); }
2428   void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr)      { append(new LIR_Op2(lir_div, left, right, res, info)); }
2429   void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2430   void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr)      { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2431 
2432   void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2433   void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2434 
2435   void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2436 
2437   void store_mem_int(jint v,    LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2438   void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2439   void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2440   void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2441   void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2442 
2443   void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2444   void idiv(LIR_Opr left, int   right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2445   void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2446   void irem(LIR_Opr left, int   right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2447 
2448   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);
2449   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);
2450 
2451   // jump is an unconditional branch
2452   void jump(BlockBegin* block) {
2453     append(new LIR_OpBranch(lir_cond_always, block));
2454   }
2455   void jump(CodeStub* stub) {
2456     append(new LIR_OpBranch(lir_cond_always, stub));
2457   }
2458   void branch(LIR_Condition cond, Label* lbl) {
2459     append(new LIR_OpBranch(cond, lbl));
2460   }
2461   // Should not be used for fp comparisons
2462   void branch(LIR_Condition cond, BlockBegin* block) {
2463     append(new LIR_OpBranch(cond, block));
2464   }
2465   // Should not be used for fp comparisons
2466   void branch(LIR_Condition cond, CodeStub* stub) {
2467     append(new LIR_OpBranch(cond, stub));
2468   }
2469   // Should only be used for fp comparisons
2470   void branch(LIR_Condition cond, BlockBegin* block, BlockBegin* unordered) {
2471     append(new LIR_OpBranch(cond, block, unordered));
2472   }
2473 
2474   void shift_left(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2475   void shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2476   void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2477 
2478   void shift_left(LIR_Opr value, int count, LIR_Opr dst)       { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2479   void shift_right(LIR_Opr value, int count, LIR_Opr dst)      { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2480   void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2481 
2482   void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst)        { append(new LIR_Op2(lir_cmp_l2i,  left, right, dst)); }
2483   void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2484 
2485   void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2486     append(new LIR_OpRTCall(routine, tmp, result, arguments));
2487   }
2488 
2489   void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2490                     LIR_OprList* arguments, CodeEmitInfo* info) {
2491     append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2492   }
2493 
2494   void load_stack_address_monitor(int monitor_ix, LIR_Opr dst)  { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2495   void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2496   void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub=nullptr);
2497 
2498   void breakpoint()                                                  { append(new LIR_Op0(lir_breakpoint)); }
2499 
2500   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)); }
2501 
2502   void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res)  { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2503 
2504   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);
2505   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);
2506   void check_flat_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
2507   void check_null_free_array(LIR_Opr array, LIR_Opr tmp);
2508   void substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
2509                               LIR_Opr tmp1, LIR_Opr tmp2,
2510                               ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
2511                               CodeEmitInfo* info, CodeStub* stub);
2512 
2513   void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2514                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2515                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2516                   ciMethod* profiled_method, int profiled_bci, bool is_null_free);
2517   // MethodData* profiling
2518   void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2519     append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2520   }
2521   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) {
2522     append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2523   }
2524   void profile_inline_type(LIR_Address* mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null) {
2525     append(new LIR_OpProfileInlineType(LIR_OprFact::address(mdp), obj, flag, tmp, not_null));
2526   }
2527 
2528   void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2529   void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2530 
2531   void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2532 
2533 #ifdef ASSERT
2534   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)); }
2535 #endif
2536 };
2537 
2538 void print_LIR(BlockList* blocks);
2539 
2540 class LIR_InsertionBuffer : public CompilationResourceObj {
2541  private:
2542   LIR_List*   _lir;   // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2543 
2544   // list of insertion points. index and count are stored alternately:
2545   // _index_and_count[i * 2]:     the index into lir list where "count" ops should be inserted
2546   // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
2547   intStack    _index_and_count;
2548 
2549   // the LIR_Ops to be inserted
2550   LIR_OpList  _ops;
2551 
2552   void append_new(int index, int count)  { _index_and_count.append(index); _index_and_count.append(count); }
2553   void set_index_at(int i, int value)    { _index_and_count.at_put((i << 1),     value); }
2554   void set_count_at(int i, int value)    { _index_and_count.at_put((i << 1) + 1, value); }
2555 
2556 #ifdef ASSERT
2557   void verify();
2558 #endif
2559  public:
2560   LIR_InsertionBuffer() : _lir(nullptr), _index_and_count(8), _ops(8) { }
2561 
2562   // must be called before using the insertion buffer
2563   void init(LIR_List* lir)  { assert(!initialized(), "already initialized"); _lir = lir; _index_and_count.clear(); _ops.clear(); }
2564   bool initialized() const  { return _lir != nullptr; }
2565   // called automatically when the buffer is appended to the LIR_List
2566   void finish()             { _lir = nullptr; }
2567 
2568   // accessors
2569   LIR_List*  lir_list() const             { return _lir; }
2570   int number_of_insertion_points() const  { return _index_and_count.length() >> 1; }
2571   int index_at(int i) const               { return _index_and_count.at((i << 1));     }
2572   int count_at(int i) const               { return _index_and_count.at((i << 1) + 1); }
2573 
2574   int number_of_ops() const               { return _ops.length(); }
2575   LIR_Op* op_at(int i) const              { return _ops.at(i); }
2576 
2577   // append an instruction to the buffer
2578   void append(int index, LIR_Op* op);
2579 
2580   // instruction
2581   void move(int index, LIR_Opr src, LIR_Opr dst, CodeEmitInfo* info = nullptr) { append(index, new LIR_Op1(lir_move, src, dst, dst->type(), lir_patch_none, info)); }
2582 };
2583 
2584 
2585 //
2586 // LIR_OpVisitState is used for manipulating LIR_Ops in an abstract way.
2587 // Calling a LIR_Op's visit function with a LIR_OpVisitState causes
2588 // information about the input, output and temporaries used by the
2589 // op to be recorded.  It also records whether the op has call semantics
2590 // and also records all the CodeEmitInfos used by this op.
2591 //
2592 
2593 
2594 class LIR_OpVisitState: public StackObj {
2595  public:
2596   typedef enum { inputMode, firstMode = inputMode, tempMode, outputMode, numModes, invalidMode = -1 } OprMode;
2597 
2598   enum {
2599     maxNumberOfOperands = 21,
2600     maxNumberOfInfos = 4
2601   };
2602 
2603  private:
2604   LIR_Op*          _op;
2605 
2606   // optimization: the operands and infos are not stored in a variable-length
2607   //               list, but in a fixed-size array to save time of size checks and resizing
2608   int              _oprs_len[numModes];
2609   LIR_Opr*         _oprs_new[numModes][maxNumberOfOperands];
2610   int _info_len;
2611   CodeEmitInfo*    _info_new[maxNumberOfInfos];
2612 
2613   bool             _has_call;
2614   bool             _has_slow_case;
2615 
2616 
2617   // only include register operands
2618   // addresses are decomposed to the base and index registers
2619   // constants and stack operands are ignored
2620   void append(LIR_Opr& opr, OprMode mode) {
2621     assert(opr->is_valid(), "should not call this otherwise");
2622     assert(mode >= 0 && mode < numModes, "bad mode");
2623 
2624     if (opr->is_register()) {
2625        assert(_oprs_len[mode] < maxNumberOfOperands, "array overflow");
2626       _oprs_new[mode][_oprs_len[mode]++] = &opr;
2627 
2628     } else if (opr->is_pointer()) {
2629       LIR_Address* address = opr->as_address_ptr();
2630       if (address != nullptr) {
2631         // special handling for addresses: add base and index register of the address
2632         // both are always input operands or temp if we want to extend
2633         // their liveness!
2634         if (mode == outputMode) {
2635           mode = inputMode;
2636         }
2637         assert (mode == inputMode || mode == tempMode, "input or temp only for addresses");
2638         if (address->_base->is_valid()) {
2639           assert(address->_base->is_register(), "must be");
2640           assert(_oprs_len[mode] < maxNumberOfOperands, "array overflow");
2641           _oprs_new[mode][_oprs_len[mode]++] = &address->_base;
2642         }
2643         if (address->_index->is_valid()) {
2644           assert(address->_index->is_register(), "must be");
2645           assert(_oprs_len[mode] < maxNumberOfOperands, "array overflow");
2646           _oprs_new[mode][_oprs_len[mode]++] = &address->_index;
2647         }
2648 
2649       } else {
2650         assert(opr->is_constant(), "constant operands are not processed");
2651       }
2652     } else {
2653       assert(opr->is_stack(), "stack operands are not processed");
2654     }
2655   }
2656 
2657   void append(CodeEmitInfo* info) {
2658     assert(info != nullptr, "should not call this otherwise");
2659     assert(_info_len < maxNumberOfInfos, "array overflow");
2660     _info_new[_info_len++] = info;
2661   }
2662 
2663  public:
2664   LIR_OpVisitState()         { reset(); }
2665 
2666   LIR_Op* op() const         { return _op; }
2667   void set_op(LIR_Op* op)    { reset(); _op = op; }
2668 
2669   bool has_call() const      { return _has_call; }
2670   bool has_slow_case() const { return _has_slow_case; }
2671 
2672   void reset() {
2673     _op = nullptr;
2674     _has_call = false;
2675     _has_slow_case = false;
2676 
2677     _oprs_len[inputMode] = 0;
2678     _oprs_len[tempMode] = 0;
2679     _oprs_len[outputMode] = 0;
2680     _info_len = 0;
2681   }
2682 
2683 
2684   int opr_count(OprMode mode) const {
2685     assert(mode >= 0 && mode < numModes, "bad mode");
2686     return _oprs_len[mode];
2687   }
2688 
2689   LIR_Opr opr_at(OprMode mode, int index) const {
2690     assert(mode >= 0 && mode < numModes, "bad mode");
2691     assert(index >= 0 && index < _oprs_len[mode], "index out of bound");
2692     return *_oprs_new[mode][index];
2693   }
2694 
2695   void set_opr_at(OprMode mode, int index, LIR_Opr opr) const {
2696     assert(mode >= 0 && mode < numModes, "bad mode");
2697     assert(index >= 0 && index < _oprs_len[mode], "index out of bound");
2698     *_oprs_new[mode][index] = opr;
2699   }
2700 
2701   int info_count() const {
2702     return _info_len;
2703   }
2704 
2705   CodeEmitInfo* info_at(int index) const {
2706     assert(index < _info_len, "index out of bounds");
2707     return _info_new[index];
2708   }
2709 
2710   XHandlers* all_xhandler();
2711 
2712   // collects all register operands of the instruction
2713   void visit(LIR_Op* op);
2714 
2715 #ifdef ASSERT
2716   // check that an operation has no operands
2717   bool no_operands(LIR_Op* op);
2718 #endif
2719 
2720   // LIR_Op visitor functions use these to fill in the state
2721   void do_input(LIR_Opr& opr)             { append(opr, LIR_OpVisitState::inputMode); }
2722   void do_output(LIR_Opr& opr)            { append(opr, LIR_OpVisitState::outputMode); }
2723   void do_temp(LIR_Opr& opr)              { append(opr, LIR_OpVisitState::tempMode); }
2724   void do_info(CodeEmitInfo* info)        { append(info); }
2725 
2726   void do_stub(CodeStub* stub);
2727   void do_call()                          { _has_call = true; }
2728   void do_slow_case()                     { _has_slow_case = true; }
2729   void do_slow_case(CodeEmitInfo* info) {
2730     _has_slow_case = true;
2731     append(info);
2732   }
2733 };
2734 
2735 
2736 inline LIR_Opr LIR_Opr::illegalOpr()   { return LIR_OprFact::illegalOpr; };
2737 
2738 inline LIR_Opr LIR_Opr::nullOpr()   { return LIR_OprFact::nullOpr; };
2739 
2740 #endif // SHARE_C1_C1_LIR_HPP