node.hpp revision 2613
1879N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// Portions of code courtesy of Clifford Click 0N/A// Optimization - Graph Style 0N/A// The type of all node counts and indexes. 0N/A// It must hold at least 16 bits, but must also be fast to load and store. 0N/A// This type, if less than 32 bits, could limit the number of possible nodes. 0N/A#
endif //OPTO_DU_ITERATOR_ASSERT 0N/A// Unknown count frequency 0N/A//------------------------------Node------------------------------------------- 0N/A// Nodes define actions in the program. They create values, which have types. 0N/A// They are both vertices in a directed graph and program primitives. Nodes 0N/A// are labeled; the label is the "opcode", the primitive function in the lambda 0N/A// calculus sense that gives meaning to the Node. Node inputs are ordered (so 0N/A// that "a-b" is different from "b-a"). The inputs to a Node are the inputs to 0N/A// the Node's function. These inputs also define a Type equation for the Node. 0N/A// Solving these Type equations amounts to doing dataflow analysis. 0N/A// Control and data are uniformly represented in the graph. Finally, Nodes 0N/A// have a unique dense integer index which is used to index into side arrays 0N/A// whenever I have phase-specific information. 0N/A // Lots of restrictions on cloning Nodes 0N/A Node(
const Node&);
// not defined; linker error to use these 0N/A // Because Nodes come and go, I define an Arena of Node structures to pull 0N/A // from. This should allow fast access to node creation & deletion. This 0N/A // field is a local cache of a value defined in some "program fragment" for 0N/A // which these Nodes are just a part of. 0N/A // New Operator that takes a Compile pointer, this will eventually 0N/A // be the "new" New operator. 0N/A n->
_in = (
Node**)n;
// magic cookie for assertion check 0N/A // New Operator that takes a Compile pointer, this will eventually 0N/A // be the "new" New operator. 0N/A n->
_in[y-
1] = n;
// magic cookie for assertion check 0N/A void operator delete(
void *
ptr ) {}
0N/A // Fancy destructor; eagerly attempt to reclaim Node numberings and storage 0N/A // Create a new Node. Required is the number is of inputs required for 0N/A // semantic correctness. 0N/A // Create a new Node with given input edges. 0N/A // This version requires use of the "edge-count" new. 0N/A // E.g. new (C,3) FooNode( C, NULL, left, right ); 0N/A // Clone an inherited Node given only the base Node type. 0N/A // Clone a Node, immediately supplying one or two new edges. 0N/A // The first and second arguments, if non-null, replace in(1) and in(2), 0N/A // Shared setup for the above constructors. 0N/A // Handles all interactions with Compile::current. 0N/A // Puts initial values in all Node fields except _idx. 0N/A // Returns the initial value for _idx, which cannot 0N/A // be initialized by assignment. 0N/A//----------------- input edge handling 0N/A friend class PhaseCFG;
// Access to address of _in array elements 0N/A Node **
_in;
// Array of use-def references to Nodes 605N/A // Input edges are split into two categories. Required edges are required 0N/A // for semantic correctness; order is important and NULLs are allowed. 0N/A // Precedence edges are used to help determine execution order and are 0N/A // added, e.g., for scheduling purposes. They are unordered and not 0N/A // duplicated; they have no embedded NULLs. Edges from 0 to _cnt-1 0N/A // are required, from _cnt to _max-1 are precedence edges. 0N/A // Output edges are an unordered list of def-use edges which exactly 0N/A // correspond to required input edges which point from other nodes 0N/A // to this one. Thus the count of the output edges is the number of 0N/A // users of this node. 0N/A // Grow the actual input array to the next larger power-of-2 bigger than len. 0N/A // Grow the output array to the next larger power-of-2 bigger than len. 0N/A // Each Node is assigned a unique small/dense number. This number is used 0N/A // to index into auxiliary arrays of data and bitvectors. 0N/A // It is declared const to defend against inadvertant assignment, 0N/A // since it is used by clients as a naked field. 0N/A // Get the (read-only) number of input edges 0N/A // Get the (read-only) number of output edges 0N/A // Iterate over the out-edges of this node. Deletions are illegal. 0N/A // Use this when the out array might have changed to suppress asserts. 0N/A // Does the node have an out at this position? (Used for iteration.) 0N/A // Iterate over the out-edges of this node. All changes are illegal. 0N/A // Iterate over the out-edges of this node, deleting one at a time. 0N/A // The inline bodies of all these methods are after the iterator definitions. 0N/A // Iterate over the out-edges of this node. Deletions are illegal. 0N/A // This iteration uses integral indexes, to decouple from array reallocations. 0N/A // Use this when the out array might have changed to suppress asserts. 0N/A // Reference to the i'th output Node. Error if out of bounds. 0N/A // Does the node have an out at this position? (Used for iteration.) 0N/A // Iterate over the out-edges of this node. All changes are illegal. 0N/A // This iteration uses a pointer internal to the out array. 0N/A // Assign a limit pointer to the reference argument: 0N/A // Return the base pointer: 0N/A // Iterate over the out-edges of this node, deleting one at a time. 0N/A // This iteration uses a pointer internal to the out array. 0N/A // Assign a limit pointer to the reference argument: 0N/A // Return the pointer to the start of the iteration: 0N/A // Reference to the i'th input Node. Error if out of bounds. 0N/A // Reference to the i'th output Node. Error if out of bounds. 0N/A // Use this accessor sparingly. We are going trying to use iterators instead. 0N/A // Return the unique out edge. 0N/A // Delete out edge at position 'i' by moving last out edge to position 'i' 0N/A // Record that a change happened here. 0N/A // Smash the old edge so it can't be used accidentally. 0N/A // Set a required input edge, also updates corresponding output edge 0N/A "remove node from hash table before modifying it");
0N/A Node** p = &
_in[i];
// cache this._in, across the del_out call 0N/A // Light version of set_req() to init inputs after node creation. 0N/A "remove node from hash table before modifying it");
0N/A // Find first occurrence of n among my edges: 0N/A // NULL out all inputs to eliminate incoming Def-Use edges. 0N/A // Return the number of edges between 'n' and 'this' 0N/A // Quickly, return true if and only if I am Compile::current()->top(). 0N/A // Reaffirm invariants for is_top. (Only from Compile::set_cached_top_node.) 0N/A // Strip away casting. (It is depth-limited.) 0N/A // Add an output edge to the end of the list 0N/A // Delete an output edge 0N/A // Find and remove n 0N/A // Smash the old edge so it can't be used accidentally. 0N/A // Record that a change happened here. 0N/A // Globally replace this node by a given new node, updating all uses. 168N/A // Globally replace this node by a given new node, updating all uses 168N/A // and cutting input edges of old node. 0N/A // Find the one non-null required input. RegionNode only 0N/A // Add or remove precedence edges 0N/A // Set this node's index, used by cisc_version to replace current node 0N/A // Swap input edge order. (Edge indexes i1 and i2 are usually 1 and 2.) 0N/A // Def-Use info is unchanged 0N/A // If this node is in the hash table, make sure it doesn't need a rehash. 0N/A // Iterators over input Nodes for a Node X are written as: 0N/A // for( i = 0; i < X.req(); i++ ) ... X[i] ... 0N/A // NOTE: Required edges can contain embedded NULL pointers. 0N/A//----------------- Other Node Properties 0N/A // Generate class id for some ideal nodes to avoid virtual query 0N/A // methods is_<Node>(). 0N/A // Class id is the set of bits corresponded to the node class and all its 0N/A // super classes so that queries for super classes are also valid. 0N/A // Subclasses of the same super class have different assigned bit 0N/A // (the third parameter in the macro DEFINE_CLASS_ID). 0N/A // Classes with deeper hierarchy are declared first. 0N/A // Classes with the same hierarchy depth are sorted by usage frequency. 0N/A // The query method masks the bits to cut off bits of subclasses 0N/A // and then compare the result with the class id 0N/A // (see the macro DEFINE_CLASS_QUERY below). 0N/A // Class_MachCall=30, ClassMask_MachCall=31 0N/A // 0 0 0 0 0 0 0 0 1 1 1 1 0 0N/A // | | Bit_MachReturn=4 0N/A // | Bit_MachSafePoint=8 0N/A // Class_CountedLoop=56, ClassMask_CountedLoop=63 0N/A // 0 0 0 0 0 0 0 1 1 1 0 0 0 0N/A // Bit_CountedLoop=32 0N/A // This enum is used only for C2 ideal and mach nodes with is_<node>() methods 0N/A // so that it's values fits into 16 bits. 0N/A // Flags are sorted by usage frequency. 0N/A // These methods should be called from constructors only. 0N/A // Return a dense integer opcode number 0N/A // Virtual inherited Node size 0N/A // Other interesting Node properties 0N/A // Special case: is_Call() returns true for both CallNode and MachCallNode. 0N/A // duplicate of is_MachSpillCopy() 0N/A // The data node which is safe to leave in dead loop during IGVN optimization. 0N/A // is_Copy() returns copied edge index (0 or 1) 0N/A virtual bool is_CFG()
const {
return false; }
0N/A // If this node is control-dependent on a test, can it be 0N/A // rerouted to a dominating equivalent test? This is usually 0N/A // true of non-CFG nodes, but can be false for operations which 0N/A // depend for their correct sequencing on more than one test. 0N/A // (In that case, hoisting to a dominating test may silently 0N/A // skip some other important test.) 0N/A // defined for MachNodes that match 'If' | 'Goto' | 'CountedLoopEnd' 0N/A // When building basic blocks, I need to have a notion of block beginning 0N/A // Nodes, next block selector Nodes (block enders), and next block 0N/A // projections. These calls need to work on their machine equivalents. The 0N/A // Ideal beginning Nodes are RootNode, RegionNode and StartNode. 0N/A // Goto and Return. This call also returns the block ending Node. 0N/A // The node is a "macro" node which needs to be expanded before matching 0N/A // Value is a vector of primitive values 0N/A//----------------- Optimization 0N/A // Get the worst-case Type output for this Node. 0N/A // If we find a better type for a node, try to record it permanently. 0N/A // Return true if this node actually changed. 0N/A // Be sure to do the hash_delete game in the "rehash" variant. 0N/A // Get the address type with which this node uses and/or defs memory, 0N/A // or NULL if none. The address type is conservatively wide. 0N/A // Returns non-null for calls, membars, loads, stores, etc. 0N/A // Returns TypePtr::BOTTOM if the node touches memory "broadly". 0N/A // Return an existing node which computes the same function as this node. 0N/A // The optimistic combined algorithm requires this to return a Node which 0N/A // is a small number of steps away (e.g., one of my inputs). 0N/A // Return the set of values this Node can take on at runtime. 0N/A // Return a node which is more "ideal" than the current node. 0N/A // The invariants on this call are subtle. If in doubt, read the 0N/A // treatise in node.cpp above the default implemention AND TEST WITH 0N/A // +VerifyIterativeGVN! 0N/A // Some nodes have specific Ideal subgraph transformations only if they are 0N/A // unique users of specific nodes. Such nodes should be put on IGVN worklist 0N/A // for the transformations to happen. 119N/A // Skip Proj and CatchProj nodes chains. Check for Null and Top. 119N/A // Check if 'this' node dominates or equal to 'sub'. 0N/A // Idealize graph, using DU info. Done after constant propagation 0N/A // See if there is valid pipeline info 0N/A // Compute the latency from the def to this instruction of the ith input node 0N/A // Hash & compare functions, for pessimistic value numbering 0N/A // If the hash function returns the special sentinel value NO_HASH, 0N/A // the node is guaranteed never to compare equal to any other node. 605N/A // If we accidentally generate a hash with value NO_HASH the node 0N/A // won't go into the table and we'll lose a little optimization. 0N/A // Operation appears to be iteratively computed (such as an induction variable) 0N/A // It is possible for this operation to return false for a loop-varying 0N/A // value, if it appears (by local graph inspection) to be computed by a simple conditional. 0N/A // Determine if a node is Counted loop induction variable. 0N/A // Return a node with opcode "opc" and same inputs as "this" if one can 0N/A // be found; Otherwise return NULL; 0N/A // Return the unique control out if only one. Null if none or more than one. 0N/A//----------------- Code Generation 0N/A // Ideal register class for Matching. Zero means unmatched instruction 0N/A // (these are cloned instead of converted to machine nodes). 0N/A // Do we Match on this edge index or not? Generally false for Control 0N/A // and true for everything else. Weird for calls & returns. 0N/A // Register class output is returned in 0N/A // Register class input is expected in 0N/A // Should we clone rather than spill this instruction? 0N/A // Return JVM State Object if this Node carries debug info, or NULL otherwise 0N/A // Print as assembly 0N/A // Emit bytes starting at parameter 'ptr' 0N/A // Bump 'ptr' by the number of output bytes 0N/A // Size of instruction in bytes 0N/A // Convenience function to extract an integer constant from a node. 0N/A // If it is not an integer constant (either Con, CastII, or Mach), 0N/A // return value_if_unknown. 0N/A // Return the constant, knowing it is an integer constant already 0N/A // Here's where the work is done. Can produce non-constant int types too. 0N/A // These guys are called by code generated by ADLC: 0N/A // Nodes which are pinned into basic blocks 0N/A virtual bool pinned()
const {
return false; }
0N/A // Nodes which use memory without consuming it, hence need antidependences 0N/A // More specifically, needs_anti_dependence_check returns true iff the node 0N/A // (a) does a load, and (b) does not perform a store (except perhaps to a 0N/A // stack slot or some other unaliased location). 0N/A // Return which operand this instruction may cisc-spill. In other words, 0N/A // return operand position that can convert from reg to memory access 0N/A//----------------- Graph walking 0N/A // Walk and apply member functions recursively. 0N/A // Supplied (this) pointer is root. 0N/A static void nop(
Node &,
void*);
// Dummy empty function 0N/A//----------------- Printing, etc 0N/A void dump()
const;
// Print this node, 0N/A void dump(
int depth)
const;
// Print this node, recursively to depth d 0N/A virtual void dump_req()
const;
// Print required-edge info 0N/A virtual void dump_prec()
const;
// Print precedence-edge info 0N/A virtual void dump_out()
const;
// Print the output edge info 0N/A void verify()
const;
// Check Def-Use info for my subgraph 0N/A // This call defines a class-unique string used to identify class instances 0N/A // RegMask Print Functions 0N/A int _hash_lock;
// Barrier to modifications of nodes in the hash table 0N/A//----------------------------------------------------------------------------- 0N/A// Iterators over DU info, and associated Node functions. 0N/A// Common code for assertion checking on DU iterators. 0N/A bool _vdui;
// cached value of VerifyDUIterators 0N/A// The VDUI_ONLY macro protects code conditionalized on VerifyDUIterators 0N/A// Default DU iterator. Allows appends onto the out array. 0N/A// Allows deletion from the out array only at the current point. 0N/A// for (DUIterator i = x->outs(); x->has_out(i); i++) { 0N/A// Node* y = x->out(i); 0N/A// Compiles in product mode to a unsigned integer index, which indexes 0N/A// onto a repeatedly reloaded base pointer of x->_out. The loop predicate 0N/A// also reloads x->_outcnt. If you delete, you must perform "--i" just 0N/A// before continuing the loop. You must delete only the last-produced 0N/A// edge. You must delete only a single copy of the last-produced edge, 0N/A// or else you must delete all copies at once (the first time the edge 0N/A// is produced by the iterator). 0N/A // This is the index which provides the product-mode behavior. 0N/A // Whatever the product-mode version of the system does to the 0N/A // DUI index is done to this index. All other fields in 0N/A // this class are used only for assertion checking. 0N/A // initialize to garbage; clear _vdui to disable asserts 0N/A// Faster DU iterator. Disallows insertions into the out array. 0N/A// Allows deletion from the out array only at the current point. 0N/A// for (DUIterator_Fast imax, i = x->fast_outs(imax); i < imax; i++) { 0N/A// Node* y = x->fast_out(i); 0N/A// Compiles in product mode to raw Node** pointer arithmetic, with 0N/A// no reloading of pointers from the original node x. If you delete, 0N/A// you must perform "--i; --imax" just before continuing the loop. 0N/A// If you delete multiple copies of the same edge, you must decrement 0N/A// imax, but not i, multiple times: "--i, imax -= num_edges". 0N/A // This is the pointer which provides the product-mode behavior. 0N/A // Whatever the product-mode version of the system does to the 0N/A // DUI pointer is done to this pointer. All other fields in 0N/A // this class are used only for assertion checking. 0N/A // Note: offset must be signed, since -1 is sometimes passed 0N/A // initialize to garbage; clear _vdui to disable asserts 0N/A void operator-=(
uint n)
// applied to the limit only 0N/A // Assign a limit pointer to the reference argument: 0N/A // Return the base pointer: 0N/A// Faster DU iterator. Requires each successive edge to be removed. 0N/A// Does not allow insertion of any edges. 0N/A// for (DUIterator_Last imin, i = x->last_outs(imin); i >= imin; i -= num_edges) { 0N/A// Node* y = x->last_out(i); 0N/A// Compiles in product mode to raw Node** pointer arithmetic, with 0N/A// no reloading of pointers from the original node x. 0N/A // Note: offset must be signed, since -1 is sometimes passed 0N/A void operator<(
int) {}
// do not use 0N/A // initialize to garbage 0N/A // Assign a limit pointer to the reference argument: 0N/A // Return the initial pointer: 0N/A#
endif //OPTO_DU_ITERATOR_ASSERT 1080N/A// An Iterator that truly follows the iterator pattern. Doesn't 1080N/A// support deletion but could be made to. 1080N/A// for (SimpleDUIterator i(n); i.has_next(); i.next()) { 0N/A//----------------------------------------------------------------------------- 0N/A// Map dense integer indices to Nodes. Uses classic doubling-array trick. 0N/A// Abstractly provides an infinite array of Node*'s, initialized to NULL. 0N/A// Note that the constructor just zeros things, and since I use Arena 0N/A// allocation I do not need a destructor to reclaim storage. 0N/A Node *
operator[] (
uint i )
const // Lookup, or NULL for not mapped 0N/A // Extend the mapping: index i maps to Node *n. 0N/A void clear();
// Set all entries to NULL, keep storage 0N/A//------------------------------Unique_Node_List------------------------------- 0N/A // Used after parsing to remove useless nodes before Iterative GVN 0N/A// Inline definition of Compile::record_for_igvn must be deferred to this point. 0N/A//------------------------------Node_Stack------------------------------------- 2613N/A // Node_Stack is used to map nodes. 0N/A//-----------------------------Node_Notes-------------------------------------- 0N/A// Debugging or profiling annotations loosely and sparsely associated 0N/A// with some nodes. See Compile::node_notes_at for the accessor. 0N/A // True if there is nothing here. 0N/A // Make there be nothing here. 0N/A // Make a new, clean node notes. 0N/A // Absorb any information from source. 0N/A// Inlined accessors for Compile::node_nodes that require the preceding class: 0N/A // (Every element of arr is a sub-array of length _node_notes_block_size.) 0N/A return false;
// nothing to write => write nothing 0N/A//------------------------------TypeNode--------------------------------------- 0N/A// Node with a Type constant. 0N/A // If this node is in the hash table, make sure it doesn't need a rehash. 1879N/A#
endif // SHARE_VM_OPTO_NODE_HPP