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