Mon, 25 May 2020 14:24:27 +0800
8244407: JVM crashes after transformation in C2 IdealLoopTree::split_fall_in
Reviewed-by: thartmann, kvn, andrew
Contributed-by: zhouyong44@huawei.com
duke@435 | 1 | /* |
shshahma@8893 | 2 | * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "memory/allocation.inline.hpp" |
stefank@2314 | 27 | #include "opto/block.hpp" |
stefank@2314 | 28 | #include "opto/callnode.hpp" |
stefank@2314 | 29 | #include "opto/cfgnode.hpp" |
stefank@2314 | 30 | #include "opto/connode.hpp" |
stefank@2314 | 31 | #include "opto/idealGraphPrinter.hpp" |
stefank@2314 | 32 | #include "opto/loopnode.hpp" |
stefank@2314 | 33 | #include "opto/machnode.hpp" |
stefank@2314 | 34 | #include "opto/opcodes.hpp" |
stefank@2314 | 35 | #include "opto/phaseX.hpp" |
stefank@2314 | 36 | #include "opto/regalloc.hpp" |
stefank@2314 | 37 | #include "opto/rootnode.hpp" |
duke@435 | 38 | |
duke@435 | 39 | //============================================================================= |
duke@435 | 40 | #define NODE_HASH_MINIMUM_SIZE 255 |
duke@435 | 41 | //------------------------------NodeHash--------------------------------------- |
duke@435 | 42 | NodeHash::NodeHash(uint est_max_size) : |
duke@435 | 43 | _max( round_up(est_max_size < NODE_HASH_MINIMUM_SIZE ? NODE_HASH_MINIMUM_SIZE : est_max_size) ), |
duke@435 | 44 | _a(Thread::current()->resource_area()), |
duke@435 | 45 | _table( NEW_ARENA_ARRAY( _a , Node* , _max ) ), // (Node**)_a->Amalloc(_max * sizeof(Node*)) ), |
duke@435 | 46 | _inserts(0), _insert_limit( insert_limit() ), |
duke@435 | 47 | _look_probes(0), _lookup_hits(0), _lookup_misses(0), |
duke@435 | 48 | _total_insert_probes(0), _total_inserts(0), |
duke@435 | 49 | _insert_probes(0), _grows(0) { |
duke@435 | 50 | // _sentinel must be in the current node space |
kvn@4115 | 51 | _sentinel = new (Compile::current()) ProjNode(NULL, TypeFunc::Control); |
duke@435 | 52 | memset(_table,0,sizeof(Node*)*_max); |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | //------------------------------NodeHash--------------------------------------- |
duke@435 | 56 | NodeHash::NodeHash(Arena *arena, uint est_max_size) : |
duke@435 | 57 | _max( round_up(est_max_size < NODE_HASH_MINIMUM_SIZE ? NODE_HASH_MINIMUM_SIZE : est_max_size) ), |
duke@435 | 58 | _a(arena), |
duke@435 | 59 | _table( NEW_ARENA_ARRAY( _a , Node* , _max ) ), |
duke@435 | 60 | _inserts(0), _insert_limit( insert_limit() ), |
duke@435 | 61 | _look_probes(0), _lookup_hits(0), _lookup_misses(0), |
duke@435 | 62 | _delete_probes(0), _delete_hits(0), _delete_misses(0), |
duke@435 | 63 | _total_insert_probes(0), _total_inserts(0), |
duke@435 | 64 | _insert_probes(0), _grows(0) { |
duke@435 | 65 | // _sentinel must be in the current node space |
kvn@4115 | 66 | _sentinel = new (Compile::current()) ProjNode(NULL, TypeFunc::Control); |
duke@435 | 67 | memset(_table,0,sizeof(Node*)*_max); |
duke@435 | 68 | } |
duke@435 | 69 | |
duke@435 | 70 | //------------------------------NodeHash--------------------------------------- |
duke@435 | 71 | NodeHash::NodeHash(NodeHash *nh) { |
duke@435 | 72 | debug_only(_table = (Node**)badAddress); // interact correctly w/ operator= |
duke@435 | 73 | // just copy in all the fields |
duke@435 | 74 | *this = *nh; |
duke@435 | 75 | // nh->_sentinel must be in the current node space |
duke@435 | 76 | } |
duke@435 | 77 | |
roland@4409 | 78 | void NodeHash::replace_with(NodeHash *nh) { |
roland@4409 | 79 | debug_only(_table = (Node**)badAddress); // interact correctly w/ operator= |
roland@4409 | 80 | // just copy in all the fields |
roland@4409 | 81 | *this = *nh; |
roland@4409 | 82 | // nh->_sentinel must be in the current node space |
roland@4409 | 83 | } |
roland@4409 | 84 | |
duke@435 | 85 | //------------------------------hash_find-------------------------------------- |
duke@435 | 86 | // Find in hash table |
duke@435 | 87 | Node *NodeHash::hash_find( const Node *n ) { |
duke@435 | 88 | // ((Node*)n)->set_hash( n->hash() ); |
duke@435 | 89 | uint hash = n->hash(); |
duke@435 | 90 | if (hash == Node::NO_HASH) { |
duke@435 | 91 | debug_only( _lookup_misses++ ); |
duke@435 | 92 | return NULL; |
duke@435 | 93 | } |
duke@435 | 94 | uint key = hash & (_max-1); |
duke@435 | 95 | uint stride = key | 0x01; |
duke@435 | 96 | debug_only( _look_probes++ ); |
duke@435 | 97 | Node *k = _table[key]; // Get hashed value |
duke@435 | 98 | if( !k ) { // ?Miss? |
duke@435 | 99 | debug_only( _lookup_misses++ ); |
duke@435 | 100 | return NULL; // Miss! |
duke@435 | 101 | } |
duke@435 | 102 | |
duke@435 | 103 | int op = n->Opcode(); |
duke@435 | 104 | uint req = n->req(); |
duke@435 | 105 | while( 1 ) { // While probing hash table |
duke@435 | 106 | if( k->req() == req && // Same count of inputs |
duke@435 | 107 | k->Opcode() == op ) { // Same Opcode |
duke@435 | 108 | for( uint i=0; i<req; i++ ) |
duke@435 | 109 | if( n->in(i)!=k->in(i)) // Different inputs? |
duke@435 | 110 | goto collision; // "goto" is a speed hack... |
duke@435 | 111 | if( n->cmp(*k) ) { // Check for any special bits |
duke@435 | 112 | debug_only( _lookup_hits++ ); |
duke@435 | 113 | return k; // Hit! |
duke@435 | 114 | } |
duke@435 | 115 | } |
duke@435 | 116 | collision: |
duke@435 | 117 | debug_only( _look_probes++ ); |
duke@435 | 118 | key = (key + stride/*7*/) & (_max-1); // Stride through table with relative prime |
duke@435 | 119 | k = _table[key]; // Get hashed value |
duke@435 | 120 | if( !k ) { // ?Miss? |
duke@435 | 121 | debug_only( _lookup_misses++ ); |
duke@435 | 122 | return NULL; // Miss! |
duke@435 | 123 | } |
duke@435 | 124 | } |
duke@435 | 125 | ShouldNotReachHere(); |
duke@435 | 126 | return NULL; |
duke@435 | 127 | } |
duke@435 | 128 | |
duke@435 | 129 | //------------------------------hash_find_insert------------------------------- |
duke@435 | 130 | // Find in hash table, insert if not already present |
duke@435 | 131 | // Used to preserve unique entries in hash table |
duke@435 | 132 | Node *NodeHash::hash_find_insert( Node *n ) { |
duke@435 | 133 | // n->set_hash( ); |
duke@435 | 134 | uint hash = n->hash(); |
duke@435 | 135 | if (hash == Node::NO_HASH) { |
duke@435 | 136 | debug_only( _lookup_misses++ ); |
duke@435 | 137 | return NULL; |
duke@435 | 138 | } |
duke@435 | 139 | uint key = hash & (_max-1); |
duke@435 | 140 | uint stride = key | 0x01; // stride must be relatively prime to table siz |
duke@435 | 141 | uint first_sentinel = 0; // replace a sentinel if seen. |
duke@435 | 142 | debug_only( _look_probes++ ); |
duke@435 | 143 | Node *k = _table[key]; // Get hashed value |
duke@435 | 144 | if( !k ) { // ?Miss? |
duke@435 | 145 | debug_only( _lookup_misses++ ); |
duke@435 | 146 | _table[key] = n; // Insert into table! |
duke@435 | 147 | debug_only(n->enter_hash_lock()); // Lock down the node while in the table. |
duke@435 | 148 | check_grow(); // Grow table if insert hit limit |
duke@435 | 149 | return NULL; // Miss! |
duke@435 | 150 | } |
duke@435 | 151 | else if( k == _sentinel ) { |
duke@435 | 152 | first_sentinel = key; // Can insert here |
duke@435 | 153 | } |
duke@435 | 154 | |
duke@435 | 155 | int op = n->Opcode(); |
duke@435 | 156 | uint req = n->req(); |
duke@435 | 157 | while( 1 ) { // While probing hash table |
duke@435 | 158 | if( k->req() == req && // Same count of inputs |
duke@435 | 159 | k->Opcode() == op ) { // Same Opcode |
duke@435 | 160 | for( uint i=0; i<req; i++ ) |
duke@435 | 161 | if( n->in(i)!=k->in(i)) // Different inputs? |
duke@435 | 162 | goto collision; // "goto" is a speed hack... |
duke@435 | 163 | if( n->cmp(*k) ) { // Check for any special bits |
duke@435 | 164 | debug_only( _lookup_hits++ ); |
duke@435 | 165 | return k; // Hit! |
duke@435 | 166 | } |
duke@435 | 167 | } |
duke@435 | 168 | collision: |
duke@435 | 169 | debug_only( _look_probes++ ); |
duke@435 | 170 | key = (key + stride) & (_max-1); // Stride through table w/ relative prime |
duke@435 | 171 | k = _table[key]; // Get hashed value |
duke@435 | 172 | if( !k ) { // ?Miss? |
duke@435 | 173 | debug_only( _lookup_misses++ ); |
duke@435 | 174 | key = (first_sentinel == 0) ? key : first_sentinel; // ?saw sentinel? |
duke@435 | 175 | _table[key] = n; // Insert into table! |
duke@435 | 176 | debug_only(n->enter_hash_lock()); // Lock down the node while in the table. |
duke@435 | 177 | check_grow(); // Grow table if insert hit limit |
duke@435 | 178 | return NULL; // Miss! |
duke@435 | 179 | } |
duke@435 | 180 | else if( first_sentinel == 0 && k == _sentinel ) { |
duke@435 | 181 | first_sentinel = key; // Can insert here |
duke@435 | 182 | } |
duke@435 | 183 | |
duke@435 | 184 | } |
duke@435 | 185 | ShouldNotReachHere(); |
duke@435 | 186 | return NULL; |
duke@435 | 187 | } |
duke@435 | 188 | |
duke@435 | 189 | //------------------------------hash_insert------------------------------------ |
duke@435 | 190 | // Insert into hash table |
duke@435 | 191 | void NodeHash::hash_insert( Node *n ) { |
duke@435 | 192 | // // "conflict" comments -- print nodes that conflict |
duke@435 | 193 | // bool conflict = false; |
duke@435 | 194 | // n->set_hash(); |
duke@435 | 195 | uint hash = n->hash(); |
duke@435 | 196 | if (hash == Node::NO_HASH) { |
duke@435 | 197 | return; |
duke@435 | 198 | } |
duke@435 | 199 | check_grow(); |
duke@435 | 200 | uint key = hash & (_max-1); |
duke@435 | 201 | uint stride = key | 0x01; |
duke@435 | 202 | |
duke@435 | 203 | while( 1 ) { // While probing hash table |
duke@435 | 204 | debug_only( _insert_probes++ ); |
duke@435 | 205 | Node *k = _table[key]; // Get hashed value |
duke@435 | 206 | if( !k || (k == _sentinel) ) break; // Found a slot |
duke@435 | 207 | assert( k != n, "already inserted" ); |
duke@435 | 208 | // if( PrintCompilation && PrintOptoStatistics && Verbose ) { tty->print(" conflict: "); k->dump(); conflict = true; } |
duke@435 | 209 | key = (key + stride) & (_max-1); // Stride through table w/ relative prime |
duke@435 | 210 | } |
duke@435 | 211 | _table[key] = n; // Insert into table! |
duke@435 | 212 | debug_only(n->enter_hash_lock()); // Lock down the node while in the table. |
duke@435 | 213 | // if( conflict ) { n->dump(); } |
duke@435 | 214 | } |
duke@435 | 215 | |
duke@435 | 216 | //------------------------------hash_delete------------------------------------ |
twisti@1040 | 217 | // Replace in hash table with sentinel |
duke@435 | 218 | bool NodeHash::hash_delete( const Node *n ) { |
duke@435 | 219 | Node *k; |
duke@435 | 220 | uint hash = n->hash(); |
duke@435 | 221 | if (hash == Node::NO_HASH) { |
duke@435 | 222 | debug_only( _delete_misses++ ); |
duke@435 | 223 | return false; |
duke@435 | 224 | } |
duke@435 | 225 | uint key = hash & (_max-1); |
duke@435 | 226 | uint stride = key | 0x01; |
duke@435 | 227 | debug_only( uint counter = 0; ); |
twisti@1040 | 228 | for( ; /* (k != NULL) && (k != _sentinel) */; ) { |
duke@435 | 229 | debug_only( counter++ ); |
duke@435 | 230 | debug_only( _delete_probes++ ); |
duke@435 | 231 | k = _table[key]; // Get hashed value |
duke@435 | 232 | if( !k ) { // Miss? |
duke@435 | 233 | debug_only( _delete_misses++ ); |
duke@435 | 234 | #ifdef ASSERT |
duke@435 | 235 | if( VerifyOpto ) { |
duke@435 | 236 | for( uint i=0; i < _max; i++ ) |
duke@435 | 237 | assert( _table[i] != n, "changed edges with rehashing" ); |
duke@435 | 238 | } |
duke@435 | 239 | #endif |
duke@435 | 240 | return false; // Miss! Not in chain |
duke@435 | 241 | } |
duke@435 | 242 | else if( n == k ) { |
duke@435 | 243 | debug_only( _delete_hits++ ); |
duke@435 | 244 | _table[key] = _sentinel; // Hit! Label as deleted entry |
duke@435 | 245 | debug_only(((Node*)n)->exit_hash_lock()); // Unlock the node upon removal from table. |
duke@435 | 246 | return true; |
duke@435 | 247 | } |
duke@435 | 248 | else { |
duke@435 | 249 | // collision: move through table with prime offset |
duke@435 | 250 | key = (key + stride/*7*/) & (_max-1); |
duke@435 | 251 | assert( counter <= _insert_limit, "Cycle in hash-table"); |
duke@435 | 252 | } |
duke@435 | 253 | } |
duke@435 | 254 | ShouldNotReachHere(); |
duke@435 | 255 | return false; |
duke@435 | 256 | } |
duke@435 | 257 | |
duke@435 | 258 | //------------------------------round_up--------------------------------------- |
duke@435 | 259 | // Round up to nearest power of 2 |
duke@435 | 260 | uint NodeHash::round_up( uint x ) { |
duke@435 | 261 | x += (x>>2); // Add 25% slop |
duke@435 | 262 | if( x <16 ) return 16; // Small stuff |
duke@435 | 263 | uint i=16; |
duke@435 | 264 | while( i < x ) i <<= 1; // Double to fit |
duke@435 | 265 | return i; // Return hash table size |
duke@435 | 266 | } |
duke@435 | 267 | |
duke@435 | 268 | //------------------------------grow------------------------------------------- |
duke@435 | 269 | // Grow _table to next power of 2 and insert old entries |
duke@435 | 270 | void NodeHash::grow() { |
duke@435 | 271 | // Record old state |
duke@435 | 272 | uint old_max = _max; |
duke@435 | 273 | Node **old_table = _table; |
duke@435 | 274 | // Construct new table with twice the space |
duke@435 | 275 | _grows++; |
duke@435 | 276 | _total_inserts += _inserts; |
duke@435 | 277 | _total_insert_probes += _insert_probes; |
duke@435 | 278 | _inserts = 0; |
duke@435 | 279 | _insert_probes = 0; |
duke@435 | 280 | _max = _max << 1; |
duke@435 | 281 | _table = NEW_ARENA_ARRAY( _a , Node* , _max ); // (Node**)_a->Amalloc( _max * sizeof(Node*) ); |
duke@435 | 282 | memset(_table,0,sizeof(Node*)*_max); |
duke@435 | 283 | _insert_limit = insert_limit(); |
duke@435 | 284 | // Insert old entries into the new table |
duke@435 | 285 | for( uint i = 0; i < old_max; i++ ) { |
duke@435 | 286 | Node *m = *old_table++; |
duke@435 | 287 | if( !m || m == _sentinel ) continue; |
duke@435 | 288 | debug_only(m->exit_hash_lock()); // Unlock the node upon removal from old table. |
duke@435 | 289 | hash_insert(m); |
duke@435 | 290 | } |
duke@435 | 291 | } |
duke@435 | 292 | |
duke@435 | 293 | //------------------------------clear------------------------------------------ |
duke@435 | 294 | // Clear all entries in _table to NULL but keep storage |
duke@435 | 295 | void NodeHash::clear() { |
duke@435 | 296 | #ifdef ASSERT |
duke@435 | 297 | // Unlock all nodes upon removal from table. |
duke@435 | 298 | for (uint i = 0; i < _max; i++) { |
duke@435 | 299 | Node* n = _table[i]; |
duke@435 | 300 | if (!n || n == _sentinel) continue; |
duke@435 | 301 | n->exit_hash_lock(); |
duke@435 | 302 | } |
duke@435 | 303 | #endif |
duke@435 | 304 | |
duke@435 | 305 | memset( _table, 0, _max * sizeof(Node*) ); |
duke@435 | 306 | } |
duke@435 | 307 | |
duke@435 | 308 | //-----------------------remove_useless_nodes---------------------------------- |
duke@435 | 309 | // Remove useless nodes from value table, |
duke@435 | 310 | // implementation does not depend on hash function |
duke@435 | 311 | void NodeHash::remove_useless_nodes(VectorSet &useful) { |
duke@435 | 312 | |
duke@435 | 313 | // Dead nodes in the hash table inherited from GVN should not replace |
duke@435 | 314 | // existing nodes, remove dead nodes. |
duke@435 | 315 | uint max = size(); |
duke@435 | 316 | Node *sentinel_node = sentinel(); |
duke@435 | 317 | for( uint i = 0; i < max; ++i ) { |
duke@435 | 318 | Node *n = at(i); |
duke@435 | 319 | if(n != NULL && n != sentinel_node && !useful.test(n->_idx)) { |
duke@435 | 320 | debug_only(n->exit_hash_lock()); // Unlock the node when removed |
duke@435 | 321 | _table[i] = sentinel_node; // Replace with placeholder |
duke@435 | 322 | } |
duke@435 | 323 | } |
duke@435 | 324 | } |
duke@435 | 325 | |
roland@6313 | 326 | |
roland@6313 | 327 | void NodeHash::check_no_speculative_types() { |
roland@6313 | 328 | #ifdef ASSERT |
roland@6313 | 329 | uint max = size(); |
roland@6313 | 330 | Node *sentinel_node = sentinel(); |
roland@6313 | 331 | for (uint i = 0; i < max; ++i) { |
roland@6313 | 332 | Node *n = at(i); |
roland@6313 | 333 | if(n != NULL && n != sentinel_node && n->is_Type()) { |
roland@6313 | 334 | TypeNode* tn = n->as_Type(); |
roland@6313 | 335 | const Type* t = tn->type(); |
roland@6313 | 336 | const Type* t_no_spec = t->remove_speculative(); |
roland@6313 | 337 | assert(t == t_no_spec, "dead node in hash table or missed node during speculative cleanup"); |
roland@6313 | 338 | } |
roland@6313 | 339 | } |
roland@6313 | 340 | #endif |
roland@6313 | 341 | } |
roland@6313 | 342 | |
duke@435 | 343 | #ifndef PRODUCT |
duke@435 | 344 | //------------------------------dump------------------------------------------- |
duke@435 | 345 | // Dump statistics for the hash table |
duke@435 | 346 | void NodeHash::dump() { |
duke@435 | 347 | _total_inserts += _inserts; |
duke@435 | 348 | _total_insert_probes += _insert_probes; |
kvn@3260 | 349 | if (PrintCompilation && PrintOptoStatistics && Verbose && (_inserts > 0)) { |
kvn@3260 | 350 | if (WizardMode) { |
kvn@3260 | 351 | for (uint i=0; i<_max; i++) { |
kvn@3260 | 352 | if (_table[i]) |
kvn@3260 | 353 | tty->print("%d/%d/%d ",i,_table[i]->hash()&(_max-1),_table[i]->_idx); |
kvn@3260 | 354 | } |
duke@435 | 355 | } |
duke@435 | 356 | tty->print("\nGVN Hash stats: %d grows to %d max_size\n", _grows, _max); |
duke@435 | 357 | tty->print(" %d/%d (%8.1f%% full)\n", _inserts, _max, (double)_inserts/_max*100.0); |
duke@435 | 358 | 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 | 359 | tty->print(" %dp/%di (%8.2f probes/insert)\n", _total_insert_probes, _total_inserts, (double)_total_insert_probes/_total_inserts); |
duke@435 | 360 | // sentinels increase lookup cost, but not insert cost |
duke@435 | 361 | assert((_lookup_misses+_lookup_hits)*4+100 >= _look_probes, "bad hash function"); |
duke@435 | 362 | assert( _inserts+(_inserts>>3) < _max, "table too full" ); |
duke@435 | 363 | assert( _inserts*3+100 >= _insert_probes, "bad hash function" ); |
duke@435 | 364 | } |
duke@435 | 365 | } |
duke@435 | 366 | |
duke@435 | 367 | Node *NodeHash::find_index(uint idx) { // For debugging |
duke@435 | 368 | // Find an entry by its index value |
duke@435 | 369 | for( uint i = 0; i < _max; i++ ) { |
duke@435 | 370 | Node *m = _table[i]; |
duke@435 | 371 | if( !m || m == _sentinel ) continue; |
duke@435 | 372 | if( m->_idx == (uint)idx ) return m; |
duke@435 | 373 | } |
duke@435 | 374 | return NULL; |
duke@435 | 375 | } |
duke@435 | 376 | #endif |
duke@435 | 377 | |
duke@435 | 378 | #ifdef ASSERT |
duke@435 | 379 | NodeHash::~NodeHash() { |
duke@435 | 380 | // Unlock all nodes upon destruction of table. |
duke@435 | 381 | if (_table != (Node**)badAddress) clear(); |
duke@435 | 382 | } |
duke@435 | 383 | |
duke@435 | 384 | void NodeHash::operator=(const NodeHash& nh) { |
duke@435 | 385 | // Unlock all nodes upon replacement of table. |
duke@435 | 386 | if (&nh == this) return; |
duke@435 | 387 | if (_table != (Node**)badAddress) clear(); |
duke@435 | 388 | memcpy(this, &nh, sizeof(*this)); |
duke@435 | 389 | // Do not increment hash_lock counts again. |
duke@435 | 390 | // Instead, be sure we never again use the source table. |
duke@435 | 391 | ((NodeHash*)&nh)->_table = (Node**)badAddress; |
duke@435 | 392 | } |
duke@435 | 393 | |
duke@435 | 394 | |
duke@435 | 395 | #endif |
duke@435 | 396 | |
duke@435 | 397 | |
duke@435 | 398 | //============================================================================= |
duke@435 | 399 | //------------------------------PhaseRemoveUseless----------------------------- |
duke@435 | 400 | // 1) Use a breadthfirst walk to collect useful nodes reachable from root. |
zmajo@8193 | 401 | PhaseRemoveUseless::PhaseRemoveUseless(PhaseGVN *gvn, Unique_Node_List *worklist, PhaseNumber phase_num) : Phase(phase_num), |
duke@435 | 402 | _useful(Thread::current()->resource_area()) { |
duke@435 | 403 | |
duke@435 | 404 | // Implementation requires 'UseLoopSafepoints == true' and an edge from root |
duke@435 | 405 | // to each SafePointNode at a backward branch. Inserted in add_safepoint(). |
duke@435 | 406 | if( !UseLoopSafepoints || !OptoRemoveUseless ) return; |
duke@435 | 407 | |
duke@435 | 408 | // Identify nodes that are reachable from below, useful. |
duke@435 | 409 | C->identify_useful_nodes(_useful); |
bharadwaj@4315 | 410 | // Update dead node list |
bharadwaj@4315 | 411 | C->update_dead_node_list(_useful); |
duke@435 | 412 | |
duke@435 | 413 | // Remove all useless nodes from PhaseValues' recorded types |
duke@435 | 414 | // Must be done before disconnecting nodes to preserve hash-table-invariant |
duke@435 | 415 | gvn->remove_useless_nodes(_useful.member_set()); |
duke@435 | 416 | |
duke@435 | 417 | // Remove all useless nodes from future worklist |
duke@435 | 418 | worklist->remove_useless_nodes(_useful.member_set()); |
duke@435 | 419 | |
duke@435 | 420 | // Disconnect 'useless' nodes that are adjacent to useful nodes |
duke@435 | 421 | C->remove_useless_nodes(_useful); |
duke@435 | 422 | |
duke@435 | 423 | // Remove edges from "root" to each SafePoint at a backward branch. |
duke@435 | 424 | // They were inserted during parsing (see add_safepoint()) to make infinite |
duke@435 | 425 | // loops without calls or exceptions visible to root, i.e., useful. |
duke@435 | 426 | Node *root = C->root(); |
duke@435 | 427 | if( root != NULL ) { |
duke@435 | 428 | for( uint i = root->req(); i < root->len(); ++i ) { |
duke@435 | 429 | Node *n = root->in(i); |
duke@435 | 430 | if( n != NULL && n->is_SafePoint() ) { |
duke@435 | 431 | root->rm_prec(i); |
duke@435 | 432 | --i; |
duke@435 | 433 | } |
duke@435 | 434 | } |
duke@435 | 435 | } |
duke@435 | 436 | } |
duke@435 | 437 | |
zmajo@8193 | 438 | //============================================================================= |
zmajo@8193 | 439 | //------------------------------PhaseRenumberLive------------------------------ |
zmajo@8193 | 440 | // First, remove useless nodes (equivalent to identifying live nodes). |
zmajo@8193 | 441 | // Then, renumber live nodes. |
zmajo@8193 | 442 | // |
zmajo@8193 | 443 | // The set of live nodes is returned by PhaseRemoveUseless in the _useful structure. |
zmajo@8193 | 444 | // If the number of live nodes is 'x' (where 'x' == _useful.size()), then the |
zmajo@8193 | 445 | // PhaseRenumberLive updates the node ID of each node (the _idx field) with a unique |
zmajo@8193 | 446 | // value in the range [0, x). |
zmajo@8193 | 447 | // |
zmajo@8193 | 448 | // At the end of the PhaseRenumberLive phase, the compiler's count of unique nodes is |
zmajo@8193 | 449 | // updated to 'x' and the list of dead nodes is reset (as there are no dead nodes). |
zmajo@8193 | 450 | // |
zmajo@8193 | 451 | // The PhaseRenumberLive phase updates two data structures with the new node IDs. |
zmajo@8193 | 452 | // (1) The worklist is used by the PhaseIterGVN phase to identify nodes that must be |
zmajo@8193 | 453 | // processed. A new worklist (with the updated node IDs) is returned in 'new_worklist'. |
zmajo@8193 | 454 | // (2) Type information (the field PhaseGVN::_types) maps type information to each |
zmajo@8193 | 455 | // node ID. The mapping is updated to use the new node IDs as well. Updated type |
zmajo@8193 | 456 | // information is returned in PhaseGVN::_types. |
zmajo@8193 | 457 | // |
zmajo@8193 | 458 | // The PhaseRenumberLive phase does not preserve the order of elements in the worklist. |
zmajo@8193 | 459 | // |
zmajo@8193 | 460 | // Other data structures used by the compiler are not updated. The hash table for value |
zmajo@8193 | 461 | // numbering (the field PhaseGVN::_table) is not updated because computing the hash |
zmajo@8193 | 462 | // values is not based on node IDs. The field PhaseGVN::_nodes is not updated either |
zmajo@8193 | 463 | // because it is empty wherever PhaseRenumberLive is used. |
zmajo@8193 | 464 | PhaseRenumberLive::PhaseRenumberLive(PhaseGVN* gvn, |
zmajo@8193 | 465 | Unique_Node_List* worklist, Unique_Node_List* new_worklist, |
zmajo@8193 | 466 | PhaseNumber phase_num) : |
zmajo@8193 | 467 | PhaseRemoveUseless(gvn, worklist, Remove_Useless_And_Renumber_Live) { |
zmajo@8193 | 468 | |
zmajo@8193 | 469 | assert(RenumberLiveNodes, "RenumberLiveNodes must be set to true for node renumbering to take place"); |
zmajo@8193 | 470 | assert(C->live_nodes() == _useful.size(), "the number of live nodes must match the number of useful nodes"); |
zmajo@8193 | 471 | assert(gvn->nodes_size() == 0, "GVN must not contain any nodes at this point"); |
zmajo@8193 | 472 | |
zmajo@8193 | 473 | uint old_unique_count = C->unique(); |
zmajo@8193 | 474 | uint live_node_count = C->live_nodes(); |
zmajo@8193 | 475 | uint worklist_size = worklist->size(); |
zmajo@8193 | 476 | |
zmajo@8193 | 477 | // Storage for the updated type information. |
zmajo@8193 | 478 | Type_Array new_type_array(C->comp_arena()); |
zmajo@8193 | 479 | |
zmajo@8193 | 480 | // Iterate over the set of live nodes. |
zmajo@8193 | 481 | uint current_idx = 0; // The current new node ID. Incremented after every assignment. |
zmajo@8193 | 482 | for (uint i = 0; i < _useful.size(); i++) { |
zmajo@8193 | 483 | Node* n = _useful.at(i); |
poonam@8945 | 484 | // Sanity check that fails if we ever decide to execute this phase after EA |
poonam@8945 | 485 | assert(!n->is_Phi() || n->as_Phi()->inst_mem_id() == -1, "should not be linked to data Phi"); |
zmajo@8193 | 486 | const Type* type = gvn->type_or_null(n); |
zmajo@8193 | 487 | new_type_array.map(current_idx, type); |
zmajo@8193 | 488 | |
zmajo@8193 | 489 | bool in_worklist = false; |
zmajo@8193 | 490 | if (worklist->member(n)) { |
zmajo@8193 | 491 | in_worklist = true; |
zmajo@8193 | 492 | } |
zmajo@8193 | 493 | |
zmajo@8193 | 494 | n->set_idx(current_idx); // Update node ID. |
zmajo@8193 | 495 | |
zmajo@8193 | 496 | if (in_worklist) { |
zmajo@8193 | 497 | new_worklist->push(n); |
zmajo@8193 | 498 | } |
zmajo@8193 | 499 | |
zmajo@8193 | 500 | current_idx++; |
zmajo@8193 | 501 | } |
zmajo@8193 | 502 | |
zmajo@8193 | 503 | assert(worklist_size == new_worklist->size(), "the new worklist must have the same size as the original worklist"); |
zmajo@8193 | 504 | assert(live_node_count == current_idx, "all live nodes must be processed"); |
zmajo@8193 | 505 | |
zmajo@8193 | 506 | // Replace the compiler's type information with the updated type information. |
zmajo@8193 | 507 | gvn->replace_types(new_type_array); |
zmajo@8193 | 508 | |
zmajo@8193 | 509 | // Update the unique node count of the compilation to the number of currently live nodes. |
zmajo@8193 | 510 | C->set_unique(live_node_count); |
zmajo@8193 | 511 | |
zmajo@8193 | 512 | // Set the dead node count to 0 and reset dead node list. |
zmajo@8193 | 513 | C->reset_dead_node_list(); |
zmajo@8193 | 514 | } |
zmajo@8193 | 515 | |
duke@435 | 516 | |
duke@435 | 517 | //============================================================================= |
duke@435 | 518 | //------------------------------PhaseTransform--------------------------------- |
duke@435 | 519 | PhaseTransform::PhaseTransform( PhaseNumber pnum ) : Phase(pnum), |
duke@435 | 520 | _arena(Thread::current()->resource_area()), |
duke@435 | 521 | _nodes(_arena), |
duke@435 | 522 | _types(_arena) |
duke@435 | 523 | { |
duke@435 | 524 | init_con_caches(); |
duke@435 | 525 | #ifndef PRODUCT |
duke@435 | 526 | clear_progress(); |
duke@435 | 527 | clear_transforms(); |
duke@435 | 528 | set_allow_progress(true); |
duke@435 | 529 | #endif |
duke@435 | 530 | // Force allocation for currently existing nodes |
duke@435 | 531 | _types.map(C->unique(), NULL); |
duke@435 | 532 | } |
duke@435 | 533 | |
duke@435 | 534 | //------------------------------PhaseTransform--------------------------------- |
duke@435 | 535 | PhaseTransform::PhaseTransform( Arena *arena, PhaseNumber pnum ) : Phase(pnum), |
duke@435 | 536 | _arena(arena), |
duke@435 | 537 | _nodes(arena), |
duke@435 | 538 | _types(arena) |
duke@435 | 539 | { |
duke@435 | 540 | init_con_caches(); |
duke@435 | 541 | #ifndef PRODUCT |
duke@435 | 542 | clear_progress(); |
duke@435 | 543 | clear_transforms(); |
duke@435 | 544 | set_allow_progress(true); |
duke@435 | 545 | #endif |
duke@435 | 546 | // Force allocation for currently existing nodes |
duke@435 | 547 | _types.map(C->unique(), NULL); |
duke@435 | 548 | } |
duke@435 | 549 | |
duke@435 | 550 | //------------------------------PhaseTransform--------------------------------- |
duke@435 | 551 | // Initialize with previously generated type information |
duke@435 | 552 | PhaseTransform::PhaseTransform( PhaseTransform *pt, PhaseNumber pnum ) : Phase(pnum), |
duke@435 | 553 | _arena(pt->_arena), |
duke@435 | 554 | _nodes(pt->_nodes), |
duke@435 | 555 | _types(pt->_types) |
duke@435 | 556 | { |
duke@435 | 557 | init_con_caches(); |
duke@435 | 558 | #ifndef PRODUCT |
duke@435 | 559 | clear_progress(); |
duke@435 | 560 | clear_transforms(); |
duke@435 | 561 | set_allow_progress(true); |
duke@435 | 562 | #endif |
duke@435 | 563 | } |
duke@435 | 564 | |
duke@435 | 565 | void PhaseTransform::init_con_caches() { |
duke@435 | 566 | memset(_icons,0,sizeof(_icons)); |
duke@435 | 567 | memset(_lcons,0,sizeof(_lcons)); |
duke@435 | 568 | memset(_zcons,0,sizeof(_zcons)); |
duke@435 | 569 | } |
duke@435 | 570 | |
duke@435 | 571 | |
duke@435 | 572 | //--------------------------------find_int_type-------------------------------- |
duke@435 | 573 | const TypeInt* PhaseTransform::find_int_type(Node* n) { |
duke@435 | 574 | if (n == NULL) return NULL; |
duke@435 | 575 | // Call type_or_null(n) to determine node's type since we might be in |
duke@435 | 576 | // parse phase and call n->Value() may return wrong type. |
duke@435 | 577 | // (For example, a phi node at the beginning of loop parsing is not ready.) |
duke@435 | 578 | const Type* t = type_or_null(n); |
duke@435 | 579 | if (t == NULL) return NULL; |
duke@435 | 580 | return t->isa_int(); |
duke@435 | 581 | } |
duke@435 | 582 | |
duke@435 | 583 | |
duke@435 | 584 | //-------------------------------find_long_type-------------------------------- |
duke@435 | 585 | const TypeLong* PhaseTransform::find_long_type(Node* n) { |
duke@435 | 586 | if (n == NULL) return NULL; |
duke@435 | 587 | // (See comment above on type_or_null.) |
duke@435 | 588 | const Type* t = type_or_null(n); |
duke@435 | 589 | if (t == NULL) return NULL; |
duke@435 | 590 | return t->isa_long(); |
duke@435 | 591 | } |
duke@435 | 592 | |
duke@435 | 593 | |
duke@435 | 594 | #ifndef PRODUCT |
duke@435 | 595 | void PhaseTransform::dump_old2new_map() const { |
duke@435 | 596 | _nodes.dump(); |
duke@435 | 597 | } |
duke@435 | 598 | |
duke@435 | 599 | void PhaseTransform::dump_new( uint nidx ) const { |
duke@435 | 600 | for( uint i=0; i<_nodes.Size(); i++ ) |
duke@435 | 601 | if( _nodes[i] && _nodes[i]->_idx == nidx ) { |
duke@435 | 602 | _nodes[i]->dump(); |
duke@435 | 603 | tty->cr(); |
duke@435 | 604 | tty->print_cr("Old index= %d",i); |
duke@435 | 605 | return; |
duke@435 | 606 | } |
duke@435 | 607 | tty->print_cr("Node %d not found in the new indices", nidx); |
duke@435 | 608 | } |
duke@435 | 609 | |
duke@435 | 610 | //------------------------------dump_types------------------------------------- |
duke@435 | 611 | void PhaseTransform::dump_types( ) const { |
duke@435 | 612 | _types.dump(); |
duke@435 | 613 | } |
duke@435 | 614 | |
duke@435 | 615 | //------------------------------dump_nodes_and_types--------------------------- |
duke@435 | 616 | void PhaseTransform::dump_nodes_and_types(const Node *root, uint depth, bool only_ctrl) { |
duke@435 | 617 | VectorSet visited(Thread::current()->resource_area()); |
duke@435 | 618 | dump_nodes_and_types_recur( root, depth, only_ctrl, visited ); |
duke@435 | 619 | } |
duke@435 | 620 | |
duke@435 | 621 | //------------------------------dump_nodes_and_types_recur--------------------- |
duke@435 | 622 | void PhaseTransform::dump_nodes_and_types_recur( const Node *n, uint depth, bool only_ctrl, VectorSet &visited) { |
duke@435 | 623 | if( !n ) return; |
duke@435 | 624 | if( depth == 0 ) return; |
duke@435 | 625 | if( visited.test_set(n->_idx) ) return; |
duke@435 | 626 | for( uint i=0; i<n->len(); i++ ) { |
duke@435 | 627 | if( only_ctrl && !(n->is_Region()) && i != TypeFunc::Control ) continue; |
duke@435 | 628 | dump_nodes_and_types_recur( n->in(i), depth-1, only_ctrl, visited ); |
duke@435 | 629 | } |
duke@435 | 630 | n->dump(); |
duke@435 | 631 | if (type_or_null(n) != NULL) { |
duke@435 | 632 | tty->print(" "); type(n)->dump(); tty->cr(); |
duke@435 | 633 | } |
duke@435 | 634 | } |
duke@435 | 635 | |
duke@435 | 636 | #endif |
duke@435 | 637 | |
duke@435 | 638 | |
duke@435 | 639 | //============================================================================= |
duke@435 | 640 | //------------------------------PhaseValues------------------------------------ |
duke@435 | 641 | // Set minimum table size to "255" |
duke@435 | 642 | PhaseValues::PhaseValues( Arena *arena, uint est_max_size ) : PhaseTransform(arena, GVN), _table(arena, est_max_size) { |
duke@435 | 643 | NOT_PRODUCT( clear_new_values(); ) |
duke@435 | 644 | } |
duke@435 | 645 | |
duke@435 | 646 | //------------------------------PhaseValues------------------------------------ |
duke@435 | 647 | // Set minimum table size to "255" |
duke@435 | 648 | PhaseValues::PhaseValues( PhaseValues *ptv ) : PhaseTransform( ptv, GVN ), |
duke@435 | 649 | _table(&ptv->_table) { |
duke@435 | 650 | NOT_PRODUCT( clear_new_values(); ) |
duke@435 | 651 | } |
duke@435 | 652 | |
duke@435 | 653 | //------------------------------PhaseValues------------------------------------ |
duke@435 | 654 | // Used by +VerifyOpto. Clear out hash table but copy _types array. |
duke@435 | 655 | PhaseValues::PhaseValues( PhaseValues *ptv, const char *dummy ) : PhaseTransform( ptv, GVN ), |
duke@435 | 656 | _table(ptv->arena(),ptv->_table.size()) { |
duke@435 | 657 | NOT_PRODUCT( clear_new_values(); ) |
duke@435 | 658 | } |
duke@435 | 659 | |
duke@435 | 660 | //------------------------------~PhaseValues----------------------------------- |
duke@435 | 661 | #ifndef PRODUCT |
duke@435 | 662 | PhaseValues::~PhaseValues() { |
duke@435 | 663 | _table.dump(); |
duke@435 | 664 | |
duke@435 | 665 | // Statistics for value progress and efficiency |
duke@435 | 666 | if( PrintCompilation && Verbose && WizardMode ) { |
duke@435 | 667 | tty->print("\n%sValues: %d nodes ---> %d/%d (%d)", |
duke@435 | 668 | is_IterGVN() ? "Iter" : " ", C->unique(), made_progress(), made_transforms(), made_new_values()); |
duke@435 | 669 | if( made_transforms() != 0 ) { |
duke@435 | 670 | tty->print_cr(" ratio %f", made_progress()/(float)made_transforms() ); |
duke@435 | 671 | } else { |
duke@435 | 672 | tty->cr(); |
duke@435 | 673 | } |
duke@435 | 674 | } |
duke@435 | 675 | } |
duke@435 | 676 | #endif |
duke@435 | 677 | |
duke@435 | 678 | //------------------------------makecon---------------------------------------- |
duke@435 | 679 | ConNode* PhaseTransform::makecon(const Type *t) { |
duke@435 | 680 | assert(t->singleton(), "must be a constant"); |
duke@435 | 681 | assert(!t->empty() || t == Type::TOP, "must not be vacuous range"); |
duke@435 | 682 | switch (t->base()) { // fast paths |
duke@435 | 683 | case Type::Half: |
duke@435 | 684 | case Type::Top: return (ConNode*) C->top(); |
duke@435 | 685 | case Type::Int: return intcon( t->is_int()->get_con() ); |
duke@435 | 686 | case Type::Long: return longcon( t->is_long()->get_con() ); |
duke@435 | 687 | } |
duke@435 | 688 | if (t->is_zero_type()) |
duke@435 | 689 | return zerocon(t->basic_type()); |
duke@435 | 690 | return uncached_makecon(t); |
duke@435 | 691 | } |
duke@435 | 692 | |
duke@435 | 693 | //--------------------------uncached_makecon----------------------------------- |
duke@435 | 694 | // Make an idealized constant - one of ConINode, ConPNode, etc. |
duke@435 | 695 | ConNode* PhaseValues::uncached_makecon(const Type *t) { |
duke@435 | 696 | assert(t->singleton(), "must be a constant"); |
duke@435 | 697 | ConNode* x = ConNode::make(C, t); |
duke@435 | 698 | ConNode* k = (ConNode*)hash_find_insert(x); // Value numbering |
duke@435 | 699 | if (k == NULL) { |
duke@435 | 700 | set_type(x, t); // Missed, provide type mapping |
duke@435 | 701 | GrowableArray<Node_Notes*>* nna = C->node_note_array(); |
duke@435 | 702 | if (nna != NULL) { |
duke@435 | 703 | Node_Notes* loc = C->locate_node_notes(nna, x->_idx, true); |
duke@435 | 704 | loc->clear(); // do not put debug info on constants |
duke@435 | 705 | } |
duke@435 | 706 | } else { |
duke@435 | 707 | x->destruct(); // Hit, destroy duplicate constant |
duke@435 | 708 | x = k; // use existing constant |
duke@435 | 709 | } |
duke@435 | 710 | return x; |
duke@435 | 711 | } |
duke@435 | 712 | |
duke@435 | 713 | //------------------------------intcon----------------------------------------- |
duke@435 | 714 | // Fast integer constant. Same as "transform(new ConINode(TypeInt::make(i)))" |
duke@435 | 715 | ConINode* PhaseTransform::intcon(int i) { |
duke@435 | 716 | // Small integer? Check cache! Check that cached node is not dead |
duke@435 | 717 | if (i >= _icon_min && i <= _icon_max) { |
duke@435 | 718 | ConINode* icon = _icons[i-_icon_min]; |
duke@435 | 719 | if (icon != NULL && icon->in(TypeFunc::Control) != NULL) |
duke@435 | 720 | return icon; |
duke@435 | 721 | } |
duke@435 | 722 | ConINode* icon = (ConINode*) uncached_makecon(TypeInt::make(i)); |
duke@435 | 723 | assert(icon->is_Con(), ""); |
duke@435 | 724 | if (i >= _icon_min && i <= _icon_max) |
duke@435 | 725 | _icons[i-_icon_min] = icon; // Cache small integers |
duke@435 | 726 | return icon; |
duke@435 | 727 | } |
duke@435 | 728 | |
duke@435 | 729 | //------------------------------longcon---------------------------------------- |
duke@435 | 730 | // Fast long constant. |
duke@435 | 731 | ConLNode* PhaseTransform::longcon(jlong l) { |
duke@435 | 732 | // Small integer? Check cache! Check that cached node is not dead |
duke@435 | 733 | if (l >= _lcon_min && l <= _lcon_max) { |
duke@435 | 734 | ConLNode* lcon = _lcons[l-_lcon_min]; |
duke@435 | 735 | if (lcon != NULL && lcon->in(TypeFunc::Control) != NULL) |
duke@435 | 736 | return lcon; |
duke@435 | 737 | } |
duke@435 | 738 | ConLNode* lcon = (ConLNode*) uncached_makecon(TypeLong::make(l)); |
duke@435 | 739 | assert(lcon->is_Con(), ""); |
duke@435 | 740 | if (l >= _lcon_min && l <= _lcon_max) |
duke@435 | 741 | _lcons[l-_lcon_min] = lcon; // Cache small integers |
duke@435 | 742 | return lcon; |
duke@435 | 743 | } |
duke@435 | 744 | |
duke@435 | 745 | //------------------------------zerocon----------------------------------------- |
duke@435 | 746 | // Fast zero or null constant. Same as "transform(ConNode::make(Type::get_zero_type(bt)))" |
duke@435 | 747 | ConNode* PhaseTransform::zerocon(BasicType bt) { |
duke@435 | 748 | assert((uint)bt <= _zcon_max, "domain check"); |
duke@435 | 749 | ConNode* zcon = _zcons[bt]; |
duke@435 | 750 | if (zcon != NULL && zcon->in(TypeFunc::Control) != NULL) |
duke@435 | 751 | return zcon; |
duke@435 | 752 | zcon = (ConNode*) uncached_makecon(Type::get_zero_type(bt)); |
duke@435 | 753 | _zcons[bt] = zcon; |
duke@435 | 754 | return zcon; |
duke@435 | 755 | } |
duke@435 | 756 | |
duke@435 | 757 | |
duke@435 | 758 | |
duke@435 | 759 | //============================================================================= |
duke@435 | 760 | //------------------------------transform-------------------------------------- |
duke@435 | 761 | // Return a node which computes the same function as this node, but in a |
kvn@476 | 762 | // faster or cheaper fashion. |
duke@435 | 763 | Node *PhaseGVN::transform( Node *n ) { |
kvn@476 | 764 | return transform_no_reclaim(n); |
duke@435 | 765 | } |
duke@435 | 766 | |
duke@435 | 767 | //------------------------------transform-------------------------------------- |
duke@435 | 768 | // Return a node which computes the same function as this node, but |
duke@435 | 769 | // in a faster or cheaper fashion. |
duke@435 | 770 | Node *PhaseGVN::transform_no_reclaim( Node *n ) { |
duke@435 | 771 | NOT_PRODUCT( set_transforms(); ) |
duke@435 | 772 | |
duke@435 | 773 | // Apply the Ideal call in a loop until it no longer applies |
duke@435 | 774 | Node *k = n; |
duke@435 | 775 | NOT_PRODUCT( uint loop_count = 0; ) |
duke@435 | 776 | while( 1 ) { |
duke@435 | 777 | Node *i = k->Ideal(this, /*can_reshape=*/false); |
duke@435 | 778 | if( !i ) break; |
duke@435 | 779 | assert( i->_idx >= k->_idx, "Idealize should return new nodes, use Identity to return old nodes" ); |
duke@435 | 780 | k = i; |
duke@435 | 781 | assert(loop_count++ < K, "infinite loop in PhaseGVN::transform"); |
duke@435 | 782 | } |
duke@435 | 783 | NOT_PRODUCT( if( loop_count != 0 ) { set_progress(); } ) |
duke@435 | 784 | |
duke@435 | 785 | |
duke@435 | 786 | // If brand new node, make space in type array. |
duke@435 | 787 | ensure_type_or_null(k); |
duke@435 | 788 | |
duke@435 | 789 | // Since I just called 'Value' to compute the set of run-time values |
duke@435 | 790 | // for this Node, and 'Value' is non-local (and therefore expensive) I'll |
duke@435 | 791 | // cache Value. Later requests for the local phase->type of this Node can |
duke@435 | 792 | // use the cached Value instead of suffering with 'bottom_type'. |
duke@435 | 793 | const Type *t = k->Value(this); // Get runtime Value set |
duke@435 | 794 | assert(t != NULL, "value sanity"); |
duke@435 | 795 | if (type_or_null(k) != t) { |
duke@435 | 796 | #ifndef PRODUCT |
duke@435 | 797 | // Do not count initial visit to node as a transformation |
duke@435 | 798 | if (type_or_null(k) == NULL) { |
duke@435 | 799 | inc_new_values(); |
duke@435 | 800 | set_progress(); |
duke@435 | 801 | } |
duke@435 | 802 | #endif |
duke@435 | 803 | set_type(k, t); |
duke@435 | 804 | // If k is a TypeNode, capture any more-precise type permanently into Node |
duke@435 | 805 | k->raise_bottom_type(t); |
duke@435 | 806 | } |
duke@435 | 807 | |
duke@435 | 808 | if( t->singleton() && !k->is_Con() ) { |
duke@435 | 809 | NOT_PRODUCT( set_progress(); ) |
duke@435 | 810 | return makecon(t); // Turn into a constant |
duke@435 | 811 | } |
duke@435 | 812 | |
duke@435 | 813 | // Now check for Identities |
duke@435 | 814 | Node *i = k->Identity(this); // Look for a nearby replacement |
duke@435 | 815 | if( i != k ) { // Found? Return replacement! |
duke@435 | 816 | NOT_PRODUCT( set_progress(); ) |
duke@435 | 817 | return i; |
duke@435 | 818 | } |
duke@435 | 819 | |
duke@435 | 820 | // Global Value Numbering |
duke@435 | 821 | i = hash_find_insert(k); // Insert if new |
duke@435 | 822 | if( i && (i != k) ) { |
duke@435 | 823 | // Return the pre-existing node |
duke@435 | 824 | NOT_PRODUCT( set_progress(); ) |
duke@435 | 825 | return i; |
duke@435 | 826 | } |
duke@435 | 827 | |
duke@435 | 828 | // Return Idealized original |
duke@435 | 829 | return k; |
duke@435 | 830 | } |
duke@435 | 831 | |
duke@435 | 832 | #ifdef ASSERT |
duke@435 | 833 | //------------------------------dead_loop_check-------------------------------- |
twisti@1040 | 834 | // Check for a simple dead loop when a data node references itself directly |
duke@435 | 835 | // or through an other data node excluding cons and phis. |
duke@435 | 836 | void PhaseGVN::dead_loop_check( Node *n ) { |
duke@435 | 837 | // Phi may reference itself in a loop |
duke@435 | 838 | if (n != NULL && !n->is_dead_loop_safe() && !n->is_CFG()) { |
duke@435 | 839 | // Do 2 levels check and only data inputs. |
duke@435 | 840 | bool no_dead_loop = true; |
duke@435 | 841 | uint cnt = n->req(); |
duke@435 | 842 | for (uint i = 1; i < cnt && no_dead_loop; i++) { |
duke@435 | 843 | Node *in = n->in(i); |
duke@435 | 844 | if (in == n) { |
duke@435 | 845 | no_dead_loop = false; |
duke@435 | 846 | } else if (in != NULL && !in->is_dead_loop_safe()) { |
duke@435 | 847 | uint icnt = in->req(); |
duke@435 | 848 | for (uint j = 1; j < icnt && no_dead_loop; j++) { |
duke@435 | 849 | if (in->in(j) == n || in->in(j) == in) |
duke@435 | 850 | no_dead_loop = false; |
duke@435 | 851 | } |
duke@435 | 852 | } |
duke@435 | 853 | } |
duke@435 | 854 | if (!no_dead_loop) n->dump(3); |
duke@435 | 855 | assert(no_dead_loop, "dead loop detected"); |
duke@435 | 856 | } |
duke@435 | 857 | } |
duke@435 | 858 | #endif |
duke@435 | 859 | |
duke@435 | 860 | //============================================================================= |
duke@435 | 861 | //------------------------------PhaseIterGVN----------------------------------- |
duke@435 | 862 | // Initialize hash table to fresh and clean for +VerifyOpto |
coleenp@548 | 863 | PhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn, const char *dummy ) : PhaseGVN(igvn,dummy), _worklist( ), |
zmajo@8068 | 864 | _stack(C->live_nodes() >> 1), |
coleenp@548 | 865 | _delay_transform(false) { |
duke@435 | 866 | } |
duke@435 | 867 | |
duke@435 | 868 | //------------------------------PhaseIterGVN----------------------------------- |
duke@435 | 869 | // Initialize with previous PhaseIterGVN info; used by PhaseCCP |
duke@435 | 870 | PhaseIterGVN::PhaseIterGVN( PhaseIterGVN *igvn ) : PhaseGVN(igvn), |
coleenp@548 | 871 | _worklist( igvn->_worklist ), |
dlong@3947 | 872 | _stack( igvn->_stack ), |
coleenp@548 | 873 | _delay_transform(igvn->_delay_transform) |
duke@435 | 874 | { |
duke@435 | 875 | } |
duke@435 | 876 | |
duke@435 | 877 | //------------------------------PhaseIterGVN----------------------------------- |
duke@435 | 878 | // Initialize with previous PhaseGVN info from Parser |
duke@435 | 879 | PhaseIterGVN::PhaseIterGVN( PhaseGVN *gvn ) : PhaseGVN(gvn), |
coleenp@548 | 880 | _worklist(*C->for_igvn()), |
zmajo@8068 | 881 | // TODO: Before incremental inlining it was allocated only once and it was fine. Now that |
zmajo@8068 | 882 | // the constructor is used in incremental inlining, this consumes too much memory: |
zmajo@8068 | 883 | // _stack(C->live_nodes() >> 1), |
zmajo@8068 | 884 | // So, as a band-aid, we replace this by: |
zmajo@8068 | 885 | _stack(C->comp_arena(), 32), |
coleenp@548 | 886 | _delay_transform(false) |
duke@435 | 887 | { |
duke@435 | 888 | uint max; |
duke@435 | 889 | |
duke@435 | 890 | // Dead nodes in the hash table inherited from GVN were not treated as |
duke@435 | 891 | // roots during def-use info creation; hence they represent an invisible |
duke@435 | 892 | // use. Clear them out. |
duke@435 | 893 | max = _table.size(); |
duke@435 | 894 | for( uint i = 0; i < max; ++i ) { |
duke@435 | 895 | Node *n = _table.at(i); |
duke@435 | 896 | if(n != NULL && n != _table.sentinel() && n->outcnt() == 0) { |
duke@435 | 897 | if( n->is_top() ) continue; |
duke@435 | 898 | assert( false, "Parse::remove_useless_nodes missed this node"); |
duke@435 | 899 | hash_delete(n); |
duke@435 | 900 | } |
duke@435 | 901 | } |
duke@435 | 902 | |
duke@435 | 903 | // Any Phis or Regions on the worklist probably had uses that could not |
duke@435 | 904 | // make more progress because the uses were made while the Phis and Regions |
duke@435 | 905 | // were in half-built states. Put all uses of Phis and Regions on worklist. |
duke@435 | 906 | max = _worklist.size(); |
duke@435 | 907 | for( uint j = 0; j < max; j++ ) { |
duke@435 | 908 | Node *n = _worklist.at(j); |
duke@435 | 909 | uint uop = n->Opcode(); |
duke@435 | 910 | if( uop == Op_Phi || uop == Op_Region || |
duke@435 | 911 | n->is_Type() || |
duke@435 | 912 | n->is_Mem() ) |
duke@435 | 913 | add_users_to_worklist(n); |
duke@435 | 914 | } |
duke@435 | 915 | } |
duke@435 | 916 | |
duke@435 | 917 | |
duke@435 | 918 | #ifndef PRODUCT |
duke@435 | 919 | void PhaseIterGVN::verify_step(Node* n) { |
duke@435 | 920 | _verify_window[_verify_counter % _verify_window_size] = n; |
duke@435 | 921 | ++_verify_counter; |
duke@435 | 922 | ResourceMark rm; |
duke@435 | 923 | ResourceArea *area = Thread::current()->resource_area(); |
duke@435 | 924 | VectorSet old_space(area), new_space(area); |
duke@435 | 925 | if (C->unique() < 1000 || |
duke@435 | 926 | 0 == _verify_counter % (C->unique() < 10000 ? 10 : 100)) { |
duke@435 | 927 | ++_verify_full_passes; |
duke@435 | 928 | Node::verify_recur(C->root(), -1, old_space, new_space); |
duke@435 | 929 | } |
duke@435 | 930 | const int verify_depth = 4; |
duke@435 | 931 | for ( int i = 0; i < _verify_window_size; i++ ) { |
duke@435 | 932 | Node* n = _verify_window[i]; |
duke@435 | 933 | if ( n == NULL ) continue; |
duke@435 | 934 | if( n->in(0) == NodeSentinel ) { // xform_idom |
duke@435 | 935 | _verify_window[i] = n->in(1); |
duke@435 | 936 | --i; continue; |
duke@435 | 937 | } |
duke@435 | 938 | // Typical fanout is 1-2, so this call visits about 6 nodes. |
duke@435 | 939 | Node::verify_recur(n, verify_depth, old_space, new_space); |
duke@435 | 940 | } |
duke@435 | 941 | } |
duke@435 | 942 | #endif |
duke@435 | 943 | |
duke@435 | 944 | |
duke@435 | 945 | //------------------------------init_worklist---------------------------------- |
duke@435 | 946 | // Initialize worklist for each node. |
duke@435 | 947 | void PhaseIterGVN::init_worklist( Node *n ) { |
duke@435 | 948 | if( _worklist.member(n) ) return; |
duke@435 | 949 | _worklist.push(n); |
duke@435 | 950 | uint cnt = n->req(); |
duke@435 | 951 | for( uint i =0 ; i < cnt; i++ ) { |
duke@435 | 952 | Node *m = n->in(i); |
duke@435 | 953 | if( m ) init_worklist(m); |
duke@435 | 954 | } |
duke@435 | 955 | } |
duke@435 | 956 | |
duke@435 | 957 | //------------------------------optimize--------------------------------------- |
duke@435 | 958 | void PhaseIterGVN::optimize() { |
duke@435 | 959 | debug_only(uint num_processed = 0;); |
duke@435 | 960 | #ifndef PRODUCT |
duke@435 | 961 | { |
duke@435 | 962 | _verify_counter = 0; |
duke@435 | 963 | _verify_full_passes = 0; |
duke@435 | 964 | for ( int i = 0; i < _verify_window_size; i++ ) { |
duke@435 | 965 | _verify_window[i] = NULL; |
duke@435 | 966 | } |
duke@435 | 967 | } |
duke@435 | 968 | #endif |
duke@435 | 969 | |
kvn@2181 | 970 | #ifdef ASSERT |
kvn@2181 | 971 | Node* prev = NULL; |
kvn@2181 | 972 | uint rep_cnt = 0; |
kvn@2181 | 973 | #endif |
kvn@2181 | 974 | uint loop_count = 0; |
kvn@2181 | 975 | |
duke@435 | 976 | // Pull from worklist; transform node; |
duke@435 | 977 | // If node has changed: update edge info and put uses on worklist. |
duke@435 | 978 | while( _worklist.size() ) { |
kvn@3154 | 979 | if (C->check_node_count(NodeLimitFudgeFactor * 2, |
kvn@3154 | 980 | "out of nodes optimizing method")) { |
kvn@3154 | 981 | return; |
kvn@3154 | 982 | } |
duke@435 | 983 | Node *n = _worklist.pop(); |
kvn@5110 | 984 | if (++loop_count >= K * C->live_nodes()) { |
kvn@2181 | 985 | debug_only(n->dump(4);) |
kvn@2181 | 986 | assert(false, "infinite loop in PhaseIterGVN::optimize"); |
kvn@2181 | 987 | C->record_method_not_compilable("infinite loop in PhaseIterGVN::optimize"); |
kvn@2181 | 988 | return; |
kvn@2181 | 989 | } |
kvn@2181 | 990 | #ifdef ASSERT |
kvn@2181 | 991 | if (n == prev) { |
kvn@2181 | 992 | if (++rep_cnt > 3) { |
kvn@2181 | 993 | n->dump(4); |
kvn@2181 | 994 | assert(false, "loop in Ideal transformation"); |
kvn@2181 | 995 | } |
kvn@2181 | 996 | } else { |
kvn@2181 | 997 | rep_cnt = 0; |
kvn@2181 | 998 | } |
kvn@2181 | 999 | prev = n; |
kvn@2181 | 1000 | #endif |
duke@435 | 1001 | if (TraceIterativeGVN && Verbose) { |
duke@435 | 1002 | tty->print(" Pop "); |
duke@435 | 1003 | NOT_PRODUCT( n->dump(); ) |
duke@435 | 1004 | debug_only(if( (num_processed++ % 100) == 0 ) _worklist.print_set();) |
duke@435 | 1005 | } |
duke@435 | 1006 | |
duke@435 | 1007 | if (n->outcnt() != 0) { |
duke@435 | 1008 | |
duke@435 | 1009 | #ifndef PRODUCT |
duke@435 | 1010 | uint wlsize = _worklist.size(); |
duke@435 | 1011 | const Type* oldtype = type_or_null(n); |
duke@435 | 1012 | #endif //PRODUCT |
duke@435 | 1013 | |
duke@435 | 1014 | Node *nn = transform_old(n); |
duke@435 | 1015 | |
duke@435 | 1016 | #ifndef PRODUCT |
duke@435 | 1017 | if (TraceIterativeGVN) { |
duke@435 | 1018 | const Type* newtype = type_or_null(n); |
duke@435 | 1019 | if (nn != n) { |
duke@435 | 1020 | // print old node |
duke@435 | 1021 | tty->print("< "); |
duke@435 | 1022 | if (oldtype != newtype && oldtype != NULL) { |
duke@435 | 1023 | oldtype->dump(); |
duke@435 | 1024 | } |
duke@435 | 1025 | do { tty->print("\t"); } while (tty->position() < 16); |
duke@435 | 1026 | tty->print("<"); |
duke@435 | 1027 | n->dump(); |
duke@435 | 1028 | } |
duke@435 | 1029 | if (oldtype != newtype || nn != n) { |
duke@435 | 1030 | // print new node and/or new type |
duke@435 | 1031 | if (oldtype == NULL) { |
duke@435 | 1032 | tty->print("* "); |
duke@435 | 1033 | } else if (nn != n) { |
duke@435 | 1034 | tty->print("> "); |
duke@435 | 1035 | } else { |
duke@435 | 1036 | tty->print("= "); |
duke@435 | 1037 | } |
duke@435 | 1038 | if (newtype == NULL) { |
duke@435 | 1039 | tty->print("null"); |
duke@435 | 1040 | } else { |
duke@435 | 1041 | newtype->dump(); |
duke@435 | 1042 | } |
duke@435 | 1043 | do { tty->print("\t"); } while (tty->position() < 16); |
duke@435 | 1044 | nn->dump(); |
duke@435 | 1045 | } |
duke@435 | 1046 | if (Verbose && wlsize < _worklist.size()) { |
duke@435 | 1047 | tty->print(" Push {"); |
duke@435 | 1048 | while (wlsize != _worklist.size()) { |
duke@435 | 1049 | Node* pushed = _worklist.at(wlsize++); |
duke@435 | 1050 | tty->print(" %d", pushed->_idx); |
duke@435 | 1051 | } |
duke@435 | 1052 | tty->print_cr(" }"); |
duke@435 | 1053 | } |
duke@435 | 1054 | } |
duke@435 | 1055 | if( VerifyIterativeGVN && nn != n ) { |
duke@435 | 1056 | verify_step((Node*) NULL); // ignore n, it might be subsumed |
duke@435 | 1057 | } |
duke@435 | 1058 | #endif |
duke@435 | 1059 | } else if (!n->is_top()) { |
duke@435 | 1060 | remove_dead_node(n); |
duke@435 | 1061 | } |
duke@435 | 1062 | } |
duke@435 | 1063 | |
duke@435 | 1064 | #ifndef PRODUCT |
duke@435 | 1065 | C->verify_graph_edges(); |
duke@435 | 1066 | if( VerifyOpto && allow_progress() ) { |
duke@435 | 1067 | // Must turn off allow_progress to enable assert and break recursion |
duke@435 | 1068 | C->root()->verify(); |
duke@435 | 1069 | { // Check if any progress was missed using IterGVN |
duke@435 | 1070 | // Def-Use info enables transformations not attempted in wash-pass |
duke@435 | 1071 | // e.g. Region/Phi cleanup, ... |
duke@435 | 1072 | // Null-check elision -- may not have reached fixpoint |
duke@435 | 1073 | // do not propagate to dominated nodes |
duke@435 | 1074 | ResourceMark rm; |
duke@435 | 1075 | PhaseIterGVN igvn2(this,"Verify"); // Fresh and clean! |
duke@435 | 1076 | // Fill worklist completely |
duke@435 | 1077 | igvn2.init_worklist(C->root()); |
duke@435 | 1078 | |
duke@435 | 1079 | igvn2.set_allow_progress(false); |
duke@435 | 1080 | igvn2.optimize(); |
duke@435 | 1081 | igvn2.set_allow_progress(true); |
duke@435 | 1082 | } |
duke@435 | 1083 | } |
duke@435 | 1084 | if ( VerifyIterativeGVN && PrintOpto ) { |
duke@435 | 1085 | if ( _verify_counter == _verify_full_passes ) |
duke@435 | 1086 | tty->print_cr("VerifyIterativeGVN: %d transforms and verify passes", |
drchase@6680 | 1087 | (int) _verify_full_passes); |
duke@435 | 1088 | else |
duke@435 | 1089 | tty->print_cr("VerifyIterativeGVN: %d transforms, %d full verify passes", |
drchase@6680 | 1090 | (int) _verify_counter, (int) _verify_full_passes); |
duke@435 | 1091 | } |
duke@435 | 1092 | #endif |
duke@435 | 1093 | } |
duke@435 | 1094 | |
duke@435 | 1095 | |
duke@435 | 1096 | //------------------register_new_node_with_optimizer--------------------------- |
duke@435 | 1097 | // Register a new node with the optimizer. Update the types array, the def-use |
duke@435 | 1098 | // info. Put on worklist. |
duke@435 | 1099 | Node* PhaseIterGVN::register_new_node_with_optimizer(Node* n, Node* orig) { |
duke@435 | 1100 | set_type_bottom(n); |
duke@435 | 1101 | _worklist.push(n); |
duke@435 | 1102 | if (orig != NULL) C->copy_node_notes_to(n, orig); |
duke@435 | 1103 | return n; |
duke@435 | 1104 | } |
duke@435 | 1105 | |
duke@435 | 1106 | //------------------------------transform-------------------------------------- |
duke@435 | 1107 | // Non-recursive: idealize Node 'n' with respect to its inputs and its value |
duke@435 | 1108 | Node *PhaseIterGVN::transform( Node *n ) { |
coleenp@548 | 1109 | if (_delay_transform) { |
coleenp@548 | 1110 | // Register the node but don't optimize for now |
coleenp@548 | 1111 | register_new_node_with_optimizer(n); |
coleenp@548 | 1112 | return n; |
coleenp@548 | 1113 | } |
coleenp@548 | 1114 | |
duke@435 | 1115 | // If brand new node, make space in type array, and give it a type. |
duke@435 | 1116 | ensure_type_or_null(n); |
duke@435 | 1117 | if (type_or_null(n) == NULL) { |
duke@435 | 1118 | set_type_bottom(n); |
duke@435 | 1119 | } |
duke@435 | 1120 | |
duke@435 | 1121 | return transform_old(n); |
duke@435 | 1122 | } |
duke@435 | 1123 | |
duke@435 | 1124 | //------------------------------transform_old---------------------------------- |
duke@435 | 1125 | Node *PhaseIterGVN::transform_old( Node *n ) { |
duke@435 | 1126 | #ifndef PRODUCT |
duke@435 | 1127 | debug_only(uint loop_count = 0;); |
duke@435 | 1128 | set_transforms(); |
duke@435 | 1129 | #endif |
duke@435 | 1130 | // Remove 'n' from hash table in case it gets modified |
duke@435 | 1131 | _table.hash_delete(n); |
duke@435 | 1132 | if( VerifyIterativeGVN ) { |
duke@435 | 1133 | assert( !_table.find_index(n->_idx), "found duplicate entry in table"); |
duke@435 | 1134 | } |
duke@435 | 1135 | |
duke@435 | 1136 | // Apply the Ideal call in a loop until it no longer applies |
duke@435 | 1137 | Node *k = n; |
duke@435 | 1138 | DEBUG_ONLY(dead_loop_check(k);) |
kvn@740 | 1139 | DEBUG_ONLY(bool is_new = (k->outcnt() == 0);) |
duke@435 | 1140 | Node *i = k->Ideal(this, /*can_reshape=*/true); |
kvn@740 | 1141 | assert(i != k || is_new || i->outcnt() > 0, "don't return dead nodes"); |
duke@435 | 1142 | #ifndef PRODUCT |
duke@435 | 1143 | if( VerifyIterativeGVN ) |
duke@435 | 1144 | verify_step(k); |
duke@435 | 1145 | if( i && VerifyOpto ) { |
duke@435 | 1146 | if( !allow_progress() ) { |
duke@435 | 1147 | if (i->is_Add() && i->outcnt() == 1) { |
duke@435 | 1148 | // Switched input to left side because this is the only use |
duke@435 | 1149 | } else if( i->is_If() && (i->in(0) == NULL) ) { |
duke@435 | 1150 | // This IF is dead because it is dominated by an equivalent IF When |
duke@435 | 1151 | // dominating if changed, info is not propagated sparsely to 'this' |
duke@435 | 1152 | // Propagating this info further will spuriously identify other |
duke@435 | 1153 | // progress. |
duke@435 | 1154 | return i; |
duke@435 | 1155 | } else |
duke@435 | 1156 | set_progress(); |
duke@435 | 1157 | } else |
duke@435 | 1158 | set_progress(); |
duke@435 | 1159 | } |
duke@435 | 1160 | #endif |
duke@435 | 1161 | |
duke@435 | 1162 | while( i ) { |
duke@435 | 1163 | #ifndef PRODUCT |
duke@435 | 1164 | debug_only( if( loop_count >= K ) i->dump(4); ) |
duke@435 | 1165 | assert(loop_count < K, "infinite loop in PhaseIterGVN::transform"); |
duke@435 | 1166 | debug_only( loop_count++; ) |
duke@435 | 1167 | #endif |
duke@435 | 1168 | assert((i->_idx >= k->_idx) || i->is_top(), "Idealize should return new nodes, use Identity to return old nodes"); |
duke@435 | 1169 | // Made a change; put users of original Node on worklist |
duke@435 | 1170 | add_users_to_worklist( k ); |
duke@435 | 1171 | // Replacing root of transform tree? |
duke@435 | 1172 | if( k != i ) { |
duke@435 | 1173 | // Make users of old Node now use new. |
duke@435 | 1174 | subsume_node( k, i ); |
duke@435 | 1175 | k = i; |
duke@435 | 1176 | } |
duke@435 | 1177 | DEBUG_ONLY(dead_loop_check(k);) |
duke@435 | 1178 | // Try idealizing again |
kvn@740 | 1179 | DEBUG_ONLY(is_new = (k->outcnt() == 0);) |
duke@435 | 1180 | i = k->Ideal(this, /*can_reshape=*/true); |
kvn@740 | 1181 | assert(i != k || is_new || i->outcnt() > 0, "don't return dead nodes"); |
duke@435 | 1182 | #ifndef PRODUCT |
duke@435 | 1183 | if( VerifyIterativeGVN ) |
duke@435 | 1184 | verify_step(k); |
duke@435 | 1185 | if( i && VerifyOpto ) set_progress(); |
duke@435 | 1186 | #endif |
duke@435 | 1187 | } |
duke@435 | 1188 | |
duke@435 | 1189 | // If brand new node, make space in type array. |
duke@435 | 1190 | ensure_type_or_null(k); |
duke@435 | 1191 | |
duke@435 | 1192 | // See what kind of values 'k' takes on at runtime |
duke@435 | 1193 | const Type *t = k->Value(this); |
duke@435 | 1194 | assert(t != NULL, "value sanity"); |
duke@435 | 1195 | |
duke@435 | 1196 | // Since I just called 'Value' to compute the set of run-time values |
duke@435 | 1197 | // for this Node, and 'Value' is non-local (and therefore expensive) I'll |
duke@435 | 1198 | // cache Value. Later requests for the local phase->type of this Node can |
duke@435 | 1199 | // use the cached Value instead of suffering with 'bottom_type'. |
duke@435 | 1200 | if (t != type_or_null(k)) { |
duke@435 | 1201 | NOT_PRODUCT( set_progress(); ) |
duke@435 | 1202 | NOT_PRODUCT( inc_new_values();) |
duke@435 | 1203 | set_type(k, t); |
duke@435 | 1204 | // If k is a TypeNode, capture any more-precise type permanently into Node |
duke@435 | 1205 | k->raise_bottom_type(t); |
duke@435 | 1206 | // Move users of node to worklist |
duke@435 | 1207 | add_users_to_worklist( k ); |
duke@435 | 1208 | } |
duke@435 | 1209 | |
duke@435 | 1210 | // If 'k' computes a constant, replace it with a constant |
duke@435 | 1211 | if( t->singleton() && !k->is_Con() ) { |
duke@435 | 1212 | NOT_PRODUCT( set_progress(); ) |
duke@435 | 1213 | Node *con = makecon(t); // Make a constant |
duke@435 | 1214 | add_users_to_worklist( k ); |
duke@435 | 1215 | subsume_node( k, con ); // Everybody using k now uses con |
duke@435 | 1216 | return con; |
duke@435 | 1217 | } |
duke@435 | 1218 | |
duke@435 | 1219 | // Now check for Identities |
duke@435 | 1220 | i = k->Identity(this); // Look for a nearby replacement |
duke@435 | 1221 | if( i != k ) { // Found? Return replacement! |
duke@435 | 1222 | NOT_PRODUCT( set_progress(); ) |
duke@435 | 1223 | add_users_to_worklist( k ); |
duke@435 | 1224 | subsume_node( k, i ); // Everybody using k now uses i |
duke@435 | 1225 | return i; |
duke@435 | 1226 | } |
duke@435 | 1227 | |
duke@435 | 1228 | // Global Value Numbering |
duke@435 | 1229 | i = hash_find_insert(k); // Check for pre-existing node |
duke@435 | 1230 | if( i && (i != k) ) { |
duke@435 | 1231 | // Return the pre-existing node if it isn't dead |
duke@435 | 1232 | NOT_PRODUCT( set_progress(); ) |
duke@435 | 1233 | add_users_to_worklist( k ); |
duke@435 | 1234 | subsume_node( k, i ); // Everybody using k now uses i |
duke@435 | 1235 | return i; |
duke@435 | 1236 | } |
duke@435 | 1237 | |
duke@435 | 1238 | // Return Idealized original |
duke@435 | 1239 | return k; |
duke@435 | 1240 | } |
duke@435 | 1241 | |
duke@435 | 1242 | //---------------------------------saturate------------------------------------ |
duke@435 | 1243 | const Type* PhaseIterGVN::saturate(const Type* new_type, const Type* old_type, |
duke@435 | 1244 | const Type* limit_type) const { |
duke@435 | 1245 | return new_type->narrow(old_type); |
duke@435 | 1246 | } |
duke@435 | 1247 | |
duke@435 | 1248 | //------------------------------remove_globally_dead_node---------------------- |
duke@435 | 1249 | // Kill a globally dead Node. All uses are also globally dead and are |
duke@435 | 1250 | // aggressively trimmed. |
duke@435 | 1251 | void PhaseIterGVN::remove_globally_dead_node( Node *dead ) { |
dlong@3947 | 1252 | enum DeleteProgress { |
dlong@3947 | 1253 | PROCESS_INPUTS, |
dlong@3947 | 1254 | PROCESS_OUTPUTS |
dlong@3947 | 1255 | }; |
dlong@3947 | 1256 | assert(_stack.is_empty(), "not empty"); |
dlong@3947 | 1257 | _stack.push(dead, PROCESS_INPUTS); |
dlong@3947 | 1258 | |
dlong@3947 | 1259 | while (_stack.is_nonempty()) { |
dlong@3947 | 1260 | dead = _stack.node(); |
dlong@3947 | 1261 | uint progress_state = _stack.index(); |
dlong@3947 | 1262 | assert(dead != C->root(), "killing root, eh?"); |
dlong@3947 | 1263 | assert(!dead->is_top(), "add check for top when pushing"); |
dlong@3947 | 1264 | NOT_PRODUCT( set_progress(); ) |
dlong@3947 | 1265 | if (progress_state == PROCESS_INPUTS) { |
dlong@3947 | 1266 | // After following inputs, continue to outputs |
dlong@3947 | 1267 | _stack.set_index(PROCESS_OUTPUTS); |
dlong@3947 | 1268 | if (!dead->is_Con()) { // Don't kill cons but uses |
dlong@3947 | 1269 | bool recurse = false; |
dlong@3947 | 1270 | // Remove from hash table |
dlong@3947 | 1271 | _table.hash_delete( dead ); |
dlong@3947 | 1272 | // Smash all inputs to 'dead', isolating him completely |
kvn@4868 | 1273 | for (uint i = 0; i < dead->req(); i++) { |
dlong@3947 | 1274 | Node *in = dead->in(i); |
kvn@4868 | 1275 | if (in != NULL && in != C->top()) { // Points to something? |
kvn@4868 | 1276 | int nrep = dead->replace_edge(in, NULL); // Kill edges |
kvn@4868 | 1277 | assert((nrep > 0), "sanity"); |
kvn@4868 | 1278 | if (in->outcnt() == 0) { // Made input go dead? |
dlong@3947 | 1279 | _stack.push(in, PROCESS_INPUTS); // Recursively remove |
dlong@3947 | 1280 | recurse = true; |
dlong@3947 | 1281 | } else if (in->outcnt() == 1 && |
dlong@3947 | 1282 | in->has_special_unique_user()) { |
dlong@3947 | 1283 | _worklist.push(in->unique_out()); |
dlong@3947 | 1284 | } else if (in->outcnt() <= 2 && dead->is_Phi()) { |
kvn@4868 | 1285 | if (in->Opcode() == Op_Region) { |
dlong@3947 | 1286 | _worklist.push(in); |
kvn@4868 | 1287 | } else if (in->is_Store()) { |
dlong@3947 | 1288 | DUIterator_Fast imax, i = in->fast_outs(imax); |
dlong@3947 | 1289 | _worklist.push(in->fast_out(i)); |
dlong@3947 | 1290 | i++; |
kvn@4868 | 1291 | if (in->outcnt() == 2) { |
dlong@3947 | 1292 | _worklist.push(in->fast_out(i)); |
dlong@3947 | 1293 | i++; |
dlong@3947 | 1294 | } |
dlong@3947 | 1295 | assert(!(i < imax), "sanity"); |
dlong@3947 | 1296 | } |
duke@435 | 1297 | } |
roland@4657 | 1298 | if (ReduceFieldZeroing && dead->is_Load() && i == MemNode::Memory && |
roland@4657 | 1299 | in->is_Proj() && in->in(0) != NULL && in->in(0)->is_Initialize()) { |
roland@4657 | 1300 | // A Load that directly follows an InitializeNode is |
roland@4657 | 1301 | // going away. The Stores that follow are candidates |
roland@4657 | 1302 | // again to be captured by the InitializeNode. |
roland@4657 | 1303 | for (DUIterator_Fast jmax, j = in->fast_outs(jmax); j < jmax; j++) { |
roland@4657 | 1304 | Node *n = in->fast_out(j); |
roland@4657 | 1305 | if (n->is_Store()) { |
roland@4657 | 1306 | _worklist.push(n); |
roland@4657 | 1307 | } |
roland@4657 | 1308 | } |
roland@4657 | 1309 | } |
kvn@4868 | 1310 | } // if (in != NULL && in != C->top()) |
kvn@4868 | 1311 | } // for (uint i = 0; i < dead->req(); i++) |
dlong@3947 | 1312 | if (recurse) { |
dlong@3947 | 1313 | continue; |
dlong@3947 | 1314 | } |
kvn@4868 | 1315 | } // if (!dead->is_Con()) |
kvn@4868 | 1316 | } // if (progress_state == PROCESS_INPUTS) |
duke@435 | 1317 | |
dlong@3947 | 1318 | // Aggressively kill globally dead uses |
dlong@3947 | 1319 | // (Rather than pushing all the outs at once, we push one at a time, |
dlong@3947 | 1320 | // plus the parent to resume later, because of the indefinite number |
dlong@3947 | 1321 | // of edge deletions per loop trip.) |
dlong@3947 | 1322 | if (dead->outcnt() > 0) { |
kvn@4868 | 1323 | // Recursively remove output edges |
dlong@3947 | 1324 | _stack.push(dead->raw_out(0), PROCESS_INPUTS); |
dlong@3947 | 1325 | } else { |
kvn@4868 | 1326 | // Finished disconnecting all input and output edges. |
dlong@3947 | 1327 | _stack.pop(); |
kvn@4868 | 1328 | // Remove dead node from iterative worklist |
kvn@4868 | 1329 | _worklist.remove(dead); |
kvn@4868 | 1330 | // Constant node that has no out-edges and has only one in-edge from |
kvn@4868 | 1331 | // root is usually dead. However, sometimes reshaping walk makes |
kvn@4868 | 1332 | // it reachable by adding use edges. So, we will NOT count Con nodes |
kvn@4868 | 1333 | // as dead to be conservative about the dead node count at any |
kvn@4868 | 1334 | // given time. |
kvn@4868 | 1335 | if (!dead->is_Con()) { |
kvn@4868 | 1336 | C->record_dead_node(dead->_idx); |
kvn@4868 | 1337 | } |
kvn@4868 | 1338 | if (dead->is_macro()) { |
kvn@4868 | 1339 | C->remove_macro_node(dead); |
kvn@4868 | 1340 | } |
kvn@4868 | 1341 | if (dead->is_expensive()) { |
kvn@4868 | 1342 | C->remove_expensive_node(dead); |
kvn@4868 | 1343 | } |
thartmann@8476 | 1344 | CastIINode* cast = dead->isa_CastII(); |
thartmann@8476 | 1345 | if (cast != NULL && cast->has_range_check()) { |
thartmann@8476 | 1346 | C->remove_range_check_cast(cast); |
thartmann@8476 | 1347 | } |
duke@435 | 1348 | } |
kvn@4868 | 1349 | } // while (_stack.is_nonempty()) |
duke@435 | 1350 | } |
duke@435 | 1351 | |
duke@435 | 1352 | //------------------------------subsume_node----------------------------------- |
duke@435 | 1353 | // Remove users from node 'old' and add them to node 'nn'. |
duke@435 | 1354 | void PhaseIterGVN::subsume_node( Node *old, Node *nn ) { |
duke@435 | 1355 | assert( old != hash_find(old), "should already been removed" ); |
duke@435 | 1356 | assert( old != C->top(), "cannot subsume top node"); |
duke@435 | 1357 | // Copy debug or profile information to the new version: |
duke@435 | 1358 | C->copy_node_notes_to(nn, old); |
duke@435 | 1359 | // Move users of node 'old' to node 'nn' |
duke@435 | 1360 | for (DUIterator_Last imin, i = old->last_outs(imin); i >= imin; ) { |
duke@435 | 1361 | Node* use = old->last_out(i); // for each use... |
duke@435 | 1362 | // use might need re-hashing (but it won't if it's a new node) |
duke@435 | 1363 | bool is_in_table = _table.hash_delete( use ); |
duke@435 | 1364 | // Update use-def info as well |
duke@435 | 1365 | // We remove all occurrences of old within use->in, |
duke@435 | 1366 | // so as to avoid rehashing any node more than once. |
duke@435 | 1367 | // The hash table probe swamps any outer loop overhead. |
duke@435 | 1368 | uint num_edges = 0; |
duke@435 | 1369 | for (uint jmax = use->len(), j = 0; j < jmax; j++) { |
duke@435 | 1370 | if (use->in(j) == old) { |
duke@435 | 1371 | use->set_req(j, nn); |
duke@435 | 1372 | ++num_edges; |
duke@435 | 1373 | } |
duke@435 | 1374 | } |
duke@435 | 1375 | // Insert into GVN hash table if unique |
duke@435 | 1376 | // If a duplicate, 'use' will be cleaned up when pulled off worklist |
duke@435 | 1377 | if( is_in_table ) { |
duke@435 | 1378 | hash_find_insert(use); |
duke@435 | 1379 | } |
duke@435 | 1380 | i -= num_edges; // we deleted 1 or more copies of this edge |
duke@435 | 1381 | } |
duke@435 | 1382 | |
poonam@8945 | 1383 | // Search for instance field data PhiNodes in the same region pointing to the old |
poonam@8945 | 1384 | // memory PhiNode and update their instance memory ids to point to the new node. |
poonam@8945 | 1385 | if (old->is_Phi() && old->as_Phi()->type()->has_memory() && old->in(0) != NULL) { |
poonam@8945 | 1386 | Node* region = old->in(0); |
poonam@8945 | 1387 | for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) { |
poonam@8945 | 1388 | PhiNode* phi = region->fast_out(i)->isa_Phi(); |
poonam@8945 | 1389 | if (phi != NULL && phi->inst_mem_id() == (int)old->_idx) { |
poonam@8945 | 1390 | phi->set_inst_mem_id((int)nn->_idx); |
poonam@8945 | 1391 | } |
poonam@8945 | 1392 | } |
poonam@8945 | 1393 | } |
poonam@8945 | 1394 | |
duke@435 | 1395 | // Smash all inputs to 'old', isolating him completely |
kvn@4115 | 1396 | Node *temp = new (C) Node(1); |
duke@435 | 1397 | temp->init_req(0,nn); // Add a use to nn to prevent him from dying |
duke@435 | 1398 | remove_dead_node( old ); |
duke@435 | 1399 | temp->del_req(0); // Yank bogus edge |
duke@435 | 1400 | #ifndef PRODUCT |
duke@435 | 1401 | if( VerifyIterativeGVN ) { |
duke@435 | 1402 | for ( int i = 0; i < _verify_window_size; i++ ) { |
duke@435 | 1403 | if ( _verify_window[i] == old ) |
duke@435 | 1404 | _verify_window[i] = nn; |
duke@435 | 1405 | } |
duke@435 | 1406 | } |
duke@435 | 1407 | #endif |
duke@435 | 1408 | _worklist.remove(temp); // this can be necessary |
duke@435 | 1409 | temp->destruct(); // reuse the _idx of this little guy |
duke@435 | 1410 | } |
duke@435 | 1411 | |
duke@435 | 1412 | //------------------------------add_users_to_worklist-------------------------- |
duke@435 | 1413 | void PhaseIterGVN::add_users_to_worklist0( Node *n ) { |
duke@435 | 1414 | for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { |
duke@435 | 1415 | _worklist.push(n->fast_out(i)); // Push on worklist |
duke@435 | 1416 | } |
duke@435 | 1417 | } |
duke@435 | 1418 | |
shshahma@8893 | 1419 | // Return counted loop Phi if as a counted loop exit condition, cmp |
shshahma@8893 | 1420 | // compares the the induction variable with n |
shshahma@8893 | 1421 | static PhiNode* countedloop_phi_from_cmp(CmpINode* cmp, Node* n) { |
shshahma@8893 | 1422 | for (DUIterator_Fast imax, i = cmp->fast_outs(imax); i < imax; i++) { |
shshahma@8893 | 1423 | Node* bol = cmp->fast_out(i); |
shshahma@8893 | 1424 | for (DUIterator_Fast i2max, i2 = bol->fast_outs(i2max); i2 < i2max; i2++) { |
shshahma@8893 | 1425 | Node* iff = bol->fast_out(i2); |
shshahma@8893 | 1426 | if (iff->is_CountedLoopEnd()) { |
shshahma@8893 | 1427 | CountedLoopEndNode* cle = iff->as_CountedLoopEnd(); |
shshahma@8893 | 1428 | if (cle->limit() == n) { |
shshahma@8893 | 1429 | PhiNode* phi = cle->phi(); |
shshahma@8893 | 1430 | if (phi != NULL) { |
shshahma@8893 | 1431 | return phi; |
shshahma@8893 | 1432 | } |
shshahma@8893 | 1433 | } |
shshahma@8893 | 1434 | } |
shshahma@8893 | 1435 | } |
shshahma@8893 | 1436 | } |
shshahma@8893 | 1437 | return NULL; |
shshahma@8893 | 1438 | } |
shshahma@8893 | 1439 | |
duke@435 | 1440 | void PhaseIterGVN::add_users_to_worklist( Node *n ) { |
duke@435 | 1441 | add_users_to_worklist0(n); |
duke@435 | 1442 | |
duke@435 | 1443 | // Move users of node to worklist |
duke@435 | 1444 | for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { |
duke@435 | 1445 | Node* use = n->fast_out(i); // Get use |
duke@435 | 1446 | |
duke@435 | 1447 | if( use->is_Multi() || // Multi-definer? Push projs on worklist |
duke@435 | 1448 | use->is_Store() ) // Enable store/load same address |
duke@435 | 1449 | add_users_to_worklist0(use); |
duke@435 | 1450 | |
duke@435 | 1451 | // If we changed the receiver type to a call, we need to revisit |
duke@435 | 1452 | // the Catch following the call. It's looking for a non-NULL |
duke@435 | 1453 | // receiver to know when to enable the regular fall-through path |
duke@435 | 1454 | // in addition to the NullPtrException path. |
duke@435 | 1455 | if (use->is_CallDynamicJava() && n == use->in(TypeFunc::Parms)) { |
duke@435 | 1456 | Node* p = use->as_CallDynamicJava()->proj_out(TypeFunc::Control); |
duke@435 | 1457 | if (p != NULL) { |
duke@435 | 1458 | add_users_to_worklist0(p); |
duke@435 | 1459 | } |
duke@435 | 1460 | } |
duke@435 | 1461 | |
roland@7394 | 1462 | uint use_op = use->Opcode(); |
roland@7394 | 1463 | if(use->is_Cmp()) { // Enable CMP/BOOL optimization |
duke@435 | 1464 | add_users_to_worklist(use); // Put Bool on worklist |
duke@435 | 1465 | if (use->outcnt() > 0) { |
duke@435 | 1466 | Node* bol = use->raw_out(0); |
duke@435 | 1467 | if (bol->outcnt() > 0) { |
duke@435 | 1468 | Node* iff = bol->raw_out(0); |
shshahma@8893 | 1469 | if (iff->outcnt() == 2) { |
roland@7394 | 1470 | // Look for the 'is_x2logic' pattern: "x ? : 0 : 1" and put the |
roland@7394 | 1471 | // phi merging either 0 or 1 onto the worklist |
duke@435 | 1472 | Node* ifproj0 = iff->raw_out(0); |
duke@435 | 1473 | Node* ifproj1 = iff->raw_out(1); |
duke@435 | 1474 | if (ifproj0->outcnt() > 0 && ifproj1->outcnt() > 0) { |
duke@435 | 1475 | Node* region0 = ifproj0->raw_out(0); |
duke@435 | 1476 | Node* region1 = ifproj1->raw_out(0); |
duke@435 | 1477 | if( region0 == region1 ) |
duke@435 | 1478 | add_users_to_worklist0(region0); |
duke@435 | 1479 | } |
duke@435 | 1480 | } |
duke@435 | 1481 | } |
duke@435 | 1482 | } |
roland@7394 | 1483 | if (use_op == Op_CmpI) { |
shshahma@8893 | 1484 | Node* phi = countedloop_phi_from_cmp((CmpINode*)use, n); |
shshahma@8893 | 1485 | if (phi != NULL) { |
shshahma@8893 | 1486 | // If an opaque node feeds into the limit condition of a |
shshahma@8893 | 1487 | // CountedLoop, we need to process the Phi node for the |
shshahma@8893 | 1488 | // induction variable when the opaque node is removed: |
shshahma@8893 | 1489 | // the range of values taken by the Phi is now known and |
shshahma@8893 | 1490 | // so its type is also known. |
shshahma@8893 | 1491 | _worklist.push(phi); |
shshahma@8893 | 1492 | } |
roland@7394 | 1493 | Node* in1 = use->in(1); |
roland@7394 | 1494 | for (uint i = 0; i < in1->outcnt(); i++) { |
roland@7394 | 1495 | if (in1->raw_out(i)->Opcode() == Op_CastII) { |
roland@7394 | 1496 | Node* castii = in1->raw_out(i); |
roland@7394 | 1497 | if (castii->in(0) != NULL && castii->in(0)->in(0) != NULL && castii->in(0)->in(0)->is_If()) { |
roland@7394 | 1498 | Node* ifnode = castii->in(0)->in(0); |
roland@7395 | 1499 | if (ifnode->in(1) != NULL && ifnode->in(1)->is_Bool() && ifnode->in(1)->in(1) == use) { |
roland@7394 | 1500 | // Reprocess a CastII node that may depend on an |
roland@7394 | 1501 | // opaque node value when the opaque node is |
roland@7394 | 1502 | // removed. In case it carries a dependency we can do |
roland@7394 | 1503 | // a better job of computing its type. |
roland@7394 | 1504 | _worklist.push(castii); |
roland@7394 | 1505 | } |
roland@7394 | 1506 | } |
roland@7394 | 1507 | } |
roland@7394 | 1508 | } |
roland@7394 | 1509 | } |
duke@435 | 1510 | } |
duke@435 | 1511 | |
duke@435 | 1512 | // If changed Cast input, check Phi users for simple cycles |
kvn@500 | 1513 | if( use->is_ConstraintCast() || use->is_CheckCastPP() ) { |
duke@435 | 1514 | for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { |
duke@435 | 1515 | Node* u = use->fast_out(i2); |
duke@435 | 1516 | if (u->is_Phi()) |
duke@435 | 1517 | _worklist.push(u); |
duke@435 | 1518 | } |
duke@435 | 1519 | } |
duke@435 | 1520 | // If changed LShift inputs, check RShift users for useless sign-ext |
duke@435 | 1521 | if( use_op == Op_LShiftI ) { |
duke@435 | 1522 | for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { |
duke@435 | 1523 | Node* u = use->fast_out(i2); |
duke@435 | 1524 | if (u->Opcode() == Op_RShiftI) |
duke@435 | 1525 | _worklist.push(u); |
duke@435 | 1526 | } |
duke@435 | 1527 | } |
kvn@6679 | 1528 | // If changed AddI/SubI inputs, check CmpU for range check optimization. |
kvn@6679 | 1529 | if (use_op == Op_AddI || use_op == Op_SubI) { |
kvn@6679 | 1530 | for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { |
kvn@6679 | 1531 | Node* u = use->fast_out(i2); |
kvn@6679 | 1532 | if (u->is_Cmp() && (u->Opcode() == Op_CmpU)) { |
kvn@6679 | 1533 | _worklist.push(u); |
kvn@6679 | 1534 | } |
kvn@6679 | 1535 | } |
kvn@6679 | 1536 | } |
duke@435 | 1537 | // If changed AddP inputs, check Stores for loop invariant |
duke@435 | 1538 | if( use_op == Op_AddP ) { |
duke@435 | 1539 | for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { |
duke@435 | 1540 | Node* u = use->fast_out(i2); |
duke@435 | 1541 | if (u->is_Mem()) |
duke@435 | 1542 | _worklist.push(u); |
duke@435 | 1543 | } |
duke@435 | 1544 | } |
duke@435 | 1545 | // If changed initialization activity, check dependent Stores |
duke@435 | 1546 | if (use_op == Op_Allocate || use_op == Op_AllocateArray) { |
duke@435 | 1547 | InitializeNode* init = use->as_Allocate()->initialization(); |
duke@435 | 1548 | if (init != NULL) { |
duke@435 | 1549 | Node* imem = init->proj_out(TypeFunc::Memory); |
duke@435 | 1550 | if (imem != NULL) add_users_to_worklist0(imem); |
duke@435 | 1551 | } |
duke@435 | 1552 | } |
duke@435 | 1553 | if (use_op == Op_Initialize) { |
duke@435 | 1554 | Node* imem = use->as_Initialize()->proj_out(TypeFunc::Memory); |
duke@435 | 1555 | if (imem != NULL) add_users_to_worklist0(imem); |
duke@435 | 1556 | } |
duke@435 | 1557 | } |
duke@435 | 1558 | } |
duke@435 | 1559 | |
roland@5991 | 1560 | /** |
roland@5991 | 1561 | * Remove the speculative part of all types that we know of |
roland@5991 | 1562 | */ |
roland@5991 | 1563 | void PhaseIterGVN::remove_speculative_types() { |
roland@5991 | 1564 | assert(UseTypeSpeculation, "speculation is off"); |
roland@5991 | 1565 | for (uint i = 0; i < _types.Size(); i++) { |
roland@5991 | 1566 | const Type* t = _types.fast_lookup(i); |
roland@6313 | 1567 | if (t != NULL) { |
roland@6313 | 1568 | _types.map(i, t->remove_speculative()); |
roland@5991 | 1569 | } |
roland@5991 | 1570 | } |
roland@6313 | 1571 | _table.check_no_speculative_types(); |
roland@5991 | 1572 | } |
roland@5991 | 1573 | |
duke@435 | 1574 | //============================================================================= |
duke@435 | 1575 | #ifndef PRODUCT |
duke@435 | 1576 | uint PhaseCCP::_total_invokes = 0; |
duke@435 | 1577 | uint PhaseCCP::_total_constants = 0; |
duke@435 | 1578 | #endif |
duke@435 | 1579 | //------------------------------PhaseCCP--------------------------------------- |
duke@435 | 1580 | // Conditional Constant Propagation, ala Wegman & Zadeck |
duke@435 | 1581 | PhaseCCP::PhaseCCP( PhaseIterGVN *igvn ) : PhaseIterGVN(igvn) { |
duke@435 | 1582 | NOT_PRODUCT( clear_constants(); ) |
duke@435 | 1583 | assert( _worklist.size() == 0, "" ); |
duke@435 | 1584 | // Clear out _nodes from IterGVN. Must be clear to transform call. |
duke@435 | 1585 | _nodes.clear(); // Clear out from IterGVN |
duke@435 | 1586 | analyze(); |
duke@435 | 1587 | } |
duke@435 | 1588 | |
duke@435 | 1589 | #ifndef PRODUCT |
duke@435 | 1590 | //------------------------------~PhaseCCP-------------------------------------- |
duke@435 | 1591 | PhaseCCP::~PhaseCCP() { |
duke@435 | 1592 | inc_invokes(); |
duke@435 | 1593 | _total_constants += count_constants(); |
duke@435 | 1594 | } |
duke@435 | 1595 | #endif |
duke@435 | 1596 | |
duke@435 | 1597 | |
duke@435 | 1598 | #ifdef ASSERT |
duke@435 | 1599 | static bool ccp_type_widens(const Type* t, const Type* t0) { |
duke@435 | 1600 | assert(t->meet(t0) == t, "Not monotonic"); |
duke@435 | 1601 | switch (t->base() == t0->base() ? t->base() : Type::Top) { |
duke@435 | 1602 | case Type::Int: |
duke@435 | 1603 | assert(t0->isa_int()->_widen <= t->isa_int()->_widen, "widen increases"); |
duke@435 | 1604 | break; |
duke@435 | 1605 | case Type::Long: |
duke@435 | 1606 | assert(t0->isa_long()->_widen <= t->isa_long()->_widen, "widen increases"); |
duke@435 | 1607 | break; |
duke@435 | 1608 | } |
duke@435 | 1609 | return true; |
duke@435 | 1610 | } |
duke@435 | 1611 | #endif //ASSERT |
duke@435 | 1612 | |
duke@435 | 1613 | //------------------------------analyze---------------------------------------- |
duke@435 | 1614 | void PhaseCCP::analyze() { |
duke@435 | 1615 | // Initialize all types to TOP, optimistic analysis |
duke@435 | 1616 | for (int i = C->unique() - 1; i >= 0; i--) { |
duke@435 | 1617 | _types.map(i,Type::TOP); |
duke@435 | 1618 | } |
duke@435 | 1619 | |
duke@435 | 1620 | // Push root onto worklist |
duke@435 | 1621 | Unique_Node_List worklist; |
duke@435 | 1622 | worklist.push(C->root()); |
duke@435 | 1623 | |
duke@435 | 1624 | // Pull from worklist; compute new value; push changes out. |
duke@435 | 1625 | // This loop is the meat of CCP. |
duke@435 | 1626 | while( worklist.size() ) { |
duke@435 | 1627 | Node *n = worklist.pop(); |
duke@435 | 1628 | const Type *t = n->Value(this); |
duke@435 | 1629 | if (t != type(n)) { |
duke@435 | 1630 | assert(ccp_type_widens(t, type(n)), "ccp type must widen"); |
duke@435 | 1631 | #ifndef PRODUCT |
duke@435 | 1632 | if( TracePhaseCCP ) { |
duke@435 | 1633 | t->dump(); |
duke@435 | 1634 | do { tty->print("\t"); } while (tty->position() < 16); |
duke@435 | 1635 | n->dump(); |
duke@435 | 1636 | } |
duke@435 | 1637 | #endif |
duke@435 | 1638 | set_type(n, t); |
duke@435 | 1639 | for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) { |
duke@435 | 1640 | Node* m = n->fast_out(i); // Get user |
aeriksso@7847 | 1641 | if (m->is_Region()) { // New path to Region? Must recheck Phis too |
duke@435 | 1642 | for (DUIterator_Fast i2max, i2 = m->fast_outs(i2max); i2 < i2max; i2++) { |
duke@435 | 1643 | Node* p = m->fast_out(i2); // Propagate changes to uses |
aeriksso@7847 | 1644 | if (p->bottom_type() != type(p)) { // If not already bottomed out |
duke@435 | 1645 | worklist.push(p); // Propagate change to user |
aeriksso@7847 | 1646 | } |
duke@435 | 1647 | } |
duke@435 | 1648 | } |
twisti@1040 | 1649 | // If we changed the receiver type to a call, we need to revisit |
duke@435 | 1650 | // the Catch following the call. It's looking for a non-NULL |
duke@435 | 1651 | // receiver to know when to enable the regular fall-through path |
duke@435 | 1652 | // in addition to the NullPtrException path |
duke@435 | 1653 | if (m->is_Call()) { |
duke@435 | 1654 | for (DUIterator_Fast i2max, i2 = m->fast_outs(i2max); i2 < i2max; i2++) { |
duke@435 | 1655 | Node* p = m->fast_out(i2); // Propagate changes to uses |
aeriksso@7847 | 1656 | if (p->is_Proj() && p->as_Proj()->_con == TypeFunc::Control && p->outcnt() == 1) { |
duke@435 | 1657 | worklist.push(p->unique_out()); |
aeriksso@7847 | 1658 | } |
duke@435 | 1659 | } |
duke@435 | 1660 | } |
aeriksso@7847 | 1661 | if (m->bottom_type() != type(m)) { // If not already bottomed out |
duke@435 | 1662 | worklist.push(m); // Propagate change to user |
aeriksso@7847 | 1663 | } |
aeriksso@7847 | 1664 | |
aeriksso@7847 | 1665 | // CmpU nodes can get their type information from two nodes up in the |
aeriksso@7847 | 1666 | // graph (instead of from the nodes immediately above). Make sure they |
aeriksso@7847 | 1667 | // are added to the worklist if nodes they depend on are updated, since |
aeriksso@7847 | 1668 | // they could be missed and get wrong types otherwise. |
aeriksso@7847 | 1669 | uint m_op = m->Opcode(); |
aeriksso@7847 | 1670 | if (m_op == Op_AddI || m_op == Op_SubI) { |
aeriksso@7847 | 1671 | for (DUIterator_Fast i2max, i2 = m->fast_outs(i2max); i2 < i2max; i2++) { |
aeriksso@7847 | 1672 | Node* p = m->fast_out(i2); // Propagate changes to uses |
aeriksso@7847 | 1673 | if (p->Opcode() == Op_CmpU) { |
aeriksso@7847 | 1674 | // Got a CmpU which might need the new type information from node n. |
aeriksso@7847 | 1675 | if(p->bottom_type() != type(p)) { // If not already bottomed out |
aeriksso@7847 | 1676 | worklist.push(p); // Propagate change to user |
aeriksso@7847 | 1677 | } |
aeriksso@7847 | 1678 | } |
aeriksso@7847 | 1679 | } |
aeriksso@7847 | 1680 | } |
shshahma@8893 | 1681 | // If n is used in a counted loop exit condition then the type |
shshahma@8893 | 1682 | // of the counted loop's Phi depends on the type of n. See |
shshahma@8893 | 1683 | // PhiNode::Value(). |
shshahma@8893 | 1684 | if (m_op == Op_CmpI) { |
shshahma@8893 | 1685 | PhiNode* phi = countedloop_phi_from_cmp((CmpINode*)m, n); |
shshahma@8893 | 1686 | if (phi != NULL) { |
shshahma@8893 | 1687 | worklist.push(phi); |
shshahma@8893 | 1688 | } |
shshahma@8893 | 1689 | } |
duke@435 | 1690 | } |
duke@435 | 1691 | } |
duke@435 | 1692 | } |
duke@435 | 1693 | } |
duke@435 | 1694 | |
duke@435 | 1695 | //------------------------------do_transform----------------------------------- |
duke@435 | 1696 | // Top level driver for the recursive transformer |
duke@435 | 1697 | void PhaseCCP::do_transform() { |
duke@435 | 1698 | // Correct leaves of new-space Nodes; they point to old-space. |
duke@435 | 1699 | C->set_root( transform(C->root())->as_Root() ); |
duke@435 | 1700 | assert( C->top(), "missing TOP node" ); |
duke@435 | 1701 | assert( C->root(), "missing root" ); |
duke@435 | 1702 | } |
duke@435 | 1703 | |
duke@435 | 1704 | //------------------------------transform-------------------------------------- |
duke@435 | 1705 | // Given a Node in old-space, clone him into new-space. |
duke@435 | 1706 | // Convert any of his old-space children into new-space children. |
duke@435 | 1707 | Node *PhaseCCP::transform( Node *n ) { |
duke@435 | 1708 | Node *new_node = _nodes[n->_idx]; // Check for transformed node |
duke@435 | 1709 | if( new_node != NULL ) |
duke@435 | 1710 | return new_node; // Been there, done that, return old answer |
duke@435 | 1711 | new_node = transform_once(n); // Check for constant |
duke@435 | 1712 | _nodes.map( n->_idx, new_node ); // Flag as having been cloned |
duke@435 | 1713 | |
duke@435 | 1714 | // Allocate stack of size _nodes.Size()/2 to avoid frequent realloc |
zmajo@8068 | 1715 | GrowableArray <Node *> trstack(C->live_nodes() >> 1); |
duke@435 | 1716 | |
duke@435 | 1717 | trstack.push(new_node); // Process children of cloned node |
duke@435 | 1718 | while ( trstack.is_nonempty() ) { |
duke@435 | 1719 | Node *clone = trstack.pop(); |
duke@435 | 1720 | uint cnt = clone->req(); |
duke@435 | 1721 | for( uint i = 0; i < cnt; i++ ) { // For all inputs do |
duke@435 | 1722 | Node *input = clone->in(i); |
duke@435 | 1723 | if( input != NULL ) { // Ignore NULLs |
duke@435 | 1724 | Node *new_input = _nodes[input->_idx]; // Check for cloned input node |
duke@435 | 1725 | if( new_input == NULL ) { |
duke@435 | 1726 | new_input = transform_once(input); // Check for constant |
duke@435 | 1727 | _nodes.map( input->_idx, new_input );// Flag as having been cloned |
duke@435 | 1728 | trstack.push(new_input); |
duke@435 | 1729 | } |
duke@435 | 1730 | assert( new_input == clone->in(i), "insanity check"); |
duke@435 | 1731 | } |
duke@435 | 1732 | } |
duke@435 | 1733 | } |
duke@435 | 1734 | return new_node; |
duke@435 | 1735 | } |
duke@435 | 1736 | |
duke@435 | 1737 | |
duke@435 | 1738 | //------------------------------transform_once--------------------------------- |
duke@435 | 1739 | // For PhaseCCP, transformation is IDENTITY unless Node computed a constant. |
duke@435 | 1740 | Node *PhaseCCP::transform_once( Node *n ) { |
duke@435 | 1741 | const Type *t = type(n); |
duke@435 | 1742 | // Constant? Use constant Node instead |
duke@435 | 1743 | if( t->singleton() ) { |
duke@435 | 1744 | Node *nn = n; // Default is to return the original constant |
duke@435 | 1745 | if( t == Type::TOP ) { |
duke@435 | 1746 | // cache my top node on the Compile instance |
duke@435 | 1747 | if( C->cached_top_node() == NULL || C->cached_top_node()->in(0) == NULL ) { |
duke@435 | 1748 | C->set_cached_top_node( ConNode::make(C, Type::TOP) ); |
duke@435 | 1749 | set_type(C->top(), Type::TOP); |
duke@435 | 1750 | } |
duke@435 | 1751 | nn = C->top(); |
duke@435 | 1752 | } |
duke@435 | 1753 | if( !n->is_Con() ) { |
duke@435 | 1754 | if( t != Type::TOP ) { |
duke@435 | 1755 | nn = makecon(t); // ConNode::make(t); |
duke@435 | 1756 | NOT_PRODUCT( inc_constants(); ) |
duke@435 | 1757 | } else if( n->is_Region() ) { // Unreachable region |
duke@435 | 1758 | // Note: nn == C->top() |
duke@435 | 1759 | n->set_req(0, NULL); // Cut selfreference |
duke@435 | 1760 | // Eagerly remove dead phis to avoid phis copies creation. |
duke@435 | 1761 | for (DUIterator i = n->outs(); n->has_out(i); i++) { |
duke@435 | 1762 | Node* m = n->out(i); |
duke@435 | 1763 | if( m->is_Phi() ) { |
duke@435 | 1764 | assert(type(m) == Type::TOP, "Unreachable region should not have live phis."); |
kvn@1976 | 1765 | replace_node(m, nn); |
duke@435 | 1766 | --i; // deleted this phi; rescan starting with next position |
duke@435 | 1767 | } |
duke@435 | 1768 | } |
duke@435 | 1769 | } |
kvn@1976 | 1770 | replace_node(n,nn); // Update DefUse edges for new constant |
duke@435 | 1771 | } |
duke@435 | 1772 | return nn; |
duke@435 | 1773 | } |
duke@435 | 1774 | |
duke@435 | 1775 | // If x is a TypeNode, capture any more-precise type permanently into Node |
duke@435 | 1776 | if (t != n->bottom_type()) { |
duke@435 | 1777 | hash_delete(n); // changing bottom type may force a rehash |
duke@435 | 1778 | n->raise_bottom_type(t); |
duke@435 | 1779 | _worklist.push(n); // n re-enters the hash table via the worklist |
duke@435 | 1780 | } |
duke@435 | 1781 | |
duke@435 | 1782 | // Idealize graph using DU info. Must clone() into new-space. |
duke@435 | 1783 | // DU info is generally used to show profitability, progress or safety |
duke@435 | 1784 | // (but generally not needed for correctness). |
duke@435 | 1785 | Node *nn = n->Ideal_DU_postCCP(this); |
duke@435 | 1786 | |
duke@435 | 1787 | // TEMPORARY fix to ensure that 2nd GVN pass eliminates NULL checks |
duke@435 | 1788 | switch( n->Opcode() ) { |
duke@435 | 1789 | case Op_FastLock: // Revisit FastLocks for lock coarsening |
duke@435 | 1790 | case Op_If: |
duke@435 | 1791 | case Op_CountedLoopEnd: |
duke@435 | 1792 | case Op_Region: |
duke@435 | 1793 | case Op_Loop: |
duke@435 | 1794 | case Op_CountedLoop: |
duke@435 | 1795 | case Op_Conv2B: |
duke@435 | 1796 | case Op_Opaque1: |
duke@435 | 1797 | case Op_Opaque2: |
duke@435 | 1798 | _worklist.push(n); |
duke@435 | 1799 | break; |
duke@435 | 1800 | default: |
duke@435 | 1801 | break; |
duke@435 | 1802 | } |
duke@435 | 1803 | if( nn ) { |
duke@435 | 1804 | _worklist.push(n); |
duke@435 | 1805 | // Put users of 'n' onto worklist for second igvn transform |
duke@435 | 1806 | add_users_to_worklist(n); |
duke@435 | 1807 | return nn; |
duke@435 | 1808 | } |
duke@435 | 1809 | |
duke@435 | 1810 | return n; |
duke@435 | 1811 | } |
duke@435 | 1812 | |
duke@435 | 1813 | //---------------------------------saturate------------------------------------ |
duke@435 | 1814 | const Type* PhaseCCP::saturate(const Type* new_type, const Type* old_type, |
duke@435 | 1815 | const Type* limit_type) const { |
never@1444 | 1816 | const Type* wide_type = new_type->widen(old_type, limit_type); |
duke@435 | 1817 | if (wide_type != new_type) { // did we widen? |
duke@435 | 1818 | // If so, we may have widened beyond the limit type. Clip it back down. |
duke@435 | 1819 | new_type = wide_type->filter(limit_type); |
duke@435 | 1820 | } |
duke@435 | 1821 | return new_type; |
duke@435 | 1822 | } |
duke@435 | 1823 | |
duke@435 | 1824 | //------------------------------print_statistics------------------------------- |
duke@435 | 1825 | #ifndef PRODUCT |
duke@435 | 1826 | void PhaseCCP::print_statistics() { |
duke@435 | 1827 | tty->print_cr("CCP: %d constants found: %d", _total_invokes, _total_constants); |
duke@435 | 1828 | } |
duke@435 | 1829 | #endif |
duke@435 | 1830 | |
duke@435 | 1831 | |
duke@435 | 1832 | //============================================================================= |
duke@435 | 1833 | #ifndef PRODUCT |
duke@435 | 1834 | uint PhasePeephole::_total_peepholes = 0; |
duke@435 | 1835 | #endif |
duke@435 | 1836 | //------------------------------PhasePeephole---------------------------------- |
duke@435 | 1837 | // Conditional Constant Propagation, ala Wegman & Zadeck |
duke@435 | 1838 | PhasePeephole::PhasePeephole( PhaseRegAlloc *regalloc, PhaseCFG &cfg ) |
duke@435 | 1839 | : PhaseTransform(Peephole), _regalloc(regalloc), _cfg(cfg) { |
duke@435 | 1840 | NOT_PRODUCT( clear_peepholes(); ) |
duke@435 | 1841 | } |
duke@435 | 1842 | |
duke@435 | 1843 | #ifndef PRODUCT |
duke@435 | 1844 | //------------------------------~PhasePeephole--------------------------------- |
duke@435 | 1845 | PhasePeephole::~PhasePeephole() { |
duke@435 | 1846 | _total_peepholes += count_peepholes(); |
duke@435 | 1847 | } |
duke@435 | 1848 | #endif |
duke@435 | 1849 | |
duke@435 | 1850 | //------------------------------transform-------------------------------------- |
duke@435 | 1851 | Node *PhasePeephole::transform( Node *n ) { |
duke@435 | 1852 | ShouldNotCallThis(); |
duke@435 | 1853 | return NULL; |
duke@435 | 1854 | } |
duke@435 | 1855 | |
duke@435 | 1856 | //------------------------------do_transform----------------------------------- |
duke@435 | 1857 | void PhasePeephole::do_transform() { |
duke@435 | 1858 | bool method_name_not_printed = true; |
duke@435 | 1859 | |
duke@435 | 1860 | // Examine each basic block |
adlertz@5539 | 1861 | for (uint block_number = 1; block_number < _cfg.number_of_blocks(); ++block_number) { |
adlertz@5539 | 1862 | Block* block = _cfg.get_block(block_number); |
duke@435 | 1863 | bool block_not_printed = true; |
duke@435 | 1864 | |
duke@435 | 1865 | // and each instruction within a block |
adlertz@5635 | 1866 | uint end_index = block->number_of_nodes(); |
duke@435 | 1867 | // block->end_idx() not valid after PhaseRegAlloc |
duke@435 | 1868 | for( uint instruction_index = 1; instruction_index < end_index; ++instruction_index ) { |
adlertz@5635 | 1869 | Node *n = block->get_node(instruction_index); |
duke@435 | 1870 | if( n->is_Mach() ) { |
duke@435 | 1871 | MachNode *m = n->as_Mach(); |
duke@435 | 1872 | int deleted_count = 0; |
duke@435 | 1873 | // check for peephole opportunities |
duke@435 | 1874 | MachNode *m2 = m->peephole( block, instruction_index, _regalloc, deleted_count, C ); |
duke@435 | 1875 | if( m2 != NULL ) { |
duke@435 | 1876 | #ifndef PRODUCT |
duke@435 | 1877 | if( PrintOptoPeephole ) { |
duke@435 | 1878 | // Print method, first time only |
duke@435 | 1879 | if( C->method() && method_name_not_printed ) { |
duke@435 | 1880 | C->method()->print_short_name(); tty->cr(); |
duke@435 | 1881 | method_name_not_printed = false; |
duke@435 | 1882 | } |
duke@435 | 1883 | // Print this block |
duke@435 | 1884 | if( Verbose && block_not_printed) { |
duke@435 | 1885 | tty->print_cr("in block"); |
duke@435 | 1886 | block->dump(); |
duke@435 | 1887 | block_not_printed = false; |
duke@435 | 1888 | } |
duke@435 | 1889 | // Print instructions being deleted |
duke@435 | 1890 | for( int i = (deleted_count - 1); i >= 0; --i ) { |
adlertz@5635 | 1891 | block->get_node(instruction_index-i)->as_Mach()->format(_regalloc); tty->cr(); |
duke@435 | 1892 | } |
duke@435 | 1893 | tty->print_cr("replaced with"); |
duke@435 | 1894 | // Print new instruction |
duke@435 | 1895 | m2->format(_regalloc); |
duke@435 | 1896 | tty->print("\n\n"); |
duke@435 | 1897 | } |
duke@435 | 1898 | #endif |
duke@435 | 1899 | // Remove old nodes from basic block and update instruction_index |
duke@435 | 1900 | // (old nodes still exist and may have edges pointing to them |
duke@435 | 1901 | // as register allocation info is stored in the allocator using |
duke@435 | 1902 | // the node index to live range mappings.) |
duke@435 | 1903 | uint safe_instruction_index = (instruction_index - deleted_count); |
duke@435 | 1904 | for( ; (instruction_index > safe_instruction_index); --instruction_index ) { |
adlertz@5635 | 1905 | block->remove_node( instruction_index ); |
duke@435 | 1906 | } |
duke@435 | 1907 | // install new node after safe_instruction_index |
adlertz@5635 | 1908 | block->insert_node(m2, safe_instruction_index + 1); |
adlertz@5635 | 1909 | end_index = block->number_of_nodes() - 1; // Recompute new block size |
duke@435 | 1910 | NOT_PRODUCT( inc_peepholes(); ) |
duke@435 | 1911 | } |
duke@435 | 1912 | } |
duke@435 | 1913 | } |
duke@435 | 1914 | } |
duke@435 | 1915 | } |
duke@435 | 1916 | |
duke@435 | 1917 | //------------------------------print_statistics------------------------------- |
duke@435 | 1918 | #ifndef PRODUCT |
duke@435 | 1919 | void PhasePeephole::print_statistics() { |
duke@435 | 1920 | tty->print_cr("Peephole: peephole rules applied: %d", _total_peepholes); |
duke@435 | 1921 | } |
duke@435 | 1922 | #endif |
duke@435 | 1923 | |
duke@435 | 1924 | |
duke@435 | 1925 | //============================================================================= |
duke@435 | 1926 | //------------------------------set_req_X-------------------------------------- |
duke@435 | 1927 | void Node::set_req_X( uint i, Node *n, PhaseIterGVN *igvn ) { |
duke@435 | 1928 | assert( is_not_dead(n), "can not use dead node"); |
duke@435 | 1929 | assert( igvn->hash_find(this) != this, "Need to remove from hash before changing edges" ); |
duke@435 | 1930 | Node *old = in(i); |
duke@435 | 1931 | set_req(i, n); |
duke@435 | 1932 | |
duke@435 | 1933 | // old goes dead? |
duke@435 | 1934 | if( old ) { |
duke@435 | 1935 | switch (old->outcnt()) { |
cfang@1362 | 1936 | case 0: |
cfang@1362 | 1937 | // Put into the worklist to kill later. We do not kill it now because the |
cfang@1362 | 1938 | // recursive kill will delete the current node (this) if dead-loop exists |
duke@435 | 1939 | if (!old->is_top()) |
cfang@1362 | 1940 | igvn->_worklist.push( old ); |
duke@435 | 1941 | break; |
duke@435 | 1942 | case 1: |
duke@435 | 1943 | if( old->is_Store() || old->has_special_unique_user() ) |
duke@435 | 1944 | igvn->add_users_to_worklist( old ); |
duke@435 | 1945 | break; |
duke@435 | 1946 | case 2: |
duke@435 | 1947 | if( old->is_Store() ) |
duke@435 | 1948 | igvn->add_users_to_worklist( old ); |
duke@435 | 1949 | if( old->Opcode() == Op_Region ) |
duke@435 | 1950 | igvn->_worklist.push(old); |
duke@435 | 1951 | break; |
duke@435 | 1952 | case 3: |
duke@435 | 1953 | if( old->Opcode() == Op_Region ) { |
duke@435 | 1954 | igvn->_worklist.push(old); |
duke@435 | 1955 | igvn->add_users_to_worklist( old ); |
duke@435 | 1956 | } |
duke@435 | 1957 | break; |
duke@435 | 1958 | default: |
duke@435 | 1959 | break; |
duke@435 | 1960 | } |
duke@435 | 1961 | } |
duke@435 | 1962 | |
duke@435 | 1963 | } |
duke@435 | 1964 | |
duke@435 | 1965 | //-------------------------------replace_by----------------------------------- |
duke@435 | 1966 | // Using def-use info, replace one node for another. Follow the def-use info |
duke@435 | 1967 | // to all users of the OLD node. Then make all uses point to the NEW node. |
duke@435 | 1968 | void Node::replace_by(Node *new_node) { |
duke@435 | 1969 | assert(!is_top(), "top node has no DU info"); |
duke@435 | 1970 | for (DUIterator_Last imin, i = last_outs(imin); i >= imin; ) { |
duke@435 | 1971 | Node* use = last_out(i); |
duke@435 | 1972 | uint uses_found = 0; |
duke@435 | 1973 | for (uint j = 0; j < use->len(); j++) { |
duke@435 | 1974 | if (use->in(j) == this) { |
duke@435 | 1975 | if (j < use->req()) |
duke@435 | 1976 | use->set_req(j, new_node); |
duke@435 | 1977 | else use->set_prec(j, new_node); |
duke@435 | 1978 | uses_found++; |
duke@435 | 1979 | } |
duke@435 | 1980 | } |
duke@435 | 1981 | i -= uses_found; // we deleted 1 or more copies of this edge |
duke@435 | 1982 | } |
duke@435 | 1983 | } |
duke@435 | 1984 | |
duke@435 | 1985 | //============================================================================= |
duke@435 | 1986 | //----------------------------------------------------------------------------- |
duke@435 | 1987 | void Type_Array::grow( uint i ) { |
duke@435 | 1988 | if( !_max ) { |
duke@435 | 1989 | _max = 1; |
duke@435 | 1990 | _types = (const Type**)_a->Amalloc( _max * sizeof(Type*) ); |
duke@435 | 1991 | _types[0] = NULL; |
duke@435 | 1992 | } |
duke@435 | 1993 | uint old = _max; |
duke@435 | 1994 | while( i >= _max ) _max <<= 1; // Double to fit |
duke@435 | 1995 | _types = (const Type**)_a->Arealloc( _types, old*sizeof(Type*),_max*sizeof(Type*)); |
duke@435 | 1996 | memset( &_types[old], 0, (_max-old)*sizeof(Type*) ); |
duke@435 | 1997 | } |
duke@435 | 1998 | |
duke@435 | 1999 | //------------------------------dump------------------------------------------- |
duke@435 | 2000 | #ifndef PRODUCT |
duke@435 | 2001 | void Type_Array::dump() const { |
duke@435 | 2002 | uint max = Size(); |
duke@435 | 2003 | for( uint i = 0; i < max; i++ ) { |
duke@435 | 2004 | if( _types[i] != NULL ) { |
duke@435 | 2005 | tty->print(" %d\t== ", i); _types[i]->dump(); tty->cr(); |
duke@435 | 2006 | } |
duke@435 | 2007 | } |
duke@435 | 2008 | } |
duke@435 | 2009 | #endif |