1 /*
   2  * Copyright (c) 1999, 2026, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_C1_C1_INSTRUCTION_HPP
  26 #define SHARE_C1_C1_INSTRUCTION_HPP
  27 
  28 #include "c1/c1_Compilation.hpp"
  29 #include "c1/c1_LIR.hpp"
  30 #include "c1/c1_ValueType.hpp"
  31 #include "ci/ciField.hpp"
  32 
  33 // Predefined classes
  34 class ciField;
  35 class ValueStack;
  36 class InstructionPrinter;
  37 class IRScope;
  38 
  39 
  40 // Instruction class hierarchy
  41 //
  42 // All leaf classes in the class hierarchy are concrete classes
  43 // (i.e., are instantiated). All other classes are abstract and
  44 // serve factoring.
  45 
  46 class Instruction;
  47 class   Phi;
  48 class   Local;
  49 class   Constant;
  50 class   AccessField;
  51 class     LoadField;
  52 class     StoreField;
  53 class   AccessArray;
  54 class     ArrayLength;
  55 class     AccessIndexed;
  56 class       LoadIndexed;
  57 class       StoreIndexed;
  58 class   NegateOp;
  59 class   Op2;
  60 class     ArithmeticOp;
  61 class     ShiftOp;
  62 class     LogicOp;
  63 class     CompareOp;
  64 class     IfOp;
  65 class   Convert;
  66 class   NullCheck;
  67 class   TypeCast;
  68 class   OsrEntry;
  69 class   ExceptionObject;
  70 class   StateSplit;
  71 class     Invoke;
  72 class     NewInstance;
  73 class     NewArray;
  74 class       NewTypeArray;
  75 class       NewObjectArray;
  76 class       NewMultiArray;
  77 class     Deoptimize;
  78 class     TypeCheck;
  79 class       CheckCast;
  80 class       InstanceOf;
  81 class     AccessMonitor;
  82 class       MonitorEnter;
  83 class       MonitorExit;
  84 class     Intrinsic;
  85 class     BlockBegin;
  86 class     BlockEnd;
  87 class       Goto;
  88 class       If;
  89 class       Switch;
  90 class         TableSwitch;
  91 class         LookupSwitch;
  92 class       Return;
  93 class       Throw;
  94 class       Base;
  95 class   UnsafeOp;
  96 class     UnsafeGet;
  97 class     UnsafePut;
  98 class     UnsafeGetAndSet;
  99 class   ProfileCall;
 100 class   ProfileReturnType;
 101 class   ProfileACmpTypes;
 102 class   ProfileInvoke;
 103 class   RuntimeCall;
 104 class   MemBar;
 105 class   RangeCheckPredicate;
 106 #ifdef ASSERT
 107 class   Assert;
 108 #endif
 109 
 110 // A Value is a reference to the instruction creating the value
 111 typedef Instruction* Value;
 112 typedef GrowableArray<Value> Values;
 113 typedef GrowableArray<ValueStack*> ValueStackStack;
 114 
 115 // BlockClosure is the base class for block traversal/iteration.
 116 
 117 class BlockClosure: public CompilationResourceObj {
 118  public:
 119   virtual void block_do(BlockBegin* block)       = 0;
 120 };
 121 
 122 
 123 // A simple closure class for visiting the values of an Instruction
 124 class ValueVisitor: public StackObj {
 125  public:
 126   virtual void visit(Value* v) = 0;
 127 };
 128 
 129 
 130 // Some array and list classes
 131 typedef GrowableArray<BlockBegin*> BlockBeginArray;
 132 
 133 class BlockList: public GrowableArray<BlockBegin*> {
 134  public:
 135   BlockList(): GrowableArray<BlockBegin*>() {}
 136   BlockList(const int size): GrowableArray<BlockBegin*>(size) {}
 137   BlockList(const int size, BlockBegin* init): GrowableArray<BlockBegin*>(size, size, init) {}
 138 
 139   void iterate_forward(BlockClosure* closure);
 140   void iterate_backward(BlockClosure* closure);
 141   void values_do(ValueVisitor* f);
 142   void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;
 143 };
 144 
 145 
 146 // InstructionVisitors provide type-based dispatch for instructions.
 147 // For each concrete Instruction class X, a virtual function do_X is
 148 // provided. Functionality that needs to be implemented for all classes
 149 // (e.g., printing, code generation) is factored out into a specialised
 150 // visitor instead of added to the Instruction classes itself.
 151 
 152 class InstructionVisitor: public StackObj {
 153  public:
 154   virtual void do_Phi            (Phi*             x) = 0;
 155   virtual void do_Local          (Local*           x) = 0;
 156   virtual void do_Constant       (Constant*        x) = 0;
 157   virtual void do_LoadField      (LoadField*       x) = 0;
 158   virtual void do_StoreField     (StoreField*      x) = 0;
 159   virtual void do_ArrayLength    (ArrayLength*     x) = 0;
 160   virtual void do_LoadIndexed    (LoadIndexed*     x) = 0;
 161   virtual void do_StoreIndexed   (StoreIndexed*    x) = 0;
 162   virtual void do_NegateOp       (NegateOp*        x) = 0;
 163   virtual void do_ArithmeticOp   (ArithmeticOp*    x) = 0;
 164   virtual void do_ShiftOp        (ShiftOp*         x) = 0;
 165   virtual void do_LogicOp        (LogicOp*         x) = 0;
 166   virtual void do_CompareOp      (CompareOp*       x) = 0;
 167   virtual void do_IfOp           (IfOp*            x) = 0;
 168   virtual void do_Convert        (Convert*         x) = 0;
 169   virtual void do_NullCheck      (NullCheck*       x) = 0;
 170   virtual void do_TypeCast       (TypeCast*        x) = 0;
 171   virtual void do_Invoke         (Invoke*          x) = 0;
 172   virtual void do_NewInstance    (NewInstance*     x) = 0;
 173   virtual void do_NewTypeArray   (NewTypeArray*    x) = 0;
 174   virtual void do_NewObjectArray (NewObjectArray*  x) = 0;
 175   virtual void do_NewMultiArray  (NewMultiArray*   x) = 0;
 176   virtual void do_CheckCast      (CheckCast*       x) = 0;
 177   virtual void do_InstanceOf     (InstanceOf*      x) = 0;
 178   virtual void do_MonitorEnter   (MonitorEnter*    x) = 0;
 179   virtual void do_MonitorExit    (MonitorExit*     x) = 0;
 180   virtual void do_Intrinsic      (Intrinsic*       x) = 0;
 181   virtual void do_BlockBegin     (BlockBegin*      x) = 0;
 182   virtual void do_Goto           (Goto*            x) = 0;
 183   virtual void do_If             (If*              x) = 0;
 184   virtual void do_TableSwitch    (TableSwitch*     x) = 0;
 185   virtual void do_LookupSwitch   (LookupSwitch*    x) = 0;
 186   virtual void do_Return         (Return*          x) = 0;
 187   virtual void do_Throw          (Throw*           x) = 0;
 188   virtual void do_Base           (Base*            x) = 0;
 189   virtual void do_OsrEntry       (OsrEntry*        x) = 0;
 190   virtual void do_ExceptionObject(ExceptionObject* x) = 0;
 191   virtual void do_UnsafeGet      (UnsafeGet*       x) = 0;
 192   virtual void do_UnsafePut      (UnsafePut*       x) = 0;
 193   virtual void do_UnsafeGetAndSet(UnsafeGetAndSet* x) = 0;
 194   virtual void do_ProfileCall    (ProfileCall*     x) = 0;
 195   virtual void do_ProfileReturnType (ProfileReturnType*  x) = 0;
 196   virtual void do_ProfileACmpTypes(ProfileACmpTypes*  x) = 0;
 197   virtual void do_ProfileInvoke  (ProfileInvoke*   x) = 0;
 198   virtual void do_RuntimeCall    (RuntimeCall*     x) = 0;
 199   virtual void do_MemBar         (MemBar*          x) = 0;
 200   virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;
 201 #ifdef ASSERT
 202   virtual void do_Assert         (Assert*          x) = 0;
 203 #endif
 204 };
 205 
 206 
 207 // Hashing support
 208 //
 209 // Note: This hash functions affect the performance
 210 //       of ValueMap - make changes carefully!
 211 
 212 #define HASH1(x1            )                    ((intx)(x1))
 213 #define HASH2(x1, x2        )                    ((HASH1(x1            ) << 7) ^ HASH1(x2))
 214 #define HASH3(x1, x2, x3    )                    ((HASH2(x1, x2        ) << 7) ^ HASH1(x3))
 215 #define HASH4(x1, x2, x3, x4)                    ((HASH3(x1, x2, x3    ) << 7) ^ HASH1(x4))
 216 #define HASH5(x1, x2, x3, x4, x5)                ((HASH4(x1, x2, x3, x4) << 7) ^ HASH1(x5))
 217 
 218 
 219 // The following macros are used to implement instruction-specific hashing.
 220 // By default, each instruction implements hash() and is_equal(Value), used
 221 // for value numbering/common subexpression elimination. The default imple-
 222 // mentation disables value numbering. Each instruction which can be value-
 223 // numbered, should define corresponding hash() and is_equal(Value) functions
 224 // via the macros below. The f arguments specify all the values/op codes, etc.
 225 // that need to be identical for two instructions to be identical.
 226 //
 227 // Note: The default implementation of hash() returns 0 in order to indicate
 228 //       that the instruction should not be considered for value numbering.
 229 //       The currently used hash functions do not guarantee that never a 0
 230 //       is produced. While this is still correct, it may be a performance
 231 //       bug (no value numbering for that node). However, this situation is
 232 //       so unlikely, that we are not going to handle it specially.
 233 
 234 #define HASHING1(class_name, enabled, f1)             \
 235   virtual intx hash() const {                         \
 236     return (enabled) ? HASH2(name(), f1) : 0;         \
 237   }                                                   \
 238   virtual bool is_equal(Value v) const {              \
 239     if (!(enabled)  ) return false;                   \
 240     class_name* _v = v->as_##class_name();            \
 241     if (_v == nullptr) return false;                  \
 242     if (f1 != _v->f1) return false;                   \
 243     return true;                                      \
 244   }                                                   \
 245 
 246 
 247 #define HASHING2(class_name, enabled, f1, f2)         \
 248   virtual intx hash() const {                         \
 249     return (enabled) ? HASH3(name(), f1, f2) : 0;     \
 250   }                                                   \
 251   virtual bool is_equal(Value v) const {              \
 252     if (!(enabled)  ) return false;                   \
 253     class_name* _v = v->as_##class_name();            \
 254     if (_v == nullptr) return false;                  \
 255     if (f1 != _v->f1) return false;                   \
 256     if (f2 != _v->f2) return false;                   \
 257     return true;                                      \
 258   }                                                   \
 259 
 260 
 261 #define HASHING3(class_name, enabled, f1, f2, f3)     \
 262   virtual intx hash() const {                         \
 263     return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
 264   }                                                   \
 265   virtual bool is_equal(Value v) const {              \
 266     if (!(enabled)  ) return false;                   \
 267     class_name* _v = v->as_##class_name();            \
 268     if (_v == nullptr) return false;                  \
 269     if (f1 != _v->f1) return false;                   \
 270     if (f2 != _v->f2) return false;                   \
 271     if (f3 != _v->f3) return false;                   \
 272     return true;                                      \
 273   }                                                   \
 274 
 275 #define HASHING4(class_name, enabled, f1, f2, f3, f4) \
 276   virtual intx hash() const {                         \
 277     return (enabled) ? HASH5(name(), f1, f2, f3, f4) : 0; \
 278   }                                                   \
 279   virtual bool is_equal(Value v) const {              \
 280     if (!(enabled)) return false;                     \
 281     class_name* _v = v->as_##class_name();            \
 282     if (_v == nullptr) return false;                  \
 283     if (f1 != _v->f1) return false;                   \
 284     if (f2 != _v->f2) return false;                   \
 285     if (f3 != _v->f3) return false;                   \
 286     if (f4 != _v->f4) return false;                   \
 287     return true;                                      \
 288   }                                                   \
 289 
 290 
 291 // The mother of all instructions...
 292 
 293 class Instruction: public CompilationResourceObj {
 294  private:
 295   int          _id;                              // the unique instruction id
 296 #ifndef PRODUCT
 297   int          _printable_bci;                   // the bci of the instruction for printing
 298 #endif
 299   int          _use_count;                       // the number of instructions referring to this value (w/o prev/next); only roots can have use count = 0 or > 1
 300   int          _pin_state;                       // set of PinReason describing the reason for pinning
 301   unsigned int _flags;                           // Flag bits
 302   ValueType*   _type;                            // the instruction value type
 303   Instruction* _next;                            // the next instruction if any (null for BlockEnd instructions)
 304   Instruction* _subst;                           // the substitution instruction if any
 305   LIR_Opr      _operand;                         // LIR specific information
 306 
 307   ValueStack*  _state_before;                    // Copy of state with input operands still on stack (or null)
 308   ValueStack*  _exception_state;                 // Copy of state for exception handling
 309   XHandlers*   _exception_handlers;              // Flat list of exception handlers covering this instruction
 310 
 311   friend class UseCountComputer;
 312   friend class GraphBuilder;
 313 
 314   void update_exception_state(ValueStack* state);
 315 
 316  protected:
 317   BlockBegin*  _block;                           // Block that contains this instruction
 318 
 319   void set_type(ValueType* type) {
 320     assert(type != nullptr, "type must exist");
 321     _type = type;
 322   }
 323 
 324   // Helper class to keep track of which arguments need a null check
 325   class ArgsNonNullState {
 326   private:
 327     int _nonnull_state; // mask identifying which args are nonnull
 328   public:
 329     ArgsNonNullState()
 330       : _nonnull_state(AllBits) {}
 331 
 332     // Does argument number i needs a null check?
 333     bool arg_needs_null_check(int i) const {
 334       // No data is kept for arguments starting at position 33 so
 335       // conservatively assume that they need a null check.
 336       if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
 337         return is_set_nth_bit(_nonnull_state, i);
 338       }
 339       return true;
 340     }
 341 
 342     // Set whether argument number i needs a null check or not
 343     void set_arg_needs_null_check(int i, bool check) {
 344       if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
 345         if (check) {
 346           _nonnull_state |= (int)nth_bit(i);
 347         } else {
 348           _nonnull_state &= (int)~(nth_bit(i));
 349         }
 350       }
 351     }
 352   };
 353 
 354  public:
 355   void* operator new(size_t size) throw() {
 356     Compilation* c = Compilation::current();
 357     void* res = c->arena()->Amalloc(size);
 358     return res;
 359   }
 360 
 361   static const int no_bci = -99;
 362 
 363   enum InstructionFlag {
 364     NeedsNullCheckFlag = 0,
 365     NeverNullFlag,
 366     CanTrapFlag,
 367     DirectCompareFlag,
 368     IsSafepointFlag,
 369     IsStaticFlag,
 370     PreservesStateFlag,
 371     TargetIsFinalFlag,
 372     TargetIsLoadedFlag,
 373     UnorderedIsTrueFlag,
 374     NeedsPatchingFlag,
 375     ThrowIncompatibleClassChangeErrorFlag,
 376     InvokeSpecialReceiverCheckFlag,
 377     ProfileMDOFlag,
 378     IsLinkedInBlockFlag,
 379     NeedsRangeCheckFlag,
 380     DeoptimizeOnException,
 381     KillsMemoryFlag,
 382     OmitChecksFlag,
 383     InstructionLastFlag
 384   };
 385 
 386  public:
 387   bool check_flag(InstructionFlag id) const      { return (_flags & (1 << id)) != 0;    }
 388   void set_flag(InstructionFlag id, bool f)      { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };
 389 
 390   // 'globally' used condition values
 391   enum Condition {
 392     eql, neq, lss, leq, gtr, geq, aeq, beq
 393   };
 394 
 395   // Instructions may be pinned for many reasons and under certain conditions
 396   // with enough knowledge it's possible to safely unpin them.
 397   enum PinReason {
 398       PinUnknown           = 1 << 0
 399     , PinExplicitNullCheck = 1 << 3
 400     , PinStackForStateSplit= 1 << 12
 401     , PinStateSplitConstructor= 1 << 13
 402     , PinGlobalValueNumbering= 1 << 14
 403   };
 404 
 405   static Condition mirror(Condition cond);
 406   static Condition negate(Condition cond);
 407 
 408   // initialization
 409   static int number_of_instructions() {
 410     return Compilation::current()->number_of_instructions();
 411   }
 412 
 413   // creation
 414   Instruction(ValueType* type, ValueStack* state_before = nullptr, bool type_is_constant = false)
 415   : _id(Compilation::current()->get_next_id()),
 416 #ifndef PRODUCT
 417   _printable_bci(-99),
 418 #endif
 419     _use_count(0)
 420   , _pin_state(0)
 421   , _flags(0)
 422   , _type(type)
 423   , _next(nullptr)
 424   , _subst(nullptr)
 425   , _operand(LIR_OprFact::illegalOpr)
 426   , _state_before(state_before)
 427   , _exception_handlers(nullptr)
 428   , _block(nullptr)
 429   {
 430     check_state(state_before);
 431     assert(type != nullptr && (!type->is_constant() || type_is_constant), "type must exist");
 432     update_exception_state(_state_before);
 433   }
 434 
 435   // accessors
 436   int id() const                                 { return _id; }
 437 #ifndef PRODUCT
 438   bool has_printable_bci() const                 { return _printable_bci != -99; }
 439   int printable_bci() const                      { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
 440   void set_printable_bci(int bci)                { _printable_bci = bci; }
 441 #endif
 442   int dominator_depth();
 443   int use_count() const                          { return _use_count; }
 444   int pin_state() const                          { return _pin_state; }
 445   bool is_pinned() const                         { return _pin_state != 0 || PinAllInstructions; }
 446   ValueType* type() const                        { return _type; }
 447   BlockBegin *block() const                      { return _block; }
 448   Instruction* prev();                           // use carefully, expensive operation
 449   Instruction* next() const                      { return _next; }
 450   bool has_subst() const                         { return _subst != nullptr; }
 451   Instruction* subst()                           { return _subst == nullptr ? this : _subst->subst(); }
 452   LIR_Opr operand() const                        { return _operand; }
 453 
 454   void set_needs_null_check(bool f)              { set_flag(NeedsNullCheckFlag, f); }
 455   bool needs_null_check() const                  { return check_flag(NeedsNullCheckFlag); }
 456   void set_null_free(bool f)                     { set_flag(NeverNullFlag, f); }
 457   bool is_null_free() const                      { return check_flag(NeverNullFlag); }
 458   bool is_linked() const                         { return check_flag(IsLinkedInBlockFlag); }
 459   bool can_be_linked()                           { return as_Local() == nullptr && as_Phi() == nullptr; }
 460 
 461   bool is_null_obj()                             { return as_Constant() != nullptr && type()->as_ObjectType()->constant_value()->is_null_object(); }
 462 
 463   bool has_uses() const                          { return use_count() > 0; }
 464   ValueStack* state_before() const               { return _state_before; }
 465   ValueStack* exception_state() const            { return _exception_state; }
 466   virtual bool needs_exception_state() const     { return true; }
 467   XHandlers* exception_handlers() const          { return _exception_handlers; }
 468   ciKlass* as_loaded_klass_or_null() const;
 469 
 470   // manipulation
 471   void pin(PinReason reason)                     { _pin_state |= reason; }
 472   void pin()                                     { _pin_state |= PinUnknown; }
 473   // DANGEROUS: only used by EliminateStores
 474   void unpin(PinReason reason)                   { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
 475 
 476   Instruction* set_next(Instruction* next) {
 477     assert(next->has_printable_bci(), "_printable_bci should have been set");
 478     assert(next != nullptr, "must not be null");
 479     assert(as_BlockEnd() == nullptr, "BlockEnd instructions must have no next");
 480     assert(next->can_be_linked(), "shouldn't link these instructions into list");
 481 
 482     BlockBegin *block = this->block();
 483     next->_block = block;
 484 
 485     next->set_flag(Instruction::IsLinkedInBlockFlag, true);
 486     _next = next;
 487     return next;
 488   }
 489 
 490   Instruction* set_next(Instruction* next, int bci) {
 491 #ifndef PRODUCT
 492     next->set_printable_bci(bci);
 493 #endif
 494     return set_next(next);
 495   }
 496 
 497   // when blocks are merged
 498   void fixup_block_pointers() {
 499     Instruction *cur = next()->next(); // next()'s block is set in set_next
 500     while (cur && cur->_block != block()) {
 501       cur->_block = block();
 502       cur = cur->next();
 503     }
 504   }
 505 
 506   Instruction *insert_after(Instruction *i) {
 507     Instruction* n = _next;
 508     set_next(i);
 509     i->set_next(n);
 510     return _next;
 511   }
 512 
 513   bool is_loaded_flat_array() const;
 514   bool maybe_flat_array() const;
 515   bool maybe_null_free_array() const;
 516 
 517   Instruction *insert_after_same_bci(Instruction *i) {
 518 #ifndef PRODUCT
 519     i->set_printable_bci(printable_bci());
 520 #endif
 521     return insert_after(i);
 522   }
 523 
 524   void set_subst(Instruction* subst)             {
 525     assert(subst == nullptr ||
 526            type()->base() == subst->type()->base() ||
 527            subst->type()->base() == illegalType, "type can't change");
 528     _subst = subst;
 529   }
 530   void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
 531   void set_exception_state(ValueStack* s)        { check_state(s); _exception_state = s; }
 532   void set_state_before(ValueStack* s)           { check_state(s); _state_before = s; }
 533 
 534   // machine-specifics
 535   void set_operand(LIR_Opr operand)              { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
 536   void clear_operand()                           { _operand = LIR_OprFact::illegalOpr; }
 537 
 538   // generic
 539   virtual Instruction*      as_Instruction()     { return this; } // to satisfy HASHING1 macro
 540   virtual Phi*              as_Phi()             { return nullptr; }
 541   virtual Local*            as_Local()           { return nullptr; }
 542   virtual Constant*         as_Constant()        { return nullptr; }
 543   virtual AccessField*      as_AccessField()     { return nullptr; }
 544   virtual LoadField*        as_LoadField()       { return nullptr; }
 545   virtual StoreField*       as_StoreField()      { return nullptr; }
 546   virtual AccessArray*      as_AccessArray()     { return nullptr; }
 547   virtual ArrayLength*      as_ArrayLength()     { return nullptr; }
 548   virtual AccessIndexed*    as_AccessIndexed()   { return nullptr; }
 549   virtual LoadIndexed*      as_LoadIndexed()     { return nullptr; }
 550   virtual StoreIndexed*     as_StoreIndexed()    { return nullptr; }
 551   virtual NegateOp*         as_NegateOp()        { return nullptr; }
 552   virtual Op2*              as_Op2()             { return nullptr; }
 553   virtual ArithmeticOp*     as_ArithmeticOp()    { return nullptr; }
 554   virtual ShiftOp*          as_ShiftOp()         { return nullptr; }
 555   virtual LogicOp*          as_LogicOp()         { return nullptr; }
 556   virtual CompareOp*        as_CompareOp()       { return nullptr; }
 557   virtual IfOp*             as_IfOp()            { return nullptr; }
 558   virtual Convert*          as_Convert()         { return nullptr; }
 559   virtual NullCheck*        as_NullCheck()       { return nullptr; }
 560   virtual OsrEntry*         as_OsrEntry()        { return nullptr; }
 561   virtual StateSplit*       as_StateSplit()      { return nullptr; }
 562   virtual Invoke*           as_Invoke()          { return nullptr; }
 563   virtual NewInstance*      as_NewInstance()     { return nullptr; }
 564   virtual NewArray*         as_NewArray()        { return nullptr; }
 565   virtual NewTypeArray*     as_NewTypeArray()    { return nullptr; }
 566   virtual NewObjectArray*   as_NewObjectArray()  { return nullptr; }
 567   virtual NewMultiArray*    as_NewMultiArray()   { return nullptr; }
 568   virtual TypeCheck*        as_TypeCheck()       { return nullptr; }
 569   virtual CheckCast*        as_CheckCast()       { return nullptr; }
 570   virtual InstanceOf*       as_InstanceOf()      { return nullptr; }
 571   virtual TypeCast*         as_TypeCast()        { return nullptr; }
 572   virtual AccessMonitor*    as_AccessMonitor()   { return nullptr; }
 573   virtual MonitorEnter*     as_MonitorEnter()    { return nullptr; }
 574   virtual MonitorExit*      as_MonitorExit()     { return nullptr; }
 575   virtual Intrinsic*        as_Intrinsic()       { return nullptr; }
 576   virtual BlockBegin*       as_BlockBegin()      { return nullptr; }
 577   virtual BlockEnd*         as_BlockEnd()        { return nullptr; }
 578   virtual Goto*             as_Goto()            { return nullptr; }
 579   virtual If*               as_If()              { return nullptr; }
 580   virtual TableSwitch*      as_TableSwitch()     { return nullptr; }
 581   virtual LookupSwitch*     as_LookupSwitch()    { return nullptr; }
 582   virtual Return*           as_Return()          { return nullptr; }
 583   virtual Throw*            as_Throw()           { return nullptr; }
 584   virtual Base*             as_Base()            { return nullptr; }
 585   virtual ExceptionObject*  as_ExceptionObject() { return nullptr; }
 586   virtual UnsafeOp*         as_UnsafeOp()        { return nullptr; }
 587   virtual ProfileInvoke*    as_ProfileInvoke()   { return nullptr; }
 588   virtual RangeCheckPredicate* as_RangeCheckPredicate() { return nullptr; }
 589 
 590 #ifdef ASSERT
 591   virtual Assert*           as_Assert()          { return nullptr; }
 592 #endif
 593 
 594   virtual void visit(InstructionVisitor* v)      = 0;
 595 
 596   virtual bool can_trap() const                  { return false; }
 597 
 598   virtual void input_values_do(ValueVisitor* f)   = 0;
 599   virtual void state_values_do(ValueVisitor* f);
 600   virtual void other_values_do(ValueVisitor* f)   { /* usually no other - override on demand */ }
 601           void       values_do(ValueVisitor* f)   { input_values_do(f); state_values_do(f); other_values_do(f); }
 602 
 603   virtual ciType* exact_type() const;
 604   virtual ciType* declared_type() const          { return nullptr; }
 605 
 606   // hashing
 607   virtual const char* name() const               = 0;
 608   HASHING1(Instruction, false, id())             // hashing disabled by default
 609 
 610   // debugging
 611   static void check_state(ValueStack* state)     PRODUCT_RETURN;
 612   void print()                                   PRODUCT_RETURN;
 613   void print_line()                              PRODUCT_RETURN;
 614   void print(InstructionPrinter& ip)             PRODUCT_RETURN;
 615 };
 616 
 617 
 618 // The following macros are used to define base (i.e., non-leaf)
 619 // and leaf instruction classes. They define class-name related
 620 // generic functionality in one place.
 621 
 622 #define BASE(class_name, super_class_name)       \
 623   class class_name: public super_class_name {    \
 624    public:                                       \
 625     virtual class_name* as_##class_name()        { return this; }              \
 626 
 627 
 628 #define LEAF(class_name, super_class_name)       \
 629   BASE(class_name, super_class_name)             \
 630    public:                                       \
 631     virtual const char* name() const             { return #class_name; }       \
 632     virtual void visit(InstructionVisitor* v)    { v->do_##class_name(this); } \
 633 
 634 
 635 // Debugging support
 636 
 637 
 638 #ifdef ASSERT
 639 class AssertValues: public ValueVisitor {
 640   void visit(Value* x)             { assert((*x) != nullptr, "value must exist"); }
 641 };
 642   #define ASSERT_VALUES                          { AssertValues assert_value; values_do(&assert_value); }
 643 #else
 644   #define ASSERT_VALUES
 645 #endif // ASSERT
 646 
 647 
 648 // A Phi is a phi function in the sense of SSA form. It stands for
 649 // the value of a local variable at the beginning of a join block.
 650 // A Phi consists of n operands, one for every incoming branch.
 651 
 652 LEAF(Phi, Instruction)
 653  private:
 654   int         _pf_flags; // the flags of the phi function
 655   int         _index;    // to value on operand stack (index < 0) or to local
 656  public:
 657   // creation
 658   Phi(ValueType* type, BlockBegin* b, int index)
 659   : Instruction(type->base())
 660   , _pf_flags(0)
 661   , _index(index)
 662   {
 663     _block = b;
 664     NOT_PRODUCT(set_printable_bci(Value(b)->printable_bci()));
 665     if (type->is_illegal()) {
 666       make_illegal();
 667     }
 668   }
 669 
 670   // flags
 671   enum Flag {
 672     no_flag         = 0,
 673     visited         = 1 << 0,
 674     cannot_simplify = 1 << 1
 675   };
 676 
 677   // accessors
 678   bool  is_local() const          { return _index >= 0; }
 679   bool  is_on_stack() const       { return !is_local(); }
 680   int   local_index() const       { assert(is_local(), ""); return _index; }
 681   int   stack_index() const       { assert(is_on_stack(), ""); return -(_index+1); }
 682 
 683   Value operand_at(int i) const;
 684   int   operand_count() const;
 685 
 686   void   set(Flag f)              { _pf_flags |=  f; }
 687   void   clear(Flag f)            { _pf_flags &= ~f; }
 688   bool   is_set(Flag f) const     { return (_pf_flags & f) != 0; }
 689 
 690   // Invalidates phis corresponding to merges of locals of two different types
 691   // (these should never be referenced, otherwise the bytecodes are illegal)
 692   void   make_illegal() {
 693     set(cannot_simplify);
 694     set_type(illegalType);
 695   }
 696 
 697   bool is_illegal() const {
 698     return type()->is_illegal();
 699   }
 700 
 701   // generic
 702   virtual void input_values_do(ValueVisitor* f) {
 703   }
 704 };
 705 
 706 
 707 // A local is a placeholder for an incoming argument to a function call.
 708 LEAF(Local, Instruction)
 709  private:
 710   int      _java_index;                          // the local index within the method to which the local belongs
 711   bool     _is_receiver;                         // if local variable holds the receiver: "this" for non-static methods
 712   ciType*  _declared_type;
 713  public:
 714   // creation
 715   Local(ciType* declared, ValueType* type, int index, bool receiver)
 716     : Instruction(type)
 717     , _java_index(index)
 718     , _is_receiver(receiver)
 719     , _declared_type(declared)
 720   {
 721     NOT_PRODUCT(set_printable_bci(-1));
 722   }
 723 
 724   // accessors
 725   int java_index() const                         { return _java_index; }
 726   bool is_receiver() const                       { return _is_receiver; }
 727 
 728   virtual ciType* declared_type() const          { return _declared_type; }
 729 
 730   // generic
 731   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
 732 };
 733 
 734 
 735 LEAF(Constant, Instruction)
 736  public:
 737   // creation
 738   Constant(ValueType* type):
 739       Instruction(type, nullptr, /*type_is_constant*/ true)
 740   {
 741     assert(type->is_constant(), "must be a constant");
 742   }
 743 
 744   Constant(ValueType* type, ValueStack* state_before, bool kills_memory = false):
 745     Instruction(type, state_before, /*type_is_constant*/ true)
 746   {
 747     assert(state_before != nullptr, "only used for constants which need patching");
 748     assert(type->is_constant(), "must be a constant");
 749     set_flag(KillsMemoryFlag, kills_memory);
 750     pin(); // since it's patching it needs to be pinned
 751   }
 752 
 753   // generic
 754   virtual bool can_trap() const                  { return state_before() != nullptr; }
 755   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
 756 
 757   virtual intx hash() const;
 758   virtual bool is_equal(Value v) const;
 759 
 760   virtual ciType* exact_type() const;
 761 
 762   bool kills_memory() const { return check_flag(KillsMemoryFlag); }
 763 
 764   enum CompareResult { not_comparable = -1, cond_false, cond_true };
 765 
 766   virtual CompareResult compare(Instruction::Condition condition, Value right) const;
 767   BlockBegin* compare(Instruction::Condition cond, Value right,
 768                       BlockBegin* true_sux, BlockBegin* false_sux) const {
 769     switch (compare(cond, right)) {
 770     case not_comparable:
 771       return nullptr;
 772     case cond_false:
 773       return false_sux;
 774     case cond_true:
 775       return true_sux;
 776     default:
 777       ShouldNotReachHere();
 778       return nullptr;
 779     }
 780   }
 781 };
 782 
 783 
 784 BASE(AccessField, Instruction)
 785  private:
 786   Value       _obj;
 787   int         _offset;
 788   ciField*    _field;
 789   NullCheck*  _explicit_null_check;              // For explicit null check elimination
 790 
 791  public:
 792   // creation
 793   AccessField(Value obj, int offset, ciField* field, bool is_static,
 794               ValueStack* state_before, bool needs_patching)
 795   : Instruction(as_ValueType(field->type()->basic_type()), state_before)
 796   , _obj(obj)
 797   , _offset(offset)
 798   , _field(field)
 799   , _explicit_null_check(nullptr)
 800   {
 801     set_needs_null_check(!is_static);
 802     set_flag(IsStaticFlag, is_static);
 803     set_flag(NeedsPatchingFlag, needs_patching);
 804     ASSERT_VALUES
 805     // pin of all instructions with memory access
 806     pin();
 807   }
 808 
 809   // accessors
 810   Value obj() const                              { return _obj; }
 811   int offset() const                             { return _offset; }
 812   ciField* field() const                         { return _field; }
 813   BasicType field_type() const                   { return _field->type()->basic_type(); }
 814   bool is_static() const                         { return check_flag(IsStaticFlag); }
 815   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 816   bool needs_patching() const                    { return check_flag(NeedsPatchingFlag); }
 817 
 818   // Unresolved getstatic and putstatic can cause initialization.
 819   // Technically it occurs at the Constant that materializes the base
 820   // of the static fields but it's simpler to model it here.
 821   bool is_init_point() const                     { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }
 822 
 823   // manipulation
 824 
 825   // Under certain circumstances, if a previous NullCheck instruction
 826   // proved the target object non-null, we can eliminate the explicit
 827   // null check and do an implicit one, simply specifying the debug
 828   // information from the NullCheck. This field should only be consulted
 829   // if needs_null_check() is true.
 830   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 831 
 832   // generic
 833   virtual bool can_trap() const                  { return needs_null_check() || needs_patching(); }
 834   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
 835 };
 836 
 837 
 838 LEAF(LoadField, AccessField)
 839  public:
 840   // creation
 841   LoadField(Value obj, int offset, ciField* field, bool is_static,
 842             ValueStack* state_before, bool needs_patching)
 843   : AccessField(obj, offset, field, is_static, state_before, needs_patching)
 844   {
 845     set_null_free(field->is_null_free());
 846   }
 847 
 848   ciType* declared_type() const;
 849 
 850   // generic; cannot be eliminated if needs patching or if volatile.
 851   HASHING3(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset(), declared_type())
 852 };
 853 
 854 
 855 LEAF(StoreField, AccessField)
 856  private:
 857   Value _value;
 858   ciField* _enclosing_field;   // enclosing field (the flat one) for nested fields
 859 
 860  public:
 861   // creation
 862   StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
 863              ValueStack* state_before, bool needs_patching)
 864     : AccessField(obj, offset, field, is_static, state_before, needs_patching)
 865       , _value(value)
 866       , _enclosing_field(nullptr) {
 867   #ifdef ASSERT
 868     AssertValues assert_value;
 869     values_do(&assert_value);
 870   #endif
 871     pin();
 872   }
 873 
 874   // accessors
 875   Value value() const                            { return _value; }
 876   ciField* enclosing_field() const               { return _enclosing_field; }
 877   void set_enclosing_field(ciField* field)       { _enclosing_field = field; }
 878 
 879   // generic
 880   virtual void input_values_do(ValueVisitor* f)   { AccessField::input_values_do(f); f->visit(&_value); }
 881 };
 882 
 883 
 884 BASE(AccessArray, Instruction)
 885  private:
 886   Value       _array;
 887 
 888  public:
 889   // creation
 890   AccessArray(ValueType* type, Value array, ValueStack* state_before)
 891   : Instruction(type, state_before)
 892   , _array(array)
 893   {
 894     set_needs_null_check(true);
 895     ASSERT_VALUES
 896     pin(); // instruction with side effect (null exception or range check throwing)
 897   }
 898 
 899   Value array() const                            { return _array; }
 900 
 901   // generic
 902   virtual bool can_trap() const                  { return needs_null_check(); }
 903   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_array); }
 904 };
 905 
 906 
 907 LEAF(ArrayLength, AccessArray)
 908  private:
 909   NullCheck*  _explicit_null_check;              // For explicit null check elimination
 910 
 911  public:
 912   // creation
 913   ArrayLength(Value array, ValueStack* state_before)
 914   : AccessArray(intType, array, state_before)
 915   , _explicit_null_check(nullptr) {}
 916 
 917   // accessors
 918   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 919 
 920   // setters
 921   // See LoadField::set_explicit_null_check for documentation
 922   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 923 
 924   // generic
 925   HASHING1(ArrayLength, true, array()->subst())
 926 };
 927 
 928 
 929 BASE(AccessIndexed, AccessArray)
 930  private:
 931   Value     _index;
 932   Value     _length;
 933   BasicType _elt_type;
 934   bool      _mismatched;
 935   ciMethod* _profiled_method;
 936   int       _profiled_bci;
 937 
 938  public:
 939   // creation
 940   AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched)
 941   : AccessArray(as_ValueType(elt_type), array, state_before)
 942   , _index(index)
 943   , _length(length)
 944   , _elt_type(elt_type)
 945   , _mismatched(mismatched)
 946   , _profiled_method(nullptr)
 947   , _profiled_bci(0)
 948   {
 949     set_flag(Instruction::NeedsRangeCheckFlag, true);
 950     ASSERT_VALUES
 951   }
 952 
 953   // accessors
 954   Value index() const                            { return _index; }
 955   Value length() const                           { return _length; }
 956   BasicType elt_type() const                     { return _elt_type; }
 957   bool mismatched() const                        { return _mismatched; }
 958 
 959   void clear_length()                            { _length = nullptr; }
 960   // perform elimination of range checks involving constants
 961   bool compute_needs_range_check();
 962 
 963   // Helpers for MethodData* profiling
 964   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
 965   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
 966   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
 967   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
 968   ciMethod* profiled_method() const                  { return _profiled_method;     }
 969   int       profiled_bci() const                     { return _profiled_bci;        }
 970 
 971   // generic
 972   virtual void input_values_do(ValueVisitor* f)   { AccessArray::input_values_do(f); f->visit(&_index); if (_length != nullptr) f->visit(&_length); }
 973 };
 974 
 975 class DelayedLoadIndexed;
 976 
 977 LEAF(LoadIndexed, AccessIndexed)
 978  private:
 979   NullCheck*  _explicit_null_check;  // For explicit null check elimination
 980   Value _buffer;                     // Buffer for load from flat arrays
 981   DelayedLoadIndexed* _delayed;
 982 
 983  public:
 984   // creation
 985   LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false)
 986   : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
 987   , _explicit_null_check(nullptr), _buffer(nullptr), _delayed(nullptr) {}
 988 
 989   // accessors
 990   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 991 
 992   // setters
 993   // See LoadField::set_explicit_null_check for documentation
 994   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 995 
 996   ciType* exact_type() const;
 997   ciType* declared_type() const;
 998 
 999   Value buffer() const { return _buffer; }
