src/share/vm/opto/split_if.cpp

Fri, 27 Feb 2009 13:27:09 -0800

author
twisti
date
Fri, 27 Feb 2009 13:27:09 -0800
changeset 1040
98cb887364d3
parent 435
a61af66fc99e
child 1607
b2b6a9bf6238
permissions
-rw-r--r--

6810672: Comment typos
Summary: I have collected some typos I have found while looking at the code.
Reviewed-by: kvn, never

duke@435 1 /*
duke@435 2 * Copyright 1999-2006 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #include "incls/_precompiled.incl"
duke@435 26 #include "incls/_split_if.cpp.incl"
duke@435 27
duke@435 28
duke@435 29 //------------------------------split_thru_region------------------------------
duke@435 30 // Split Node 'n' through merge point.
duke@435 31 Node *PhaseIdealLoop::split_thru_region( Node *n, Node *region ) {
duke@435 32 uint wins = 0;
duke@435 33 assert( n->is_CFG(), "" );
duke@435 34 assert( region->is_Region(), "" );
duke@435 35 Node *r = new (C, region->req()) RegionNode( region->req() );
duke@435 36 IdealLoopTree *loop = get_loop( n );
duke@435 37 for( uint i = 1; i < region->req(); i++ ) {
duke@435 38 Node *x = n->clone();
duke@435 39 Node *in0 = n->in(0);
duke@435 40 if( in0->in(0) == region ) x->set_req( 0, in0->in(i) );
duke@435 41 for( uint j = 1; j < n->req(); j++ ) {
duke@435 42 Node *in = n->in(j);
duke@435 43 if( get_ctrl(in) == region )
duke@435 44 x->set_req( j, in->in(i) );
duke@435 45 }
duke@435 46 _igvn.register_new_node_with_optimizer(x);
duke@435 47 set_loop(x, loop);
duke@435 48 set_idom(x, x->in(0), dom_depth(x->in(0))+1);
duke@435 49 r->init_req(i, x);
duke@435 50 }
duke@435 51
duke@435 52 // Record region
duke@435 53 r->set_req(0,region); // Not a TRUE RegionNode
duke@435 54 _igvn.register_new_node_with_optimizer(r);
duke@435 55 set_loop(r, loop);
duke@435 56 if( !loop->_child )
duke@435 57 loop->_body.push(r);
duke@435 58 return r;
duke@435 59 }
duke@435 60
duke@435 61 //------------------------------split_up---------------------------------------
duke@435 62 // Split block-local op up through the phis to empty the current block
duke@435 63 bool PhaseIdealLoop::split_up( Node *n, Node *blk1, Node *blk2 ) {
duke@435 64 if( n->is_CFG() ) {
duke@435 65 assert( n->in(0) != blk1, "Lousy candidate for split-if" );
duke@435 66 return false;
duke@435 67 }
duke@435 68 if( get_ctrl(n) != blk1 && get_ctrl(n) != blk2 )
duke@435 69 return false; // Not block local
duke@435 70 if( n->is_Phi() ) return false; // Local PHIs are expected
duke@435 71
duke@435 72 // Recursively split-up inputs
duke@435 73 for (uint i = 1; i < n->req(); i++) {
duke@435 74 if( split_up( n->in(i), blk1, blk2 ) ) {
duke@435 75 // Got split recursively and self went dead?
duke@435 76 if (n->outcnt() == 0)
duke@435 77 _igvn.remove_dead_node(n);
duke@435 78 return true;
duke@435 79 }
duke@435 80 }
duke@435 81
duke@435 82 // Check for needing to clone-up a compare. Can't do that, it forces
duke@435 83 // another (nested) split-if transform. Instead, clone it "down".
duke@435 84 if( n->is_Cmp() ) {
duke@435 85 assert(get_ctrl(n) == blk2 || get_ctrl(n) == blk1, "must be in block with IF");
duke@435 86 // Check for simple Cmp/Bool/CMove which we can clone-up. Cmp/Bool/CMove
duke@435 87 // sequence can have no other users and it must all reside in the split-if
duke@435 88 // block. Non-simple Cmp/Bool/CMove sequences are 'cloned-down' below -
duke@435 89 // private, per-use versions of the Cmp and Bool are made. These sink to
duke@435 90 // the CMove block. If the CMove is in the split-if block, then in the
duke@435 91 // next iteration this will become a simple Cmp/Bool/CMove set to clone-up.
duke@435 92 Node *bol, *cmov;
duke@435 93 if( !(n->outcnt() == 1 && n->unique_out()->is_Bool() &&
duke@435 94 (bol = n->unique_out()->as_Bool()) &&
duke@435 95 (get_ctrl(bol) == blk1 ||
duke@435 96 get_ctrl(bol) == blk2) &&
duke@435 97 bol->outcnt() == 1 &&
duke@435 98 bol->unique_out()->is_CMove() &&
duke@435 99 (cmov = bol->unique_out()->as_CMove()) &&
duke@435 100 (get_ctrl(cmov) == blk1 ||
duke@435 101 get_ctrl(cmov) == blk2) ) ) {
duke@435 102
duke@435 103 // Must clone down
duke@435 104 #ifndef PRODUCT
duke@435 105 if( PrintOpto && VerifyLoopOptimizations ) {
duke@435 106 tty->print("Cloning down: ");
duke@435 107 n->dump();
duke@435 108 }
duke@435 109 #endif
duke@435 110 // Clone down any block-local BoolNode uses of this CmpNode
duke@435 111 for (DUIterator i = n->outs(); n->has_out(i); i++) {
duke@435 112 Node* bol = n->out(i);
duke@435 113 assert( bol->is_Bool(), "" );
duke@435 114 if (bol->outcnt() == 1) {
duke@435 115 Node* use = bol->unique_out();
duke@435 116 Node *use_c = use->is_If() ? use->in(0) : get_ctrl(use);
duke@435 117 if (use_c == blk1 || use_c == blk2) {
duke@435 118 continue;
duke@435 119 }
duke@435 120 }
duke@435 121 if (get_ctrl(bol) == blk1 || get_ctrl(bol) == blk2) {
duke@435 122 // Recursively sink any BoolNode
duke@435 123 #ifndef PRODUCT
duke@435 124 if( PrintOpto && VerifyLoopOptimizations ) {
duke@435 125 tty->print("Cloning down: ");
duke@435 126 bol->dump();
duke@435 127 }
duke@435 128 #endif
duke@435 129 for (DUIterator_Last jmin, j = bol->last_outs(jmin); j >= jmin; --j) {
duke@435 130 // Uses are either IfNodes or CMoves
duke@435 131 Node* iff = bol->last_out(j);
duke@435 132 assert( iff->in(1) == bol, "" );
duke@435 133 // Get control block of either the CMove or the If input
duke@435 134 Node *iff_ctrl = iff->is_If() ? iff->in(0) : get_ctrl(iff);
duke@435 135 Node *x = bol->clone();
duke@435 136 register_new_node(x, iff_ctrl);
duke@435 137 _igvn.hash_delete(iff);
duke@435 138 iff->set_req(1, x);
duke@435 139 _igvn._worklist.push(iff);
duke@435 140 }
duke@435 141 _igvn.remove_dead_node( bol );
duke@435 142 --i;
duke@435 143 }
duke@435 144 }
duke@435 145 // Clone down this CmpNode
duke@435 146 for (DUIterator_Last jmin, j = n->last_outs(jmin); j >= jmin; --j) {
duke@435 147 Node* bol = n->last_out(j);
duke@435 148 assert( bol->in(1) == n, "" );
duke@435 149 Node *x = n->clone();
duke@435 150 register_new_node(x, get_ctrl(bol));
duke@435 151 _igvn.hash_delete(bol);
duke@435 152 bol->set_req(1, x);
duke@435 153 _igvn._worklist.push(bol);
duke@435 154 }
duke@435 155 _igvn.remove_dead_node( n );
duke@435 156
duke@435 157 return true;
duke@435 158 }
duke@435 159 }
duke@435 160
duke@435 161 // See if splitting-up a Store. Any anti-dep loads must go up as
duke@435 162 // well. An anti-dep load might be in the wrong block, because in
duke@435 163 // this particular layout/schedule we ignored anti-deps and allow
duke@435 164 // memory to be alive twice. This only works if we do the same
duke@435 165 // operations on anti-dep loads as we do their killing stores.
duke@435 166 if( n->is_Store() && n->in(MemNode::Memory)->in(0) == n->in(0) ) {
duke@435 167 // Get store's memory slice
duke@435 168 int alias_idx = C->get_alias_index(_igvn.type(n->in(MemNode::Address))->is_ptr());
duke@435 169
duke@435 170 // Get memory-phi anti-dep loads will be using
duke@435 171 Node *memphi = n->in(MemNode::Memory);
duke@435 172 assert( memphi->is_Phi(), "" );
duke@435 173 // Hoist any anti-dep load to the splitting block;
duke@435 174 // it will then "split-up".
duke@435 175 for (DUIterator_Fast imax,i = memphi->fast_outs(imax); i < imax; i++) {
duke@435 176 Node *load = memphi->fast_out(i);
duke@435 177 if( load->is_Load() && alias_idx == C->get_alias_index(_igvn.type(load->in(MemNode::Address))->is_ptr()) )
duke@435 178 set_ctrl(load,blk1);
duke@435 179 }
duke@435 180 }
duke@435 181
duke@435 182 // Found some other Node; must clone it up
duke@435 183 #ifndef PRODUCT
duke@435 184 if( PrintOpto && VerifyLoopOptimizations ) {
duke@435 185 tty->print("Cloning up: ");
duke@435 186 n->dump();
duke@435 187 }
duke@435 188 #endif
duke@435 189
duke@435 190 // Now actually split-up this guy. One copy per control path merging.
duke@435 191 Node *phi = PhiNode::make_blank(blk1, n);
duke@435 192 for( uint j = 1; j < blk1->req(); j++ ) {
duke@435 193 Node *x = n->clone();
duke@435 194 if( n->in(0) && n->in(0) == blk1 )
duke@435 195 x->set_req( 0, blk1->in(j) );
duke@435 196 for( uint i = 1; i < n->req(); i++ ) {
duke@435 197 Node *m = n->in(i);
duke@435 198 if( get_ctrl(m) == blk1 ) {
duke@435 199 assert( m->in(0) == blk1, "" );
duke@435 200 x->set_req( i, m->in(j) );
duke@435 201 }
duke@435 202 }
duke@435 203 register_new_node( x, blk1->in(j) );
duke@435 204 phi->init_req( j, x );
duke@435 205 }
duke@435 206 // Announce phi to optimizer
duke@435 207 register_new_node(phi, blk1);
duke@435 208
duke@435 209 // Remove cloned-up value from optimizer; use phi instead
duke@435 210 _igvn.hash_delete(n);
duke@435 211 _igvn.subsume_node( n, phi );
duke@435 212
duke@435 213 // (There used to be a self-recursive call to split_up() here,
duke@435 214 // but it is not needed. All necessary forward walking is done
duke@435 215 // by do_split_if() below.)
duke@435 216
duke@435 217 return true;
duke@435 218 }
duke@435 219
duke@435 220 //------------------------------register_new_node------------------------------
duke@435 221 void PhaseIdealLoop::register_new_node( Node *n, Node *blk ) {
duke@435 222 _igvn.register_new_node_with_optimizer(n);
duke@435 223 set_ctrl(n, blk);
duke@435 224 IdealLoopTree *loop = get_loop(blk);
duke@435 225 if( !loop->_child )
duke@435 226 loop->_body.push(n);
duke@435 227 }
duke@435 228
duke@435 229 //------------------------------small_cache------------------------------------
duke@435 230 struct small_cache : public Dict {
duke@435 231
duke@435 232 small_cache() : Dict( cmpkey, hashptr ) {}
duke@435 233 Node *probe( Node *use_blk ) { return (Node*)((*this)[use_blk]); }
duke@435 234 void lru_insert( Node *use_blk, Node *new_def ) { Insert(use_blk,new_def); }
duke@435 235 };
duke@435 236
duke@435 237 //------------------------------spinup-----------------------------------------
duke@435 238 // "Spin up" the dominator tree, starting at the use site and stopping when we
duke@435 239 // find the post-dominating point.
duke@435 240
duke@435 241 // We must be at the merge point which post-dominates 'new_false' and
duke@435 242 // 'new_true'. Figure out which edges into the RegionNode eventually lead up
duke@435 243 // to false and which to true. Put in a PhiNode to merge values; plug in
duke@435 244 // the appropriate false-arm or true-arm values. If some path leads to the
duke@435 245 // original IF, then insert a Phi recursively.
duke@435 246 Node *PhaseIdealLoop::spinup( Node *iff_dom, Node *new_false, Node *new_true, Node *use_blk, Node *def, small_cache *cache ) {
duke@435 247 if (use_blk->is_top()) // Handle dead uses
duke@435 248 return use_blk;
duke@435 249 Node *prior_n = (Node*)0xdeadbeef;
duke@435 250 Node *n = use_blk; // Get path input
duke@435 251 assert( use_blk != iff_dom, "" );
duke@435 252 // Here's the "spinup" the dominator tree loop. Do a cache-check
duke@435 253 // along the way, in case we've come this way before.
duke@435 254 while( n != iff_dom ) { // Found post-dominating point?
duke@435 255 prior_n = n;
duke@435 256 n = idom(n); // Search higher
duke@435 257 Node *s = cache->probe( prior_n ); // Check cache
duke@435 258 if( s ) return s; // Cache hit!
duke@435 259 }
duke@435 260
duke@435 261 Node *phi_post;
duke@435 262 if( prior_n == new_false || prior_n == new_true ) {
duke@435 263 phi_post = def->clone();
duke@435 264 phi_post->set_req(0, prior_n );
duke@435 265 register_new_node(phi_post, prior_n);
duke@435 266 } else {
duke@435 267 // This method handles both control uses (looking for Regions) or data
duke@435 268 // uses (looking for Phis). If looking for a control use, then we need
duke@435 269 // to insert a Region instead of a Phi; however Regions always exist
duke@435 270 // previously (the hash_find_insert below would always hit) so we can
duke@435 271 // return the existing Region.
duke@435 272 if( def->is_CFG() ) {
duke@435 273 phi_post = prior_n; // If looking for CFG, return prior
duke@435 274 } else {
duke@435 275 assert( def->is_Phi(), "" );
duke@435 276 assert( prior_n->is_Region(), "must be a post-dominating merge point" );
duke@435 277
duke@435 278 // Need a Phi here
duke@435 279 phi_post = PhiNode::make_blank(prior_n, def);
duke@435 280 // Search for both true and false on all paths till find one.
duke@435 281 for( uint i = 1; i < phi_post->req(); i++ ) // For all paths
duke@435 282 phi_post->init_req( i, spinup( iff_dom, new_false, new_true, prior_n->in(i), def, cache ) );
duke@435 283 Node *t = _igvn.hash_find_insert(phi_post);
duke@435 284 if( t ) { // See if we already have this one
duke@435 285 // phi_post will not be used, so kill it
duke@435 286 _igvn.remove_dead_node(phi_post);
duke@435 287 phi_post->destruct();
duke@435 288 phi_post = t;
duke@435 289 } else {
duke@435 290 register_new_node( phi_post, prior_n );
duke@435 291 }
duke@435 292 }
duke@435 293 }
duke@435 294
duke@435 295 // Update cache everywhere
duke@435 296 prior_n = (Node*)0xdeadbeef; // Reset IDOM walk
duke@435 297 n = use_blk; // Get path input
duke@435 298 // Spin-up the idom tree again, basically doing path-compression.
duke@435 299 // Insert cache entries along the way, so that if we ever hit this
duke@435 300 // point in the IDOM tree again we'll stop immediately on a cache hit.
duke@435 301 while( n != iff_dom ) { // Found post-dominating point?
duke@435 302 prior_n = n;
duke@435 303 n = idom(n); // Search higher
duke@435 304 cache->lru_insert( prior_n, phi_post ); // Fill cache
duke@435 305 } // End of while not gone high enough
duke@435 306
duke@435 307 return phi_post;
duke@435 308 }
duke@435 309
duke@435 310 //------------------------------find_use_block---------------------------------
duke@435 311 // Find the block a USE is in. Normally USE's are in the same block as the
duke@435 312 // using instruction. For Phi-USE's, the USE is in the predecessor block
duke@435 313 // along the corresponding path.
duke@435 314 Node *PhaseIdealLoop::find_use_block( Node *use, Node *def, Node *old_false, Node *new_false, Node *old_true, Node *new_true ) {
duke@435 315 // CFG uses are their own block
duke@435 316 if( use->is_CFG() )
duke@435 317 return use;
duke@435 318
duke@435 319 if( use->is_Phi() ) { // Phi uses in prior block
duke@435 320 // Grab the first Phi use; there may be many.
twisti@1040 321 // Each will be handled as a separate iteration of
duke@435 322 // the "while( phi->outcnt() )" loop.
duke@435 323 uint j;
duke@435 324 for( j = 1; j < use->req(); j++ )
duke@435 325 if( use->in(j) == def )
duke@435 326 break;
duke@435 327 assert( j < use->req(), "def should be among use's inputs" );
duke@435 328 return use->in(0)->in(j);
duke@435 329 }
duke@435 330 // Normal (non-phi) use
duke@435 331 Node *use_blk = get_ctrl(use);
duke@435 332 // Some uses are directly attached to the old (and going away)
duke@435 333 // false and true branches.
duke@435 334 if( use_blk == old_false ) {
duke@435 335 use_blk = new_false;
duke@435 336 set_ctrl(use, new_false);
duke@435 337 }
duke@435 338 if( use_blk == old_true ) {
duke@435 339 use_blk = new_true;
duke@435 340 set_ctrl(use, new_true);
duke@435 341 }
duke@435 342
duke@435 343 if (use_blk == NULL) { // He's dead, Jim
duke@435 344 _igvn.hash_delete(use);
duke@435 345 _igvn.subsume_node(use, C->top());
duke@435 346 }
duke@435 347
duke@435 348 return use_blk;
duke@435 349 }
duke@435 350
duke@435 351 //------------------------------handle_use-------------------------------------
duke@435 352 // Handle uses of the merge point. Basically, split-if makes the merge point
duke@435 353 // go away so all uses of the merge point must go away as well. Most block
duke@435 354 // local uses have already been split-up, through the merge point. Uses from
duke@435 355 // far below the merge point can't always be split up (e.g., phi-uses are
duke@435 356 // pinned) and it makes too much stuff live. Instead we use a path-based
duke@435 357 // solution to move uses down.
duke@435 358 //
duke@435 359 // If the use is along the pre-split-CFG true branch, then the new use will
duke@435 360 // be from the post-split-CFG true merge point. Vice-versa for the false
duke@435 361 // path. Some uses will be along both paths; then we sink the use to the
duke@435 362 // post-dominating location; we may need to insert a Phi there.
duke@435 363 void PhaseIdealLoop::handle_use( Node *use, Node *def, small_cache *cache, Node *region_dom, Node *new_false, Node *new_true, Node *old_false, Node *old_true ) {
duke@435 364
duke@435 365 Node *use_blk = find_use_block(use,def,old_false,new_false,old_true,new_true);
duke@435 366 if( !use_blk ) return; // He's dead, Jim
duke@435 367
duke@435 368 // Walk up the dominator tree until I hit either the old IfFalse, the old
duke@435 369 // IfTrue or the old If. Insert Phis where needed.
duke@435 370 Node *new_def = spinup( region_dom, new_false, new_true, use_blk, def, cache );
duke@435 371
duke@435 372 // Found where this USE goes. Re-point him.
duke@435 373 uint i;
duke@435 374 for( i = 0; i < use->req(); i++ )
duke@435 375 if( use->in(i) == def )
duke@435 376 break;
duke@435 377 assert( i < use->req(), "def should be among use's inputs" );
duke@435 378 _igvn.hash_delete(use);
duke@435 379 use->set_req(i, new_def);
duke@435 380 _igvn._worklist.push(use);
duke@435 381 }
duke@435 382
duke@435 383 //------------------------------do_split_if------------------------------------
duke@435 384 // Found an If getting its condition-code input from a Phi in the same block.
duke@435 385 // Split thru the Region.
duke@435 386 void PhaseIdealLoop::do_split_if( Node *iff ) {
duke@435 387 #ifndef PRODUCT
duke@435 388 if( PrintOpto && VerifyLoopOptimizations )
duke@435 389 tty->print_cr("Split-if");
duke@435 390 #endif
duke@435 391 C->set_major_progress();
duke@435 392 Node *region = iff->in(0);
duke@435 393 Node *region_dom = idom(region);
duke@435 394
duke@435 395 // We are going to clone this test (and the control flow with it) up through
duke@435 396 // the incoming merge point. We need to empty the current basic block.
duke@435 397 // Clone any instructions which must be in this block up through the merge
duke@435 398 // point.
duke@435 399 DUIterator i, j;
duke@435 400 bool progress = true;
duke@435 401 while (progress) {
duke@435 402 progress = false;
duke@435 403 for (i = region->outs(); region->has_out(i); i++) {
duke@435 404 Node* n = region->out(i);
duke@435 405 if( n == region ) continue;
duke@435 406 // The IF to be split is OK.
duke@435 407 if( n == iff ) continue;
duke@435 408 if( !n->is_Phi() ) { // Found pinned memory op or such
duke@435 409 if (split_up(n, region, iff)) {
duke@435 410 i = region->refresh_out_pos(i);
duke@435 411 progress = true;
duke@435 412 }
duke@435 413 continue;
duke@435 414 }
duke@435 415 assert( n->in(0) == region, "" );
duke@435 416
duke@435 417 // Recursively split up all users of a Phi
duke@435 418 for (j = n->outs(); n->has_out(j); j++) {
duke@435 419 Node* m = n->out(j);
duke@435 420 // If m is dead, throw it away, and declare progress
duke@435 421 if (_nodes[m->_idx] == NULL) {
duke@435 422 _igvn.remove_dead_node(m);
duke@435 423 // fall through
duke@435 424 }
duke@435 425 else if (m != iff && split_up(m, region, iff)) {
duke@435 426 // fall through
duke@435 427 } else {
duke@435 428 continue;
duke@435 429 }
duke@435 430 // Something unpredictable changed.
duke@435 431 // Tell the iterators to refresh themselves, and rerun the loop.
duke@435 432 i = region->refresh_out_pos(i);
duke@435 433 j = region->refresh_out_pos(j);
duke@435 434 progress = true;
duke@435 435 }
duke@435 436 }
duke@435 437 }
duke@435 438
duke@435 439 // Now we have no instructions in the block containing the IF.
duke@435 440 // Split the IF.
duke@435 441 Node *new_iff = split_thru_region( iff, region );
duke@435 442
duke@435 443 // Replace both uses of 'new_iff' with Regions merging True/False
duke@435 444 // paths. This makes 'new_iff' go dead.
duke@435 445 Node *old_false, *old_true;
duke@435 446 Node *new_false, *new_true;
duke@435 447 for (DUIterator_Last j2min, j2 = iff->last_outs(j2min); j2 >= j2min; --j2) {
duke@435 448 Node *ifp = iff->last_out(j2);
duke@435 449 assert( ifp->Opcode() == Op_IfFalse || ifp->Opcode() == Op_IfTrue, "" );
duke@435 450 ifp->set_req(0, new_iff);
duke@435 451 Node *ifpx = split_thru_region( ifp, region );
duke@435 452
duke@435 453 // Replace 'If' projection of a Region with a Region of
duke@435 454 // 'If' projections.
duke@435 455 ifpx->set_req(0, ifpx); // A TRUE RegionNode
duke@435 456
duke@435 457 // Setup dominator info
duke@435 458 set_idom(ifpx, region_dom, dom_depth(region_dom) + 1);
duke@435 459
duke@435 460 // Check for splitting loop tails
duke@435 461 if( get_loop(iff)->tail() == ifp )
duke@435 462 get_loop(iff)->_tail = ifpx;
duke@435 463
duke@435 464 // Replace in the graph with lazy-update mechanism
duke@435 465 new_iff->set_req(0, new_iff); // hook self so it does not go dead
duke@435 466 lazy_replace_proj( ifp, ifpx );
duke@435 467 new_iff->set_req(0, region);
duke@435 468
duke@435 469 // Record bits for later xforms
duke@435 470 if( ifp->Opcode() == Op_IfFalse ) {
duke@435 471 old_false = ifp;
duke@435 472 new_false = ifpx;
duke@435 473 } else {
duke@435 474 old_true = ifp;
duke@435 475 new_true = ifpx;
duke@435 476 }
duke@435 477 }
duke@435 478 _igvn.remove_dead_node(new_iff);
duke@435 479 // Lazy replace IDOM info with the region's dominator
duke@435 480 lazy_replace( iff, region_dom );
duke@435 481
duke@435 482 // Now make the original merge point go dead, by handling all its uses.
duke@435 483 small_cache region_cache;
duke@435 484 // Preload some control flow in region-cache
duke@435 485 region_cache.lru_insert( new_false, new_false );
duke@435 486 region_cache.lru_insert( new_true , new_true );
duke@435 487 // Now handle all uses of the splitting block
duke@435 488 for (DUIterator_Last kmin, k = region->last_outs(kmin); k >= kmin; --k) {
duke@435 489 Node* phi = region->last_out(k);
duke@435 490 if( !phi->in(0) ) { // Dead phi? Remove it
duke@435 491 _igvn.remove_dead_node(phi);
duke@435 492 continue;
duke@435 493 }
duke@435 494 assert( phi->in(0) == region, "" );
duke@435 495 if( phi == region ) { // Found the self-reference
duke@435 496 phi->set_req(0, NULL);
duke@435 497 continue; // Break the self-cycle
duke@435 498 }
duke@435 499 // Expected common case: Phi hanging off of Region
duke@435 500 if( phi->is_Phi() ) {
duke@435 501 // Need a per-def cache. Phi represents a def, so make a cache
duke@435 502 small_cache phi_cache;
duke@435 503
duke@435 504 // Inspect all Phi uses to make the Phi go dead
duke@435 505 for (DUIterator_Last lmin, l = phi->last_outs(lmin); l >= lmin; --l) {
duke@435 506 Node* use = phi->last_out(l);
duke@435 507 // Compute the new DEF for this USE. New DEF depends on the path
duke@435 508 // taken from the original DEF to the USE. The new DEF may be some
duke@435 509 // collection of PHI's merging values from different paths. The Phis
duke@435 510 // inserted depend only on the location of the USE. We use a
duke@435 511 // 2-element cache to handle multiple uses from the same block.
duke@435 512 handle_use( use, phi, &phi_cache, region_dom, new_false, new_true, old_false, old_true );
duke@435 513 } // End of while phi has uses
duke@435 514
duke@435 515 // Because handle_use might relocate region->_out,
duke@435 516 // we must refresh the iterator.
duke@435 517 k = region->last_outs(kmin);
duke@435 518
duke@435 519 // Remove the dead Phi
duke@435 520 _igvn.remove_dead_node( phi );
duke@435 521
duke@435 522 } else {
duke@435 523 // Random memory op guarded by Region. Compute new DEF for USE.
duke@435 524 handle_use( phi, region, &region_cache, region_dom, new_false, new_true, old_false, old_true );
duke@435 525 }
duke@435 526
duke@435 527 } // End of while merge point has phis
duke@435 528
duke@435 529 // Any leftover bits in the splitting block must not have depended on local
duke@435 530 // Phi inputs (these have already been split-up). Hence it's safe to hoist
duke@435 531 // these guys to the dominating point.
duke@435 532 lazy_replace( region, region_dom );
duke@435 533 #ifndef PRODUCT
duke@435 534 if( VerifyLoopOptimizations ) verify();
duke@435 535 #endif
duke@435 536 }

mercurial