src/share/vm/opto/split_if.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 8604
04d83ba48607
child 9448
73d689add964
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

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

mercurial