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