split_if.cpp revision 2727
1472N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A//------------------------------split_thru_region------------------------------ 0N/A// Split Node 'n' through merge point. 0N/A//------------------------------split_up--------------------------------------- 0N/A// Split block-local op up through the phis to empty the current block 0N/A return false;
// Not block local 0N/A if( n->
is_Phi() )
return false;
// Local PHIs are expected 0N/A // Recursively split-up inputs 0N/A // Got split recursively and self went dead? 0N/A // Check for needing to clone-up a compare. Can't do that, it forces 0N/A // another (nested) split-if transform. Instead, clone it "down". 0N/A // sequence can have no other users and it must all reside in the split-if 0N/A // private, per-use versions of the Cmp and Bool are made. These sink to 0N/A // the CMove block. If the CMove is in the split-if block, then in the 0N/A // next iteration this will become a simple Cmp/Bool/CMove set to clone-up. 0N/A // Clone down any block-local BoolNode uses of this CmpNode 0N/A // Recursively sink any BoolNode 0N/A // Uses are either IfNodes or CMoves 0N/A // Get control block of either the CMove or the If input 0N/A // Clone down this CmpNode 0N/A // See if splitting-up a Store. Any anti-dep loads must go up as 0N/A // well. An anti-dep load might be in the wrong block, because in 0N/A // memory to be alive twice. This only works if we do the same 0N/A // operations on anti-dep loads as we do their killing stores. 0N/A // Get store's memory slice 0N/A // Get memory-phi anti-dep loads will be using 0N/A // Hoist any anti-dep load to the splitting block; 0N/A // it will then "split-up". 0N/A // Found some other Node; must clone it up 1273N/A // ConvI2L may have type information on it which becomes invalid if 1273N/A // it moves up in the graph so change any clones so widen the type 1273N/A // to TypeLong::INT when pushing it up. 0N/A // Now actually split-up this guy. One copy per control path merging. 1273N/A // Widen the type of the ConvI2L when pushing up. 0N/A // Announce phi to optimizer 0N/A // Remove cloned-up value from optimizer; use phi instead 0N/A // (There used to be a self-recursive call to split_up() here, 0N/A // but it is not needed. All necessary forward walking is done 0N/A // by do_split_if() below.) 0N/A//------------------------------register_new_node------------------------------ 0N/A//------------------------------small_cache------------------------------------ 0N/A//------------------------------spinup----------------------------------------- 0N/A// "Spin up" the dominator tree, starting at the use site and stopping when we 0N/A// find the post-dominating point. 0N/A// We must be at the merge point which post-dominates 'new_false' and 0N/A// 'new_true'. Figure out which edges into the RegionNode eventually lead up 0N/A// to false and which to true. Put in a PhiNode to merge values; plug in 0N/A// the appropriate false-arm or true-arm values. If some path leads to the 0N/A// original IF, then insert a Phi recursively. 0N/A // Here's the "spinup" the dominator tree loop. Do a cache-check 0N/A // along the way, in case we've come this way before. 0N/A while( n !=
iff_dom ) {
// Found post-dominating point? 0N/A if( s )
return s;
// Cache hit! 0N/A // This method handles both control uses (looking for Regions) or data 0N/A // uses (looking for Phis). If looking for a control use, then we need 0N/A // to insert a Region instead of a Phi; however Regions always exist 0N/A // previously (the hash_find_insert below would always hit) so we can 0N/A // return the existing Region. 0N/A // Search for both true and false on all paths till find one. 0N/A if( t ) {
// See if we already have this one 0N/A // phi_post will not be used, so kill it 0N/A // Update cache everywhere 0N/A // Spin-up the idom tree again, basically doing path-compression. 0N/A // Insert cache entries along the way, so that if we ever hit this 0N/A // point in the IDOM tree again we'll stop immediately on a cache hit. 0N/A while( n !=
iff_dom ) {
// Found post-dominating point? 0N/A }
// End of while not gone high enough 0N/A//------------------------------find_use_block--------------------------------- 0N/A// Find the block a USE is in. Normally USE's are in the same block as the 0N/A// using instruction. For Phi-USE's, the USE is in the predecessor block 0N/A// along the corresponding path. 0N/A // CFG uses are their own block 0N/A // Grab the first Phi use; there may be many. 605N/A // Each will be handled as a separate iteration of 0N/A // the "while( phi->outcnt() )" loop. 0N/A // Normal (non-phi) use 0N/A // Some uses are directly attached to the old (and going away) 0N/A // false and true branches. 0N/A//------------------------------handle_use------------------------------------- 0N/A// Handle uses of the merge point. Basically, split-if makes the merge point 0N/A// go away so all uses of the merge point must go away as well. Most block 0N/A// local uses have already been split-up, through the merge point. Uses from 0N/A// far below the merge point can't always be split up (e.g., phi-uses are 0N/A// pinned) and it makes too much stuff live. Instead we use a path-based 0N/A// solution to move uses down. 0N/A// If the use is along the pre-split-CFG true branch, then the new use will 0N/A// be from the post-split-CFG true merge point. Vice-versa for the false 0N/A// path. Some uses will be along both paths; then we sink the use to the 0N/A// post-dominating location; we may need to insert a Phi there. 0N/A // Walk up the dominator tree until I hit either the old IfFalse, the old 0N/A // IfTrue or the old If. Insert Phis where needed. 0N/A // Found where this USE goes. Re-point him. 0N/A//------------------------------do_split_if------------------------------------ 0N/A// Found an If getting its condition-code input from a Phi in the same block. 0N/A// Split thru the Region. 0N/A // We are going to clone this test (and the control flow with it) up through 0N/A // the incoming merge point. We need to empty the current basic block. 0N/A // Clone any instructions which must be in this block up through the merge 0N/A // The IF to be split is OK. 0N/A if( !n->
is_Phi() ) {
// Found pinned memory op or such 0N/A // Recursively split up all users of a Phi 0N/A // If m is dead, throw it away, and declare progress 0N/A // Something unpredictable changed. 0N/A // Tell the iterators to refresh themselves, and rerun the loop. 0N/A // Now we have no instructions in the block containing the IF. 0N/A // Replace both uses of 'new_iff' with Regions merging True/False 0N/A // paths. This makes 'new_iff' go dead. 0N/A // Replace 'If' projection of a Region with a Region of 0N/A // 'If' projections. 0N/A // Setup dominator info 0N/A // Check for splitting loop tails 0N/A // Replace in the graph with lazy-update mechanism 0N/A // Record bits for later xforms 0N/A // Lazy replace IDOM info with the region's dominator 0N/A // Now make the original merge point go dead, by handling all its uses. 0N/A // Preload some control flow in region-cache 0N/A // Now handle all uses of the splitting block 2727N/A continue;
// No roll-back of DUIterator 2727N/A }
else if (
phi->
is_Phi()) {
// Expected common case: Phi hanging off of Region 0N/A // Need a per-def cache. Phi represents a def, so make a cache 0N/A // Inspect all Phi uses to make the Phi go dead 0N/A // Compute the new DEF for this USE. New DEF depends on the path 0N/A // taken from the original DEF to the USE. The new DEF may be some 0N/A // collection of PHI's merging values from different paths. The Phis 0N/A // inserted depend only on the location of the USE. We use a 0N/A // 2-element cache to handle multiple uses from the same block. 0N/A }
// End of while phi has uses 0N/A // Remove the dead Phi 0N/A // Random memory op guarded by Region. Compute new DEF for USE. 2727N/A // Every path above deletes a use of the region, except for the region 2727N/A // self-cycle (which is needed by handle_use calling find_use_block 2727N/A // calling get_ctrl calling get_ctrl_no_update looking for dead 2727N/A // regions). So roll back the DUIterator innards. 2727N/A }
// End of while merge point has phis 0N/A // Any leftover bits in the splitting block must not have depended on local 0N/A // Phi inputs (these have already been split-up). Hence it's safe to hoist 0N/A // these guys to the dominating point.