duke@435: /* duke@435: * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_node.cpp.incl" duke@435: duke@435: class RegMask; duke@435: // #include "phase.hpp" duke@435: class PhaseTransform; duke@435: class PhaseGVN; duke@435: duke@435: // Arena we are currently building Nodes in duke@435: const uint Node::NotAMachineReg = 0xffff0000; duke@435: duke@435: #ifndef PRODUCT duke@435: extern int nodes_created; duke@435: #endif duke@435: duke@435: #ifdef ASSERT duke@435: duke@435: //-------------------------- construct_node------------------------------------ duke@435: // Set a breakpoint here to identify where a particular node index is built. duke@435: void Node::verify_construction() { duke@435: _debug_orig = NULL; duke@435: int old_debug_idx = Compile::debug_idx(); duke@435: int new_debug_idx = old_debug_idx+1; duke@435: if (new_debug_idx > 0) { duke@435: // Arrange that the lowest five decimal digits of _debug_idx duke@435: // will repeat thos of _idx. In case this is somehow pathological, duke@435: // we continue to assign negative numbers (!) consecutively. duke@435: const int mod = 100000; duke@435: int bump = (int)(_idx - new_debug_idx) % mod; duke@435: if (bump < 0) bump += mod; duke@435: assert(bump >= 0 && bump < mod, ""); duke@435: new_debug_idx += bump; duke@435: } duke@435: Compile::set_debug_idx(new_debug_idx); duke@435: set_debug_idx( new_debug_idx ); duke@435: assert(Compile::current()->unique() < (uint)MaxNodeLimit, "Node limit exceeded"); duke@435: if (BreakAtNode != 0 && (_debug_idx == BreakAtNode || (int)_idx == BreakAtNode)) { duke@435: tty->print_cr("BreakAtNode: _idx=%d _debug_idx=%d", _idx, _debug_idx); duke@435: BREAKPOINT; duke@435: } duke@435: #if OPTO_DU_ITERATOR_ASSERT duke@435: _last_del = NULL; duke@435: _del_tick = 0; duke@435: #endif duke@435: _hash_lock = 0; duke@435: } duke@435: duke@435: duke@435: // #ifdef ASSERT ... duke@435: duke@435: #if OPTO_DU_ITERATOR_ASSERT duke@435: void DUIterator_Common::sample(const Node* node) { duke@435: _vdui = VerifyDUIterators; duke@435: _node = node; duke@435: _outcnt = node->_outcnt; duke@435: _del_tick = node->_del_tick; duke@435: _last = NULL; duke@435: } duke@435: duke@435: void DUIterator_Common::verify(const Node* node, bool at_end_ok) { duke@435: assert(_node == node, "consistent iterator source"); duke@435: assert(_del_tick == node->_del_tick, "no unexpected deletions allowed"); duke@435: } duke@435: duke@435: void DUIterator_Common::verify_resync() { duke@435: // Ensure that the loop body has just deleted the last guy produced. duke@435: const Node* node = _node; duke@435: // Ensure that at least one copy of the last-seen edge was deleted. duke@435: // Note: It is OK to delete multiple copies of the last-seen edge. duke@435: // Unfortunately, we have no way to verify that all the deletions delete duke@435: // that same edge. On this point we must use the Honor System. duke@435: assert(node->_del_tick >= _del_tick+1, "must have deleted an edge"); duke@435: assert(node->_last_del == _last, "must have deleted the edge just produced"); duke@435: // We liked this deletion, so accept the resulting outcnt and tick. duke@435: _outcnt = node->_outcnt; duke@435: _del_tick = node->_del_tick; duke@435: } duke@435: duke@435: void DUIterator_Common::reset(const DUIterator_Common& that) { duke@435: if (this == &that) return; // ignore assignment to self duke@435: if (!_vdui) { duke@435: // We need to initialize everything, overwriting garbage values. duke@435: _last = that._last; duke@435: _vdui = that._vdui; duke@435: } duke@435: // Note: It is legal (though odd) for an iterator over some node x duke@435: // to be reassigned to iterate over another node y. Some doubly-nested duke@435: // progress loops depend on being able to do this. duke@435: const Node* node = that._node; duke@435: // Re-initialize everything, except _last. duke@435: _node = node; duke@435: _outcnt = node->_outcnt; duke@435: _del_tick = node->_del_tick; duke@435: } duke@435: duke@435: void DUIterator::sample(const Node* node) { duke@435: DUIterator_Common::sample(node); // Initialize the assertion data. duke@435: _refresh_tick = 0; // No refreshes have happened, as yet. duke@435: } duke@435: duke@435: void DUIterator::verify(const Node* node, bool at_end_ok) { duke@435: DUIterator_Common::verify(node, at_end_ok); duke@435: assert(_idx < node->_outcnt + (uint)at_end_ok, "idx in range"); duke@435: } duke@435: duke@435: void DUIterator::verify_increment() { duke@435: if (_refresh_tick & 1) { duke@435: // We have refreshed the index during this loop. duke@435: // Fix up _idx to meet asserts. duke@435: if (_idx > _outcnt) _idx = _outcnt; duke@435: } duke@435: verify(_node, true); duke@435: } duke@435: duke@435: void DUIterator::verify_resync() { duke@435: // Note: We do not assert on _outcnt, because insertions are OK here. duke@435: DUIterator_Common::verify_resync(); duke@435: // Make sure we are still in sync, possibly with no more out-edges: duke@435: verify(_node, true); duke@435: } duke@435: duke@435: void DUIterator::reset(const DUIterator& that) { duke@435: if (this == &that) return; // self assignment is always a no-op duke@435: assert(that._refresh_tick == 0, "assign only the result of Node::outs()"); duke@435: assert(that._idx == 0, "assign only the result of Node::outs()"); duke@435: assert(_idx == that._idx, "already assigned _idx"); duke@435: if (!_vdui) { duke@435: // We need to initialize everything, overwriting garbage values. duke@435: sample(that._node); duke@435: } else { duke@435: DUIterator_Common::reset(that); duke@435: if (_refresh_tick & 1) { duke@435: _refresh_tick++; // Clear the "was refreshed" flag. duke@435: } duke@435: assert(_refresh_tick < 2*100000, "DU iteration must converge quickly"); duke@435: } duke@435: } duke@435: duke@435: void DUIterator::refresh() { duke@435: DUIterator_Common::sample(_node); // Re-fetch assertion data. duke@435: _refresh_tick |= 1; // Set the "was refreshed" flag. duke@435: } duke@435: duke@435: void DUIterator::verify_finish() { duke@435: // If the loop has killed the node, do not require it to re-run. duke@435: if (_node->_outcnt == 0) _refresh_tick &= ~1; duke@435: // If this assert triggers, it means that a loop used refresh_out_pos duke@435: // to re-synch an iteration index, but the loop did not correctly duke@435: // re-run itself, using a "while (progress)" construct. duke@435: // This iterator enforces the rule that you must keep trying the loop duke@435: // until it "runs clean" without any need for refreshing. duke@435: assert(!(_refresh_tick & 1), "the loop must run once with no refreshing"); duke@435: } duke@435: duke@435: duke@435: void DUIterator_Fast::verify(const Node* node, bool at_end_ok) { duke@435: DUIterator_Common::verify(node, at_end_ok); duke@435: Node** out = node->_out; duke@435: uint cnt = node->_outcnt; duke@435: assert(cnt == _outcnt, "no insertions allowed"); duke@435: assert(_outp >= out && _outp <= out + cnt - !at_end_ok, "outp in range"); duke@435: // This last check is carefully designed to work for NO_OUT_ARRAY. duke@435: } duke@435: duke@435: void DUIterator_Fast::verify_limit() { duke@435: const Node* node = _node; duke@435: verify(node, true); duke@435: assert(_outp == node->_out + node->_outcnt, "limit still correct"); duke@435: } duke@435: duke@435: void DUIterator_Fast::verify_resync() { duke@435: const Node* node = _node; duke@435: if (_outp == node->_out + _outcnt) { duke@435: // Note that the limit imax, not the pointer i, gets updated with the duke@435: // exact count of deletions. (For the pointer it's always "--i".) duke@435: assert(node->_outcnt+node->_del_tick == _outcnt+_del_tick, "no insertions allowed with deletion(s)"); duke@435: // This is a limit pointer, with a name like "imax". duke@435: // Fudge the _last field so that the common assert will be happy. duke@435: _last = (Node*) node->_last_del; duke@435: DUIterator_Common::verify_resync(); duke@435: } else { duke@435: assert(node->_outcnt < _outcnt, "no insertions allowed with deletion(s)"); duke@435: // A normal internal pointer. duke@435: DUIterator_Common::verify_resync(); duke@435: // Make sure we are still in sync, possibly with no more out-edges: duke@435: verify(node, true); duke@435: } duke@435: } duke@435: duke@435: void DUIterator_Fast::verify_relimit(uint n) { duke@435: const Node* node = _node; duke@435: assert((int)n > 0, "use imax -= n only with a positive count"); duke@435: // This must be a limit pointer, with a name like "imax". duke@435: assert(_outp == node->_out + node->_outcnt, "apply -= only to a limit (imax)"); duke@435: // The reported number of deletions must match what the node saw. duke@435: assert(node->_del_tick == _del_tick + n, "must have deleted n edges"); duke@435: // Fudge the _last field so that the common assert will be happy. duke@435: _last = (Node*) node->_last_del; duke@435: DUIterator_Common::verify_resync(); duke@435: } duke@435: duke@435: void DUIterator_Fast::reset(const DUIterator_Fast& that) { duke@435: assert(_outp == that._outp, "already assigned _outp"); duke@435: DUIterator_Common::reset(that); duke@435: } duke@435: duke@435: void DUIterator_Last::verify(const Node* node, bool at_end_ok) { duke@435: // at_end_ok means the _outp is allowed to underflow by 1 duke@435: _outp += at_end_ok; duke@435: DUIterator_Fast::verify(node, at_end_ok); // check _del_tick, etc. duke@435: _outp -= at_end_ok; duke@435: assert(_outp == (node->_out + node->_outcnt) - 1, "pointer must point to end of nodes"); duke@435: } duke@435: duke@435: void DUIterator_Last::verify_limit() { duke@435: // Do not require the limit address to be resynched. duke@435: //verify(node, true); duke@435: assert(_outp == _node->_out, "limit still correct"); duke@435: } duke@435: duke@435: void DUIterator_Last::verify_step(uint num_edges) { duke@435: assert((int)num_edges > 0, "need non-zero edge count for loop progress"); duke@435: _outcnt -= num_edges; duke@435: _del_tick += num_edges; duke@435: // Make sure we are still in sync, possibly with no more out-edges: duke@435: const Node* node = _node; duke@435: verify(node, true); duke@435: assert(node->_last_del == _last, "must have deleted the edge just produced"); duke@435: } duke@435: duke@435: #endif //OPTO_DU_ITERATOR_ASSERT duke@435: duke@435: duke@435: #endif //ASSERT duke@435: duke@435: duke@435: // This constant used to initialize _out may be any non-null value. duke@435: // The value NULL is reserved for the top node only. duke@435: #define NO_OUT_ARRAY ((Node**)-1) duke@435: duke@435: // This funny expression handshakes with Node::operator new duke@435: // to pull Compile::current out of the new node's _out field, duke@435: // and then calls a subroutine which manages most field duke@435: // initializations. The only one which is tricky is the duke@435: // _idx field, which is const, and so must be initialized duke@435: // by a return value, not an assignment. duke@435: // duke@435: // (Aren't you thankful that Java finals don't require so many tricks?) duke@435: #define IDX_INIT(req) this->Init((req), (Compile*) this->_out) duke@435: #ifdef _MSC_VER // the IDX_INIT hack falls foul of warning C4355 duke@435: #pragma warning( disable:4355 ) // 'this' : used in base member initializer list duke@435: #endif duke@435: duke@435: // Out-of-line code from node constructors. duke@435: // Executed only when extra debug info. is being passed around. duke@435: static void init_node_notes(Compile* C, int idx, Node_Notes* nn) { duke@435: C->set_node_notes_at(idx, nn); duke@435: } duke@435: duke@435: // Shared initialization code. duke@435: inline int Node::Init(int req, Compile* C) { duke@435: assert(Compile::current() == C, "must use operator new(Compile*)"); duke@435: int idx = C->next_unique(); duke@435: duke@435: // If there are default notes floating around, capture them: duke@435: Node_Notes* nn = C->default_node_notes(); duke@435: if (nn != NULL) init_node_notes(C, idx, nn); duke@435: duke@435: // Note: At this point, C is dead, duke@435: // and we begin to initialize the new Node. duke@435: duke@435: _cnt = _max = req; duke@435: _outcnt = _outmax = 0; duke@435: _class_id = Class_Node; duke@435: _flags = 0; duke@435: _out = NO_OUT_ARRAY; duke@435: return idx; duke@435: } duke@435: duke@435: //------------------------------Node------------------------------------------- duke@435: // Create a Node, with a given number of required edges. duke@435: Node::Node(uint req) duke@435: : _idx(IDX_INIT(req)) duke@435: { duke@435: assert( req < (uint)(MaxNodeLimit - NodeLimitFudgeFactor), "Input limit exceeded" ); duke@435: debug_only( verify_construction() ); duke@435: NOT_PRODUCT(nodes_created++); duke@435: if (req == 0) { duke@435: assert( _in == (Node**)this, "Must not pass arg count to 'new'" ); duke@435: _in = NULL; duke@435: } else { duke@435: assert( _in[req-1] == this, "Must pass arg count to 'new'" ); duke@435: Node** to = _in; duke@435: for(uint i = 0; i < req; i++) { duke@435: to[i] = NULL; duke@435: } duke@435: } duke@435: } duke@435: duke@435: //------------------------------Node------------------------------------------- duke@435: Node::Node(Node *n0) duke@435: : _idx(IDX_INIT(1)) duke@435: { duke@435: debug_only( verify_construction() ); duke@435: NOT_PRODUCT(nodes_created++); duke@435: // Assert we allocated space for input array already duke@435: assert( _in[0] == this, "Must pass arg count to 'new'" ); duke@435: assert( is_not_dead(n0), "can not use dead node"); duke@435: _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); duke@435: } duke@435: duke@435: //------------------------------Node------------------------------------------- duke@435: Node::Node(Node *n0, Node *n1) duke@435: : _idx(IDX_INIT(2)) duke@435: { duke@435: debug_only( verify_construction() ); duke@435: NOT_PRODUCT(nodes_created++); duke@435: // Assert we allocated space for input array already duke@435: assert( _in[1] == this, "Must pass arg count to 'new'" ); duke@435: assert( is_not_dead(n0), "can not use dead node"); duke@435: assert( is_not_dead(n1), "can not use dead node"); duke@435: _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); duke@435: _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); duke@435: } duke@435: duke@435: //------------------------------Node------------------------------------------- duke@435: Node::Node(Node *n0, Node *n1, Node *n2) duke@435: : _idx(IDX_INIT(3)) duke@435: { duke@435: debug_only( verify_construction() ); duke@435: NOT_PRODUCT(nodes_created++); duke@435: // Assert we allocated space for input array already duke@435: assert( _in[2] == this, "Must pass arg count to 'new'" ); duke@435: assert( is_not_dead(n0), "can not use dead node"); duke@435: assert( is_not_dead(n1), "can not use dead node"); duke@435: assert( is_not_dead(n2), "can not use dead node"); duke@435: _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); duke@435: _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); duke@435: _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); duke@435: } duke@435: duke@435: //------------------------------Node------------------------------------------- duke@435: Node::Node(Node *n0, Node *n1, Node *n2, Node *n3) duke@435: : _idx(IDX_INIT(4)) duke@435: { duke@435: debug_only( verify_construction() ); duke@435: NOT_PRODUCT(nodes_created++); duke@435: // Assert we allocated space for input array already duke@435: assert( _in[3] == this, "Must pass arg count to 'new'" ); duke@435: assert( is_not_dead(n0), "can not use dead node"); duke@435: assert( is_not_dead(n1), "can not use dead node"); duke@435: assert( is_not_dead(n2), "can not use dead node"); duke@435: assert( is_not_dead(n3), "can not use dead node"); duke@435: _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); duke@435: _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); duke@435: _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); duke@435: _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); duke@435: } duke@435: duke@435: //------------------------------Node------------------------------------------- duke@435: Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, Node *n4) duke@435: : _idx(IDX_INIT(5)) duke@435: { duke@435: debug_only( verify_construction() ); duke@435: NOT_PRODUCT(nodes_created++); duke@435: // Assert we allocated space for input array already duke@435: assert( _in[4] == this, "Must pass arg count to 'new'" ); duke@435: assert( is_not_dead(n0), "can not use dead node"); duke@435: assert( is_not_dead(n1), "can not use dead node"); duke@435: assert( is_not_dead(n2), "can not use dead node"); duke@435: assert( is_not_dead(n3), "can not use dead node"); duke@435: assert( is_not_dead(n4), "can not use dead node"); duke@435: _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); duke@435: _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); duke@435: _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); duke@435: _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); duke@435: _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); duke@435: } duke@435: duke@435: //------------------------------Node------------------------------------------- duke@435: Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, duke@435: Node *n4, Node *n5) duke@435: : _idx(IDX_INIT(6)) duke@435: { duke@435: debug_only( verify_construction() ); duke@435: NOT_PRODUCT(nodes_created++); duke@435: // Assert we allocated space for input array already duke@435: assert( _in[5] == this, "Must pass arg count to 'new'" ); duke@435: assert( is_not_dead(n0), "can not use dead node"); duke@435: assert( is_not_dead(n1), "can not use dead node"); duke@435: assert( is_not_dead(n2), "can not use dead node"); duke@435: assert( is_not_dead(n3), "can not use dead node"); duke@435: assert( is_not_dead(n4), "can not use dead node"); duke@435: assert( is_not_dead(n5), "can not use dead node"); duke@435: _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); duke@435: _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); duke@435: _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); duke@435: _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); duke@435: _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); duke@435: _in[5] = n5; if (n5 != NULL) n5->add_out((Node *)this); duke@435: } duke@435: duke@435: //------------------------------Node------------------------------------------- duke@435: Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, duke@435: Node *n4, Node *n5, Node *n6) duke@435: : _idx(IDX_INIT(7)) duke@435: { duke@435: debug_only( verify_construction() ); duke@435: NOT_PRODUCT(nodes_created++); duke@435: // Assert we allocated space for input array already duke@435: assert( _in[6] == this, "Must pass arg count to 'new'" ); duke@435: assert( is_not_dead(n0), "can not use dead node"); duke@435: assert( is_not_dead(n1), "can not use dead node"); duke@435: assert( is_not_dead(n2), "can not use dead node"); duke@435: assert( is_not_dead(n3), "can not use dead node"); duke@435: assert( is_not_dead(n4), "can not use dead node"); duke@435: assert( is_not_dead(n5), "can not use dead node"); duke@435: assert( is_not_dead(n6), "can not use dead node"); duke@435: _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this); duke@435: _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this); duke@435: _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this); duke@435: _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this); duke@435: _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this); duke@435: _in[5] = n5; if (n5 != NULL) n5->add_out((Node *)this); duke@435: _in[6] = n6; if (n6 != NULL) n6->add_out((Node *)this); duke@435: } duke@435: duke@435: duke@435: //------------------------------clone------------------------------------------ duke@435: // Clone a Node. duke@435: Node *Node::clone() const { duke@435: Compile *compile = Compile::current(); duke@435: uint s = size_of(); // Size of inherited Node duke@435: Node *n = (Node*)compile->node_arena()->Amalloc_D(size_of() + _max*sizeof(Node*)); duke@435: Copy::conjoint_words_to_lower((HeapWord*)this, (HeapWord*)n, s); duke@435: // Set the new input pointer array duke@435: n->_in = (Node**)(((char*)n)+s); duke@435: // Cannot share the old output pointer array, so kill it duke@435: n->_out = NO_OUT_ARRAY; duke@435: // And reset the counters to 0 duke@435: n->_outcnt = 0; duke@435: n->_outmax = 0; duke@435: // Unlock this guy, since he is not in any hash table. duke@435: debug_only(n->_hash_lock = 0); duke@435: // Walk the old node's input list to duplicate its edges duke@435: uint i; duke@435: for( i = 0; i < len(); i++ ) { duke@435: Node *x = in(i); duke@435: n->_in[i] = x; duke@435: if (x != NULL) x->add_out(n); duke@435: } duke@435: if (is_macro()) duke@435: compile->add_macro_node(n); duke@435: duke@435: n->set_idx(compile->next_unique()); // Get new unique index as well duke@435: debug_only( n->verify_construction() ); duke@435: NOT_PRODUCT(nodes_created++); duke@435: // Do not patch over the debug_idx of a clone, because it makes it duke@435: // impossible to break on the clone's moment of creation. duke@435: //debug_only( n->set_debug_idx( debug_idx() ) ); duke@435: duke@435: compile->copy_node_notes_to(n, (Node*) this); duke@435: duke@435: // MachNode clone duke@435: uint nopnds; duke@435: if (this->is_Mach() && (nopnds = this->as_Mach()->num_opnds()) > 0) { duke@435: MachNode *mach = n->as_Mach(); duke@435: MachNode *mthis = this->as_Mach(); duke@435: // Get address of _opnd_array. duke@435: // It should be the same offset since it is the clone of this node. duke@435: MachOper **from = mthis->_opnds; duke@435: MachOper **to = (MachOper **)((size_t)(&mach->_opnds) + duke@435: pointer_delta((const void*)from, duke@435: (const void*)(&mthis->_opnds), 1)); duke@435: mach->_opnds = to; duke@435: for ( uint i = 0; i < nopnds; ++i ) { duke@435: to[i] = from[i]->clone(compile); duke@435: } duke@435: } duke@435: // cloning CallNode may need to clone JVMState duke@435: if (n->is_Call()) { duke@435: CallNode *call = n->as_Call(); duke@435: call->clone_jvms(); duke@435: } duke@435: return n; // Return the clone duke@435: } duke@435: duke@435: //---------------------------setup_is_top-------------------------------------- duke@435: // Call this when changing the top node, to reassert the invariants duke@435: // required by Node::is_top. See Compile::set_cached_top_node. duke@435: void Node::setup_is_top() { duke@435: if (this == (Node*)Compile::current()->top()) { duke@435: // This node has just become top. Kill its out array. duke@435: _outcnt = _outmax = 0; duke@435: _out = NULL; // marker value for top duke@435: assert(is_top(), "must be top"); duke@435: } else { duke@435: if (_out == NULL) _out = NO_OUT_ARRAY; duke@435: assert(!is_top(), "must not be top"); duke@435: } duke@435: } duke@435: duke@435: duke@435: //------------------------------~Node------------------------------------------ duke@435: // Fancy destructor; eagerly attempt to reclaim Node numberings and storage duke@435: extern int reclaim_idx ; duke@435: extern int reclaim_in ; duke@435: extern int reclaim_node; duke@435: void Node::destruct() { duke@435: // Eagerly reclaim unique Node numberings duke@435: Compile* compile = Compile::current(); duke@435: if ((uint)_idx+1 == compile->unique()) { duke@435: compile->set_unique(compile->unique()-1); duke@435: #ifdef ASSERT duke@435: reclaim_idx++; duke@435: #endif duke@435: } duke@435: // Clear debug info: duke@435: Node_Notes* nn = compile->node_notes_at(_idx); duke@435: if (nn != NULL) nn->clear(); duke@435: // Walk the input array, freeing the corresponding output edges duke@435: _cnt = _max; // forget req/prec distinction duke@435: uint i; duke@435: for( i = 0; i < _max; i++ ) { duke@435: set_req(i, NULL); duke@435: //assert(def->out(def->outcnt()-1) == (Node *)this,"bad def-use hacking in reclaim"); duke@435: } duke@435: assert(outcnt() == 0, "deleting a node must not leave a dangling use"); duke@435: // See if the input array was allocated just prior to the object duke@435: int edge_size = _max*sizeof(void*); duke@435: int out_edge_size = _outmax*sizeof(void*); duke@435: char *edge_end = ((char*)_in) + edge_size; duke@435: char *out_array = (char*)(_out == NO_OUT_ARRAY? NULL: _out); duke@435: char *out_edge_end = out_array + out_edge_size; duke@435: int node_size = size_of(); duke@435: duke@435: // Free the output edge array duke@435: if (out_edge_size > 0) { duke@435: #ifdef ASSERT duke@435: if( out_edge_end == compile->node_arena()->hwm() ) duke@435: reclaim_in += out_edge_size; // count reclaimed out edges with in edges duke@435: #endif duke@435: compile->node_arena()->Afree(out_array, out_edge_size); duke@435: } duke@435: duke@435: // Free the input edge array and the node itself duke@435: if( edge_end == (char*)this ) { duke@435: #ifdef ASSERT duke@435: if( edge_end+node_size == compile->node_arena()->hwm() ) { duke@435: reclaim_in += edge_size; duke@435: reclaim_node+= node_size; duke@435: } duke@435: #else duke@435: // It was; free the input array and object all in one hit duke@435: compile->node_arena()->Afree(_in,edge_size+node_size); duke@435: #endif duke@435: } else { duke@435: duke@435: // Free just the input array duke@435: #ifdef ASSERT duke@435: if( edge_end == compile->node_arena()->hwm() ) duke@435: reclaim_in += edge_size; duke@435: #endif duke@435: compile->node_arena()->Afree(_in,edge_size); duke@435: duke@435: // Free just the object duke@435: #ifdef ASSERT duke@435: if( ((char*)this) + node_size == compile->node_arena()->hwm() ) duke@435: reclaim_node+= node_size; duke@435: #else duke@435: compile->node_arena()->Afree(this,node_size); duke@435: #endif duke@435: } duke@435: if (is_macro()) { duke@435: compile->remove_macro_node(this); duke@435: } duke@435: #ifdef ASSERT duke@435: // We will not actually delete the storage, but we'll make the node unusable. duke@435: *(address*)this = badAddress; // smash the C++ vtbl, probably duke@435: _in = _out = (Node**) badAddress; duke@435: _max = _cnt = _outmax = _outcnt = 0; duke@435: #endif duke@435: } duke@435: duke@435: //------------------------------grow------------------------------------------- duke@435: // Grow the input array, making space for more edges duke@435: void Node::grow( uint len ) { duke@435: Arena* arena = Compile::current()->node_arena(); duke@435: uint new_max = _max; duke@435: if( new_max == 0 ) { duke@435: _max = 4; duke@435: _in = (Node**)arena->Amalloc(4*sizeof(Node*)); duke@435: Node** to = _in; duke@435: to[0] = NULL; duke@435: to[1] = NULL; duke@435: to[2] = NULL; duke@435: to[3] = NULL; duke@435: return; duke@435: } duke@435: while( new_max <= len ) new_max <<= 1; // Find next power-of-2 duke@435: // Trimming to limit allows a uint8 to handle up to 255 edges. duke@435: // Previously I was using only powers-of-2 which peaked at 128 edges. duke@435: //if( new_max >= limit ) new_max = limit-1; duke@435: _in = (Node**)arena->Arealloc(_in, _max*sizeof(Node*), new_max*sizeof(Node*)); duke@435: Copy::zero_to_bytes(&_in[_max], (new_max-_max)*sizeof(Node*)); // NULL all new space duke@435: _max = new_max; // Record new max length duke@435: // This assertion makes sure that Node::_max is wide enough to duke@435: // represent the numerical value of new_max. duke@435: assert(_max == new_max && _max > len, "int width of _max is too small"); duke@435: } duke@435: duke@435: //-----------------------------out_grow---------------------------------------- duke@435: // Grow the input array, making space for more edges duke@435: void Node::out_grow( uint len ) { duke@435: assert(!is_top(), "cannot grow a top node's out array"); duke@435: Arena* arena = Compile::current()->node_arena(); duke@435: uint new_max = _outmax; duke@435: if( new_max == 0 ) { duke@435: _outmax = 4; duke@435: _out = (Node **)arena->Amalloc(4*sizeof(Node*)); duke@435: return; duke@435: } duke@435: while( new_max <= len ) new_max <<= 1; // Find next power-of-2 duke@435: // Trimming to limit allows a uint8 to handle up to 255 edges. duke@435: // Previously I was using only powers-of-2 which peaked at 128 edges. duke@435: //if( new_max >= limit ) new_max = limit-1; duke@435: assert(_out != NULL && _out != NO_OUT_ARRAY, "out must have sensible value"); duke@435: _out = (Node**)arena->Arealloc(_out,_outmax*sizeof(Node*),new_max*sizeof(Node*)); duke@435: //Copy::zero_to_bytes(&_out[_outmax], (new_max-_outmax)*sizeof(Node*)); // NULL all new space duke@435: _outmax = new_max; // Record new max length duke@435: // This assertion makes sure that Node::_max is wide enough to duke@435: // represent the numerical value of new_max. duke@435: assert(_outmax == new_max && _outmax > len, "int width of _outmax is too small"); duke@435: } duke@435: duke@435: #ifdef ASSERT duke@435: //------------------------------is_dead---------------------------------------- duke@435: bool Node::is_dead() const { duke@435: // Mach and pinch point nodes may look like dead. duke@435: if( is_top() || is_Mach() || (Opcode() == Op_Node && _outcnt > 0) ) duke@435: return false; duke@435: for( uint i = 0; i < _max; i++ ) duke@435: if( _in[i] != NULL ) duke@435: return false; duke@435: dump(); duke@435: return true; duke@435: } duke@435: #endif duke@435: duke@435: //------------------------------add_req---------------------------------------- duke@435: // Add a new required input at the end duke@435: void Node::add_req( Node *n ) { duke@435: assert( is_not_dead(n), "can not use dead node"); duke@435: duke@435: // Look to see if I can move precedence down one without reallocating duke@435: if( (_cnt >= _max) || (in(_max-1) != NULL) ) duke@435: grow( _max+1 ); duke@435: duke@435: // Find a precedence edge to move duke@435: if( in(_cnt) != NULL ) { // Next precedence edge is busy? duke@435: uint i; duke@435: for( i=_cnt; i<_max; i++ ) duke@435: if( in(i) == NULL ) // Find the NULL at end of prec edge list duke@435: break; // There must be one, since we grew the array duke@435: _in[i] = in(_cnt); // Move prec over, making space for req edge duke@435: } duke@435: _in[_cnt++] = n; // Stuff over old prec edge duke@435: if (n != NULL) n->add_out((Node *)this); duke@435: } duke@435: duke@435: //---------------------------add_req_batch------------------------------------- duke@435: // Add a new required input at the end duke@435: void Node::add_req_batch( Node *n, uint m ) { duke@435: assert( is_not_dead(n), "can not use dead node"); duke@435: // check various edge cases duke@435: if ((int)m <= 1) { duke@435: assert((int)m >= 0, "oob"); duke@435: if (m != 0) add_req(n); duke@435: return; duke@435: } duke@435: duke@435: // Look to see if I can move precedence down one without reallocating duke@435: if( (_cnt+m) > _max || _in[_max-m] ) duke@435: grow( _max+m ); duke@435: duke@435: // Find a precedence edge to move duke@435: if( _in[_cnt] != NULL ) { // Next precedence edge is busy? duke@435: uint i; duke@435: for( i=_cnt; i<_max; i++ ) duke@435: if( _in[i] == NULL ) // Find the NULL at end of prec edge list duke@435: break; // There must be one, since we grew the array duke@435: // Slide all the precs over by m positions (assume #prec << m). duke@435: Copy::conjoint_words_to_higher((HeapWord*)&_in[_cnt], (HeapWord*)&_in[_cnt+m], ((i-_cnt)*sizeof(Node*))); duke@435: } duke@435: duke@435: // Stuff over the old prec edges duke@435: for(uint i=0; iis_top()) { duke@435: for(uint i=0; iadd_out((Node *)this); duke@435: } duke@435: } duke@435: } duke@435: duke@435: //------------------------------del_req---------------------------------------- duke@435: // Delete the required edge and compact the edge array duke@435: void Node::del_req( uint idx ) { duke@435: // First remove corresponding def-use edge duke@435: Node *n = in(idx); duke@435: if (n != NULL) n->del_out((Node *)this); duke@435: _in[idx] = in(--_cnt); // Compact the array duke@435: _in[_cnt] = NULL; // NULL out emptied slot duke@435: } duke@435: duke@435: //------------------------------ins_req---------------------------------------- duke@435: // Insert a new required input at the end duke@435: void Node::ins_req( uint idx, Node *n ) { duke@435: assert( is_not_dead(n), "can not use dead node"); duke@435: add_req(NULL); // Make space duke@435: assert( idx < _max, "Must have allocated enough space"); duke@435: // Slide over duke@435: if(_cnt-idx-1 > 0) { duke@435: Copy::conjoint_words_to_higher((HeapWord*)&_in[idx], (HeapWord*)&_in[idx+1], ((_cnt-idx-1)*sizeof(Node*))); duke@435: } duke@435: _in[idx] = n; // Stuff over old required edge duke@435: if (n != NULL) n->add_out((Node *)this); // Add reciprocal def-use edge duke@435: } duke@435: duke@435: //-----------------------------find_edge--------------------------------------- duke@435: int Node::find_edge(Node* n) { duke@435: for (uint i = 0; i < len(); i++) { duke@435: if (_in[i] == n) return i; duke@435: } duke@435: return -1; duke@435: } duke@435: duke@435: //----------------------------replace_edge------------------------------------- duke@435: int Node::replace_edge(Node* old, Node* neww) { duke@435: if (old == neww) return 0; // nothing to do duke@435: uint nrep = 0; duke@435: for (uint i = 0; i < len(); i++) { duke@435: if (in(i) == old) { duke@435: if (i < req()) duke@435: set_req(i, neww); duke@435: else duke@435: set_prec(i, neww); duke@435: nrep++; duke@435: } duke@435: } duke@435: return nrep; duke@435: } duke@435: duke@435: //-------------------------disconnect_inputs----------------------------------- duke@435: // NULL out all inputs to eliminate incoming Def-Use edges. duke@435: // Return the number of edges between 'n' and 'this' duke@435: int Node::disconnect_inputs(Node *n) { duke@435: int edges_to_n = 0; duke@435: duke@435: uint cnt = req(); duke@435: for( uint i = 0; i < cnt; ++i ) { duke@435: if( in(i) == 0 ) continue; duke@435: if( in(i) == n ) ++edges_to_n; duke@435: set_req(i, NULL); duke@435: } duke@435: // Remove precedence edges if any exist duke@435: // Note: Safepoints may have precedence edges, even during parsing duke@435: if( (req() != len()) && (in(req()) != NULL) ) { duke@435: uint max = len(); duke@435: for( uint i = 0; i < max; ++i ) { duke@435: if( in(i) == 0 ) continue; duke@435: if( in(i) == n ) ++edges_to_n; duke@435: set_prec(i, NULL); duke@435: } duke@435: } duke@435: duke@435: // Node::destruct requires all out edges be deleted first duke@435: // debug_only(destruct();) // no reuse benefit expected duke@435: return edges_to_n; duke@435: } duke@435: duke@435: //-----------------------------uncast--------------------------------------- duke@435: // %%% Temporary, until we sort out CheckCastPP vs. CastPP. duke@435: // Strip away casting. (It is depth-limited.) duke@435: Node* Node::uncast() const { duke@435: // Should be inline: duke@435: //return is_ConstraintCast() ? uncast_helper(this) : (Node*) this; kvn@500: if (is_ConstraintCast() || is_CheckCastPP()) duke@435: return uncast_helper(this); duke@435: else duke@435: return (Node*) this; duke@435: } duke@435: duke@435: //---------------------------uncast_helper------------------------------------- duke@435: Node* Node::uncast_helper(const Node* p) { duke@435: uint max_depth = 3; duke@435: for (uint i = 0; i < max_depth; i++) { duke@435: if (p == NULL || p->req() != 2) { duke@435: break; duke@435: } else if (p->is_ConstraintCast()) { duke@435: p = p->in(1); kvn@500: } else if (p->is_CheckCastPP()) { duke@435: p = p->in(1); duke@435: } else { duke@435: break; duke@435: } duke@435: } duke@435: return (Node*) p; duke@435: } duke@435: duke@435: //------------------------------add_prec--------------------------------------- duke@435: // Add a new precedence input. Precedence inputs are unordered, with duke@435: // duplicates removed and NULLs packed down at the end. duke@435: void Node::add_prec( Node *n ) { duke@435: assert( is_not_dead(n), "can not use dead node"); duke@435: duke@435: // Check for NULL at end duke@435: if( _cnt >= _max || in(_max-1) ) duke@435: grow( _max+1 ); duke@435: duke@435: // Find a precedence edge to move duke@435: uint i = _cnt; duke@435: while( in(i) != NULL ) i++; duke@435: _in[i] = n; // Stuff prec edge over NULL duke@435: if ( n != NULL) n->add_out((Node *)this); // Add mirror edge duke@435: } duke@435: duke@435: //------------------------------rm_prec---------------------------------------- duke@435: // Remove a precedence input. Precedence inputs are unordered, with duke@435: // duplicates removed and NULLs packed down at the end. duke@435: void Node::rm_prec( uint j ) { duke@435: duke@435: // Find end of precedence list to pack NULLs duke@435: uint i; duke@435: for( i=j; i<_max; i++ ) duke@435: if( !_in[i] ) // Find the NULL at end of prec edge list duke@435: break; duke@435: if (_in[j] != NULL) _in[j]->del_out((Node *)this); duke@435: _in[j] = _in[--i]; // Move last element over removed guy duke@435: _in[i] = NULL; // NULL out last element duke@435: } duke@435: duke@435: //------------------------------size_of---------------------------------------- duke@435: uint Node::size_of() const { return sizeof(*this); } duke@435: duke@435: //------------------------------ideal_reg-------------------------------------- duke@435: uint Node::ideal_reg() const { return 0; } duke@435: duke@435: //------------------------------jvms------------------------------------------- duke@435: JVMState* Node::jvms() const { return NULL; } duke@435: duke@435: #ifdef ASSERT duke@435: //------------------------------jvms------------------------------------------- duke@435: bool Node::verify_jvms(const JVMState* using_jvms) const { duke@435: for (JVMState* jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) { duke@435: if (jvms == using_jvms) return true; duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: //------------------------------init_NodeProperty------------------------------ duke@435: void Node::init_NodeProperty() { duke@435: assert(_max_classes <= max_jushort, "too many NodeProperty classes"); duke@435: assert(_max_flags <= max_jushort, "too many NodeProperty flags"); duke@435: } duke@435: #endif duke@435: duke@435: //------------------------------format----------------------------------------- duke@435: // Print as assembly duke@435: void Node::format( PhaseRegAlloc *, outputStream *st ) const {} duke@435: //------------------------------emit------------------------------------------- duke@435: // Emit bytes starting at parameter 'ptr'. duke@435: void Node::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {} duke@435: //------------------------------size------------------------------------------- duke@435: // Size of instruction in bytes duke@435: uint Node::size(PhaseRegAlloc *ra_) const { return 0; } duke@435: duke@435: //------------------------------CFG Construction------------------------------- duke@435: // Nodes that end basic blocks, e.g. IfTrue/IfFalse, JumpProjNode, Root, duke@435: // Goto and Return. duke@435: const Node *Node::is_block_proj() const { return 0; } duke@435: duke@435: // Minimum guaranteed type duke@435: const Type *Node::bottom_type() const { return Type::BOTTOM; } duke@435: duke@435: duke@435: //------------------------------raise_bottom_type------------------------------ duke@435: // Get the worst-case Type output for this Node. duke@435: void Node::raise_bottom_type(const Type* new_type) { duke@435: if (is_Type()) { duke@435: TypeNode *n = this->as_Type(); duke@435: if (VerifyAliases) { duke@435: assert(new_type->higher_equal(n->type()), "new type must refine old type"); duke@435: } duke@435: n->set_type(new_type); duke@435: } else if (is_Load()) { duke@435: LoadNode *n = this->as_Load(); duke@435: if (VerifyAliases) { duke@435: assert(new_type->higher_equal(n->type()), "new type must refine old type"); duke@435: } duke@435: n->set_type(new_type); duke@435: } duke@435: } duke@435: duke@435: //------------------------------Identity--------------------------------------- duke@435: // Return a node that the given node is equivalent to. duke@435: Node *Node::Identity( PhaseTransform * ) { duke@435: return this; // Default to no identities duke@435: } duke@435: duke@435: //------------------------------Value------------------------------------------ duke@435: // Compute a new Type for a node using the Type of the inputs. duke@435: const Type *Node::Value( PhaseTransform * ) const { duke@435: return bottom_type(); // Default to worst-case Type duke@435: } duke@435: duke@435: //------------------------------Ideal------------------------------------------ duke@435: // duke@435: // 'Idealize' the graph rooted at this Node. duke@435: // duke@435: // In order to be efficient and flexible there are some subtle invariants duke@435: // these Ideal calls need to hold. Running with '+VerifyIterativeGVN' checks duke@435: // these invariants, although its too slow to have on by default. If you are duke@435: // hacking an Ideal call, be sure to test with +VerifyIterativeGVN! duke@435: // duke@435: // The Ideal call almost arbitrarily reshape the graph rooted at the 'this' duke@435: // pointer. If ANY change is made, it must return the root of the reshaped duke@435: // graph - even if the root is the same Node. Example: swapping the inputs duke@435: // to an AddINode gives the same answer and same root, but you still have to duke@435: // return the 'this' pointer instead of NULL. duke@435: // duke@435: // You cannot return an OLD Node, except for the 'this' pointer. Use the duke@435: // Identity call to return an old Node; basically if Identity can find duke@435: // another Node have the Ideal call make no change and return NULL. duke@435: // Example: AddINode::Ideal must check for add of zero; in this case it duke@435: // returns NULL instead of doing any graph reshaping. duke@435: // duke@435: // You cannot modify any old Nodes except for the 'this' pointer. Due to duke@435: // sharing there may be other users of the old Nodes relying on their current duke@435: // semantics. Modifying them will break the other users. duke@435: // Example: when reshape "(X+3)+4" into "X+7" you must leave the Node for duke@435: // "X+3" unchanged in case it is shared. duke@435: // duke@435: // If you modify the 'this' pointer's inputs, you must use 'set_req' with duke@435: // def-use info. If you are making a new Node (either as the new root or duke@435: // some new internal piece) you must NOT use set_req with def-use info. duke@435: // You can make a new Node with either 'new' or 'clone'. In either case, duke@435: // def-use info is (correctly) not generated. duke@435: // Example: reshape "(X+3)+4" into "X+7": duke@435: // set_req(1,in(1)->in(1) /* grab X */, du /* must use DU on 'this' */); duke@435: // set_req(2,phase->intcon(7),du); duke@435: // return this; duke@435: // Example: reshape "X*4" into "X<<1" duke@435: // return new (C,3) LShiftINode( in(1), phase->intcon(1) ); duke@435: // duke@435: // You must call 'phase->transform(X)' on any new Nodes X you make, except duke@435: // for the returned root node. Example: reshape "X*31" with "(X<<5)-1". duke@435: // Node *shift=phase->transform(new(C,3)LShiftINode(in(1),phase->intcon(5))); duke@435: // return new (C,3) AddINode(shift, phase->intcon(-1)); duke@435: // duke@435: // When making a Node for a constant use 'phase->makecon' or 'phase->intcon'. duke@435: // These forms are faster than 'phase->transform(new (C,1) ConNode())' and Do duke@435: // The Right Thing with def-use info. duke@435: // duke@435: // You cannot bury the 'this' Node inside of a graph reshape. If the reshaped duke@435: // graph uses the 'this' Node it must be the root. If you want a Node with duke@435: // the same Opcode as the 'this' pointer use 'clone'. duke@435: // duke@435: Node *Node::Ideal(PhaseGVN *phase, bool can_reshape) { duke@435: return NULL; // Default to being Ideal already duke@435: } duke@435: duke@435: // Some nodes have specific Ideal subgraph transformations only if they are duke@435: // unique users of specific nodes. Such nodes should be put on IGVN worklist duke@435: // for the transformations to happen. duke@435: bool Node::has_special_unique_user() const { duke@435: assert(outcnt() == 1, "match only for unique out"); duke@435: Node* n = unique_out(); duke@435: int op = Opcode(); duke@435: if( this->is_Store() ) { duke@435: // Condition for back-to-back stores folding. duke@435: return n->Opcode() == op && n->in(MemNode::Memory) == this; duke@435: } else if( op == Op_AddL ) { duke@435: // Condition for convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y)) duke@435: return n->Opcode() == Op_ConvL2I && n->in(1) == this; duke@435: } else if( op == Op_SubI || op == Op_SubL ) { duke@435: // Condition for subI(x,subI(y,z)) ==> subI(addI(x,z),y) duke@435: return n->Opcode() == op && n->in(2) == this; duke@435: } duke@435: return false; duke@435: }; duke@435: duke@435: //------------------------------remove_dead_region----------------------------- duke@435: // This control node is dead. Follow the subgraph below it making everything duke@435: // using it dead as well. This will happen normally via the usual IterGVN duke@435: // worklist but this call is more efficient. Do not update use-def info duke@435: // inside the dead region, just at the borders. duke@435: static bool kill_dead_code( Node *dead, PhaseIterGVN *igvn ) { duke@435: // Con's are a popular node to re-hit in the hash table again. duke@435: if( dead->is_Con() ) return false; duke@435: duke@435: // Can't put ResourceMark here since igvn->_worklist uses the same arena duke@435: // for verify pass with +VerifyOpto and we add/remove elements in it here. duke@435: Node_List nstack(Thread::current()->resource_area()); duke@435: duke@435: Node *top = igvn->C->top(); duke@435: bool progress = false; duke@435: nstack.push(dead); duke@435: duke@435: while (nstack.size() > 0) { duke@435: dead = nstack.pop(); duke@435: if (dead->outcnt() > 0) { duke@435: // Keep dead node on stack until all uses are processed. duke@435: nstack.push(dead); duke@435: // For all Users of the Dead... ;-) duke@435: for (DUIterator_Last kmin, k = dead->last_outs(kmin); k >= kmin; ) { duke@435: Node* use = dead->last_out(k); duke@435: igvn->hash_delete(use); // Yank from hash table prior to mod duke@435: if (use->in(0) == dead) { // Found another dead node duke@435: assert (!use->is_Con(), "Control for Con node should be Root node.") duke@435: use->set_req(0, top); // Cut dead edge to prevent processing duke@435: nstack.push(use); // the dead node again. duke@435: } else { // Else found a not-dead user duke@435: for (uint j = 1; j < use->req(); j++) { duke@435: if (use->in(j) == dead) { // Turn all dead inputs into TOP duke@435: use->set_req(j, top); duke@435: } duke@435: } duke@435: igvn->_worklist.push(use); duke@435: } duke@435: // Refresh the iterator, since any number of kills might have happened. duke@435: k = dead->last_outs(kmin); duke@435: } duke@435: } else { // (dead->outcnt() == 0) duke@435: // Done with outputs. duke@435: igvn->hash_delete(dead); duke@435: igvn->_worklist.remove(dead); duke@435: igvn->set_type(dead, Type::TOP); duke@435: if (dead->is_macro()) { duke@435: igvn->C->remove_macro_node(dead); duke@435: } duke@435: // Kill all inputs to the dead guy duke@435: for (uint i=0; i < dead->req(); i++) { duke@435: Node *n = dead->in(i); // Get input to dead guy duke@435: if (n != NULL && !n->is_top()) { // Input is valid? duke@435: progress = true; duke@435: dead->set_req(i, top); // Smash input away duke@435: if (n->outcnt() == 0) { // Input also goes dead? duke@435: if (!n->is_Con()) duke@435: nstack.push(n); // Clear it out as well duke@435: } else if (n->outcnt() == 1 && duke@435: n->has_special_unique_user()) { duke@435: igvn->add_users_to_worklist( n ); duke@435: } else if (n->outcnt() <= 2 && n->is_Store()) { duke@435: // Push store's uses on worklist to enable folding optimization for duke@435: // store/store and store/load to the same address. duke@435: // The restriction (outcnt() <= 2) is the same as in set_req_X() duke@435: // and remove_globally_dead_node(). duke@435: igvn->add_users_to_worklist( n ); duke@435: } duke@435: } duke@435: } duke@435: } // (dead->outcnt() == 0) duke@435: } // while (nstack.size() > 0) for outputs duke@435: return progress; duke@435: } duke@435: duke@435: //------------------------------remove_dead_region----------------------------- duke@435: bool Node::remove_dead_region(PhaseGVN *phase, bool can_reshape) { duke@435: Node *n = in(0); duke@435: if( !n ) return false; duke@435: // Lost control into this guy? I.e., it became unreachable? duke@435: // Aggressively kill all unreachable code. duke@435: if (can_reshape && n->is_top()) { duke@435: return kill_dead_code(this, phase->is_IterGVN()); duke@435: } duke@435: duke@435: if( n->is_Region() && n->as_Region()->is_copy() ) { duke@435: Node *m = n->nonnull_req(); duke@435: set_req(0, m); duke@435: return true; duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: //------------------------------Ideal_DU_postCCP------------------------------- duke@435: // Idealize graph, using DU info. Must clone result into new-space duke@435: Node *Node::Ideal_DU_postCCP( PhaseCCP * ) { duke@435: return NULL; // Default to no change duke@435: } duke@435: duke@435: //------------------------------hash------------------------------------------- duke@435: // Hash function over Nodes. duke@435: uint Node::hash() const { duke@435: uint sum = 0; duke@435: for( uint i=0; i<_cnt; i++ ) // Add in all inputs duke@435: sum = (sum<<1)-(uintptr_t)in(i); // Ignore embedded NULLs duke@435: return (sum>>2) + _cnt + Opcode(); duke@435: } duke@435: duke@435: //------------------------------cmp-------------------------------------------- duke@435: // Compare special parts of simple Nodes duke@435: uint Node::cmp( const Node &n ) const { duke@435: return 1; // Must be same duke@435: } duke@435: duke@435: //------------------------------rematerialize----------------------------------- duke@435: // Should we clone rather than spill this instruction? duke@435: bool Node::rematerialize() const { duke@435: if ( is_Mach() ) duke@435: return this->as_Mach()->rematerialize(); duke@435: else duke@435: return (_flags & Flag_rematerialize) != 0; duke@435: } duke@435: duke@435: //------------------------------needs_anti_dependence_check--------------------- duke@435: // Nodes which use memory without consuming it, hence need antidependences. duke@435: bool Node::needs_anti_dependence_check() const { duke@435: if( req() < 2 || (_flags & Flag_needs_anti_dependence_check) == 0 ) duke@435: return false; duke@435: else duke@435: return in(1)->bottom_type()->has_memory(); duke@435: } duke@435: duke@435: duke@435: // Get an integer constant from a ConNode (or CastIINode). duke@435: // Return a default value if there is no apparent constant here. duke@435: const TypeInt* Node::find_int_type() const { duke@435: if (this->is_Type()) { duke@435: return this->as_Type()->type()->isa_int(); duke@435: } else if (this->is_Con()) { duke@435: assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode"); duke@435: return this->bottom_type()->isa_int(); duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: // Get a pointer constant from a ConstNode. duke@435: // Returns the constant if it is a pointer ConstNode duke@435: intptr_t Node::get_ptr() const { duke@435: assert( Opcode() == Op_ConP, "" ); duke@435: return ((ConPNode*)this)->type()->is_ptr()->get_con(); duke@435: } duke@435: coleenp@548: // Get a narrow oop constant from a ConNNode. coleenp@548: intptr_t Node::get_narrowcon() const { coleenp@548: assert( Opcode() == Op_ConN, "" ); coleenp@548: return ((ConNNode*)this)->type()->is_narrowoop()->get_con(); coleenp@548: } coleenp@548: duke@435: // Get a long constant from a ConNode. duke@435: // Return a default value if there is no apparent constant here. duke@435: const TypeLong* Node::find_long_type() const { duke@435: if (this->is_Type()) { duke@435: return this->as_Type()->type()->isa_long(); duke@435: } else if (this->is_Con()) { duke@435: assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode"); duke@435: return this->bottom_type()->isa_long(); duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: // Get a double constant from a ConstNode. duke@435: // Returns the constant if it is a double ConstNode duke@435: jdouble Node::getd() const { duke@435: assert( Opcode() == Op_ConD, "" ); duke@435: return ((ConDNode*)this)->type()->is_double_constant()->getd(); duke@435: } duke@435: duke@435: // Get a float constant from a ConstNode. duke@435: // Returns the constant if it is a float ConstNode duke@435: jfloat Node::getf() const { duke@435: assert( Opcode() == Op_ConF, "" ); duke@435: return ((ConFNode*)this)->type()->is_float_constant()->getf(); duke@435: } duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: //----------------------------NotANode---------------------------------------- duke@435: // Used in debugging code to avoid walking across dead or uninitialized edges. duke@435: static inline bool NotANode(const Node* n) { duke@435: if (n == NULL) return true; duke@435: if (((intptr_t)n & 1) != 0) return true; // uninitialized, etc. duke@435: if (*(address*)n == badAddress) return true; // kill by Node::destruct duke@435: return false; duke@435: } duke@435: duke@435: duke@435: //------------------------------find------------------------------------------ duke@435: // Find a neighbor of this Node with the given _idx duke@435: // If idx is negative, find its absolute value, following both _in and _out. duke@435: static void find_recur( Node* &result, Node *n, int idx, bool only_ctrl, duke@435: VectorSet &old_space, VectorSet &new_space ) { duke@435: int node_idx = (idx >= 0) ? idx : -idx; duke@435: if (NotANode(n)) return; // Gracefully handle NULL, -1, 0xabababab, etc. duke@435: // Contained in new_space or old_space? duke@435: VectorSet *v = Compile::current()->node_arena()->contains(n) ? &new_space : &old_space; duke@435: if( v->test(n->_idx) ) return; duke@435: if( (int)n->_idx == node_idx duke@435: debug_only(|| n->debug_idx() == node_idx) ) { duke@435: if (result != NULL) duke@435: tty->print("find: " INTPTR_FORMAT " and " INTPTR_FORMAT " both have idx==%d\n", duke@435: (uintptr_t)result, (uintptr_t)n, node_idx); duke@435: result = n; duke@435: } duke@435: v->set(n->_idx); duke@435: for( uint i=0; ilen(); i++ ) { duke@435: if( only_ctrl && !(n->is_Region()) && (n->Opcode() != Op_Root) && (i != TypeFunc::Control) ) continue; duke@435: find_recur( result, n->in(i), idx, only_ctrl, old_space, new_space ); duke@435: } duke@435: // Search along forward edges also: duke@435: if (idx < 0 && !only_ctrl) { duke@435: for( uint j=0; joutcnt(); j++ ) { duke@435: find_recur( result, n->raw_out(j), idx, only_ctrl, old_space, new_space ); duke@435: } duke@435: } duke@435: #ifdef ASSERT duke@435: // Search along debug_orig edges last: duke@435: for (Node* orig = n->debug_orig(); orig != NULL; orig = orig->debug_orig()) { duke@435: if (NotANode(orig)) break; duke@435: find_recur( result, orig, idx, only_ctrl, old_space, new_space ); duke@435: } duke@435: #endif //ASSERT duke@435: } duke@435: duke@435: // call this from debugger: duke@435: Node* find_node(Node* n, int idx) { duke@435: return n->find(idx); duke@435: } duke@435: duke@435: //------------------------------find------------------------------------------- duke@435: Node* Node::find(int idx) const { duke@435: ResourceArea *area = Thread::current()->resource_area(); duke@435: VectorSet old_space(area), new_space(area); duke@435: Node* result = NULL; duke@435: find_recur( result, (Node*) this, idx, false, old_space, new_space ); duke@435: return result; duke@435: } duke@435: duke@435: //------------------------------find_ctrl-------------------------------------- duke@435: // Find an ancestor to this node in the control history with given _idx duke@435: Node* Node::find_ctrl(int idx) const { duke@435: ResourceArea *area = Thread::current()->resource_area(); duke@435: VectorSet old_space(area), new_space(area); duke@435: Node* result = NULL; duke@435: find_recur( result, (Node*) this, idx, true, old_space, new_space ); duke@435: return result; duke@435: } duke@435: #endif duke@435: duke@435: duke@435: duke@435: #ifndef PRODUCT duke@435: int Node::_in_dump_cnt = 0; duke@435: duke@435: // -----------------------------Name------------------------------------------- duke@435: extern const char *NodeClassNames[]; duke@435: const char *Node::Name() const { return NodeClassNames[Opcode()]; } duke@435: duke@435: static bool is_disconnected(const Node* n) { duke@435: for (uint i = 0; i < n->req(); i++) { duke@435: if (n->in(i) != NULL) return false; duke@435: } duke@435: return true; duke@435: } duke@435: duke@435: #ifdef ASSERT duke@435: static void dump_orig(Node* orig) { duke@435: Compile* C = Compile::current(); duke@435: if (NotANode(orig)) orig = NULL; duke@435: if (orig != NULL && !C->node_arena()->contains(orig)) orig = NULL; duke@435: if (orig == NULL) return; duke@435: tty->print(" !orig="); duke@435: Node* fast = orig->debug_orig(); // tortoise & hare algorithm to detect loops duke@435: if (NotANode(fast)) fast = NULL; duke@435: while (orig != NULL) { duke@435: bool discon = is_disconnected(orig); // if discon, print [123] else 123 duke@435: if (discon) tty->print("["); duke@435: if (!Compile::current()->node_arena()->contains(orig)) duke@435: tty->print("o"); duke@435: tty->print("%d", orig->_idx); duke@435: if (discon) tty->print("]"); duke@435: orig = orig->debug_orig(); duke@435: if (NotANode(orig)) orig = NULL; duke@435: if (orig != NULL && !C->node_arena()->contains(orig)) orig = NULL; duke@435: if (orig != NULL) tty->print(","); duke@435: if (fast != NULL) { duke@435: // Step fast twice for each single step of orig: duke@435: fast = fast->debug_orig(); duke@435: if (NotANode(fast)) fast = NULL; duke@435: if (fast != NULL && fast != orig) { duke@435: fast = fast->debug_orig(); duke@435: if (NotANode(fast)) fast = NULL; duke@435: } duke@435: if (fast == orig) { duke@435: tty->print("..."); duke@435: break; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: void Node::set_debug_orig(Node* orig) { duke@435: _debug_orig = orig; duke@435: if (BreakAtNode == 0) return; duke@435: if (NotANode(orig)) orig = NULL; duke@435: int trip = 10; duke@435: while (orig != NULL) { duke@435: if (orig->debug_idx() == BreakAtNode || (int)orig->_idx == BreakAtNode) { duke@435: tty->print_cr("BreakAtNode: _idx=%d _debug_idx=%d orig._idx=%d orig._debug_idx=%d", duke@435: this->_idx, this->debug_idx(), orig->_idx, orig->debug_idx()); duke@435: BREAKPOINT; duke@435: } duke@435: orig = orig->debug_orig(); duke@435: if (NotANode(orig)) orig = NULL; duke@435: if (trip-- <= 0) break; duke@435: } duke@435: } duke@435: #endif //ASSERT duke@435: duke@435: //------------------------------dump------------------------------------------ duke@435: // Dump a Node duke@435: void Node::dump() const { duke@435: Compile* C = Compile::current(); duke@435: bool is_new = C->node_arena()->contains(this); duke@435: _in_dump_cnt++; duke@435: tty->print("%c%d\t%s\t=== ", duke@435: is_new ? ' ' : 'o', _idx, Name()); duke@435: duke@435: // Dump the required and precedence inputs duke@435: dump_req(); duke@435: dump_prec(); duke@435: // Dump the outputs duke@435: dump_out(); duke@435: duke@435: if (is_disconnected(this)) { duke@435: #ifdef ASSERT duke@435: tty->print(" [%d]",debug_idx()); duke@435: dump_orig(debug_orig()); duke@435: #endif duke@435: tty->cr(); duke@435: _in_dump_cnt--; duke@435: return; // don't process dead nodes duke@435: } duke@435: duke@435: // Dump node-specific info duke@435: dump_spec(tty); duke@435: #ifdef ASSERT duke@435: // Dump the non-reset _debug_idx duke@435: if( Verbose && WizardMode ) { duke@435: tty->print(" [%d]",debug_idx()); duke@435: } duke@435: #endif duke@435: duke@435: const Type *t = bottom_type(); duke@435: duke@435: if (t != NULL && (t->isa_instptr() || t->isa_klassptr())) { duke@435: const TypeInstPtr *toop = t->isa_instptr(); duke@435: const TypeKlassPtr *tkls = t->isa_klassptr(); duke@435: ciKlass* klass = toop ? toop->klass() : (tkls ? tkls->klass() : NULL ); duke@435: if( klass && klass->is_loaded() && klass->is_interface() ) { duke@435: tty->print(" Interface:"); duke@435: } else if( toop ) { duke@435: tty->print(" Oop:"); duke@435: } else if( tkls ) { duke@435: tty->print(" Klass:"); duke@435: } duke@435: t->dump(); duke@435: } else if( t == Type::MEMORY ) { duke@435: tty->print(" Memory:"); duke@435: MemNode::dump_adr_type(this, adr_type(), tty); duke@435: } else if( Verbose || WizardMode ) { duke@435: tty->print(" Type:"); duke@435: if( t ) { duke@435: t->dump(); duke@435: } else { duke@435: tty->print("no type"); duke@435: } duke@435: } duke@435: if (is_new) { duke@435: debug_only(dump_orig(debug_orig())); duke@435: Node_Notes* nn = C->node_notes_at(_idx); duke@435: if (nn != NULL && !nn->is_clear()) { duke@435: if (nn->jvms() != NULL) { duke@435: tty->print(" !jvms:"); duke@435: nn->jvms()->dump_spec(tty); duke@435: } duke@435: } duke@435: } duke@435: tty->cr(); duke@435: _in_dump_cnt--; duke@435: } duke@435: duke@435: //------------------------------dump_req-------------------------------------- duke@435: void Node::dump_req() const { duke@435: // Dump the required input edges duke@435: for (uint i = 0; i < req(); i++) { // For all required inputs duke@435: Node* d = in(i); duke@435: if (d == NULL) { duke@435: tty->print("_ "); duke@435: } else if (NotANode(d)) { duke@435: tty->print("NotANode "); // uninitialized, sentinel, garbage, etc. duke@435: } else { duke@435: tty->print("%c%d ", Compile::current()->node_arena()->contains(d) ? ' ' : 'o', d->_idx); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: //------------------------------dump_prec------------------------------------- duke@435: void Node::dump_prec() const { duke@435: // Dump the precedence edges duke@435: int any_prec = 0; duke@435: for (uint i = req(); i < len(); i++) { // For all precedence inputs duke@435: Node* p = in(i); duke@435: if (p != NULL) { duke@435: if( !any_prec++ ) tty->print(" |"); duke@435: if (NotANode(p)) { tty->print("NotANode "); continue; } duke@435: tty->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx); duke@435: } duke@435: } duke@435: } duke@435: duke@435: //------------------------------dump_out-------------------------------------- duke@435: void Node::dump_out() const { duke@435: // Delimit the output edges duke@435: tty->print(" [["); duke@435: // Dump the output edges duke@435: for (uint i = 0; i < _outcnt; i++) { // For all outputs duke@435: Node* u = _out[i]; duke@435: if (u == NULL) { duke@435: tty->print("_ "); duke@435: } else if (NotANode(u)) { duke@435: tty->print("NotANode "); duke@435: } else { duke@435: tty->print("%c%d ", Compile::current()->node_arena()->contains(u) ? ' ' : 'o', u->_idx); duke@435: } duke@435: } duke@435: tty->print("]] "); duke@435: } duke@435: duke@435: //------------------------------dump_nodes------------------------------------- duke@435: static void dump_nodes(const Node* start, int d, bool only_ctrl) { duke@435: Node* s = (Node*)start; // remove const duke@435: if (NotANode(s)) return; duke@435: kvn@459: uint depth = (uint)ABS(d); kvn@459: int direction = d; duke@435: Compile* C = Compile::current(); kvn@475: GrowableArray nstack(C->unique()); duke@435: kvn@475: nstack.append(s); kvn@475: int begin = 0; kvn@475: int end = 0; kvn@475: for(uint i = 0; i < depth; i++) { kvn@475: end = nstack.length(); kvn@475: for(int j = begin; j < end; j++) { kvn@475: Node* tp = nstack.at(j); kvn@475: uint limit = direction > 0 ? tp->len() : tp->outcnt(); kvn@475: for(uint k = 0; k < limit; k++) { kvn@475: Node* n = direction > 0 ? tp->in(k) : tp->raw_out(k); duke@435: kvn@475: if (NotANode(n)) continue; kvn@475: // do not recurse through top or the root (would reach unrelated stuff) kvn@475: if (n->is_Root() || n->is_top()) continue; kvn@475: if (only_ctrl && !n->is_CFG()) continue; duke@435: kvn@475: bool on_stack = nstack.contains(n); kvn@475: if (!on_stack) { kvn@475: nstack.append(n); duke@435: } duke@435: } duke@435: } kvn@475: begin = end; kvn@475: } kvn@475: end = nstack.length(); kvn@475: if (direction > 0) { kvn@475: for(int j = end-1; j >= 0; j--) { kvn@475: nstack.at(j)->dump(); kvn@475: } kvn@475: } else { kvn@475: for(int j = 0; j < end; j++) { kvn@475: nstack.at(j)->dump(); kvn@475: } duke@435: } duke@435: } duke@435: duke@435: //------------------------------dump------------------------------------------- duke@435: void Node::dump(int d) const { duke@435: dump_nodes(this, d, false); duke@435: } duke@435: duke@435: //------------------------------dump_ctrl-------------------------------------- duke@435: // Dump a Node's control history to depth duke@435: void Node::dump_ctrl(int d) const { duke@435: dump_nodes(this, d, true); duke@435: } duke@435: duke@435: // VERIFICATION CODE duke@435: // For each input edge to a node (ie - for each Use-Def edge), verify that duke@435: // there is a corresponding Def-Use edge. duke@435: //------------------------------verify_edges----------------------------------- duke@435: void Node::verify_edges(Unique_Node_List &visited) { duke@435: uint i, j, idx; duke@435: int cnt; duke@435: Node *n; duke@435: duke@435: // Recursive termination test duke@435: if (visited.member(this)) return; duke@435: visited.push(this); duke@435: duke@435: // Walk over all input edges, checking for correspondance duke@435: for( i = 0; i < len(); i++ ) { duke@435: n = in(i); duke@435: if (n != NULL && !n->is_top()) { duke@435: // Count instances of (Node *)this duke@435: cnt = 0; duke@435: for (idx = 0; idx < n->_outcnt; idx++ ) { duke@435: if (n->_out[idx] == (Node *)this) cnt++; duke@435: } duke@435: assert( cnt > 0,"Failed to find Def-Use edge." ); duke@435: // Check for duplicate edges duke@435: // walk the input array downcounting the input edges to n duke@435: for( j = 0; j < len(); j++ ) { duke@435: if( in(j) == n ) cnt--; duke@435: } duke@435: assert( cnt == 0,"Mismatched edge count."); duke@435: } else if (n == NULL) { duke@435: assert(i >= req() || i == 0 || is_Region() || is_Phi(), "only regions or phis have null data edges"); duke@435: } else { duke@435: assert(n->is_top(), "sanity"); duke@435: // Nothing to check. duke@435: } duke@435: } duke@435: // Recursive walk over all input edges duke@435: for( i = 0; i < len(); i++ ) { duke@435: n = in(i); duke@435: if( n != NULL ) duke@435: in(i)->verify_edges(visited); duke@435: } duke@435: } duke@435: duke@435: //------------------------------verify_recur----------------------------------- duke@435: static const Node *unique_top = NULL; duke@435: duke@435: void Node::verify_recur(const Node *n, int verify_depth, duke@435: VectorSet &old_space, VectorSet &new_space) { duke@435: if ( verify_depth == 0 ) return; duke@435: if (verify_depth > 0) --verify_depth; duke@435: duke@435: Compile* C = Compile::current(); duke@435: duke@435: // Contained in new_space or old_space? duke@435: VectorSet *v = C->node_arena()->contains(n) ? &new_space : &old_space; duke@435: // Check for visited in the proper space. Numberings are not unique duke@435: // across spaces so we need a seperate VectorSet for each space. duke@435: if( v->test_set(n->_idx) ) return; duke@435: duke@435: if (n->is_Con() && n->bottom_type() == Type::TOP) { duke@435: if (C->cached_top_node() == NULL) duke@435: C->set_cached_top_node((Node*)n); duke@435: assert(C->cached_top_node() == n, "TOP node must be unique"); duke@435: } duke@435: duke@435: for( uint i = 0; i < n->len(); i++ ) { duke@435: Node *x = n->in(i); duke@435: if (!x || x->is_top()) continue; duke@435: duke@435: // Verify my input has a def-use edge to me duke@435: if (true /*VerifyDefUse*/) { duke@435: // Count use-def edges from n to x duke@435: int cnt = 0; duke@435: for( uint j = 0; j < n->len(); j++ ) duke@435: if( n->in(j) == x ) duke@435: cnt++; duke@435: // Count def-use edges from x to n duke@435: uint max = x->_outcnt; duke@435: for( uint k = 0; k < max; k++ ) duke@435: if (x->_out[k] == n) duke@435: cnt--; duke@435: assert( cnt == 0, "mismatched def-use edge counts" ); duke@435: } duke@435: duke@435: verify_recur(x, verify_depth, old_space, new_space); duke@435: } duke@435: duke@435: } duke@435: duke@435: //------------------------------verify----------------------------------------- duke@435: // Check Def-Use info for my subgraph duke@435: void Node::verify() const { duke@435: Compile* C = Compile::current(); duke@435: Node* old_top = C->cached_top_node(); duke@435: ResourceMark rm; duke@435: ResourceArea *area = Thread::current()->resource_area(); duke@435: VectorSet old_space(area), new_space(area); duke@435: verify_recur(this, -1, old_space, new_space); duke@435: C->set_cached_top_node(old_top); duke@435: } duke@435: #endif duke@435: duke@435: duke@435: //------------------------------walk------------------------------------------- duke@435: // Graph walk, with both pre-order and post-order functions duke@435: void Node::walk(NFunc pre, NFunc post, void *env) { duke@435: VectorSet visited(Thread::current()->resource_area()); // Setup for local walk duke@435: walk_(pre, post, env, visited); duke@435: } duke@435: duke@435: void Node::walk_(NFunc pre, NFunc post, void *env, VectorSet &visited) { duke@435: if( visited.test_set(_idx) ) return; duke@435: pre(*this,env); // Call the pre-order walk function duke@435: for( uint i=0; i<_max; i++ ) duke@435: if( in(i) ) // Input exists and is not walked? duke@435: in(i)->walk_(pre,post,env,visited); // Walk it with pre & post functions duke@435: post(*this,env); // Call the post-order walk function duke@435: } duke@435: duke@435: void Node::nop(Node &, void*) {} duke@435: duke@435: //------------------------------Registers-------------------------------------- duke@435: // Do we Match on this edge index or not? Generally false for Control duke@435: // and true for everything else. Weird for calls & returns. duke@435: uint Node::match_edge(uint idx) const { duke@435: return idx; // True for other than index 0 (control) duke@435: } duke@435: duke@435: // Register classes are defined for specific machines duke@435: const RegMask &Node::out_RegMask() const { duke@435: ShouldNotCallThis(); duke@435: return *(new RegMask()); duke@435: } duke@435: duke@435: const RegMask &Node::in_RegMask(uint) const { duke@435: ShouldNotCallThis(); duke@435: return *(new RegMask()); duke@435: } duke@435: duke@435: //============================================================================= duke@435: //----------------------------------------------------------------------------- duke@435: void Node_Array::reset( Arena *new_arena ) { duke@435: _a->Afree(_nodes,_max*sizeof(Node*)); duke@435: _max = 0; duke@435: _nodes = NULL; duke@435: _a = new_arena; duke@435: } duke@435: duke@435: //------------------------------clear------------------------------------------ duke@435: // Clear all entries in _nodes to NULL but keep storage duke@435: void Node_Array::clear() { duke@435: Copy::zero_to_bytes( _nodes, _max*sizeof(Node*) ); duke@435: } duke@435: duke@435: //----------------------------------------------------------------------------- duke@435: void Node_Array::grow( uint i ) { duke@435: if( !_max ) { duke@435: _max = 1; duke@435: _nodes = (Node**)_a->Amalloc( _max * sizeof(Node*) ); duke@435: _nodes[0] = NULL; duke@435: } duke@435: uint old = _max; duke@435: while( i >= _max ) _max <<= 1; // Double to fit duke@435: _nodes = (Node**)_a->Arealloc( _nodes, old*sizeof(Node*),_max*sizeof(Node*)); duke@435: Copy::zero_to_bytes( &_nodes[old], (_max-old)*sizeof(Node*) ); duke@435: } duke@435: duke@435: //----------------------------------------------------------------------------- duke@435: void Node_Array::insert( uint i, Node *n ) { duke@435: if( _nodes[_max-1] ) grow(_max); // Get more space if full duke@435: Copy::conjoint_words_to_higher((HeapWord*)&_nodes[i], (HeapWord*)&_nodes[i+1], ((_max-i-1)*sizeof(Node*))); duke@435: _nodes[i] = n; duke@435: } duke@435: duke@435: //----------------------------------------------------------------------------- duke@435: void Node_Array::remove( uint i ) { duke@435: Copy::conjoint_words_to_lower((HeapWord*)&_nodes[i+1], (HeapWord*)&_nodes[i], ((_max-i-1)*sizeof(Node*))); duke@435: _nodes[_max-1] = NULL; duke@435: } duke@435: duke@435: //----------------------------------------------------------------------------- duke@435: void Node_Array::sort( C_sort_func_t func) { duke@435: qsort( _nodes, _max, sizeof( Node* ), func ); duke@435: } duke@435: duke@435: //----------------------------------------------------------------------------- duke@435: void Node_Array::dump() const { duke@435: #ifndef PRODUCT duke@435: for( uint i = 0; i < _max; i++ ) { duke@435: Node *nn = _nodes[i]; duke@435: if( nn != NULL ) { duke@435: tty->print("%5d--> ",i); nn->dump(); duke@435: } duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: //--------------------------is_iteratively_computed------------------------------ duke@435: // Operation appears to be iteratively computed (such as an induction variable) duke@435: // It is possible for this operation to return false for a loop-varying duke@435: // value, if it appears (by local graph inspection) to be computed by a simple conditional. duke@435: bool Node::is_iteratively_computed() { duke@435: if (ideal_reg()) { // does operation have a result register? duke@435: for (uint i = 1; i < req(); i++) { duke@435: Node* n = in(i); duke@435: if (n != NULL && n->is_Phi()) { duke@435: for (uint j = 1; j < n->req(); j++) { duke@435: if (n->in(j) == this) { duke@435: return true; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: //--------------------------find_similar------------------------------ duke@435: // Return a node with opcode "opc" and same inputs as "this" if one can duke@435: // be found; Otherwise return NULL; duke@435: Node* Node::find_similar(int opc) { duke@435: if (req() >= 2) { duke@435: Node* def = in(1); duke@435: if (def && def->outcnt() >= 2) { duke@435: for (DUIterator_Fast dmax, i = def->fast_outs(dmax); i < dmax; i++) { duke@435: Node* use = def->fast_out(i); duke@435: if (use->Opcode() == opc && duke@435: use->req() == req()) { duke@435: uint j; duke@435: for (j = 0; j < use->req(); j++) { duke@435: if (use->in(j) != in(j)) { duke@435: break; duke@435: } duke@435: } duke@435: if (j == use->req()) { duke@435: return use; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: duke@435: //--------------------------unique_ctrl_out------------------------------ duke@435: // Return the unique control out if only one. Null if none or more than one. duke@435: Node* Node::unique_ctrl_out() { duke@435: Node* found = NULL; duke@435: for (uint i = 0; i < outcnt(); i++) { duke@435: Node* use = raw_out(i); duke@435: if (use->is_CFG() && use != this) { duke@435: if (found != NULL) return NULL; duke@435: found = use; duke@435: } duke@435: } duke@435: return found; duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------yank------------------------------------------- duke@435: // Find and remove duke@435: void Node_List::yank( Node *n ) { duke@435: uint i; duke@435: for( i = 0; i < _cnt; i++ ) duke@435: if( _nodes[i] == n ) duke@435: break; duke@435: duke@435: if( i < _cnt ) duke@435: _nodes[i] = _nodes[--_cnt]; duke@435: } duke@435: duke@435: //------------------------------dump------------------------------------------- duke@435: void Node_List::dump() const { duke@435: #ifndef PRODUCT duke@435: for( uint i = 0; i < _cnt; i++ ) duke@435: if( _nodes[i] ) { duke@435: tty->print("%5d--> ",i); duke@435: _nodes[i]->dump(); duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: //============================================================================= duke@435: //------------------------------remove----------------------------------------- duke@435: void Unique_Node_List::remove( Node *n ) { duke@435: if( _in_worklist[n->_idx] ) { duke@435: for( uint i = 0; i < size(); i++ ) duke@435: if( _nodes[i] == n ) { duke@435: map(i,Node_List::pop()); duke@435: _in_worklist >>= n->_idx; duke@435: return; duke@435: } duke@435: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: //-----------------------remove_useless_nodes---------------------------------- duke@435: // Remove useless nodes from worklist duke@435: void Unique_Node_List::remove_useless_nodes(VectorSet &useful) { duke@435: duke@435: for( uint i = 0; i < size(); ++i ) { duke@435: Node *n = at(i); duke@435: assert( n != NULL, "Did not expect null entries in worklist"); duke@435: if( ! useful.test(n->_idx) ) { duke@435: _in_worklist >>= n->_idx; duke@435: map(i,Node_List::pop()); duke@435: // Node *replacement = Node_List::pop(); duke@435: // if( i != size() ) { // Check if removing last entry duke@435: // _nodes[i] = replacement; duke@435: // } duke@435: --i; // Visit popped node duke@435: // If it was last entry, loop terminates since size() was also reduced duke@435: } duke@435: } duke@435: } duke@435: duke@435: //============================================================================= duke@435: void Node_Stack::grow() { duke@435: size_t old_top = pointer_delta(_inode_top,_inodes,sizeof(INode)); // save _top duke@435: size_t old_max = pointer_delta(_inode_max,_inodes,sizeof(INode)); duke@435: size_t max = old_max << 1; // max * 2 duke@435: _inodes = REALLOC_ARENA_ARRAY(_a, INode, _inodes, old_max, max); duke@435: _inode_max = _inodes + max; duke@435: _inode_top = _inodes + old_top; // restore _top duke@435: } duke@435: duke@435: //============================================================================= duke@435: uint TypeNode::size_of() const { return sizeof(*this); } duke@435: #ifndef PRODUCT duke@435: void TypeNode::dump_spec(outputStream *st) const { duke@435: if( !Verbose && !WizardMode ) { duke@435: // standard dump does this in Verbose and WizardMode duke@435: st->print(" #"); _type->dump_on(st); duke@435: } duke@435: } duke@435: #endif duke@435: uint TypeNode::hash() const { duke@435: return Node::hash() + _type->hash(); duke@435: } duke@435: uint TypeNode::cmp( const Node &n ) const duke@435: { return !Type::cmp( _type, ((TypeNode&)n)._type ); } duke@435: const Type *TypeNode::bottom_type() const { return _type; } duke@435: const Type *TypeNode::Value( PhaseTransform * ) const { return _type; } duke@435: duke@435: //------------------------------ideal_reg-------------------------------------- duke@435: uint TypeNode::ideal_reg() const { duke@435: return Matcher::base2reg[_type->base()]; duke@435: }