1000 
1001   void set_buffer(Value buffer) {
1002     assert(buffer == nullptr || buffer->as_NewInstance() != nullptr, "LoadIndexed flat array buffer must be a NewInstance");
1003     _buffer = buffer;
1004   }
1005 
1006   DelayedLoadIndexed* delayed() const { return _delayed; }
1007   void set_delayed(DelayedLoadIndexed* delayed) { _delayed = delayed; }
1008 
1009   virtual void input_values_do(ValueVisitor* f) {
1010     AccessIndexed::input_values_do(f);
1011     if (_buffer != nullptr) {
1012       f->visit(&_buffer);
1013       assert(_buffer->as_NewInstance() != nullptr, "LoadIndexed flat array buffer must stay a NewInstance");
1014     }
1015   }
1016 
1017   // generic;
1018   HASHING4(LoadIndexed, delayed() == nullptr && !should_profile(), elt_type(), array()->subst(), index()->subst(), buffer())
1019 };
1020 
1021 // Records a flat-array LoadIndexed while following getfield bytecodes are parsed.
1022 // This allows LIR generation to access the selected field directly, without first
1023 // buffering the enclosing flat-array element.
1024 class DelayedLoadIndexed : public CompilationResourceObj {
1025 private:
1026   LoadIndexed* _load_instr;
1027   ValueStack* _state_before;
1028   ciField* _field;
1029   size_t _offset;
1030  public:
1031   DelayedLoadIndexed(LoadIndexed* load, ValueStack* state_before)
1032   : _load_instr(load)
1033   , _state_before(state_before)
1034   , _field(nullptr)
1035   , _offset(0) { }
1036 
1037   void update(ciField* field, int offset) {
1038     assert(offset >= 0, "must be");
1039     _field = field;
1040     _offset += offset;
1041   }
1042 
1043   LoadIndexed* load_instr() const { return _load_instr; }
1044   ValueStack* state_before() const { return _state_before; }
1045   ciField* field() const { return _field; }
1046   size_t offset() const { return _offset; }
1047 };
1048 
1049 LEAF(StoreIndexed, AccessIndexed)
1050  private:
1051   Value       _value;
1052 
1053   bool      _check_boolean;
1054 
1055  public:
1056   // creation
1057   StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value,
1058                ValueStack* state_before, bool check_boolean, bool mismatched = false)
1059     : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
1060       , _value(value), _check_boolean(check_boolean) {
1061   #ifdef ASSERT
1062     AssertValues assert_value;
1063     values_do(&assert_value);
1064   #endif
1065     pin();
1066   }
1067 
1068 
1069   // accessors
1070   Value value() const                            { return _value; }
1071   bool check_boolean() const                     { return _check_boolean; }
1072 
1073   // Flattened array support
1074   bool is_exact_flat_array_store() const;
1075   // generic
1076   virtual void input_values_do(ValueVisitor* f)   { AccessIndexed::input_values_do(f); f->visit(&_value); }
1077 };
1078 
1079 
1080 LEAF(NegateOp, Instruction)
1081  private:
1082   Value _x;
1083 
1084  public:
1085   // creation
1086   NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
1087     ASSERT_VALUES
1088   }
1089 
1090   // accessors
1091   Value x() const                                { return _x; }
1092 
1093   // generic
1094   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); }
1095 };
1096 
1097 
1098 BASE(Op2, Instruction)
1099  private:
1100   Bytecodes::Code _op;
1101   Value           _x;
1102   Value           _y;
1103 
1104  public:
1105   // creation
1106   Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = nullptr)
1107   : Instruction(type, state_before)
1108   , _op(op)
1109   , _x(x)
1110   , _y(y)
1111   {
1112     ASSERT_VALUES
1113   }
1114 
1115   // accessors
1116   Bytecodes::Code op() const                     { return _op; }
1117   Value x() const                                { return _x; }
1118   Value y() const                                { return _y; }
1119 
1120   // manipulators
1121   void swap_operands() {
1122     assert(is_commutative(), "operation must be commutative");
1123     Value t = _x; _x = _y; _y = t;
1124   }
1125 
1126   // generic
1127   virtual bool is_commutative() const            { return false; }
1128   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); f->visit(&_y); }
1129 };
1130 
1131 
1132 LEAF(ArithmeticOp, Op2)
1133  public:
1134   // creation
1135   ArithmeticOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1136   : Op2(x->type()->meet(y->type()), op, x, y, state_before)
1137   {
1138     if (can_trap()) pin();
1139   }
1140 
1141   // generic
1142   virtual bool is_commutative() const;
1143   virtual bool can_trap() const;
1144   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1145 };
1146 
1147 
1148 LEAF(ShiftOp, Op2)
1149  public:
1150   // creation
1151   ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}
1152 
1153   // generic
1154   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1155 };
1156 
1157 
1158 LEAF(LogicOp, Op2)
1159  public:
1160   // creation
1161   LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}
1162 
1163   // generic
1164   virtual bool is_commutative() const;
1165   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1166 };
1167 
1168 
1169 LEAF(CompareOp, Op2)
1170  public:
1171   // creation
1172   CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1173   : Op2(intType, op, x, y, state_before)
1174   {}
1175 
1176   // generic
1177   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1178 };
1179 
1180 
1181 LEAF(IfOp, Op2)
1182  private:
1183   Value _tval;
1184   Value _fval;
1185   bool _substitutability_check;
1186 
1187  public:
1188   // creation
1189   IfOp(Value x, Condition cond, Value y, Value tval, Value fval, ValueStack* state_before, bool substitutability_check)
1190   : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1191   , _tval(tval)
1192   , _fval(fval)
1193   , _substitutability_check(substitutability_check)
1194   {
1195     ASSERT_VALUES
1196     assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1197     set_state_before(state_before);
1198   }
1199 
1200   // accessors
1201   virtual bool is_commutative() const;
1202   Bytecodes::Code op() const                     { ShouldNotCallThis(); return Bytecodes::_illegal; }
1203   Condition cond() const                         { return (Condition)Op2::op(); }
1204   Value tval() const                             { return _tval; }
1205   Value fval() const                             { return _fval; }
1206   bool substitutability_check() const            { return _substitutability_check; }
1207   // generic
1208   virtual void input_values_do(ValueVisitor* f)   { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1209 };
1210 
1211 
1212 LEAF(Convert, Instruction)
1213  private:
1214   Bytecodes::Code _op;
1215   Value           _value;
1216 
1217  public:
1218   // creation
1219   Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1220     ASSERT_VALUES
1221   }
1222 
1223   // accessors
1224   Bytecodes::Code op() const                     { return _op; }
1225   Value value() const                            { return _value; }
1226 
1227   // generic
1228   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_value); }
1229   HASHING2(Convert, true, op(), value()->subst())
1230 };
1231 
1232 
1233 LEAF(NullCheck, Instruction)
1234  private:
1235   Value       _obj;
1236 
1237  public:
1238   // creation
1239   NullCheck(Value obj, ValueStack* state_before)
1240   : Instruction(obj->type()->base(), state_before)
1241   , _obj(obj)
1242   {
1243     ASSERT_VALUES
1244     set_can_trap(true);
1245     assert(_obj->type()->is_object(), "null check must be applied to objects only");
1246     pin(Instruction::PinExplicitNullCheck);
1247   }
1248 
1249   // accessors
1250   Value obj() const                              { return _obj; }
1251 
1252   // setters
1253   void set_can_trap(bool can_trap)               { set_flag(CanTrapFlag, can_trap); }
1254 
1255   // generic
1256   virtual bool can_trap() const                  { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
1257   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
1258   HASHING1(NullCheck, true, obj()->subst())
1259 };
1260 
1261 
1262 // This node is supposed to cast the type of another node to a more precise
1263 // declared type.
1264 LEAF(TypeCast, Instruction)
1265  private:
1266   ciType* _declared_type;
1267   Value   _obj;
1268 
1269  public:
1270   // The type of this node is the same type as the object type (and it might be constant).
1271   TypeCast(ciType* type, Value obj, ValueStack* state_before)
1272   : Instruction(obj->type(), state_before, obj->type()->is_constant()),
1273     _declared_type(type),
1274     _obj(obj) {}
1275 
1276   // accessors
1277   ciType* declared_type() const                  { return _declared_type; }
1278   Value   obj() const                            { return _obj; }
1279 
1280   // generic
1281   virtual void input_values_do(ValueVisitor* f)  { f->visit(&_obj); }
1282 };
1283 
1284 
1285 BASE(StateSplit, Instruction)
1286  private:
1287   ValueStack* _state;
1288 
1289  protected:
1290   static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);
1291 
1292  public:
1293   // creation
1294   StateSplit(ValueType* type, ValueStack* state_before = nullptr)
1295   : Instruction(type, state_before)
1296   , _state(nullptr)
1297   {
1298     pin(PinStateSplitConstructor);
1299   }
1300 
1301   // accessors
1302   ValueStack* state() const                      { return _state; }
1303   IRScope* scope() const;                        // the state's scope
1304 
1305   // manipulation
1306   void set_state(ValueStack* state)              { assert(_state == nullptr, "overwriting existing state"); check_state(state); _state = state; }
1307 
1308   // generic
1309   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
1310   virtual void state_values_do(ValueVisitor* f);
1311 };
1312 
1313 
1314 LEAF(Invoke, StateSplit)
1315  private:
1316   Bytecodes::Code _code;
1317   Value           _recv;
1318   Values*         _args;
1319   BasicTypeList*  _signature;
1320   ciMethod*       _target;
1321   ciType*         _return_type;
1322 
1323  public:
1324   // creation
1325   Invoke(Bytecodes::Code code, ciType* return_type, Value recv, Values* args,
1326          ciMethod* target, ValueStack* state_before);
1327 
1328   // accessors
1329   Bytecodes::Code code() const                   { return _code; }
1330   Value receiver() const                         { return _recv; }
1331   bool has_receiver() const                      { return receiver() != nullptr; }
1332   int number_of_arguments() const                { return _args->length(); }
1333   Value argument_at(int i) const                 { return _args->at(i); }
1334   BasicTypeList* signature() const               { return _signature; }
1335   ciMethod* target() const                       { return _target; }
1336 
1337   ciType* declared_type() const;
1338 
1339   // Returns false if target is not loaded
1340   bool target_is_final() const                   { return check_flag(TargetIsFinalFlag); }
1341   bool target_is_loaded() const                  { return check_flag(TargetIsLoadedFlag); }
1342 
1343   // JSR 292 support
1344   bool is_invokedynamic() const                  { return code() == Bytecodes::_invokedynamic; }
1345   bool is_method_handle_intrinsic() const        { return target()->is_method_handle_intrinsic(); }
1346 
1347   virtual bool needs_exception_state() const     { return false; }
1348 
1349   // generic
1350   virtual bool can_trap() const                  { return true; }
1351   virtual void input_values_do(ValueVisitor* f) {
1352     StateSplit::input_values_do(f);
1353     if (has_receiver()) f->visit(&_recv);
1354     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1355   }
1356   virtual void state_values_do(ValueVisitor *f);
1357 };
1358 
1359 
1360 LEAF(NewInstance, StateSplit)
1361  private:
1362   ciInstanceKlass* _klass;
1363   bool _is_unresolved;
1364   bool _needs_state_before;
1365 
1366  public:
1367   // creation
1368   NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved, bool needs_state_before)
1369   : StateSplit(instanceType, state_before)
1370   , _klass(klass), _is_unresolved(is_unresolved), _needs_state_before(needs_state_before)
1371   {}
1372 
1373   // accessors
1374   ciInstanceKlass* klass() const                 { return _klass; }
1375   bool is_unresolved() const                     { return _is_unresolved; }
1376   bool needs_state_before() const                { return _needs_state_before; }
1377 
1378   virtual bool needs_exception_state() const     { return false; }
1379 
1380   // generic
1381   virtual bool can_trap() const                  { return true; }
1382   ciType* exact_type() const;
1383   ciType* declared_type() const;
1384 };
1385 
1386 BASE(NewArray, StateSplit)
1387  private:
1388   Value       _length;
1389 
1390  public:
1391   // creation
1392   NewArray(Value length, ValueStack* state_before)
1393   : StateSplit(objectType, state_before)
1394   , _length(length)
1395   {
1396     // Do not ASSERT_VALUES since length is null for NewMultiArray
1397   }
1398 
1399   // accessors
1400   Value length() const                           { return _length; }
1401 
1402   virtual bool needs_exception_state() const     { return false; }
1403 
1404   ciType* exact_type() const                     { return nullptr; }
1405   ciType* declared_type() const;
1406 
1407   // generic
1408   virtual bool can_trap() const                  { return true; }
1409   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_length); }
1410 };
1411 
1412 
1413 LEAF(NewTypeArray, NewArray)
1414  private:
1415   BasicType _elt_type;
1416   bool _zero_array;
1417 
1418  public:
1419   // creation
1420   NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before, bool zero_array)
1421   : NewArray(length, state_before)
1422   , _elt_type(elt_type)
1423   , _zero_array(zero_array)
1424   {}
1425 
1426   // accessors
1427   BasicType elt_type() const                     { return _elt_type; }
1428   bool zero_array()    const                     { return _zero_array; }
1429   ciType* exact_type() const;
1430 };
1431 
1432 
1433 LEAF(NewObjectArray, NewArray)
1434  private:
1435   ciKlass* _klass;
1436 
1437  public:
1438   // creation
1439   NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before)
1440   : NewArray(length, state_before), _klass(klass) { }
1441 
1442   // accessors
1443   ciKlass* klass() const                         { return _klass; }
1444   ciType* exact_type() const;
1445 };
1446 
1447 
1448 LEAF(NewMultiArray, NewArray)
1449  private:
1450   ciKlass* _klass;
1451   Values*  _dims;
1452 
1453  public:
1454   // creation
1455   NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(nullptr, state_before), _klass(klass), _dims(dims) {
1456     ASSERT_VALUES
1457   }
1458 
1459   // accessors
1460   ciKlass* klass() const                         { return _klass; }
1461   Values* dims() const                           { return _dims; }
1462   int rank() const                               { return dims()->length(); }
1463 
1464   // generic
1465   virtual void input_values_do(ValueVisitor* f) {
1466     // NOTE: we do not call NewArray::input_values_do since "length"
1467     // is meaningless for a multi-dimensional array; passing the
1468     // zeroth element down to NewArray as its length is a bad idea
1469     // since there will be a copy in the "dims" array which doesn't
1470     // get updated, and the value must not be traversed twice. Was bug
1471     // - kbr 4/10/2001
1472     StateSplit::input_values_do(f);
1473     for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1474   }
1475 
1476   ciType* exact_type() const;
1477 };
1478 
1479 
1480 BASE(TypeCheck, StateSplit)
1481  private:
1482   ciKlass*    _klass;
1483   Value       _obj;
1484 
1485   ciMethod* _profiled_method;
1486   int       _profiled_bci;
1487 
1488  public:
1489   // creation
1490   TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1491   : StateSplit(type, state_before), _klass(klass), _obj(obj),
1492     _profiled_method(nullptr), _profiled_bci(0) {
1493     ASSERT_VALUES
1494     set_direct_compare(false);
1495   }
1496 
1497   // accessors
1498   ciKlass* klass() const                         { return _klass; }
1499   Value obj() const                              { return _obj; }
1500   bool is_loaded() const                         { return klass() != nullptr; }
1501   bool direct_compare() const                    { return check_flag(DirectCompareFlag); }
1502 
1503   // manipulation
1504   void set_direct_compare(bool flag)             { set_flag(DirectCompareFlag, flag); }
1505 
1506   // generic
1507   virtual bool can_trap() const                  { return true; }
1508   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1509 
1510   // Helpers for MethodData* profiling
1511   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
1512   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
1513   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
1514   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
1515   ciMethod* profiled_method() const                  { return _profiled_method;     }
1516   int       profiled_bci() const                     { return _profiled_bci;        }
1517 };
1518 
1519 
1520 LEAF(CheckCast, TypeCheck)
1521  public:
1522   // creation
1523   CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1524   : TypeCheck(klass, obj, objectType, state_before) {}
1525 
1526   void set_incompatible_class_change_check() {
1527     set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1528   }
1529   bool is_incompatible_class_change_check() const {
1530     return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1531   }
1532   void set_invokespecial_receiver_check() {
1533     set_flag(InvokeSpecialReceiverCheckFlag, true);
1534   }
1535   bool is_invokespecial_receiver_check() const {
1536     return check_flag(InvokeSpecialReceiverCheckFlag);
1537   }
1538 
1539   virtual bool needs_exception_state() const {
1540     return !is_invokespecial_receiver_check();
1541   }
1542 
1543   ciType* declared_type() const;
1544 };
1545 
1546 
1547 LEAF(InstanceOf, TypeCheck)
1548  public:
1549   // creation
1550   InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
1551 
1552   virtual bool needs_exception_state() const     { return false; }
1553 };
1554 
1555 
1556 BASE(AccessMonitor, StateSplit)
1557  private:
1558   Value       _obj;
1559   int         _monitor_no;
1560 
1561  public:
1562   // creation
1563   AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = nullptr)
1564   : StateSplit(illegalType, state_before)
1565   , _obj(obj)
1566   , _monitor_no(monitor_no)
1567   {
1568     set_needs_null_check(true);
1569     ASSERT_VALUES
1570   }
1571 
1572   // accessors
1573   Value obj() const                              { return _obj; }
1574   int monitor_no() const                         { return _monitor_no; }
1575 
1576   // generic
1577   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1578 };
1579 
1580 
1581 LEAF(MonitorEnter, AccessMonitor)
1582   bool _maybe_inlinetype;
1583  public:
1584   // creation
1585   MonitorEnter(Value obj, int monitor_no, ValueStack* state_before, bool maybe_inlinetype)
1586   : AccessMonitor(obj, monitor_no, state_before)
1587   , _maybe_inlinetype(maybe_inlinetype)
1588   {
1589     ASSERT_VALUES
1590   }
1591 
1592   // accessors
1593   bool maybe_inlinetype() const                   { return _maybe_inlinetype; }
1594 
1595   // generic
1596   virtual bool can_trap() const                  { return true; }
1597 };
1598 
1599 
1600 LEAF(MonitorExit, AccessMonitor)
1601  public:
1602   // creation
1603   MonitorExit(Value obj, int monitor_no)
1604   : AccessMonitor(obj, monitor_no, nullptr)
1605   {
1606     ASSERT_VALUES
1607   }
1608 };
1609 
1610 
1611 LEAF(Intrinsic, StateSplit)
1612  private:
1613   vmIntrinsics::ID _id;
1614   ArgsNonNullState _nonnull_state;
1615   Values*          _args;
1616   Value            _recv;
1617 
1618  public:
1619   // preserves_state can be set to true for Intrinsics
1620   // which are guaranteed to preserve register state across any slow
1621   // cases; setting it to true does not mean that the Intrinsic can
1622   // not trap, only that if we continue execution in the same basic
1623   // block after the Intrinsic, all of the registers are intact. This
1624   // allows load elimination and common expression elimination to be
1625   // performed across the Intrinsic.  The default value is false.
1626   Intrinsic(ValueType* type,
1627             vmIntrinsics::ID id,
1628             Values* args,
1629             bool has_receiver,
1630             ValueStack* state_before,
1631             bool preserves_state,
1632             bool cantrap = true)
1633   : StateSplit(type, state_before)
1634   , _id(id)
1635   , _args(args)
1636   , _recv(nullptr)
1637   {
1638     assert(args != nullptr, "args must exist");
1639     ASSERT_VALUES
1640     set_flag(PreservesStateFlag, preserves_state);
1641     set_flag(CanTrapFlag,        cantrap);
1642     if (has_receiver) {
1643       _recv = argument_at(0);
1644     }
1645     set_needs_null_check(has_receiver);
1646 
1647     // some intrinsics can't trap, so don't force them to be pinned
1648     if (!can_trap() && !vmIntrinsics::should_be_pinned(_id)) {
1649       unpin(PinStateSplitConstructor);
1650     }
1651   }
1652 
1653   // accessors
1654   vmIntrinsics::ID id() const                    { return _id; }
1655   int number_of_arguments() const                { return _args->length(); }
1656   Value argument_at(int i) const                 { return _args->at(i); }
1657 
1658   bool has_receiver() const                      { return (_recv != nullptr); }
1659   Value receiver() const                         { assert(has_receiver(), "must have receiver"); return _recv; }
1660   bool preserves_state() const                   { return check_flag(PreservesStateFlag); }
1661 
1662   bool arg_needs_null_check(int i) const {
1663     return _nonnull_state.arg_needs_null_check(i);
1664   }
1665 
1666   void set_arg_needs_null_check(int i, bool check) {
1667     _nonnull_state.set_arg_needs_null_check(i, check);
1668   }
1669 
1670   // generic
1671   virtual bool can_trap() const                  { return check_flag(CanTrapFlag); }
1672   virtual void input_values_do(ValueVisitor* f) {
1673     StateSplit::input_values_do(f);
1674     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1675   }
1676 };
1677 
1678 
1679 class LIR_List;
1680 
1681 LEAF(BlockBegin, StateSplit)
1682  private:
1683   int        _block_id;                          // the unique block id
1684   int        _bci;                               // start-bci of block
1685   int        _depth_first_number;                // number of this block in a depth-first ordering
1686   int        _linear_scan_number;                // number of this block in linear-scan ordering
1687   int        _dominator_depth;
1688   int        _loop_depth;                        // the loop nesting level of this block
1689   int        _loop_index;                        // number of the innermost loop of this block
1690   int        _flags;                             // the flags associated with this block
1691 
1692   // fields used by BlockListBuilder
1693   int            _total_preds;                   // number of predecessors found by BlockListBuilder
1694   ResourceBitMap _stores_to_locals;              // bit is set when a local variable is stored in the block
1695 
1696   // SSA specific fields: (factor out later)
1697   BlockList   _predecessors;                     // the predecessors of this block
1698   BlockList   _dominates;                        // list of blocks that are dominated by this block
1699   BlockBegin* _dominator;                        // the dominator of this block
1700   // SSA specific ends
1701   BlockEnd*  _end;                               // the last instruction of this block
1702   BlockList  _exception_handlers;                // the exception handlers potentially invoked by this block
1703   ValueStackStack* _exception_states;            // only for xhandler entries: states of all instructions that have an edge to this xhandler
1704   int        _exception_handler_pco;             // if this block is the start of an exception handler,
1705                                                  // this records the PC offset in the assembly code of the
1706                                                  // first instruction in this block
1707   Label      _label;                             // the label associated with this block
1708   LIR_List*  _lir;                               // the low level intermediate representation for this block
1709 
1710   ResourceBitMap _live_in;                       // set of live LIR_Opr registers at entry to this block
1711   ResourceBitMap _live_out;                      // set of live LIR_Opr registers at exit from this block
1712   ResourceBitMap _live_gen;                      // set of registers used before any redefinition in this block
1713   ResourceBitMap _live_kill;                     // set of registers defined in this block
1714 
1715   ResourceBitMap _fpu_register_usage;
1716   int            _first_lir_instruction_id;      // ID of first LIR instruction in this block
1717   int            _last_lir_instruction_id;       // ID of last LIR instruction in this block
1718 
1719   void iterate_preorder (boolArray& mark, BlockClosure* closure);
1720   void iterate_postorder(boolArray& mark, BlockClosure* closure);
1721 
1722   friend class SuxAndWeightAdjuster;
1723 
1724  public:
1725    void* operator new(size_t size) throw() {
1726     Compilation* c = Compilation::current();
1727     void* res = c->arena()->Amalloc(size);
1728     return res;
1729   }
1730 
1731   // initialization/counting
1732   static int  number_of_blocks() {
1733     return Compilation::current()->number_of_blocks();
1734   }
1735 
1736   // creation
1737   BlockBegin(int bci)
1738   : StateSplit(illegalType)
1739   , _block_id(Compilation::current()->get_next_block_id())
1740   , _bci(bci)
1741   , _depth_first_number(-1)
1742   , _linear_scan_number(-1)
1743   , _dominator_depth(-1)
1744   , _loop_depth(0)
1745   , _loop_index(-1)
1746   , _flags(0)
1747   , _total_preds(0)
1748   , _stores_to_locals()
1749   , _predecessors(2)
1750   , _dominates(2)
1751   , _dominator(nullptr)
1752   , _end(nullptr)
1753   , _exception_handlers(1)
1754   , _exception_states(nullptr)
1755   , _exception_handler_pco(-1)
1756   , _lir(nullptr)
1757   , _live_in()
1758   , _live_out()
1759   , _live_gen()
1760   , _live_kill()
1761   , _fpu_register_usage()
1762   , _first_lir_instruction_id(-1)
1763   , _last_lir_instruction_id(-1)
1764   {
1765     _block = this;
1766 #ifndef PRODUCT
1767     set_printable_bci(bci);
1768 #endif
1769   }
1770 
1771   // accessors
1772   int block_id() const                           { return _block_id; }
1773   int bci() const                                { return _bci; }
1774   BlockList* dominates()                         { return &_dominates; }
1775   BlockBegin* dominator() const                  { return _dominator; }
1776   int loop_depth() const                         { return _loop_depth; }
1777   int dominator_depth() const                    { return _dominator_depth; }
1778   int depth_first_number() const                 { return _depth_first_number; }
1779   int linear_scan_number() const                 { return _linear_scan_number; }
1780   BlockEnd* end() const                          { return _end; }
1781   Label* label()                                 { return &_label; }
1782   LIR_List* lir() const                          { return _lir; }
1783   int exception_handler_pco() const              { return _exception_handler_pco; }
1784   ResourceBitMap& live_in()                      { return _live_in;        }
1785   ResourceBitMap& live_out()                     { return _live_out;       }
1786   ResourceBitMap& live_gen()                     { return _live_gen;       }
1787   ResourceBitMap& live_kill()                    { return _live_kill;      }
1788   ResourceBitMap& fpu_register_usage()           { return _fpu_register_usage; }
1789   int first_lir_instruction_id() const           { return _first_lir_instruction_id; }
1790   int last_lir_instruction_id() const            { return _last_lir_instruction_id; }
1791   int total_preds() const                        { return _total_preds; }
1792   BitMap& stores_to_locals()                     { return _stores_to_locals; }
1793 
1794   // manipulation
1795   void set_dominator(BlockBegin* dom)            { _dominator = dom; }
1796   void set_loop_depth(int d)                     { _loop_depth = d; }
1797   void set_dominator_depth(int d)                { _dominator_depth = d; }
1798   void set_depth_first_number(int dfn)           { _depth_first_number = dfn; }
1799   void set_linear_scan_number(int lsn)           { _linear_scan_number = lsn; }
1800   void set_end(BlockEnd* new_end);
1801   static void disconnect_edge(BlockBegin* from, BlockBegin* to);
1802   BlockBegin* insert_block_between(BlockBegin* sux);
1803   void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1804   void set_lir(LIR_List* lir)                    { _lir = lir; }
1805   void set_exception_handler_pco(int pco)        { _exception_handler_pco = pco; }
1806   void set_live_in  (const ResourceBitMap& map)  { _live_in = map;   }
1807   void set_live_out (const ResourceBitMap& map)  { _live_out = map;  }
1808   void set_live_gen (const ResourceBitMap& map)  { _live_gen = map;  }
1809   void set_live_kill(const ResourceBitMap& map)  { _live_kill = map; }
1810   void set_fpu_register_usage(const ResourceBitMap& map) { _fpu_register_usage = map; }
1811   void set_first_lir_instruction_id(int id)      { _first_lir_instruction_id = id;  }
1812   void set_last_lir_instruction_id(int id)       { _last_lir_instruction_id = id;  }
1813   void increment_total_preds(int n = 1)          { _total_preds += n; }
1814   void init_stores_to_locals(int locals_count)   { _stores_to_locals.initialize(locals_count); }
1815 
1816   // generic
1817   virtual void state_values_do(ValueVisitor* f);
1818 
1819   // successors and predecessors
1820   int number_of_sux() const;
1821   BlockBegin* sux_at(int i) const;
1822   void add_predecessor(BlockBegin* pred);
1823   void remove_predecessor(BlockBegin* pred);
1824   bool is_predecessor(BlockBegin* pred) const    { return _predecessors.contains(pred); }
1825   int number_of_preds() const                    { return _predecessors.length(); }
1826   BlockBegin* pred_at(int i) const               { return _predecessors.at(i); }
1827 
1828   // exception handlers potentially invoked by this block
1829   void add_exception_handler(BlockBegin* b);
1830   bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
1831   int  number_of_exception_handlers() const      { return _exception_handlers.length(); }
1832   BlockBegin* exception_handler_at(int i) const  { return _exception_handlers.at(i); }
1833 
1834   // states of the instructions that have an edge to this exception handler
1835   int number_of_exception_states()               { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == nullptr ? 0 : _exception_states->length(); }
1836   ValueStack* exception_state_at(int idx) const  { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
1837   int add_exception_state(ValueStack* state);
1838 
1839   // flags
1840   enum Flag {
1841     no_flag                       = 0,
1842     std_entry_flag                = 1 << 0,
1843     osr_entry_flag                = 1 << 1,
1844     exception_entry_flag          = 1 << 2,
1845     subroutine_entry_flag         = 1 << 3,
1846     backward_branch_target_flag   = 1 << 4,
1847     is_on_work_list_flag          = 1 << 5,
1848     was_visited_flag              = 1 << 6,
1849     parser_loop_header_flag       = 1 << 7,  // set by parser to identify blocks where phi functions can not be created on demand
1850     critical_edge_split_flag      = 1 << 8, // set for all blocks that are introduced when critical edges are split
1851     linear_scan_loop_header_flag  = 1 << 9, // set during loop-detection for LinearScan
1852     linear_scan_loop_end_flag     = 1 << 10, // set during loop-detection for LinearScan
1853     donot_eliminate_range_checks  = 1 << 11  // Should be try to eliminate range checks in this block
1854   };
1855 
1856   void set(Flag f)                               { _flags |= f; }
1857   void clear(Flag f)                             { _flags &= ~f; }
1858   bool is_set(Flag f) const                      { return (_flags & f) != 0; }
1859   bool is_entry_block() const {
1860     const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
1861     return (_flags & entry_mask) != 0;
1862   }
1863 
1864   // iteration
1865   void iterate_preorder   (BlockClosure* closure);
1866   void iterate_postorder  (BlockClosure* closure);
1867 
1868   void block_values_do(ValueVisitor* f);
1869 
1870   // loops
1871   void set_loop_index(int ix)                    { _loop_index = ix;        }
1872   int  loop_index() const                        { return _loop_index;      }
1873 
1874   // merging
1875   bool try_merge(ValueStack* state, bool has_irreducible_loops);  // try to merge states at block begin
1876   void merge(ValueStack* state, bool has_irreducible_loops) {
1877     bool b = try_merge(state, has_irreducible_loops);
1878     assert(b, "merge failed");
1879   }
1880 
1881   // debugging
1882   void print_block()                             PRODUCT_RETURN;
1883   void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
1884 
1885 };
1886 
1887 
1888 BASE(BlockEnd, StateSplit)
1889  private:
1890   BlockList*  _sux;
1891 
1892  protected:
1893   BlockList* sux() const                         { return _sux; }
1894 
1895   void set_sux(BlockList* sux) {
1896 #ifdef ASSERT
1897     assert(sux != nullptr, "sux must exist");
1898     for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != nullptr, "sux must exist");
1899 #endif
1900     _sux = sux;
1901   }
1902 
1903  public:
1904   // creation
1905   BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
1906   : StateSplit(type, state_before)
1907   , _sux(nullptr)
1908   {
1909     set_flag(IsSafepointFlag, is_safepoint);
1910   }
1911 
1912   // accessors
1913   bool is_safepoint() const                      { return check_flag(IsSafepointFlag); }
1914   // For compatibility with old code, for new code use block()
1915   BlockBegin* begin() const                      { return _block; }
1916 
1917   // manipulation
1918   inline void remove_sux_at(int i) { _sux->remove_at(i);}
1919   inline int find_sux(BlockBegin* sux) {return _sux->find(sux);}
1920 
1921   // successors
1922   int number_of_sux() const                      { return _sux != nullptr ? _sux->length() : 0; }
1923   BlockBegin* sux_at(int i) const                { return _sux->at(i); }
1924   bool is_sux(BlockBegin* sux) const             { return _sux == nullptr ? false : _sux->contains(sux); }
1925   BlockBegin* default_sux() const                { return sux_at(number_of_sux() - 1); }
1926   void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1927 };
1928 
1929 
1930 LEAF(Goto, BlockEnd)
1931  public:
1932   enum Direction {
1933     none,            // Just a regular goto
1934     taken, not_taken // Goto produced from If
1935   };
1936  private:
1937   ciMethod*   _profiled_method;
1938   int         _profiled_bci;
1939   Direction   _direction;
1940  public:
1941   // creation
1942   Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)
1943     : BlockEnd(illegalType, state_before, is_safepoint)
1944     , _profiled_method(nullptr)
1945     , _profiled_bci(0)
1946     , _direction(none) {
1947     BlockList* s = new BlockList(1);
1948     s->append(sux);
1949     set_sux(s);
1950   }
1951 
1952   Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, nullptr, is_safepoint)
1953                                            , _profiled_method(nullptr)
1954                                            , _profiled_bci(0)
1955                                            , _direction(none) {
1956     BlockList* s = new BlockList(1);
1957     s->append(sux);
1958     set_sux(s);
1959   }
1960 
1961   bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
1962   ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
1963   int profiled_bci() const                       { return _profiled_bci; }
1964   Direction direction() const                    { return _direction; }
1965 
1966   void set_should_profile(bool value)            { set_flag(ProfileMDOFlag, value); }
1967   void set_profiled_method(ciMethod* method)     { _profiled_method = method; }
1968   void set_profiled_bci(int bci)                 { _profiled_bci = bci; }
1969   void set_direction(Direction d)                { _direction = d; }
1970 };
1971 
1972 #ifdef ASSERT
1973 LEAF(Assert, Instruction)
1974   private:
1975   Value       _x;
1976   Condition   _cond;
1977   Value       _y;
1978   char        *_message;
1979 
1980  public:
1981   // creation
1982   // unordered_is_true is valid for float/double compares only
1983    Assert(Value x, Condition cond, bool unordered_is_true, Value y);
1984 
1985   // accessors
1986   Value x() const                                { return _x; }
1987   Condition cond() const                         { return _cond; }
1988   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
1989   Value y() const                                { return _y; }
1990   const char *message() const                    { return _message; }
1991 
1992   // generic
1993   virtual void input_values_do(ValueVisitor* f)  { f->visit(&_x); f->visit(&_y); }
1994 };
1995 #endif
1996 
1997 LEAF(RangeCheckPredicate, StateSplit)
1998  private:
1999   Value       _x;
2000   Condition   _cond;
2001   Value       _y;
2002 
2003   void check_state();
2004 
2005  public:
2006   // creation
2007   // unordered_is_true is valid for float/double compares only
2008    RangeCheckPredicate(Value x, Condition cond, bool unordered_is_true, Value y, ValueStack* state) : StateSplit(illegalType)
2009   , _x(x)
2010   , _cond(cond)
2011   , _y(y)
2012   {
2013     ASSERT_VALUES
2014     set_flag(UnorderedIsTrueFlag, unordered_is_true);
2015     assert(x->type()->tag() == y->type()->tag(), "types must match");
2016     this->set_state(state);
2017     check_state();
2018   }
2019 
2020   // Always deoptimize
2021   RangeCheckPredicate(ValueStack* state) : StateSplit(illegalType)
2022   {
2023     this->set_state(state);
2024     _x = _y = nullptr;
2025     check_state();
2026   }
2027 
2028   // accessors
2029   Value x() const                                { return _x; }
2030   Condition cond() const                         { return _cond; }
2031   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
2032   Value y() const                                { return _y; }
2033 
2034   void always_fail()                             { _x = _y = nullptr; }
2035 
2036   // generic
2037   virtual void input_values_do(ValueVisitor* f)  { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2038   HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
2039 };
2040 
2041 LEAF(If, BlockEnd)
2042  private:
2043   Value       _x;
2044   Condition   _cond;
2045   Value       _y;
2046   ciMethod*   _profiled_method;
2047   int         _profiled_bci; // Canonicalizer may alter bci of If node
2048   bool        _swapped;      // Is the order reversed with respect to the original If in the
2049                              // bytecode stream?
2050   bool        _substitutability_check;
2051  public:
2052   // creation
2053   // unordered_is_true is valid for float/double compares only
2054   If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint, bool substitutability_check=false)
2055     : BlockEnd(illegalType, state_before, is_safepoint)
2056   , _x(x)
2057   , _cond(cond)
2058   , _y(y)
2059   , _profiled_method(nullptr)
2060   , _profiled_bci(0)
2061   , _swapped(false)
2062   , _substitutability_check(substitutability_check)
2063   {
2064     ASSERT_VALUES
2065     set_flag(UnorderedIsTrueFlag, unordered_is_true);
2066     assert(x->type()->tag() == y->type()->tag(), "types must match");
2067     BlockList* s = new BlockList(2);
2068     s->append(tsux);
2069     s->append(fsux);
2070     set_sux(s);
2071   }
2072 
2073   // accessors
2074   Value x() const                                { return _x; }
2075   Condition cond() const                         { return _cond; }
2076   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
2077   Value y() const                                { return _y; }
2078   BlockBegin* sux_for(bool is_true) const        { return sux_at(is_true ? 0 : 1); }
2079   BlockBegin* tsux() const                       { return sux_for(true); }
2080   BlockBegin* fsux() const                       { return sux_for(false); }
2081   BlockBegin* usux() const                       { return sux_for(unordered_is_true()); }
2082   bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
2083   ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
2084   int profiled_bci() const                       { return _profiled_bci; }    // set for profiled branches and tiered
2085   bool is_swapped() const                        { return _swapped; }
2086 
2087   // manipulation
2088   void swap_operands() {
2089     Value t = _x; _x = _y; _y = t;
2090     _cond = mirror(_cond);
2091   }
2092 
2093   void set_should_profile(bool value)             { set_flag(ProfileMDOFlag, value); }
2094   void set_profiled_method(ciMethod* method)      { _profiled_method = method; }
2095   void set_profiled_bci(int bci)                  { _profiled_bci = bci;       }
2096   void set_swapped(bool value)                    { _swapped = value;         }
2097   bool substitutability_check() const             { return _substitutability_check; }
2098   // generic
2099   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2100 };
2101 
2102 
2103 BASE(Switch, BlockEnd)
2104  private:
2105   Value       _tag;
2106 
2107  public:
2108   // creation
2109   Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
2110   : BlockEnd(illegalType, state_before, is_safepoint)
2111   , _tag(tag) {
2112     ASSERT_VALUES
2113     set_sux(sux);
2114   }
2115 
2116   // accessors
2117   Value tag() const                              { return _tag; }
2118   int length() const                             { return number_of_sux() - 1; }
2119 
2120   virtual bool needs_exception_state() const     { return false; }
2121 
2122   // generic
2123   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_tag); }
2124 };
2125 
2126 
2127 LEAF(TableSwitch, Switch)
2128  private:
2129   int _lo_key;
2130 
2131  public:
2132   // creation
2133   TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
2134     : Switch(tag, sux, state_before, is_safepoint)
2135   , _lo_key(lo_key) { assert(_lo_key <= hi_key(), "integer overflow"); }
2136 
2137   // accessors
2138   int lo_key() const                             { return _lo_key; }
2139   int hi_key() const                             { return _lo_key + (length() - 1); }
2140 };
2141 
2142 
2143 LEAF(LookupSwitch, Switch)
2144  private:
2145   intArray* _keys;
2146 
2147  public:
2148   // creation
2149   LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
2150   : Switch(tag, sux, state_before, is_safepoint)
2151   , _keys(keys) {
2152     assert(keys != nullptr, "keys must exist");
2153     assert(keys->length() == length(), "sux & keys have incompatible lengths");
2154   }
2155 
2156   // accessors
2157   int key_at(int i) const                        { return _keys->at(i); }
2158 };
2159 
2160 
2161 LEAF(Return, BlockEnd)
2162  private:
2163   Value _result;
2164 
2165  public:
2166   // creation
2167   Return(Value result) :
2168     BlockEnd(result == nullptr ? voidType : result->type()->base(), nullptr, true),
2169     _result(result) {}
2170 
2171   // accessors
2172   Value result() const                           { return _result; }
2173   bool has_result() const                        { return result() != nullptr; }
2174 
2175   // generic
2176   virtual void input_values_do(ValueVisitor* f) {
2177     BlockEnd::input_values_do(f);
2178     if (has_result()) f->visit(&_result);
2179   }
2180 };
2181 
2182 
2183 LEAF(Throw, BlockEnd)
2184  private:
2185   Value _exception;
2186 
2187  public:
2188   // creation
2189   Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
2190     ASSERT_VALUES
2191   }
2192 
2193   // accessors
2194   Value exception() const                        { return _exception; }
2195 
2196   // generic
2197   virtual bool can_trap() const                  { return true; }
2198   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_exception); }
2199 };
2200 
2201 
2202 LEAF(Base, BlockEnd)
2203  public:
2204   // creation
2205   Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, nullptr, false) {
2206     assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");
2207     assert(osr_entry == nullptr || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");
2208     BlockList* s = new BlockList(2);
2209     if (osr_entry != nullptr) s->append(osr_entry);
2210     s->append(std_entry); // must be default sux!
2211     set_sux(s);
2212   }
2213 
2214   // accessors
2215   BlockBegin* std_entry() const                  { return default_sux(); }
2216   BlockBegin* osr_entry() const                  { return number_of_sux() < 2 ? nullptr : sux_at(0); }
2217 };
2218 
2219 
2220 LEAF(OsrEntry, Instruction)
2221  public:
2222   // creation
2223 #ifdef _LP64
2224   OsrEntry() : Instruction(longType) { pin(); }
2225 #else
2226   OsrEntry() : Instruction(intType)  { pin(); }
2227 #endif
2228 
2229   // generic
2230   virtual void input_values_do(ValueVisitor* f)   { }
2231 };
2232 
2233 
2234 // Models the incoming exception at a catch site
2235 LEAF(ExceptionObject, Instruction)
2236  public:
2237   // creation
2238   ExceptionObject() : Instruction(objectType) {
2239     pin();
2240   }
2241 
2242   // generic
2243   virtual void input_values_do(ValueVisitor* f)   { }
2244 };
2245 
2246 
2247 BASE(UnsafeOp, Instruction)
2248  private:
2249   Value _object;                                 // Object to be fetched from or mutated
2250   Value _offset;                                 // Offset within object
2251   bool  _is_volatile;                            // true if volatile - dl/JSR166
2252   BasicType _basic_type;                         // ValueType can not express byte-sized integers
2253 
2254  protected:
2255   // creation
2256   UnsafeOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)
2257     : Instruction(is_put ? voidType : as_ValueType(basic_type)),
2258     _object(object), _offset(offset), _is_volatile(is_volatile), _basic_type(basic_type)
2259   {
2260     //Note:  Unsafe ops are not not guaranteed to throw NPE.
2261     // Convservatively, Unsafe operations must be pinned though we could be
2262     // looser about this if we wanted to..
2263     pin();
2264   }
2265 
2266  public:
2267   // accessors
2268   BasicType basic_type()                         { return _basic_type; }
2269   Value object()                                 { return _object; }
2270   Value offset()                                 { return _offset; }
2271   bool  is_volatile()                            { return _is_volatile; }
2272 
2273   // generic
2274   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_object);
2275                                                     f->visit(&_offset); }
2276 };
2277 
2278 LEAF(UnsafeGet, UnsafeOp)
2279  private:
2280   bool _is_raw;
2281  public:
2282   UnsafeGet(BasicType basic_type, Value object, Value offset, bool is_volatile)
2283   : UnsafeOp(basic_type, object, offset, false, is_volatile)
2284   {
2285     ASSERT_VALUES
2286     _is_raw = false;
2287   }
2288   UnsafeGet(BasicType basic_type, Value object, Value offset, bool is_volatile, bool is_raw)
2289   : UnsafeOp(basic_type, object, offset, false, is_volatile), _is_raw(is_raw)
2290   {
2291     ASSERT_VALUES
2292   }
2293 
2294   // accessors
2295   bool is_raw()                             { return _is_raw; }
2296 };
2297 
2298 
2299 LEAF(UnsafePut, UnsafeOp)
2300  private:
2301   Value _value;                                  // Value to be stored
2302  public:
2303   UnsafePut(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)
2304   : UnsafeOp(basic_type, object, offset, true, is_volatile)
2305     , _value(value)
2306   {
2307     ASSERT_VALUES
2308   }
2309 
2310   // accessors
2311   Value value()                                  { return _value; }
2312 
2313   // generic
2314   virtual void input_values_do(ValueVisitor* f)   { UnsafeOp::input_values_do(f);
2315                                                    f->visit(&_value); }
2316 };
2317 
2318 LEAF(UnsafeGetAndSet, UnsafeOp)
2319  private:
2320   Value _value;                                  // Value to be stored
2321   bool  _is_add;
2322  public:
2323   UnsafeGetAndSet(BasicType basic_type, Value object, Value offset, Value value, bool is_add)
2324   : UnsafeOp(basic_type, object, offset, false, false)
2325     , _value(value)
2326     , _is_add(is_add)
2327   {
2328     ASSERT_VALUES
2329   }
2330 
2331   // accessors
2332   bool is_add() const                            { return _is_add; }
2333   Value value()                                  { return _value; }
2334 
2335   // generic
2336   virtual void input_values_do(ValueVisitor* f)   { UnsafeOp::input_values_do(f);
2337                                                    f->visit(&_value); }
2338 };
2339 
2340 LEAF(ProfileCall, Instruction)
2341  private:
2342   ciMethod*        _method;
2343   int              _bci_of_invoke;
2344   ciMethod*        _callee;         // the method that is called at the given bci
2345   Value            _recv;
2346   ciKlass*         _known_holder;
2347   Values*          _obj_args;       // arguments for type profiling
2348   ArgsNonNullState _nonnull_state;  // Do we know whether some arguments are never null?
2349   bool             _inlined;        // Are we profiling a call that is inlined
2350 
2351  public:
2352   ProfileCall(ciMethod* method, int bci, ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined)
2353     : Instruction(voidType)
2354     , _method(method)
2355     , _bci_of_invoke(bci)
2356     , _callee(callee)
2357     , _recv(recv)
2358     , _known_holder(known_holder)
2359     , _obj_args(obj_args)
2360     , _inlined(inlined)
2361   {
2362     // The ProfileCall has side-effects and must occur precisely where located
2363     pin();
2364   }
2365 
2366   ciMethod* method()             const { return _method; }
2367   int bci_of_invoke()            const { return _bci_of_invoke; }
2368   ciMethod* callee()             const { return _callee; }
2369   Value recv()                   const { return _recv; }
2370   ciKlass* known_holder()        const { return _known_holder; }
2371   int nb_profiled_args()         const { return _obj_args == nullptr ? 0 : _obj_args->length(); }
2372   Value profiled_arg_at(int i)   const { return _obj_args->at(i); }
2373   bool arg_needs_null_check(int i) const {
2374     return _nonnull_state.arg_needs_null_check(i);
2375   }
2376   bool inlined()                 const { return _inlined; }
2377 
2378   void set_arg_needs_null_check(int i, bool check) {
2379     _nonnull_state.set_arg_needs_null_check(i, check);
2380   }
2381 
2382   virtual void input_values_do(ValueVisitor* f)   {
2383     if (_recv != nullptr) {
2384       f->visit(&_recv);
2385     }
2386     for (int i = 0; i < nb_profiled_args(); i++) {
2387       f->visit(_obj_args->adr_at(i));
2388     }
2389   }
2390 };
2391 
2392 LEAF(ProfileReturnType, Instruction)
2393  private:
2394   ciMethod*        _method;
2395   ciMethod*        _callee;
2396   int              _bci_of_invoke;
2397   Value            _ret;
2398 
2399  public:
2400   ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
2401     : Instruction(voidType)
2402     , _method(method)
2403     , _callee(callee)
2404     , _bci_of_invoke(bci)
2405     , _ret(ret)
2406   {
2407     set_needs_null_check(true);
2408     // The ProfileReturnType has side-effects and must occur precisely where located
2409     pin();
2410   }
2411 
2412   ciMethod* method()             const { return _method; }
2413   ciMethod* callee()             const { return _callee; }
2414   int bci_of_invoke()            const { return _bci_of_invoke; }
2415   Value ret()                    const { return _ret; }
2416 
2417   virtual void input_values_do(ValueVisitor* f)   {
2418     if (_ret != nullptr) {
2419       f->visit(&_ret);
2420     }
2421   }
2422 };
2423 
2424 LEAF(ProfileACmpTypes, Instruction)
2425  private:
2426   ciMethod*        _method;
2427   int              _bci;
2428   Value            _left;
2429   Value            _right;
2430   bool             _left_maybe_null;
2431   bool             _right_maybe_null;
2432 
2433  public:
2434   ProfileACmpTypes(ciMethod* method, int bci, Value left, Value right)
2435     : Instruction(voidType)
2436     , _method(method)
2437     , _bci(bci)
2438     , _left(left)
2439     , _right(right)
2440   {
2441     // The ProfileACmp has side-effects and must occur precisely where located
2442     pin();
2443     _left_maybe_null = true;
2444     _right_maybe_null = true;
2445   }
2446 
2447   ciMethod* method()             const { return _method; }
2448   int bci()                      const { return _bci; }
2449   Value left()                   const { return _left; }
2450   Value right()                  const { return _right; }
2451   bool left_maybe_null()         const { return _left_maybe_null; }
2452   bool right_maybe_null()        const { return _right_maybe_null; }
2453   void set_left_maybe_null(bool v)     { _left_maybe_null = v; }
2454   void set_right_maybe_null(bool v)    { _right_maybe_null = v; }
2455 
2456   virtual void input_values_do(ValueVisitor* f)   {
2457     if (_left != nullptr) {
2458       f->visit(&_left);
2459     }
2460     if (_right != nullptr) {
2461       f->visit(&_right);
2462     }
2463   }
2464 };
2465 
2466 // Call some C runtime function that doesn't safepoint,
2467 // optionally passing the current thread as the first argument.
2468 LEAF(RuntimeCall, Instruction)
2469  private:
2470   const char* _entry_name;
2471   address     _entry;
2472   Values*     _args;
2473   bool        _pass_thread;  // Pass the JavaThread* as an implicit first argument
2474 
2475  public:
2476   RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2477     : Instruction(type)
2478     , _entry_name(entry_name)
2479     , _entry(entry)
2480     , _args(args)
2481     , _pass_thread(pass_thread) {
2482     ASSERT_VALUES
2483     pin();
2484   }
2485 
2486   const char* entry_name() const  { return _entry_name; }
2487   address entry() const           { return _entry; }
2488   int number_of_arguments() const { return _args->length(); }
2489   Value argument_at(int i) const  { return _args->at(i); }
2490   bool pass_thread() const        { return _pass_thread; }
2491 
2492   virtual void input_values_do(ValueVisitor* f)   {
2493     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
2494   }
2495 };
2496 
2497 // Use to trip invocation counter of an inlined method
2498 
2499 LEAF(ProfileInvoke, Instruction)
2500  private:
2501   ciMethod*   _inlinee;
2502   ValueStack* _state;
2503 
2504  public:
2505   ProfileInvoke(ciMethod* inlinee,  ValueStack* state)
2506     : Instruction(voidType)
2507     , _inlinee(inlinee)
2508     , _state(state)
2509   {
2510     // The ProfileInvoke has side-effects and must occur precisely where located QQQ???
2511     pin();
2512   }
2513 
2514   ciMethod* inlinee()      { return _inlinee; }
2515   ValueStack* state()      { return _state; }
2516   virtual void input_values_do(ValueVisitor*)   {}
2517   virtual void state_values_do(ValueVisitor*);
2518 };
2519 
2520 LEAF(MemBar, Instruction)
2521  private:
2522   LIR_Code _code;
2523 
2524  public:
2525   MemBar(LIR_Code code)
2526     : Instruction(voidType)
2527     , _code(code)
2528   {
2529     pin();
2530   }
2531 
2532   LIR_Code code()           { return _code; }
2533 
2534   virtual void input_values_do(ValueVisitor*)   {}
2535 };
2536 
2537 class BlockPair: public CompilationResourceObj {
2538  private:
2539   BlockBegin* _from;
2540   int _index; // sux index of 'to' block
2541  public:
2542   BlockPair(BlockBegin* from, int index): _from(from), _index(index) {}
2543   BlockBegin* from() const { return _from; }
2544   int index() const        { return _index; }
2545 };
2546 
2547 typedef GrowableArray<BlockPair*> BlockPairList;
2548 
2549 inline int         BlockBegin::number_of_sux() const            { assert(_end != nullptr, "need end"); return _end->number_of_sux(); }
2550 inline BlockBegin* BlockBegin::sux_at(int i) const              { assert(_end != nullptr , "need end"); return _end->sux_at(i); }
2551 
2552 #undef ASSERT_VALUES
2553 
2554 #endif // SHARE_C1_C1_INSTRUCTION_HPP