1 /*
   2  * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_C1_C1_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,          // For "Q" signatures
 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();
 515   bool maybe_null_free_array();
 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, bool null_free)
 716     : Instruction(type)
 717     , _java_index(index)
 718     , _is_receiver(receiver)
 719     , _declared_type(declared)
 720   {
 721     set_null_free(null_free);
 722     NOT_PRODUCT(set_printable_bci(-1));
 723   }
 724 
 725   // accessors
 726   int java_index() const                         { return _java_index; }
 727   bool is_receiver() const                       { return _is_receiver; }
 728 
 729   virtual ciType* declared_type() const          { return _declared_type; }
 730 
 731   // generic
 732   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
 733 };
 734 
 735 
 736 LEAF(Constant, Instruction)
 737  public:
 738   // creation
 739   Constant(ValueType* type):
 740       Instruction(type, nullptr, /*type_is_constant*/ true)
 741   {
 742     assert(type->is_constant(), "must be a constant");
 743   }
 744 
 745   Constant(ValueType* type, ValueStack* state_before, bool kills_memory = false):
 746     Instruction(type, state_before, /*type_is_constant*/ true)
 747   {
 748     assert(state_before != nullptr, "only used for constants which need patching");
 749     assert(type->is_constant(), "must be a constant");
 750     set_flag(KillsMemoryFlag, kills_memory);
 751     pin(); // since it's patching it needs to be pinned
 752   }
 753 
 754   // generic
 755   virtual bool can_trap() const                  { return state_before() != nullptr; }
 756   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
 757 
 758   virtual intx hash() const;
 759   virtual bool is_equal(Value v) const;
 760 
 761   virtual ciType* exact_type() const;
 762 
 763   bool kills_memory() const { return check_flag(KillsMemoryFlag); }
 764 
 765   enum CompareResult { not_comparable = -1, cond_false, cond_true };
 766 
 767   virtual CompareResult compare(Instruction::Condition condition, Value right) const;
 768   BlockBegin* compare(Instruction::Condition cond, Value right,
 769                       BlockBegin* true_sux, BlockBegin* false_sux) const {
 770     switch (compare(cond, right)) {
 771     case not_comparable:
 772       return nullptr;
 773     case cond_false:
 774       return false_sux;
 775     case cond_true:
 776       return true_sux;
 777     default:
 778       ShouldNotReachHere();
 779       return nullptr;
 780     }
 781   }
 782 };
 783 
 784 
 785 BASE(AccessField, Instruction)
 786  private:
 787   Value       _obj;
 788   int         _offset;
 789   ciField*    _field;
 790   NullCheck*  _explicit_null_check;              // For explicit null check elimination
 791 
 792  public:
 793   // creation
 794   AccessField(Value obj, int offset, ciField* field, bool is_static,
 795               ValueStack* state_before, bool needs_patching)
 796   : Instruction(as_ValueType(field->type()->basic_type()), state_before)
 797   , _obj(obj)
 798   , _offset(offset)
 799   , _field(field)
 800   , _explicit_null_check(nullptr)
 801   {
 802     set_needs_null_check(!is_static);
 803     set_flag(IsStaticFlag, is_static);
 804     set_flag(NeedsPatchingFlag, needs_patching);
 805     ASSERT_VALUES
 806     // pin of all instructions with memory access
 807     pin();
 808   }
 809 
 810   // accessors
 811   Value obj() const                              { return _obj; }
 812   int offset() const                             { return _offset; }
 813   ciField* field() const                         { return _field; }
 814   BasicType field_type() const                   { return _field->type()->basic_type(); }
 815   bool is_static() const                         { return check_flag(IsStaticFlag); }
 816   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 817   bool needs_patching() const                    { return check_flag(NeedsPatchingFlag); }
 818 
 819   // Unresolved getstatic and putstatic can cause initialization.
 820   // Technically it occurs at the Constant that materializes the base
 821   // of the static fields but it's simpler to model it here.
 822   bool is_init_point() const                     { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }
 823 
 824   // manipulation
 825 
 826   // Under certain circumstances, if a previous NullCheck instruction
 827   // proved the target object non-null, we can eliminate the explicit
 828   // null check and do an implicit one, simply specifying the debug
 829   // information from the NullCheck. This field should only be consulted
 830   // if needs_null_check() is true.
 831   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 832 
 833   // generic
 834   virtual bool can_trap() const                  { return needs_null_check() || needs_patching(); }
 835   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
 836 };
 837 
 838 
 839 LEAF(LoadField, AccessField)
 840  public:
 841   // creation
 842   LoadField(Value obj, int offset, ciField* field, bool is_static,
 843             ValueStack* state_before, bool needs_patching)
 844   : AccessField(obj, offset, field, is_static, state_before, needs_patching)
 845   {
 846     set_null_free(field->is_null_free());
 847   }
 848 
 849   ciType* declared_type() const;
 850 
 851   // generic; cannot be eliminated if needs patching or if volatile.
 852   HASHING3(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset(), declared_type())
 853 };
 854 
 855 
 856 LEAF(StoreField, AccessField)
 857  private:
 858   Value _value;
 859   ciField* _enclosing_field;   // enclosing field (the flat one) for nested fields
 860 
 861  public:
 862   // creation
 863   StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
 864              ValueStack* state_before, bool needs_patching);
 865 
 866   // accessors
 867   Value value() const                            { return _value; }
 868   ciField* enclosing_field() const               { return _enclosing_field; }
 869   void set_enclosing_field(ciField* field)       { _enclosing_field = field; }
 870 
 871   // generic
 872   virtual void input_values_do(ValueVisitor* f)   { AccessField::input_values_do(f); f->visit(&_value); }
 873 };
 874 
 875 
 876 BASE(AccessArray, Instruction)
 877  private:
 878   Value       _array;
 879 
 880  public:
 881   // creation
 882   AccessArray(ValueType* type, Value array, ValueStack* state_before)
 883   : Instruction(type, state_before)
 884   , _array(array)
 885   {
 886     set_needs_null_check(true);
 887     ASSERT_VALUES
 888     pin(); // instruction with side effect (null exception or range check throwing)
 889   }
 890 
 891   Value array() const                            { return _array; }
 892 
 893   // generic
 894   virtual bool can_trap() const                  { return needs_null_check(); }
 895   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_array); }
 896 };
 897 
 898 
 899 LEAF(ArrayLength, AccessArray)
 900  private:
 901   NullCheck*  _explicit_null_check;              // For explicit null check elimination
 902 
 903  public:
 904   // creation
 905   ArrayLength(Value array, ValueStack* state_before)
 906   : AccessArray(intType, array, state_before)
 907   , _explicit_null_check(nullptr) {}
 908 
 909   // accessors
 910   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 911 
 912   // setters
 913   // See LoadField::set_explicit_null_check for documentation
 914   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 915 
 916   // generic
 917   HASHING1(ArrayLength, true, array()->subst())
 918 };
 919 
 920 
 921 BASE(AccessIndexed, AccessArray)
 922  private:
 923   Value     _index;
 924   Value     _length;
 925   BasicType _elt_type;
 926   bool      _mismatched;
 927   ciMethod* _profiled_method;
 928   int       _profiled_bci;
 929 
 930  public:
 931   // creation
 932   AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched)
 933   : AccessArray(as_ValueType(elt_type), array, state_before)
 934   , _index(index)
 935   , _length(length)
 936   , _elt_type(elt_type)
 937   , _mismatched(mismatched)
 938   , _profiled_method(nullptr), _profiled_bci(0)
 939   {
 940     set_flag(Instruction::NeedsRangeCheckFlag, true);
 941     ASSERT_VALUES
 942   }
 943 
 944   // accessors
 945   Value index() const                            { return _index; }
 946   Value length() const                           { return _length; }
 947   BasicType elt_type() const                     { return _elt_type; }
 948   bool mismatched() const                        { return _mismatched; }
 949 
 950   void clear_length()                            { _length = nullptr; }
 951   // perform elimination of range checks involving constants
 952   bool compute_needs_range_check();
 953 
 954   // Helpers for MethodData* profiling
 955   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
 956   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
 957   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
 958   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
 959   ciMethod* profiled_method() const                  { return _profiled_method;     }
 960   int       profiled_bci() const                     { return _profiled_bci;        }
 961 
 962 
 963   // generic
 964   virtual void input_values_do(ValueVisitor* f)   { AccessArray::input_values_do(f); f->visit(&_index); if (_length != nullptr) f->visit(&_length); }
 965 };
 966 
 967 class DelayedLoadIndexed;
 968 
 969 LEAF(LoadIndexed, AccessIndexed)
 970  private:
 971   NullCheck*  _explicit_null_check;              // For explicit null check elimination
 972   NewInstance* _vt;
 973   DelayedLoadIndexed* _delayed;
 974 
 975  public:
 976   // creation
 977   LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false)
 978   : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
 979   , _explicit_null_check(nullptr), _vt(nullptr), _delayed(nullptr) {}
 980 
 981   // accessors
 982   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 983 
 984   // setters
 985   // See LoadField::set_explicit_null_check for documentation
 986   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 987 
 988   ciType* exact_type() const;
 989   ciType* declared_type() const;
 990 
 991   NewInstance* vt() const { return _vt; }
 992   void set_vt(NewInstance* vt) { _vt = vt; }
 993 
 994   DelayedLoadIndexed* delayed() const { return _delayed; }
 995   void set_delayed(DelayedLoadIndexed* delayed) { _delayed = delayed; }
 996 
 997   // generic;
 998   HASHING4(LoadIndexed, delayed() == nullptr && !should_profile(), elt_type(), array()->subst(), index()->subst(), vt())
 999 };
