/*
* 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 "compiler/oopMap.hpp"
#include "memory/allocation.inline.hpp"
#include "opto/addnode.hpp"
#include "opto/callnode.hpp"
#include "opto/cfgnode.hpp"
#include "opto/chaitin.hpp"
#include "opto/coalesce.hpp"
#include "opto/connode.hpp"
#include "opto/indexSet.hpp"
#include "opto/machnode.hpp"
#include "opto/memnode.hpp"
#include "opto/opcodes.hpp"
//=============================================================================
//------------------------------IFG--------------------------------------------
}
//------------------------------init-------------------------------------------
_is_square = false;
// Make uninitialized adjacency lists
// Also make empty live range structures
// Init all to empty
}
}
//------------------------------add--------------------------------------------
// Add edge between vertices a & b. These are sorted (triangular matrix),
// then the smaller number is inserted in the larger numbered array.
lrgs(a).invalid_degree();
lrgs(b).invalid_degree();
// Sort a and b, so that a is bigger
}
//------------------------------add_vector-------------------------------------
// Add an edge between 'a' and everything in the vector.
// IFG is triangular, so do the inserts where 'a' < 'b'.
}
}
//------------------------------test-------------------------------------------
// Is there an edge between a and b?
// Sort a and b, so that a is larger
}
//------------------------------SquareUp---------------------------------------
// Convert triangular matrix to square matrix
// Simple transpose
}
}
_is_square = true;
}
//------------------------------Compute_Effective_Degree-----------------------
// Compute effective degree in bulk
}
//------------------------------test_edge_sq-----------------------------------
// Swap, so that 'a' has the lesser count. Then binary search is on
// the smaller of a's list and b's list.
//return _adjs[a].unordered_member(b);
}
//------------------------------Union------------------------------------------
// Union edges of B into A
lrgs(a).invalid_degree();
}
}
}
//------------------------------remove_node------------------------------------
// Yank a Node and all connected edges from the IFG. Return a
// list of neighbors (edges) yanked.
// I remove the LRG from all neighbors.
}
return neighbors(a);
}
//------------------------------re_insert--------------------------------------
// Re-insert a yanked Node.
(*_yanked) >>= a;
}
}
//------------------------------compute_degree---------------------------------
// Compute the degree between 2 live ranges. If both live ranges are
// aligned-adjacent powers-of-2 then we use the MAX size. If either is
// mis-aligned (or for Fat-Projections, not-adjacent) then we have to
// MULTIPLY the sizes. Inspect Brigg's thesis on register pairs to see why
// this is so.
int tmp;
return tmp;
}
//------------------------------effective_degree-------------------------------
// Compute effective degree for this live range. If both live ranges are
// aligned-adjacent powers-of-2 then we use the MAX size. If either is
// mis-aligned (or for Fat-Projections, not-adjacent) then we have to
// MULTIPLY the sizes. Inspect Brigg's thesis on register pairs to see why
// this is so.
int eff = 0;
}
return eff;
}
#ifndef PRODUCT
//------------------------------dump-------------------------------------------
if( _is_square ) {
}
}
return;
}
// Triangular
uint j;
for( j = _maxlrg; j > i; j-- )
if( test_edge(j - 1,i) ) {
}
}
}
}
//------------------------------stats------------------------------------------
uint i;
for( i = 0; i < _maxlrg; i++ ) {
h_cnt[neighbor_cnt(i)]++;
}
for( i = 0; i < _maxlrg*2; i++ )
if( h_cnt[i] )
}
//------------------------------verify-----------------------------------------
// IFG is square, sorted and no need for Find
}
}
}
#endif
//------------------------------interfere_with_live----------------------------
// Interfere this register with everything currently live. Use the RegMasks
// to trim the set of possible interferences. Return a count of register-only
// interferences as an estimate of register pressure.
// Interfere with everything live.
// Check for interference by checking overlap of regmasks.
// Only interfere if acceptable register masks overlap.
uint l;
}
//------------------------------build_ifg_virtual------------------------------
// Actually build the interference graph. Uses virtual registers only, no
// physical register masks. This allows me to be very aggressive when
// coalescing copies. Some of this aggressiveness will have to be undone
// later, but I'd rather get all the copies I can now (since unremoved copies
// at this point can end up in bad places). Copies I re-insert later I have
// more opportunity to insert them in low-frequency locations.
// For all blocks (in any order) do...
// The IFG is built by a single reverse pass over each basic block.
// Starting with the known live-out set, we remove things that get
// defined and add things that become live (essentially executing one
// pass of a standard LIVE analysis). Just before a Node defines a value
// (and removes it from the live-ness set) that value is certainly live.
// The defined value interferes with everything currently live. The
// value is then removed from the live-ness set and it's inputs are
// added to the live-ness set.
// Get value being defined
// Some special values do not allocate
if( r ) {
// Remove from live-out set
// Copies do not define a new value and so do not interfere.
// Remove the copies source from the liveout set before interfering.
// Interfere with everything live
interfere_with_live( r, liveout );
}
// Make all inputs live
if( !n->is_Phi() ) { // Phi function uses come from prior block
}
// 2-address instructions always have the defined value live
// on entry to the instruction, even though it is being defined
// by the instruction. We pretend a virtual copy sits just prior
// to the instruction and kills the src-def'd register.
// In other words, for 2-address instructions the defined value
// interferes with all inputs.
// Sometimes my 2-address ADDs are commuted in a bad way.
// We generally want the USE-DEF register to refer to the
// loop-varying quantity, to avoid a copy.
// Check that mach->num_opnds() == 3 to ensure instruction is
// not subsuming constants, effectively excludes addI_cin_imm
// Can NOT swap for instructions like addI_cin_imm since it
// is adding zero to yhi + carry and the second ideal-input
// points to the result of adding low-halves.
// Checking req() and num_opnds() does NOT distinguish addI_cout from addI_cout_imm
// See if the ADD is involved in a tight data loop the wrong way
}
// Defined value interferes with all inputs
}
}
} // End of forall instructions in block
} // End of forall blocks
}
//------------------------------count_int_pressure-----------------------------
}
return cnt;
}
//------------------------------count_float_pressure---------------------------
}
return cnt;
}
//------------------------------lower_pressure---------------------------------
// Adjust register pressure down by 1. Capture last hi-to-low transition,
#ifdef EXACT_PRESSURE
#else
#endif
}
#ifdef EXACT_PRESSURE
if( pressure[0] > b->_reg_pressure )
#else
#endif
}
}
}
}
//------------------------------build_ifg_physical-----------------------------
// Build the interference graph using physical registers when available.
// That is, if 2 live ranges are simultaneously alive but in their acceptable
// register sets do not overlap, then they do not interfere.
// For all blocks (in any order) do...
// Clone (rather than smash in place) the liveout info, so it is alive
// for the "collect_gc_info" phase later.
// Compute first nonphi node index
break;
// Spills could be inserted before CreateEx node which should be
// first instruction in block after Phis. Move CreateEx up.
if( ex->is_SpillCopy() ) continue;
// If the CreateEx isn't above all the MachSpillCopies
// then move it to the top.
}
// Stop once a CreateEx or any other node is found
break;
}
// Reset block's register pressure values for each ifg construction
b->_reg_pressure = b->_freg_pressure = 0;
// Liveout things are presumed live for the whole block. We accumulate
// 'area' accordingly. If they get killed in the block, we'll subtract
// the unused part of the block from the area.
// Compute initial register pressure
#ifdef EXACT_PRESSURE
#endif
// Count int pressure, but do not count the SP, flags
#ifdef EXACT_PRESSURE
if( pressure[0] > b->_reg_pressure )
b->_reg_pressure = pressure[0];
#endif
}
}
}
// The IFG is built by a single reverse pass over each basic block.
// Starting with the known live-out set, we remove things that get
// defined and add things that become live (essentially executing one
// pass of a standard LIVE analysis). Just before a Node defines a value
// (and removes it from the live-ness set) that value is certainly live.
// The defined value interferes with everything currently live. The
// value is then removed from the live-ness set and it's inputs are added
// to the live-ness set.
uint j;
// Get value being defined
// Some special values do not allocate
if( r ) {
// A DEF normally costs block frequency; rematerialized values are
// removed from the DEF sight, so LOWER costs here.
// If it is not live, then this instruction is dead. Probably caused
// by spilling and rematerialization. Who cares why, yank this baby.
if( !n->is_Proj() ||
// Could also be a flags-projection of a dead ADD or such.
n->disconnect_inputs(NULL, C);
n->replace_by(C->top());
// Since yanking a Node from block, high pressure moves up one
hrp_index[0]--;
hrp_index[1]--;
continue;
}
// Fat-projections kill many registers which cannot be used to
// hold live ranges.
// Count the int-only registers
#ifdef EXACT_PRESSURE
#endif
#ifndef EXACT_PRESSURE
#endif
hrp_index[0] = j-1;
}
// Count the float-only registers
#ifdef EXACT_PRESSURE
#endif
#ifndef EXACT_PRESSURE
#endif
}
}
} else { // Else it is live
// A DEF also ends 'area' partway through the block.
// Insure high score for immediate-use spill copies so they get a color
if( n->is_SpillCopy()
// All single-use MachSpillCopy(s) that immediately precede their
// use must color early. If a longer live range steals their
// color, the spill copy will split and may push another spill copy
// further away resulting in an infinite spill-split-retry cycle.
// Assigning a zero area results in a high score() and a good
// location in the simplify list.
//
// Use can be earlier in block if it is a Phi, but then I should be a MultiDef
// Find first non SpillCopy 'm' that follows the current instruction
// (j - 1) is index for current instruction 'n'
Node *m = n;
if( m == single_use ) {
}
}
// Remove from live-out set
// Adjust register pressure.
// Capture last hi-to-lo pressure transition
}
// Copies do not define a new value and so do not interfere.
// Remove the copies source from the liveout set before interfering.
if( idx ) {
// Adjust register pressure.
}
}
} // End of if live or not
// Interfere with everything live. If the defined value must
// go in a particular register, just remove that register from
// all conflicting parties and avoid the interference.
// Make exclusions for rematerializable defs. Since rematerializable
// DEFs are not bound but the live range is, some uses must be bound.
// If we spill live range 'r', it can rematerialize at each use site
// according to its bindings.
// Check for common case
// Smear odd bits
uint l;
// If 'l' must spill already, do not further hack his bits.
// He'll get some interferences and be forced to spill later.
if( lrg._must_spill ) continue;
// Remove bound register(s) from 'l's choices
// Remove the bits from LRG 'r' from LRG 'l' so 'l' no
// longer interferes with 'r'. If 'l' requires aligned
// adjacent pairs, subtract out bit pairs.
// Leave only aligned set of bits.
// It includes vector case.
} else { // Common case: size 1 bound removal
}
}
// If 'l' goes completely dry, it must spill.
// Give 'l' some kind of reasonable mask, so he picks up
// interferences (and will spill later).
must_spill++;
}
}
} // End of if bound
// Now interference with everything that is live and has
// compatible register sets.
} // End of if normal register-allocated value
// Area remaining in the block
inst_count--;
// Make all inputs live
if( !n->is_Phi() ) { // Phi function uses come from prior block
// Start loop at 1 (skip control edge) for most Nodes.
// SCMemProj's might be the sole use of a StoreLConditional.
// While StoreLConditionals set memory (the SCMemProj use)
// they also def flags; if that flag def is unused the
// allocator sees a flag-setting instruction with no use of
// the flags and assumes it's dead. This keeps the (useless)
// flag-setting behavior alive while also keeping the (useful)
// memory update effect.
if( !x ) continue;
// No use-side cost for spilling debug info
if( k < debug_start )
// A USE costs twice block frequency (once for the Load, once
// for a Load-delay). Rematerialized uses only cost once.
// It is live now
// Newly live things assumed live from here to top of block
// Adjust register pressure
#ifdef EXACT_PRESSURE
#endif
#ifdef EXACT_PRESSURE
if( pressure[0] > b->_reg_pressure )
b->_reg_pressure = pressure[0];
#endif
}
}
}
}
}
} // End of reverse pass over all instructions in block
// If we run off the top of the block with high pressure and
// never see a hi-to-low pressure transition, just record that
// the whole block is high pressure.
hrp_index[0] = 0;
#ifdef EXACT_PRESSURE
if( pressure[0] > b->_reg_pressure )
b->_reg_pressure = pressure[0];
#else
#endif
}
hrp_index[1] = 0;
#ifdef EXACT_PRESSURE
#else
#endif
}
// Compute high pressure indice; avoid landing in the middle of projnodes
j = hrp_index[0];
j--;
}
}
b->_ihrp_index = j;
j = hrp_index[1];
j--;
}
}
b->_fhrp_index = j;
#ifndef PRODUCT
// Gather Register Pressure Statistics
if( PrintOptoStatistics ) {
else
}
#endif
} // End of for all blocks
return must_spill;
}