1 /*
   2  * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2024, Alibaba Group Holding Limited. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #ifndef SHARE_OPTO_NODE_HPP
  27 #define SHARE_OPTO_NODE_HPP
  28 
  29 #include "libadt/vectset.hpp"
  30 #include "opto/compile.hpp"
  31 #include "opto/type.hpp"
  32 #include "utilities/copy.hpp"
  33 
  34 // Portions of code courtesy of Clifford Click
  35 
  36 // Optimization - Graph Style
  37 
  38 
  39 class AbstractLockNode;
  40 class AddNode;
  41 class AddPNode;
  42 class AliasInfo;
  43 class AllocateArrayNode;
  44 class AllocateNode;
  45 class ArrayCopyNode;
  46 class BaseCountedLoopNode;
  47 class BaseCountedLoopEndNode;
  48 class BlackholeNode;
  49 class Block;
  50 class BoolNode;
  51 class BoxLockNode;
  52 class CMoveNode;
  53 class CallDynamicJavaNode;
  54 class CallJavaNode;
  55 class CallLeafNode;
  56 class CallLeafNoFPNode;
  57 class CallNode;
  58 class CallRuntimeNode;
  59 class CallStaticJavaNode;
  60 class CastFFNode;
  61 class CastDDNode;
  62 class CastVVNode;
  63 class CastIINode;
  64 class CastLLNode;
  65 class CastPPNode;
  66 class CatchNode;
  67 class CatchProjNode;
  68 class CheckCastPPNode;
  69 class ClearArrayNode;
  70 class CmpNode;
  71 class CodeBuffer;
  72 class ConstraintCastNode;
  73 class ConNode;
  74 class ConINode;
  75 class ConvertNode;
  76 class CompareAndSwapNode;
  77 class CompareAndExchangeNode;
  78 class CountedLoopNode;
  79 class CountedLoopEndNode;
  80 class DecodeNarrowPtrNode;
  81 class DecodeNNode;
  82 class DecodeNKlassNode;
  83 class EncodeNarrowPtrNode;
  84 class EncodePNode;
  85 class EncodePKlassNode;
  86 class FastLockNode;
  87 class FastUnlockNode;
  88 class HaltNode;
  89 class IfNode;
  90 class IfProjNode;
  91 class IfFalseNode;
  92 class IfTrueNode;
  93 class InitializeNode;
  94 class JVMState;
  95 class JumpNode;
  96 class JumpProjNode;
  97 class LoadNode;
  98 class LoadStoreNode;
  99 class LoadStoreConditionalNode;
 100 class LockNode;
 101 class LongCountedLoopNode;
 102 class LongCountedLoopEndNode;
 103 class LoopNode;
 104 class LShiftNode;
 105 class MachBranchNode;
 106 class MachCallDynamicJavaNode;
 107 class MachCallJavaNode;
 108 class MachCallLeafNode;
 109 class MachCallNode;
 110 class MachCallRuntimeNode;
 111 class MachCallStaticJavaNode;
 112 class MachConstantBaseNode;
 113 class MachConstantNode;
 114 class MachGotoNode;
 115 class MachIfNode;
 116 class MachJumpNode;
 117 class MachNode;
 118 class MachNullCheckNode;
 119 class MachProjNode;
 120 class MachReturnNode;
 121 class MachSafePointNode;
 122 class MachSpillCopyNode;
 123 class MachTempNode;
 124 class MachMergeNode;
 125 class MachMemBarNode;
 126 class Matcher;
 127 class MemBarNode;
 128 class MemBarStoreStoreNode;
 129 class MemNode;
 130 class MergeMemNode;
 131 class MoveNode;
 132 class MulNode;
 133 class MultiNode;
 134 class MultiBranchNode;
 135 class NegNode;
 136 class NegVNode;
 137 class NeverBranchNode;
 138 class Opaque1Node;
 139 class OpaqueLoopInitNode;
 140 class OpaqueLoopStrideNode;
 141 class OpaqueNotNullNode;
 142 class OpaqueInitializedAssertionPredicateNode;
 143 class OpaqueTemplateAssertionPredicateNode;
 144 class OuterStripMinedLoopNode;
 145 class OuterStripMinedLoopEndNode;
 146 class Node;
 147 class Node_Array;
 148 class Node_List;
 149 class Node_Stack;
 150 class OopMap;
 151 class ParmNode;
 152 class ParsePredicateNode;
 153 class PCTableNode;
 154 class PhaseCCP;
 155 class PhaseGVN;
 156 class PhaseIterGVN;
 157 class PhaseRegAlloc;
 158 class PhaseTransform;
 159 class PhaseValues;
 160 class PhiNode;
 161 class Pipeline;
 162 class PopulateIndexNode;
 163 class ProjNode;
 164 class RangeCheckNode;
 165 class ReductionNode;
 166 class RegMask;
 167 class RegionNode;
 168 class RootNode;
 169 class SafePointNode;
 170 class SafePointScalarObjectNode;
 171 class SafePointScalarMergeNode;
 172 class SaturatingVectorNode;
 173 class StartNode;
 174 class State;
 175 class StoreNode;
 176 class SubNode;
 177 class SubTypeCheckNode;
 178 class Type;
 179 class TypeNode;
 180 class UnlockNode;
 181 class VectorNode;
 182 class LoadVectorNode;
 183 class LoadVectorMaskedNode;
 184 class StoreVectorMaskedNode;
 185 class LoadVectorGatherNode;
 186 class LoadVectorGatherMaskedNode;
 187 class StoreVectorNode;
 188 class StoreVectorScatterNode;
 189 class StoreVectorScatterMaskedNode;
 190 class VerifyVectorAlignmentNode;
 191 class VectorMaskCmpNode;
 192 class VectorUnboxNode;
 193 class VectorSet;
 194 class VectorReinterpretNode;
 195 class ShiftVNode;
 196 class ExpandVNode;
 197 class CompressVNode;
 198 class CompressMNode;
 199 class C2_MacroAssembler;
 200 
 201 
 202 #ifndef OPTO_DU_ITERATOR_ASSERT
 203 #ifdef ASSERT
 204 #define OPTO_DU_ITERATOR_ASSERT 1
 205 #else
 206 #define OPTO_DU_ITERATOR_ASSERT 0
 207 #endif
 208 #endif //OPTO_DU_ITERATOR_ASSERT
 209 
 210 #if OPTO_DU_ITERATOR_ASSERT
 211 class DUIterator;
 212 class DUIterator_Fast;
 213 class DUIterator_Last;
 214 #else
 215 typedef uint   DUIterator;
 216 typedef Node** DUIterator_Fast;
 217 typedef Node** DUIterator_Last;
 218 #endif
 219 
 220 typedef ResizeableResourceHashtable<Node*, Node*, AnyObj::RESOURCE_AREA, mtCompiler> OrigToNewHashtable;
 221 
 222 // Node Sentinel
 223 #define NodeSentinel (Node*)-1
 224 
 225 // Unknown count frequency
 226 #define COUNT_UNKNOWN (-1.0f)
 227 
 228 //------------------------------Node-------------------------------------------
 229 // Nodes define actions in the program.  They create values, which have types.
 230 // They are both vertices in a directed graph and program primitives.  Nodes
 231 // are labeled; the label is the "opcode", the primitive function in the lambda
 232 // calculus sense that gives meaning to the Node.  Node inputs are ordered (so
 233 // that "a-b" is different from "b-a").  The inputs to a Node are the inputs to
 234 // the Node's function.  These inputs also define a Type equation for the Node.
 235 // Solving these Type equations amounts to doing dataflow analysis.
 236 // Control and data are uniformly represented in the graph.  Finally, Nodes
 237 // have a unique dense integer index which is used to index into side arrays
 238 // whenever I have phase-specific information.
 239 
 240 class Node {
 241   friend class VMStructs;
 242 
 243   // Lots of restrictions on cloning Nodes
 244   NONCOPYABLE(Node);
 245 
 246 public:
 247   friend class Compile;
 248   #if OPTO_DU_ITERATOR_ASSERT
 249   friend class DUIterator_Common;
 250   friend class DUIterator;
 251   friend class DUIterator_Fast;
 252   friend class DUIterator_Last;
 253   #endif
 254 
 255   // Because Nodes come and go, I define an Arena of Node structures to pull
 256   // from.  This should allow fast access to node creation & deletion.  This
 257   // field is a local cache of a value defined in some "program fragment" for
 258   // which these Nodes are just a part of.
 259 
 260   inline void* operator new(size_t x) throw() {
 261     Compile* C = Compile::current();
 262     Node* n = (Node*)C->node_arena()->AmallocWords(x);
 263     return (void*)n;
 264   }
 265 
 266   // Delete is a NOP
 267   void operator delete( void *ptr ) {}
 268   // Fancy destructor; eagerly attempt to reclaim Node numberings and storage
 269   void destruct(PhaseValues* phase);
 270 
 271   // Create a new Node.  Required is the number is of inputs required for
 272   // semantic correctness.
 273   Node( uint required );
 274 
 275   // Create a new Node with given input edges.
 276   // This version requires use of the "edge-count" new.
 277   // E.g.  new (C,3) FooNode( C, nullptr, left, right );
 278   Node( Node *n0 );
 279   Node( Node *n0, Node *n1 );
 280   Node( Node *n0, Node *n1, Node *n2 );
 281   Node( Node *n0, Node *n1, Node *n2, Node *n3 );
 282   Node( Node *n0, Node *n1, Node *n2, Node *n3, Node *n4 );
 283   Node( Node *n0, Node *n1, Node *n2, Node *n3, Node *n4, Node *n5 );
 284   Node( Node *n0, Node *n1, Node *n2, Node *n3,
 285             Node *n4, Node *n5, Node *n6 );
 286 
 287   // Clone an inherited Node given only the base Node type.
 288   Node* clone() const;
 289 
 290   // Clone a Node, immediately supplying one or two new edges.
 291   // The first and second arguments, if non-null, replace in(1) and in(2),
 292   // respectively.
 293   Node* clone_with_data_edge(Node* in1, Node* in2 = nullptr) const {
 294     Node* nn = clone();
 295     if (in1 != nullptr)  nn->set_req(1, in1);
 296     if (in2 != nullptr)  nn->set_req(2, in2);
 297     return nn;
 298   }
 299 
 300 private:
 301   // Shared setup for the above constructors.
 302   // Handles all interactions with Compile::current.
 303   // Puts initial values in all Node fields except _idx.
 304   // Returns the initial value for _idx, which cannot
 305   // be initialized by assignment.
 306   inline int Init(int req);
 307 
 308 //----------------- input edge handling
 309 protected:
 310   friend class PhaseCFG;        // Access to address of _in array elements
 311   Node **_in;                   // Array of use-def references to Nodes
 312   Node **_out;                  // Array of def-use references to Nodes
 313 
 314   // Input edges are split into two categories.  Required edges are required
 315   // for semantic correctness; order is important and nulls are allowed.
 316   // Precedence edges are used to help determine execution order and are
 317   // added, e.g., for scheduling purposes.  They are unordered and not
 318   // duplicated; they have no embedded nulls.  Edges from 0 to _cnt-1
 319   // are required, from _cnt to _max-1 are precedence edges.
 320   node_idx_t _cnt;              // Total number of required Node inputs.
 321 
 322   node_idx_t _max;              // Actual length of input array.
 323 
 324   // Output edges are an unordered list of def-use edges which exactly
 325   // correspond to required input edges which point from other nodes
 326   // to this one.  Thus the count of the output edges is the number of
 327   // users of this node.
 328   node_idx_t _outcnt;           // Total number of Node outputs.
 329 
 330   node_idx_t _outmax;           // Actual length of output array.
 331 
 332   // Grow the actual input array to the next larger power-of-2 bigger than len.
 333   void grow( uint len );
 334   // Grow the output array to the next larger power-of-2 bigger than len.
 335   void out_grow( uint len );
 336 
 337  public:
 338   // Each Node is assigned a unique small/dense number.  This number is used
 339   // to index into auxiliary arrays of data and bit vectors.
 340   // The field _idx is declared constant to defend against inadvertent assignments,
 341   // since it is used by clients as a naked field. However, the field's value can be
 342   // changed using the set_idx() method.
 343   //
 344   // The PhaseRenumberLive phase renumbers nodes based on liveness information.
 345   // Therefore, it updates the value of the _idx field. The parse-time _idx is
 346   // preserved in _parse_idx.
 347   const node_idx_t _idx;
 348   DEBUG_ONLY(const node_idx_t _parse_idx;)
 349   // IGV node identifier. Two nodes, possibly in different compilation phases,
 350   // have the same IGV identifier if (and only if) they are the very same node
 351   // (same memory address) or one is "derived" from the other (by e.g.
 352   // renumbering or matching). This identifier makes it possible to follow the
 353   // entire lifetime of a node in IGV even if its C2 identifier (_idx) changes.
 354   NOT_PRODUCT(node_idx_t _igv_idx;)
 355 
 356   // Get the (read-only) number of input edges
 357   uint req() const { return _cnt; }
 358   uint len() const { return _max; }
 359   // Get the (read-only) number of output edges
 360   uint outcnt() const { return _outcnt; }
 361 
 362 #if OPTO_DU_ITERATOR_ASSERT
 363   // Iterate over the out-edges of this node.  Deletions are illegal.
 364   inline DUIterator outs() const;
 365   // Use this when the out array might have changed to suppress asserts.
 366   inline DUIterator& refresh_out_pos(DUIterator& i) const;
 367   // Does the node have an out at this position?  (Used for iteration.)
 368   inline bool has_out(DUIterator& i) const;
 369   inline Node*    out(DUIterator& i) const;
 370   // Iterate over the out-edges of this node.  All changes are illegal.
 371   inline DUIterator_Fast fast_outs(DUIterator_Fast& max) const;
 372   inline Node*    fast_out(DUIterator_Fast& i) const;
 373   // Iterate over the out-edges of this node, deleting one at a time.
 374   inline DUIterator_Last last_outs(DUIterator_Last& min) const;
 375   inline Node*    last_out(DUIterator_Last& i) const;
 376   // The inline bodies of all these methods are after the iterator definitions.
 377 #else
 378   // Iterate over the out-edges of this node.  Deletions are illegal.
 379   // This iteration uses integral indexes, to decouple from array reallocations.
 380   DUIterator outs() const  { return 0; }
 381   // Use this when the out array might have changed to suppress asserts.
 382   DUIterator refresh_out_pos(DUIterator i) const { return i; }
 383 
 384   // Reference to the i'th output Node.  Error if out of bounds.
 385   Node*    out(DUIterator i) const { assert(i < _outcnt, "oob"); return _out[i]; }
 386   // Does the node have an out at this position?  (Used for iteration.)
 387   bool has_out(DUIterator i) const { return i < _outcnt; }
 388 
 389   // Iterate over the out-edges of this node.  All changes are illegal.
 390   // This iteration uses a pointer internal to the out array.
 391   DUIterator_Fast fast_outs(DUIterator_Fast& max) const {
 392     Node** out = _out;
 393     // Assign a limit pointer to the reference argument:
 394     max = out + (ptrdiff_t)_outcnt;
 395     // Return the base pointer:
 396     return out;
 397   }
 398   Node*    fast_out(DUIterator_Fast i) const  { return *i; }
 399   // Iterate over the out-edges of this node, deleting one at a time.
 400   // This iteration uses a pointer internal to the out array.
 401   DUIterator_Last last_outs(DUIterator_Last& min) const {
 402     Node** out = _out;
 403     // Assign a limit pointer to the reference argument:
 404     min = out;
 405     // Return the pointer to the start of the iteration:
 406     return out + (ptrdiff_t)_outcnt - 1;
 407   }
 408   Node*    last_out(DUIterator_Last i) const  { return *i; }
 409 #endif
 410 
 411   // Reference to the i'th input Node.  Error if out of bounds.
 412   Node* in(uint i) const { assert(i < _max, "oob: i=%d, _max=%d", i, _max); return _in[i]; }
 413   // Reference to the i'th input Node.  null if out of bounds.
 414   Node* lookup(uint i) const { return ((i < _max) ? _in[i] : nullptr); }
 415   // Reference to the i'th output Node.  Error if out of bounds.
 416   // Use this accessor sparingly.  We are going trying to use iterators instead.
 417   Node* raw_out(uint i) const { assert(i < _outcnt,"oob"); return _out[i]; }
 418   // Return the unique out edge.
 419   Node* unique_out() const { assert(_outcnt==1,"not unique"); return _out[0]; }
 420   // Delete out edge at position 'i' by moving last out edge to position 'i'
 421   void  raw_del_out(uint i) {
 422     assert(i < _outcnt,"oob");
 423     assert(_outcnt > 0,"oob");
 424     #if OPTO_DU_ITERATOR_ASSERT
 425     // Record that a change happened here.
 426     debug_only(_last_del = _out[i]; ++_del_tick);
 427     #endif
 428     _out[i] = _out[--_outcnt];
 429     // Smash the old edge so it can't be used accidentally.
 430     debug_only(_out[_outcnt] = (Node *)(uintptr_t)0xdeadbeef);
 431   }
 432 
 433 #ifdef ASSERT
 434   bool is_dead() const;
 435   static bool is_not_dead(const Node* n);
 436   bool is_reachable_from_root() const;
 437 #endif
 438   // Check whether node has become unreachable
 439   bool is_unreachable(PhaseIterGVN &igvn) const;
 440 
 441   // Set a required input edge, also updates corresponding output edge
 442   void add_req( Node *n ); // Append a NEW required input
 443   void add_req( Node *n0, Node *n1 ) {
 444     add_req(n0); add_req(n1); }
 445   void add_req( Node *n0, Node *n1, Node *n2 ) {
 446     add_req(n0); add_req(n1); add_req(n2); }
 447   void add_req_batch( Node* n, uint m ); // Append m NEW required inputs (all n).
 448   void del_req( uint idx ); // Delete required edge & compact
 449   void del_req_ordered( uint idx ); // Delete required edge & compact with preserved order
 450   void ins_req( uint i, Node *n ); // Insert a NEW required input
 451   void set_req( uint i, Node *n ) {
 452     assert( is_not_dead(n), "can not use dead node");
 453     assert( i < _cnt, "oob: i=%d, _cnt=%d", i, _cnt);
 454     assert( !VerifyHashTableKeys || _hash_lock == 0,
 455             "remove node from hash table before modifying it");
 456     Node** p = &_in[i];    // cache this._in, across the del_out call
 457     if (*p != nullptr)  (*p)->del_out((Node *)this);
 458     (*p) = n;
 459     if (n != nullptr)      n->add_out((Node *)this);
 460     Compile::current()->record_modified_node(this);
 461   }
 462   // Light version of set_req() to init inputs after node creation.
 463   void init_req( uint i, Node *n ) {
 464     assert( (i == 0 && this == n) ||
 465             is_not_dead(n), "can not use dead node");
 466     assert( i < _cnt, "oob");
 467     assert( !VerifyHashTableKeys || _hash_lock == 0,
 468             "remove node from hash table before modifying it");
 469     assert( _in[i] == nullptr, "sanity");
 470     _in[i] = n;
 471     if (n != nullptr)      n->add_out((Node *)this);
 472     Compile::current()->record_modified_node(this);
 473   }
 474   // Find first occurrence of n among my edges:
 475   int find_edge(Node* n);
 476   int find_prec_edge(Node* n) {
 477     for (uint i = req(); i < len(); i++) {
 478       if (_in[i] == n) return i;
 479       if (_in[i] == nullptr) {
 480         DEBUG_ONLY( while ((++i) < len()) assert(_in[i] == nullptr, "Gap in prec edges!"); )
 481         break;
 482       }
 483     }
 484     return -1;
 485   }
 486   int replace_edge(Node* old, Node* neww, PhaseGVN* gvn = nullptr);
 487   int replace_edges_in_range(Node* old, Node* neww, int start, int end, PhaseGVN* gvn);
 488   // null out all inputs to eliminate incoming Def-Use edges.
 489   void disconnect_inputs(Compile* C);
 490 
 491   // Quickly, return true if and only if I am Compile::current()->top().
 492   bool is_top() const {
 493     assert((this == (Node*) Compile::current()->top()) == (_out == nullptr), "");
 494     return (_out == nullptr);
 495   }
 496   // Reaffirm invariants for is_top.  (Only from Compile::set_cached_top_node.)
 497   void setup_is_top();
 498 
 499   // Strip away casting.  (It is depth-limited.)
 500   Node* uncast(bool keep_deps = false) const;
 501   // Return whether two Nodes are equivalent, after stripping casting.
 502   bool eqv_uncast(const Node* n, bool keep_deps = false) const {
 503     return (this->uncast(keep_deps) == n->uncast(keep_deps));
 504   }
 505 
 506   // Find out of current node that matches opcode.
 507   Node* find_out_with(int opcode);
 508   // Return true if the current node has an out that matches opcode.
 509   bool has_out_with(int opcode);
 510   // Return true if the current node has an out that matches any of the opcodes.
 511   bool has_out_with(int opcode1, int opcode2, int opcode3, int opcode4);
 512 
 513 private:
 514   static Node* uncast_helper(const Node* n, bool keep_deps);
 515 
 516   // Add an output edge to the end of the list
 517   void add_out( Node *n ) {
 518     if (is_top())  return;
 519     if( _outcnt == _outmax ) out_grow(_outcnt);
 520     _out[_outcnt++] = n;
 521   }
 522   // Delete an output edge
 523   void del_out( Node *n ) {
 524     if (is_top())  return;
 525     Node** outp = &_out[_outcnt];
 526     // Find and remove n
 527     do {
 528       assert(outp > _out, "Missing Def-Use edge");
 529     } while (*--outp != n);
 530     *outp = _out[--_outcnt];
 531     // Smash the old edge so it can't be used accidentally.
 532     debug_only(_out[_outcnt] = (Node *)(uintptr_t)0xdeadbeef);
 533     // Record that a change happened here.
 534     #if OPTO_DU_ITERATOR_ASSERT
 535     debug_only(_last_del = n; ++_del_tick);
 536     #endif
 537   }
 538   // Close gap after removing edge.
 539   void close_prec_gap_at(uint gap) {
 540     assert(_cnt <= gap && gap < _max, "no valid prec edge");
 541     uint i = gap;
 542     Node *last = nullptr;
 543     for (; i < _max-1; ++i) {
 544       Node *next = _in[i+1];
 545       if (next == nullptr) break;
 546       last = next;
 547     }
 548     _in[gap] = last;  // Move last slot to empty one.
 549     _in[i] = nullptr; // null out last slot.
 550   }
 551 
 552 public:
 553   // Globally replace this node by a given new node, updating all uses.
 554   void replace_by(Node* new_node);
 555   // Globally replace this node by a given new node, updating all uses
 556   // and cutting input edges of old node.
 557   void subsume_by(Node* new_node, Compile* c) {
 558     replace_by(new_node);
 559     disconnect_inputs(c);
 560   }
 561   void set_req_X(uint i, Node *n, PhaseIterGVN *igvn);
 562   void set_req_X(uint i, Node *n, PhaseGVN *gvn);
 563   // Find the one non-null required input.  RegionNode only
 564   Node *nonnull_req() const;
 565   // Add or remove precedence edges
 566   void add_prec( Node *n );
 567   void rm_prec( uint i );
 568 
 569   // Note: prec(i) will not necessarily point to n if edge already exists.
 570   void set_prec( uint i, Node *n ) {
 571     assert(i < _max, "oob: i=%d, _max=%d", i, _max);
 572     assert(is_not_dead(n), "can not use dead node");
 573     assert(i >= _cnt, "not a precedence edge");
 574     // Avoid spec violation: duplicated prec edge.
 575     if (_in[i] == n) return;
 576     if (n == nullptr || find_prec_edge(n) != -1) {
 577       rm_prec(i);
 578       return;
 579     }
 580     if (_in[i] != nullptr) _in[i]->del_out((Node *)this);
 581     _in[i] = n;
 582     n->add_out((Node *)this);
 583     Compile::current()->record_modified_node(this);
 584   }
 585 
 586   // Set this node's index, used by cisc_version to replace current node
 587   void set_idx(uint new_idx) {
 588     const node_idx_t* ref = &_idx;
 589     *(node_idx_t*)ref = new_idx;
 590   }
 591   // Swap input edge order.  (Edge indexes i1 and i2 are usually 1 and 2.)
 592   void swap_edges(uint i1, uint i2) {
 593     debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH);
 594     // Def-Use info is unchanged
 595     Node* n1 = in(i1);
 596     Node* n2 = in(i2);
 597     _in[i1] = n2;
 598     _in[i2] = n1;
 599     // If this node is in the hash table, make sure it doesn't need a rehash.
 600     assert(check_hash == NO_HASH || check_hash == hash(), "edge swap must preserve hash code");
 601     // Flip swapped edges flag.
 602     if (has_swapped_edges()) {
 603       remove_flag(Node::Flag_has_swapped_edges);
 604     } else {
 605       add_flag(Node::Flag_has_swapped_edges);
 606     }
 607   }
 608 
 609   // Iterators over input Nodes for a Node X are written as:
 610   // for( i = 0; i < X.req(); i++ ) ... X[i] ...
 611   // NOTE: Required edges can contain embedded null pointers.
 612 
 613 //----------------- Other Node Properties
 614 
 615   // Generate class IDs for (some) ideal nodes so that it is possible to determine
 616   // the type of a node using a non-virtual method call (the method is_<Node>() below).
 617   //
 618   // A class ID of an ideal node is a set of bits. In a class ID, a single bit determines
 619   // the type of the node the ID represents; another subset of an ID's bits are reserved
 620   // for the superclasses of the node represented by the ID.
 621   //
 622   // By design, if A is a supertype of B, A.is_B() returns true and B.is_A()
 623   // returns false. A.is_A() returns true.
 624   //
 625   // If two classes, A and B, have the same superclass, a different bit of A's class id
 626   // is reserved for A's type than for B's type. That bit is specified by the third
 627   // parameter in the macro DEFINE_CLASS_ID.
 628   //
 629   // By convention, classes with deeper hierarchy are declared first. Moreover,
 630   // classes with the same hierarchy depth are sorted by usage frequency.
 631   //
 632   // The query method masks the bits to cut off bits of subclasses and then compares
 633   // the result with the class id (see the macro DEFINE_CLASS_QUERY below).
 634   //
 635   //  Class_MachCall=30, ClassMask_MachCall=31
 636   // 12               8               4               0
 637   //  0   0   0   0   0   0   0   0   1   1   1   1   0
 638   //                                  |   |   |   |
 639   //                                  |   |   |   Bit_Mach=2
 640   //                                  |   |   Bit_MachReturn=4
 641   //                                  |   Bit_MachSafePoint=8
 642   //                                  Bit_MachCall=16
 643   //
 644   //  Class_CountedLoop=56, ClassMask_CountedLoop=63
 645   // 12               8               4               0
 646   //  0   0   0   0   0   0   0   1   1   1   0   0   0
 647   //                              |   |   |
 648   //                              |   |   Bit_Region=8
 649   //                              |   Bit_Loop=16
 650   //                              Bit_CountedLoop=32
 651 
 652   #define DEFINE_CLASS_ID(cl, supcl, subn) \
 653   Bit_##cl = (Class_##supcl == 0) ? 1 << subn : (Bit_##supcl) << (1 + subn) , \
 654   Class_##cl = Class_##supcl + Bit_##cl , \
 655   ClassMask_##cl = ((Bit_##cl << 1) - 1) ,
 656 
 657   // This enum is used only for C2 ideal and mach nodes with is_<node>() methods
 658   // so that its values fit into 32 bits.
 659   enum NodeClasses {
 660     Bit_Node   = 0x00000000,
 661     Class_Node = 0x00000000,
 662     ClassMask_Node = 0xFFFFFFFF,
 663 
 664     DEFINE_CLASS_ID(Multi, Node, 0)
 665       DEFINE_CLASS_ID(SafePoint, Multi, 0)
 666         DEFINE_CLASS_ID(Call,      SafePoint, 0)
 667           DEFINE_CLASS_ID(CallJava,         Call, 0)
 668             DEFINE_CLASS_ID(CallStaticJava,   CallJava, 0)
 669             DEFINE_CLASS_ID(CallDynamicJava,  CallJava, 1)
 670           DEFINE_CLASS_ID(CallRuntime,      Call, 1)
 671             DEFINE_CLASS_ID(CallLeaf,         CallRuntime, 0)
 672               DEFINE_CLASS_ID(CallLeafNoFP,     CallLeaf, 0)
 673           DEFINE_CLASS_ID(Allocate,         Call, 2)
 674             DEFINE_CLASS_ID(AllocateArray,    Allocate, 0)
 675           DEFINE_CLASS_ID(AbstractLock,     Call, 3)
 676             DEFINE_CLASS_ID(Lock,             AbstractLock, 0)
 677             DEFINE_CLASS_ID(Unlock,           AbstractLock, 1)
 678           DEFINE_CLASS_ID(ArrayCopy,        Call, 4)
 679       DEFINE_CLASS_ID(MultiBranch, Multi, 1)
 680         DEFINE_CLASS_ID(PCTable,     MultiBranch, 0)
 681           DEFINE_CLASS_ID(Catch,       PCTable, 0)
 682           DEFINE_CLASS_ID(Jump,        PCTable, 1)
 683         DEFINE_CLASS_ID(If,          MultiBranch, 1)
 684           DEFINE_CLASS_ID(BaseCountedLoopEnd,     If, 0)
 685             DEFINE_CLASS_ID(CountedLoopEnd,       BaseCountedLoopEnd, 0)
 686             DEFINE_CLASS_ID(LongCountedLoopEnd,   BaseCountedLoopEnd, 1)
 687           DEFINE_CLASS_ID(RangeCheck,             If, 1)
 688           DEFINE_CLASS_ID(OuterStripMinedLoopEnd, If, 2)
 689           DEFINE_CLASS_ID(ParsePredicate,         If, 3)
 690         DEFINE_CLASS_ID(NeverBranch, MultiBranch, 2)
 691       DEFINE_CLASS_ID(Start,       Multi, 2)
 692       DEFINE_CLASS_ID(MemBar,      Multi, 3)
 693         DEFINE_CLASS_ID(Initialize,       MemBar, 0)
 694         DEFINE_CLASS_ID(MemBarStoreStore, MemBar, 1)
 695 
 696     DEFINE_CLASS_ID(Mach,  Node, 1)
 697       DEFINE_CLASS_ID(MachReturn, Mach, 0)
 698         DEFINE_CLASS_ID(MachSafePoint, MachReturn, 0)
 699           DEFINE_CLASS_ID(MachCall, MachSafePoint, 0)
 700             DEFINE_CLASS_ID(MachCallJava,         MachCall, 0)
 701               DEFINE_CLASS_ID(MachCallStaticJava,   MachCallJava, 0)
 702               DEFINE_CLASS_ID(MachCallDynamicJava,  MachCallJava, 1)
 703             DEFINE_CLASS_ID(MachCallRuntime,      MachCall, 1)
 704               DEFINE_CLASS_ID(MachCallLeaf,         MachCallRuntime, 0)
 705       DEFINE_CLASS_ID(MachBranch, Mach, 1)
 706         DEFINE_CLASS_ID(MachIf,         MachBranch, 0)
 707         DEFINE_CLASS_ID(MachGoto,       MachBranch, 1)
 708         DEFINE_CLASS_ID(MachNullCheck,  MachBranch, 2)
 709       DEFINE_CLASS_ID(MachSpillCopy,    Mach, 2)
 710       DEFINE_CLASS_ID(MachTemp,         Mach, 3)
 711       DEFINE_CLASS_ID(MachConstantBase, Mach, 4)
 712       DEFINE_CLASS_ID(MachConstant,     Mach, 5)
 713         DEFINE_CLASS_ID(MachJump,       MachConstant, 0)
 714       DEFINE_CLASS_ID(MachMerge,        Mach, 6)
 715       DEFINE_CLASS_ID(MachMemBar,       Mach, 7)
 716 
 717     DEFINE_CLASS_ID(Type,  Node, 2)
 718       DEFINE_CLASS_ID(Phi,   Type, 0)
 719       DEFINE_CLASS_ID(ConstraintCast, Type, 1)
 720         DEFINE_CLASS_ID(CastII, ConstraintCast, 0)
 721         DEFINE_CLASS_ID(CheckCastPP, ConstraintCast, 1)
 722         DEFINE_CLASS_ID(CastLL, ConstraintCast, 2)
 723         DEFINE_CLASS_ID(CastFF, ConstraintCast, 3)
 724         DEFINE_CLASS_ID(CastDD, ConstraintCast, 4)
 725         DEFINE_CLASS_ID(CastVV, ConstraintCast, 5)
 726         DEFINE_CLASS_ID(CastPP, ConstraintCast, 6)
 727       DEFINE_CLASS_ID(CMove, Type, 3)
 728       DEFINE_CLASS_ID(SafePointScalarObject, Type, 4)
 729       DEFINE_CLASS_ID(DecodeNarrowPtr, Type, 5)
 730         DEFINE_CLASS_ID(DecodeN, DecodeNarrowPtr, 0)
 731         DEFINE_CLASS_ID(DecodeNKlass, DecodeNarrowPtr, 1)
 732       DEFINE_CLASS_ID(EncodeNarrowPtr, Type, 6)
 733         DEFINE_CLASS_ID(EncodeP, EncodeNarrowPtr, 0)
 734         DEFINE_CLASS_ID(EncodePKlass, EncodeNarrowPtr, 1)
 735       DEFINE_CLASS_ID(Vector, Type, 7)
 736         DEFINE_CLASS_ID(VectorMaskCmp, Vector, 0)
 737         DEFINE_CLASS_ID(VectorUnbox, Vector, 1)
 738         DEFINE_CLASS_ID(VectorReinterpret, Vector, 2)
 739         DEFINE_CLASS_ID(ShiftV, Vector, 3)
 740         DEFINE_CLASS_ID(CompressV, Vector, 4)
 741         DEFINE_CLASS_ID(ExpandV, Vector, 5)
 742         DEFINE_CLASS_ID(CompressM, Vector, 6)
 743         DEFINE_CLASS_ID(Reduction, Vector, 7)
 744         DEFINE_CLASS_ID(NegV, Vector, 8)
 745         DEFINE_CLASS_ID(SaturatingVector, Vector, 9)
 746       DEFINE_CLASS_ID(Con, Type, 8)
 747           DEFINE_CLASS_ID(ConI, Con, 0)
 748       DEFINE_CLASS_ID(SafePointScalarMerge, Type, 9)
 749       DEFINE_CLASS_ID(Convert, Type, 10)
 750 
 751 
 752     DEFINE_CLASS_ID(Proj,  Node, 3)
 753       DEFINE_CLASS_ID(CatchProj, Proj, 0)
 754       DEFINE_CLASS_ID(JumpProj,  Proj, 1)
 755       DEFINE_CLASS_ID(IfProj,    Proj, 2)
 756         DEFINE_CLASS_ID(IfTrue,    IfProj, 0)
 757         DEFINE_CLASS_ID(IfFalse,   IfProj, 1)
 758       DEFINE_CLASS_ID(Parm,      Proj, 4)
 759       DEFINE_CLASS_ID(MachProj,  Proj, 5)
 760 
 761     DEFINE_CLASS_ID(Mem, Node, 4)
 762       DEFINE_CLASS_ID(Load, Mem, 0)
 763         DEFINE_CLASS_ID(LoadVector,  Load, 0)
 764           DEFINE_CLASS_ID(LoadVectorGather, LoadVector, 0)
 765           DEFINE_CLASS_ID(LoadVectorGatherMasked, LoadVector, 1)
 766           DEFINE_CLASS_ID(LoadVectorMasked, LoadVector, 2)
 767       DEFINE_CLASS_ID(Store, Mem, 1)
 768         DEFINE_CLASS_ID(StoreVector, Store, 0)
 769           DEFINE_CLASS_ID(StoreVectorScatter, StoreVector, 0)
 770           DEFINE_CLASS_ID(StoreVectorScatterMasked, StoreVector, 1)
 771           DEFINE_CLASS_ID(StoreVectorMasked, StoreVector, 2)
 772       DEFINE_CLASS_ID(LoadStore, Mem, 2)
 773         DEFINE_CLASS_ID(LoadStoreConditional, LoadStore, 0)
 774           DEFINE_CLASS_ID(CompareAndSwap, LoadStoreConditional, 0)
 775         DEFINE_CLASS_ID(CompareAndExchangeNode, LoadStore, 1)
 776 
 777     DEFINE_CLASS_ID(Region, Node, 5)
 778       DEFINE_CLASS_ID(Loop, Region, 0)
 779         DEFINE_CLASS_ID(Root,                Loop, 0)
 780         DEFINE_CLASS_ID(BaseCountedLoop,     Loop, 1)
 781           DEFINE_CLASS_ID(CountedLoop,       BaseCountedLoop, 0)
 782           DEFINE_CLASS_ID(LongCountedLoop,   BaseCountedLoop, 1)
 783         DEFINE_CLASS_ID(OuterStripMinedLoop, Loop, 2)
 784 
 785     DEFINE_CLASS_ID(Sub,   Node, 6)
 786       DEFINE_CLASS_ID(Cmp,   Sub, 0)
 787         DEFINE_CLASS_ID(FastLock,   Cmp, 0)
 788         DEFINE_CLASS_ID(FastUnlock, Cmp, 1)
 789         DEFINE_CLASS_ID(SubTypeCheck,Cmp, 2)
 790 
 791     DEFINE_CLASS_ID(MergeMem, Node, 7)
 792     DEFINE_CLASS_ID(Bool,     Node, 8)
 793     DEFINE_CLASS_ID(AddP,     Node, 9)
 794     DEFINE_CLASS_ID(BoxLock,  Node, 10)
 795     DEFINE_CLASS_ID(Add,      Node, 11)
 796     DEFINE_CLASS_ID(Mul,      Node, 12)
 797     DEFINE_CLASS_ID(ClearArray, Node, 14)
 798     DEFINE_CLASS_ID(Halt,     Node, 15)
 799     DEFINE_CLASS_ID(Opaque1,  Node, 16)
 800       DEFINE_CLASS_ID(OpaqueLoopInit, Opaque1, 0)
 801       DEFINE_CLASS_ID(OpaqueLoopStride, Opaque1, 1)
 802     DEFINE_CLASS_ID(OpaqueNotNull,  Node, 17)
 803     DEFINE_CLASS_ID(OpaqueInitializedAssertionPredicate,  Node, 18)
 804     DEFINE_CLASS_ID(OpaqueTemplateAssertionPredicate,  Node, 19)
 805     DEFINE_CLASS_ID(Move,     Node, 20)
 806     DEFINE_CLASS_ID(LShift,   Node, 21)
 807     DEFINE_CLASS_ID(Neg,      Node, 22)
 808 
 809     _max_classes  = ClassMask_Neg
 810   };
 811   #undef DEFINE_CLASS_ID
 812 
 813   // Flags are sorted by usage frequency.
 814   enum NodeFlags {
 815     Flag_is_Copy                     = 1 << 0, // should be first bit to avoid shift
 816     Flag_rematerialize               = 1 << 1,
 817     Flag_needs_anti_dependence_check = 1 << 2,
 818     Flag_is_macro                    = 1 << 3,
 819     Flag_is_Con                      = 1 << 4,
 820     Flag_is_cisc_alternate           = 1 << 5,
 821     Flag_is_dead_loop_safe           = 1 << 6,
 822     Flag_may_be_short_branch         = 1 << 7,
 823     Flag_avoid_back_to_back_before   = 1 << 8,
 824     Flag_avoid_back_to_back_after    = 1 << 9,
 825     Flag_has_call                    = 1 << 10,
 826     Flag_has_swapped_edges           = 1 << 11,
 827     Flag_is_scheduled                = 1 << 12,
 828     Flag_is_expensive                = 1 << 13,
 829     Flag_is_predicated_vector        = 1 << 14,
 830     Flag_for_post_loop_opts_igvn     = 1 << 15,
 831     Flag_is_removed_by_peephole      = 1 << 16,
 832     Flag_is_predicated_using_blend   = 1 << 17,
 833     _last_flag                       = Flag_is_predicated_using_blend
 834   };
 835 
 836   class PD;
 837 
 838 private:
 839   juint _class_id;
 840   juint _flags;
 841 
 842 #ifdef ASSERT
 843   static juint max_flags();
 844 #endif
 845 
 846 protected:
 847   // These methods should be called from constructors only.
 848   void init_class_id(juint c) {
 849     _class_id = c; // cast out const
 850   }
 851   void init_flags(uint fl) {
 852     assert(fl <= max_flags(), "invalid node flag");
 853     _flags |= fl;
 854   }
 855   void clear_flag(uint fl) {
 856     assert(fl <= max_flags(), "invalid node flag");
 857     _flags &= ~fl;
 858   }
 859 
 860 public:
 861   juint class_id() const { return _class_id; }
 862 
 863   juint flags() const { return _flags; }
 864 
 865   void add_flag(juint fl) { init_flags(fl); }
 866 
 867   void remove_flag(juint fl) { clear_flag(fl); }
 868 
 869   // Return a dense integer opcode number
 870   virtual int Opcode() const;
 871 
 872   // Virtual inherited Node size
 873   virtual uint size_of() const;
 874 
 875   // Other interesting Node properties
 876   #define DEFINE_CLASS_QUERY(type)                           \
 877   bool is_##type() const {                                   \
 878     return ((_class_id & ClassMask_##type) == Class_##type); \
 879   }                                                          \
 880   type##Node *as_##type() const {                            \
 881     assert(is_##type(), "invalid node class: %s", Name());   \
 882     return (type##Node*)this;                                \
 883   }                                                          \
 884   type##Node* isa_##type() const {                           \
 885     return (is_##type()) ? as_##type() : nullptr;            \
 886   }
 887 
 888   DEFINE_CLASS_QUERY(AbstractLock)
 889   DEFINE_CLASS_QUERY(Add)
 890   DEFINE_CLASS_QUERY(AddP)
 891   DEFINE_CLASS_QUERY(Allocate)
 892   DEFINE_CLASS_QUERY(AllocateArray)
 893   DEFINE_CLASS_QUERY(ArrayCopy)
 894   DEFINE_CLASS_QUERY(BaseCountedLoop)
 895   DEFINE_CLASS_QUERY(BaseCountedLoopEnd)
 896   DEFINE_CLASS_QUERY(Bool)
 897   DEFINE_CLASS_QUERY(BoxLock)
 898   DEFINE_CLASS_QUERY(Call)
 899   DEFINE_CLASS_QUERY(CallDynamicJava)
 900   DEFINE_CLASS_QUERY(CallJava)
 901   DEFINE_CLASS_QUERY(CallLeaf)
 902   DEFINE_CLASS_QUERY(CallLeafNoFP)
 903   DEFINE_CLASS_QUERY(CallRuntime)
 904   DEFINE_CLASS_QUERY(CallStaticJava)
 905   DEFINE_CLASS_QUERY(Catch)
 906   DEFINE_CLASS_QUERY(CatchProj)
 907   DEFINE_CLASS_QUERY(CheckCastPP)
 908   DEFINE_CLASS_QUERY(CastII)
 909   DEFINE_CLASS_QUERY(CastLL)
 910   DEFINE_CLASS_QUERY(ConI)
 911   DEFINE_CLASS_QUERY(CastPP)
 912   DEFINE_CLASS_QUERY(ConstraintCast)
 913   DEFINE_CLASS_QUERY(ClearArray)
 914   DEFINE_CLASS_QUERY(CMove)
 915   DEFINE_CLASS_QUERY(Cmp)
 916   DEFINE_CLASS_QUERY(Convert)
 917   DEFINE_CLASS_QUERY(CountedLoop)
 918   DEFINE_CLASS_QUERY(CountedLoopEnd)
 919   DEFINE_CLASS_QUERY(DecodeNarrowPtr)
 920   DEFINE_CLASS_QUERY(DecodeN)
 921   DEFINE_CLASS_QUERY(DecodeNKlass)
 922   DEFINE_CLASS_QUERY(EncodeNarrowPtr)
 923   DEFINE_CLASS_QUERY(EncodeP)
 924   DEFINE_CLASS_QUERY(EncodePKlass)
 925   DEFINE_CLASS_QUERY(FastLock)
 926   DEFINE_CLASS_QUERY(FastUnlock)
 927   DEFINE_CLASS_QUERY(Halt)
 928   DEFINE_CLASS_QUERY(If)
 929   DEFINE_CLASS_QUERY(RangeCheck)
 930   DEFINE_CLASS_QUERY(IfProj)
 931   DEFINE_CLASS_QUERY(IfFalse)
 932   DEFINE_CLASS_QUERY(IfTrue)
 933   DEFINE_CLASS_QUERY(Initialize)
 934   DEFINE_CLASS_QUERY(Jump)
 935   DEFINE_CLASS_QUERY(JumpProj)
 936   DEFINE_CLASS_QUERY(LongCountedLoop)
 937   DEFINE_CLASS_QUERY(LongCountedLoopEnd)
 938   DEFINE_CLASS_QUERY(Load)
 939   DEFINE_CLASS_QUERY(LoadStore)
 940   DEFINE_CLASS_QUERY(LoadStoreConditional)
 941   DEFINE_CLASS_QUERY(Lock)
 942   DEFINE_CLASS_QUERY(Loop)
 943   DEFINE_CLASS_QUERY(LShift)
 944   DEFINE_CLASS_QUERY(Mach)
 945   DEFINE_CLASS_QUERY(MachBranch)
 946   DEFINE_CLASS_QUERY(MachCall)
 947   DEFINE_CLASS_QUERY(MachCallDynamicJava)
 948   DEFINE_CLASS_QUERY(MachCallJava)
 949   DEFINE_CLASS_QUERY(MachCallLeaf)
 950   DEFINE_CLASS_QUERY(MachCallRuntime)
 951   DEFINE_CLASS_QUERY(MachCallStaticJava)
 952   DEFINE_CLASS_QUERY(MachConstantBase)
 953   DEFINE_CLASS_QUERY(MachConstant)
 954   DEFINE_CLASS_QUERY(MachGoto)
 955   DEFINE_CLASS_QUERY(MachIf)
 956   DEFINE_CLASS_QUERY(MachJump)
 957   DEFINE_CLASS_QUERY(MachNullCheck)
 958   DEFINE_CLASS_QUERY(MachProj)
 959   DEFINE_CLASS_QUERY(MachReturn)
 960   DEFINE_CLASS_QUERY(MachSafePoint)
 961   DEFINE_CLASS_QUERY(MachSpillCopy)
 962   DEFINE_CLASS_QUERY(MachTemp)
 963   DEFINE_CLASS_QUERY(MachMemBar)
 964   DEFINE_CLASS_QUERY(MachMerge)
 965   DEFINE_CLASS_QUERY(Mem)
 966   DEFINE_CLASS_QUERY(MemBar)
 967   DEFINE_CLASS_QUERY(MemBarStoreStore)
 968   DEFINE_CLASS_QUERY(MergeMem)
 969   DEFINE_CLASS_QUERY(Move)
 970   DEFINE_CLASS_QUERY(Mul)
 971   DEFINE_CLASS_QUERY(Multi)
 972   DEFINE_CLASS_QUERY(MultiBranch)
 973   DEFINE_CLASS_QUERY(Neg)
 974   DEFINE_CLASS_QUERY(NegV)
 975   DEFINE_CLASS_QUERY(NeverBranch)
 976   DEFINE_CLASS_QUERY(Opaque1)
 977   DEFINE_CLASS_QUERY(OpaqueNotNull)
 978   DEFINE_CLASS_QUERY(OpaqueInitializedAssertionPredicate)
 979   DEFINE_CLASS_QUERY(OpaqueTemplateAssertionPredicate)
 980   DEFINE_CLASS_QUERY(OpaqueLoopInit)
 981   DEFINE_CLASS_QUERY(OpaqueLoopStride)
 982   DEFINE_CLASS_QUERY(OuterStripMinedLoop)
 983   DEFINE_CLASS_QUERY(OuterStripMinedLoopEnd)
 984   DEFINE_CLASS_QUERY(Parm)
 985   DEFINE_CLASS_QUERY(ParsePredicate)
 986   DEFINE_CLASS_QUERY(PCTable)
 987   DEFINE_CLASS_QUERY(Phi)
 988   DEFINE_CLASS_QUERY(Proj)
 989   DEFINE_CLASS_QUERY(Reduction)
 990   DEFINE_CLASS_QUERY(Region)
 991   DEFINE_CLASS_QUERY(Root)
 992   DEFINE_CLASS_QUERY(SafePoint)
 993   DEFINE_CLASS_QUERY(SafePointScalarObject)
 994   DEFINE_CLASS_QUERY(SafePointScalarMerge)
 995   DEFINE_CLASS_QUERY(Start)
 996   DEFINE_CLASS_QUERY(Store)
 997   DEFINE_CLASS_QUERY(Sub)
 998   DEFINE_CLASS_QUERY(SubTypeCheck)
 999   DEFINE_CLASS_QUERY(Type)
1000   DEFINE_CLASS_QUERY(Vector)
1001   DEFINE_CLASS_QUERY(VectorMaskCmp)
1002   DEFINE_CLASS_QUERY(VectorUnbox)
1003   DEFINE_CLASS_QUERY(VectorReinterpret)
1004   DEFINE_CLASS_QUERY(CompressV)
1005   DEFINE_CLASS_QUERY(ExpandV)
1006   DEFINE_CLASS_QUERY(CompressM)
1007   DEFINE_CLASS_QUERY(LoadVector)
1008   DEFINE_CLASS_QUERY(LoadVectorGather)
1009   DEFINE_CLASS_QUERY(LoadVectorMasked)
1010   DEFINE_CLASS_QUERY(LoadVectorGatherMasked)
1011   DEFINE_CLASS_QUERY(StoreVector)
1012   DEFINE_CLASS_QUERY(StoreVectorScatter)
1013   DEFINE_CLASS_QUERY(StoreVectorMasked)
1014   DEFINE_CLASS_QUERY(StoreVectorScatterMasked)
1015   DEFINE_CLASS_QUERY(SaturatingVector)
1016   DEFINE_CLASS_QUERY(ShiftV)
1017   DEFINE_CLASS_QUERY(Unlock)
1018 
1019   #undef DEFINE_CLASS_QUERY
1020 
1021   // duplicate of is_MachSpillCopy()
1022   bool is_SpillCopy () const {
1023     return ((_class_id & ClassMask_MachSpillCopy) == Class_MachSpillCopy);
1024   }
1025 
1026   bool is_Con () const { return (_flags & Flag_is_Con) != 0; }
1027   // The data node which is safe to leave in dead loop during IGVN optimization.
1028   bool is_dead_loop_safe() const;
1029 
1030   // is_Copy() returns copied edge index (0 or 1)
1031   uint is_Copy() const { return (_flags & Flag_is_Copy); }
1032 
1033   virtual bool is_CFG() const { return false; }
1034 
1035   // If this node is control-dependent on a test, can it be
1036   // rerouted to a dominating equivalent test?  This is usually
1037   // true of non-CFG nodes, but can be false for operations which
1038   // depend for their correct sequencing on more than one test.
1039   // (In that case, hoisting to a dominating test may silently
1040   // skip some other important test.)
1041   virtual bool depends_only_on_test() const { assert(!is_CFG(), ""); return true; };
1042 
1043   // When building basic blocks, I need to have a notion of block beginning
1044   // Nodes, next block selector Nodes (block enders), and next block
1045   // projections.  These calls need to work on their machine equivalents.  The
1046   // Ideal beginning Nodes are RootNode, RegionNode and StartNode.
1047   bool is_block_start() const {
1048     if ( is_Region() )
1049       return this == (const Node*)in(0);
1050     else
1051       return is_Start();
1052   }
1053 
1054   // The Ideal control projection Nodes are IfTrue/IfFalse, JumpProjNode, Root,
1055   // Goto and Return.  This call also returns the block ending Node.
1056   virtual const Node *is_block_proj() const;
1057 
1058   // The node is a "macro" node which needs to be expanded before matching
1059   bool is_macro() const { return (_flags & Flag_is_macro) != 0; }
1060   // The node is expensive: the best control is set during loop opts
1061   bool is_expensive() const { return (_flags & Flag_is_expensive) != 0 && in(0) != nullptr; }
1062   // The node's original edge position is swapped.
1063   bool has_swapped_edges() const { return (_flags & Flag_has_swapped_edges) != 0; }
1064 
1065   bool is_predicated_vector() const { return (_flags & Flag_is_predicated_vector) != 0; }
1066 
1067   bool is_predicated_using_blend() const { return (_flags & Flag_is_predicated_using_blend) != 0; }
1068 
1069   // Used in lcm to mark nodes that have scheduled
1070   bool is_scheduled() const { return (_flags & Flag_is_scheduled) != 0; }
1071 
1072   bool for_post_loop_opts_igvn() const { return (_flags & Flag_for_post_loop_opts_igvn) != 0; }
1073 
1074   // Is 'n' possibly a loop entry (i.e. a Parse Predicate projection)?
1075   static bool may_be_loop_entry(Node* n) {
1076     return n != nullptr && n->is_IfProj() && n->in(0)->is_ParsePredicate();
1077   }
1078 
1079 //----------------- Optimization
1080 
1081   // Get the worst-case Type output for this Node.
1082   virtual const class Type *bottom_type() const;
1083 
1084   // If we find a better type for a node, try to record it permanently.
1085   // Return true if this node actually changed.
1086   // Be sure to do the hash_delete game in the "rehash" variant.
1087   void raise_bottom_type(const Type* new_type);
1088 
1089   // Get the address type with which this node uses and/or defs memory,
1090   // or null if none.  The address type is conservatively wide.
1091   // Returns non-null for calls, membars, loads, stores, etc.
1092   // Returns TypePtr::BOTTOM if the node touches memory "broadly".
1093   virtual const class TypePtr *adr_type() const { return nullptr; }
1094 
1095   // Return an existing node which computes the same function as this node.
1096   // The optimistic combined algorithm requires this to return a Node which
1097   // is a small number of steps away (e.g., one of my inputs).
1098   virtual Node* Identity(PhaseGVN* phase);
1099 
1100   // Return the set of values this Node can take on at runtime.
1101   virtual const Type* Value(PhaseGVN* phase) const;
1102 
1103   // Return a node which is more "ideal" than the current node.
1104   // The invariants on this call are subtle.  If in doubt, read the
1105   // treatise in node.cpp above the default implementation AND TEST WITH
1106   // -XX:VerifyIterativeGVN=1
1107   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
1108 
1109   // Some nodes have specific Ideal subgraph transformations only if they are
1110   // unique users of specific nodes. Such nodes should be put on IGVN worklist
1111   // for the transformations to happen.
1112   bool has_special_unique_user() const;
1113 
1114   // Skip Proj and CatchProj nodes chains. Check for Null and Top.
1115   Node* find_exact_control(Node* ctrl);
1116 
1117   // Results of the dominance analysis.
1118   enum class DomResult {
1119     NotDominate,         // 'this' node does not dominate 'sub'.
1120     Dominate,            // 'this' node dominates or is equal to 'sub'.
1121     EncounteredDeadCode  // Result is undefined due to encountering dead code.
1122   };
1123   // Check if 'this' node dominates or equal to 'sub'.
1124   DomResult dominates(Node* sub, Node_List &nlist);
1125 
1126 protected:
1127   bool remove_dead_region(PhaseGVN *phase, bool can_reshape);
1128 public:
1129 
1130   // See if there is valid pipeline info
1131   static  const Pipeline *pipeline_class();
1132   virtual const Pipeline *pipeline() const;
1133 
1134   // Compute the latency from the def to this instruction of the ith input node
1135   uint latency(uint i);
1136 
1137   // Hash & compare functions, for pessimistic value numbering
1138 
1139   // If the hash function returns the special sentinel value NO_HASH,
1140   // the node is guaranteed never to compare equal to any other node.
1141   // If we accidentally generate a hash with value NO_HASH the node
1142   // won't go into the table and we'll lose a little optimization.
1143   static const uint NO_HASH = 0;
1144   virtual uint hash() const;
1145   virtual bool cmp( const Node &n ) const;
1146 
1147   // Operation appears to be iteratively computed (such as an induction variable)
1148   // It is possible for this operation to return false for a loop-varying
1149   // value, if it appears (by local graph inspection) to be computed by a simple conditional.
1150   bool is_iteratively_computed();
1151 
1152   // Determine if a node is a counted loop induction variable.
1153   // NOTE: The method is defined in "loopnode.cpp".
1154   bool is_cloop_ind_var() const;
1155 
1156   // Return a node with opcode "opc" and same inputs as "this" if one can
1157   // be found; Otherwise return null;
1158   Node* find_similar(int opc);
1159 
1160   // Return the unique control out if only one. Null if none or more than one.
1161   Node* unique_ctrl_out_or_null() const;
1162   // Return the unique control out. Asserts if none or more than one control out.
1163   Node* unique_ctrl_out() const;
1164 
1165   // Set control or add control as precedence edge
1166   void ensure_control_or_add_prec(Node* c);
1167 
1168   // Visit boundary uses of the node and apply a callback function for each.
1169   // Recursively traverse uses, stopping and applying the callback when
1170   // reaching a boundary node, defined by is_boundary. Note: the function
1171   // definition appears after the complete type definition of Node_List.
1172   template <typename Callback, typename Check>
1173   void visit_uses(Callback callback, Check is_boundary) const;
1174 
1175   // Returns a clone of the current node that's pinned (if the current node is not) for nodes found in array accesses
1176   // (Load and range check CastII nodes).
1177   // This is used when an array access is made dependent on 2 or more range checks (range check smearing or Loop Predication).
1178   virtual Node* pin_array_access_node() const {
1179     return nullptr;
1180   }
1181 
1182   //----------------- Code Generation
1183 
1184   // Ideal register class for Matching.  Zero means unmatched instruction
1185   // (these are cloned instead of converted to machine nodes).
1186   virtual uint ideal_reg() const;
1187 
1188   static const uint NotAMachineReg;   // must be > max. machine register
1189 
1190   // Do we Match on this edge index or not?  Generally false for Control
1191   // and true for everything else.  Weird for calls & returns.
1192   virtual uint match_edge(uint idx) const;
1193 
1194   // Register class output is returned in
1195   virtual const RegMask &out_RegMask() const;
1196   // Register class input is expected in
1197   virtual const RegMask &in_RegMask(uint) const;
1198   // Should we clone rather than spill this instruction?
1199   bool rematerialize() const;
1200 
1201   // Return JVM State Object if this Node carries debug info, or null otherwise
1202   virtual JVMState* jvms() const;
1203 
1204   // Print as assembly
1205   virtual void format( PhaseRegAlloc *, outputStream* st = tty ) const;
1206   // Emit bytes using C2_MacroAssembler
1207   virtual void emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const;
1208   // Size of instruction in bytes
1209   virtual uint size(PhaseRegAlloc *ra_) const;
1210 
1211   // Convenience function to extract an integer constant from a node.
1212   // If it is not an integer constant (either Con, CastII, or Mach),
1213   // return value_if_unknown.
1214   jint find_int_con(jint value_if_unknown) const {
1215     const TypeInt* t = find_int_type();
1216     return (t != nullptr && t->is_con()) ? t->get_con() : value_if_unknown;
1217   }
1218   // Return the constant, knowing it is an integer constant already
1219   jint get_int() const {
1220     const TypeInt* t = find_int_type();
1221     guarantee(t != nullptr, "must be con");
1222     return t->get_con();
1223   }
1224   // Here's where the work is done.  Can produce non-constant int types too.
1225   const TypeInt* find_int_type() const;
1226   const TypeInteger* find_integer_type(BasicType bt) const;
1227 
1228   // Same thing for long (and intptr_t, via type.hpp):
1229   jlong get_long() const {
1230     const TypeLong* t = find_long_type();
1231     guarantee(t != nullptr, "must be con");
1232     return t->get_con();
1233   }
1234   jlong find_long_con(jint value_if_unknown) const {
1235     const TypeLong* t = find_long_type();
1236     return (t != nullptr && t->is_con()) ? t->get_con() : value_if_unknown;
1237   }
1238   const TypeLong* find_long_type() const;
1239 
1240   jlong get_integer_as_long(BasicType bt) const {
1241     const TypeInteger* t = find_integer_type(bt);
1242     guarantee(t != nullptr && t->is_con(), "must be con");
1243     return t->get_con_as_long(bt);
1244   }
1245   jlong find_integer_as_long(BasicType bt, jlong value_if_unknown) const {
1246     const TypeInteger* t = find_integer_type(bt);
1247     if (t == nullptr || !t->is_con())  return value_if_unknown;
1248     return t->get_con_as_long(bt);
1249   }
1250   const TypePtr* get_ptr_type() const;
1251 
1252   // These guys are called by code generated by ADLC:
1253   intptr_t get_ptr() const;
1254   intptr_t get_narrowcon() const;
1255   jdouble getd() const;
1256   jfloat getf() const;
1257 
1258   // Nodes which are pinned into basic blocks
1259   virtual bool pinned() const { return false; }
1260 
1261   // Nodes which use memory without consuming it, hence need antidependences
1262   // More specifically, needs_anti_dependence_check returns true iff the node
1263   // (a) does a load, and (b) does not perform a store (except perhaps to a
1264   // stack slot or some other unaliased location).
1265   bool needs_anti_dependence_check() const;
1266 
1267   // Return which operand this instruction may cisc-spill. In other words,
1268   // return operand position that can convert from reg to memory access
1269   virtual int cisc_operand() const { return AdlcVMDeps::Not_cisc_spillable; }
1270   bool is_cisc_alternate() const { return (_flags & Flag_is_cisc_alternate) != 0; }
1271 
1272   // Whether this is a memory-writing machine node.
1273   bool is_memory_writer() const { return is_Mach() && bottom_type()->has_memory(); }
1274 
1275   // Whether this is a memory phi node
1276   bool is_memory_phi() const { return is_Phi() && bottom_type() == Type::MEMORY; }
1277 
1278 //----------------- Printing, etc
1279 #ifndef PRODUCT
1280  public:
1281   Node* find(int idx, bool only_ctrl = false); // Search the graph for the given idx.
1282   Node* find_ctrl(int idx); // Search control ancestors for the given idx.
1283   void dump_bfs(const int max_distance, Node* target, const char* options, outputStream* st) const;
1284   void dump_bfs(const int max_distance, Node* target, const char* options) const; // directly to tty
1285   void dump_bfs(const int max_distance) const; // dump_bfs(max_distance, nullptr, nullptr)
1286   class DumpConfig {
1287    public:
1288     // overridden to implement coloring of node idx
1289     virtual void pre_dump(outputStream *st, const Node* n) = 0;
1290     virtual void post_dump(outputStream *st) = 0;
1291   };
1292   void dump_idx(bool align = false, outputStream* st = tty, DumpConfig* dc = nullptr) const;
1293   void dump_name(outputStream* st = tty, DumpConfig* dc = nullptr) const;
1294   void dump() const; // print node with newline
1295   void dump(const char* suffix, bool mark = false, outputStream* st = tty, DumpConfig* dc = nullptr) const; // Print this node.
1296   void dump(int depth) const;        // Print this node, recursively to depth d
1297   void dump_ctrl(int depth) const;   // Print control nodes, to depth d
1298   void dump_comp() const;            // Print this node in compact representation.
1299   // Print this node in compact representation.
1300   void dump_comp(const char* suffix, outputStream *st = tty) const;
1301  private:
1302   virtual void dump_req(outputStream* st = tty, DumpConfig* dc = nullptr) const;    // Print required-edge info
1303   virtual void dump_prec(outputStream* st = tty, DumpConfig* dc = nullptr) const;   // Print precedence-edge info
1304   virtual void dump_out(outputStream* st = tty, DumpConfig* dc = nullptr) const;    // Print the output edge info
1305  public:
1306   virtual void dump_spec(outputStream *st) const {};      // Print per-node info
1307   // Print compact per-node info
1308   virtual void dump_compact_spec(outputStream *st) const { dump_spec(st); }
1309 
1310   static void verify(int verify_depth, VectorSet& visited, Node_List& worklist);
1311 
1312   // This call defines a class-unique string used to identify class instances
1313   virtual const char *Name() const;
1314 
1315   void dump_format(PhaseRegAlloc *ra) const; // debug access to MachNode::format(...)
1316   static bool in_dump() { return Compile::current()->_in_dump_cnt > 0; } // check if we are in a dump call
1317 #endif
1318 #ifdef ASSERT
1319   void verify_construction();
1320   bool verify_jvms(const JVMState* jvms) const;
1321 
1322   Node* _debug_orig;                   // Original version of this, if any.
1323   Node*  debug_orig() const            { return _debug_orig; }
1324   void   set_debug_orig(Node* orig);   // _debug_orig = orig
1325   void   dump_orig(outputStream *st, bool print_key = true) const;
1326 
1327   uint64_t _debug_idx;                 // Unique value assigned to every node.
1328   uint64_t debug_idx() const           { return _debug_idx; }
1329   void set_debug_idx(uint64_t debug_idx) { _debug_idx = debug_idx; }
1330 
1331   int        _hash_lock;               // Barrier to modifications of nodes in the hash table
1332   void  enter_hash_lock() { ++_hash_lock; assert(_hash_lock < 99, "in too many hash tables?"); }
1333   void   exit_hash_lock() { --_hash_lock; assert(_hash_lock >= 0, "mispaired hash locks"); }
1334 
1335   static void init_NodeProperty();
1336 
1337   #if OPTO_DU_ITERATOR_ASSERT
1338   const Node* _last_del;               // The last deleted node.
1339   uint        _del_tick;               // Bumped when a deletion happens..
1340   #endif
1341 #endif
1342 };
1343 
1344 inline bool not_a_node(const Node* n) {
1345   if (n == nullptr)                return true;
1346   if (((intptr_t)n & 1) != 0)      return true;  // uninitialized, etc.
1347   if (*(address*)n == badAddress)  return true;  // kill by Node::destruct
1348   return false;
1349 }
1350 
1351 //-----------------------------------------------------------------------------
1352 // Iterators over DU info, and associated Node functions.
1353 
1354 #if OPTO_DU_ITERATOR_ASSERT
1355 
1356 // Common code for assertion checking on DU iterators.
1357 class DUIterator_Common {
1358 #ifdef ASSERT
1359  protected:
1360   bool         _vdui;               // cached value of VerifyDUIterators
1361   const Node*  _node;               // the node containing the _out array
1362   uint         _outcnt;             // cached node->_outcnt
1363   uint         _del_tick;           // cached node->_del_tick
1364   Node*        _last;               // last value produced by the iterator
1365 
1366   void sample(const Node* node);    // used by c'tor to set up for verifies
1367   void verify(const Node* node, bool at_end_ok = false);
1368   void verify_resync();
1369   void reset(const DUIterator_Common& that);
1370 
1371 // The VDUI_ONLY macro protects code conditionalized on VerifyDUIterators
1372   #define I_VDUI_ONLY(i,x) { if ((i)._vdui) { x; } }
1373 #else
1374   #define I_VDUI_ONLY(i,x) { }
1375 #endif //ASSERT
1376 };
1377 
1378 #define VDUI_ONLY(x)     I_VDUI_ONLY(*this, x)
1379 
1380 // Default DU iterator.  Allows appends onto the out array.
1381 // Allows deletion from the out array only at the current point.
1382 // Usage:
1383 //  for (DUIterator i = x->outs(); x->has_out(i); i++) {
1384 //    Node* y = x->out(i);
1385 //    ...
1386 //  }
1387 // Compiles in product mode to a unsigned integer index, which indexes
1388 // onto a repeatedly reloaded base pointer of x->_out.  The loop predicate
1389 // also reloads x->_outcnt.  If you delete, you must perform "--i" just
1390 // before continuing the loop.  You must delete only the last-produced
1391 // edge.  You must delete only a single copy of the last-produced edge,
1392 // or else you must delete all copies at once (the first time the edge
1393 // is produced by the iterator).
1394 class DUIterator : public DUIterator_Common {
1395   friend class Node;
1396 
1397   // This is the index which provides the product-mode behavior.
1398   // Whatever the product-mode version of the system does to the
1399   // DUI index is done to this index.  All other fields in
1400   // this class are used only for assertion checking.
1401   uint         _idx;
1402 
1403   #ifdef ASSERT
1404   uint         _refresh_tick;    // Records the refresh activity.
1405 
1406   void sample(const Node* node); // Initialize _refresh_tick etc.
1407   void verify(const Node* node, bool at_end_ok = false);
1408   void verify_increment();       // Verify an increment operation.
1409   void verify_resync();          // Verify that we can back up over a deletion.
1410   void verify_finish();          // Verify that the loop terminated properly.
1411   void refresh();                // Resample verification info.
1412   void reset(const DUIterator& that);  // Resample after assignment.
1413   #endif
1414 
1415   DUIterator(const Node* node, int dummy_to_avoid_conversion)
1416     { _idx = 0;                         debug_only(sample(node)); }
1417 
1418  public:
1419   // initialize to garbage; clear _vdui to disable asserts
1420   DUIterator()
1421     { /*initialize to garbage*/         debug_only(_vdui = false); }
1422 
1423   DUIterator(const DUIterator& that)
1424     { _idx = that._idx;                 debug_only(_vdui = false; reset(that)); }
1425 
1426   void operator++(int dummy_to_specify_postfix_op)
1427     { _idx++;                           VDUI_ONLY(verify_increment()); }
1428 
1429   void operator--()
1430     { VDUI_ONLY(verify_resync());       --_idx; }
1431 
1432   ~DUIterator()
1433     { VDUI_ONLY(verify_finish()); }
1434 
1435   void operator=(const DUIterator& that)
1436     { _idx = that._idx;                 debug_only(reset(that)); }
1437 };
1438 
1439 DUIterator Node::outs() const
1440   { return DUIterator(this, 0); }
1441 DUIterator& Node::refresh_out_pos(DUIterator& i) const
1442   { I_VDUI_ONLY(i, i.refresh());        return i; }
1443 bool Node::has_out(DUIterator& i) const
1444   { I_VDUI_ONLY(i, i.verify(this,true));return i._idx < _outcnt; }
1445 Node*    Node::out(DUIterator& i) const
1446   { I_VDUI_ONLY(i, i.verify(this));     return debug_only(i._last=) _out[i._idx]; }
1447 
1448 
1449 // Faster DU iterator.  Disallows insertions into the out array.
1450 // Allows deletion from the out array only at the current point.
1451 // Usage:
1452 //  for (DUIterator_Fast imax, i = x->fast_outs(imax); i < imax; i++) {
1453 //    Node* y = x->fast_out(i);
1454 //    ...
1455 //  }
1456 // Compiles in product mode to raw Node** pointer arithmetic, with
1457 // no reloading of pointers from the original node x.  If you delete,
1458 // you must perform "--i; --imax" just before continuing the loop.
1459 // If you delete multiple copies of the same edge, you must decrement
1460 // imax, but not i, multiple times:  "--i, imax -= num_edges".
1461 class DUIterator_Fast : public DUIterator_Common {
1462   friend class Node;
1463   friend class DUIterator_Last;
1464 
1465   // This is the pointer which provides the product-mode behavior.
1466   // Whatever the product-mode version of the system does to the
1467   // DUI pointer is done to this pointer.  All other fields in
1468   // this class are used only for assertion checking.
1469   Node**       _outp;
1470 
1471   #ifdef ASSERT
1472   void verify(const Node* node, bool at_end_ok = false);
1473   void verify_limit();
1474   void verify_resync();
1475   void verify_relimit(uint n);
1476   void reset(const DUIterator_Fast& that);
1477   #endif
1478 
1479   // Note:  offset must be signed, since -1 is sometimes passed
1480   DUIterator_Fast(const Node* node, ptrdiff_t offset)
1481     { _outp = node->_out + offset;      debug_only(sample(node)); }
1482 
1483  public:
1484   // initialize to garbage; clear _vdui to disable asserts
1485   DUIterator_Fast()
1486     { /*initialize to garbage*/         debug_only(_vdui = false); }
1487 
1488   DUIterator_Fast(const DUIterator_Fast& that)
1489     { _outp = that._outp;               debug_only(_vdui = false; reset(that)); }
1490 
1491   void operator++(int dummy_to_specify_postfix_op)
1492     { _outp++;                          VDUI_ONLY(verify(_node, true)); }
1493 
1494   void operator--()
1495     { VDUI_ONLY(verify_resync());       --_outp; }
1496 
1497   void operator-=(uint n)   // applied to the limit only
1498     { _outp -= n;           VDUI_ONLY(verify_relimit(n));  }
1499 
1500   bool operator<(DUIterator_Fast& limit) {
1501     I_VDUI_ONLY(*this, this->verify(_node, true));
1502     I_VDUI_ONLY(limit, limit.verify_limit());
1503     return _outp < limit._outp;
1504   }
1505 
1506   void operator=(const DUIterator_Fast& that)
1507     { _outp = that._outp;               debug_only(reset(that)); }
1508 };
1509 
1510 DUIterator_Fast Node::fast_outs(DUIterator_Fast& imax) const {
1511   // Assign a limit pointer to the reference argument:
1512   imax = DUIterator_Fast(this, (ptrdiff_t)_outcnt);
1513   // Return the base pointer:
1514   return DUIterator_Fast(this, 0);
1515 }
1516 Node* Node::fast_out(DUIterator_Fast& i) const {
1517   I_VDUI_ONLY(i, i.verify(this));
1518   return debug_only(i._last=) *i._outp;
1519 }
1520 
1521 
1522 // Faster DU iterator.  Requires each successive edge to be removed.
1523 // Does not allow insertion of any edges.
1524 // Usage:
1525 //  for (DUIterator_Last imin, i = x->last_outs(imin); i >= imin; i -= num_edges) {
1526 //    Node* y = x->last_out(i);
1527 //    ...
1528 //  }
1529 // Compiles in product mode to raw Node** pointer arithmetic, with
1530 // no reloading of pointers from the original node x.
1531 class DUIterator_Last : private DUIterator_Fast {
1532   friend class Node;
1533 
1534   #ifdef ASSERT
1535   void verify(const Node* node, bool at_end_ok = false);
1536   void verify_limit();
1537   void verify_step(uint num_edges);
1538   #endif
1539 
1540   // Note:  offset must be signed, since -1 is sometimes passed
1541   DUIterator_Last(const Node* node, ptrdiff_t offset)
1542     : DUIterator_Fast(node, offset) { }
1543 
1544   void operator++(int dummy_to_specify_postfix_op) {} // do not use
1545   void operator<(int)                              {} // do not use
1546 
1547  public:
1548   DUIterator_Last() { }
1549   // initialize to garbage
1550 
1551   DUIterator_Last(const DUIterator_Last& that) = default;
1552 
1553   void operator--()
1554     { _outp--;              VDUI_ONLY(verify_step(1));  }
1555 
1556   void operator-=(uint n)
1557     { _outp -= n;           VDUI_ONLY(verify_step(n));  }
1558 
1559   bool operator>=(DUIterator_Last& limit) {
1560     I_VDUI_ONLY(*this, this->verify(_node, true));
1561     I_VDUI_ONLY(limit, limit.verify_limit());
1562     return _outp >= limit._outp;
1563   }
1564 
1565   DUIterator_Last& operator=(const DUIterator_Last& that) = default;
1566 };
1567 
1568 DUIterator_Last Node::last_outs(DUIterator_Last& imin) const {
1569   // Assign a limit pointer to the reference argument:
1570   imin = DUIterator_Last(this, 0);
1571   // Return the initial pointer:
1572   return DUIterator_Last(this, (ptrdiff_t)_outcnt - 1);
1573 }
1574 Node* Node::last_out(DUIterator_Last& i) const {
1575   I_VDUI_ONLY(i, i.verify(this));
1576   return debug_only(i._last=) *i._outp;
1577 }
1578 
1579 #endif //OPTO_DU_ITERATOR_ASSERT
1580 
1581 #undef I_VDUI_ONLY
1582 #undef VDUI_ONLY
1583 
1584 // An Iterator that truly follows the iterator pattern.  Doesn't
1585 // support deletion but could be made to.
1586 //
1587 //   for (SimpleDUIterator i(n); i.has_next(); i.next()) {
1588 //     Node* m = i.get();
1589 //
1590 class SimpleDUIterator : public StackObj {
1591  private:
1592   Node* node;
1593   DUIterator_Fast imax;
1594   DUIterator_Fast i;
1595  public:
1596   SimpleDUIterator(Node* n): node(n), i(n->fast_outs(imax)) {}
1597   bool has_next() { return i < imax; }
1598   void next() { i++; }
1599   Node* get() { return node->fast_out(i); }
1600 };
1601 
1602 
1603 //-----------------------------------------------------------------------------
1604 // Map dense integer indices to Nodes.  Uses classic doubling-array trick.
1605 // Abstractly provides an infinite array of Node*'s, initialized to null.
1606 // Note that the constructor just zeros things, and since I use Arena
1607 // allocation I do not need a destructor to reclaim storage.
1608 class Node_Array : public AnyObj {
1609   friend class VMStructs;
1610 protected:
1611   Arena* _a;                    // Arena to allocate in
1612   uint   _max;
1613   Node** _nodes;
1614   ReallocMark _nesting;         // Safety checks for arena reallocation
1615 
1616   // Grow array to required capacity
1617   void maybe_grow(uint i) {
1618     if (i >= _max) {
1619       grow(i);
1620     }
1621   }
1622   void grow(uint i);
1623 
1624 public:
1625   Node_Array(Arena* a, uint max = OptoNodeListSize) : _a(a), _max(max) {
1626     _nodes = NEW_ARENA_ARRAY(a, Node*, max);
1627     clear();
1628   }
1629   Node_Array() : Node_Array(Thread::current()->resource_area()) {}
1630 
1631   NONCOPYABLE(Node_Array);
1632   Node_Array& operator=(Node_Array&&) = delete;
1633   // Allow move constructor for && (eg. capture return of function)
1634   Node_Array(Node_Array&&) = default;
1635 
1636   Node *operator[] ( uint i ) const // Lookup, or null for not mapped
1637   { return (i<_max) ? _nodes[i] : (Node*)nullptr; }
1638   Node* at(uint i) const { assert(i<_max,"oob"); return _nodes[i]; }
1639   Node** adr() { return _nodes; }
1640   // Extend the mapping: index i maps to Node *n.
1641   void map( uint i, Node *n ) { maybe_grow(i); _nodes[i] = n; }
1642   void insert( uint i, Node *n );
1643   void remove( uint i );        // Remove, preserving order
1644   // Clear all entries in _nodes to null but keep storage
1645   void clear() {
1646     Copy::zero_to_bytes(_nodes, _max * sizeof(Node*));
1647   }
1648 
1649   uint max() const { return _max; }
1650   void dump() const;
1651 };
1652 
1653 class Node_List : public Node_Array {
1654   friend class VMStructs;
1655   uint _cnt;
1656 public:
1657   Node_List(uint max = OptoNodeListSize) : Node_Array(Thread::current()->resource_area(), max), _cnt(0) {}
1658   Node_List(Arena *a, uint max = OptoNodeListSize) : Node_Array(a, max), _cnt(0) {}
1659 
1660   NONCOPYABLE(Node_List);
1661   Node_List& operator=(Node_List&&) = delete;
1662   // Allow move constructor for && (eg. capture return of function)
1663   Node_List(Node_List&&) = default;
1664 
1665   bool contains(const Node* n) const {
1666     for (uint e = 0; e < size(); e++) {
1667       if (at(e) == n) return true;
1668     }
1669     return false;
1670   }
1671   void insert( uint i, Node *n ) { Node_Array::insert(i,n); _cnt++; }
1672   void remove( uint i ) { Node_Array::remove(i); _cnt--; }
1673   void push( Node *b ) { map(_cnt++,b); }
1674   void yank( Node *n );         // Find and remove
1675   Node *pop() { return _nodes[--_cnt]; }
1676   void clear() { _cnt = 0; Node_Array::clear(); } // retain storage
1677   void copy(const Node_List& from) {
1678     if (from._max > _max) {
1679       grow(from._max);
1680     }
1681     _cnt = from._cnt;
1682     Copy::conjoint_words_to_higher((HeapWord*)&from._nodes[0], (HeapWord*)&_nodes[0], from._max * sizeof(Node*));
1683   }
1684 
1685   uint size() const { return _cnt; }
1686   void dump() const;
1687   void dump_simple() const;
1688 };
1689 
1690 // Definition must appear after complete type definition of Node_List
1691 template <typename Callback, typename Check>
1692 void Node::visit_uses(Callback callback, Check is_boundary) const {
1693   ResourceMark rm;
1694   VectorSet visited;
1695   Node_List worklist;
1696 
1697   // The initial worklist consists of the direct uses
1698   for (DUIterator_Fast kmax, k = fast_outs(kmax); k < kmax; k++) {
1699     Node* out = fast_out(k);
1700     if (!visited.test_set(out->_idx)) { worklist.push(out); }
1701   }
1702 
1703   while (worklist.size() > 0) {
1704     Node* use = worklist.pop();
1705     // Apply callback on boundary nodes
1706     if (is_boundary(use)) {
1707       callback(use);
1708     } else {
1709       // Not a boundary node, continue search
1710       for (DUIterator_Fast kmax, k = use->fast_outs(kmax); k < kmax; k++) {
1711         Node* out = use->fast_out(k);
1712         if (!visited.test_set(out->_idx)) { worklist.push(out); }
1713       }
1714     }
1715   }
1716 }
1717 
1718 
1719 //------------------------------Unique_Node_List-------------------------------
1720 class Unique_Node_List : public Node_List {
1721   friend class VMStructs;
1722   VectorSet _in_worklist;
1723   uint _clock_index;            // Index in list where to pop from next
1724 public:
1725   Unique_Node_List() : Node_List(), _clock_index(0) {}
1726   Unique_Node_List(Arena *a) : Node_List(a), _in_worklist(a), _clock_index(0) {}
1727 
1728   NONCOPYABLE(Unique_Node_List);
1729   Unique_Node_List& operator=(Unique_Node_List&&) = delete;
1730   // Allow move constructor for && (eg. capture return of function)
1731   Unique_Node_List(Unique_Node_List&&) = default;
1732 
1733   void remove( Node *n );
1734   bool member( Node *n ) { return _in_worklist.test(n->_idx) != 0; }
1735   VectorSet& member_set(){ return _in_worklist; }
1736 
1737   void push(Node* b) {
1738     if( !_in_worklist.test_set(b->_idx) )
1739       Node_List::push(b);
1740   }
1741   void push_non_cfg_inputs_of(const Node* node) {
1742     for (uint i = 1; i < node->req(); i++) {
1743       Node* input = node->in(i);
1744       if (input != nullptr && !input->is_CFG()) {
1745         push(input);
1746       }
1747     }
1748   }
1749 
1750   void push_outputs_of(const Node* node) {
1751     for (DUIterator_Fast imax, i = node->fast_outs(imax); i < imax; i++) {
1752       Node* output = node->fast_out(i);
1753       push(output);
1754     }
1755   }
1756 
1757   Node *pop() {
1758     if( _clock_index >= size() ) _clock_index = 0;
1759     Node *b = at(_clock_index);
1760     map( _clock_index, Node_List::pop());
1761     if (size() != 0) _clock_index++; // Always start from 0
1762     _in_worklist.remove(b->_idx);
1763     return b;
1764   }
1765   Node *remove(uint i) {
1766     Node *b = Node_List::at(i);
1767     _in_worklist.remove(b->_idx);
1768     map(i,Node_List::pop());
1769     return b;
1770   }
1771   void yank(Node *n) {
1772     _in_worklist.remove(n->_idx);
1773     Node_List::yank(n);
1774   }
1775   void  clear() {
1776     _in_worklist.clear();        // Discards storage but grows automatically
1777     Node_List::clear();
1778     _clock_index = 0;
1779   }
1780   void ensure_empty() {
1781     assert(size() == 0, "must be empty");
1782     clear(); // just in case
1783   }
1784 
1785   // Used after parsing to remove useless nodes before Iterative GVN
1786   void remove_useless_nodes(VectorSet& useful);
1787 
1788   // If the idx of the Nodes change, we must recompute the VectorSet
1789   void recompute_idx_set() {
1790     _in_worklist.clear();
1791     for (uint i = 0; i < size(); i++) {
1792       Node* n = at(i);
1793       _in_worklist.set(n->_idx);
1794     }
1795   }
1796 
1797 #ifdef ASSERT
1798   bool is_subset_of(Unique_Node_List& other) {
1799     for (uint i = 0; i < size(); i++) {
1800       Node* n = at(i);
1801       if (!other.member(n)) {
1802         return false;
1803       }
1804     }
1805     return true;
1806   }
1807 #endif
1808 
1809   bool contains(const Node* n) const {
1810     fatal("use faster member() instead");
1811     return false;
1812   }
1813 
1814 #ifndef PRODUCT
1815   void print_set() const { _in_worklist.print(); }
1816 #endif
1817 };
1818 
1819 // Unique_Mixed_Node_List
1820 // unique: nodes are added only once
1821 // mixed: allow new and old nodes
1822 class Unique_Mixed_Node_List : public ResourceObj {
1823 public:
1824   Unique_Mixed_Node_List() : _visited_set(cmpkey, hashkey) {}
1825 
1826   void add(Node* node) {
1827     if (not_a_node(node)) {
1828       return; // Gracefully handle null, -1, 0xabababab, etc.
1829     }
1830     if (_visited_set[node] == nullptr) {
1831       _visited_set.Insert(node, node);
1832       _worklist.push(node);
1833     }
1834   }
1835 
1836   Node* operator[] (uint i) const {
1837     return _worklist[i];
1838   }
1839 
1840   size_t size() {
1841     return _worklist.size();
1842   }
1843 
1844 private:
1845   Dict _visited_set;
1846   Node_List _worklist;
1847 };
1848 
1849 // Inline definition of Compile::record_for_igvn must be deferred to this point.
1850 inline void Compile::record_for_igvn(Node* n) {
1851   _igvn_worklist->push(n);
1852 }
1853 
1854 // Inline definition of Compile::remove_for_igvn must be deferred to this point.
1855 inline void Compile::remove_for_igvn(Node* n) {
1856   _igvn_worklist->remove(n);
1857 }
1858 
1859 //------------------------------Node_Stack-------------------------------------
1860 class Node_Stack {
1861   friend class VMStructs;
1862 protected:
1863   struct INode {
1864     Node *node; // Processed node
1865     uint  indx; // Index of next node's child
1866   };
1867   INode *_inode_top; // tos, stack grows up
1868   INode *_inode_max; // End of _inodes == _inodes + _max
1869   INode *_inodes;    // Array storage for the stack
1870   Arena *_a;         // Arena to allocate in
1871   ReallocMark _nesting; // Safety checks for arena reallocation
1872   void grow();
1873 public:
1874   Node_Stack(int size) {
1875     size_t max = (size > OptoNodeListSize) ? size : OptoNodeListSize;
1876     _a = Thread::current()->resource_area();
1877     _inodes = NEW_ARENA_ARRAY( _a, INode, max );
1878     _inode_max = _inodes + max;
1879     _inode_top = _inodes - 1; // stack is empty
1880   }
1881 
1882   Node_Stack(Arena *a, int size) : _a(a) {
1883     size_t max = (size > OptoNodeListSize) ? size : OptoNodeListSize;
1884     _inodes = NEW_ARENA_ARRAY( _a, INode, max );
1885     _inode_max = _inodes + max;
1886     _inode_top = _inodes - 1; // stack is empty
1887   }
1888 
1889   void pop() {
1890     assert(_inode_top >= _inodes, "node stack underflow");
1891     --_inode_top;
1892   }
1893   void push(Node *n, uint i) {
1894     ++_inode_top;
1895     grow();
1896     INode *top = _inode_top; // optimization
1897     top->node = n;
1898     top->indx = i;
1899   }
1900   Node *node() const {
1901     return _inode_top->node;
1902   }
1903   Node* node_at(uint i) const {
1904     assert(_inodes + i <= _inode_top, "in range");
1905     return _inodes[i].node;
1906   }
1907   uint index() const {
1908     return _inode_top->indx;
1909   }
1910   uint index_at(uint i) const {
1911     assert(_inodes + i <= _inode_top, "in range");
1912     return _inodes[i].indx;
1913   }
1914   void set_node(Node *n) {
1915     _inode_top->node = n;
1916   }
1917   void set_index(uint i) {
1918     _inode_top->indx = i;
1919   }
1920   uint size_max() const { return (uint)pointer_delta(_inode_max, _inodes,  sizeof(INode)); } // Max size
1921   uint size() const { return (uint)pointer_delta((_inode_top+1), _inodes,  sizeof(INode)); } // Current size
1922   bool is_nonempty() const { return (_inode_top >= _inodes); }
1923   bool is_empty() const { return (_inode_top < _inodes); }
1924   void clear() { _inode_top = _inodes - 1; } // retain storage
1925 
1926   // Node_Stack is used to map nodes.
1927   Node* find(uint idx) const;
1928 
1929   NONCOPYABLE(Node_Stack);
1930 };
1931 
1932 
1933 //-----------------------------Node_Notes--------------------------------------
1934 // Debugging or profiling annotations loosely and sparsely associated
1935 // with some nodes.  See Compile::node_notes_at for the accessor.
1936 class Node_Notes {
1937   friend class VMStructs;
1938   JVMState* _jvms;
1939 
1940 public:
1941   Node_Notes(JVMState* jvms = nullptr) {
1942     _jvms = jvms;
1943   }
1944 
1945   JVMState* jvms()            { return _jvms; }
1946   void  set_jvms(JVMState* x) {        _jvms = x; }
1947 
1948   // True if there is nothing here.
1949   bool is_clear() {
1950     return (_jvms == nullptr);
1951   }
1952 
1953   // Make there be nothing here.
1954   void clear() {
1955     _jvms = nullptr;
1956   }
1957 
1958   // Make a new, clean node notes.
1959   static Node_Notes* make(Compile* C) {
1960     Node_Notes* nn = NEW_ARENA_ARRAY(C->comp_arena(), Node_Notes, 1);
1961     nn->clear();
1962     return nn;
1963   }
1964 
1965   Node_Notes* clone(Compile* C) {
1966     Node_Notes* nn = NEW_ARENA_ARRAY(C->comp_arena(), Node_Notes, 1);
1967     (*nn) = (*this);
1968     return nn;
1969   }
1970 
1971   // Absorb any information from source.
1972   bool update_from(Node_Notes* source) {
1973     bool changed = false;
1974     if (source != nullptr) {
1975       if (source->jvms() != nullptr) {
1976         set_jvms(source->jvms());
1977         changed = true;
1978       }
1979     }
1980     return changed;
1981   }
1982 };
1983 
1984 // Inlined accessors for Compile::node_nodes that require the preceding class:
1985 inline Node_Notes*
1986 Compile::locate_node_notes(GrowableArray<Node_Notes*>* arr,
1987                            int idx, bool can_grow) {
1988   assert(idx >= 0, "oob");
1989   int block_idx = (idx >> _log2_node_notes_block_size);
1990   int grow_by = (block_idx - (arr == nullptr? 0: arr->length()));
1991   if (grow_by >= 0) {
1992     if (!can_grow) return nullptr;
1993     grow_node_notes(arr, grow_by + 1);
1994   }
1995   if (arr == nullptr) return nullptr;
1996   // (Every element of arr is a sub-array of length _node_notes_block_size.)
1997   return arr->at(block_idx) + (idx & (_node_notes_block_size-1));
1998 }
1999 
2000 inline bool
2001 Compile::set_node_notes_at(int idx, Node_Notes* value) {
2002   if (value == nullptr || value->is_clear())
2003     return false;  // nothing to write => write nothing
2004   Node_Notes* loc = locate_node_notes(_node_note_array, idx, true);
2005   assert(loc != nullptr, "");
2006   return loc->update_from(value);
2007 }
2008 
2009 
2010 //------------------------------TypeNode---------------------------------------
2011 // Node with a Type constant.
2012 class TypeNode : public Node {
2013 protected:
2014   virtual uint hash() const;    // Check the type
2015   virtual bool cmp( const Node &n ) const;
2016   virtual uint size_of() const; // Size is bigger
2017   const Type* const _type;
2018 public:
2019   void set_type(const Type* t) {
2020     assert(t != nullptr, "sanity");
2021     debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH);
2022     *(const Type**)&_type = t;   // cast away const-ness
2023     // If this node is in the hash table, make sure it doesn't need a rehash.
2024     assert(check_hash == NO_HASH || check_hash == hash(), "type change must preserve hash code");
2025   }
2026   const Type* type() const { assert(_type != nullptr, "sanity"); return _type; };
2027   TypeNode( const Type *t, uint required ) : Node(required), _type(t) {
2028     init_class_id(Class_Type);
2029   }
2030   virtual const Type* Value(PhaseGVN* phase) const;
2031   virtual const Type *bottom_type() const;
2032   virtual       uint  ideal_reg() const;
2033 #ifndef PRODUCT
2034   virtual void dump_spec(outputStream *st) const;
2035   virtual void dump_compact_spec(outputStream *st) const;
2036 #endif
2037 };
2038 
2039 #include "opto/opcodes.hpp"
2040 
2041 #define Op_IL(op) \
2042   inline int Op_ ## op(BasicType bt) { \
2043   assert(bt == T_INT || bt == T_LONG, "only for int or longs"); \
2044   if (bt == T_INT) { \
2045     return Op_## op ## I; \
2046   } \
2047   return Op_## op ## L; \
2048 }
2049 
2050 Op_IL(Add)
2051 Op_IL(Sub)
2052 Op_IL(Mul)
2053 Op_IL(URShift)
2054 Op_IL(LShift)
2055 Op_IL(Xor)
2056 Op_IL(Cmp)
2057 
2058 inline int Op_ConIL(BasicType bt) {
2059   assert(bt == T_INT || bt == T_LONG, "only for int or longs");
2060   if (bt == T_INT) {
2061     return Op_ConI;
2062   }
2063   return Op_ConL;
2064 }
2065 
2066 inline int Op_Cmp_unsigned(BasicType bt) {
2067   assert(bt == T_INT || bt == T_LONG, "only for int or longs");
2068   if (bt == T_INT) {
2069     return Op_CmpU;
2070   }
2071   return Op_CmpUL;
2072 }
2073 
2074 inline int Op_Cast(BasicType bt) {
2075   assert(bt == T_INT || bt == T_LONG, "only for int or longs");
2076   if (bt == T_INT) {
2077     return Op_CastII;
2078   }
2079   return Op_CastLL;
2080 }
2081 
2082 inline int Op_DivIL(BasicType bt, bool is_unsigned) {
2083   assert(bt == T_INT || bt == T_LONG, "only for int or longs");
2084   if (bt == T_INT) {
2085     if (is_unsigned) {
2086       return Op_UDivI;
2087     } else {
2088       return Op_DivI;
2089     }
2090   }
2091   if (is_unsigned) {
2092     return Op_UDivL;
2093   } else {
2094     return Op_DivL;
2095   }
2096 }
2097 
2098 inline int Op_DivModIL(BasicType bt, bool is_unsigned) {
2099   assert(bt == T_INT || bt == T_LONG, "only for int or longs");
2100   if (bt == T_INT) {
2101     if (is_unsigned) {
2102       return Op_UDivModI;
2103     } else {
2104       return Op_DivModI;
2105     }
2106   }
2107   if (is_unsigned) {
2108     return Op_UDivModL;
2109   } else {
2110     return Op_DivModL;
2111   }
2112 }
2113 
2114 #endif // SHARE_OPTO_NODE_HPP