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