1 /*
   2  * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  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_sqrt
 948       , lir_abs
 949       , lir_neg
 950       , lir_f2hf
 951       , lir_hf2f
 952       , lir_safepoint
 953       , lir_unwind
 954       , lir_load_klass
 955   , end_op1
 956   , begin_op2
 957       , lir_branch
 958       , lir_cond_float_branch
 959       , lir_cmp
 960       , lir_cmp_l2i
 961       , lir_ucmp_fd2i
 962       , lir_cmp_fd2i
 963       , lir_add
 964       , lir_sub
 965       , lir_mul
 966       , lir_div
 967       , lir_rem
 968       , lir_logic_and
 969       , lir_logic_or
 970       , lir_logic_xor
 971       , lir_shl
 972       , lir_shr
 973       , lir_ushr
 974       , lir_alloc_array
 975       , lir_throw
 976       , lir_xadd
 977       , lir_xchg
 978   , end_op2
 979   , begin_op3
 980       , lir_idiv
 981       , lir_irem
 982       , lir_fmad
 983       , lir_fmaf
 984   , end_op3
 985   , begin_op4
 986       , lir_cmove
 987   , end_op4
 988   , begin_opJavaCall
 989       , lir_static_call
 990       , lir_optvirtual_call
 991       , lir_icvirtual_call
 992       , lir_dynamic_call
 993   , end_opJavaCall
 994   , begin_opArrayCopy
 995       , lir_arraycopy
 996   , end_opArrayCopy
 997   , begin_opUpdateCRC32
 998       , lir_updatecrc32
 999   , end_opUpdateCRC32
1000   , begin_opLock
1001     , lir_lock
1002     , lir_unlock
1003   , end_opLock
1004   , begin_delay_slot
1005     , lir_delay_slot
1006   , end_delay_slot
1007   , begin_opTypeCheck
1008     , lir_instanceof
1009     , lir_checkcast
1010     , lir_store_check
1011   , end_opTypeCheck
1012   , begin_opFlattenedArrayCheck
1013     , lir_flat_array_check
1014   , end_opFlattenedArrayCheck
1015   , begin_opNullFreeArrayCheck
1016     , lir_null_free_array_check
1017   , end_opNullFreeArrayCheck
1018   , begin_opSubstitutabilityCheck
1019     , lir_substitutability_check
1020   , end_opSubstitutabilityCheck
1021   , begin_opCompareAndSwap
1022     , lir_cas_long
1023     , lir_cas_obj
1024     , lir_cas_int
1025   , end_opCompareAndSwap
1026   , begin_opMDOProfile
1027     , lir_profile_call
1028     , lir_profile_type
1029     , lir_profile_inline_type
1030   , end_opMDOProfile
1031   , begin_opAssert
1032     , lir_assert
1033   , end_opAssert
1034 #if INCLUDE_ZGC
1035   , begin_opXLoadBarrierTest
1036     , lir_xloadbarrier_test
1037   , end_opXLoadBarrierTest
1038 #endif
1039 };
1040 
1041 
1042 enum LIR_Condition {
1043     lir_cond_equal
1044   , lir_cond_notEqual
1045   , lir_cond_less
1046   , lir_cond_lessEqual
1047   , lir_cond_greaterEqual
1048   , lir_cond_greater
1049   , lir_cond_belowEqual
1050   , lir_cond_aboveEqual
1051   , lir_cond_always
1052   , lir_cond_unknown = -1
1053 };
1054 
1055 
1056 enum LIR_PatchCode {
1057   lir_patch_none,
1058   lir_patch_low,
1059   lir_patch_high,
1060   lir_patch_normal
1061 };
1062 
1063 
1064 enum LIR_MoveKind {
1065   lir_move_normal,
1066   lir_move_volatile,
1067   lir_move_wide,
1068   lir_move_max_flag
1069 };
1070 
1071 
1072 // --------------------------------------------------
1073 // LIR_Op
1074 // --------------------------------------------------
1075 class LIR_Op: public CompilationResourceObj {
1076  friend class LIR_OpVisitState;
1077 
1078 #ifdef ASSERT
1079  private:
1080   const char *  _file;
1081   int           _line;
1082 #endif
1083 
1084  protected:
1085   LIR_Opr       _result;
1086   unsigned short _code;
1087   unsigned short _flags;
1088   CodeEmitInfo* _info;
1089   int           _id;     // value id for register allocation
1090   int           _fpu_pop_count;
1091   Instruction*  _source; // for debugging
1092 
1093   static void print_condition(outputStream* out, LIR_Condition cond) PRODUCT_RETURN;
1094 
1095  protected:
1096   static bool is_in_range(LIR_Code test, LIR_Code start, LIR_Code end)  { return start < test && test < end; }
1097 
1098  public:
1099   LIR_Op()
1100     :
1101 #ifdef ASSERT
1102       _file(nullptr)
1103     , _line(0),
1104 #endif
1105       _result(LIR_OprFact::illegalOpr)
1106     , _code(lir_none)
1107     , _flags(0)
1108     , _info(nullptr)
1109     , _id(-1)
1110     , _fpu_pop_count(0)
1111     , _source(nullptr) {}
1112 
1113   LIR_Op(LIR_Code code, LIR_Opr result, CodeEmitInfo* info)
1114     :
1115 #ifdef ASSERT
1116       _file(nullptr)
1117     , _line(0),
1118 #endif
1119       _result(result)
1120     , _code(code)
1121     , _flags(0)
1122     , _info(info)
1123     , _id(-1)
1124     , _fpu_pop_count(0)
1125     , _source(nullptr) {}
1126 
1127   CodeEmitInfo* info() const                  { return _info;   }
1128   LIR_Code code()      const                  { return (LIR_Code)_code;   }
1129   LIR_Opr result_opr() const                  { return _result; }
1130   void    set_result_opr(LIR_Opr opr)         { _result = opr;  }
1131 
1132 #ifdef ASSERT
1133   void set_file_and_line(const char * file, int line) {
1134     _file = file;
1135     _line = line;
1136   }
1137 #endif
1138 
1139   virtual const char * name() const PRODUCT_RETURN_NULL;
1140   virtual void visit(LIR_OpVisitState* state);
1141 
1142   int id()             const                  { return _id;     }
1143   void set_id(int id)                         { _id = id; }
1144 
1145   // FPU stack simulation helpers -- only used on Intel
1146   void set_fpu_pop_count(int count)           { assert(count >= 0 && count <= 1, "currently only 0 and 1 are valid"); _fpu_pop_count = count; }
1147   int  fpu_pop_count() const                  { return _fpu_pop_count; }
1148   bool pop_fpu_stack()                        { return _fpu_pop_count > 0; }
1149 
1150   Instruction* source() const                 { return _source; }
1151   void set_source(Instruction* ins)           { _source = ins; }
1152 
1153   virtual void emit_code(LIR_Assembler* masm) = 0;
1154   virtual void print_instr(outputStream* out) const   = 0;
1155   virtual void print_on(outputStream* st) const PRODUCT_RETURN;
1156 
1157   virtual bool is_patching() { return false; }
1158   virtual LIR_OpCall* as_OpCall() { return nullptr; }
1159   virtual LIR_OpJavaCall* as_OpJavaCall() { return nullptr; }
1160   virtual LIR_OpLabel* as_OpLabel() { return nullptr; }
1161   virtual LIR_OpDelay* as_OpDelay() { return nullptr; }
1162   virtual LIR_OpLock* as_OpLock() { return nullptr; }
1163   virtual LIR_OpAllocArray* as_OpAllocArray() { return nullptr; }
1164   virtual LIR_OpAllocObj* as_OpAllocObj() { return nullptr; }
1165   virtual LIR_OpRoundFP* as_OpRoundFP() { return nullptr; }
1166   virtual LIR_OpBranch* as_OpBranch() { return nullptr; }
1167   virtual LIR_OpReturn* as_OpReturn() { return nullptr; }
1168   virtual LIR_OpRTCall* as_OpRTCall() { return nullptr; }
1169   virtual LIR_OpConvert* as_OpConvert() { return nullptr; }
1170   virtual LIR_Op0* as_Op0() { return nullptr; }
1171   virtual LIR_Op1* as_Op1() { return nullptr; }
1172   virtual LIR_Op2* as_Op2() { return nullptr; }
1173   virtual LIR_Op3* as_Op3() { return nullptr; }
1174   virtual LIR_Op4* as_Op4() { return nullptr; }
1175   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return nullptr; }
1176   virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return nullptr; }
1177   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return nullptr; }
1178   virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return nullptr; }
1179   virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return nullptr; }
1180   virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return nullptr; }
1181   virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return nullptr; }
1182   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return nullptr; }
1183   virtual LIR_OpProfileCall* as_OpProfileCall() { return nullptr; }
1184   virtual LIR_OpProfileType* as_OpProfileType() { return nullptr; }
1185   virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return nullptr; }
1186 #ifdef ASSERT
1187   virtual LIR_OpAssert* as_OpAssert() { return nullptr; }
1188 #endif
1189 
1190   virtual void verify() const {}
1191 };
1192 
1193 // for calls
1194 class LIR_OpCall: public LIR_Op {
1195  friend class LIR_OpVisitState;
1196 
1197  protected:
1198   address      _addr;
1199   LIR_OprList* _arguments;
1200  protected:
1201   LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1202              LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1203     : LIR_Op(code, result, info)
1204     , _addr(addr)
1205     , _arguments(arguments) {}
1206 
1207  public:
1208   address addr() const                           { return _addr; }
1209   const LIR_OprList* arguments() const           { return _arguments; }
1210   virtual LIR_OpCall* as_OpCall()                { return this; }
1211 };
1212 
1213 
1214 // --------------------------------------------------
1215 // LIR_OpJavaCall
1216 // --------------------------------------------------
1217 class LIR_OpJavaCall: public LIR_OpCall {
1218  friend class LIR_OpVisitState;
1219 
1220  private:
1221   ciMethod* _method;
1222   LIR_Opr   _receiver;
1223   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.
1224 
1225  public:
1226   LIR_OpJavaCall(LIR_Code code, ciMethod* method,
1227                  LIR_Opr receiver, LIR_Opr result,
1228                  address addr, LIR_OprList* arguments,
1229                  CodeEmitInfo* info)
1230   : LIR_OpCall(code, addr, result, arguments, info)
1231   , _method(method)
1232   , _receiver(receiver)
1233   , _method_handle_invoke_SP_save_opr(LIR_OprFact::illegalOpr)
1234   { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1235 
1236   LIR_OpJavaCall(LIR_Code code, ciMethod* method,
1237                  LIR_Opr receiver, LIR_Opr result, intptr_t vtable_offset,
1238                  LIR_OprList* arguments, CodeEmitInfo* info)
1239   : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1240   , _method(method)
1241   , _receiver(receiver)
1242   , _method_handle_invoke_SP_save_opr(LIR_OprFact::illegalOpr)
1243   { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1244 
1245   LIR_Opr receiver() const                       { return _receiver; }
1246   ciMethod* method() const                       { return _method;   }
1247 
1248   // JSR 292 support.
1249   bool is_invokedynamic() const                  { return code() == lir_dynamic_call; }
1250   bool is_method_handle_invoke() const {
1251     return method()->is_compiled_lambda_form() ||   // Java-generated lambda form
1252            method()->is_method_handle_intrinsic();  // JVM-generated MH intrinsic
1253   }
1254 
1255   virtual void emit_code(LIR_Assembler* masm);
1256   virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1257   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1258 
1259   bool maybe_return_as_fields(ciInlineKlass** vk = nullptr) const;
1260 };
1261 
1262 // --------------------------------------------------
1263 // LIR_OpLabel
1264 // --------------------------------------------------
1265 // Location where a branch can continue
1266 class LIR_OpLabel: public LIR_Op {
1267  friend class LIR_OpVisitState;
1268 
1269  private:
1270   Label* _label;
1271  public:
1272   LIR_OpLabel(Label* lbl)
1273    : LIR_Op(lir_label, LIR_OprFact::illegalOpr, nullptr)
1274    , _label(lbl)                                 {}
1275   Label* label() const                           { return _label; }
1276 
1277   virtual void emit_code(LIR_Assembler* masm);
1278   virtual LIR_OpLabel* as_OpLabel() { return this; }
1279   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1280 };
1281 
1282 // LIR_OpArrayCopy
1283 class LIR_OpArrayCopy: public LIR_Op {
1284  friend class LIR_OpVisitState;
1285 
1286  private:
1287   ArrayCopyStub*  _stub;
1288   LIR_Opr   _src;
1289   LIR_Opr   _src_pos;
1290   LIR_Opr   _dst;
1291   LIR_Opr   _dst_pos;
1292   LIR_Opr   _length;
1293   LIR_Opr   _tmp;
1294   ciArrayKlass* _expected_type;
1295   int       _flags;
1296 
1297 public:
1298   enum Flags {
1299     src_null_check         = 1 << 0,
1300     dst_null_check         = 1 << 1,
1301     src_pos_positive_check = 1 << 2,
1302     dst_pos_positive_check = 1 << 3,
1303     length_positive_check  = 1 << 4,
1304     src_range_check        = 1 << 5,
1305     dst_range_check        = 1 << 6,
1306     type_check             = 1 << 7,
1307     overlapping            = 1 << 8,
1308     unaligned              = 1 << 9,
1309     src_objarray           = 1 << 10,
1310     dst_objarray           = 1 << 11,
1311     always_slow_path       = 1 << 12,
1312     src_inlinetype_check   = 1 << 13,
1313     dst_inlinetype_check   = 1 << 14,
1314     all_flags              = (1 << 15) - 1
1315   };
1316 
1317   LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1318                   ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1319 
1320   LIR_Opr src() const                            { return _src; }
1321   LIR_Opr src_pos() const                        { return _src_pos; }
1322   LIR_Opr dst() const                            { return _dst; }
1323   LIR_Opr dst_pos() const                        { return _dst_pos; }
1324   LIR_Opr length() const                         { return _length; }
1325   LIR_Opr tmp() const                            { return _tmp; }
1326   int flags() const                              { return _flags; }
1327   ciArrayKlass* expected_type() const            { return _expected_type; }
1328   ArrayCopyStub* stub() const                    { return _stub; }
1329 
1330   virtual void emit_code(LIR_Assembler* masm);
1331   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1332   void print_instr(outputStream* out) const PRODUCT_RETURN;
1333 };
1334 
1335 // LIR_OpUpdateCRC32
1336 class LIR_OpUpdateCRC32: public LIR_Op {
1337   friend class LIR_OpVisitState;
1338 
1339 private:
1340   LIR_Opr   _crc;
1341   LIR_Opr   _val;
1342 
1343 public:
1344 
1345   LIR_OpUpdateCRC32(LIR_Opr crc, LIR_Opr val, LIR_Opr res);
1346 
1347   LIR_Opr crc() const                            { return _crc; }
1348   LIR_Opr val() const                            { return _val; }
1349 
1350   virtual void emit_code(LIR_Assembler* masm);
1351   virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32()  { return this; }
1352   void print_instr(outputStream* out) const PRODUCT_RETURN;
1353 };
1354 
1355 // --------------------------------------------------
1356 // LIR_Op0
1357 // --------------------------------------------------
1358 class LIR_Op0: public LIR_Op {
1359  friend class LIR_OpVisitState;
1360 
1361  public:
1362   LIR_Op0(LIR_Code code)
1363    : LIR_Op(code, LIR_OprFact::illegalOpr, nullptr)  { assert(is_in_range(code, begin_op0, end_op0), "code check"); }
1364   LIR_Op0(LIR_Code code, LIR_Opr result, CodeEmitInfo* info = nullptr)
1365    : LIR_Op(code, result, info)  { assert(is_in_range(code, begin_op0, end_op0), "code check"); }
1366 
1367   virtual void emit_code(LIR_Assembler* masm);
1368   virtual LIR_Op0* as_Op0() { return this; }
1369   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1370 };
1371 
1372 
1373 // --------------------------------------------------
1374 // LIR_Op1
1375 // --------------------------------------------------
1376 
1377 class LIR_Op1: public LIR_Op {
1378  friend class LIR_OpVisitState;
1379 
1380  protected:
1381   LIR_Opr         _opr;   // input operand
1382   LIR_Opr         _tmp;
1383   BasicType       _type;  // Operand types
1384   LIR_PatchCode   _patch; // only required with patchin (NEEDS_CLEANUP: do we want a special instruction for patching?)
1385 
1386   static void print_patch_code(outputStream* out, LIR_PatchCode code);
1387 
1388   void set_kind(LIR_MoveKind kind) {
1389     assert(code() == lir_move, "must be");
1390     _flags = kind;
1391   }
1392 
1393  public:
1394   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)
1395     : LIR_Op(code, result, info)
1396     , _opr(opr)
1397     , _tmp(LIR_OprFact::illegalOpr)
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, LIR_Opr tmp, BasicType type = T_ILLEGAL, LIR_PatchCode patch = lir_patch_none, CodeEmitInfo* info = nullptr)
1402     : LIR_Op(code, result, info)
1403     , _opr(opr)
1404     , _tmp(tmp)
1405     , _type(type)
1406     , _patch(patch)                    { assert(is_in_range(code, begin_op1, end_op1), "code check"); }
1407 
1408   LIR_Op1(LIR_Code code, LIR_Opr opr, LIR_Opr result, BasicType type, LIR_PatchCode patch, CodeEmitInfo* info, LIR_MoveKind kind)
1409     : LIR_Op(code, result, info)
1410     , _opr(opr)
1411     , _tmp(LIR_OprFact::illegalOpr)
1412     , _type(type)
1413     , _patch(patch)                    {
1414     assert(code == lir_move, "must be");
1415     set_kind(kind);
1416   }
1417 
1418   LIR_Op1(LIR_Code code, LIR_Opr opr, CodeEmitInfo* info)
1419     : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1420     , _opr(opr)
1421     , _tmp(LIR_OprFact::illegalOpr)
1422     , _type(T_ILLEGAL)
1423     , _patch(lir_patch_none)           { assert(is_in_range(code, begin_op1, end_op1), "code check"); }
1424 
1425   LIR_Opr in_opr()           const               { return _opr;   }
1426   LIR_Opr tmp_opr()          const               { return _tmp;   }
1427   LIR_PatchCode patch_code() const               { return _patch; }
1428   BasicType type()           const               { return _type;  }
1429 
1430   LIR_MoveKind move_kind() const {
1431     assert(code() == lir_move, "must be");
1432     return (LIR_MoveKind)_flags;
1433   }
1434 
1435   virtual bool is_patching() { return _patch != lir_patch_none; }
1436   virtual void emit_code(LIR_Assembler* masm);
1437   virtual LIR_Op1* as_Op1() { return this; }
1438   virtual const char * name() const PRODUCT_RETURN_NULL;
1439 
1440   void set_in_opr(LIR_Opr opr) { _opr = opr; }
1441 
1442   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1443   virtual void verify() const;
1444 };
1445 
1446 
1447 // for runtime calls
1448 class LIR_OpRTCall: public LIR_OpCall {
1449  friend class LIR_OpVisitState;
1450 
1451  private:
1452   LIR_Opr _tmp;
1453  public:
1454   LIR_OpRTCall(address addr, LIR_Opr tmp,
1455                LIR_Opr result, LIR_OprList* arguments, CodeEmitInfo* info = nullptr)
1456     : LIR_OpCall(lir_rtcall, addr, result, arguments, info)
1457     , _tmp(tmp) {}
1458 
1459   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1460   virtual void emit_code(LIR_Assembler* masm);
1461   virtual LIR_OpRTCall* as_OpRTCall() { return this; }
1462 
1463   LIR_Opr tmp() const                            { return _tmp; }
1464 
1465   virtual void verify() const;
1466 };
1467 
1468 
1469 
1470 class LIR_OpReturn: public LIR_Op1 {
1471  friend class LIR_OpVisitState;
1472 
1473  private:
1474   C1SafepointPollStub* _stub;
1475 
1476  public:
1477   LIR_OpReturn(LIR_Opr opr);
1478 
1479   C1SafepointPollStub* stub() const { return _stub; }
1480   virtual LIR_OpReturn* as_OpReturn() { return this; }
1481 };
1482 
1483 class ConversionStub;
1484 
1485 class LIR_OpConvert: public LIR_Op1 {
1486  friend class LIR_OpVisitState;
1487 
1488  private:
1489    Bytecodes::Code _bytecode;
1490    ConversionStub* _stub;
1491 
1492  public:
1493    LIR_OpConvert(Bytecodes::Code code, LIR_Opr opr, LIR_Opr result, ConversionStub* stub)
1494      : LIR_Op1(lir_convert, opr, result)
1495      , _bytecode(code)
1496      , _stub(stub)                               {}
1497 
1498   Bytecodes::Code bytecode() const               { return _bytecode; }
1499   ConversionStub* stub() const                   { return _stub; }
1500 
1501   virtual void emit_code(LIR_Assembler* masm);
1502   virtual LIR_OpConvert* as_OpConvert() { return this; }
1503   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1504 
1505   static void print_bytecode(outputStream* out, Bytecodes::Code code) PRODUCT_RETURN;
1506 };
1507 
1508 
1509 // LIR_OpAllocObj
1510 class LIR_OpAllocObj : public LIR_Op1 {
1511  friend class LIR_OpVisitState;
1512 
1513  private:
1514   LIR_Opr _tmp1;
1515   LIR_Opr _tmp2;
1516   LIR_Opr _tmp3;
1517   LIR_Opr _tmp4;
1518   int     _hdr_size;
1519   int     _obj_size;
1520   CodeStub* _stub;
1521   bool    _init_check;
1522 
1523  public:
1524   LIR_OpAllocObj(LIR_Opr klass, LIR_Opr result,
1525                  LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4,
1526                  int hdr_size, int obj_size, bool init_check, CodeStub* stub)
1527     : LIR_Op1(lir_alloc_object, klass, result)
1528     , _tmp1(t1)
1529     , _tmp2(t2)
1530     , _tmp3(t3)
1531     , _tmp4(t4)
1532     , _hdr_size(hdr_size)
1533     , _obj_size(obj_size)
1534     , _stub(stub)
1535     , _init_check(init_check)                    { }
1536 
1537   LIR_Opr klass()        const                   { return in_opr();     }
1538   LIR_Opr obj()          const                   { return result_opr(); }
1539   LIR_Opr tmp1()         const                   { return _tmp1;        }
1540   LIR_Opr tmp2()         const                   { return _tmp2;        }
1541   LIR_Opr tmp3()         const                   { return _tmp3;        }
1542   LIR_Opr tmp4()         const                   { return _tmp4;        }
1543   int     header_size()  const                   { return _hdr_size;    }
1544   int     object_size()  const                   { return _obj_size;    }
1545   bool    init_check()   const                   { return _init_check;  }
1546   CodeStub* stub()       const                   { return _stub;        }
1547 
1548   virtual void emit_code(LIR_Assembler* masm);
1549   virtual LIR_OpAllocObj * as_OpAllocObj () { return this; }
1550   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1551 };
1552 
1553 
1554 // LIR_OpRoundFP
1555 class LIR_OpRoundFP : public LIR_Op1 {
1556  friend class LIR_OpVisitState;
1557 
1558  private:
1559   LIR_Opr _tmp;
1560 
1561  public:
1562   LIR_OpRoundFP(LIR_Opr reg, LIR_Opr stack_loc_temp, LIR_Opr result)
1563     : LIR_Op1(lir_roundfp, reg, result)
1564     , _tmp(stack_loc_temp) {}
1565 
1566   LIR_Opr tmp() const                            { return _tmp; }
1567   virtual LIR_OpRoundFP* as_OpRoundFP()          { return this; }
1568   void print_instr(outputStream* out) const PRODUCT_RETURN;
1569 };
1570 
1571 // LIR_OpTypeCheck
1572 class LIR_OpTypeCheck: public LIR_Op {
1573  friend class LIR_OpVisitState;
1574 
1575  private:
1576   LIR_Opr       _object;
1577   LIR_Opr       _array;
1578   ciKlass*      _klass;
1579   LIR_Opr       _tmp1;
1580   LIR_Opr       _tmp2;
1581   LIR_Opr       _tmp3;
1582   CodeEmitInfo* _info_for_patch;
1583   CodeEmitInfo* _info_for_exception;
1584   CodeStub*     _stub;
1585   ciMethod*     _profiled_method;
1586   int           _profiled_bci;
1587   bool          _should_profile;
1588   bool          _fast_check;
1589   bool          _need_null_check;
1590 
1591 public:
1592   LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1593                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1594                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub, bool need_null_check = true);
1595   LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1596                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1597 
1598   LIR_Opr object() const                         { return _object;         }
1599   LIR_Opr array() const                          { assert(code() == lir_store_check, "not valid"); return _array;         }
1600   LIR_Opr tmp1() const                           { return _tmp1;           }
1601   LIR_Opr tmp2() const                           { return _tmp2;           }
1602   LIR_Opr tmp3() const                           { return _tmp3;           }
1603   ciKlass* klass() const                         { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass;          }
1604   bool fast_check() const                        { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check;     }
1605   CodeEmitInfo* info_for_patch() const           { return _info_for_patch;  }
1606   CodeEmitInfo* info_for_exception() const       { return _info_for_exception; }
1607   CodeStub* stub() const                         { return _stub;           }
1608 
1609   // MethodData* profiling
1610   void set_profiled_method(ciMethod *method)     { _profiled_method = method; }
1611   void set_profiled_bci(int bci)                 { _profiled_bci = bci;       }
1612   void set_should_profile(bool b)                { _should_profile = b;       }
1613   ciMethod* profiled_method() const              { return _profiled_method;   }
1614   int       profiled_bci() const                 { return _profiled_bci;      }
1615   bool      should_profile() const               { return _should_profile;    }
1616   bool      need_null_check() const              { return _need_null_check;   }
1617   virtual bool is_patching() { return _info_for_patch != nullptr; }
1618   virtual void emit_code(LIR_Assembler* masm);
1619   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1620   void print_instr(outputStream* out) const PRODUCT_RETURN;
1621 };
1622 
1623 // LIR_OpFlattenedArrayCheck
1624 class LIR_OpFlattenedArrayCheck: public LIR_Op {
1625  friend class LIR_OpVisitState;
1626 
1627  private:
1628   LIR_Opr       _array;
1629   LIR_Opr       _value;
1630   LIR_Opr       _tmp;
1631   CodeStub*     _stub;
1632 public:
1633   LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
1634   LIR_Opr array() const                          { return _array;         }
1635   LIR_Opr value() const                          { return _value;         }
1636   LIR_Opr tmp() const                            { return _tmp;           }
1637   CodeStub* stub() const                         { return _stub;          }
1638 
1639   virtual void emit_code(LIR_Assembler* masm);
1640   virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return this; }
1641   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1642 };
1643 
1644 // LIR_OpNullFreeArrayCheck
1645 class LIR_OpNullFreeArrayCheck: public LIR_Op {
1646  friend class LIR_OpVisitState;
1647 
1648  private:
1649   LIR_Opr       _array;
1650   LIR_Opr       _tmp;
1651 public:
1652   LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp);
1653   LIR_Opr array() const                          { return _array;         }
1654   LIR_Opr tmp() const                            { return _tmp;           }
1655 
1656   virtual void emit_code(LIR_Assembler* masm);
1657   virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return this; }
1658   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1659 };
1660 
1661 class LIR_OpSubstitutabilityCheck: public LIR_Op {
1662  friend class LIR_OpVisitState;
1663 
1664  private:
1665   LIR_Opr       _left;
1666   LIR_Opr       _right;
1667   LIR_Opr       _equal_result;
1668   LIR_Opr       _not_equal_result;
1669   LIR_Opr       _tmp1;
1670   LIR_Opr       _tmp2;
1671   ciKlass*      _left_klass;
1672   ciKlass*      _right_klass;
1673   LIR_Opr       _left_klass_op;
1674   LIR_Opr       _right_klass_op;
1675   CodeStub*     _stub;
1676 public:
1677   LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1678                               LIR_Opr tmp1, LIR_Opr tmp2,
1679                               ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
1680                               CodeEmitInfo* info, CodeStub* stub);
1681 
1682   LIR_Opr left() const             { return _left; }
1683   LIR_Opr right() const            { return _right; }
1684   LIR_Opr equal_result() const     { return _equal_result; }
1685   LIR_Opr not_equal_result() const { return _not_equal_result; }
1686   LIR_Opr tmp1() const             { return _tmp1; }
1687   LIR_Opr tmp2() const             { return _tmp2; }
1688   ciKlass* left_klass() const      { return _left_klass; }
1689   ciKlass* right_klass() const     { return _right_klass; }
1690   LIR_Opr left_klass_op() const    { return _left_klass_op; }
1691   LIR_Opr right_klass_op() const   { return _right_klass_op; }
1692   CodeStub* stub() const           { return _stub; }
1693 
1694   virtual void emit_code(LIR_Assembler* masm);
1695   virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return this; }
1696   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1697 };
1698 
1699 // LIR_Op2
1700 class LIR_Op2: public LIR_Op {
1701  friend class LIR_OpVisitState;
1702 
1703  protected:
1704   LIR_Opr   _opr1;
1705   LIR_Opr   _opr2;
1706   LIR_Opr   _tmp1;
1707   LIR_Opr   _tmp2;
1708   LIR_Opr   _tmp3;
1709   LIR_Opr   _tmp4;
1710   LIR_Opr   _tmp5;
1711   LIR_Condition _condition;
1712   BasicType _type;
1713 
1714   void verify() const;
1715 
1716  public:
1717   LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1718     : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1719     , _opr1(opr1)
1720     , _opr2(opr2)
1721     , _tmp1(LIR_OprFact::illegalOpr)
1722     , _tmp2(LIR_OprFact::illegalOpr)
1723     , _tmp3(LIR_OprFact::illegalOpr)
1724     , _tmp4(LIR_OprFact::illegalOpr)
1725     , _tmp5(LIR_OprFact::illegalOpr)
1726     , _condition(condition)
1727     , _type(type) {
1728     assert(code == lir_cmp || code == lir_branch || code == lir_cond_float_branch || code == lir_assert, "code check");
1729   }
1730 
1731   LIR_Op2(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result, BasicType type)
1732     : LIR_Op(code, result, nullptr)
1733     , _opr1(opr1)
1734     , _opr2(opr2)
1735     , _tmp1(LIR_OprFact::illegalOpr)
1736     , _tmp2(LIR_OprFact::illegalOpr)
1737     , _tmp3(LIR_OprFact::illegalOpr)
1738     , _tmp4(LIR_OprFact::illegalOpr)
1739     , _tmp5(LIR_OprFact::illegalOpr)
1740     , _condition(condition)
1741     , _type(type) {
1742     assert(code == lir_cmove, "code check");
1743     assert(type != T_ILLEGAL, "cmove should have type");
1744   }
1745 
1746   LIR_Op2(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result = LIR_OprFact::illegalOpr,
1747           CodeEmitInfo* info = nullptr, BasicType type = T_ILLEGAL)
1748     : LIR_Op(code, result, info)
1749     , _opr1(opr1)
1750     , _opr2(opr2)
1751     , _tmp1(LIR_OprFact::illegalOpr)
1752     , _tmp2(LIR_OprFact::illegalOpr)
1753     , _tmp3(LIR_OprFact::illegalOpr)
1754     , _tmp4(LIR_OprFact::illegalOpr)
1755     , _tmp5(LIR_OprFact::illegalOpr)
1756     , _condition(lir_cond_unknown)
1757     , _type(type) {
1758     assert(code != lir_cmp && code != lir_branch && code != lir_cond_float_branch && is_in_range(code, begin_op2, end_op2), "code check");
1759   }
1760 
1761   LIR_Op2(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr result, LIR_Opr tmp1, LIR_Opr tmp2 = LIR_OprFact::illegalOpr,
1762           LIR_Opr tmp3 = LIR_OprFact::illegalOpr, LIR_Opr tmp4 = LIR_OprFact::illegalOpr, LIR_Opr tmp5 = LIR_OprFact::illegalOpr)
1763     : LIR_Op(code, result, nullptr)
1764     , _opr1(opr1)
1765     , _opr2(opr2)
1766     , _tmp1(tmp1)
1767     , _tmp2(tmp2)
1768     , _tmp3(tmp3)
1769     , _tmp4(tmp4)
1770     , _tmp5(tmp5)
1771     , _condition(lir_cond_unknown)
1772     , _type(T_ILLEGAL)    {
1773     assert(code != lir_cmp && code != lir_branch && code != lir_cond_float_branch && is_in_range(code, begin_op2, end_op2), "code check");
1774   }
1775 
1776   LIR_Opr in_opr1() const                        { return _opr1; }
1777   LIR_Opr in_opr2() const                        { return _opr2; }
1778   BasicType type()  const                        { return _type; }
1779   LIR_Opr tmp1_opr() const                       { return _tmp1; }
1780   LIR_Opr tmp2_opr() const                       { return _tmp2; }
1781   LIR_Opr tmp3_opr() const                       { return _tmp3; }
1782   LIR_Opr tmp4_opr() const                       { return _tmp4; }
1783   LIR_Opr tmp5_opr() const                       { return _tmp5; }
1784   LIR_Condition condition() const  {
1785     assert(code() == lir_cmp || code() == lir_branch || code() == lir_cond_float_branch || code() == lir_assert, "only valid for branch and assert"); return _condition;
1786   }
1787   void set_condition(LIR_Condition condition) {
1788     assert(code() == lir_cmp || code() == lir_branch || code() == lir_cond_float_branch, "only valid for branch"); _condition = condition;
1789   }
1790 
1791   void set_in_opr1(LIR_Opr opr)                  { _opr1 = opr; }
1792   void set_in_opr2(LIR_Opr opr)                  { _opr2 = opr; }
1793 
1794   virtual void emit_code(LIR_Assembler* masm);
1795   virtual LIR_Op2* as_Op2() { return this; }
1796   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1797 };
1798 
1799 class LIR_OpBranch: public LIR_Op2 {
1800  friend class LIR_OpVisitState;
1801 
1802  private:
1803   Label*        _label;
1804   BlockBegin*   _block;  // if this is a branch to a block, this is the block
1805   BlockBegin*   _ublock; // if this is a float-branch, this is the unordered block
1806   CodeStub*     _stub;   // if this is a branch to a stub, this is the stub
1807 
1808  public:
1809   LIR_OpBranch(LIR_Condition cond, Label* lbl)
1810     : LIR_Op2(lir_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*) nullptr)
1811     , _label(lbl)
1812     , _block(nullptr)
1813     , _ublock(nullptr)
1814     , _stub(nullptr) { }
1815 
1816   LIR_OpBranch(LIR_Condition cond, BlockBegin* block);
1817   LIR_OpBranch(LIR_Condition cond, CodeStub* stub);
1818 
1819   // for unordered comparisons
1820   LIR_OpBranch(LIR_Condition cond, BlockBegin* block, BlockBegin* ublock);
1821 
1822   LIR_Condition cond() const {
1823     return condition();
1824   }
1825 
1826   void set_cond(LIR_Condition cond) {
1827     set_condition(cond);
1828   }
1829 
1830   Label*        label()       const              { return _label;       }
1831   BlockBegin*   block()       const              { return _block;       }
1832   BlockBegin*   ublock()      const              { return _ublock;      }
1833   CodeStub*     stub()        const              { return _stub;        }
1834 
1835   void          change_block(BlockBegin* b);
1836   void          change_ublock(BlockBegin* b);
1837   void          negate_cond();
1838 
1839   virtual void emit_code(LIR_Assembler* masm);
1840   virtual LIR_OpBranch* as_OpBranch() { return this; }
1841   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1842 };
1843 
1844 class LIR_OpAllocArray : public LIR_Op {
1845  friend class LIR_OpVisitState;
1846 
1847  private:
1848   LIR_Opr   _klass;
1849   LIR_Opr   _len;
1850   LIR_Opr   _tmp1;
1851   LIR_Opr   _tmp2;
1852   LIR_Opr   _tmp3;
1853   LIR_Opr   _tmp4;
1854   CodeStub* _stub;
1855   BasicType _type;
1856   bool      _zero_array;
1857   bool      _is_null_free;
1858 
1859  public:
1860   LIR_OpAllocArray(LIR_Opr klass, LIR_Opr len, LIR_Opr result, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, BasicType type, CodeStub* stub, bool zero_array, bool is_null_free)
1861     : LIR_Op(lir_alloc_array, result, nullptr)
1862     , _klass(klass)
1863     , _len(len)
1864     , _tmp1(t1)
1865     , _tmp2(t2)
1866     , _tmp3(t3)
1867     , _tmp4(t4)
1868     , _stub(stub)
1869     , _type(type)
1870     , _zero_array(zero_array)
1871     , _is_null_free(is_null_free) {}
1872 
1873   LIR_Opr   klass()   const                      { return _klass;       }
1874   LIR_Opr   len()     const                      { return _len;         }
1875   LIR_Opr   obj()     const                      { return result_opr(); }
1876   LIR_Opr   tmp1()    const                      { return _tmp1;        }
1877   LIR_Opr   tmp2()    const                      { return _tmp2;        }
1878   LIR_Opr   tmp3()    const                      { return _tmp3;        }
1879   LIR_Opr   tmp4()    const                      { return _tmp4;        }
1880   BasicType type()    const                      { return _type;        }
1881   CodeStub* stub()    const                      { return _stub;        }
1882   bool      zero_array()   const                 { return _zero_array;  }
1883   bool      is_null_free() const                 { return _is_null_free;}
1884 
1885   virtual void emit_code(LIR_Assembler* masm);
1886   virtual LIR_OpAllocArray * as_OpAllocArray () { return this; }
1887   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1888 };
1889 
1890 
1891 class LIR_Op3: public LIR_Op {
1892  friend class LIR_OpVisitState;
1893 
1894  private:
1895   LIR_Opr _opr1;
1896   LIR_Opr _opr2;
1897   LIR_Opr _opr3;
1898  public:
1899   LIR_Op3(LIR_Code code, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr result, CodeEmitInfo* info = nullptr)
1900     : LIR_Op(code, result, info)
1901     , _opr1(opr1)
1902     , _opr2(opr2)
1903     , _opr3(opr3)                                { assert(is_in_range(code, begin_op3, end_op3), "code check"); }
1904   LIR_Opr in_opr1() const                        { return _opr1; }
1905   LIR_Opr in_opr2() const                        { return _opr2; }
1906   LIR_Opr in_opr3() const                        { return _opr3; }
1907 
1908   virtual void emit_code(LIR_Assembler* masm);
1909   virtual LIR_Op3* as_Op3() { return this; }
1910   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1911 };
1912 
1913 class LIR_Op4: public LIR_Op {
1914   friend class LIR_OpVisitState;
1915  protected:
1916   LIR_Opr   _opr1;
1917   LIR_Opr   _opr2;
1918   LIR_Opr   _opr3;
1919   LIR_Opr   _opr4;
1920   LIR_Opr   _tmp1;
1921   LIR_Opr   _tmp2;
1922   LIR_Opr   _tmp3;
1923   LIR_Opr   _tmp4;
1924   LIR_Opr   _tmp5;
1925   LIR_Condition _condition;
1926   BasicType _type;
1927 
1928  public:
1929   LIR_Op4(LIR_Code code, LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, LIR_Opr opr3, LIR_Opr opr4,
1930           LIR_Opr result, BasicType type)
1931     : LIR_Op(code, result, nullptr)
1932     , _opr1(opr1)
1933     , _opr2(opr2)
1934     , _opr3(opr3)
1935     , _opr4(opr4)
1936     , _tmp1(LIR_OprFact::illegalOpr)
1937     , _tmp2(LIR_OprFact::illegalOpr)
1938     , _tmp3(LIR_OprFact::illegalOpr)
1939     , _tmp4(LIR_OprFact::illegalOpr)
1940     , _tmp5(LIR_OprFact::illegalOpr)
1941     , _condition(condition)
1942     , _type(type) {
1943     assert(code == lir_cmove, "code check");
1944     assert(type != T_ILLEGAL, "cmove should have type");
1945   }
1946 
1947   LIR_Opr in_opr1() const                        { return _opr1; }
1948   LIR_Opr in_opr2() const                        { return _opr2; }
1949   LIR_Opr in_opr3() const                        { return _opr3; }
1950   LIR_Opr in_opr4() const                        { return _opr4; }
1951   BasicType type()  const                        { return _type; }
1952   LIR_Opr tmp1_opr() const                       { return _tmp1; }
1953   LIR_Opr tmp2_opr() const                       { return _tmp2; }
1954   LIR_Opr tmp3_opr() const                       { return _tmp3; }
1955   LIR_Opr tmp4_opr() const                       { return _tmp4; }
1956   LIR_Opr tmp5_opr() const                       { return _tmp5; }
1957 
1958   LIR_Condition condition() const                { return _condition; }
1959   void set_condition(LIR_Condition condition)    { _condition = condition; }
1960 
1961   void set_in_opr1(LIR_Opr opr)                  { _opr1 = opr; }
1962   void set_in_opr2(LIR_Opr opr)                  { _opr2 = opr; }
1963   void set_in_opr3(LIR_Opr opr)                  { _opr3 = opr; }
1964   void set_in_opr4(LIR_Opr opr)                  { _opr4 = opr; }
1965   virtual void emit_code(LIR_Assembler* masm);
1966   virtual LIR_Op4* as_Op4() { return this; }
1967 
1968   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1969 };
1970 
1971 //--------------------------------
1972 class LabelObj: public CompilationResourceObj {
1973  private:
1974   Label _label;
1975  public:
1976   LabelObj()                                     {}
1977   Label* label()                                 { return &_label; }
1978 };
1979 
1980 
1981 class LIR_OpLock: public LIR_Op {
1982  friend class LIR_OpVisitState;
1983 
1984  private:
1985   LIR_Opr _hdr;
1986   LIR_Opr _obj;
1987   LIR_Opr _lock;
1988   LIR_Opr _scratch;
1989   CodeStub* _stub;
1990   CodeStub* _throw_ie_stub;
1991  public:
1992   LIR_OpLock(LIR_Code code, LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub=nullptr)
1993     : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1994     , _hdr(hdr)
1995     , _obj(obj)
1996     , _lock(lock)
1997     , _scratch(scratch)
1998     , _stub(stub)
1999     , _throw_ie_stub(throw_ie_stub)                    {}
2000 
2001   LIR_Opr hdr_opr() const                        { return _hdr; }
2002   LIR_Opr obj_opr() const                        { return _obj; }
2003   LIR_Opr lock_opr() const                       { return _lock; }
2004   LIR_Opr scratch_opr() const                    { return _scratch; }
2005   CodeStub* stub() const                         { return _stub; }
2006   CodeStub* throw_ie_stub() const                { return _throw_ie_stub; }
2007 
2008   virtual void emit_code(LIR_Assembler* masm);
2009   virtual LIR_OpLock* as_OpLock() { return this; }
2010   void print_instr(outputStream* out) const PRODUCT_RETURN;
2011 };
2012 
2013 class LIR_OpLoadKlass: public LIR_Op {
2014   friend class LIR_OpVisitState;
2015 
2016  private:
2017   LIR_Opr _obj;
2018  public:
2019   LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
2020     : LIR_Op(lir_load_klass, result, info)
2021     , _obj(obj)
2022     {}
2023 
2024   LIR_Opr obj()        const { return _obj;  }
2025 
2026   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }
2027   virtual void emit_code(LIR_Assembler* masm);
2028   void print_instr(outputStream* out) const PRODUCT_RETURN;
2029 };
2030 
2031 class LIR_OpDelay: public LIR_Op {
2032  friend class LIR_OpVisitState;
2033 
2034  private:
2035   LIR_Op* _op;
2036 
2037  public:
2038   LIR_OpDelay(LIR_Op* op, CodeEmitInfo* info):
2039     LIR_Op(lir_delay_slot, LIR_OprFact::illegalOpr, info),
2040     _op(op) {
2041     assert(op->code() == lir_nop, "should be filling with nops");
2042   }
2043   virtual void emit_code(LIR_Assembler* masm);
2044   virtual LIR_OpDelay* as_OpDelay() { return this; }
2045   void print_instr(outputStream* out) const PRODUCT_RETURN;
2046   LIR_Op* delay_op() const { return _op; }
2047   CodeEmitInfo* call_info() const { return info(); }
2048 };
2049 
2050 #ifdef ASSERT
2051 // LIR_OpAssert
2052 class LIR_OpAssert : public LIR_Op2 {
2053  friend class LIR_OpVisitState;
2054 
2055  private:
2056   const char* _msg;
2057   bool        _halt;
2058 
2059  public:
2060   LIR_OpAssert(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, const char* msg, bool halt)
2061     : LIR_Op2(lir_assert, condition, opr1, opr2)
2062     , _msg(msg)
2063     , _halt(halt) {
2064   }
2065 
2066   const char* msg() const                        { return _msg; }
2067   bool        halt() const                       { return _halt; }
2068 
2069   virtual void emit_code(LIR_Assembler* masm);
2070   virtual LIR_OpAssert* as_OpAssert()            { return this; }
2071   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2072 };
2073 #endif
2074 
2075 // LIR_OpCompareAndSwap
2076 class LIR_OpCompareAndSwap : public LIR_Op {
2077  friend class LIR_OpVisitState;
2078 
2079  private:
2080   LIR_Opr _addr;
2081   LIR_Opr _cmp_value;
2082   LIR_Opr _new_value;
2083   LIR_Opr _tmp1;
2084   LIR_Opr _tmp2;
2085 
2086  public:
2087   LIR_OpCompareAndSwap(LIR_Code code, LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2088                        LIR_Opr t1, LIR_Opr t2, LIR_Opr result)
2089     : LIR_Op(code, result, nullptr)  // no result, no info
2090     , _addr(addr)
2091     , _cmp_value(cmp_value)
2092     , _new_value(new_value)
2093     , _tmp1(t1)
2094     , _tmp2(t2)                                  { }
2095 
2096   LIR_Opr addr()        const                    { return _addr;  }
2097   LIR_Opr cmp_value()   const                    { return _cmp_value; }
2098   LIR_Opr new_value()   const                    { return _new_value; }
2099   LIR_Opr tmp1()        const                    { return _tmp1;      }
2100   LIR_Opr tmp2()        const                    { return _tmp2;      }
2101 
2102   virtual void emit_code(LIR_Assembler* masm);
2103   virtual LIR_OpCompareAndSwap * as_OpCompareAndSwap () { return this; }
2104   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2105 };
2106 
2107 // LIR_OpProfileCall
2108 class LIR_OpProfileCall : public LIR_Op {
2109  friend class LIR_OpVisitState;
2110 
2111  private:
2112   ciMethod* _profiled_method;
2113   int       _profiled_bci;
2114   ciMethod* _profiled_callee;
2115   LIR_Opr   _mdo;
2116   LIR_Opr   _recv;
2117   LIR_Opr   _tmp1;
2118   ciKlass*  _known_holder;
2119 
2120  public:
2121   // Destroys recv
2122   LIR_OpProfileCall(ciMethod* profiled_method, int profiled_bci, ciMethod* profiled_callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* known_holder)
2123     : LIR_Op(lir_profile_call, LIR_OprFact::illegalOpr, nullptr)  // no result, no info
2124     , _profiled_method(profiled_method)
2125     , _profiled_bci(profiled_bci)
2126     , _profiled_callee(profiled_callee)
2127     , _mdo(mdo)
2128     , _recv(recv)
2129     , _tmp1(t1)
2130     , _known_holder(known_holder)                { }
2131 
2132   ciMethod* profiled_method() const              { return _profiled_method;  }
2133   int       profiled_bci()    const              { return _profiled_bci;     }
2134   ciMethod* profiled_callee() const              { return _profiled_callee;  }
2135   LIR_Opr   mdo()             const              { return _mdo;              }
2136   LIR_Opr   recv()            const              { return _recv;             }
2137   LIR_Opr   tmp1()            const              { return _tmp1;             }
2138   ciKlass*  known_holder()    const              { return _known_holder;     }
2139 
2140   virtual void emit_code(LIR_Assembler* masm);
2141   virtual LIR_OpProfileCall* as_OpProfileCall() { return this; }
2142   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2143   bool should_profile_receiver_type() const {
2144     bool callee_is_static = _profiled_callee->is_loaded() && _profiled_callee->is_static();
2145     bool callee_is_private = _profiled_callee->is_loaded() && _profiled_callee->is_private();
2146     Bytecodes::Code bc = _profiled_method->java_code_at_bci(_profiled_bci);
2147     bool call_is_virtual = (bc == Bytecodes::_invokevirtual && !callee_is_private) || bc == Bytecodes::_invokeinterface;
2148     return C1ProfileVirtualCalls && call_is_virtual && !callee_is_static;
2149   }
2150 };
2151 
2152 // LIR_OpProfileType
2153 class LIR_OpProfileType : public LIR_Op {
2154  friend class LIR_OpVisitState;
2155 
2156  private:
2157   LIR_Opr      _mdp;
2158   LIR_Opr      _obj;
2159   LIR_Opr      _tmp;
2160   ciKlass*     _exact_klass;   // non null if we know the klass statically (no need to load it from _obj)
2161   intptr_t     _current_klass; // what the profiling currently reports
2162   bool         _not_null;      // true if we know statically that _obj cannot be null
2163   bool         _no_conflict;   // true if we're profling parameters, _exact_klass is not null and we know
2164                                // _exact_klass it the only possible type for this parameter in any context.
2165 
2166  public:
2167   // Destroys recv
2168   LIR_OpProfileType(LIR_Opr mdp, LIR_Opr obj, ciKlass* exact_klass, intptr_t current_klass, LIR_Opr tmp, bool not_null, bool no_conflict)
2169     : LIR_Op(lir_profile_type, LIR_OprFact::illegalOpr, nullptr)  // no result, no info
2170     , _mdp(mdp)
2171     , _obj(obj)
2172     , _tmp(tmp)
2173     , _exact_klass(exact_klass)
2174     , _current_klass(current_klass)
2175     , _not_null(not_null)
2176     , _no_conflict(no_conflict) { }
2177 
2178   LIR_Opr      mdp()              const             { return _mdp;              }
2179   LIR_Opr      obj()              const             { return _obj;              }
2180   LIR_Opr      tmp()              const             { return _tmp;              }
2181   ciKlass*     exact_klass()      const             { return _exact_klass;      }
2182   intptr_t     current_klass()    const             { return _current_klass;    }
2183   bool         not_null()         const             { return _not_null;         }
2184   bool         no_conflict()      const             { return _no_conflict;      }
2185 
2186   virtual void emit_code(LIR_Assembler* masm);
2187   virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2188   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2189 };
2190 
2191 // LIR_OpProfileInlineType
2192 class LIR_OpProfileInlineType : public LIR_Op {
2193  friend class LIR_OpVisitState;
2194 
2195  private:
2196   LIR_Opr      _mdp;
2197   LIR_Opr      _obj;
2198   int          _flag;
2199   LIR_Opr      _tmp;
2200   bool         _not_null;      // true if we know statically that _obj cannot be null
2201 
2202  public:
2203   // Destroys recv
2204   LIR_OpProfileInlineType(LIR_Opr mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null)
2205     : LIR_Op(lir_profile_inline_type, LIR_OprFact::illegalOpr, nullptr)  // no result, no info
2206     , _mdp(mdp)
2207     , _obj(obj)
2208     , _flag(flag)
2209     , _tmp(tmp)
2210     , _not_null(not_null) { }
2211 
2212   LIR_Opr      mdp()              const             { return _mdp;              }
2213   LIR_Opr      obj()              const             { return _obj;              }
2214   int          flag()             const             { return _flag;             }
2215   LIR_Opr      tmp()              const             { return _tmp;              }
2216   bool         not_null()         const             { return _not_null;         }
2217 
2218   virtual void emit_code(LIR_Assembler* masm);
2219   virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return this; }
2220   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2221 };
2222 
2223 class LIR_InsertionBuffer;
2224 
2225 //--------------------------------LIR_List---------------------------------------------------
2226 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2227 // The LIR instructions are appended by the LIR_List class itself;
2228 //
2229 // Notes:
2230 // - all offsets are(should be) in bytes
2231 // - local positions are specified with an offset, with offset 0 being local 0
2232 
2233 class LIR_List: public CompilationResourceObj {
2234  private:
2235   LIR_OpList  _operations;
2236 
2237   Compilation*  _compilation;
2238 #ifndef PRODUCT
2239   BlockBegin*   _block;
2240 #endif
2241 #ifdef ASSERT
2242   const char *  _file;
2243   int           _line;
2244 #endif
2245 #ifdef RISCV
2246   LIR_Opr       _cmp_opr1;
2247   LIR_Opr       _cmp_opr2;
2248 #endif
2249 
2250  public:
2251   void append(LIR_Op* op) {
2252     if (op->source() == nullptr)
2253       op->set_source(_compilation->current_instruction());
2254 #ifndef PRODUCT
2255     if (PrintIRWithLIR) {
2256       _compilation->maybe_print_current_instruction();
2257       op->print(); tty->cr();
2258     }
2259 #endif // PRODUCT
2260 
2261 #ifdef RISCV
2262     set_cmp_oprs(op);
2263     // lir_cmp set cmp oprs only on riscv
2264     if (op->code() == lir_cmp) return;
2265 #endif
2266 
2267     _operations.append(op);
2268 
2269 #ifdef ASSERT
2270     op->verify();
2271     op->set_file_and_line(_file, _line);
2272     _file = nullptr;
2273     _line = 0;
2274 #endif
2275   }
2276 
2277   LIR_List(Compilation* compilation, BlockBegin* block = nullptr);
2278 
2279 #ifdef ASSERT
2280   void set_file_and_line(const char * file, int line);
2281 #endif
2282 
2283 #ifdef RISCV
2284   void set_cmp_oprs(LIR_Op* op);
2285 #endif
2286 
2287   //---------- accessors ---------------
2288   LIR_OpList* instructions_list()                { return &_operations; }
2289   int         length() const                     { return _operations.length(); }
2290   LIR_Op*     at(int i) const                    { return _operations.at(i); }
2291 
2292   NOT_PRODUCT(BlockBegin* block() const          { return _block; });
2293 
2294   // insert LIR_Ops in buffer to right places in LIR_List
2295   void append(LIR_InsertionBuffer* buffer);
2296 
2297   //---------- mutators ---------------
2298   void insert_before(int i, LIR_List* op_list)   { _operations.insert_before(i, op_list->instructions_list()); }
2299   void insert_before(int i, LIR_Op* op)          { _operations.insert_before(i, op); }
2300   void remove_at(int i)                          { _operations.remove_at(i); }
2301 
2302   //---------- printing -------------
2303   void print_instructions() PRODUCT_RETURN;
2304 
2305 
2306   //---------- instructions -------------
2307   void call_opt_virtual(ciMethod* method, LIR_Opr receiver, LIR_Opr result,
2308                         address dest, LIR_OprList* arguments,
2309                         CodeEmitInfo* info) {
2310     append(new LIR_OpJavaCall(lir_optvirtual_call, method, receiver, result, dest, arguments, info));
2311   }
2312   void call_static(ciMethod* method, LIR_Opr result,
2313                    address dest, LIR_OprList* arguments, CodeEmitInfo* info) {
2314     append(new LIR_OpJavaCall(lir_static_call, method, LIR_OprFact::illegalOpr, result, dest, arguments, info));
2315   }
2316   void call_icvirtual(ciMethod* method, LIR_Opr receiver, LIR_Opr result,
2317                       address dest, LIR_OprList* arguments, CodeEmitInfo* info) {
2318     append(new LIR_OpJavaCall(lir_icvirtual_call, method, receiver, result, dest, arguments, info));
2319   }
2320   void call_dynamic(ciMethod* method, LIR_Opr receiver, LIR_Opr result,
2321                     address dest, LIR_OprList* arguments, CodeEmitInfo* info) {
2322     append(new LIR_OpJavaCall(lir_dynamic_call, method, receiver, result, dest, arguments, info));
2323   }
2324 
2325   void get_thread(LIR_Opr result)                { append(new LIR_Op0(lir_get_thread, result)); }
2326   void membar()                                  { append(new LIR_Op0(lir_membar)); }
2327   void membar_acquire()                          { append(new LIR_Op0(lir_membar_acquire)); }
2328   void membar_release()                          { append(new LIR_Op0(lir_membar_release)); }
2329   void membar_loadload()                         { append(new LIR_Op0(lir_membar_loadload)); }
2330   void membar_storestore()                       { append(new LIR_Op0(lir_membar_storestore)); }
2331   void membar_loadstore()                        { append(new LIR_Op0(lir_membar_loadstore)); }
2332   void membar_storeload()                        { append(new LIR_Op0(lir_membar_storeload)); }
2333 
2334   void nop()                                     { append(new LIR_Op0(lir_nop)); }
2335 
2336   void std_entry(LIR_Opr receiver)               { append(new LIR_Op0(lir_std_entry, receiver)); }
2337   void osr_entry(LIR_Opr osrPointer)             { append(new LIR_Op0(lir_osr_entry, osrPointer)); }
2338 
2339   void on_spin_wait()                            { append(new LIR_Op0(lir_on_spin_wait)); }
2340 
2341   void branch_destination(Label* lbl)            { append(new LIR_OpLabel(lbl)); }
2342 
2343   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)); }
2344 
2345   // result is a stack location for old backend and vreg for UseLinearScan
2346   // stack_loc_temp is an illegal register for old backend
2347   void roundfp(LIR_Opr reg, LIR_Opr stack_loc_temp, LIR_Opr result) { append(new LIR_OpRoundFP(reg, stack_loc_temp, result)); }
2348   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)); }
2349   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)); }
2350   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)); }
2351   void move_wide(LIR_Address* src, LIR_Opr dst, CodeEmitInfo* info = nullptr) {
2352     if (UseCompressedOops) {
2353       append(new LIR_Op1(lir_move, LIR_OprFact::address(src), dst, src->type(), lir_patch_none, info, lir_move_wide));
2354     } else {
2355       move(src, dst, info);
2356     }
2357   }
2358   void move_wide(LIR_Opr src, LIR_Address* dst, CodeEmitInfo* info = nullptr) {
2359     if (UseCompressedOops) {
2360       append(new LIR_Op1(lir_move, src, LIR_OprFact::address(dst), dst->type(), lir_patch_none, info, lir_move_wide));
2361     } else {
2362       move(src, dst, info);
2363     }
2364   }
2365   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)); }
2366 
2367   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));   }
2368   void oop2reg_patch(jobject o, LIR_Opr reg, CodeEmitInfo* info);
2369 
2370   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));   }
2371   void klass2reg_patch(Metadata* o, LIR_Opr reg, CodeEmitInfo* info);
2372 
2373   void safepoint(LIR_Opr tmp, CodeEmitInfo* info)  { append(new LIR_Op1(lir_safepoint, tmp, info)); }
2374   void return_op(LIR_Opr result)                   { append(new LIR_OpReturn(result)); }
2375 
2376   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)); }
2377 
2378   void logical_and (LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_logic_and,  left, right, dst)); }
2379   void logical_or  (LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_logic_or,   left, right, dst)); }
2380   void logical_xor (LIR_Opr left, LIR_Opr right, LIR_Opr dst) { append(new LIR_Op2(lir_logic_xor,  left, right, dst)); }
2381 
2382   void null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null = false);
2383   void throw_exception(LIR_Opr exceptionPC, LIR_Opr exceptionOop, CodeEmitInfo* info) {
2384     append(new LIR_Op2(lir_throw, exceptionPC, exceptionOop, LIR_OprFact::illegalOpr, info));
2385   }
2386   void unwind_exception(LIR_Opr exceptionOop) {
2387     append(new LIR_Op1(lir_unwind, exceptionOop));
2388   }
2389 
2390   void push(LIR_Opr opr)                                   { append(new LIR_Op1(lir_push, opr)); }
2391   void pop(LIR_Opr reg)                                    { append(new LIR_Op1(lir_pop,  reg)); }
2392 
2393   void cmp(LIR_Condition condition, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = nullptr) {
2394     append(new LIR_Op2(lir_cmp, condition, left, right, info));
2395   }
2396   void cmp(LIR_Condition condition, LIR_Opr left, int right, CodeEmitInfo* info = nullptr) {
2397     cmp(condition, left, LIR_OprFact::intConst(right), info);
2398   }
2399 
2400   void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
2401   void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Address* addr, CodeEmitInfo* info);
2402 
2403   void cmove(LIR_Condition condition, LIR_Opr src1, LIR_Opr src2, LIR_Opr dst, BasicType type,
2404              LIR_Opr cmp_opr1 = LIR_OprFact::illegalOpr, LIR_Opr cmp_opr2 = LIR_OprFact::illegalOpr) {
2405     append(new LIR_Op4(lir_cmove, condition, src1, src2, cmp_opr1, cmp_opr2, dst, type));
2406   }
2407 
2408   void cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2409                 LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2410   void cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2411                LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2412   void cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
2413                LIR_Opr t1, LIR_Opr t2, LIR_Opr result = LIR_OprFact::illegalOpr);
2414 
2415   void abs (LIR_Opr from, LIR_Opr to, LIR_Opr tmp)                { append(new LIR_Op1(lir_abs , from, to, tmp)); }
2416   void negate(LIR_Opr from, LIR_Opr to, LIR_Opr tmp = LIR_OprFact::illegalOpr) { append(new LIR_Op1(lir_neg, from, to, tmp)); }
2417   void sqrt(LIR_Opr from, LIR_Opr to, LIR_Opr tmp)                { append(new LIR_Op1(lir_sqrt, from, to, tmp)); }
2418   void fmad(LIR_Opr from, LIR_Opr from1, LIR_Opr from2, LIR_Opr to) { append(new LIR_Op3(lir_fmad, from, from1, from2, to)); }
2419   void fmaf(LIR_Opr from, LIR_Opr from1, LIR_Opr from2, LIR_Opr to) { append(new LIR_Op3(lir_fmaf, from, from1, from2, to)); }
2420   void f2hf(LIR_Opr from, LIR_Opr to, LIR_Opr tmp)                { append(new LIR_Op1(lir_f2hf, from, to, tmp)); }
2421   void hf2f(LIR_Opr from, LIR_Opr to, LIR_Opr tmp)                { append(new LIR_Op1(lir_hf2f, from, to, tmp)); }
2422 
2423   void add (LIR_Opr left, LIR_Opr right, LIR_Opr res)      { append(new LIR_Op2(lir_add, left, right, res)); }
2424   void sub (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr) { append(new LIR_Op2(lir_sub, left, right, res, info)); }
2425   void mul (LIR_Opr left, LIR_Opr right, LIR_Opr res) { append(new LIR_Op2(lir_mul, left, right, res)); }
2426   void mul (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_mul, left, right, res, tmp)); }
2427   void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr)      { append(new LIR_Op2(lir_div, left, right, res, info)); }
2428   void div (LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_div, left, right, res, tmp)); }
2429   void rem (LIR_Opr left, LIR_Opr right, LIR_Opr res, CodeEmitInfo* info = nullptr)      { append(new LIR_Op2(lir_rem, left, right, res, info)); }
2430 
2431   void volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2432   void volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2433 
2434   void load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2435 
2436   void store_mem_int(jint v,    LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2437   void store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2438   void store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info = nullptr, LIR_PatchCode patch_code = lir_patch_none);
2439   void volatile_store_mem_reg(LIR_Opr src, LIR_Address* address, CodeEmitInfo* info, LIR_PatchCode patch_code = lir_patch_none);
2440   void volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code);
2441 
2442   void idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2443   void idiv(LIR_Opr left, int   right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2444   void irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2445   void irem(LIR_Opr left, int   right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info);
2446 
2447   void allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub);
2448   void allocate_array(LIR_Opr dst, LIR_Opr len, LIR_Opr t1,LIR_Opr t2, LIR_Opr t3,LIR_Opr t4, BasicType type, LIR_Opr klass, CodeStub* stub, bool zero_array = true, bool is_null_free = false);
2449 
2450   // jump is an unconditional branch
2451   void jump(BlockBegin* block) {
2452     append(new LIR_OpBranch(lir_cond_always, block));
2453   }
2454   void jump(CodeStub* stub) {
2455     append(new LIR_OpBranch(lir_cond_always, stub));
2456   }
2457   void branch(LIR_Condition cond, Label* lbl) {
2458     append(new LIR_OpBranch(cond, lbl));
2459   }
2460   // Should not be used for fp comparisons
2461   void branch(LIR_Condition cond, BlockBegin* block) {
2462     append(new LIR_OpBranch(cond, block));
2463   }
2464   // Should not be used for fp comparisons
2465   void branch(LIR_Condition cond, CodeStub* stub) {
2466     append(new LIR_OpBranch(cond, stub));
2467   }
2468   // Should only be used for fp comparisons
2469   void branch(LIR_Condition cond, BlockBegin* block, BlockBegin* unordered) {
2470     append(new LIR_OpBranch(cond, block, unordered));
2471   }
2472 
2473   void shift_left(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2474   void shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2475   void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2476 
2477   void shift_left(LIR_Opr value, int count, LIR_Opr dst)       { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2478   void shift_right(LIR_Opr value, int count, LIR_Opr dst)      { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2479   void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2480 
2481   void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst)        { append(new LIR_Op2(lir_cmp_l2i,  left, right, dst)); }
2482   void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2483 
2484   void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2485     append(new LIR_OpRTCall(routine, tmp, result, arguments));
2486   }
2487 
2488   void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2489                     LIR_OprList* arguments, CodeEmitInfo* info) {
2490     append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2491   }
2492 
2493   void load_stack_address_monitor(int monitor_ix, LIR_Opr dst)  { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2494   void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2495   void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub=nullptr);
2496 
2497   void breakpoint()                                                  { append(new LIR_Op0(lir_breakpoint)); }
2498 
2499   void arraycopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info) { append(new LIR_OpArrayCopy(src, src_pos, dst, dst_pos, length, tmp, expected_type, flags, info)); }
2500 
2501   void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res)  { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2502 
2503   void instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci);
2504   void store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci);
2505   void check_flat_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
2506   void check_null_free_array(LIR_Opr array, LIR_Opr tmp);
2507   void substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
2508                               LIR_Opr tmp1, LIR_Opr tmp2,
2509                               ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
2510                               CodeEmitInfo* info, CodeStub* stub);
2511 
2512   void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2513                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2514                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2515                   ciMethod* profiled_method, int profiled_bci, bool is_null_free);
2516   // MethodData* profiling
2517   void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2518     append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2519   }
2520   void profile_type(LIR_Address* mdp, LIR_Opr obj, ciKlass* exact_klass, intptr_t current_klass, LIR_Opr tmp, bool not_null, bool no_conflict) {
2521     append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2522   }
2523   void profile_inline_type(LIR_Address* mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null) {
2524     append(new LIR_OpProfileInlineType(LIR_OprFact::address(mdp), obj, flag, tmp, not_null));
2525   }
2526 
2527   void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2528   void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2529 
2530   void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2531 
2532 #ifdef ASSERT
2533   void lir_assert(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, const char* msg, bool halt) { append(new LIR_OpAssert(condition, opr1, opr2, msg, halt)); }
2534 #endif
2535 };
2536 
2537 void print_LIR(BlockList* blocks);
2538 
2539 class LIR_InsertionBuffer : public CompilationResourceObj {
2540  private:
2541   LIR_List*   _lir;   // the lir list where ops of this buffer should be inserted later (null when uninitialized)
2542 
2543   // list of insertion points. index and count are stored alternately:
2544   // _index_and_count[i * 2]:     the index into lir list where "count" ops should be inserted
2545   // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
2546   intStack    _index_and_count;
2547 
2548   // the LIR_Ops to be inserted
2549   LIR_OpList  _ops;
2550 
2551   void append_new(int index, int count)  { _index_and_count.append(index); _index_and_count.append(count); }
2552   void set_index_at(int i, int value)    { _index_and_count.at_put((i << 1),     value); }
2553   void set_count_at(int i, int value)    { _index_and_count.at_put((i << 1) + 1, value); }
2554 
2555 #ifdef ASSERT
2556   void verify();
2557 #endif
2558  public:
2559   LIR_InsertionBuffer() : _lir(nullptr), _index_and_count(8), _ops(8) { }
2560 
2561   // must be called before using the insertion buffer
2562   void init(LIR_List* lir)  { assert(!initialized(), "already initialized"); _lir = lir; _index_and_count.clear(); _ops.clear(); }
2563   bool initialized() const  { return _lir != nullptr; }
2564   // called automatically when the buffer is appended to the LIR_List
2565   void finish()             { _lir = nullptr; }
2566 
2567   // accessors
2568   LIR_List*  lir_list() const             { return _lir; }
2569   int number_of_insertion_points() const  { return _index_and_count.length() >> 1; }
2570   int index_at(int i) const               { return _index_and_count.at((i << 1));     }
2571   int count_at(int i) const               { return _index_and_count.at((i << 1) + 1); }
2572 
2573   int number_of_ops() const               { return _ops.length(); }
2574   LIR_Op* op_at(int i) const              { return _ops.at(i); }
2575 
2576   // append an instruction to the buffer
2577   void append(int index, LIR_Op* op);
2578 
2579   // instruction
2580   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)); }
2581 };
2582 
2583 
2584 //
2585 // LIR_OpVisitState is used for manipulating LIR_Ops in an abstract way.
2586 // Calling a LIR_Op's visit function with a LIR_OpVisitState causes
2587 // information about the input, output and temporaries used by the
2588 // op to be recorded.  It also records whether the op has call semantics
2589 // and also records all the CodeEmitInfos used by this op.
2590 //
2591 
2592 
2593 class LIR_OpVisitState: public StackObj {
2594  public:
2595   typedef enum { inputMode, firstMode = inputMode, tempMode, outputMode, numModes, invalidMode = -1 } OprMode;
2596 
2597   enum {
2598     maxNumberOfOperands = 21,
2599     maxNumberOfInfos = 4
2600   };
2601 
2602  private:
2603   LIR_Op*          _op;
2604 
2605   // optimization: the operands and infos are not stored in a variable-length
2606   //               list, but in a fixed-size array to save time of size checks and resizing
2607   int              _oprs_len[numModes];
2608   LIR_Opr*         _oprs_new[numModes][maxNumberOfOperands];
2609   int _info_len;
2610   CodeEmitInfo*    _info_new[maxNumberOfInfos];
2611 
2612   bool             _has_call;
2613   bool             _has_slow_case;
2614 
2615 
2616   // only include register operands
2617   // addresses are decomposed to the base and index registers
2618   // constants and stack operands are ignored
2619   void append(LIR_Opr& opr, OprMode mode) {
2620     assert(opr->is_valid(), "should not call this otherwise");
2621     assert(mode >= 0 && mode < numModes, "bad mode");
2622 
2623     if (opr->is_register()) {
2624        assert(_oprs_len[mode] < maxNumberOfOperands, "array overflow");
2625       _oprs_new[mode][_oprs_len[mode]++] = &opr;
2626 
2627     } else if (opr->is_pointer()) {
2628       LIR_Address* address = opr->as_address_ptr();
2629       if (address != nullptr) {
2630         // special handling for addresses: add base and index register of the address
2631         // both are always input operands or temp if we want to extend
2632         // their liveness!
2633         if (mode == outputMode) {
2634           mode = inputMode;
2635         }
2636         assert (mode == inputMode || mode == tempMode, "input or temp only for addresses");
2637         if (address->_base->is_valid()) {
2638           assert(address->_base->is_register(), "must be");
2639           assert(_oprs_len[mode] < maxNumberOfOperands, "array overflow");
2640           _oprs_new[mode][_oprs_len[mode]++] = &address->_base;
2641         }
2642         if (address->_index->is_valid()) {
2643           assert(address->_index->is_register(), "must be");
2644           assert(_oprs_len[mode] < maxNumberOfOperands, "array overflow");
2645           _oprs_new[mode][_oprs_len[mode]++] = &address->_index;
2646         }
2647 
2648       } else {
2649         assert(opr->is_constant(), "constant operands are not processed");
2650       }
2651     } else {
2652       assert(opr->is_stack(), "stack operands are not processed");
2653     }
2654   }
2655 
2656   void append(CodeEmitInfo* info) {
2657     assert(info != nullptr, "should not call this otherwise");
2658     assert(_info_len < maxNumberOfInfos, "array overflow");
2659     _info_new[_info_len++] = info;
2660   }
2661 
2662  public:
2663   LIR_OpVisitState()         { reset(); }
2664 
2665   LIR_Op* op() const         { return _op; }
2666   void set_op(LIR_Op* op)    { reset(); _op = op; }
2667 
2668   bool has_call() const      { return _has_call; }
2669   bool has_slow_case() const { return _has_slow_case; }
2670 
2671   void reset() {
2672     _op = nullptr;
2673     _has_call = false;
2674     _has_slow_case = false;
2675 
2676     _oprs_len[inputMode] = 0;
2677     _oprs_len[tempMode] = 0;
2678     _oprs_len[outputMode] = 0;
2679     _info_len = 0;
2680   }
2681 
2682 
2683   int opr_count(OprMode mode) const {
2684     assert(mode >= 0 && mode < numModes, "bad mode");
2685     return _oprs_len[mode];
2686   }
2687 
2688   LIR_Opr opr_at(OprMode mode, int index) const {
2689     assert(mode >= 0 && mode < numModes, "bad mode");
2690     assert(index >= 0 && index < _oprs_len[mode], "index out of bound");
2691     return *_oprs_new[mode][index];
2692   }
2693 
2694   void set_opr_at(OprMode mode, int index, LIR_Opr opr) const {
2695     assert(mode >= 0 && mode < numModes, "bad mode");
2696     assert(index >= 0 && index < _oprs_len[mode], "index out of bound");
2697     *_oprs_new[mode][index] = opr;
2698   }
2699 
2700   int info_count() const {
2701     return _info_len;
2702   }
2703 
2704   CodeEmitInfo* info_at(int index) const {
2705     assert(index < _info_len, "index out of bounds");
2706     return _info_new[index];
2707   }
2708 
2709   XHandlers* all_xhandler();
2710 
2711   // collects all register operands of the instruction
2712   void visit(LIR_Op* op);
2713 
2714 #ifdef ASSERT
2715   // check that an operation has no operands
2716   bool no_operands(LIR_Op* op);
2717 #endif
2718 
2719   // LIR_Op visitor functions use these to fill in the state
2720   void do_input(LIR_Opr& opr)             { append(opr, LIR_OpVisitState::inputMode); }
2721   void do_output(LIR_Opr& opr)            { append(opr, LIR_OpVisitState::outputMode); }
2722   void do_temp(LIR_Opr& opr)              { append(opr, LIR_OpVisitState::tempMode); }
2723   void do_info(CodeEmitInfo* info)        { append(info); }
2724 
2725   void do_stub(CodeStub* stub);
2726   void do_call()                          { _has_call = true; }
2727   void do_slow_case()                     { _has_slow_case = true; }
2728   void do_slow_case(CodeEmitInfo* info) {
2729     _has_slow_case = true;
2730     append(info);
2731   }
2732 };
2733 
2734 
2735 inline LIR_Opr LIR_Opr::illegalOpr()   { return LIR_OprFact::illegalOpr; };
2736 
2737 inline LIR_Opr LIR_Opr::nullOpr()   { return LIR_OprFact::nullOpr; };
2738 
2739 #endif // SHARE_C1_C1_LIR_HPP