/*
* 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/connode.hpp"
#include "opto/loopnode.hpp"
#include "opto/rootnode.hpp"
//================= Loop Unswitching =====================
//
// orig: transformed:
// if (invariant-test) then
// predicate predicate
// loop loop
// stmt1 stmt1
// if (invariant-test) then stmt2
// stmt2 stmt4
// else endloop
// stmt3 else
// endif predicate [clone]
// stmt4 loop [clone]
// endloop stmt1 [clone]
// stmt3
// stmt4 [clone]
// endloop
// endif
//
// Note: the "else" clause may be empty
//------------------------------policy_unswitching-----------------------------
// Return TRUE or FALSE if the loop should be unswitched
// (ie. clone loop with an invariant test that does not exit the loop)
if( !LoopUnswitching ) {
return false;
}
return false;
}
return false; // Too speculative if running low on nodes.
}
return false;
}
}
//------------------------------find_unswitching_candidate-----------------------------
// Find candidate "if" for unswitching
// Find first invariant test that doesn't exit the loop
while (n != head) {
if (n->is_Region()) {
// If condition is invariant and not a loop exit,
// then found reason to unswitch.
unswitch_iff = iff;
}
}
}
}
}
n = n_dom;
}
return unswitch_iff;
}
//------------------------------do_unswitching-----------------------------
// Clone loop with an invariant test (that does not exit) and
// insert a clone of the test that selects which version to
// execute.
// Find first invariant test that doesn't exit the loop
#ifndef PRODUCT
if (TraceLoopOpts) {
}
#endif
// Need to revert back to normal loop
}
#ifdef ASSERT
// We may have two predicates, find first.
}
#endif
// Increment unswitch count
// Add test to new "if" outside of loop
// Hoist invariant casts out of each loop to the appropriate
// control projection.
// Copy to a worklist for easier manipulation
}
}
// Same for the clone
}
}
// Hardwire the control paths in the loops into if(true) and if(false)
// Reoptimize loops
loop->record_for_igvn();
}
#ifndef PRODUCT
if (TraceLoopUnswitching) {
}
#endif
C->set_major_progress();
}
//-------------------------create_slow_version_of_loop------------------------
// Create a slow version of the loop by cloning the loop
// and inserting an if to select fast-slow versions.
// Return control projection of the entry to the fast version.
// Clone the loop body. The clone becomes the fast loop. The
// original pre-header will (illegally) have 3 control users
// (old & new loops & new if).
// Fast (true) control
// Slow (false) control
return iffast;
}