/*
* 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 "libadt/vectset.hpp"
#include "memory/allocation.inline.hpp"
#include "opto/c2compiler.hpp"
#include "opto/callnode.hpp"
#include "opto/cfgnode.hpp"
#include "opto/machnode.hpp"
#include "opto/opcodes.hpp"
#include "opto/phaseX.hpp"
#include "opto/rootnode.hpp"
#include "opto/runtime.hpp"
#include "runtime/deoptimization.hpp"
#ifdef TARGET_ARCH_MODEL_x86_32
# include "adfiles/ad_x86_32.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_x86_64
# include "adfiles/ad_x86_64.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_sparc
# include "adfiles/ad_sparc.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_zero
# include "adfiles/ad_zero.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_arm
# include "adfiles/ad_arm.hpp"
#endif
#ifdef TARGET_ARCH_MODEL_ppc
# include "adfiles/ad_ppc.hpp"
#endif
// Portions of code courtesy of Clifford Click
// Optimization - Graph Style
// To avoid float value underflow
//----------------------------schedule_node_into_block-------------------------
// Insert node n into block b. Look for projections of n and make sure they
// are in b also.
// Set basic block of n, Add n to b,
b->add_inst(n);
// After Matching, nearly any old Node may have projections trailing it.
// These are usually machine-dependent flags. In any case, they might
// float to another block below this one. Move them up.
if (buse != b) { // In wrong block?
}
}
}
}
//----------------------------replace_block_proj_ctrl-------------------------
// Nodes that have is_block_proj() nodes as their control need to use
// the appropriate Region for their actual block as their control since
// the projection will be in a predecessor block.
if (p != NULL && p != n) { // Control from a block projection?
assert(!n->pinned() || n->is_MachConstantBase(), "only pinned MachConstantBase node is expected here");
// Find trailing Region
uint j = 0;
// Search for successor
// Find which output path belongs to projection
break;
}
// Change control to match head of successor basic block
j -= start;
}
}
}
//------------------------------schedule_pinned_nodes--------------------------
// Set the basic block for Nodes pinned into blocks
// Allocate node stack of size C->unique()+8 to avoid frequent realloc
while ( spstack.is_nonempty() ) {
// Before setting block replace block_proj control edge
while( !input->is_block_start() )
schedule_node_into_block(n, b);
}
}
}
}
}
#ifdef ASSERT
// Assert that new input b2 is dominated by all previous inputs.
// Check this by by seeing that it is dominated by b1, the deepest
// input observed until b2.
}
// Detected an unschedulable graph. Print some nice stuff and die.
}
n->dump();
assert(false, "unscheduable graph");
}
}
#endif
// Find the last input dominated by all other inputs.
int deepb_dom_depth = 0;
// The new inb must be dominated by the previous deepb.
// The various inputs must be linearly ordered in the dom
// tree, or else there will not be a unique deepest block.
}
}
return deepb;
}
//------------------------------schedule_early---------------------------------
// Find the earliest Block any instruction can be placed in. Some instructions
// are pinned into Blocks. Unpinned instructions can appear in last block in
// which all their inputs occur.
// Allocate stack with enough space to avoid frequent realloc
// roots.push(_root); _root will be processed among C->top() inputs
// Use local variables nstack_top_n & nstack_top_i to cache values
// on stack's top.
//while_nstack_nonempty:
while (true) {
// Get parent node and next input's index from stack's top.
Node *n = nstack_top_n;
uint i = nstack_top_i;
if (i == 0) {
// Fixup some control. Constants without control get attached
// to root and nodes that use is_block_proj() nodes should be attached
// to the region that starts their block.
} else { // n->in(0) == NULL
}
}
}
// First, visit all inputs and force them to get a block. If an
// input is already in a block we quit following inputs (to avoid
// cycles). Instead we put that Node on a worklist to be handled
// later (since IT'S inputs may not have a block yet).
while (i < n->len()) { // For all inputs
++i;
if (is_visited) {
// assert( !visited.test(in->_idx), "did not schedule early" );
return false;
}
nstack_top_i = 0;
done = false; // Not all n's inputs processed.
break; // continue while_nstack_nonempty;
} else if (!is_visited) { // Input not yet visited?
}
}
if (done) {
// All of n's inputs have been processed, complete post-processing.
// Some instructions are pinned into a block. These include Region,
// Phi, Start, Return, and other control-dependent instructions and
// any projections which depend on them.
if (!n->pinned()) {
// Set earliest legal block.
} else {
assert(_bbs[n->_idx] == _bbs[n->in(0)->_idx], "Pinned Node should be at the same block as its control edge");
}
// Finished all nodes on stack.
// Process next node on the worklist 'roots'.
break;
}
// Get saved parent node and next input's index.
} // if (done)
} // while (true)
} // while (roots.size() != 0)
return true;
}
//------------------------------dom_lca----------------------------------------
// Find least common ancestor in dominator tree
// LCA is a current notion of LCA, to be raised above 'this'.
// As a convenient boundary condition, return 'this' if LCA is NULL.
// Find the LCA of those two nodes.
}
return LCA;
}
//--------------------------raise_LCA_above_use--------------------------------
// We are placing a definition, and have been given a def->use edge.
// The definition must dominate the use, so move the LCA upward in the
// dominator tree to dominate the use. If the use is a phi, adjust
// the LCA only with the phi input paths which actually use this def.
// Why does not this loop just break after finding the matching input to
// chains. Means I cannot distinguish, from the def-use direction, which
// of many use-defs lead from the same use to the same def. That is, this
// Phi might have several uses of the same def. Each use appears in a
// different predecessor block. But when I enter here, I cannot distinguish
// which use-def edge I should find the predecessor block for. So I find
// them all. Means I do a little extra work if a Phi uses the same value
// more than once.
}
}
return LCA;
}
//----------------------------raise_LCA_above_marks----------------------------
// Return a new LCA that dominates LCA and any of its marked predecessors.
// Search all my parents up to 'early' (exclusive), looking for predecessors
// which are marked with the given index. Return the LCA (in the dom tree)
// of all marked blocks. If there are none marked, return the original
// LCA.
// Test and set the visited bit.
// Don't process the current LCA, otherwise the search may terminate early
// Raise the LCA.
// Resume searching at that point, skipping intermediate levels.
continue; // Don't mark as visited to avoid early termination.
} else {
// Keep searching through this block's predecessors.
}
}
}
return LCA;
}
//--------------------------memory_early_block--------------------------------
// This is a variation of find_deepest_input, the heart of schedule_early.
// Find the "early" block for a load, if we considered only memory and
// address inputs, that is, if other data inputs were ignored.
//
// Because a subset of edges are considered, the resulting block will
// be earlier (at a shallower dom_depth) than the true schedule_early
// point of the node. We compute this earlier block as a more permissive
// site for anti-dependency insertion, but only if subsume_loads is enabled.
int mem_inputs_length = 0;
// In the comparision below, add one to account for the control input,
// which may be null, but always takes up a spot in the in array.
// This "load" has more inputs than just the memory, base and index inputs.
// For purposes of checking anti-dependences, we need to start
// from the early block of only the address portion of the instruction,
// and ignore other blocks that may have factored into the wider
// schedule_early calculation.
int deepb_dom_depth = 0;
for (int i = 0; i < mem_inputs_length; i++) {
// The new inb must be dominated by the previous deepb.
// The various inputs must be linearly ordered in the dom
// tree, or else there will not be a unique deepest block.
}
}
}
return early;
}
//--------------------------insert_anti_dependences---------------------------
// A load may need to witness memory that nearby stores can overwrite.
// For each nearby store, either insert an "anti-dependence" edge
// from the load to the store, or else move LCA upward to force the
// load to (eventually) be scheduled in a block above the store.
//
// Do not add edges to stores on distinct control-flow paths;
// only add edges to stores which might interfere.
//
// Return the (updated) LCA. There will not be any possibly interfering
// store between the load's "early block" and the updated LCA.
// Any stores in the updated LCA will have new precedence edges
// back to the load. The caller is expected to schedule the load
// in the LCA, in which case the precedence edges will make LCM
// preserve anti-dependences. The caller may also hoist the load
// above the LCA, if it is not the early block.
// Compute the alias index. Loads and stores with different alias indices
// do not need anti-dependence edges.
#ifdef ASSERT
(PrintOpto || VerifyAliases ||
// Load nodes should not consume all of memory.
// Reporting a bottom type indicates a bug in adlc.
// If some particular type of node validly consumes all of memory,
// sharpen the preceding "if" to exclude it, so we can catch bugs here.
}
#endif
"String compare is only known 'load' that does not conflict with any stores");
"String equals is a 'load' that does not conflict with any stores");
"String indexOf is a 'load' that does not conflict with any stores");
"Arrays equals is a 'load' that do not conflict with any stores");
// It is impossible to spoil this load by putting stores before it,
// because we know that the stores will never update the value
// which 'load' must witness.
return LCA;
}
// Note the earliest legal placement of 'load', as determined by
// by the unique point in the dom tree where all memory effects
// and other inputs are first available. (Computed by schedule_early.)
// For normal loads, 'early' is the shallowest place (dom graph wise)
// to look for anti-deps between this load and any store.
// If we are subsuming loads, compute an "early" block that only considers
// memory or address inputs. This block may be different than the
// schedule_early block in that it could be at an even shallower depth in the
// dominator tree, and allow for a broader discovery of anti-dependences.
if (C->subsume_loads()) {
}
bool must_raise_LCA = false;
#ifdef TRACK_PHI_INPUTS
// %%% This extra checking fails because MergeMem nodes are not GVNed.
// Provide "phi_inputs" to check if every input to a PhiNode is from the
// original memory state. This indicates a PhiNode for which should not
// prevent the load from sinking. For such a block, set_raise_LCA_mark
// may be overly conservative.
// Mechanism: count inputs seen for each Phi encountered in worklist_store.
#endif
// 'load' uses some memory state; look for users of the same state.
// Recurse through MergeMem nodes to the stores that use them.
// Each of these stores is a possible definition of memory
// that 'load' needs to use. We need to force 'load'
// to occur before each such store. When the store is in
// the same block as 'load', we insert an anti-dependence
// edge load->store.
// The relevant stores "nearby" the load consist of a tree rooted
// at initial_mem, with internal nodes of type MergeMem.
// Therefore, the branches visited by the worklist are of this form:
// initial_mem -> (MergeMem ->)* store
// The anti-dependence constraints apply only to the fringe of this tree.
while (worklist_store.size() > 0) {
// Examine a nearby store to see if it might interfere with our load.
// MergeMems do not directly have anti-deps.
// Treat them as internal nodes in a forward tree of memory states,
// the leaves of which are each a 'possible-def'.
) {
if (store == initial_mem)
if (store->is_MergeMem()) {
// Be sure we don't get into combinatorial problems.
// (Allow phis to be repeated; they can merge two relevant states.)
for (; j > 0; j--) {
}
if (j > 0) continue; // already on work list; do not repeat
}
}
continue;
}
// Compute the alias index. Loads and stores with different alias
// indices do not need anti-dependence edges. Wide MemBar's are
// anti-dependent on everything (except immutable memories).
// Most slow-path runtime calls do NOT modify Java memory, but
// they can block and so write Raw memory.
// Check for call into the runtime using the Java calling
// convention (and from there into a wrapper); it has no
// _method. Can't do this optimization for Native calls because
// they CAN write to Java memory.
// These runtime calls do not write to Java visible memory
// (other than Raw) and so do not require anti-dependence edges.
continue;
}
}
// This is basically a workaround for SafePoints only defining control
// instead of control + memory.
continue;
} else {
// Some raw memory, such as the load of "top" at an allocation,
// can be control dependent on the previous safepoint. See
// comments in GraphKit::allocate_heap() about control input.
// Inserting an anti-dep between such a safepoint and a use
// creates a cycle, and will cause a subsequent failure in
// local scheduling. (BugId 4919904)
// (%%% How can a control input be a safepoint and not a projection??)
continue;
}
}
// Identify a block that the current load must be above,
// or else observe that 'store' is all the way up in the
// earliest legal block for 'load'. In the latter case,
// immediately insert an anti-dependence edge.
// 'load' uses memory which is one (or more) of the Phi's inputs.
// It must be scheduled not before the Phi, but rather before
// each of the relevant Phi inputs.
//
// Instead of finding the LCA of all inputs to a Phi that match 'mem',
// we mark each corresponding predecessor block and do a combined
// hoisting operation later (raise_LCA_above_marks).
//
// Do not assert(store_block != early, "Phi merging memory after access")
// PhiNode may be at start of block 'early' with backedge to 'early'
DEBUG_ONLY(bool found_match = false);
DEBUG_ONLY(found_match = true);
if (pred_block != early) {
// If any predecessor of the Phi matches the load's "early block",
// we do not need a precedence edge between the Phi and 'load'
// since the load will be forced into a block preceding the Phi.
must_raise_LCA = true;
} else {
// anti-dependent upon PHI pinned below 'early', no edge needed
}
}
}
#ifdef TRACK_PHI_INPUTS
#ifdef ASSERT
// This assert asks about correct handling of PhiNodes, which may not
// have all input edges directly from 'mem'. See BugId 4621264
// Increment by exactly one even if there are multiple copies of 'mem'
// coming into the phi, because we will run this block several times
// if there are several copies of 'mem'. (That's how DU iterators work.)
"Expect at least one phi input will not be from original memory state");
#endif //ASSERT
#endif //TRACK_PHI_INPUTS
} else if (store_block != early) {
// 'store' is between the current LCA and earliest possible block.
// Label its block, and decide later on how to raise the LCA
// to include the effect on LCA of this store.
// If this store's block gets chosen as the raised LCA, we
// will find him on the non_early_stores list and stick him
// with a precedence edge.
// (But, don't bother if LCA is already raised all the way.)
must_raise_LCA = true;
}
} else {
// Found a possibly-interfering store in the load's 'early' block.
// This means 'load' cannot sink at all in the dominator tree.
// Add an anti-dep edge, and squeeze 'load' into the highest block.
if (verify) {
} else {
}
// This turns off the process of gathering non_early_stores.
}
}
// (Worklist is now empty; all nearby stores have been visited.)
// Finished if 'load' must be scheduled in its 'early' block.
// If we found any stores there, they have already been given
// precedence edges.
// We get here only if there are no possibly-interfering stores
// in the load's 'early' block. Move LCA up above all predecessors
// which contain stores we have noted.
//
// The raised LCA block can be a home to such interfering stores,
// but its predecessors must not contain any such stores.
//
// The raised LCA will be a lower bound for placing the load,
// preventing the load from sinking past any block containing
// a store that may invalidate the memory state required by 'load'.
if (must_raise_LCA)
// Insert anti-dependence edges from 'load' to each store
// in the non-early LCA block.
// Mine the non_early_stores list for such stores.
while (non_early_stores.size() > 0) {
if (store_block == LCA) {
// add anti_dependence from store to load in its own block
if (verify) {
} else {
}
} else {
// Any other stores we found must be either inside the new LCA
// or else outside the original LCA. In the latter case, they
// did not interfere with any use of 'load'.
}
}
}
// Return the highest block containing stores; any stores
// within that block have been given anti-dependence edges.
return LCA;
}
// This class is used to iterate backwards over the nodes in the graph.
class Node_Backward_Iterator {
private:
public:
// Constructor for the iterator
// Postincrement operator to iterate over the nodes
private:
};
// Constructor for the Node_Backward_Iterator
Node_Backward_Iterator::Node_Backward_Iterator( Node *root, VectorSet &visited, Node_List &stack, Block_Array &bbs )
// The stack should contain exactly the root
// Clear the visited bits
}
// Iterator for the Node_Backward_Iterator
// If the _stack is empty, then just return NULL: finished.
return NULL;
// '_stack' is emulating a real _stack. The 'visit-all-users' loop has been
// made stateless, so I do not need to record the index 'i' on my _stack.
// Instead I visit all users each time, scanning for unvisited users.
// I visit unvisited not-anti-dependence users first, then anti-dependent
// children next.
// I cycle here when I am entering a deeper level of recursion.
// The key variable 'self' was set prior to jumping here.
while( 1 ) {
// Now schedule all uses as late as possible.
// Schedule all nodes in a post-order visit
// Scan for unvisited nodes
// For all uses, schedule late
// Skip already visited children
continue;
// do not traverse backward control edges
continue;
// Phi nodes always precede uses in a basic block
continue;
unvisited = n; // Found unvisited
// Check for possible-anti-dependent
if( !n->needs_anti_dependence_check() )
break; // Not visited, not anti-dep; schedule it NOW
}
// Did I find an unvisited not-anti-dependent Node?
if ( !unvisited )
break; // All done with children; post-visit 'self'
// Visit the unvisited Node. Contains the obvious push to
// indicate I'm entering a deeper level of recursion. I push the
// old state onto the _stack and set a new state and loop (recurse).
} // End recursion loop
return self;
}
//------------------------------ComputeLatenciesBackwards----------------------
// Compute the latency of all the instructions.
#ifndef PRODUCT
if (trace_opto_pipelining())
#endif
Node *n;
// Walk over all the nodes from last to first
// Set the latency for the definitions of this instruction
}
} // end ComputeLatenciesBackwards
//------------------------------partial_latency_of_defs------------------------
// Compute the latency impact of this node on all defs. This computes
// a number that increases as we approach the beginning of the routine.
// Set the latency for this instruction
#ifndef PRODUCT
if (trace_opto_pipelining()) {
dump();
}
#endif
if (n->is_Proj())
n = n->in(0);
if (n->is_Root())
return;
continue;
// Walk backwards thru projections
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
// If the defining block is not known, assume it is ok
if ( (use_pre_order < def_pre_order) ||
continue;
}
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
}
}
//------------------------------latency_from_use-------------------------------
// Compute the latency of a specific use
// If self-reference, return no latency
return 0;
// If the use is not a projection, then it is simple...
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
if (use_pre_order < def_pre_order)
return 0;
return 0;
// Change this if we want local latencies
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
}
}
} else {
// This is a projection, just grab the latency of the use(s)
}
}
return latency;
}
//------------------------------latency_from_uses------------------------------
// Compute the latency of this instruction relative to all of it's uses.
// This computes a number that increases as we approach the beginning of the
// routine.
// Set the latency for this instruction
#ifndef PRODUCT
if (trace_opto_pipelining()) {
dump();
}
#endif
}
}
//------------------------------hoist_to_cheaper_block-------------------------
// Pick a block for node self, between early and LCA, that is a cheaper
// alternative to LCA.
// Turn off latency scheduling if scheduling is just plain off
if (!C->do_scheduling())
in_latency = true;
// Do not hoist (to cover latency) instructions which target a
// single register. Hoisting stretches the live range of the
// single register and may force spilling.
in_latency = true;
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
// Walk up the dominator tree from LCA (Lowest common ancestor) to
// the earliest legal location. Capture the least execution frequency.
// Bailout without retry
C->record_method_not_compilable("late schedule failed: LCA == NULL");
return least;
}
// Don't hoist machine instructions to the root basic block
break;
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
( !in_latency && // No block containing latency
// because they may end up above other uses of their phi forcing
// their result register to be different from their input.
) {
in_latency = true;
}
}
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
// See if the latency needs to be updated
if (target < end_latency) {
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
}
return least;
}
//------------------------------schedule_late-----------------------------------
// Now schedule all codes as LATE as possible. This is the LCA in the
// dominator tree of all USES of a value. Pick the block with the least
// loop nesting depth that is lowest in the dominator tree.
extern const char must_clone[];
#ifndef PRODUCT
if (trace_opto_pipelining())
#endif
// Walk over all the nodes from last to first
// Top node goes in bb #2 with other constants.
// It must be special-cased, because it has no out edges.
continue;
}
// No uses, just terminate
continue; // Must be a dead machine projection
}
// If node is pinned in the block, then no scheduling can be done.
continue;
if (mach) {
switch (mach->ideal_Opcode()) {
case Op_CreateEx:
// Don't move exception creation
continue;
break;
case Op_CheckCastPP:
// Don't move CheckCastPP nodes away from their input, if the input
// is a rawptr (5071820).
#ifdef ASSERT
#endif
continue;
}
break;
}
}
// Gather LCA of all uses
{
// For all uses, find LCA
}
} // (Hide defs of imax, i from rest of block.)
// Place temps in the block of their use. This isn't a
// requirement for correctness but it reduces useless
// interference between temps and other nodes.
continue;
}
// Check if 'self' could be anti-dependent on memory
if (self->needs_anti_dependence_check()) {
// Hoist LCA above possible-defs and insert anti-dependences to
// defs in new LCA block.
}
// Somehow the LCA has moved above the earliest legal point.
// (One way this can happen is via memory_early_block.)
if (C->subsume_loads() == true && !C->failing()) {
// Retry with subsume_loads == false
// If this is the first failure, the sentinel string will "stick"
// to the Compile object, and the C2Compiler will see it and retry.
} else {
// Bailout without retry when (early->_dom_depth > LCA->_dom_depth)
C->record_method_not_compilable("late schedule failed: incorrect graph");
}
return;
}
// If there is no opportunity to hoist, then we're done.
// Must clone guys stay next to use; no hoisting allowed.
// Also cannot hoist guys that alter memory or are otherwise not
// allocatable (hoisting can make a value live longer, leading to
// anti and output dependency problems which are normally resolved
// by the register allocator giving everyone a different register).
try_to_hoist = false;
if (try_to_hoist) {
// Now find the block with the least execution frequency.
// Start at the latest schedule and work up to the earliest schedule
// in the dominator tree. Thus the Node will dominate all its uses.
} else {
// Just use the LCA of the uses.
}
// Put the node into target block
#ifdef ASSERT
if (self->needs_anti_dependence_check()) {
// since precedence edges are only inserted when we're sure they
// are needed make sure that after placement in a block we don't
// need any new precedence edges.
}
#endif
} // Loop until all nodes have been visited
} // end ScheduleLate
//------------------------------GlobalCodeMotion-------------------------------
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
// Initialize the bbs.map for things on the proj_list
uint i;
// Set the basic block for Nodes pinned into blocks
// Find the earliest Block any instruction can be placed in. Some
// instructions are pinned into Blocks. Unpinned instructions can
// appear in last block in which all their inputs occur.
// Bailout without retry
C->record_method_not_compilable("early schedule failed");
return;
}
// Build Def-Use edges.
// Compute the latency information (via backwards walk) for all the
// instructions in the graph
if( C->do_scheduling() )
// Now schedule all codes as LATE as possible. This is the LCA in the
// dominator tree of all USES of a value. Pick the block with the least
// loop nesting depth that is lowest in the dominator tree.
// ( visited.Clear() called in schedule_late()->Node_Backward_Iterator() )
if( C->failing() ) {
// schedule_late fails only when graph is incorrect.
return;
}
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
// Detect implicit-null-check opportunities. Basically, find NULL checks
// with suitable memory ops nearby. Use the memory op to do the NULL check.
// I can generate a memory op if there is not one nearby.
if (C->is_method_compilation()) {
// Don't do it for natives, adapters, or runtime stubs
int allowed_reasons = 0;
// ...and don't do it when there have been too many traps, globally.
}
// By reversing the loop direction we get a very minor gain on mpegaudio.
// Feel free to revert to a forward loop for clarity.
// for( int i=0; i < (int)matcher._null_check_tests.size(); i+=2 ) {
// The implicit_null_check will only perform the transformation
// if the null branch is truly uncommon, *and* it leads to an
// uncommon trap. Combined with the too_many_traps guards
// above, this prevents SEGV storms reported in 6366351,
// by recompiling offending methods without this optimization.
}
}
#ifndef PRODUCT
if (trace_opto_pipelining()) {
}
#endif
// Schedule locally. Right now a simple topological sort.
// Later, do a real latency aware scheduler.
for (i = 0; i < _num_blocks; i++) {
C->record_method_not_compilable("local schedule failed");
}
return;
}
}
// If we inserted any instructions between a Call and his CatchNode,
// clone the instructions on all paths below the Catch.
for( i=0; i < _num_blocks; i++ )
#ifndef PRODUCT
if (trace_opto_pipelining()) {
for (uint i = 0; i < _num_blocks; i++) {
}
}
#endif
// Dead.
}
//------------------------------Estimate_Block_Frequency-----------------------
// Estimate block frequencies based on IfNode probabilities.
// Force conditional branches leading to uncommon traps to be unlikely,
// not because we get to the uncommon_trap with less relative frequency,
// but because an uncommon_trap typically causes a deopt, so we only get
// there once.
if (C->do_freq_based_layout()) {
if (pb->has_uncommon_code()) {
}
}
}
}
}
}
// Create the loop tree and calculate loop depth.
// Compute block frequency of each block, relative to a single loop entry.
// Adjust all frequencies to be relative to a single method entry
_root_loop->scale_freq();
// Save outmost loop frequency for LRG frequency threshold
// force paths ending at uncommon traps to be infrequent
if (!C->do_freq_based_layout()) {
if (pb->has_uncommon_code()) {
}
}
}
}
}
}
#ifdef ASSERT
for (uint i = 0; i < _num_blocks; i++ ) {
}
#endif
#ifndef PRODUCT
if (PrintCFGBlockFreq) {
_root_loop->dump_tree();
if (Verbose) {
dump();
}
}
#endif
}
//----------------------------create_loop_tree--------------------------------
// Create a loop tree from the CFG
#ifdef ASSERT
for (uint i = 0; i < _num_blocks; i++ ) {
// Check that _loop field are clear...we could clear them if not.
// Sanity check that the RPO numbering is reflected in the _blocks array.
// It doesn't have to be for the loop tree to be built, but if it is not,
// then the blocks have been reordered since dom graph building...which
// may question the RPO numbering
}
#endif
int idct = 0;
// Assign blocks to loops
// Defensively filter out Loop nodes for non-single-entry loops.
// For all reasonable loops, the head occurs before the tail in RPO.
// The tail and (recursive) predecessors of the tail
// are made members of a new loop.
// Add to nloop so push_pred() will skip over inner loops
}
}
}
}
}
}
// Create a member list for each loop consisting
// of both blocks and (immediate child) loops.
for (uint i = 0; i < _num_blocks; i++) {
// Not assigned to a loop. Add it to the method's pseudo loop.
}
lp->add_member(b);
}
// Not a nested loop. Make it a child of the method's pseudo loop.
}
// Add nested loop to member list of parent loop.
}
}
}
return root_loop;
}
//------------------------------push_pred--------------------------------------
// Filter out blocks for non-single-entry loops.
// For all reasonable loops, the head occurs before the tail in RPO.
}
} else if (pred_loop != this) {
// Nested loop.
}
// Make pred's loop be a child
// Continue with loop entry predecessor.
} else {
}
}
}
//------------------------------add_nested_loop--------------------------------
// Make cl a child of the current loop in the loop tree.
} else {
}
}
//------------------------------compute_loop_depth-----------------------------
// Store the loop depth in each CFGLoop object.
// Recursively walk the children to do the same for them.
}
}
//------------------------------compute_freq-----------------------------------
// Compute the frequency of each block and loop, relative to a single entry
// into the dominating loop head.
// Bottom up traversal of loop tree (visit inner loops first.)
// Set loop head frequency to 1.0, then transitively
// compute frequency for all successors in the loop,
// as well as for each exit edge. Inner loops are
// treated as single blocks with loop exit targets
// as the successor blocks.
// Nested loops first
ch->compute_freq();
}
if (s->is_block()) {
for (uint j = 0; j < b->_num_succs; j++) {
}
} else {
}
}
}
// For all loops other than the outer, "method" loop,
// sum and normalize the exit probability. The "method" loop
// should keep the initial exit probability of 1, so that
// inner blocks do not get erroneously scaled.
if (_depth != 0) {
// Total the exit probabilities for this loop.
}
// Normalize the exit probabilities. Until now, the
// probabilities estimate the possibility of exit per
// a single loop iteration; afterward, they estimate
// the probability of exit per loop entry.
}
}
// Save the total, but guard against unreasonable probability,
// as the value is used to estimate the loop trip count.
// An infinite trip count would blur relative block
// frequencies.
}
}
//------------------------------succ_prob-------------------------------------
// Determine the probability of reaching successor 'i' from the receiver block.
if (n->is_Mach()) {
if (n->is_MachNullCheck()) {
// Can only reach here if called after lcm. The original Op_If is gone,
// so we attempt to infer the probability from one or both of the
// successor blocks.
// If either successor has only one predecessor, then the
// probability estimate can be derived using the
// relative frequency of the successor and this block.
} else {
// Estimate using both successor frequencies
}
}
}
// Switch on branch type
switch( op ) {
case Op_CountedLoopEnd:
case Op_If: {
// Conditionals pass on only part of their frequency
// If succ[i] is the FALSE branch, invert path info
} else {
return prob; // taken
}
}
case Op_Jump:
// Divide the frequency between all successors evenly
return 1.0f/_num_succs;
case Op_Catch: {
// Fall-thru path gets the lion's share.
} else {
// Presume exceptional paths are equally unlikely
return PROB_UNLIKELY_MAG(5);
}
}
case Op_Root:
case Op_Goto:
// Pass frequency straight thru to target
return 1.0f;
case Op_NeverBranch:
return 0.0f;
case Op_TailCall:
case Op_TailJump:
case Op_Return:
case Op_Halt:
case Op_Rethrow:
// Do not push out freq to root block
return 0.0f;
default:
}
return 0.0f;
}
//------------------------------num_fall_throughs-----------------------------
// Return the number of fall-through candidates for a block
if (n->is_Mach()) {
if (n->is_MachNullCheck()) {
// In theory, either side can fall-thru, for simplicity sake,
// let's say only the false branch can now.
return 1;
}
}
// Switch on branch type
switch( op ) {
case Op_CountedLoopEnd:
case Op_If:
return 2;
case Op_Root:
case Op_Goto:
return 1;
case Op_Catch: {
for (uint i = 0; i < _num_succs; i++) {
return 1;
}
}
return 0;
}
case Op_Jump:
case Op_NeverBranch:
case Op_TailCall:
case Op_TailJump:
case Op_Return:
case Op_Halt:
case Op_Rethrow:
return 0;
default:
}
return 0;
}
//------------------------------succ_fall_through-----------------------------
// Return true if a specific successor could be fall-through target.
if (n->is_Mach()) {
if (n->is_MachNullCheck()) {
// In theory, either side can fall-thru, for simplicity sake,
// let's say only the false branch can now.
}
}
// Switch on branch type
switch( op ) {
case Op_CountedLoopEnd:
case Op_If:
case Op_Root:
case Op_Goto:
return true;
case Op_Catch: {
}
case Op_Jump:
case Op_NeverBranch:
case Op_TailCall:
case Op_TailJump:
case Op_Return:
case Op_Halt:
case Op_Rethrow:
return false;
default:
}
return false;
}
//------------------------------update_uncommon_branch------------------------
// Update the probability of a two-branch to be uncommon
// Which successor is ub?
uint s;
for (s = 0; s <_num_succs; s++) {
}
// If ub is the true path, make the proability small, else
// ub is the false path, and make the probability large
// Get existing probability
if (invert) p = 1.0 - p;
if (p > PROB_MIN) {
p = PROB_MIN;
}
if (invert) p = 1.0 - p;
}
//------------------------------update_succ_freq-------------------------------
// Update the appropriate frequency associated with block 'b', a successor of
// a block in this loop.
if (b->_loop == this) {
if (b == head()) {
// back branch within the loop
// Do nothing now, the loop carried frequency will be
// adjust later in scale_freq().
} else {
// simple branch within the loop
}
} else if (!in_loop_nest(b)) {
// branch is exit from this loop
} else {
// branch into nested loop
}
}
//------------------------------in_loop_nest-----------------------------------
// Determine if block b is in the receiver's loop nest.
return true;
}
}
return b_loop == this;
}
//------------------------------scale_freq-------------------------------------
// Scale frequency of loops and blocks by trip counts from outer loops
// Do a top down traversal of loop tree (visit outer loops first.)
s->_freq = block_freq;
}
ch->scale_freq();
}
}
// Frequency of outer loop
}
return _freq;
}
#ifndef PRODUCT
//------------------------------dump_tree--------------------------------------
dump();
}
//------------------------------dump-------------------------------------------
int k = 0;
if (k++ >= 6) {
k = 0;
}
if (s->is_block()) {
} else {
}
}
k = 0;
if (k++ >= 7) {
k = 0;
}
}
}
#endif