1000 
1001 class DelayedLoadIndexed : public CompilationResourceObj {
1002 private:
1003   LoadIndexed* _load_instr;
1004   ValueStack* _state_before;
1005   ciField* _field;
1006   int _offset;
1007  public:
1008   DelayedLoadIndexed(LoadIndexed* load, ValueStack* state_before)
1009   : _load_instr(load)
1010   , _state_before(state_before)
1011   , _field(nullptr)
1012   , _offset(0) { }
1013 
1014   void update(ciField* field, int offset) {
1015     _field = field;
1016     _offset += offset;
1017   }
1018 
1019   LoadIndexed* load_instr() const { return _load_instr; }
1020   ValueStack* state_before() const { return _state_before; }
1021   ciField* field() const { return _field; }
1022   int offset() const { return _offset; }
1023 };
1024 
1025 LEAF(StoreIndexed, AccessIndexed)
1026  private:
1027   Value       _value;
1028 
1029   bool      _check_boolean;
1030 
1031  public:
1032   // creation
1033   StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before,
1034                bool check_boolean, bool mismatched = false);
1035 
1036   // accessors
1037   Value value() const                            { return _value; }
1038   bool check_boolean() const                     { return _check_boolean; }
1039 
1040   // Flattened array support
1041   bool is_exact_flat_array_store() const;
1042   // generic
1043   virtual void input_values_do(ValueVisitor* f)   { AccessIndexed::input_values_do(f); f->visit(&_value); }
1044 };
1045 
1046 
1047 LEAF(NegateOp, Instruction)
1048  private:
1049   Value _x;
1050 
1051  public:
1052   // creation
1053   NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
1054     ASSERT_VALUES
1055   }
1056 
1057   // accessors
1058   Value x() const                                { return _x; }
1059 
1060   // generic
1061   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); }
1062 };
1063 
1064 
1065 BASE(Op2, Instruction)
1066  private:
1067   Bytecodes::Code _op;
1068   Value           _x;
1069   Value           _y;
1070 
1071  public:
1072   // creation
1073   Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = nullptr)
1074   : Instruction(type, state_before)
1075   , _op(op)
1076   , _x(x)
1077   , _y(y)
1078   {
1079     ASSERT_VALUES
1080   }
1081 
1082   // accessors
1083   Bytecodes::Code op() const                     { return _op; }
1084   Value x() const                                { return _x; }
1085   Value y() const                                { return _y; }
1086 
1087   // manipulators
1088   void swap_operands() {
1089     assert(is_commutative(), "operation must be commutative");
1090     Value t = _x; _x = _y; _y = t;
1091   }
1092 
1093   // generic
1094   virtual bool is_commutative() const            { return false; }
1095   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); f->visit(&_y); }
1096 };
1097 
1098 
1099 LEAF(ArithmeticOp, Op2)
1100  public:
1101   // creation
1102   ArithmeticOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1103   : Op2(x->type()->meet(y->type()), op, x, y, state_before)
1104   {
1105     if (can_trap()) pin();
1106   }
1107 
1108   // generic
1109   virtual bool is_commutative() const;
1110   virtual bool can_trap() const;
1111   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1112 };
1113 
1114 
1115 LEAF(ShiftOp, Op2)
1116  public:
1117   // creation
1118   ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}
1119 
1120   // generic
1121   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1122 };
1123 
1124 
1125 LEAF(LogicOp, Op2)
1126  public:
1127   // creation
1128   LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}
1129 
1130   // generic
1131   virtual bool is_commutative() const;
1132   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1133 };
1134 
1135 
1136 LEAF(CompareOp, Op2)
1137  public:
1138   // creation
1139   CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1140   : Op2(intType, op, x, y, state_before)
1141   {}
1142 
1143   // generic
1144   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1145 };
1146 
1147 
1148 LEAF(IfOp, Op2)
1149  private:
1150   Value _tval;
1151   Value _fval;
1152   bool _substitutability_check;
1153 
1154  public:
1155   // creation
1156   IfOp(Value x, Condition cond, Value y, Value tval, Value fval, ValueStack* state_before, bool substitutability_check)
1157   : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1158   , _tval(tval)
1159   , _fval(fval)
1160   , _substitutability_check(substitutability_check)
1161   {
1162     ASSERT_VALUES
1163     assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1164     set_state_before(state_before);
1165   }
1166 
1167   // accessors
1168   virtual bool is_commutative() const;
1169   Bytecodes::Code op() const                     { ShouldNotCallThis(); return Bytecodes::_illegal; }
1170   Condition cond() const                         { return (Condition)Op2::op(); }
1171   Value tval() const                             { return _tval; }
1172   Value fval() const                             { return _fval; }
1173   bool substitutability_check() const             { return _substitutability_check; }
1174   // generic
1175   virtual void input_values_do(ValueVisitor* f)   { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1176 };
1177 
1178 
1179 LEAF(Convert, Instruction)
1180  private:
1181   Bytecodes::Code _op;
1182   Value           _value;
1183 
1184  public:
1185   // creation
1186   Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1187     ASSERT_VALUES
1188   }
1189 
1190   // accessors
1191   Bytecodes::Code op() const                     { return _op; }
1192   Value value() const                            { return _value; }
1193 
1194   // generic
1195   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_value); }
1196   HASHING2(Convert, true, op(), value()->subst())
1197 };
1198 
1199 
1200 LEAF(NullCheck, Instruction)
1201  private:
1202   Value       _obj;
1203 
1204  public:
1205   // creation
1206   NullCheck(Value obj, ValueStack* state_before)
1207   : Instruction(obj->type()->base(), state_before)
1208   , _obj(obj)
1209   {
1210     ASSERT_VALUES
1211     set_can_trap(true);
1212     assert(_obj->type()->is_object(), "null check must be applied to objects only");
1213     pin(Instruction::PinExplicitNullCheck);
1214   }
1215 
1216   // accessors
1217   Value obj() const                              { return _obj; }
1218 
1219   // setters
1220   void set_can_trap(bool can_trap)               { set_flag(CanTrapFlag, can_trap); }
1221 
1222   // generic
1223   virtual bool can_trap() const                  { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
1224   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
1225   HASHING1(NullCheck, true, obj()->subst())
1226 };
1227 
1228 
1229 // This node is supposed to cast the type of another node to a more precise
1230 // declared type.
1231 LEAF(TypeCast, Instruction)
1232  private:
1233   ciType* _declared_type;
1234   Value   _obj;
1235 
1236  public:
1237   // The type of this node is the same type as the object type (and it might be constant).
1238   TypeCast(ciType* type, Value obj, ValueStack* state_before)
1239   : Instruction(obj->type(), state_before, obj->type()->is_constant()),
1240     _declared_type(type),
1241     _obj(obj) {}
1242 
1243   // accessors
1244   ciType* declared_type() const                  { return _declared_type; }
1245   Value   obj() const                            { return _obj; }
1246 
1247   // generic
1248   virtual void input_values_do(ValueVisitor* f)  { f->visit(&_obj); }
1249 };
1250 
1251 
1252 BASE(StateSplit, Instruction)
1253  private:
1254   ValueStack* _state;
1255 
1256  protected:
1257   static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);
1258 
1259  public:
1260   // creation
1261   StateSplit(ValueType* type, ValueStack* state_before = nullptr)
1262   : Instruction(type, state_before)
1263   , _state(nullptr)
1264   {
1265     pin(PinStateSplitConstructor);
1266   }
1267 
1268   // accessors
1269   ValueStack* state() const                      { return _state; }
1270   IRScope* scope() const;                        // the state's scope
1271 
1272   // manipulation
1273   void set_state(ValueStack* state)              { assert(_state == nullptr, "overwriting existing state"); check_state(state); _state = state; }
1274 
1275   // generic
1276   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
1277   virtual void state_values_do(ValueVisitor* f);
1278 };
1279 
1280 
1281 LEAF(Invoke, StateSplit)
1282  private:
1283   Bytecodes::Code _code;
1284   Value           _recv;
1285   Values*         _args;
1286   BasicTypeList*  _signature;
1287   ciMethod*       _target;
1288 
1289  public:
1290   // creation
1291   Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1292          ciMethod* target, ValueStack* state_before);
1293 
1294   // accessors
1295   Bytecodes::Code code() const                   { return _code; }
1296   Value receiver() const                         { return _recv; }
1297   bool has_receiver() const                      { return receiver() != nullptr; }
1298   int number_of_arguments() const                { return _args->length(); }
1299   Value argument_at(int i) const                 { return _args->at(i); }
1300   BasicTypeList* signature() const               { return _signature; }
1301   ciMethod* target() const                       { return _target; }
1302 
1303   ciType* declared_type() const;
1304 
1305   // Returns false if target is not loaded
1306   bool target_is_final() const                   { return check_flag(TargetIsFinalFlag); }
1307   bool target_is_loaded() const                  { return check_flag(TargetIsLoadedFlag); }
1308 
1309   // JSR 292 support
1310   bool is_invokedynamic() const                  { return code() == Bytecodes::_invokedynamic; }
1311   bool is_method_handle_intrinsic() const        { return target()->is_method_handle_intrinsic(); }
1312 
1313   virtual bool needs_exception_state() const     { return false; }
1314 
1315   // generic
1316   virtual bool can_trap() const                  { return true; }
1317   virtual void input_values_do(ValueVisitor* f) {
1318     StateSplit::input_values_do(f);
1319     if (has_receiver()) f->visit(&_recv);
1320     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1321   }
1322   virtual void state_values_do(ValueVisitor *f);
1323 };
1324 
1325 
1326 LEAF(NewInstance, StateSplit)
1327  private:
1328   ciInstanceKlass* _klass;
1329   bool _is_unresolved;
1330   bool _needs_state_before;
1331 
1332  public:
1333   // creation
1334   NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved, bool needs_state_before)
1335   : StateSplit(instanceType, state_before)
1336   , _klass(klass), _is_unresolved(is_unresolved), _needs_state_before(needs_state_before)
1337   {}
1338 
1339   // accessors
1340   ciInstanceKlass* klass() const                 { return _klass; }
1341   bool is_unresolved() const                     { return _is_unresolved; }
1342   bool needs_state_before() const                { return _needs_state_before; }
1343 
1344   virtual bool needs_exception_state() const     { return false; }
1345 
1346   // generic
1347   virtual bool can_trap() const                  { return true; }
1348   ciType* exact_type() const;
1349   ciType* declared_type() const;
1350 };
1351 
1352 BASE(NewArray, StateSplit)
1353  private:
1354   Value       _length;
1355 
1356  public:
1357   // creation
1358   NewArray(Value length, ValueStack* state_before)
1359   : StateSplit(objectType, state_before)
1360   , _length(length)
1361   {
1362     // Do not ASSERT_VALUES since length is null for NewMultiArray
1363   }
1364 
1365   // accessors
1366   Value length() const                           { return _length; }
1367 
1368   virtual bool needs_exception_state() const     { return false; }
1369 
1370   ciType* exact_type() const                     { return nullptr; }
1371   ciType* declared_type() const;
1372 
1373   // generic
1374   virtual bool can_trap() const                  { return true; }
1375   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_length); }
1376 };
1377 
1378 
1379 LEAF(NewTypeArray, NewArray)
1380  private:
1381   BasicType _elt_type;
1382   bool _zero_array;
1383 
1384  public:
1385   // creation
1386   NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before, bool zero_array)
1387   : NewArray(length, state_before)
1388   , _elt_type(elt_type)
1389   , _zero_array(zero_array)
1390   {}
1391 
1392   // accessors
1393   BasicType elt_type() const                     { return _elt_type; }
1394   bool zero_array()    const                     { return _zero_array; }
1395   ciType* exact_type() const;
1396 };
1397 
1398 
1399 LEAF(NewObjectArray, NewArray)
1400  private:
1401   ciKlass* _klass;
1402 
1403  public:
1404   // creation
1405   NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before)
1406   : NewArray(length, state_before), _klass(klass) { }
1407 
1408   // accessors
1409   ciKlass* klass() const                         { return _klass; }
1410   ciType* exact_type() const;
1411 };
1412 
1413 
1414 LEAF(NewMultiArray, NewArray)
1415  private:
1416   ciKlass* _klass;
1417   Values*  _dims;
1418 
1419  public:
1420   // creation
1421   NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(nullptr, state_before), _klass(klass), _dims(dims) {
1422     ASSERT_VALUES
1423   }
1424 
1425   // accessors
1426   ciKlass* klass() const                         { return _klass; }
1427   Values* dims() const                           { return _dims; }
1428   int rank() const                               { return dims()->length(); }
1429 
1430   // generic
1431   virtual void input_values_do(ValueVisitor* f) {
1432     // NOTE: we do not call NewArray::input_values_do since "length"
1433     // is meaningless for a multi-dimensional array; passing the
1434     // zeroth element down to NewArray as its length is a bad idea
1435     // since there will be a copy in the "dims" array which doesn't
1436     // get updated, and the value must not be traversed twice. Was bug
1437     // - kbr 4/10/2001
1438     StateSplit::input_values_do(f);
1439     for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1440   }
1441 
1442   ciType* exact_type() const;
1443 };
1444 
1445 
1446 BASE(TypeCheck, StateSplit)
1447  private:
1448   ciKlass*    _klass;
1449   Value       _obj;
1450 
1451   ciMethod* _profiled_method;
1452   int       _profiled_bci;
1453 
1454  public:
1455   // creation
1456   TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1457   : StateSplit(type, state_before), _klass(klass), _obj(obj),
1458     _profiled_method(nullptr), _profiled_bci(0) {
1459     ASSERT_VALUES
1460     set_direct_compare(false);
1461   }
1462 
1463   // accessors
1464   ciKlass* klass() const                         { return _klass; }
1465   Value obj() const                              { return _obj; }
1466   bool is_loaded() const                         { return klass() != nullptr; }
1467   bool direct_compare() const                    { return check_flag(DirectCompareFlag); }
1468 
1469   // manipulation
1470   void set_direct_compare(bool flag)             { set_flag(DirectCompareFlag, flag); }
1471 
1472   // generic
1473   virtual bool can_trap() const                  { return true; }
1474   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1475 
1476   // Helpers for MethodData* profiling
1477   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
1478   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
1479   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
1480   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
1481   ciMethod* profiled_method() const                  { return _profiled_method;     }
1482   int       profiled_bci() const                     { return _profiled_bci;        }
1483 };
1484 
1485 
1486 LEAF(CheckCast, TypeCheck)
1487  public:
1488   // creation
1489   CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1490   : TypeCheck(klass, obj, objectType, state_before) { }
1491 
1492   void set_incompatible_class_change_check() {
1493     set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1494   }
1495   bool is_incompatible_class_change_check() const {
1496     return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1497   }
1498   void set_invokespecial_receiver_check() {
1499     set_flag(InvokeSpecialReceiverCheckFlag, true);
1500   }
1501   bool is_invokespecial_receiver_check() const {
1502     return check_flag(InvokeSpecialReceiverCheckFlag);
1503   }
1504 
1505   virtual bool needs_exception_state() const {
1506     return !is_invokespecial_receiver_check();
1507   }
1508 
1509   ciType* declared_type() const;
1510 };
1511 
1512 
1513 LEAF(InstanceOf, TypeCheck)
1514  public:
1515   // creation
1516   InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
1517 
1518   virtual bool needs_exception_state() const     { return false; }
1519 };
1520 
1521 
1522 BASE(AccessMonitor, StateSplit)
1523  private:
1524   Value       _obj;
1525   int         _monitor_no;
1526 
1527  public:
1528   // creation
1529   AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = nullptr)
1530   : StateSplit(illegalType, state_before)
1531   , _obj(obj)
1532   , _monitor_no(monitor_no)
1533   {
1534     set_needs_null_check(true);
1535     ASSERT_VALUES
1536   }
1537 
1538   // accessors
1539   Value obj() const                              { return _obj; }
1540   int monitor_no() const                         { return _monitor_no; }
1541 
1542   // generic
1543   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1544 };
1545 
1546 
1547 LEAF(MonitorEnter, AccessMonitor)
1548   bool _maybe_inlinetype;
1549  public:
1550   // creation
1551   MonitorEnter(Value obj, int monitor_no, ValueStack* state_before, bool maybe_inlinetype)
1552   : AccessMonitor(obj, monitor_no, state_before)
1553   , _maybe_inlinetype(maybe_inlinetype)
1554   {
1555     ASSERT_VALUES
1556   }
1557 
1558   // accessors
1559   bool maybe_inlinetype() const                   { return _maybe_inlinetype; }
1560 
1561   // generic
1562   virtual bool can_trap() const                  { return true; }
1563 };
1564 
1565 
1566 LEAF(MonitorExit, AccessMonitor)
1567  public:
1568   // creation
1569   MonitorExit(Value obj, int monitor_no)
1570   : AccessMonitor(obj, monitor_no, nullptr)
1571   {
1572     ASSERT_VALUES
1573   }
1574 };
1575 
1576 
1577 LEAF(Intrinsic, StateSplit)
1578  private:
1579   vmIntrinsics::ID _id;
1580   ArgsNonNullState _nonnull_state;
1581   Values*          _args;
1582   Value            _recv;
1583 
1584  public:
1585   // preserves_state can be set to true for Intrinsics
1586   // which are guaranteed to preserve register state across any slow
1587   // cases; setting it to true does not mean that the Intrinsic can
1588   // not trap, only that if we continue execution in the same basic
1589   // block after the Intrinsic, all of the registers are intact. This
1590   // allows load elimination and common expression elimination to be
1591   // performed across the Intrinsic.  The default value is false.
1592   Intrinsic(ValueType* type,
1593             vmIntrinsics::ID id,
1594             Values* args,
1595             bool has_receiver,
1596             ValueStack* state_before,
1597             bool preserves_state,
1598             bool cantrap = true)
1599   : StateSplit(type, state_before)
1600   , _id(id)
1601   , _args(args)
1602   , _recv(nullptr)
1603   {
1604     assert(args != nullptr, "args must exist");
1605     ASSERT_VALUES
1606     set_flag(PreservesStateFlag, preserves_state);
1607     set_flag(CanTrapFlag,        cantrap);
1608     if (has_receiver) {
1609       _recv = argument_at(0);
1610     }
1611     set_needs_null_check(has_receiver);
1612 
1613     // some intrinsics can't trap, so don't force them to be pinned
1614     if (!can_trap() && !vmIntrinsics::should_be_pinned(_id)) {
1615       unpin(PinStateSplitConstructor);
1616     }
1617   }
1618 
1619   // accessors
1620   vmIntrinsics::ID id() const                    { return _id; }
1621   int number_of_arguments() const                { return _args->length(); }
1622   Value argument_at(int i) const                 { return _args->at(i); }
1623 
1624   bool has_receiver() const                      { return (_recv != nullptr); }
1625   Value receiver() const                         { assert(has_receiver(), "must have receiver"); return _recv; }
1626   bool preserves_state() const                   { return check_flag(PreservesStateFlag); }
1627 
1628   bool arg_needs_null_check(int i) const {
1629     return _nonnull_state.arg_needs_null_check(i);
1630   }
1631 
1632   void set_arg_needs_null_check(int i, bool check) {
1633     _nonnull_state.set_arg_needs_null_check(i, check);
1634   }
1635 
1636   // generic
1637   virtual bool can_trap() const                  { return check_flag(CanTrapFlag); }
1638   virtual void input_values_do(ValueVisitor* f) {
1639     StateSplit::input_values_do(f);
1640     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1641   }
1642 };
1643 
1644 
1645 class LIR_List;
1646 
1647 LEAF(BlockBegin, StateSplit)
1648  private:
1649   int        _block_id;                          // the unique block id
1650   int        _bci;                               // start-bci of block
1651   int        _depth_first_number;                // number of this block in a depth-first ordering
1652   int        _linear_scan_number;                // number of this block in linear-scan ordering
1653   int        _dominator_depth;
1654   int        _loop_depth;                        // the loop nesting level of this block
1655   int        _loop_index;                        // number of the innermost loop of this block
1656   int        _flags;                             // the flags associated with this block
1657 
1658   // fields used by BlockListBuilder
1659   int            _total_preds;                   // number of predecessors found by BlockListBuilder
1660   ResourceBitMap _stores_to_locals;              // bit is set when a local variable is stored in the block
1661 
1662   // SSA specific fields: (factor out later)
1663   BlockList   _predecessors;                     // the predecessors of this block
1664   BlockList   _dominates;                        // list of blocks that are dominated by this block
1665   BlockBegin* _dominator;                        // the dominator of this block
1666   // SSA specific ends
1667   BlockEnd*  _end;                               // the last instruction of this block
1668   BlockList  _exception_handlers;                // the exception handlers potentially invoked by this block
1669   ValueStackStack* _exception_states;            // only for xhandler entries: states of all instructions that have an edge to this xhandler
1670   int        _exception_handler_pco;             // if this block is the start of an exception handler,
1671                                                  // this records the PC offset in the assembly code of the
1672                                                  // first instruction in this block
1673   Label      _label;                             // the label associated with this block
1674   LIR_List*  _lir;                               // the low level intermediate representation for this block
1675 
1676   ResourceBitMap _live_in;                       // set of live LIR_Opr registers at entry to this block
1677   ResourceBitMap _live_out;                      // set of live LIR_Opr registers at exit from this block
1678   ResourceBitMap _live_gen;                      // set of registers used before any redefinition in this block
1679   ResourceBitMap _live_kill;                     // set of registers defined in this block
1680 
1681   ResourceBitMap _fpu_register_usage;
1682   int            _first_lir_instruction_id;      // ID of first LIR instruction in this block
1683   int            _last_lir_instruction_id;       // ID of last LIR instruction in this block
1684 
1685   void iterate_preorder (boolArray& mark, BlockClosure* closure);
1686   void iterate_postorder(boolArray& mark, BlockClosure* closure);
1687 
1688   friend class SuxAndWeightAdjuster;
1689 
1690  public:
1691    void* operator new(size_t size) throw() {
1692     Compilation* c = Compilation::current();
1693     void* res = c->arena()->Amalloc(size);
1694     return res;
1695   }
1696 
1697   // initialization/counting
1698   static int  number_of_blocks() {
1699     return Compilation::current()->number_of_blocks();
1700   }
1701 
1702   // creation
1703   BlockBegin(int bci)
1704   : StateSplit(illegalType)
1705   , _block_id(Compilation::current()->get_next_block_id())
1706   , _bci(bci)
1707   , _depth_first_number(-1)
1708   , _linear_scan_number(-1)
1709   , _dominator_depth(-1)
1710   , _loop_depth(0)
1711   , _loop_index(-1)
1712   , _flags(0)
1713   , _total_preds(0)
1714   , _stores_to_locals()
1715   , _predecessors(2)
1716   , _dominates(2)
1717   , _dominator(nullptr)
1718   , _end(nullptr)
1719   , _exception_handlers(1)
1720   , _exception_states(nullptr)
1721   , _exception_handler_pco(-1)
1722   , _lir(nullptr)
1723   , _live_in()
1724   , _live_out()
1725   , _live_gen()
1726   , _live_kill()
1727   , _fpu_register_usage()
1728   , _first_lir_instruction_id(-1)
1729   , _last_lir_instruction_id(-1)
1730   {
1731     _block = this;
1732 #ifndef PRODUCT
1733     set_printable_bci(bci);
1734 #endif
1735   }
1736 
1737   // accessors
1738   int block_id() const                           { return _block_id; }
1739   int bci() const                                { return _bci; }
1740   BlockList* dominates()                         { return &_dominates; }
1741   BlockBegin* dominator() const                  { return _dominator; }
1742   int loop_depth() const                         { return _loop_depth; }
1743   int dominator_depth() const                    { return _dominator_depth; }
1744   int depth_first_number() const                 { return _depth_first_number; }
1745   int linear_scan_number() const                 { return _linear_scan_number; }
1746   BlockEnd* end() const                          { return _end; }
1747   Label* label()                                 { return &_label; }
1748   LIR_List* lir() const                          { return _lir; }
1749   int exception_handler_pco() const              { return _exception_handler_pco; }
1750   ResourceBitMap& live_in()                      { return _live_in;        }
1751   ResourceBitMap& live_out()                     { return _live_out;       }
1752   ResourceBitMap& live_gen()                     { return _live_gen;       }
1753   ResourceBitMap& live_kill()                    { return _live_kill;      }
1754   ResourceBitMap& fpu_register_usage()           { return _fpu_register_usage; }
1755   int first_lir_instruction_id() const           { return _first_lir_instruction_id; }
1756   int last_lir_instruction_id() const            { return _last_lir_instruction_id; }
1757   int total_preds() const                        { return _total_preds; }
1758   BitMap& stores_to_locals()                     { return _stores_to_locals; }
1759 
1760   // manipulation
1761   void set_dominator(BlockBegin* dom)            { _dominator = dom; }
1762   void set_loop_depth(int d)                     { _loop_depth = d; }
1763   void set_dominator_depth(int d)                { _dominator_depth = d; }
1764   void set_depth_first_number(int dfn)           { _depth_first_number = dfn; }
1765   void set_linear_scan_number(int lsn)           { _linear_scan_number = lsn; }
1766   void set_end(BlockEnd* new_end);
1767   static void disconnect_edge(BlockBegin* from, BlockBegin* to);
1768   BlockBegin* insert_block_between(BlockBegin* sux);
1769   void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1770   void set_lir(LIR_List* lir)                    { _lir = lir; }
1771   void set_exception_handler_pco(int pco)        { _exception_handler_pco = pco; }
1772   void set_live_in  (const ResourceBitMap& map)  { _live_in = map;   }
1773   void set_live_out (const ResourceBitMap& map)  { _live_out = map;  }
1774   void set_live_gen (const ResourceBitMap& map)  { _live_gen = map;  }
1775   void set_live_kill(const ResourceBitMap& map)  { _live_kill = map; }
1776   void set_fpu_register_usage(const ResourceBitMap& map) { _fpu_register_usage = map; }
1777   void set_first_lir_instruction_id(int id)      { _first_lir_instruction_id = id;  }
1778   void set_last_lir_instruction_id(int id)       { _last_lir_instruction_id = id;  }
1779   void increment_total_preds(int n = 1)          { _total_preds += n; }
1780   void init_stores_to_locals(int locals_count)   { _stores_to_locals.initialize(locals_count); }
1781 
1782   // generic
1783   virtual void state_values_do(ValueVisitor* f);
1784 
1785   // successors and predecessors
1786   int number_of_sux() const;
1787   BlockBegin* sux_at(int i) const;
1788   void add_predecessor(BlockBegin* pred);
1789   void remove_predecessor(BlockBegin* pred);
1790   bool is_predecessor(BlockBegin* pred) const    { return _predecessors.contains(pred); }
1791   int number_of_preds() const                    { return _predecessors.length(); }
1792   BlockBegin* pred_at(int i) const               { return _predecessors.at(i); }
1793 
1794   // exception handlers potentially invoked by this block
1795   void add_exception_handler(BlockBegin* b);
1796   bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
1797   int  number_of_exception_handlers() const      { return _exception_handlers.length(); }
1798   BlockBegin* exception_handler_at(int i) const  { return _exception_handlers.at(i); }
1799 
1800   // states of the instructions that have an edge to this exception handler
1801   int number_of_exception_states()               { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == nullptr ? 0 : _exception_states->length(); }
1802   ValueStack* exception_state_at(int idx) const  { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
1803   int add_exception_state(ValueStack* state);
1804 
1805   // flags
1806   enum Flag {
1807     no_flag                       = 0,
1808     std_entry_flag                = 1 << 0,
1809     osr_entry_flag                = 1 << 1,
1810     exception_entry_flag          = 1 << 2,
1811     subroutine_entry_flag         = 1 << 3,
1812     backward_branch_target_flag   = 1 << 4,
1813     is_on_work_list_flag          = 1 << 5,
1814     was_visited_flag              = 1 << 6,
1815     parser_loop_header_flag       = 1 << 7,  // set by parser to identify blocks where phi functions can not be created on demand
1816     critical_edge_split_flag      = 1 << 8, // set for all blocks that are introduced when critical edges are split
1817     linear_scan_loop_header_flag  = 1 << 9, // set during loop-detection for LinearScan
1818     linear_scan_loop_end_flag     = 1 << 10, // set during loop-detection for LinearScan
1819     donot_eliminate_range_checks  = 1 << 11  // Should be try to eliminate range checks in this block
1820   };
1821 
1822   void set(Flag f)                               { _flags |= f; }
1823   void clear(Flag f)                             { _flags &= ~f; }
1824   bool is_set(Flag f) const                      { return (_flags & f) != 0; }
1825   bool is_entry_block() const {
1826     const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
1827     return (_flags & entry_mask) != 0;
1828   }
1829 
1830   // iteration
1831   void iterate_preorder   (BlockClosure* closure);
1832   void iterate_postorder  (BlockClosure* closure);
1833 
1834   void block_values_do(ValueVisitor* f);
1835 
1836   // loops
1837   void set_loop_index(int ix)                    { _loop_index = ix;        }
1838   int  loop_index() const                        { return _loop_index;      }
1839 
1840   // merging
1841   bool try_merge(ValueStack* state, bool has_irreducible_loops);  // try to merge states at block begin
1842   void merge(ValueStack* state, bool has_irreducible_loops) {
1843     bool b = try_merge(state, has_irreducible_loops);
1844     assert(b, "merge failed");
1845   }
1846 
1847   // debugging
1848   void print_block()                             PRODUCT_RETURN;
1849   void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
1850 
1851 };
1852 
1853 
1854 BASE(BlockEnd, StateSplit)
1855  private:
1856   BlockList*  _sux;
1857 
1858  protected:
1859   BlockList* sux() const                         { return _sux; }
1860 
1861   void set_sux(BlockList* sux) {
1862 #ifdef ASSERT
1863     assert(sux != nullptr, "sux must exist");
1864     for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != nullptr, "sux must exist");
1865 #endif
1866     _sux = sux;
1867   }
1868 
1869  public:
1870   // creation
1871   BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
1872   : StateSplit(type, state_before)
1873   , _sux(nullptr)
1874   {
1875     set_flag(IsSafepointFlag, is_safepoint);
1876   }
1877 
1878   // accessors
1879   bool is_safepoint() const                      { return check_flag(IsSafepointFlag); }
1880   // For compatibility with old code, for new code use block()
1881   BlockBegin* begin() const                      { return _block; }
1882 
1883   // manipulation
1884   inline void remove_sux_at(int i) { _sux->remove_at(i);}
1885   inline int find_sux(BlockBegin* sux) {return _sux->find(sux);}
1886 
1887   // successors
1888   int number_of_sux() const                      { return _sux != nullptr ? _sux->length() : 0; }
1889   BlockBegin* sux_at(int i) const                { return _sux->at(i); }
1890   bool is_sux(BlockBegin* sux) const             { return _sux == nullptr ? false : _sux->contains(sux); }
1891   BlockBegin* default_sux() const                { return sux_at(number_of_sux() - 1); }
1892   void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1893 };
1894 
1895 
1896 LEAF(Goto, BlockEnd)
1897  public:
1898   enum Direction {
1899     none,            // Just a regular goto
1900     taken, not_taken // Goto produced from If
1901   };
1902  private:
1903   ciMethod*   _profiled_method;
1904   int         _profiled_bci;
1905   Direction   _direction;
1906  public:
1907   // creation
1908   Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)
1909     : BlockEnd(illegalType, state_before, is_safepoint)
1910     , _profiled_method(nullptr)
1911     , _profiled_bci(0)
1912     , _direction(none) {
1913     BlockList* s = new BlockList(1);
1914     s->append(sux);
1915     set_sux(s);
1916   }
1917 
1918   Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, nullptr, is_safepoint)
1919                                            , _profiled_method(nullptr)
1920                                            , _profiled_bci(0)
1921                                            , _direction(none) {
1922     BlockList* s = new BlockList(1);
1923     s->append(sux);
1924     set_sux(s);
1925   }
1926 
1927   bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
1928   ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
1929   int profiled_bci() const                       { return _profiled_bci; }
1930   Direction direction() const                    { return _direction; }
1931 
1932   void set_should_profile(bool value)            { set_flag(ProfileMDOFlag, value); }
1933   void set_profiled_method(ciMethod* method)     { _profiled_method = method; }
1934   void set_profiled_bci(int bci)                 { _profiled_bci = bci; }
1935   void set_direction(Direction d)                { _direction = d; }
1936 };
1937 
1938 #ifdef ASSERT
1939 LEAF(Assert, Instruction)
1940   private:
1941   Value       _x;
1942   Condition   _cond;
1943   Value       _y;
1944   char        *_message;
1945 
1946  public:
1947   // creation
1948   // unordered_is_true is valid for float/double compares only
1949    Assert(Value x, Condition cond, bool unordered_is_true, Value y);
1950 
1951   // accessors
1952   Value x() const                                { return _x; }
1953   Condition cond() const                         { return _cond; }
1954   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
1955   Value y() const                                { return _y; }
1956   const char *message() const                    { return _message; }
1957 
1958   // generic
1959   virtual void input_values_do(ValueVisitor* f)  { f->visit(&_x); f->visit(&_y); }
1960 };
1961 #endif
1962 
1963 LEAF(RangeCheckPredicate, StateSplit)
1964  private:
1965   Value       _x;
1966   Condition   _cond;
1967   Value       _y;
1968 
1969   void check_state();
1970 
1971  public:
1972   // creation
1973   // unordered_is_true is valid for float/double compares only
1974    RangeCheckPredicate(Value x, Condition cond, bool unordered_is_true, Value y, ValueStack* state) : StateSplit(illegalType)
1975   , _x(x)
1976   , _cond(cond)
1977   , _y(y)
1978   {
1979     ASSERT_VALUES
1980     set_flag(UnorderedIsTrueFlag, unordered_is_true);
1981     assert(x->type()->tag() == y->type()->tag(), "types must match");
1982     this->set_state(state);
1983     check_state();
1984   }
1985 
1986   // Always deoptimize
1987   RangeCheckPredicate(ValueStack* state) : StateSplit(illegalType)
1988   {
1989     this->set_state(state);
1990     _x = _y = nullptr;
1991     check_state();
1992   }
1993 
1994   // accessors
1995   Value x() const                                { return _x; }
1996   Condition cond() const                         { return _cond; }
1997   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
1998   Value y() const                                { return _y; }
1999 
2000   void always_fail()                             { _x = _y = nullptr; }
2001 
2002   // generic
2003   virtual void input_values_do(ValueVisitor* f)  { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2004   HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
2005 };
2006 
2007 LEAF(If, BlockEnd)
2008  private:
2009   Value       _x;
2010   Condition   _cond;
2011   Value       _y;
2012   ciMethod*   _profiled_method;
2013   int         _profiled_bci; // Canonicalizer may alter bci of If node
2014   bool        _swapped;      // Is the order reversed with respect to the original If in the
2015                              // bytecode stream?
2016   bool        _substitutability_check;
2017  public:
2018   // creation
2019   // unordered_is_true is valid for float/double compares only
2020   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)
2021     : BlockEnd(illegalType, state_before, is_safepoint)
2022   , _x(x)
2023   , _cond(cond)
2024   , _y(y)
2025   , _profiled_method(nullptr)
2026   , _profiled_bci(0)
2027   , _swapped(false)
2028   , _substitutability_check(substitutability_check)
2029   {
2030     ASSERT_VALUES
2031     set_flag(UnorderedIsTrueFlag, unordered_is_true);
2032     assert(x->type()->tag() == y->type()->tag(), "types must match");
2033     BlockList* s = new BlockList(2);
2034     s->append(tsux);
2035     s->append(fsux);
2036     set_sux(s);
2037   }
2038 
2039   // accessors
2040   Value x() const                                { return _x; }
2041   Condition cond() const                         { return _cond; }
2042   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
2043   Value y() const                                { return _y; }
2044   BlockBegin* sux_for(bool is_true) const        { return sux_at(is_true ? 0 : 1); }
2045   BlockBegin* tsux() const                       { return sux_for(true); }
2046   BlockBegin* fsux() const                       { return sux_for(false); }
2047   BlockBegin* usux() const                       { return sux_for(unordered_is_true()); }
2048   bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
2049   ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
2050   int profiled_bci() const                       { return _profiled_bci; }    // set for profiled branches and tiered
2051   bool is_swapped() const                        { return _swapped; }
2052 
2053   // manipulation
2054   void swap_operands() {
2055     Value t = _x; _x = _y; _y = t;
2056     _cond = mirror(_cond);
2057   }
2058 
2059   void set_should_profile(bool value)             { set_flag(ProfileMDOFlag, value); }
2060   void set_profiled_method(ciMethod* method)      { _profiled_method = method; }
2061   void set_profiled_bci(int bci)                  { _profiled_bci = bci;       }
2062   void set_swapped(bool value)                    { _swapped = value;         }
2063   bool substitutability_check() const              { return _substitutability_check; }
2064   // generic
2065   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2066 };
2067 
2068 
2069 BASE(Switch, BlockEnd)
2070  private:
2071   Value       _tag;
2072 
2073  public:
2074   // creation
2075   Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
2076   : BlockEnd(illegalType, state_before, is_safepoint)
2077   , _tag(tag) {
2078     ASSERT_VALUES
2079     set_sux(sux);
2080   }
2081 
2082   // accessors
2083   Value tag() const                              { return _tag; }
2084   int length() const                             { return number_of_sux() - 1; }
2085 
2086   virtual bool needs_exception_state() const     { return false; }
2087 
2088   // generic
2089   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_tag); }
2090 };
2091 
2092 
2093 LEAF(TableSwitch, Switch)
2094  private:
2095   int _lo_key;
2096 
2097  public:
2098   // creation
2099   TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
2100     : Switch(tag, sux, state_before, is_safepoint)
2101   , _lo_key(lo_key) { assert(_lo_key <= hi_key(), "integer overflow"); }
2102 
2103   // accessors
2104   int lo_key() const                             { return _lo_key; }
2105   int hi_key() const                             { return _lo_key + (length() - 1); }
2106 };
2107 
2108 
2109 LEAF(LookupSwitch, Switch)
2110  private:
2111   intArray* _keys;
2112 
2113  public:
2114   // creation
2115   LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
2116   : Switch(tag, sux, state_before, is_safepoint)
2117   , _keys(keys) {
2118     assert(keys != nullptr, "keys must exist");
2119     assert(keys->length() == length(), "sux & keys have incompatible lengths");
2120   }
2121 
2122   // accessors
2123   int key_at(int i) const                        { return _keys->at(i); }
2124 };
2125 
2126 
2127 LEAF(Return, BlockEnd)
2128  private:
2129   Value _result;
2130 
2131  public:
2132   // creation
2133   Return(Value result) :
2134     BlockEnd(result == nullptr ? voidType : result->type()->base(), nullptr, true),
2135     _result(result) {}
2136 
2137   // accessors
2138   Value result() const                           { return _result; }
2139   bool has_result() const                        { return result() != nullptr; }
2140 
2141   // generic
2142   virtual void input_values_do(ValueVisitor* f) {
2143     BlockEnd::input_values_do(f);
2144     if (has_result()) f->visit(&_result);
2145   }
2146 };
2147 
2148 
2149 LEAF(Throw, BlockEnd)
2150  private:
2151   Value _exception;
2152 
2153  public:
2154   // creation
2155   Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
2156     ASSERT_VALUES
2157   }
2158 
2159   // accessors
2160   Value exception() const                        { return _exception; }
2161 
2162   // generic
2163   virtual bool can_trap() const                  { return true; }
2164   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_exception); }
2165 };
2166 
2167 
2168 LEAF(Base, BlockEnd)
2169  public:
2170   // creation
2171   Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, nullptr, false) {
2172     assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");
2173     assert(osr_entry == nullptr || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");
2174     BlockList* s = new BlockList(2);
2175     if (osr_entry != nullptr) s->append(osr_entry);
2176     s->append(std_entry); // must be default sux!
2177     set_sux(s);
2178   }
2179 
2180   // accessors
2181   BlockBegin* std_entry() const                  { return default_sux(); }
2182   BlockBegin* osr_entry() const                  { return number_of_sux() < 2 ? nullptr : sux_at(0); }
2183 };
2184 
2185 
2186 LEAF(OsrEntry, Instruction)
2187  public:
2188   // creation
2189 #ifdef _LP64
2190   OsrEntry() : Instruction(longType) { pin(); }
2191 #else
2192   OsrEntry() : Instruction(intType)  { pin(); }
2193 #endif
2194 
2195   // generic
2196   virtual void input_values_do(ValueVisitor* f)   { }
2197 };
2198 
2199 
2200 // Models the incoming exception at a catch site
2201 LEAF(ExceptionObject, Instruction)
2202  public:
2203   // creation
2204   ExceptionObject() : Instruction(objectType) {
2205     pin();
2206   }
2207 
2208   // generic
2209   virtual void input_values_do(ValueVisitor* f)   { }
2210 };
2211 
2212 
2213 BASE(UnsafeOp, Instruction)
2214  private:
2215   Value _object;                                 // Object to be fetched from or mutated
2216   Value _offset;                                 // Offset within object
2217   bool  _is_volatile;                            // true if volatile - dl/JSR166
2218   BasicType _basic_type;                         // ValueType can not express byte-sized integers
2219 
2220  protected:
2221   // creation
2222   UnsafeOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)
2223     : Instruction(is_put ? voidType : as_ValueType(basic_type)),
2224     _object(object), _offset(offset), _is_volatile(is_volatile), _basic_type(basic_type)
2225   {
2226     //Note:  Unsafe ops are not not guaranteed to throw NPE.
2227     // Convservatively, Unsafe operations must be pinned though we could be
2228     // looser about this if we wanted to..
2229     pin();
2230   }
2231 
2232  public:
2233   // accessors
2234   BasicType basic_type()                         { return _basic_type; }
2235   Value object()                                 { return _object; }
2236   Value offset()                                 { return _offset; }
2237   bool  is_volatile()                            { return _is_volatile; }
2238 
2239   // generic
2240   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_object);
2241                                                     f->visit(&_offset); }
2242 };
2243 
2244 LEAF(UnsafeGet, UnsafeOp)
2245  private:
2246   bool _is_raw;
2247  public:
2248   UnsafeGet(BasicType basic_type, Value object, Value offset, bool is_volatile)
2249   : UnsafeOp(basic_type, object, offset, false, is_volatile)
2250   {
2251     ASSERT_VALUES
2252     _is_raw = false;
2253   }
2254   UnsafeGet(BasicType basic_type, Value object, Value offset, bool is_volatile, bool is_raw)
2255   : UnsafeOp(basic_type, object, offset, false, is_volatile), _is_raw(is_raw)
2256   {
2257     ASSERT_VALUES
2258   }
2259 
2260   // accessors
2261   bool is_raw()                             { return _is_raw; }
2262 };
2263 
2264 
2265 LEAF(UnsafePut, UnsafeOp)
2266  private:
2267   Value _value;                                  // Value to be stored
2268  public:
2269   UnsafePut(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)
2270   : UnsafeOp(basic_type, object, offset, true, is_volatile)
2271     , _value(value)
2272   {
2273     ASSERT_VALUES
2274   }
2275 
2276   // accessors
2277   Value value()                                  { return _value; }
2278 
2279   // generic
2280   virtual void input_values_do(ValueVisitor* f)   { UnsafeOp::input_values_do(f);
2281                                                    f->visit(&_value); }
2282 };
2283 
2284 LEAF(UnsafeGetAndSet, UnsafeOp)
2285  private:
2286   Value _value;                                  // Value to be stored
2287   bool  _is_add;
2288  public:
2289   UnsafeGetAndSet(BasicType basic_type, Value object, Value offset, Value value, bool is_add)
2290   : UnsafeOp(basic_type, object, offset, false, false)
2291     , _value(value)
2292     , _is_add(is_add)
2293   {
2294     ASSERT_VALUES
2295   }
2296 
2297   // accessors
2298   bool is_add() const                            { return _is_add; }
2299   Value value()                                  { return _value; }
2300 
2301   // generic
2302   virtual void input_values_do(ValueVisitor* f)   { UnsafeOp::input_values_do(f);
2303                                                    f->visit(&_value); }
2304 };
2305 
2306 LEAF(ProfileCall, Instruction)
2307  private:
2308   ciMethod*        _method;
2309   int              _bci_of_invoke;
2310   ciMethod*        _callee;         // the method that is called at the given bci
2311   Value            _recv;
2312   ciKlass*         _known_holder;
2313   Values*          _obj_args;       // arguments for type profiling
2314   ArgsNonNullState _nonnull_state;  // Do we know whether some arguments are never null?
2315   bool             _inlined;        // Are we profiling a call that is inlined
2316 
2317  public:
2318   ProfileCall(ciMethod* method, int bci, ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined)
2319     : Instruction(voidType)
2320     , _method(method)
2321     , _bci_of_invoke(bci)
2322     , _callee(callee)
2323     , _recv(recv)
2324     , _known_holder(known_holder)
2325     , _obj_args(obj_args)
2326     , _inlined(inlined)
2327   {
2328     // The ProfileCall has side-effects and must occur precisely where located
2329     pin();
2330   }
2331 
2332   ciMethod* method()             const { return _method; }
2333   int bci_of_invoke()            const { return _bci_of_invoke; }
2334   ciMethod* callee()             const { return _callee; }
2335   Value recv()                   const { return _recv; }
2336   ciKlass* known_holder()        const { return _known_holder; }
2337   int nb_profiled_args()         const { return _obj_args == nullptr ? 0 : _obj_args->length(); }
2338   Value profiled_arg_at(int i)   const { return _obj_args->at(i); }
2339   bool arg_needs_null_check(int i) const {
2340     return _nonnull_state.arg_needs_null_check(i);
2341   }
2342   bool inlined()                 const { return _inlined; }
2343 
2344   void set_arg_needs_null_check(int i, bool check) {
2345     _nonnull_state.set_arg_needs_null_check(i, check);
2346   }
2347 
2348   virtual void input_values_do(ValueVisitor* f)   {
2349     if (_recv != nullptr) {
2350       f->visit(&_recv);
2351     }
2352     for (int i = 0; i < nb_profiled_args(); i++) {
2353       f->visit(_obj_args->adr_at(i));
2354     }
2355   }
2356 };
2357 
2358 LEAF(ProfileReturnType, Instruction)
2359  private:
2360   ciMethod*        _method;
2361   ciMethod*        _callee;
2362   int              _bci_of_invoke;
2363   Value            _ret;
2364 
2365  public:
2366   ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
2367     : Instruction(voidType)
2368     , _method(method)
2369     , _callee(callee)
2370     , _bci_of_invoke(bci)
2371     , _ret(ret)
2372   {
2373     set_needs_null_check(true);
2374     // The ProfileReturnType has side-effects and must occur precisely where located
2375     pin();
2376   }
2377 
2378   ciMethod* method()             const { return _method; }
2379   ciMethod* callee()             const { return _callee; }
2380   int bci_of_invoke()            const { return _bci_of_invoke; }
2381   Value ret()                    const { return _ret; }
2382 
2383   virtual void input_values_do(ValueVisitor* f)   {
2384     if (_ret != nullptr) {
2385       f->visit(&_ret);
2386     }
2387   }
2388 };
2389 
2390 LEAF(ProfileACmpTypes, Instruction)
2391  private:
2392   ciMethod*        _method;
2393   int              _bci;
2394   Value            _left;
2395   Value            _right;
2396   bool             _left_maybe_null;
2397   bool             _right_maybe_null;
2398 
2399  public:
2400   ProfileACmpTypes(ciMethod* method, int bci, Value left, Value right)
2401     : Instruction(voidType)
2402     , _method(method)
2403     , _bci(bci)
2404     , _left(left)
2405     , _right(right)
2406   {
2407     // The ProfileACmp has side-effects and must occur precisely where located
2408     pin();
2409     _left_maybe_null = true;
2410     _right_maybe_null = true;
2411   }
2412 
2413   ciMethod* method()             const { return _method; }
2414   int bci()                      const { return _bci; }
2415   Value left()                   const { return _left; }
2416   Value right()                  const { return _right; }
2417   bool left_maybe_null()         const { return _left_maybe_null; }
2418   bool right_maybe_null()        const { return _right_maybe_null; }
2419   void set_left_maybe_null(bool v)     { _left_maybe_null = v; }
2420   void set_right_maybe_null(bool v)    { _right_maybe_null = v; }
2421 
2422   virtual void input_values_do(ValueVisitor* f)   {
2423     if (_left != nullptr) {
2424       f->visit(&_left);
2425     }
2426     if (_right != nullptr) {
2427       f->visit(&_right);
2428     }
2429   }
2430 };
2431 
2432 // Call some C runtime function that doesn't safepoint,
2433 // optionally passing the current thread as the first argument.
2434 LEAF(RuntimeCall, Instruction)
2435  private:
2436   const char* _entry_name;
2437   address     _entry;
2438   Values*     _args;
2439   bool        _pass_thread;  // Pass the JavaThread* as an implicit first argument
2440 
2441  public:
2442   RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2443     : Instruction(type)
2444     , _entry_name(entry_name)
2445     , _entry(entry)
2446     , _args(args)
2447     , _pass_thread(pass_thread) {
2448     ASSERT_VALUES
2449     pin();
2450   }
2451 
2452   const char* entry_name() const  { return _entry_name; }
2453   address entry() const           { return _entry; }
2454   int number_of_arguments() const { return _args->length(); }
2455   Value argument_at(int i) const  { return _args->at(i); }
2456   bool pass_thread() const        { return _pass_thread; }
2457 
2458   virtual void input_values_do(ValueVisitor* f)   {
2459     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
2460   }
2461 };
2462 
2463 // Use to trip invocation counter of an inlined method
2464 
2465 LEAF(ProfileInvoke, Instruction)
2466  private:
2467   ciMethod*   _inlinee;
2468   ValueStack* _state;
2469 
2470  public:
2471   ProfileInvoke(ciMethod* inlinee,  ValueStack* state)
2472     : Instruction(voidType)
2473     , _inlinee(inlinee)
2474     , _state(state)
2475   {
2476     // The ProfileInvoke has side-effects and must occur precisely where located QQQ???
2477     pin();
2478   }
2479 
2480   ciMethod* inlinee()      { return _inlinee; }
2481   ValueStack* state()      { return _state; }
2482   virtual void input_values_do(ValueVisitor*)   {}
2483   virtual void state_values_do(ValueVisitor*);
2484 };
2485 
2486 LEAF(MemBar, Instruction)
2487  private:
2488   LIR_Code _code;
2489 
2490  public:
2491   MemBar(LIR_Code code)
2492     : Instruction(voidType)
2493     , _code(code)
2494   {
2495     pin();
2496   }
2497 
2498   LIR_Code code()           { return _code; }
2499 
2500   virtual void input_values_do(ValueVisitor*)   {}
2501 };
2502 
2503 class BlockPair: public CompilationResourceObj {
2504  private:
2505   BlockBegin* _from;
2506   int _index; // sux index of 'to' block
2507  public:
2508   BlockPair(BlockBegin* from, int index): _from(from), _index(index) {}
2509   BlockBegin* from() const { return _from; }
2510   int index() const        { return _index; }
2511 };
2512 
2513 typedef GrowableArray<BlockPair*> BlockPairList;
2514 
2515 inline int         BlockBegin::number_of_sux() const            { assert(_end != nullptr, "need end"); return _end->number_of_sux(); }
2516 inline BlockBegin* BlockBegin::sux_at(int i) const              { assert(_end != nullptr , "need end"); return _end->sux_at(i); }
2517 
2518 #undef ASSERT_VALUES
2519 
2520 #endif // SHARE_C1_C1_INSTRUCTION_HPP