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