0N/A/*
2794N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 "memory/allocation.inline.hpp"
1879N/A#include "opto/block.hpp"
1879N/A#include "opto/callnode.hpp"
1879N/A#include "opto/cfgnode.hpp"
1879N/A#include "opto/connode.hpp"
1879N/A#include "opto/idealGraphPrinter.hpp"
1879N/A#include "opto/loopnode.hpp"
1879N/A#include "opto/machnode.hpp"
1879N/A#include "opto/opcodes.hpp"
1879N/A#include "opto/phaseX.hpp"
1879N/A#include "opto/regalloc.hpp"
1879N/A#include "opto/rootnode.hpp"
0N/A
0N/A//=============================================================================
0N/A#define NODE_HASH_MINIMUM_SIZE 255
0N/A//------------------------------NodeHash---------------------------------------
0N/ANodeHash::NodeHash(uint est_max_size) :
0N/A _max( round_up(est_max_size < NODE_HASH_MINIMUM_SIZE ? NODE_HASH_MINIMUM_SIZE : est_max_size) ),
0N/A _a(Thread::current()->resource_area()),
0N/A _table( NEW_ARENA_ARRAY( _a , Node* , _max ) ), // (Node**)_a->Amalloc(_max * sizeof(Node*)) ),
0N/A _inserts(0), _insert_limit( insert_limit() ),
0N/A _look_probes(0), _lookup_hits(0), _lookup_misses(0),
0N/A _total_insert_probes(0), _total_inserts(0),
0N/A _insert_probes(0), _grows(0) {
0N/A // _sentinel must be in the current node space
4022N/A _sentinel = new (Compile::current()) ProjNode(NULL, TypeFunc::Control);
0N/A memset(_table,0,sizeof(Node*)*_max);
0N/A}
0N/A
0N/A//------------------------------NodeHash---------------------------------------
0N/ANodeHash::NodeHash(Arena *arena, uint est_max_size) :
0N/A _max( round_up(est_max_size < NODE_HASH_MINIMUM_SIZE ? NODE_HASH_MINIMUM_SIZE : est_max_size) ),
0N/A _a(arena),
0N/A _table( NEW_ARENA_ARRAY( _a , Node* , _max ) ),
0N/A _inserts(0), _insert_limit( insert_limit() ),
0N/A _look_probes(0), _lookup_hits(0), _lookup_misses(0),
0N/A _delete_probes(0), _delete_hits(0), _delete_misses(0),
0N/A _total_insert_probes(0), _total_inserts(0),
0N/A _insert_probes(0), _grows(0) {
0N/A // _sentinel must be in the current node space
4022N/A _sentinel = new (Compile::current()) ProjNode(NULL, TypeFunc::Control);
0N/A memset(_table,0,sizeof(Node*)*_max);
0N/A}
0N/A
0N/A//------------------------------NodeHash---------------------------------------
0N/ANodeHash::NodeHash(NodeHash *nh) {
0N/A debug_only(_table = (Node**)badAddress); // interact correctly w/ operator=
0N/A // just copy in all the fields
0N/A *this = *nh;
0N/A // nh->_sentinel must be in the current node space
0N/A}
0N/A
4132N/Avoid NodeHash::replace_with(NodeHash *nh) {
4132N/A debug_only(_table = (Node**)badAddress); // interact correctly w/ operator=
4132N/A // just copy in all the fields
4132N/A *this = *nh;
4132N/A // nh->_sentinel must be in the current node space
4132N/A}
4132N/A
0N/A//------------------------------hash_find--------------------------------------
0N/A// Find in hash table
0N/ANode *NodeHash::hash_find( const Node *n ) {
0N/A // ((Node*)n)->set_hash( n->hash() );
0N/A uint hash = n->hash();
0N/A if (hash == Node::NO_HASH) {
0N/A debug_only( _lookup_misses++ );
0N/A return NULL;
0N/A }
0N/A uint key = hash & (_max-1);
0N/A uint stride = key | 0x01;
0N/A debug_only( _look_probes++ );
0N/A Node *k = _table[key]; // Get hashed value
0N/A if( !k ) { // ?Miss?
0N/A debug_only( _lookup_misses++ );
0N/A return NULL; // Miss!
0N/A }
0N/A
0N/A int op = n->Opcode();
0N/A uint req = n->req();
0N/A while( 1 ) { // While probing hash table
0N/A if( k->req() == req && // Same count of inputs
0N/A k->Opcode() == op ) { // Same Opcode
0N/A for( uint i=0; i<req; i++ )
0N/A if( n->in(i)!=k->in(i)) // Different inputs?
0N/A goto collision; // "goto" is a speed hack...
0N/A if( n->cmp(*k) ) { // Check for any special bits
0N/A debug_only( _lookup_hits++ );
0N/A return k; // Hit!
0N/A }
0N/A }
0N/A collision:
0N/A debug_only( _look_probes++ );
0N/A key = (key + stride/*7*/) & (_max-1); // Stride through table with relative prime
0N/A k = _table[key]; // Get hashed value
0N/A if( !k ) { // ?Miss?
0N/A debug_only( _lookup_misses++ );
0N/A return NULL; // Miss!
0N/A }
0N/A }
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
0N/A//------------------------------hash_find_insert-------------------------------
0N/A// Find in hash table, insert if not already present
0N/A// Used to preserve unique entries in hash table
0N/ANode *NodeHash::hash_find_insert( Node *n ) {
0N/A // n->set_hash( );
0N/A uint hash = n->hash();
0N/A if (hash == Node::NO_HASH) {
0N/A debug_only( _lookup_misses++ );
0N/A return NULL;
0N/A }
0N/A uint key = hash & (_max-1);
0N/A uint stride = key | 0x01; // stride must be relatively prime to table siz
0N/A uint first_sentinel = 0; // replace a sentinel if seen.
0N/A debug_only( _look_probes++ );
0N/A Node *k = _table[key]; // Get hashed value
0N/A if( !k ) { // ?Miss?
0N/A debug_only( _lookup_misses++ );
0N/A _table[key] = n; // Insert into table!
0N/A debug_only(n->enter_hash_lock()); // Lock down the node while in the table.
0N/A check_grow(); // Grow table if insert hit limit
0N/A return NULL; // Miss!
0N/A }
0N/A else if( k == _sentinel ) {
0N/A first_sentinel = key; // Can insert here
0N/A }
0N/A
0N/A int op = n->Opcode();
0N/A uint req = n->req();
0N/A while( 1 ) { // While probing hash table
0N/A if( k->req() == req && // Same count of inputs
0N/A k->Opcode() == op ) { // Same Opcode
0N/A for( uint i=0; i<req; i++ )
0N/A if( n->in(i)!=k->in(i)) // Different inputs?
0N/A goto collision; // "goto" is a speed hack...
0N/A if( n->cmp(*k) ) { // Check for any special bits
0N/A debug_only( _lookup_hits++ );
0N/A return k; // Hit!
0N/A }
0N/A }
0N/A collision:
0N/A debug_only( _look_probes++ );
0N/A key = (key + stride) & (_max-1); // Stride through table w/ relative prime
0N/A k = _table[key]; // Get hashed value
0N/A if( !k ) { // ?Miss?
0N/A debug_only( _lookup_misses++ );
0N/A key = (first_sentinel == 0) ? key : first_sentinel; // ?saw sentinel?
0N/A _table[key] = n; // Insert into table!
0N/A debug_only(n->enter_hash_lock()); // Lock down the node while in the table.
0N/A check_grow(); // Grow table if insert hit limit
0N/A return NULL; // Miss!
0N/A }
0N/A else if( first_sentinel == 0 && k == _sentinel ) {
0N/A first_sentinel = key; // Can insert here
0N/A }
0N/A
0N/A }
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
0N/A//------------------------------hash_insert------------------------------------
0N/A// Insert into hash table
0N/Avoid NodeHash::hash_insert( Node *n ) {
0N/A // // "conflict" comments -- print nodes that conflict
0N/A // bool conflict = false;
0N/A // n->set_hash();
0N/A uint hash = n->hash();
0N/A if (hash == Node::NO_HASH) {
0N/A return;
0N/A }
0N/A check_grow();
0N/A uint key = hash & (_max-1);
0N/A uint stride = key | 0x01;
0N/A
0N/A while( 1 ) { // While probing hash table
0N/A debug_only( _insert_probes++ );
0N/A Node *k = _table[key]; // Get hashed value
0N/A if( !k || (k == _sentinel) ) break; // Found a slot
0N/A assert( k != n, "already inserted" );
0N/A // if( PrintCompilation && PrintOptoStatistics && Verbose ) { tty->print(" conflict: "); k->dump(); conflict = true; }
0N/A key = (key + stride) & (_max-1); // Stride through table w/ relative prime
0N/A }
0N/A _table[key] = n; // Insert into table!
0N/A debug_only(n->enter_hash_lock()); // Lock down the node while in the table.
0N/A // if( conflict ) { n->dump(); }
0N/A}
0N/A
0N/A//------------------------------hash_delete------------------------------------
605N/A// Replace in hash table with sentinel
0N/Abool NodeHash::hash_delete( const Node *n ) {
0N/A Node *k;
0N/A uint hash = n->hash();
0N/A if (hash == Node::NO_HASH) {
0N/A debug_only( _delete_misses++ );
0N/A return false;
0N/A }
0N/A uint key = hash & (_max-1);
0N/A uint stride = key | 0x01;
0N/A debug_only( uint counter = 0; );
605N/A for( ; /* (k != NULL) && (k != _sentinel) */; ) {
0N/A debug_only( counter++ );
0N/A debug_only( _delete_probes++ );
0N/A k = _table[key]; // Get hashed value
0N/A if( !k ) { // Miss?
0N/A debug_only( _delete_misses++ );
0N/A#ifdef ASSERT
0N/A if( VerifyOpto ) {
0N/A for( uint i=0; i < _max; i++ )
0N/A assert( _table[i] != n, "changed edges with rehashing" );
0N/A }
0N/A#endif
0N/A return false; // Miss! Not in chain
0N/A }
0N/A else if( n == k ) {
0N/A debug_only( _delete_hits++ );
0N/A _table[key] = _sentinel; // Hit! Label as deleted entry
0N/A debug_only(((Node*)n)->exit_hash_lock()); // Unlock the node upon removal from table.
0N/A return true;
0N/A }
0N/A else {
0N/A // collision: move through table with prime offset
0N/A key = (key + stride/*7*/) & (_max-1);
0N/A assert( counter <= _insert_limit, "Cycle in hash-table");
0N/A }
0N/A }
0N/A ShouldNotReachHere();
0N/A return false;
0N/A}
0N/A
0N/A//------------------------------round_up---------------------------------------
0N/A// Round up to nearest power of 2
0N/Auint NodeHash::round_up( uint x ) {
0N/A x += (x>>2); // Add 25% slop
0N/A if( x <16 ) return 16; // Small stuff
0N/A uint i=16;
0N/A while( i < x ) i <<= 1; // Double to fit
0N/A return i; // Return hash table size
0N/A}
0N/A
0N/A//------------------------------grow-------------------------------------------
0N/A// Grow _table to next power of 2 and insert old entries
0N/Avoid NodeHash::grow() {
0N/A // Record old state
0N/A uint old_max = _max;
0N/A Node **old_table = _table;
0N/A // Construct new table with twice the space
0N/A _grows++;
0N/A _total_inserts += _inserts;
0N/A _total_insert_probes += _insert_probes;
0N/A _inserts = 0;
0N/A _insert_probes = 0;
0N/A _max = _max << 1;
0N/A _table = NEW_ARENA_ARRAY( _a , Node* , _max ); // (Node**)_a->Amalloc( _max * sizeof(Node*) );
0N/A memset(_table,0,sizeof(Node*)*_max);
0N/A _insert_limit = insert_limit();
0N/A // Insert old entries into the new table
0N/A for( uint i = 0; i < old_max; i++ ) {
0N/A Node *m = *old_table++;
0N/A if( !m || m == _sentinel ) continue;
0N/A debug_only(m->exit_hash_lock()); // Unlock the node upon removal from old table.
0N/A hash_insert(m);
0N/A }
0N/A}
0N/A
0N/A//------------------------------clear------------------------------------------
0N/A// Clear all entries in _table to NULL but keep storage
0N/Avoid NodeHash::clear() {
0N/A#ifdef ASSERT
0N/A // Unlock all nodes upon removal from table.
0N/A for (uint i = 0; i < _max; i++) {
0N/A Node* n = _table[i];
0N/A if (!n || n == _sentinel) continue;
0N/A n->exit_hash_lock();
0N/A }
0N/A#endif
0N/A
0N/A memset( _table, 0, _max * sizeof(Node*) );
0N/A}
0N/A
0N/A//-----------------------remove_useless_nodes----------------------------------
0N/A// Remove useless nodes from value table,
0N/A// implementation does not depend on hash function
0N/Avoid NodeHash::remove_useless_nodes(VectorSet &useful) {
0N/A
0N/A // Dead nodes in the hash table inherited from GVN should not replace
0N/A // existing nodes, remove dead nodes.
0N/A uint max = size();
0N/A Node *sentinel_node = sentinel();
0N/A for( uint i = 0; i < max; ++i ) {
0N/A Node *n = at(i);
0N/A if(n != NULL && n != sentinel_node && !useful.test(n->_idx)) {
0N/A debug_only(n->exit_hash_lock()); // Unlock the node when removed
0N/A _table[i] = sentinel_node; // Replace with placeholder
0N/A }
0N/A }
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/A//------------------------------dump-------------------------------------------
0N/A// Dump statistics for the hash table
0N/Avoid NodeHash::dump() {
0N/A _total_inserts += _inserts;
0N/A _total_insert_probes += _insert_probes;
2902N/A if (PrintCompilation && PrintOptoStatistics && Verbose && (_inserts > 0)) {
2902N/A if (WizardMode) {
2902N/A for (uint i=0; i<_max; i++) {
2902N/A if (_table[i])
2902N/A tty->print("%d/%d/%d ",i,_table[i]->hash()&(_max-1),_table[i]->_idx);
2902N/A }
0N/A }
0N/A tty->print("\nGVN Hash stats: %d grows to %d max_size\n", _grows, _max);
0N/A tty->print(" %d/%d (%8.1f%% full)\n", _inserts, _max, (double)_inserts/_max*100.0);
0N/A tty->print(" %dp/(%dh+%dm) (%8.2f probes/lookup)\n", _look_probes, _lookup_hits, _lookup_misses, (double)_look_probes/(_lookup_hits+_lookup_misses));
0N/A tty->print(" %dp/%di (%8.2f probes/insert)\n", _total_insert_probes, _total_inserts, (double)_total_insert_probes/_total_inserts);
0N/A // sentinels increase lookup cost, but not insert cost
0N/A assert((_lookup_misses+_lookup_hits)*4+100 >= _look_probes, "bad hash function");
0N/A assert( _inserts+(_inserts>>3) < _max, "table too full" );
0N/A assert( _inserts*3+100 >= _insert_probes, "bad hash function" );
0N/A }
0N/A}
0N/A
0N/ANode *NodeHash::find_index(uint idx) { // For debugging
0N/A // Find an entry by its index value
0N/A for( uint i = 0; i < _max; i++ ) {
0N/A Node *m = _table[i];
0N/A if( !m || m == _sentinel ) continue;
0N/A if( m->_idx == (uint)idx ) return m;
0N/A }
0N/A return NULL;
0N/A}
0N/A#endif
0N/A
0N/A#ifdef ASSERT
0N/ANodeHash::~NodeHash() {
0N/A // Unlock all nodes upon destruction of table.
0N/A if (_table != (Node**)badAddress) clear();
0N/A}
0N/A
0N/Avoid NodeHash::operator=(const NodeHash& nh) {
0N/A // Unlock all nodes upon replacement of table.
0N/A if (&nh == this) return;
0N/A if (_table != (Node**)badAddress) clear();
0N/A memcpy(this, &nh, sizeof(*this));
0N/A // Do not increment hash_lock counts again.
0N/A // Instead, be sure we never again use the source table.
0N/A ((NodeHash*)&nh)->_table = (Node**)badAddress;
0N/A}
0N/A
0N/A
0N/A#endif
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------PhaseRemoveUseless-----------------------------
0N/A// 1) Use a breadthfirst walk to collect useful nodes reachable from root.
0N/APhaseRemoveUseless::PhaseRemoveUseless( PhaseGVN *gvn, Unique_Node_List *worklist ) : Phase(Remove_Useless),
0N/A _useful(Thread::current()->resource_area()) {
0N/A
0N/A // Implementation requires 'UseLoopSafepoints == true' and an edge from root
0N/A // to each SafePointNode at a backward branch. Inserted in add_safepoint().
0N/A if( !UseLoopSafepoints || !OptoRemoveUseless ) return;
0N/A
0N/A // Identify nodes that are reachable from below, useful.
0N/A C->identify_useful_nodes(_useful);
4123N/A // Update dead node list
4123N/A C->update_dead_node_list(_useful);
0N/A
0N/A // Remove all useless nodes from PhaseValues' recorded types
0N/A // Must be done before disconnecting nodes to preserve hash-table-invariant
0N/A gvn->remove_useless_nodes(_useful.member_set());
0N/A
0N/A // Remove all useless nodes from future worklist
0N/A worklist->remove_useless_nodes(_useful.member_set());
0N/A
0N/A // Disconnect 'useless' nodes that are adjacent to useful nodes
0N/A C->remove_useless_nodes(_useful);
0N/A
0N/A // Remove edges from "root" to each SafePoint at a backward branch.
0N/A // They were inserted during parsing (see add_safepoint()) to make infinite
0N/A // loops without calls or exceptions visible to root, i.e., useful.
0N/A Node *root = C->root();
0N/A if( root != NULL ) {
0N/A for( uint i = root->req(); i < root->len(); ++i ) {
0N/A Node *n = root->in(i);
0N/A if( n != NULL && n->is_SafePoint() ) {
0N/A root->rm_prec(i);
0N/A --i;
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------PhaseTransform---------------------------------
0N/APhaseTransform::PhaseTransform( PhaseNumber pnum ) : Phase(pnum),
0N/A _arena(Thread::current()->resource_area()),
0N/A _nodes(_arena),
0N/A _types(_arena)
0N/A{
0N/A init_con_caches();
0N/A#ifndef PRODUCT
0N/A clear_progress();
0N/A clear_transforms();
0N/A set_allow_progress(true);
0N/A#endif
0N/A // Force allocation for currently existing nodes
0N/A _types.map(C->unique(), NULL);
0N/A}
0N/A
0N/A//------------------------------PhaseTransform---------------------------------
0N/APhaseTransform::PhaseTransform( Arena *arena, PhaseNumber pnum ) : Phase(pnum),
0N/A _arena(arena),
0N/A _nodes(arena),
0N/A _types(arena)
0N/A{
0N/A init_con_caches();
0N/A#ifndef PRODUCT
0N/A clear_progress();
0N/A clear_transforms();
0N/A set_allow_progress(true);
0N/A#endif
0N/A // Force allocation for currently existing nodes
0N/A _types.map(C->unique(), NULL);
0N/A}
0N/A
0N/A//------------------------------PhaseTransform---------------------------------
0N/A// Initialize with previously generated type information
0N/APhaseTransform::PhaseTransform( PhaseTransform *pt, PhaseNumber pnum ) : Phase(pnum),
0N/A _arena(pt->_arena),
0N/A _nodes(pt->_nodes),
0N/A _types(pt->_types)
0N/A{
0N/A init_con_caches();
0N/A#ifndef PRODUCT
0N/A clear_progress();
0N/A clear_transforms();
0N/A set_allow_progress(true);
0N/A#endif
0N/A}
0N/A
0N/Avoid PhaseTransform::init_con_caches() {
0N/A memset(_icons,0,sizeof(_icons));
0N/A memset(_lcons,0,sizeof(_lcons));
0N/A memset(_zcons,0,sizeof(_zcons));
0N/A}
0N/A
0N/A
0N/A//--------------------------------find_int_type--------------------------------
0N/Aconst TypeInt* PhaseTransform::find_int_type(Node* n) {
0N/A if (n == NULL) return NULL;
0N/A // Call type_or_null(n) to determine node's type since we might be in
0N/A // parse phase and call n->Value() may return wrong type.
0N/A // (For example, a phi node at the beginning of loop parsing is not ready.)
0N/A const Type* t = type_or_null(n);
0N/A if (t == NULL) return NULL;
0N/A return t->isa_int();
0N/A}
0N/A
0N/A
0N/A//-------------------------------find_long_type--------------------------------
0N/Aconst TypeLong* PhaseTransform::find_long_type(Node* n) {
0N/A if (n == NULL) return NULL;
0N/A // (See comment above on type_or_null.)
0N/A const Type* t = type_or_null(n);
0N/A if (t == NULL) return NULL;
0N/A return t->isa_long();
0N/A}
0N/A
0N/A
0N/A#ifndef PRODUCT
0N/Avoid PhaseTransform::dump_old2new_map() const {
0N/A _nodes.dump();
0N/A}
0N/A
0N/Avoid PhaseTransform::dump_new( uint nidx ) const {
0N/A for( uint i=0; i<_nodes.Size(); i++ )
0N/A if( _nodes[i] && _nodes[i]->_idx == nidx ) {
0N/A _nodes[i]->dump();
0N/A tty->cr();
0N/A tty->print_cr("Old index= %d",i);
0N/A return;
0N/A }
0N/A tty->print_cr("Node %d not found in the new indices", nidx);
0N/A}
0N/A
0N/A//------------------------------dump_types-------------------------------------
0N/Avoid PhaseTransform::dump_types( ) const {
0N/A _types.dump();
0N/A}
0N/A
0N/A//------------------------------dump_nodes_and_types---------------------------
0N/Avoid PhaseTransform::dump_nodes_and_types(const Node *root, uint depth, bool only_ctrl) {
0N/A VectorSet visited(Thread::current()->resource_area());
0N/A dump_nodes_and_types_recur( root, depth, only_ctrl, visited );
0N/A}
0N/A
0N/A//------------------------------dump_nodes_and_types_recur---------------------
0N/Avoid PhaseTransform::dump_nodes_and_types_recur( const Node *n, uint depth, bool only_ctrl, VectorSet &visited) {
0N/A if( !n ) return;
0N/A if( depth == 0 ) return;
0N/A if( visited.test_set(n->_idx) ) return;
0N/A for( uint i=0; i<n->len(); i++ ) {
0N/A if( only_ctrl && !(n->is_Region()) && i != TypeFunc::Control ) continue;
0N/A dump_nodes_and_types_recur( n->in(i), depth-1, only_ctrl, visited );
0N/A }
0N/A n->dump();
0N/A if (type_or_null(n) != NULL) {
0N/A tty->print(" "); type(n)->dump(); tty->cr();
0N/A }
0N/A}
0N/A
0N/A#endif
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------PhaseValues------------------------------------
0N/A// Set minimum table size to "255"
0N/APhaseValues::PhaseValues( Arena *arena, uint est_max_size ) : PhaseTransform(arena, GVN), _table(arena, est_max_size) {
0N/A NOT_PRODUCT( clear_new_values(); )
0N/A}
0N/A
0N/A//------------------------------PhaseValues------------------------------------
0N/A// Set minimum table size to "255"
0N/APhaseValues::PhaseValues( PhaseValues *ptv ) : PhaseTransform( ptv, GVN ),
0N/A _table(&ptv->_table) {
0N/A NOT_PRODUCT( clear_new_values(); )
0N/A}
0N/A
0N/A//------------------------------PhaseValues------------------------------------
0N/A// Used by +VerifyOpto. Clear out hash table but copy _types array.
0N/APhaseValues::PhaseValues( PhaseValues *ptv, const char *dummy ) : PhaseTransform( ptv, GVN ),
0N/A _table(ptv->arena(),ptv->_table.size()) {
0N/A NOT_PRODUCT( clear_new_values(); )
0N/A}
0N/A
0N/A//------------------------------~PhaseValues-----------------------------------
0N/A#ifndef PRODUCT
0N/APhaseValues::~PhaseValues() {
0N/A _table.dump();
0N/A
0N/A // Statistics for value progress and efficiency
0N/A if( PrintCompilation && Verbose && WizardMode ) {
0N/A tty->print("\n%sValues: %d nodes ---> %d/%d (%d)",
0N/A is_IterGVN() ? "Iter" : " ", C->unique(), made_progress(), made_transforms(), made_new_values());
0N/A if( made_transforms() != 0 ) {
0N/A tty->print_cr(" ratio %f", made_progress()/(float)made_transforms() );
0N/A } else {
0N/A tty->cr();
0N/A }
0N/A }
0N/A}
0N/A#endif
0N/A
0N/A//------------------------------makecon----------------------------------------
0N/AConNode* PhaseTransform::makecon(const Type *t) {
0N/A assert(t->singleton(), "must be a constant");
0N/A assert(!t->empty() || t == Type::TOP, "must not be vacuous range");
0N/A switch (t->base()) { // fast paths
0N/A case Type::Half:
0N/A case Type::Top: return (ConNode*) C->top();
0N/A case Type::Int: return intcon( t->is_int()->get_con() );
0N/A case Type::Long: return longcon( t->is_long()->get_con() );
0N/A }
0N/A if (t->is_zero_type())
0N/A return zerocon(t->basic_type());
0N/A return uncached_makecon(t);
0N/A}
0N/A
0N/A//--------------------------uncached_makecon-----------------------------------
0N/A// Make an idealized constant - one of ConINode, ConPNode, etc.
0N/AConNode* PhaseValues::uncached_makecon(const Type *t) {
0N/A assert(t->singleton(), "must be a constant");
0N/A ConNode* x = ConNode::make(C, t);
0N/A ConNode* k = (ConNode*)hash_find_insert(x); // Value numbering
0N/A if (k == NULL) {
0N/A set_type(x, t); // Missed, provide type mapping
0N/A GrowableArray<Node_Notes*>* nna = C->node_note_array();
0N/A if (nna != NULL) {
0N/A Node_Notes* loc = C->locate_node_notes(nna, x->_idx, true);
0N/A loc->clear(); // do not put debug info on constants
0N/A }
0N/A } else {
0N/A x->destruct(); // Hit, destroy duplicate constant
0N/A x = k; // use existing constant
0N/A }
0N/A return x;
0N/A}
0N/A
0N/A//------------------------------intcon-----------------------------------------
0N/A// Fast integer constant. Same as "transform(new ConINode(TypeInt::make(i)))"
0N/AConINode* PhaseTransform::intcon(int i) {
0N/A // Small integer? Check cache! Check that cached node is not dead
0N/A if (i >= _icon_min && i <= _icon_max) {
0N/A ConINode* icon = _icons[i-_icon_min];
0N/A if (icon != NULL && icon->in(TypeFunc::Control) != NULL)
0N/A return icon;
0N/A }
0N/A ConINode* icon = (ConINode*) uncached_makecon(TypeInt::make(i));
0N/A assert(icon->is_Con(), "");
0N/A if (i >= _icon_min && i <= _icon_max)
0N/A _icons[i-_icon_min] = icon; // Cache small integers
0N/A return icon;
0N/A}
0N/A
0N/A//------------------------------longcon----------------------------------------
0N/A// Fast long constant.
0N/AConLNode* PhaseTransform::longcon(jlong l) {
0N/A // Small integer? Check cache! Check that cached node is not dead
0N/A if (l >= _lcon_min && l <= _lcon_max) {
0N/A ConLNode* lcon = _lcons[l-_lcon_min];
0N/A if (lcon != NULL && lcon->in(TypeFunc::Control) != NULL)
0N/A return lcon;
0N/A }
0N/A ConLNode* lcon = (ConLNode*) uncached_makecon(TypeLong::make(l));
0N/A assert(lcon->is_Con(), "");
0N/A if (l >= _lcon_min && l <= _lcon_max)
0N/A _lcons[l-_lcon_min] = lcon; // Cache small integers
0N/A return lcon;
0N/A}
0N/A
0N/A//------------------------------zerocon-----------------------------------------
0N/A// Fast zero or null constant. Same as "transform(ConNode::make(Type::get_zero_type(bt)))"
0N/AConNode* PhaseTransform::zerocon(BasicType bt) {
0N/A assert((uint)bt <= _zcon_max, "domain check");
0N/A ConNode* zcon = _zcons[bt];
0N/A if (zcon != NULL && zcon->in(TypeFunc::Control) != NULL)
0N/A return zcon;
0N/A zcon = (ConNode*) uncached_makecon(Type::get_zero_type(bt));
0N/A _zcons[bt] = zcon;
0N/A return zcon;
0N/A}
0N/A
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------transform--------------------------------------
0N/A// Return a node which computes the same function as this node, but in a
41N/A// faster or cheaper fashion.
0N/ANode *PhaseGVN::transform( Node *n ) {
41N/A return transform_no_reclaim(n);
0N/A}
0N/A
0N/A//------------------------------transform--------------------------------------
0N/A// Return a node which computes the same function as this node, but
0N/A// in a faster or cheaper fashion.
0N/ANode *PhaseGVN::transform_no_reclaim( Node *n ) {
0N/A NOT_PRODUCT( set_transforms(); )
0N/A
0N/A // Apply the Ideal call in a loop until it no longer applies
0N/A Node *k = n;
0N/A NOT_PRODUCT( uint loop_count = 0; )
0N/A while( 1 ) {
0N/A Node *i = k->Ideal(this, /*can_reshape=*/false);
0N/A if( !i ) break;
0N/A assert( i->_idx >= k->_idx, "Idealize should return new nodes, use Identity to return old nodes" );
0N/A k = i;
0N/A assert(loop_count++ < K, "infinite loop in PhaseGVN::transform");
0N/A }
0N/A NOT_PRODUCT( if( loop_count != 0 ) { set_progress(); } )
0N/A
0N/A
0N/A // If brand new node, make space in type array.
0N/A ensure_type_or_null(k);
0N/A
0N/A // Since I just called 'Value' to compute the set of run-time values
0N/A // for this Node, and 'Value' is non-local (and therefore expensive) I'll
0N/A // cache Value. Later requests for the local phase->type of this Node can
0N/A // use the cached Value instead of suffering with 'bottom_type'.
0N/A const Type *t = k->Value(this); // Get runtime Value set
0N/A assert(t != NULL, "value sanity");
0N/A if (type_or_null(k) != t) {
0N/A#ifndef PRODUCT
0N/A // Do not count initial visit to node as a transformation
0N/A if (type_or_null(k) == NULL) {
0N/A inc_new_values();
0N/A set_progress();
0N/A }
0N/A#endif
0N/A set_type(k, t);
0N/A // If k is a TypeNode, capture any more-precise type permanently into Node
0N/A k->raise_bottom_type(t);
0N/A }
0N/A
0N/A if( t->singleton() && !k->is_Con() ) {
0N/A NOT_PRODUCT( set_progress(); )
0N/A return makecon(t); // Turn into a constant
0N/A }
0N/A
0N/A // Now check for Identities
0N/A Node *i = k->Identity(this); // Look for a nearby replacement
0N/A if( i != k ) { // Found? Return replacement!
0N/A NOT_PRODUCT( set_progress(); )
0N/A return i;
0N/A }
0N/A
0N/A // Global Value Numbering
0N/A i = hash_find_insert(k); // Insert if new
0N/A if( i && (i != k) ) {
0N/A // Return the pre-existing node
0N/A NOT_PRODUCT( set_progress(); )
0N/A return i;
0N/A }
0N/A
0N/A // Return Idealized original
0N/A return k;
0N/A}
0N/A
0N/A#ifdef ASSERT
0N/A//------------------------------dead_loop_check--------------------------------
605N/A// Check for a simple dead loop when a data node references itself directly
0N/A// or through an other data node excluding cons and phis.
0N/Avoid PhaseGVN::dead_loop_check( Node *n ) {
0N/A // Phi may reference itself in a loop
0N/A if (n != NULL && !n->is_dead_loop_safe() && !n->is_CFG()) {
0N/A // Do 2 levels check and only data inputs.
0N/A bool no_dead_loop = true;
0N/A uint cnt = n->req();
0N/A for (uint i = 1; i < cnt && no_dead_loop; i++) {
0N/A Node *in = n->in(i);
0N/A if (in == n) {
0N/A no_dead_loop = false;
0N/A } else if (in != NULL && !in->is_dead_loop_safe()) {
0N/A uint icnt = in->req();
0N/A for (uint j = 1; j < icnt && no_dead_loop; j++) {
0N/A if (in->in(j) == n || in->in(j) == in)
0N/A no_dead_loop = false;
0N/A }
0N/A }
0N/A }
0N/A if (!no_dead_loop) n->dump(3);
0N/A assert(no_dead_loop, "dead loop detected");
0N/A }
0N/A}
0N/A#endif
0N/A
0N/A//=============================================================================
0N/A//------------------------------PhaseIterGVN-----------------------------------
0N/A// Initialize hash table to fresh and clean for +VerifyOpto
113N/APhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn, const char *dummy ) : PhaseGVN(igvn,dummy), _worklist( ),
3910N/A _stack(C->unique() >> 1),
113N/A _delay_transform(false) {
0N/A}
0N/A
0N/A//------------------------------PhaseIterGVN-----------------------------------
0N/A// Initialize with previous PhaseIterGVN info; used by PhaseCCP
0N/APhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn ) : PhaseGVN(igvn),
113N/A _worklist( igvn->_worklist ),
3910N/A _stack( igvn->_stack ),
113N/A _delay_transform(igvn->_delay_transform)
0N/A{
0N/A}
0N/A
0N/A//------------------------------PhaseIterGVN-----------------------------------
0N/A// Initialize with previous PhaseGVN info from Parser
0N/APhaseIterGVN::PhaseIterGVN( PhaseGVN *gvn ) : PhaseGVN(gvn),
113N/A _worklist(*C->for_igvn()),
3910N/A _stack(C->unique() >> 1),
113N/A _delay_transform(false)
0N/A{
0N/A uint max;
0N/A
0N/A // Dead nodes in the hash table inherited from GVN were not treated as
0N/A // roots during def-use info creation; hence they represent an invisible
0N/A // use. Clear them out.
0N/A max = _table.size();
0N/A for( uint i = 0; i < max; ++i ) {
0N/A Node *n = _table.at(i);
0N/A if(n != NULL && n != _table.sentinel() && n->outcnt() == 0) {
0N/A if( n->is_top() ) continue;
0N/A assert( false, "Parse::remove_useless_nodes missed this node");
0N/A hash_delete(n);
0N/A }
0N/A }
0N/A
0N/A // Any Phis or Regions on the worklist probably had uses that could not
0N/A // make more progress because the uses were made while the Phis and Regions
0N/A // were in half-built states. Put all uses of Phis and Regions on worklist.
0N/A max = _worklist.size();
0N/A for( uint j = 0; j < max; j++ ) {
0N/A Node *n = _worklist.at(j);
0N/A uint uop = n->Opcode();
0N/A if( uop == Op_Phi || uop == Op_Region ||
0N/A n->is_Type() ||
0N/A n->is_Mem() )
0N/A add_users_to_worklist(n);
0N/A }
0N/A}
0N/A
0N/A
0N/A#ifndef PRODUCT
0N/Avoid PhaseIterGVN::verify_step(Node* n) {
0N/A _verify_window[_verify_counter % _verify_window_size] = n;
0N/A ++_verify_counter;
0N/A ResourceMark rm;
0N/A ResourceArea *area = Thread::current()->resource_area();
0N/A VectorSet old_space(area), new_space(area);
0N/A if (C->unique() < 1000 ||
0N/A 0 == _verify_counter % (C->unique() < 10000 ? 10 : 100)) {
0N/A ++_verify_full_passes;
0N/A Node::verify_recur(C->root(), -1, old_space, new_space);
0N/A }
0N/A const int verify_depth = 4;
0N/A for ( int i = 0; i < _verify_window_size; i++ ) {
0N/A Node* n = _verify_window[i];
0N/A if ( n == NULL ) continue;
0N/A if( n->in(0) == NodeSentinel ) { // xform_idom
0N/A _verify_window[i] = n->in(1);
0N/A --i; continue;
0N/A }
0N/A // Typical fanout is 1-2, so this call visits about 6 nodes.
0N/A Node::verify_recur(n, verify_depth, old_space, new_space);
0N/A }
0N/A}
0N/A#endif
0N/A
0N/A
0N/A//------------------------------init_worklist----------------------------------
0N/A// Initialize worklist for each node.
0N/Avoid PhaseIterGVN::init_worklist( Node *n ) {
0N/A if( _worklist.member(n) ) return;
0N/A _worklist.push(n);
0N/A uint cnt = n->req();
0N/A for( uint i =0 ; i < cnt; i++ ) {
0N/A Node *m = n->in(i);
0N/A if( m ) init_worklist(m);
0N/A }
0N/A}
0N/A
0N/A//------------------------------optimize---------------------------------------
0N/Avoid PhaseIterGVN::optimize() {
0N/A debug_only(uint num_processed = 0;);
0N/A#ifndef PRODUCT
0N/A {
0N/A _verify_counter = 0;
0N/A _verify_full_passes = 0;
0N/A for ( int i = 0; i < _verify_window_size; i++ ) {
0N/A _verify_window[i] = NULL;
0N/A }
0N/A }
0N/A#endif
0N/A
1746N/A#ifdef ASSERT
1746N/A Node* prev = NULL;
1746N/A uint rep_cnt = 0;
1746N/A#endif
1746N/A uint loop_count = 0;
1746N/A
0N/A // Pull from worklist; transform node;
0N/A // If node has changed: update edge info and put uses on worklist.
0N/A while( _worklist.size() ) {
2794N/A if (C->check_node_count(NodeLimitFudgeFactor * 2,
2794N/A "out of nodes optimizing method")) {
2794N/A return;
2794N/A }
0N/A Node *n = _worklist.pop();
1746N/A if (++loop_count >= K * C->unique()) {
1746N/A debug_only(n->dump(4);)
1746N/A assert(false, "infinite loop in PhaseIterGVN::optimize");
1746N/A C->record_method_not_compilable("infinite loop in PhaseIterGVN::optimize");
1746N/A return;
1746N/A }
1746N/A#ifdef ASSERT
1746N/A if (n == prev) {
1746N/A if (++rep_cnt > 3) {
1746N/A n->dump(4);
1746N/A assert(false, "loop in Ideal transformation");
1746N/A }
1746N/A } else {
1746N/A rep_cnt = 0;
1746N/A }
1746N/A prev = n;
1746N/A#endif
0N/A if (TraceIterativeGVN && Verbose) {
0N/A tty->print(" Pop ");
0N/A NOT_PRODUCT( n->dump(); )
0N/A debug_only(if( (num_processed++ % 100) == 0 ) _worklist.print_set();)
0N/A }
0N/A
0N/A if (n->outcnt() != 0) {
0N/A
0N/A#ifndef PRODUCT
0N/A uint wlsize = _worklist.size();
0N/A const Type* oldtype = type_or_null(n);
0N/A#endif //PRODUCT
0N/A
0N/A Node *nn = transform_old(n);
0N/A
0N/A#ifndef PRODUCT
0N/A if (TraceIterativeGVN) {
0N/A const Type* newtype = type_or_null(n);
0N/A if (nn != n) {
0N/A // print old node
0N/A tty->print("< ");
0N/A if (oldtype != newtype && oldtype != NULL) {
0N/A oldtype->dump();
0N/A }
0N/A do { tty->print("\t"); } while (tty->position() < 16);
0N/A tty->print("<");
0N/A n->dump();
0N/A }
0N/A if (oldtype != newtype || nn != n) {
0N/A // print new node and/or new type
0N/A if (oldtype == NULL) {
0N/A tty->print("* ");
0N/A } else if (nn != n) {
0N/A tty->print("> ");
0N/A } else {
0N/A tty->print("= ");
0N/A }
0N/A if (newtype == NULL) {
0N/A tty->print("null");
0N/A } else {
0N/A newtype->dump();
0N/A }
0N/A do { tty->print("\t"); } while (tty->position() < 16);
0N/A nn->dump();
0N/A }
0N/A if (Verbose && wlsize < _worklist.size()) {
0N/A tty->print(" Push {");
0N/A while (wlsize != _worklist.size()) {
0N/A Node* pushed = _worklist.at(wlsize++);
0N/A tty->print(" %d", pushed->_idx);
0N/A }
0N/A tty->print_cr(" }");
0N/A }
0N/A }
0N/A if( VerifyIterativeGVN && nn != n ) {
0N/A verify_step((Node*) NULL); // ignore n, it might be subsumed
0N/A }
0N/A#endif
0N/A } else if (!n->is_top()) {
0N/A remove_dead_node(n);
0N/A }
0N/A }
0N/A
0N/A#ifndef PRODUCT
0N/A C->verify_graph_edges();
0N/A if( VerifyOpto && allow_progress() ) {
0N/A // Must turn off allow_progress to enable assert and break recursion
0N/A C->root()->verify();
0N/A { // Check if any progress was missed using IterGVN
0N/A // Def-Use info enables transformations not attempted in wash-pass
0N/A // e.g. Region/Phi cleanup, ...
0N/A // Null-check elision -- may not have reached fixpoint
0N/A // do not propagate to dominated nodes
0N/A ResourceMark rm;
0N/A PhaseIterGVN igvn2(this,"Verify"); // Fresh and clean!
0N/A // Fill worklist completely
0N/A igvn2.init_worklist(C->root());
0N/A
0N/A igvn2.set_allow_progress(false);
0N/A igvn2.optimize();
0N/A igvn2.set_allow_progress(true);
0N/A }
0N/A }
0N/A if ( VerifyIterativeGVN && PrintOpto ) {
0N/A if ( _verify_counter == _verify_full_passes )
0N/A tty->print_cr("VerifyIterativeGVN: %d transforms and verify passes",
0N/A _verify_full_passes);
0N/A else
0N/A tty->print_cr("VerifyIterativeGVN: %d transforms, %d full verify passes",
0N/A _verify_counter, _verify_full_passes);
0N/A }
0N/A#endif
0N/A}
0N/A
0N/A
0N/A//------------------register_new_node_with_optimizer---------------------------
0N/A// Register a new node with the optimizer. Update the types array, the def-use
0N/A// info. Put on worklist.
0N/ANode* PhaseIterGVN::register_new_node_with_optimizer(Node* n, Node* orig) {
0N/A set_type_bottom(n);
0N/A _worklist.push(n);
0N/A if (orig != NULL) C->copy_node_notes_to(n, orig);
0N/A return n;
0N/A}
0N/A
0N/A//------------------------------transform--------------------------------------
0N/A// Non-recursive: idealize Node 'n' with respect to its inputs and its value
0N/ANode *PhaseIterGVN::transform( Node *n ) {
113N/A if (_delay_transform) {
113N/A // Register the node but don't optimize for now
113N/A register_new_node_with_optimizer(n);
113N/A return n;
113N/A }
113N/A
0N/A // If brand new node, make space in type array, and give it a type.
0N/A ensure_type_or_null(n);
0N/A if (type_or_null(n) == NULL) {
0N/A set_type_bottom(n);
0N/A }
0N/A
0N/A return transform_old(n);
0N/A}
0N/A
0N/A//------------------------------transform_old----------------------------------
0N/ANode *PhaseIterGVN::transform_old( Node *n ) {
0N/A#ifndef PRODUCT
0N/A debug_only(uint loop_count = 0;);
0N/A set_transforms();
0N/A#endif
0N/A // Remove 'n' from hash table in case it gets modified
0N/A _table.hash_delete(n);
0N/A if( VerifyIterativeGVN ) {
0N/A assert( !_table.find_index(n->_idx), "found duplicate entry in table");
0N/A }
0N/A
0N/A // Apply the Ideal call in a loop until it no longer applies
0N/A Node *k = n;
0N/A DEBUG_ONLY(dead_loop_check(k);)
305N/A DEBUG_ONLY(bool is_new = (k->outcnt() == 0);)
0N/A Node *i = k->Ideal(this, /*can_reshape=*/true);
305N/A assert(i != k || is_new || i->outcnt() > 0, "don't return dead nodes");
0N/A#ifndef PRODUCT
0N/A if( VerifyIterativeGVN )
0N/A verify_step(k);
0N/A if( i && VerifyOpto ) {
0N/A if( !allow_progress() ) {
0N/A if (i->is_Add() && i->outcnt() == 1) {
0N/A // Switched input to left side because this is the only use
0N/A } else if( i->is_If() && (i->in(0) == NULL) ) {
0N/A // This IF is dead because it is dominated by an equivalent IF When
0N/A // dominating if changed, info is not propagated sparsely to 'this'
0N/A // Propagating this info further will spuriously identify other
0N/A // progress.
0N/A return i;
0N/A } else
0N/A set_progress();
0N/A } else
0N/A set_progress();
0N/A }
0N/A#endif
0N/A
0N/A while( i ) {
0N/A#ifndef PRODUCT
0N/A debug_only( if( loop_count >= K ) i->dump(4); )
0N/A assert(loop_count < K, "infinite loop in PhaseIterGVN::transform");
0N/A debug_only( loop_count++; )
0N/A#endif
0N/A assert((i->_idx >= k->_idx) || i->is_top(), "Idealize should return new nodes, use Identity to return old nodes");
0N/A // Made a change; put users of original Node on worklist
0N/A add_users_to_worklist( k );
0N/A // Replacing root of transform tree?
0N/A if( k != i ) {
0N/A // Make users of old Node now use new.
0N/A subsume_node( k, i );
0N/A k = i;
0N/A }
0N/A DEBUG_ONLY(dead_loop_check(k);)
0N/A // Try idealizing again
305N/A DEBUG_ONLY(is_new = (k->outcnt() == 0);)
0N/A i = k->Ideal(this, /*can_reshape=*/true);
305N/A assert(i != k || is_new || i->outcnt() > 0, "don't return dead nodes");
0N/A#ifndef PRODUCT
0N/A if( VerifyIterativeGVN )
0N/A verify_step(k);
0N/A if( i && VerifyOpto ) set_progress();
0N/A#endif
0N/A }
0N/A
0N/A // If brand new node, make space in type array.
0N/A ensure_type_or_null(k);
0N/A
0N/A // See what kind of values 'k' takes on at runtime
0N/A const Type *t = k->Value(this);
0N/A assert(t != NULL, "value sanity");
0N/A
0N/A // Since I just called 'Value' to compute the set of run-time values
0N/A // for this Node, and 'Value' is non-local (and therefore expensive) I'll
0N/A // cache Value. Later requests for the local phase->type of this Node can
0N/A // use the cached Value instead of suffering with 'bottom_type'.
0N/A if (t != type_or_null(k)) {
0N/A NOT_PRODUCT( set_progress(); )
0N/A NOT_PRODUCT( inc_new_values();)
0N/A set_type(k, t);
0N/A // If k is a TypeNode, capture any more-precise type permanently into Node
0N/A k->raise_bottom_type(t);
0N/A // Move users of node to worklist
0N/A add_users_to_worklist( k );
0N/A }
0N/A
0N/A // If 'k' computes a constant, replace it with a constant
0N/A if( t->singleton() && !k->is_Con() ) {
0N/A NOT_PRODUCT( set_progress(); )
0N/A Node *con = makecon(t); // Make a constant
0N/A add_users_to_worklist( k );
0N/A subsume_node( k, con ); // Everybody using k now uses con
0N/A return con;
0N/A }
0N/A
0N/A // Now check for Identities
0N/A i = k->Identity(this); // Look for a nearby replacement
0N/A if( i != k ) { // Found? Return replacement!
0N/A NOT_PRODUCT( set_progress(); )
0N/A add_users_to_worklist( k );
0N/A subsume_node( k, i ); // Everybody using k now uses i
0N/A return i;
0N/A }
0N/A
0N/A // Global Value Numbering
0N/A i = hash_find_insert(k); // Check for pre-existing node
0N/A if( i && (i != k) ) {
0N/A // Return the pre-existing node if it isn't dead
0N/A NOT_PRODUCT( set_progress(); )
0N/A add_users_to_worklist( k );
0N/A subsume_node( k, i ); // Everybody using k now uses i
0N/A return i;
0N/A }
0N/A
0N/A // Return Idealized original
0N/A return k;
0N/A}
0N/A
0N/A//---------------------------------saturate------------------------------------
0N/Aconst Type* PhaseIterGVN::saturate(const Type* new_type, const Type* old_type,
0N/A const Type* limit_type) const {
0N/A return new_type->narrow(old_type);
0N/A}
0N/A
0N/A//------------------------------remove_globally_dead_node----------------------
0N/A// Kill a globally dead Node. All uses are also globally dead and are
0N/A// aggressively trimmed.
0N/Avoid PhaseIterGVN::remove_globally_dead_node( Node *dead ) {
3910N/A enum DeleteProgress {
3910N/A PROCESS_INPUTS,
3910N/A PROCESS_OUTPUTS
3910N/A };
3910N/A assert(_stack.is_empty(), "not empty");
3910N/A _stack.push(dead, PROCESS_INPUTS);
3910N/A
3910N/A while (_stack.is_nonempty()) {
3910N/A dead = _stack.node();
3910N/A uint progress_state = _stack.index();
3910N/A assert(dead != C->root(), "killing root, eh?");
3910N/A assert(!dead->is_top(), "add check for top when pushing");
3910N/A NOT_PRODUCT( set_progress(); )
3910N/A if (progress_state == PROCESS_INPUTS) {
3910N/A // After following inputs, continue to outputs
3910N/A _stack.set_index(PROCESS_OUTPUTS);
3910N/A if (!dead->is_Con()) { // Don't kill cons but uses
3910N/A bool recurse = false;
3910N/A // Remove from hash table
3910N/A _table.hash_delete( dead );
3910N/A // Smash all inputs to 'dead', isolating him completely
4345N/A for (uint i = 0; i < dead->req(); i++) {
3910N/A Node *in = dead->in(i);
4345N/A if (in != NULL && in != C->top()) { // Points to something?
4345N/A int nrep = dead->replace_edge(in, NULL); // Kill edges
4345N/A assert((nrep > 0), "sanity");
4345N/A if (in->outcnt() == 0) { // Made input go dead?
3910N/A _stack.push(in, PROCESS_INPUTS); // Recursively remove
3910N/A recurse = true;
3910N/A } else if (in->outcnt() == 1 &&
3910N/A in->has_special_unique_user()) {
3910N/A _worklist.push(in->unique_out());
3910N/A } else if (in->outcnt() <= 2 && dead->is_Phi()) {
4345N/A if (in->Opcode() == Op_Region) {
3910N/A _worklist.push(in);
4345N/A } else if (in->is_Store()) {
3910N/A DUIterator_Fast imax, i = in->fast_outs(imax);
3910N/A _worklist.push(in->fast_out(i));
3910N/A i++;
4345N/A if (in->outcnt() == 2) {
3910N/A _worklist.push(in->fast_out(i));
3910N/A i++;
3910N/A }
3910N/A assert(!(i < imax), "sanity");
3910N/A }
0N/A }
4326N/A if (ReduceFieldZeroing && dead->is_Load() && i == MemNode::Memory &&
4326N/A in->is_Proj() && in->in(0) != NULL && in->in(0)->is_Initialize()) {
4326N/A // A Load that directly follows an InitializeNode is
4326N/A // going away. The Stores that follow are candidates
4326N/A // again to be captured by the InitializeNode.
4326N/A for (DUIterator_Fast jmax, j = in->fast_outs(jmax); j < jmax; j++) {
4326N/A Node *n = in->fast_out(j);
4326N/A if (n->is_Store()) {
4326N/A _worklist.push(n);
4326N/A }
4326N/A }
4326N/A }
4345N/A } // if (in != NULL && in != C->top())
4345N/A } // for (uint i = 0; i < dead->req(); i++)
3910N/A if (recurse) {
3910N/A continue;
3910N/A }
4345N/A } // if (!dead->is_Con())
4345N/A } // if (progress_state == PROCESS_INPUTS)
0N/A
3910N/A // Aggressively kill globally dead uses
3910N/A // (Rather than pushing all the outs at once, we push one at a time,
3910N/A // plus the parent to resume later, because of the indefinite number
3910N/A // of edge deletions per loop trip.)
3910N/A if (dead->outcnt() > 0) {
4345N/A // Recursively remove output edges
3910N/A _stack.push(dead->raw_out(0), PROCESS_INPUTS);
3910N/A } else {
4345N/A // Finished disconnecting all input and output edges.
3910N/A _stack.pop();
4345N/A // Remove dead node from iterative worklist
4345N/A _worklist.remove(dead);
4345N/A // Constant node that has no out-edges and has only one in-edge from
4345N/A // root is usually dead. However, sometimes reshaping walk makes
4345N/A // it reachable by adding use edges. So, we will NOT count Con nodes
4345N/A // as dead to be conservative about the dead node count at any
4345N/A // given time.
4345N/A if (!dead->is_Con()) {
4345N/A C->record_dead_node(dead->_idx);
4345N/A }
4345N/A if (dead->is_macro()) {
4345N/A C->remove_macro_node(dead);
4345N/A }
4345N/A if (dead->is_expensive()) {
4345N/A C->remove_expensive_node(dead);
4345N/A }
0N/A }
4345N/A } // while (_stack.is_nonempty())
0N/A}
0N/A
0N/A//------------------------------subsume_node-----------------------------------
0N/A// Remove users from node 'old' and add them to node 'nn'.
0N/Avoid PhaseIterGVN::subsume_node( Node *old, Node *nn ) {
0N/A assert( old != hash_find(old), "should already been removed" );
0N/A assert( old != C->top(), "cannot subsume top node");
0N/A // Copy debug or profile information to the new version:
0N/A C->copy_node_notes_to(nn, old);
0N/A // Move users of node 'old' to node 'nn'
0N/A for (DUIterator_Last imin, i = old->last_outs(imin); i >= imin; ) {
0N/A Node* use = old->last_out(i); // for each use...
0N/A // use might need re-hashing (but it won't if it's a new node)
0N/A bool is_in_table = _table.hash_delete( use );
0N/A // Update use-def info as well
0N/A // We remove all occurrences of old within use->in,
0N/A // so as to avoid rehashing any node more than once.
0N/A // The hash table probe swamps any outer loop overhead.
0N/A uint num_edges = 0;
0N/A for (uint jmax = use->len(), j = 0; j < jmax; j++) {
0N/A if (use->in(j) == old) {
0N/A use->set_req(j, nn);
0N/A ++num_edges;
0N/A }
0N/A }
0N/A // Insert into GVN hash table if unique
0N/A // If a duplicate, 'use' will be cleaned up when pulled off worklist
0N/A if( is_in_table ) {
0N/A hash_find_insert(use);
0N/A }
0N/A i -= num_edges; // we deleted 1 or more copies of this edge
0N/A }
0N/A
0N/A // Smash all inputs to 'old', isolating him completely
4022N/A Node *temp = new (C) Node(1);
0N/A temp->init_req(0,nn); // Add a use to nn to prevent him from dying
0N/A remove_dead_node( old );
0N/A temp->del_req(0); // Yank bogus edge
0N/A#ifndef PRODUCT
0N/A if( VerifyIterativeGVN ) {
0N/A for ( int i = 0; i < _verify_window_size; i++ ) {
0N/A if ( _verify_window[i] == old )
0N/A _verify_window[i] = nn;
0N/A }
0N/A }
0N/A#endif
0N/A _worklist.remove(temp); // this can be necessary
0N/A temp->destruct(); // reuse the _idx of this little guy
0N/A}
0N/A
0N/A//------------------------------add_users_to_worklist--------------------------
0N/Avoid PhaseIterGVN::add_users_to_worklist0( Node *n ) {
0N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
0N/A _worklist.push(n->fast_out(i)); // Push on worklist
0N/A }
0N/A}
0N/A
0N/Avoid PhaseIterGVN::add_users_to_worklist( Node *n ) {
0N/A add_users_to_worklist0(n);
0N/A
0N/A // Move users of node to worklist
0N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
0N/A Node* use = n->fast_out(i); // Get use
0N/A
0N/A if( use->is_Multi() || // Multi-definer? Push projs on worklist
0N/A use->is_Store() ) // Enable store/load same address
0N/A add_users_to_worklist0(use);
0N/A
0N/A // If we changed the receiver type to a call, we need to revisit
0N/A // the Catch following the call. It's looking for a non-NULL
0N/A // receiver to know when to enable the regular fall-through path
0N/A // in addition to the NullPtrException path.
0N/A if (use->is_CallDynamicJava() && n == use->in(TypeFunc::Parms)) {
0N/A Node* p = use->as_CallDynamicJava()->proj_out(TypeFunc::Control);
0N/A if (p != NULL) {
0N/A add_users_to_worklist0(p);
0N/A }
0N/A }
0N/A
0N/A if( use->is_Cmp() ) { // Enable CMP/BOOL optimization
0N/A add_users_to_worklist(use); // Put Bool on worklist
0N/A // Look for the 'is_x2logic' pattern: "x ? : 0 : 1" and put the
0N/A // phi merging either 0 or 1 onto the worklist
0N/A if (use->outcnt() > 0) {
0N/A Node* bol = use->raw_out(0);
0N/A if (bol->outcnt() > 0) {
0N/A Node* iff = bol->raw_out(0);
0N/A if (iff->outcnt() == 2) {
0N/A Node* ifproj0 = iff->raw_out(0);
0N/A Node* ifproj1 = iff->raw_out(1);
0N/A if (ifproj0->outcnt() > 0 && ifproj1->outcnt() > 0) {
0N/A Node* region0 = ifproj0->raw_out(0);
0N/A Node* region1 = ifproj1->raw_out(0);
0N/A if( region0 == region1 )
0N/A add_users_to_worklist0(region0);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A uint use_op = use->Opcode();
0N/A // If changed Cast input, check Phi users for simple cycles
65N/A if( use->is_ConstraintCast() || use->is_CheckCastPP() ) {
0N/A for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
0N/A Node* u = use->fast_out(i2);
0N/A if (u->is_Phi())
0N/A _worklist.push(u);
0N/A }
0N/A }
0N/A // If changed LShift inputs, check RShift users for useless sign-ext
0N/A if( use_op == Op_LShiftI ) {
0N/A for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
0N/A Node* u = use->fast_out(i2);
0N/A if (u->Opcode() == Op_RShiftI)
0N/A _worklist.push(u);
0N/A }
0N/A }
0N/A // If changed AddP inputs, check Stores for loop invariant
0N/A if( use_op == Op_AddP ) {
0N/A for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
0N/A Node* u = use->fast_out(i2);
0N/A if (u->is_Mem())
0N/A _worklist.push(u);
0N/A }
0N/A }
0N/A // If changed initialization activity, check dependent Stores
0N/A if (use_op == Op_Allocate || use_op == Op_AllocateArray) {
0N/A InitializeNode* init = use->as_Allocate()->initialization();
0N/A if (init != NULL) {
0N/A Node* imem = init->proj_out(TypeFunc::Memory);
0N/A if (imem != NULL) add_users_to_worklist0(imem);
0N/A }
0N/A }
0N/A if (use_op == Op_Initialize) {
0N/A Node* imem = use->as_Initialize()->proj_out(TypeFunc::Memory);
0N/A if (imem != NULL) add_users_to_worklist0(imem);
0N/A }
0N/A }
0N/A}
0N/A
0N/A//=============================================================================
0N/A#ifndef PRODUCT
0N/Auint PhaseCCP::_total_invokes = 0;
0N/Auint PhaseCCP::_total_constants = 0;
0N/A#endif
0N/A//------------------------------PhaseCCP---------------------------------------
0N/A// Conditional Constant Propagation, ala Wegman & Zadeck
0N/APhaseCCP::PhaseCCP( PhaseIterGVN *igvn ) : PhaseIterGVN(igvn) {
0N/A NOT_PRODUCT( clear_constants(); )
0N/A assert( _worklist.size() == 0, "" );
0N/A // Clear out _nodes from IterGVN. Must be clear to transform call.
0N/A _nodes.clear(); // Clear out from IterGVN
0N/A analyze();
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/A//------------------------------~PhaseCCP--------------------------------------
0N/APhaseCCP::~PhaseCCP() {
0N/A inc_invokes();
0N/A _total_constants += count_constants();
0N/A}
0N/A#endif
0N/A
0N/A
0N/A#ifdef ASSERT
0N/Astatic bool ccp_type_widens(const Type* t, const Type* t0) {
0N/A assert(t->meet(t0) == t, "Not monotonic");
0N/A switch (t->base() == t0->base() ? t->base() : Type::Top) {
0N/A case Type::Int:
0N/A assert(t0->isa_int()->_widen <= t->isa_int()->_widen, "widen increases");
0N/A break;
0N/A case Type::Long:
0N/A assert(t0->isa_long()->_widen <= t->isa_long()->_widen, "widen increases");
0N/A break;
0N/A }
0N/A return true;
0N/A}
0N/A#endif //ASSERT
0N/A
0N/A//------------------------------analyze----------------------------------------
0N/Avoid PhaseCCP::analyze() {
0N/A // Initialize all types to TOP, optimistic analysis
0N/A for (int i = C->unique() - 1; i >= 0; i--) {
0N/A _types.map(i,Type::TOP);
0N/A }
0N/A
0N/A // Push root onto worklist
0N/A Unique_Node_List worklist;
0N/A worklist.push(C->root());
0N/A
0N/A // Pull from worklist; compute new value; push changes out.
0N/A // This loop is the meat of CCP.
0N/A while( worklist.size() ) {
0N/A Node *n = worklist.pop();
0N/A const Type *t = n->Value(this);
0N/A if (t != type(n)) {
0N/A assert(ccp_type_widens(t, type(n)), "ccp type must widen");
0N/A#ifndef PRODUCT
0N/A if( TracePhaseCCP ) {
0N/A t->dump();
0N/A do { tty->print("\t"); } while (tty->position() < 16);
0N/A n->dump();
0N/A }
0N/A#endif
0N/A set_type(n, t);
0N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
0N/A Node* m = n->fast_out(i); // Get user
0N/A if( m->is_Region() ) { // New path to Region? Must recheck Phis too
0N/A for (DUIterator_Fast i2max, i2 = m->fast_outs(i2max); i2 < i2max; i2++) {
0N/A Node* p = m->fast_out(i2); // Propagate changes to uses
0N/A if( p->bottom_type() != type(p) ) // If not already bottomed out
0N/A worklist.push(p); // Propagate change to user
0N/A }
0N/A }
605N/A // If we changed the receiver type to a call, we need to revisit
0N/A // the Catch following the call. It's looking for a non-NULL
0N/A // receiver to know when to enable the regular fall-through path
0N/A // in addition to the NullPtrException path
0N/A if (m->is_Call()) {
0N/A for (DUIterator_Fast i2max, i2 = m->fast_outs(i2max); i2 < i2max; i2++) {
0N/A Node* p = m->fast_out(i2); // Propagate changes to uses
0N/A if (p->is_Proj() && p->as_Proj()->_con == TypeFunc::Control && p->outcnt() == 1)
0N/A worklist.push(p->unique_out());
0N/A }
0N/A }
0N/A if( m->bottom_type() != type(m) ) // If not already bottomed out
0N/A worklist.push(m); // Propagate change to user
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/A//------------------------------do_transform-----------------------------------
0N/A// Top level driver for the recursive transformer
0N/Avoid PhaseCCP::do_transform() {
0N/A // Correct leaves of new-space Nodes; they point to old-space.
0N/A C->set_root( transform(C->root())->as_Root() );
0N/A assert( C->top(), "missing TOP node" );
0N/A assert( C->root(), "missing root" );
0N/A}
0N/A
0N/A//------------------------------transform--------------------------------------
0N/A// Given a Node in old-space, clone him into new-space.
0N/A// Convert any of his old-space children into new-space children.
0N/ANode *PhaseCCP::transform( Node *n ) {
0N/A Node *new_node = _nodes[n->_idx]; // Check for transformed node
0N/A if( new_node != NULL )
0N/A return new_node; // Been there, done that, return old answer
0N/A new_node = transform_once(n); // Check for constant
0N/A _nodes.map( n->_idx, new_node ); // Flag as having been cloned
0N/A
0N/A // Allocate stack of size _nodes.Size()/2 to avoid frequent realloc
0N/A GrowableArray <Node *> trstack(C->unique() >> 1);
0N/A
0N/A trstack.push(new_node); // Process children of cloned node
0N/A while ( trstack.is_nonempty() ) {
0N/A Node *clone = trstack.pop();
0N/A uint cnt = clone->req();
0N/A for( uint i = 0; i < cnt; i++ ) { // For all inputs do
0N/A Node *input = clone->in(i);
0N/A if( input != NULL ) { // Ignore NULLs
0N/A Node *new_input = _nodes[input->_idx]; // Check for cloned input node
0N/A if( new_input == NULL ) {
0N/A new_input = transform_once(input); // Check for constant
0N/A _nodes.map( input->_idx, new_input );// Flag as having been cloned
0N/A trstack.push(new_input);
0N/A }
0N/A assert( new_input == clone->in(i), "insanity check");
0N/A }
0N/A }
0N/A }
0N/A return new_node;
0N/A}
0N/A
0N/A
0N/A//------------------------------transform_once---------------------------------
0N/A// For PhaseCCP, transformation is IDENTITY unless Node computed a constant.
0N/ANode *PhaseCCP::transform_once( Node *n ) {
0N/A const Type *t = type(n);
0N/A // Constant? Use constant Node instead
0N/A if( t->singleton() ) {
0N/A Node *nn = n; // Default is to return the original constant
0N/A if( t == Type::TOP ) {
0N/A // cache my top node on the Compile instance
0N/A if( C->cached_top_node() == NULL || C->cached_top_node()->in(0) == NULL ) {
0N/A C->set_cached_top_node( ConNode::make(C, Type::TOP) );
0N/A set_type(C->top(), Type::TOP);
0N/A }
0N/A nn = C->top();
0N/A }
0N/A if( !n->is_Con() ) {
0N/A if( t != Type::TOP ) {
0N/A nn = makecon(t); // ConNode::make(t);
0N/A NOT_PRODUCT( inc_constants(); )
0N/A } else if( n->is_Region() ) { // Unreachable region
0N/A // Note: nn == C->top()
0N/A n->set_req(0, NULL); // Cut selfreference
0N/A // Eagerly remove dead phis to avoid phis copies creation.
0N/A for (DUIterator i = n->outs(); n->has_out(i); i++) {
0N/A Node* m = n->out(i);
0N/A if( m->is_Phi() ) {
0N/A assert(type(m) == Type::TOP, "Unreachable region should not have live phis.");
1541N/A replace_node(m, nn);
0N/A --i; // deleted this phi; rescan starting with next position
0N/A }
0N/A }
0N/A }
1541N/A replace_node(n,nn); // Update DefUse edges for new constant
0N/A }
0N/A return nn;
0N/A }
0N/A
0N/A // If x is a TypeNode, capture any more-precise type permanently into Node
0N/A if (t != n->bottom_type()) {
0N/A hash_delete(n); // changing bottom type may force a rehash
0N/A n->raise_bottom_type(t);
0N/A _worklist.push(n); // n re-enters the hash table via the worklist
0N/A }
0N/A
0N/A // Idealize graph using DU info. Must clone() into new-space.
0N/A // DU info is generally used to show profitability, progress or safety
0N/A // (but generally not needed for correctness).
0N/A Node *nn = n->Ideal_DU_postCCP(this);
0N/A
0N/A // TEMPORARY fix to ensure that 2nd GVN pass eliminates NULL checks
0N/A switch( n->Opcode() ) {
0N/A case Op_FastLock: // Revisit FastLocks for lock coarsening
0N/A case Op_If:
0N/A case Op_CountedLoopEnd:
0N/A case Op_Region:
0N/A case Op_Loop:
0N/A case Op_CountedLoop:
0N/A case Op_Conv2B:
0N/A case Op_Opaque1:
0N/A case Op_Opaque2:
0N/A _worklist.push(n);
0N/A break;
0N/A default:
0N/A break;
0N/A }
0N/A if( nn ) {
0N/A _worklist.push(n);
0N/A // Put users of 'n' onto worklist for second igvn transform
0N/A add_users_to_worklist(n);
0N/A return nn;
0N/A }
0N/A
0N/A return n;
0N/A}
0N/A
0N/A//---------------------------------saturate------------------------------------
0N/Aconst Type* PhaseCCP::saturate(const Type* new_type, const Type* old_type,
0N/A const Type* limit_type) const {
1009N/A const Type* wide_type = new_type->widen(old_type, limit_type);
0N/A if (wide_type != new_type) { // did we widen?
0N/A // If so, we may have widened beyond the limit type. Clip it back down.
0N/A new_type = wide_type->filter(limit_type);
0N/A }
0N/A return new_type;
0N/A}
0N/A
0N/A//------------------------------print_statistics-------------------------------
0N/A#ifndef PRODUCT
0N/Avoid PhaseCCP::print_statistics() {
0N/A tty->print_cr("CCP: %d constants found: %d", _total_invokes, _total_constants);
0N/A}
0N/A#endif
0N/A
0N/A
0N/A//=============================================================================
0N/A#ifndef PRODUCT
0N/Auint PhasePeephole::_total_peepholes = 0;
0N/A#endif
0N/A//------------------------------PhasePeephole----------------------------------
0N/A// Conditional Constant Propagation, ala Wegman & Zadeck
0N/APhasePeephole::PhasePeephole( PhaseRegAlloc *regalloc, PhaseCFG &cfg )
0N/A : PhaseTransform(Peephole), _regalloc(regalloc), _cfg(cfg) {
0N/A NOT_PRODUCT( clear_peepholes(); )
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/A//------------------------------~PhasePeephole---------------------------------
0N/APhasePeephole::~PhasePeephole() {
0N/A _total_peepholes += count_peepholes();
0N/A}
0N/A#endif
0N/A
0N/A//------------------------------transform--------------------------------------
0N/ANode *PhasePeephole::transform( Node *n ) {
0N/A ShouldNotCallThis();
0N/A return NULL;
0N/A}
0N/A
0N/A//------------------------------do_transform-----------------------------------
0N/Avoid PhasePeephole::do_transform() {
0N/A bool method_name_not_printed = true;
0N/A
0N/A // Examine each basic block
0N/A for( uint block_number = 1; block_number < _cfg._num_blocks; ++block_number ) {
0N/A Block *block = _cfg._blocks[block_number];
0N/A bool block_not_printed = true;
0N/A
0N/A // and each instruction within a block
0N/A uint end_index = block->_nodes.size();
0N/A // block->end_idx() not valid after PhaseRegAlloc
0N/A for( uint instruction_index = 1; instruction_index < end_index; ++instruction_index ) {
0N/A Node *n = block->_nodes.at(instruction_index);
0N/A if( n->is_Mach() ) {
0N/A MachNode *m = n->as_Mach();
0N/A int deleted_count = 0;
0N/A // check for peephole opportunities
0N/A MachNode *m2 = m->peephole( block, instruction_index, _regalloc, deleted_count, C );
0N/A if( m2 != NULL ) {
0N/A#ifndef PRODUCT
0N/A if( PrintOptoPeephole ) {
0N/A // Print method, first time only
0N/A if( C->method() && method_name_not_printed ) {
0N/A C->method()->print_short_name(); tty->cr();
0N/A method_name_not_printed = false;
0N/A }
0N/A // Print this block
0N/A if( Verbose && block_not_printed) {
0N/A tty->print_cr("in block");
0N/A block->dump();
0N/A block_not_printed = false;
0N/A }
0N/A // Print instructions being deleted
0N/A for( int i = (deleted_count - 1); i >= 0; --i ) {
0N/A block->_nodes.at(instruction_index-i)->as_Mach()->format(_regalloc); tty->cr();
0N/A }
0N/A tty->print_cr("replaced with");
0N/A // Print new instruction
0N/A m2->format(_regalloc);
0N/A tty->print("\n\n");
0N/A }
0N/A#endif
0N/A // Remove old nodes from basic block and update instruction_index
0N/A // (old nodes still exist and may have edges pointing to them
0N/A // as register allocation info is stored in the allocator using
0N/A // the node index to live range mappings.)
0N/A uint safe_instruction_index = (instruction_index - deleted_count);
0N/A for( ; (instruction_index > safe_instruction_index); --instruction_index ) {
0N/A block->_nodes.remove( instruction_index );
0N/A }
0N/A // install new node after safe_instruction_index
0N/A block->_nodes.insert( safe_instruction_index + 1, m2 );
0N/A end_index = block->_nodes.size() - 1; // Recompute new block size
0N/A NOT_PRODUCT( inc_peepholes(); )
0N/A }
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/A//------------------------------print_statistics-------------------------------
0N/A#ifndef PRODUCT
0N/Avoid PhasePeephole::print_statistics() {
0N/A tty->print_cr("Peephole: peephole rules applied: %d", _total_peepholes);
0N/A}
0N/A#endif
0N/A
0N/A
0N/A//=============================================================================
0N/A//------------------------------set_req_X--------------------------------------
0N/Avoid Node::set_req_X( uint i, Node *n, PhaseIterGVN *igvn ) {
0N/A assert( is_not_dead(n), "can not use dead node");
0N/A assert( igvn->hash_find(this) != this, "Need to remove from hash before changing edges" );
0N/A Node *old = in(i);
0N/A set_req(i, n);
0N/A
0N/A // old goes dead?
0N/A if( old ) {
0N/A switch (old->outcnt()) {
927N/A case 0:
927N/A // Put into the worklist to kill later. We do not kill it now because the
927N/A // recursive kill will delete the current node (this) if dead-loop exists
0N/A if (!old->is_top())
927N/A igvn->_worklist.push( old );
0N/A break;
0N/A case 1:
0N/A if( old->is_Store() || old->has_special_unique_user() )
0N/A igvn->add_users_to_worklist( old );
0N/A break;
0N/A case 2:
0N/A if( old->is_Store() )
0N/A igvn->add_users_to_worklist( old );
0N/A if( old->Opcode() == Op_Region )
0N/A igvn->_worklist.push(old);
0N/A break;
0N/A case 3:
0N/A if( old->Opcode() == Op_Region ) {
0N/A igvn->_worklist.push(old);
0N/A igvn->add_users_to_worklist( old );
0N/A }
0N/A break;
0N/A default:
0N/A break;
0N/A }
0N/A }
0N/A
0N/A}
0N/A
0N/A//-------------------------------replace_by-----------------------------------
0N/A// Using def-use info, replace one node for another. Follow the def-use info
0N/A// to all users of the OLD node. Then make all uses point to the NEW node.
0N/Avoid Node::replace_by(Node *new_node) {
0N/A assert(!is_top(), "top node has no DU info");
0N/A for (DUIterator_Last imin, i = last_outs(imin); i >= imin; ) {
0N/A Node* use = last_out(i);
0N/A uint uses_found = 0;
0N/A for (uint j = 0; j < use->len(); j++) {
0N/A if (use->in(j) == this) {
0N/A if (j < use->req())
0N/A use->set_req(j, new_node);
0N/A else use->set_prec(j, new_node);
0N/A uses_found++;
0N/A }
0N/A }
0N/A i -= uses_found; // we deleted 1 or more copies of this edge
0N/A }
0N/A}
0N/A
0N/A//=============================================================================
0N/A//-----------------------------------------------------------------------------
0N/Avoid Type_Array::grow( uint i ) {
0N/A if( !_max ) {
0N/A _max = 1;
0N/A _types = (const Type**)_a->Amalloc( _max * sizeof(Type*) );
0N/A _types[0] = NULL;
0N/A }
0N/A uint old = _max;
0N/A while( i >= _max ) _max <<= 1; // Double to fit
0N/A _types = (const Type**)_a->Arealloc( _types, old*sizeof(Type*),_max*sizeof(Type*));
0N/A memset( &_types[old], 0, (_max-old)*sizeof(Type*) );
0N/A}
0N/A
0N/A//------------------------------dump-------------------------------------------
0N/A#ifndef PRODUCT
0N/Avoid Type_Array::dump() const {
0N/A uint max = Size();
0N/A for( uint i = 0; i < max; i++ ) {
0N/A if( _types[i] != NULL ) {
0N/A tty->print(" %d\t== ", i); _types[i]->dump(); tty->cr();
0N/A }
0N/A }
0N/A}
0N/A#endif