/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "memory/allocation.inline.hpp"
#include "opto/addnode.hpp"
#include "opto/connode.hpp"
#include "opto/divnode.hpp"
#include "opto/loopnode.hpp"
#include "opto/matcher.hpp"
#include "opto/mulnode.hpp"
#include "opto/rootnode.hpp"
#include "opto/subnode.hpp"
//=============================================================================
//------------------------------split_thru_phi---------------------------------
// Split Node 'n' through merge point if there is enough win.
// ConvI2L may have type information on it which is unsafe to push up
// so disable this for now
return NULL;
}
int wins = 0;
} else {
}
Node *x;
x = C->top(); // Dead path? Use a dead data op
} else {
x = n->clone(); // Else clone up the data op
the_clone = x; // Remember for possible deletion.
// Alter data node to use pre-phi inputs
}
}
// Check for a 'win' on some paths
// A TOP singleton indicates that there are no possible values incoming
// along a particular edge. In most cases, this is OK, and the Phi will
// be eliminated later in an Ideal call. However, we can't allow this to
// happen if the singleton occurs on loop entry, as the elimination of
// the PhiNode may cause the resulting node to migrate back to a previous
// loop iteration.
// Is_Loop() == false does not confirm the absence of a loop (e.g., an
// irreducible loop may not be indicated by an affirmative is_Loop());
// therefore, the only top we can split thru a phi is on a backedge of
// a loop.
}
if (singleton) {
wins++;
} else {
// We now call Identity to try to simplify the cloned node.
// Note that some Identity methods call phase->type(this).
// Make sure that the type array is big enough for
// our new node, even though we may throw the node away.
// (Note: This tweaking with igvn only works because x is a new node.)
// If x is a TypeNode, capture any more-precise type permanently into Node
// otherwise it will be not updated during igvn->transform since
// igvn->type(x) is set to x->Value() already.
x->raise_bottom_type(t);
if (y != x) {
wins++;
x = y;
} else {
if (y) {
wins++;
x = y;
} else {
// Else x is a new node we are keeping
// We do not need register_new_node_with_optimizer
// because set_type has already been called.
}
}
}
}
// Too few wins?
return NULL;
}
// Record Phi
// If we commoned up the cloned 'x' with another existing Node,
// the existing Node picks up a new use. We need to make the
// existing Node occur higher up so it dominates its uses.
if (x->is_Con()) {
// Constant's control is always root.
continue;
}
// The occasional new node
} else {
}
// New late point must dominate new use
continue;
// Don't move x into a loop if its uses are
// outside of loop. Otherwise x will be cloned
// for each use outside of this loop.
// Take early control, later control will be recalculated
// during next iteration of loop optimizations.
new_ctrl = get_early_ctrl(x);
}
// Set new location
// If changing loop bodies, see if we need to collect into new body
}
}
return phi;
}
//------------------------------dominated_by------------------------------------
// Replace the dominated test with an obvious true or false. Place it on the
// IGVN worklist for later cleanup. Move control-dependent data Nodes on the
// live path up to the dominating control.
void PhaseIdealLoop::dominated_by( Node *prevdom, Node *iff, bool flip, bool exclude_loop_predicate ) {
#ifndef PRODUCT
#endif
// prevdom is the dominating projection of the dominating test.
assert( iff->Opcode() == Op_If || iff->Opcode() == Op_CountedLoopEnd, "Check this code when new subtype is added");
if (flip) {
pop = Op_IfFalse;
else
}
// 'con' is set to true or false to kill the dominated test.
// Hack the dominated test
// If I dont have a reachable TRUE and FALSE path following the IfNode then
// I can assume this path reaches an infinite loop. In this case it's not
// important to optimize the data Nodes - either the whole compilation will
// be tossed or this path (and all data Nodes) will go dead.
// Make control-dependent data Nodes on the live path (path that will remain
// once the dominated IF is removed) become control-dependent on the
// dominating projection.
// Loop predicates may have depending checks which should not
// be skipped. For example, range check predicate has two checks
// for lower and upper bounds.
if (exclude_loop_predicate &&
return; // Let IGVN transformation change control dependence.
if (cd->depends_only_on_test()) {
}
--i;
--imax;
}
}
}
//------------------------------has_local_phi_input----------------------------
// Return TRUE if 'n' has Phi inputs from its local block and no other
// block-local inputs (all non-local-phi inputs come from earlier blocks)
// See if some inputs come from a Phi in this block, or from before
// this block.
uint i;
for( i = 1; i < n->req(); i++ ) {
break;
}
if( i >= n->req() )
return NULL; // No Phi inputs; nowhere to clone thru
// Check for inputs created between 'n' and the Phi input. These
// must split as well; they have already been given the chance
// (courtesy of a post-order visit) and since they did not we must
// recover the 'cost' of splitting them by being very profitable
// when splitting 'n'. Since this is unlikely we simply give up.
for( i = 1; i < n->req(); i++ ) {
// We allow the special case of AddP's with no local inputs.
// This allows us to split-up address expressions.
if (m->is_AddP() &&
// Move the AddP up to dominating point
continue;
}
return NULL;
}
}
return n_ctrl;
}
//------------------------------remix_address_expressions----------------------
// Rework addressing expressions to get the most loop-invariant stuff
// moved out. We'd like to do all associative operators, but it's especially
// important (common) to do address expressions.
// See if 'n' mixes loop-varying and loop-invariant inputs and
// itself is loop-varying.
// Only interested in binary ops (and AddP)
// Does one of my inputs spin in a tighter loop than self?
return NULL; // Leave well enough alone
// Is at least one of my inputs loop-invariant?
return NULL; // No loop-invariant inputs
// Replace expressions like ((V+I) << 2) with (V<<2 + I<<2).
if( n_op == Op_LShiftI ) {
// Scale is loop invariant
return NULL;
// Add must vary with loop (else shift would be loop-invariant)
//assert( n_loop == add_loop, "" );
// Convert I-V into I+ (0-V); same for V-I
}
// See if one add input is loop invariant
if( add_var_loop == n_loop ) {
} else if( add_invar_loop == n_loop ) {
// Swap to find the invariant part
} else // Else neither input is loop invariant
return NULL;
return NULL; // No invariant part of the add?
// Yes! Reshape address expression!
return var_add;
}
// Replace (I+V) with (V+I)
}
}
// Replace ((I1 +p V) +p I2) with ((I1 +p I2) +p V),
// but not if I2 is a constant.
// Stuff new AddP in the loop preheader
return add2;
}
}
}
// Replace (I1 +p (I2 + V)) with ((I1 +p I2) +p V)
} else {
}
// Stuff new AddP in the loop preheader
return add2;
}
}
}
}
return NULL;
}
//------------------------------conditional_move-------------------------------
// Attempt to replace a Phi with a conditional move. We have some pretty
// strict profitability requirements. All Phis at the merge point must
// be converted, so we can remove the control flow. We need to limit the
// number of c-moves to a small handful. All code that was in the side-arms
// of the CFG diamond is now speculatively executed. This code has to be
// "cheap enough". We are pretty much limited to CFG diamonds that merge
// 1 or 2 items with a total of 1 or 2 ops executed speculatively.
// Check for CFG diamond
// Check for ops pinned in an arm of the diamond.
// Can't remove the control flow in this case
// Always convert to CMOVE if all results are used only outside this loop.
// Check profitability
int cost = 0;
int phis = 0;
phis++;
switch (bt) {
case T_FLOAT:
case T_DOUBLE: {
break;
}
case T_LONG: {
}
case T_INT: // These all CMOV fine
case T_ADDRESS: { // (RawPtr)
cost++;
break;
}
case T_NARROWOOP: // Fall through
case T_OBJECT: { // Base oops are OK, but not derived oops
// Derived pointers are Bad (tm): what's the Base (for GC purposes) of a
// CMOVE'd derived pointer? It's a CMOVE'd derived base. Thus
// CMOVE'ing a derived pointer requires we also CMOVE the base. If we
// have a Phi for the base here that we convert to a CMOVE all is well
// and good. But if the base is dead, we'll not make a CMOVE. Later
// the allocator will have to produce a base by creating a CMOVE of the
// relevant bases. This puts the allocator in the business of
// manufacturing expensive instructions, generally a bad plan.
// Just Say No to Conditionally-Moved Derived Pointers.
return NULL;
cost++;
break;
}
default:
return NULL; // In particular, can't do memory or I/O
}
// Add in cost any speculative ops
cost++;
// Check for a chain of dependent ops; these will all become
// speculative in a CMOV.
}
}
// This will likely Split-If, a higher-payoff operation.
// Is there a use inside the loop?
// Note: check only basic types since CMoveP is pinned.
used_inside_loop = true;
}
}
}
}
// It is expensive to generate flags from a float compare.
// Avoid duplicated float compare.
// Ignore cost and blocks frequency if CMOVE can be moved outside the loop.
if (used_inside_loop) {
// BlockLayoutByFrequency optimization moves infrequent branch
// from hot path. No point in CMOV'ing in such case (110 is used
// instead of 100 to take into account not exactness of float value).
if (BlockLayoutByFrequency) {
}
}
// Check for highly predictable branch. No point in CMOV'ing if
// we are going to predict accurately all the time.
return NULL;
// --------------
// Now replace all Phis with CMOV's
while (1) {
break;
}
}
#ifndef PRODUCT
#endif
// Move speculative ops
#ifndef PRODUCT
if (PrintOpto && VerifyLoopOptimizations) {
}
#endif
}
}
Node *cmov = CMoveNode::make( C, cmov_ctrl, iff->in(1), phi->in(1+flip), phi->in(2-flip), _igvn.type(phi) );
#ifndef PRODUCT
if (TraceLoopOpts) {
if (Verbose) {
}
}
if (VerifyLoopOptimizations) verify();
#endif
}
// The useless CFG diamond will fold up later; see the optimization in
// RegionNode::Ideal.
}
//------------------------------split_if_with_blocks_pre-----------------------
// Do the real work in a non-recursive function. Data nodes want to be
// cloned in the pre-order so they can feed each other nicely.
// Cloning these guys is unlikely to win
if( n_op == Op_MergeMem ) return n;
if( n->is_Proj() ) return n;
// Do not clone-up CmpFXXX variations, as these are always
// followed by a CmpI
if( n->is_Cmp() ) return n;
}
if( n->is_CFG() || n->is_LoadStore() )
return n;
n_op == Op_Opaque2 ) {
if( !C->major_progress() ) // If chance of no more loop opts...
return n;
}
if( n->is_Con() ) return n; // No cloning for Con nodes
if( !n_ctrl ) return n; // Dead node
// Attempt to remix address expressions for loop invariants
Node *m = remix_address_expressions( n );
if( m ) return m;
// Determine if the Node has inputs from some local Phi.
// Returns the block to clone thru.
if( !n_blk ) return n;
// Do not clone the trip counter through on a CountedLoop
// (messes up the canonical shape).
// Check for having no control input; not pinned. Allow
// dominating control.
if( n->in(0) ) {
return n;
}
// Policy: when is it profitable. You must get more wins than
// policy before it is considered profitable. Policy is usually 0,
// so 1 win is considered profitable. Big merges will require big
// cloning, so get a larger policy.
// If the loop is a candidate for range check elimination,
// delay splitting through it's phi until a later loop optimization
if (n_blk->is_CountedLoop()) {
return n;
}
}
// Use same limit as split_if_with_blocks_post
// Split 'n' through the merge point if it is profitable
if (!phi) return n;
// Found a Phi to split thru!
// Replace 'n' with the new phi
// Moved a load around the loop, 'en-registering' something.
C->set_major_progress();
return phi;
}
// Bail out if the region and its phis have too many users.
int weight = 0;
}
#ifndef PRODUCT
if (PrintOpto)
#endif
return true;
} else {
return false;
}
}
// 4799512: Stop split_if_with_blocks from splitting a block with a ConvI2LNode
// having a PhiNode input. This sidesteps the dangerous case where the split
// ConvI2LNode may become TOP if the input Value() does not
// overlap the ConvI2L range, leaving a node which may not dominate its
// uses.
// A better fix for this problem can be found in the BugTraq entry, but
// expediency for Mantis demands this hack.
// 6855164: If the merge point has a FastLockNode with a PhiNode input, we stop
// split_if_with_blocks from splitting a block because we could not move around
// the FastLockNode.
if (n->is_Phi()) {
if (m->is_FastLock())
return false;
#ifdef _LP64
if (m->Opcode() == Op_ConvI2L)
return false;
#endif
}
}
}
return true;
}
//------------------------------place_near_use---------------------------------
// Place some computation next to use but not inside inner loops.
// For inner loop uses move it to the preheader area.
? useblock
}
//------------------------------split_if_with_blocks_post----------------------
// Do the real work in a non-recursive function. CFG hackery wants to be
// in the post-order, so it can dirty the I-DOM info and not use the dirtied
// info.
// Cloning Cmp through Phi's involves the split-if transform.
// FastLock is not used by an If
if( n->is_Cmp() && !n->is_FastLock() ) {
// Do not do 'split-if' if irreducible loops are present.
if( _has_irreducible_loops )
return;
// Determine if the Node has inputs from some local Phi.
// Returns the block to clone thru.
if( merge_point_too_heavy(C, n_ctrl) )
return;
// Check some safety conditions
// Can't split CMove with different control edge.
return; // Inputs not yet split-up
return; // Loop-invar test gates loop-varying CMOVE
}
} else {
return; // some other kind of node, such as an Allocate
}
// Do not do 'split-if' if some paths are dead. First do dead code
// elimination and then see if its still profitable.
return;
// When is split-if profitable? Every 'win' on means some control flow
// goes dead, so it's almost always a win.
int policy = 0;
// If trying to do a 'Split-If' at the loop head, it is only
// profitable if the cmp folds up on BOTH paths. Otherwise we
// risk peeling a loop forever.
// CNC - Disabled for now. Requires careful handling of loop
// body selection for the cloned code. Also, make sure we check
// for any input path not being in the same loop as n_ctrl. For
// irreducible loops we cannot check for 'n_ctrl->is_Loop()'
// because the alternative loop entry points won't be converted
// into LoopNodes.
return;
// Check for safety of the merge point.
if( !merge_point_safe(n_ctrl) ) {
return;
}
// Split compare 'n' through the merge point if it is profitable
if( !phi ) return;
// Found a Phi to split thru!
// Replace 'n' with the new phi
// Now split the bool up thru the phi
return;
// Conditional-move? Must split up now
return;
}
// Now split the IF
do_split_if( iff );
return;
}
// Check for an IF ready to split; one that has its
// condition codes input coming from a Phi at the block start.
// Check for an IF being dominated by another IF same test
// Check for same test used more than once?
// Search up IDOMs to see if this IF is dominated.
// Now search up IDOMs till cutoff, looking for a dominating test
// Replace the dominated test with an obvious true or false.
// Place it on the IGVN worklist for later cleanup.
C->set_major_progress();
dominated_by( prevdom, n, false, true );
#ifndef PRODUCT
if( VerifyLoopOptimizations ) verify();
#endif
return;
}
}
}
}
// See if a shared loop-varying computation has no loop-varying uses.
// Happens if something is only used for JVM state in uncommon trap exits,
// like various versions of induction variable+offset. Clone the
// computation per usage to allow it to sink out of the loop.
if( n_loop != _ltree_root ) {
for (; i < imax; i++) {
if( !has_ctrl(u) ) break; // Found control user
}
if (n->is_Load()) {
// If n is a load, get and save the result from get_late_ctrl(),
// to be later used in calculating the control for n's clones.
}
// If n is a load, and the late control is the same as the current
// control, then the cloning of n is a pointless exercise, because
// GVN will ensure that we end up where we started.
if( u->is_Phi() ) {
// Replace all uses of normal nodes. Replace Phi uses
// individually, so the separate Nodes can sink down
// different paths.
uint k = 1;
while( u->in(k) != n ) k++;
u->set_req( k, x );
// x goes next to Phi input path
--j;
} else { // Normal use
// Replace all uses
if( u->in(k) == n ) {
u->set_req( k, x );
--j;
}
}
}
// Find control for 'x' next to use but not inside inner loops.
// For inner loop uses get the preheader area.
if (n->is_Load()) {
// For loads, add a control edge to a CFG node outside of the loop
// to force them to not combine and return back inside the loop
// during GVN optimization (4641526).
//
// Because we are setting the actual control input, factor in
// the result from get_late_ctrl() so we respect any
// anti-dependences. (6233005).
// Don't allow the control input to be a CFG splitting node.
// Such nodes should only have ProjNodes as outs, e.g. IfNode
// should only have IfTrueNode and IfFalseNode (4985384).
}
register_new_node(x, x_ctrl);
// Some institutional knowledge is needed here: 'x' is
// yanked because if the optimizer runs GVN on it all the
// cloned x's will common up and undo this optimization and
// be forced back in the loop. This is annoying because it
// makes +VerifyOpto report false-positives on progress. I
// tried setting control edges on the x's to force them to
// not combine, but the matching gets worried when it tries
// to fold a StoreP and an AddP together (as part of an
// address expression) and the AddP and StoreP have
// different controls.
}
}
}
}
}
// Check for Opaque2's who's loop has disappeared - who's input is in the
// same loop nest as their output. Remove 'em, they are no longer useful.
if( n_op == Op_Opaque2 &&
}
}
//------------------------------split_if_with_blocks---------------------------
// Check for aggressive application of 'split-if' optimization,
// using basic block level info.
// Do pre-visit work for root
n = split_if_with_blocks_pre( n );
uint i = 0;
while (true) {
// Visit all children
if (i < cnt) {
++i;
// Now do pre-visit work for this use
n = use; // Process all children of current use.
i = 0;
}
}
else {
// All of n's children have been processed, complete post-processing.
}
// Finished all nodes on stack.
break;
}
// Get saved parent node and next use's index. Visit the rest of uses.
}
}
}
//=============================================================================
//
// C L O N E A L O O P B O D Y
//
//------------------------------clone_iff--------------------------------------
// "Nearly" because all Nodes have been cloned from the original in the loop,
// through the Phi recursively, and return a Bool.
// Convert this Phi into a Phi merging Bools
uint i;
if( b->is_Phi() ) {
} else {
}
}
// Make Phis to merge the Cmp's inputs.
}
// See if these Phis have been made before.
// Register with optimizer
if( hit1 ) { // Hit, toss just made Phi
} else { // Miss
}
if( hit2 ) { // Hit, toss just made Phi
} else { // Miss
}
// Make a new Cmp
// Make a new Bool
return (BoolNode*)b;
}
//------------------------------clone_bool-------------------------------------
// "Nearly" because all Nodes have been cloned from the original in the loop,
// through the Phi recursively, and return a Bool.
uint i;
// Convert this Phi into a Phi merging Bools
if( b->is_Phi() ) {
} else {
}
}
// Make Phis to merge the Cmp's inputs.
} else {
}
}
// See if these Phis have been made before.
// Register with optimizer
if( hit1 ) { // Hit, toss just made Phi
} else { // Miss
}
if( hit2 ) { // Hit, toss just made Phi
} else { // Miss
}
// Make a new Cmp
}
//------------------------------sink_use---------------------------------------
// If 'use' was in the loop-exit block, it now needs to be sunk
// below the post-loop merge point.
}
}
//------------------------------clone_loop-------------------------------------
//
// C L O N E A L O O P B O D Y
//
// This is the basic building block of the loop optimizations. It clones an
// entire loop body. It makes an old_new loop body mapping; with this mapping
// you can find the new-loop equivalent to an old-loop node. All new-loop
// nodes are exactly equal to their old-loop counterparts, all edges are the
// same. All exits from the old-loop now have a RegionNode that merges the
// equivalent new-loop path. This is true even for the normal "loop-exit"
// condition. All uses of loop-invariant old-loop values now come from (one
// or more) Phis that merge their new-loop equivalents.
//
// This operation leaves the graph in an illegal state: there are two valid
// control edges coming from the loop pre-header to both loop bodies. I'll
// definitely have to hack the graph after running this transform.
//
// From this building block I will further edit edges to perform loop peeling
// or loop unrolling or iteration splitting (Range-Check-Elimination), etc.
//
// Parameter side_by_size_idom:
// When side_by_size_idom is NULL, the dominator tree is constructed for
// the clone loop to dominate the original. Used in construction of
// pre-main-post loop sequence.
// When nonnull, the clone and original are side-by-side, both are
// dominated by the side_by_side_idom node. Used in construction of
// unswitched loops.
// Step 1: Clone the loop body. Make the old->new mapping.
uint i;
}
// Step 2: Fix the edges in the new body. If the old input is outside the
// loop use it. If the old input is INside the loop, use the corresponding
// new node instead.
} else {
}
}
// Correct edges to the new node
if( n ) {
}
}
}
// Step 3: Now fix control uses. Loop varying control uses have already
// been fixed up (as part of all input edges in Step 2). Loop invariant
// control uses must be either an IfFalse or an IfTrue. Make a merge
// refer to this.
// Copy uses to a worklist, so I can munge the def-use info
// with impunity.
// Both OLD and USE are CFG nodes here.
// Clone the loop exit control projection
// We need a Region to merge the exit from the peeled body and the
// exit from the old loop body.
// Map the old use to the new merge point
// The original user of 'use' uses 'r' instead.
uses_found++;
}
}
uses_found++;
}
}
l -= uses_found; // we deleted 1 or more copies of this edge
}
// Now finish up 'r'
} // End of if a loop-exit test
}
}
// Step 4: If loop-invariant use is not control, it must be dominated by a
// there if needed. Make a Phi there merging old and new used values.
// Copy uses to a worklist, so I can munge the def-use info
// with impunity.
// Check for data-use outside of loop - at least one of OLD or USE
// must not be a CFG node.
// If the Data use is an IF, that means we have an IF outside of the
// loop that is switching on a condition that is set inside of the
// loop. Happens if people set a loop-exit flag; then test the flag
// in the loop to break the loop, then test is again outside of the
// loop to determine which way the loop exited.
// Since this code is highly unlikely, we lazily build the worklist
// of such Nodes to go split.
if( !split_if_set )
}
if( !split_bool_set )
}
if( !split_cex_set )
}
// Get "block" use is in
continue;
}
}
// If the use occurs after merging several exits from the loop, then
// old value must have dominated all those exits. Since the same old
// value was used on all those exits we did not need a Phi at this
// merge point. NOW we do need a Phi here. Each loop exit value
// is now merged with the peeled body exit; each exit gets its own
// private Phi and those Phis need to be merged here.
if( idx == 0 ) { // Updating control edge?
} else { // Else need a new Phi
// Now recursively fix up the new uses of old!
}
}
} else {
// Get new RegionNode merging old and new loop exits
if( idx == 0 ) { // Updating control edge?
} else { // Else need a new Phi
// Make a new Phi merging data values properly
}
}
// If inserting a new Phi, check for prior hits
if( idx != 0 ) {
} else { // or
// Remove the new phi from the graph and use the hit
}
}
// Make 'use' use the Phi instead of the old loop body exit value
// Not needed for correctness, but prevents a weak assert
// in AddPNode from tripping (when we end up with different
// base & derived Phis that will become the same after
// IGVN does CSE).
if( hit ) // Go ahead and re-hash for hits.
}
// If 'use' was in the loop-exit block, it now needs to be sunk
// below the post-loop merge point.
}
}
}
// the loop uses a condition set in the loop. The original IF probably
// takes control from one or more OLD Regions (which in turn get from NEW
// Regions). In any case, there will be a set of Phis for each merge point
// from the IF up to where the original BOOL def exists the loop.
if( split_if_set ) {
while( split_if_set->size() ) {
}
}
}
if( split_bool_set ) {
while( split_bool_set->size() ) {
}
}
if( split_cex_set ) {
while( split_cex_set->size() ) {
}
}
}
//---------------------- stride_of_possible_iv -------------------------------------
// being a cycle involving an add and a phi,
// with an optional truncation (left-shift followed by a right-shift)
// of the add. Returns zero if not an iv.
return 0;
}
return 0;
}
// Must have an invariant operand
return 0;
}
// (If (Bool (CmpX phi:(Phi ...(Optional-trunc(AddI phi add2))) )))
break;
}
}
} else {
// (If (Bool (CmpX addtrunc:(Optional-trunc((AddI (Phi ...addtrunc...) add2)) )))
break;
}
}
}
}
}
}
return 0;
}
//---------------------- stay_in_loop -------------------------------------
// Return the (unique) control output node that's in the loop (if it exists.)
if (!n) return NULL;
return NULL;
}
}
}
return unique;
}
//------------------------------ register_node -------------------------------------
// Utility to register node "n" with PhaseIdealLoop
if (n->is_CFG()) {
} else {
}
}
//------------------------------ proj_clone -------------------------------------
// Utility to create an if-projection
return c;
}
//------------------------------ short_circuit_if -------------------------------------
// Force the iff control output to be the live_proj
if (iff) {
}
return con;
}
//------------------------------ insert_if_before_proj -------------------------------------
// Insert a new if before an if projection (* - new node)
//
// before
// if(test)
// / \
// v v
// other-proj proj (arg)
//
// after
// if(test)
// / \
// / v
// | * proj-clone
// v |
// other-proj v
// * new_if(relop(cmp[IU](left,right)))
// / \
// v v
// * new-proj proj
// (returned)
//
ProjNode* PhaseIdealLoop::insert_if_before_proj(Node* left, bool Signed, BoolTest::mask relop, Node* right, ProjNode* proj) {
return new_exit;
}
//------------------------------ insert_region_before_proj -------------------------------------
// Insert a region before an if projection (* - new node)
//
// before
// if(test)
// / |
// v |
// proj v
// other-proj
//
// after
// if(test)
// / |
// v |
// * proj-clone v
// | other-proj
// v
// * new-region
// |
// v
// * dum_if
// / \
// v \
// * dum-proj v
// proj
//
return reg;
}
//------------------------------ insert_cmpi_loop_exit -------------------------------------
// Clone a signed compare loop exit from an unsigned compare and
// insert it before the unsigned cmp on the stay-in-loop path.
// All new nodes inserted in the dominator tree between the original
// if and it's projections. The original if test is replaced with
// a constant to force the stay-in-loop path.
//
// This is done to make sure that the original if and it's projections
// still dominate the same set of control nodes, that the ctrl() relation
// from data nodes to them is preserved, and that their loop nesting is
// preserved.
//
// before
// if(i <u limit) unsigned compare loop exit
// / |
// v v
// exit-proj stay-in-loop-proj
//
// after
// if(stay-in-loop-const) original if
// / |
// / v
// / if(i < limit) new signed test
// / / |
// / / v
// / / if(i <u limit) new cloned unsigned test
// / / / |
// v v v |
// region |
// | |
// dum-if |
// / | |
// ether | |
// v v
// exit-proj stay-in-loop-proj
//
const bool Signed = true;
const bool Unsigned = false;
if (stride > 0) {
} else {
}
// Create a new region on the exit path
// Clone the if-cmpu-true-false using a signed compare
// Clone the if-cmpu-true-false
ProjNode* cmpu_exit = insert_if_before_proj(cmpu->in(1), Unsigned, rel_u, cmpu->in(2), lp_continue);
// Force original if to stay in loop.
}
//------------------------------ remove_cmpi_loop_exit -------------------------------------
// Remove a previously inserted signed compare loop exit.
}
//------------------------------ scheduled_nodelist -------------------------------------
// Create a post order schedule of nodes that are in the
// "member" set. The list is returned in "sched".
// The first node in "sched" is the loop head, followed by
// nodes which have no inputs in the "member" set, and then
// followed by the nodes that have an immediate input dependence
// on a node in "sched".
void PhaseIdealLoop::scheduled_nodelist( IdealLoopTree *loop, VectorSet& member, Node_List &sched ) {
// Initially push all with no inputs from within member set
bool found = false;
found = true;
break;
}
}
n = elt;
}
}
}
// traverse out's that are in the member set
while (true) {
idx++;
n = use;
idx = 0;
}
}
} else {
// All outputs processed
}
}
}
//------------------------------ has_use_in_set -------------------------------------
// Has a use in the vector set
return true;
}
}
return false;
}
//------------------------------ has_use_internal_to_set -------------------------------------
// Has use internal to the vector set (ie. not in a phi at the loop head)
return true;
}
}
return false;
}
//------------------------------ clone_for_use_outside_loop -------------------------------------
// clone "n" for uses that are outside of loop
int PhaseIdealLoop::clone_for_use_outside_loop( IdealLoopTree *loop, Node* n, Node_List& worklist ) {
int cloned = 0;
}
}
uint j;
}
// clone "n" and insert it between the inputs of "n" and the use outside the loop
cloned++;
} else {
// Use in a phi is considered a use in the associated predecessor block
}
#if !defined(PRODUCT)
if (TracePartialPeeling) {
tty->print_cr("loop exit cloning old: %d new: %d newbb: %d", n->_idx, n_clone->_idx, get_ctrl(n_clone)->_idx);
}
#endif
}
return cloned;
}
//------------------------------ clone_for_special_use_inside_loop -------------------------------------
// clone "n" for special uses that are in the not_peeled region.
// If these def-uses occur in separate blocks, the code generator
// marks the method as not compilable. For example, if a "BoolNode"
// is in a different basic block than the "IfNode" that uses it, then
// the compilation is aborted in the code generator.
return;
}
}
}
// clone "n" and insert it between inputs of "n" and the use
#if !defined(PRODUCT)
if (TracePartialPeeling) {
}
#endif
}
}
}
}
}
//------------------------------ insert_phi_for_loop -------------------------------------
// Insert phi(lp_entry_val, back_edge_val) at use->in(idx) for loop lp if phi does not already exist
void PhaseIdealLoop::insert_phi_for_loop( Node* use, uint idx, Node* lp_entry_val, Node* back_edge_val, LoopNode* lp ) {
// Use existing phi if it already exists
} else {
// Remove the new phi from the graph and use the hit
}
}
#ifdef ASSERT
//------------------------------ is_valid_loop_partition -------------------------------------
// Validate the loop partition sets: peel and not_peel
bool PhaseIdealLoop::is_valid_loop_partition( IdealLoopTree *loop, VectorSet& peel, Node_List& peel_list,
uint i;
// Check that peel_list entries are in the peel set
return false;
}
}
// Check at loop members are in one of peel set or not_peel set
// Check that peel set elements are in peel_list
return false;
}
// Must be in peel_list also
bool found = false;
found = true;
break;
}
}
if (!found) {
return false;
}
return false;
}
} else {
return false;
}
}
return true;
}
//------------------------------ is_valid_clone_loop_exit_use -------------------------------------
// Ensure a use outside of loop is of the right form
}
//------------------------------ is_valid_clone_loop_form -------------------------------------
// Ensure that all uses outside of loop are of the right form
// use is not in the loop, check for correct structure
// Okay
return false;
}
}
}
}
return true;
}
#endif
//------------------------------ partial_peel -------------------------------------
// Partially peel (aka loop rotation) the top portion of a loop (called
// the peel section below) by cloning it and placing one copy just before
// the new loop head and the other copy at the bottom of the new loop.
//
// before after where it came from
//
// stmt1 stmt1
// loop: stmt2 clone
// stmt2 if condA goto exitA clone
// if condA goto exitA new_loop: new
// stmt3 stmt3 clone
// if !condB goto loop if condB goto exitB clone
// exitB: stmt2 orig
// stmt4 if !condA goto new_loop orig
// exitA: goto exitA
// exitB:
// stmt4
// exitA:
//
// Step 1: find the cut point: an exit test on probable
// induction variable.
// Step 2: schedule (with cloning) operations in the peel
// section that can be executed after the cut into
// the section that is not peeled. This may need
// to clone operations into exit blocks. For
// instance, a reference to A[i] in the not-peel
// section and a reference to B[i] in an exit block
// may cause a left-shift of i by 2 to be placed
// in the peel block. This step will clone the left
// shift into the exit block and sink the left shift
// from the peel to the not-peel section.
// Step 3: clone the loop, retarget the control, and insert
// phis for values that are live across the new loop
// head. This is very dependent on the graph structure
// from clone_loop. It creates region nodes for
// exit control and associated phi nodes for values
// flow out of the loop through that exit. The region
// node is dominated by the clone's control projection.
// So the clone's peel section is placed before the
// new loop head, and the clone's not-peel section is
// forms the top part of the new loop. The original
// peel section forms the tail of the new loop.
// Step 4: update the dominator tree and recompute the
// dominator depth.
//
// orig
//
// stmt1
// |
// v
// loop predicate
// |
// v
// loop<----+
// | |
// stmt2 |
// | |
// v |
// ifA |
// / | |
// v v |
// false true ^ <-- last_peel
// / | |
// / ===|==cut |
// / stmt3 | <-- first_not_peel
// / | |
// | v |
// v ifB |
// exitA: / \ |
// / \ |
// v v |
// false true |
// / \ |
// / ----+
// |
// v
// exitB:
// stmt4
//
//
// after clone loop
//
// stmt1
// |
// v
// loop predicate
// / \
// clone / \ orig
// / \
// / \
// v v
// +---->loop loop<----+
// | | | |
// | stmt2 stmt2 |
// | | | |
// | v v |
// | ifA ifA |
// | | \ / | |
// | v v v v |
// ^ true false false true ^ <-- last_peel
// | | ^ \ / | |
// | cut==|== \ \ / ===|==cut |
// | stmt3 \ \ / stmt3 | <-- first_not_peel
// | | dom | | | |
// | v \ 1v v2 v |
// | ifB regionA ifB |
// | / \ | / \ |
// | / \ v / \ |
// | v v exitA: v v |
// | true false false true |
// | / ^ \ / \ |
// +---- \ \ / ----+
// dom \ /
// \ 1v v2
// regionB
// |
// v
// exitB:
// stmt4
//
//
// after partial peel
//
// stmt1
// |
// v
// loop predicate
// /
// clone / orig
// / TOP
// / \
// v v
// TOP->loop loop----+
// | | |
// stmt2 stmt2 |
// | | |
// v v |
// ifA ifA |
// | \ / | |
// v v v v |
// true false false true | <-- last_peel
// | ^ \ / +------|---+
// +->newloop \ \ / === ==cut | |
// | stmt3 \ \ / TOP | |
// | | dom | | stmt3 | | <-- first_not_peel
// | v \ 1v v2 v | |
// | ifB regionA ifB ^ v
// | / \ | / \ | |
// | / \ v / \ | |
// | v v exitA: v v | |
// | true false false true | |
// | / ^ \ / \ | |
// | | \ \ / v | |
// | | dom \ / TOP | |
// | | \ 1v v2 | |
// ^ v regionB | |
// | | | | |
// | | v ^ v
// | | exitB: | |
// | | stmt4 | |
// | +------------>-----------------+ |
// | |
// +-----------------<---------------------+
//
//
// final graph
//
// stmt1
// |
// v
// loop predicate
// |
// v
// stmt2 clone
// |
// v
// ........> ifA clone
// : / |
// dom / |
// : v v
// : false true
// : | |
// : | v
// : | newloop<-----+
// : | | |
// : | stmt3 clone |
// : | | |
// : | v |
// : | ifB |
// : | / \ |
// : | v v |
// : | false true |
// : | | | |
// : | v stmt2 |
// : | exitB: | |
// : | stmt4 v |
// : | ifA orig |
// : | / \ |
// : | / \ |
// : | v v |
// : | false true |
// : | / \ |
// : v v -----+
// RegionA
// |
// v
// exitA
//
return false; }
return false;
}
// Check for complex exit control
if (n->is_Call() ||
opc == Op_CatchProj ||
opc == Op_JumpProj) {
#if !defined(PRODUCT)
if (TracePartialPeeling) {
}
#endif
return false;
}
}
// Step 1: find cut point
// Walk up dominators to loop head looking for first loop exit
// which is executed on every path thru loop.
// If loop-varying exit-test, check for induction variable
} else {
}
}
}
}
// Prefer signed compare over unsigned compare.
return false; // No peel point found
}
if (new_peel_if == NULL) {
return false; // No peel point found
}
}
return false;
}
#if !defined(PRODUCT)
if (TraceLoopOpts) {
}
if (TracePartialPeeling) {
while (true) {
if (t == head) break;
t = idom(t);
}
}
}
#endif
// Set of cfg nodes to peel are those that are executable from
// the head through last_peel.
if (n != last_peel) {
}
}
}
}
// Set of non-cfg nodes to peel are those that are control
// dependent on the cfg nodes.
uint i;
} else {
}
}
// Step 2: move operations from the peeled section down into the
// not-peeled section
// Get a post order schedule of nodes in the peel region
// Result in right-most operand.
// For future check for too many new phis
}
#if !defined(PRODUCT)
if (TracePartialPeeling) {
}
#endif
// Evacuate nodes in peel region into the not_peeled region if possible
#if !defined(PRODUCT)
if (TracePartialPeeling) n->dump();
#endif
bool incr = true;
if ( !n->is_CFG() ) {
if ( has_use_in_set(n, not_peel) ) {
// If not used internal to the peeled region,
// move "n" from peeled to not_peeled region.
// if not pinned and not a load (which maybe anti-dependent on a store)
// and not a CMove (Matcher expects only bool->cmove).
incr = false;
#if !defined(PRODUCT)
if (TracePartialPeeling) {
}
#endif
}
} else {
// Otherwise check for special def-use cases that span
new_phi_cnt++;
}
}
}
if (incr) i++;
}
#if !defined(PRODUCT)
if (TracePartialPeeling) {
}
#endif
if (new_peel_if != NULL) {
}
// Inhibit more partial peeling on this loop
if (cloned_for_outside_use > 0) {
// Terminate this round of loop opts because
// the graph outside this loop was changed.
C->set_major_progress();
return true;
}
return false;
}
// Step 3: clone loop, retarget control, and insert new phis
// Create new loop head for new phis and to hang
// the nodes being moved (sinked) from the peel region.
}
assert(is_valid_clone_loop_form( loop, peel_list, orig_exit_idx, clone_exit_idx ), "bad clone loop");
// Add phi if "def" node is in peel set and "use" is not
}
}
if (n == def) {
// "def" is in peel set, "use" is not in peel set
// or "use" is in the entry boundary (a phi) of the peel set
// use is in loop
}
} else {
// use is not in the loop, check if the live range includes the cut
}
}
}
}
}
}
}
// Step 3b: retarget control
// Redirect control to the new loop head if a cloned node in
// the not_peeled region has control that points into the peeled region.
// This necessary because the cloned peeled region will be outside
// the loop.
// from to
// cloned-peeled <---+
// new_head_clone: | <--+
// cloned-not_peeled in(0) in(0)
// orig-peeled
}
}
// Backedge of the surviving new_head (the clone) is original last_peel
// Cut first node in original not_peel set
new_head->set_req(LoopNode::EntryControl, C->top()); // use rehash_node_delayed / set_req instead of
// Copy head_clone back-branch info to original head
// and remove original head's loop entry and
// clone head's back-branch
// Similarly modify the phis
}
}
// Step 4: update dominator tree and dominator depth
// Inhibit more partial peeling on this loop
C->set_major_progress();
#if !defined(PRODUCT)
if (TracePartialPeeling) {
while (true) {
if (t == head_clone) break;
t = idom(t);
}
}
}
#endif
return true;
}
//------------------------------reorg_offsets----------------------------------
// Reorganize offset computations to lower register pressure. Mostly
// prevent loop-fallout uses of the pre-incremented trip counter (which are
// then alive with the post-incremented trip counter forcing an extra
// register move)
// Perform it only for canonical counted loops.
// Loop's shape could be messed up by iteration_split_impl.
return;
return;
// Check for the special case of folks using the pre-incremented
// trip-counter on the fall-out path (forces the pre-incremented
// and post-incremented trip counter to be live at the same time).
// Fix this by adjusting to use the post-increment trip counter.
bool progress = true;
while (progress) {
progress = false;
}
// Look for loop-invariant use
// Check that use is live out the bottom. Assuming the trip-counter
// update is right at the bottom, uses of of the loop middle are ok.
// Hit! Refactor use to use the post-incremented tripcounter.
// Compute a post-increment tripcounter.
}
// Since DU info changed, rerun loop
progress = true;
break;
}
}
}