0N/A/*
3239N/A * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "compiler/compileLog.hpp"
1879N/A#include "compiler/oopMap.hpp"
1879N/A#include "memory/allocation.inline.hpp"
1879N/A#include "opto/addnode.hpp"
1879N/A#include "opto/block.hpp"
1879N/A#include "opto/callnode.hpp"
1879N/A#include "opto/cfgnode.hpp"
1879N/A#include "opto/chaitin.hpp"
1879N/A#include "opto/coalesce.hpp"
1879N/A#include "opto/connode.hpp"
1879N/A#include "opto/idealGraphPrinter.hpp"
1879N/A#include "opto/indexSet.hpp"
1879N/A#include "opto/machnode.hpp"
1879N/A#include "opto/memnode.hpp"
1879N/A#include "opto/opcodes.hpp"
1879N/A#include "opto/rootnode.hpp"
0N/A
0N/A//=============================================================================
0N/A
0N/A#ifndef PRODUCT
0N/Avoid LRG::dump( ) const {
0N/A ttyLocker ttyl;
0N/A tty->print("%d ",num_regs());
0N/A _mask.dump();
0N/A if( _msize_valid ) {
0N/A if( mask_size() == compute_mask_size() ) tty->print(", #%d ",_mask_size);
0N/A else tty->print(", #!!!_%d_vs_%d ",_mask_size,_mask.Size());
0N/A } else {
0N/A tty->print(", #?(%d) ",_mask.Size());
0N/A }
0N/A
0N/A tty->print("EffDeg: ");
0N/A if( _degree_valid ) tty->print( "%d ", _eff_degree );
0N/A else tty->print("? ");
0N/A
295N/A if( is_multidef() ) {
0N/A tty->print("MultiDef ");
0N/A if (_defs != NULL) {
0N/A tty->print("(");
0N/A for (int i = 0; i < _defs->length(); i++) {
0N/A tty->print("N%d ", _defs->at(i)->_idx);
0N/A }
0N/A tty->print(") ");
0N/A }
0N/A }
0N/A else if( _def == 0 ) tty->print("Dead ");
0N/A else tty->print("Def: N%d ",_def->_idx);
0N/A
0N/A tty->print("Cost:%4.2g Area:%4.2g Score:%4.2g ",_cost,_area, score());
0N/A // Flags
0N/A if( _is_oop ) tty->print("Oop ");
0N/A if( _is_float ) tty->print("Float ");
3845N/A if( _is_vector ) tty->print("Vector ");
0N/A if( _was_spilled1 ) tty->print("Spilled ");
0N/A if( _was_spilled2 ) tty->print("Spilled2 ");
0N/A if( _direct_conflict ) tty->print("Direct_conflict ");
0N/A if( _fat_proj ) tty->print("Fat ");
0N/A if( _was_lo ) tty->print("Lo ");
0N/A if( _has_copy ) tty->print("Copy ");
0N/A if( _at_risk ) tty->print("Risk ");
0N/A
0N/A if( _must_spill ) tty->print("Must_spill ");
0N/A if( _is_bound ) tty->print("Bound ");
0N/A if( _msize_valid ) {
0N/A if( _degree_valid && lo_degree() ) tty->print("Trivial ");
0N/A }
0N/A
0N/A tty->cr();
0N/A}
0N/A#endif
0N/A
0N/A//------------------------------score------------------------------------------
0N/A// Compute score from cost and area. Low score is best to spill.
0N/Astatic double raw_score( double cost, double area ) {
0N/A return cost - (area*RegisterCostAreaRatio) * 1.52588e-5;
0N/A}
0N/A
0N/Adouble LRG::score() const {
0N/A // Scale _area by RegisterCostAreaRatio/64K then subtract from cost.
0N/A // Bigger area lowers score, encourages spilling this live range.
0N/A // Bigger cost raise score, prevents spilling this live range.
0N/A // (Note: 1/65536 is the magic constant below; I dont trust the C optimizer
0N/A // to turn a divide by a constant into a multiply by the reciprical).
0N/A double score = raw_score( _cost, _area);
0N/A
0N/A // Account for area. Basically, LRGs covering large areas are better
0N/A // to spill because more other LRGs get freed up.
0N/A if( _area == 0.0 ) // No area? Then no progress to spill
0N/A return 1e35;
0N/A
0N/A if( _was_spilled2 ) // If spilled once before, we are unlikely
0N/A return score + 1e30; // to make progress again.
0N/A
0N/A if( _cost >= _area*3.0 ) // Tiny area relative to cost
0N/A return score + 1e17; // Probably no progress to spill
0N/A
0N/A if( (_cost+_cost) >= _area*3.0 ) // Small area relative to cost
0N/A return score + 1e10; // Likely no progress to spill
0N/A
0N/A return score;
0N/A}
0N/A
0N/A//------------------------------LRG_List---------------------------------------
0N/ALRG_List::LRG_List( uint max ) : _cnt(max), _max(max), _lidxs(NEW_RESOURCE_ARRAY(uint,max)) {
0N/A memset( _lidxs, 0, sizeof(uint)*max );
0N/A}
0N/A
0N/Avoid LRG_List::extend( uint nidx, uint lidx ) {
0N/A _nesting.check();
0N/A if( nidx >= _max ) {
0N/A uint size = 16;
0N/A while( size <= nidx ) size <<=1;
0N/A _lidxs = REALLOC_RESOURCE_ARRAY( uint, _lidxs, _max, size );
0N/A _max = size;
0N/A }
0N/A while( _cnt <= nidx )
0N/A _lidxs[_cnt++] = 0;
0N/A _lidxs[nidx] = lidx;
0N/A}
0N/A
0N/A#define NUMBUCKS 3
0N/A
0N/A//------------------------------Chaitin----------------------------------------
0N/APhaseChaitin::PhaseChaitin(uint unique, PhaseCFG &cfg, Matcher &matcher)
0N/A : PhaseRegAlloc(unique, cfg, matcher,
0N/A#ifndef PRODUCT
0N/A print_chaitin_statistics
0N/A#else
0N/A NULL
0N/A#endif
0N/A ),
0N/A _names(unique), _uf_map(unique),
0N/A _maxlrg(0), _live(0),
0N/A _spilled_once(Thread::current()->resource_area()),
0N/A _spilled_twice(Thread::current()->resource_area()),
0N/A _lo_degree(0), _lo_stk_degree(0), _hi_degree(0), _simplified(0),
0N/A _oldphi(unique)
0N/A#ifndef PRODUCT
0N/A , _trace_spilling(TraceSpilling || C->method_has_option("TraceSpilling"))
0N/A#endif
0N/A{
0N/A NOT_PRODUCT( Compile::TracePhase t3("ctorChaitin", &_t_ctorChaitin, TimeCompiler); )
673N/A
673N/A _high_frequency_lrg = MIN2(float(OPTO_LRG_HIGH_FREQ), _cfg._outer_loop_freq);
673N/A
0N/A uint i,j;
0N/A // Build a list of basic blocks, sorted by frequency
0N/A _blks = NEW_RESOURCE_ARRAY( Block *, _cfg._num_blocks );
0N/A // Experiment with sorting strategies to speed compilation
0N/A double cutoff = BLOCK_FREQUENCY(1.0); // Cutoff for high frequency bucket
0N/A Block **buckets[NUMBUCKS]; // Array of buckets
0N/A uint buckcnt[NUMBUCKS]; // Array of bucket counters
0N/A double buckval[NUMBUCKS]; // Array of bucket value cutoffs
0N/A for( i = 0; i < NUMBUCKS; i++ ) {
0N/A buckets[i] = NEW_RESOURCE_ARRAY( Block *, _cfg._num_blocks );
0N/A buckcnt[i] = 0;
0N/A // Bump by three orders of magnitude each time
0N/A cutoff *= 0.001;
0N/A buckval[i] = cutoff;
0N/A for( j = 0; j < _cfg._num_blocks; j++ ) {
0N/A buckets[i][j] = NULL;
0N/A }
0N/A }
0N/A // Sort blocks into buckets
0N/A for( i = 0; i < _cfg._num_blocks; i++ ) {
0N/A for( j = 0; j < NUMBUCKS; j++ ) {
0N/A if( (j == NUMBUCKS-1) || (_cfg._blocks[i]->_freq > buckval[j]) ) {
0N/A // Assign block to end of list for appropriate bucket
0N/A buckets[j][buckcnt[j]++] = _cfg._blocks[i];
0N/A break; // kick out of inner loop
0N/A }
0N/A }
0N/A }
0N/A // Dump buckets into final block array
0N/A uint blkcnt = 0;
0N/A for( i = 0; i < NUMBUCKS; i++ ) {
0N/A for( j = 0; j < buckcnt[i]; j++ ) {
0N/A _blks[blkcnt++] = buckets[i][j];
0N/A }
0N/A }
0N/A
0N/A assert(blkcnt == _cfg._num_blocks, "Block array not totally filled");
0N/A}
0N/A
0N/Avoid PhaseChaitin::Register_Allocate() {
0N/A
0N/A // Above the OLD FP (and in registers) are the incoming arguments. Stack
0N/A // slots in this area are called "arg_slots". Above the NEW FP (and in
0N/A // registers) is the outgoing argument area; above that is the spill/temp
0N/A // area. These are all "frame_slots". Arg_slots start at the zero
0N/A // stack_slots and count up to the known arg_size. Frame_slots start at
0N/A // the stack_slot #arg_size and go up. After allocation I map stack
0N/A // slots to actual offsets. Stack-slots in the arg_slot area are biased
0N/A // by the frame_size; stack-slots in the frame_slot area are biased by 0.
0N/A
0N/A _trip_cnt = 0;
0N/A _alternate = 0;
0N/A _matcher._allocation_started = true;
0N/A
3982N/A ResourceArea split_arena; // Arena for Split local resources
0N/A ResourceArea live_arena; // Arena for liveness & IFG info
0N/A ResourceMark rm(&live_arena);
0N/A
0N/A // Need live-ness for the IFG; need the IFG for coalescing. If the
0N/A // liveness is JUST for coalescing, then I can get some mileage by renaming
0N/A // all copy-related live ranges low and then using the max copy-related
0N/A // live range as a cut-off for LIVE and the IFG. In other words, I can
0N/A // build a subset of LIVE and IFG just for copies.
0N/A PhaseLive live(_cfg,_names,&live_arena);
0N/A
0N/A // Need IFG for coalescing and coloring
0N/A PhaseIFG ifg( &live_arena );
0N/A _ifg = &ifg;
0N/A
0N/A if (C->unique() > _names.Size()) _names.extend(C->unique()-1, 0);
0N/A
0N/A // Come out of SSA world to the Named world. Assign (virtual) registers to
0N/A // Nodes. Use the same register for all inputs and the output of PhiNodes
0N/A // - effectively ending SSA form. This requires either coalescing live
0N/A // ranges or inserting copies. For the moment, we insert "virtual copies"
0N/A // - we pretend there is a copy prior to each Phi in predecessor blocks.
0N/A // We will attempt to coalesce such "virtual copies" before we manifest
0N/A // them for real.
0N/A de_ssa();
0N/A
566N/A#ifdef ASSERT
566N/A // Veify the graph before RA.
566N/A verify(&live_arena);
566N/A#endif
566N/A
0N/A {
0N/A NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); )
0N/A _live = NULL; // Mark live as being not available
0N/A rm.reset_to_mark(); // Reclaim working storage
0N/A IndexSet::reset_memory(C, &live_arena);
0N/A ifg.init(_maxlrg); // Empty IFG
0N/A gather_lrg_masks( false ); // Collect LRG masks
0N/A live.compute( _maxlrg ); // Compute liveness
0N/A _live = &live; // Mark LIVE as being available
0N/A }
0N/A
0N/A // Base pointers are currently "used" by instructions which define new
0N/A // derived pointers. This makes base pointers live up to the where the
0N/A // derived pointer is made, but not beyond. Really, they need to be live
0N/A // across any GC point where the derived value is live. So this code looks
0N/A // at all the GC points, and "stretches" the live range of any base pointer
0N/A // to the GC point.
0N/A if( stretch_base_pointer_live_ranges(&live_arena) ) {
0N/A NOT_PRODUCT( Compile::TracePhase t3("computeLive (sbplr)", &_t_computeLive, TimeCompiler); )
0N/A // Since some live range stretched, I need to recompute live
0N/A _live = NULL;
0N/A rm.reset_to_mark(); // Reclaim working storage
0N/A IndexSet::reset_memory(C, &live_arena);
0N/A ifg.init(_maxlrg);
0N/A gather_lrg_masks( false );
0N/A live.compute( _maxlrg );
0N/A _live = &live;
0N/A }
0N/A // Create the interference graph using virtual copies
0N/A build_ifg_virtual( ); // Include stack slots this time
0N/A
0N/A // Aggressive (but pessimistic) copy coalescing.
0N/A // This pass works on virtual copies. Any virtual copies which are not
0N/A // coalesced get manifested as actual copies
0N/A {
0N/A // The IFG is/was triangular. I am 'squaring it up' so Union can run
0N/A // faster. Union requires a 'for all' operation which is slow on the
0N/A // triangular adjacency matrix (quick reminder: the IFG is 'sparse' -
0N/A // meaning I can visit all the Nodes neighbors less than a Node in time
0N/A // O(# of neighbors), but I have to visit all the Nodes greater than a
0N/A // given Node and search them for an instance, i.e., time O(#MaxLRG)).
0N/A _ifg->SquareUp();
0N/A
0N/A PhaseAggressiveCoalesce coalesce( *this );
0N/A coalesce.coalesce_driver( );
0N/A // Insert un-coalesced copies. Visit all Phis. Where inputs to a Phi do
0N/A // not match the Phi itself, insert a copy.
0N/A coalesce.insert_copies(_matcher);
0N/A }
0N/A
0N/A // After aggressive coalesce, attempt a first cut at coloring.
0N/A // To color, we need the IFG and for that we need LIVE.
0N/A {
0N/A NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); )
0N/A _live = NULL;
0N/A rm.reset_to_mark(); // Reclaim working storage
0N/A IndexSet::reset_memory(C, &live_arena);
0N/A ifg.init(_maxlrg);
0N/A gather_lrg_masks( true );
0N/A live.compute( _maxlrg );
0N/A _live = &live;
0N/A }
0N/A
0N/A // Build physical interference graph
0N/A uint must_spill = 0;
0N/A must_spill = build_ifg_physical( &live_arena );
0N/A // If we have a guaranteed spill, might as well spill now
0N/A if( must_spill ) {
0N/A if( !_maxlrg ) return;
0N/A // Bail out if unique gets too large (ie - unique > MaxNodeLimit)
0N/A C->check_node_count(10*must_spill, "out of nodes before split");
0N/A if (C->failing()) return;
3982N/A _maxlrg = Split(_maxlrg, &split_arena); // Split spilling LRG everywhere
0N/A // Bail out if unique gets too large (ie - unique > MaxNodeLimit - 2*NodeLimitFudgeFactor)
0N/A // or we failed to split
0N/A C->check_node_count(2*NodeLimitFudgeFactor, "out of nodes after physical split");
0N/A if (C->failing()) return;
0N/A
0N/A NOT_PRODUCT( C->verify_graph_edges(); )
0N/A
0N/A compact(); // Compact LRGs; return new lower max lrg
0N/A
0N/A {
0N/A NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); )
0N/A _live = NULL;
0N/A rm.reset_to_mark(); // Reclaim working storage
0N/A IndexSet::reset_memory(C, &live_arena);
0N/A ifg.init(_maxlrg); // Build a new interference graph
0N/A gather_lrg_masks( true ); // Collect intersect mask
0N/A live.compute( _maxlrg ); // Compute LIVE
0N/A _live = &live;
0N/A }
0N/A build_ifg_physical( &live_arena );
0N/A _ifg->SquareUp();
0N/A _ifg->Compute_Effective_Degree();
0N/A // Only do conservative coalescing if requested
0N/A if( OptoCoalesce ) {
0N/A // Conservative (and pessimistic) copy coalescing of those spills
0N/A PhaseConservativeCoalesce coalesce( *this );
0N/A // If max live ranges greater than cutoff, don't color the stack.
0N/A // This cutoff can be larger than below since it is only done once.
0N/A coalesce.coalesce_driver( );
0N/A }
0N/A compress_uf_map_for_nodes();
0N/A
0N/A#ifdef ASSERT
566N/A verify(&live_arena, true);
0N/A#endif
0N/A } else {
0N/A ifg.SquareUp();
0N/A ifg.Compute_Effective_Degree();
0N/A#ifdef ASSERT
0N/A set_was_low();
0N/A#endif
0N/A }
0N/A
0N/A // Prepare for Simplify & Select
0N/A cache_lrg_info(); // Count degree of LRGs
0N/A
0N/A // Simplify the InterFerence Graph by removing LRGs of low degree.
0N/A // LRGs of low degree are trivially colorable.
0N/A Simplify();
0N/A
0N/A // Select colors by re-inserting LRGs back into the IFG in reverse order.
0N/A // Return whether or not something spills.
0N/A uint spills = Select( );
0N/A
0N/A // If we spill, split and recycle the entire thing
0N/A while( spills ) {
0N/A if( _trip_cnt++ > 24 ) {
0N/A DEBUG_ONLY( dump_for_spill_split_recycle(); )
0N/A if( _trip_cnt > 27 ) {
0N/A C->record_method_not_compilable("failed spill-split-recycle sanity check");
0N/A return;
0N/A }
0N/A }
0N/A
0N/A if( !_maxlrg ) return;
3982N/A _maxlrg = Split(_maxlrg, &split_arena); // Split spilling LRG everywhere
0N/A // Bail out if unique gets too large (ie - unique > MaxNodeLimit - 2*NodeLimitFudgeFactor)
0N/A C->check_node_count(2*NodeLimitFudgeFactor, "out of nodes after split");
0N/A if (C->failing()) return;
0N/A
0N/A compact(); // Compact LRGs; return new lower max lrg
0N/A
0N/A // Nuke the live-ness and interference graph and LiveRanGe info
0N/A {
0N/A NOT_PRODUCT( Compile::TracePhase t3("computeLive", &_t_computeLive, TimeCompiler); )
0N/A _live = NULL;
0N/A rm.reset_to_mark(); // Reclaim working storage
0N/A IndexSet::reset_memory(C, &live_arena);
0N/A ifg.init(_maxlrg);
0N/A
0N/A // Create LiveRanGe array.
0N/A // Intersect register masks for all USEs and DEFs
0N/A gather_lrg_masks( true );
0N/A live.compute( _maxlrg );
0N/A _live = &live;
0N/A }
0N/A must_spill = build_ifg_physical( &live_arena );
0N/A _ifg->SquareUp();
0N/A _ifg->Compute_Effective_Degree();
0N/A
0N/A // Only do conservative coalescing if requested
0N/A if( OptoCoalesce ) {
0N/A // Conservative (and pessimistic) copy coalescing
0N/A PhaseConservativeCoalesce coalesce( *this );
0N/A // Check for few live ranges determines how aggressive coalesce is.
0N/A coalesce.coalesce_driver( );
0N/A }
0N/A compress_uf_map_for_nodes();
0N/A#ifdef ASSERT
566N/A verify(&live_arena, true);
0N/A#endif
0N/A cache_lrg_info(); // Count degree of LRGs
0N/A
0N/A // Simplify the InterFerence Graph by removing LRGs of low degree.
0N/A // LRGs of low degree are trivially colorable.
0N/A Simplify();
0N/A
0N/A // Select colors by re-inserting LRGs back into the IFG in reverse order.
0N/A // Return whether or not something spills.
0N/A spills = Select( );
0N/A }
0N/A
0N/A // Count number of Simplify-Select trips per coloring success.
0N/A _allocator_attempts += _trip_cnt + 1;
0N/A _allocator_successes += 1;
0N/A
0N/A // Peephole remove copies
0N/A post_allocate_copy_removal();
0N/A
566N/A#ifdef ASSERT
566N/A // Veify the graph after RA.
566N/A verify(&live_arena);
566N/A#endif
566N/A
0N/A // max_reg is past the largest *register* used.
0N/A // Convert that to a frame_slot number.
0N/A if( _max_reg <= _matcher._new_SP )
0N/A _framesize = C->out_preserve_stack_slots();
0N/A else _framesize = _max_reg -_matcher._new_SP;
0N/A assert((int)(_matcher._new_SP+_framesize) >= (int)_matcher._out_arg_limit, "framesize must be large enough");
0N/A
0N/A // This frame must preserve the required fp alignment
419N/A _framesize = round_to(_framesize, Matcher::stack_alignment_in_slots());
0N/A assert( _framesize >= 0 && _framesize <= 1000000, "sanity check" );
0N/A#ifndef PRODUCT
0N/A _total_framesize += _framesize;
0N/A if( (int)_framesize > _max_framesize )
0N/A _max_framesize = _framesize;
0N/A#endif
0N/A
0N/A // Convert CISC spills
0N/A fixup_spills();
0N/A
0N/A // Log regalloc results
0N/A CompileLog* log = Compile::current()->log();
0N/A if (log != NULL) {
0N/A log->elem("regalloc attempts='%d' success='%d'", _trip_cnt, !C->failing());
0N/A }
0N/A
0N/A if (C->failing()) return;
0N/A
0N/A NOT_PRODUCT( C->verify_graph_edges(); )
0N/A
0N/A // Move important info out of the live_arena to longer lasting storage.
0N/A alloc_node_regs(_names.Size());
3845N/A for (uint i=0; i < _names.Size(); i++) {
3845N/A if (_names[i]) { // Live range associated with Node?
3845N/A LRG &lrg = lrgs(_names[i]);
3845N/A if (!lrg.alive()) {
3970N/A set_bad(i);
3845N/A } else if (lrg.num_regs() == 1) {
3970N/A set1(i, lrg.reg());
3970N/A } else { // Must be a register-set
3970N/A if (!lrg._fat_proj) { // Must be aligned adjacent register set
0N/A // Live ranges record the highest register in their mask.
0N/A // We want the low register for the AD file writer's convenience.
3970N/A OptoReg::Name hi = lrg.reg(); // Get hi register
3970N/A OptoReg::Name lo = OptoReg::add(hi, (1-lrg.num_regs())); // Find lo
3970N/A // We have to use pair [lo,lo+1] even for wide vectors because
3970N/A // the rest of code generation works only with pairs. It is safe
3970N/A // since for registers encoding only 'lo' is used.
3970N/A // Second reg from pair is used in ScheduleAndBundle on SPARC where
3970N/A // vector max size is 8 which corresponds to registers pair.
3970N/A // It is also used in BuildOopMaps but oop operations are not
3970N/A // vectorized.
3970N/A set2(i, lo);
0N/A } else { // Misaligned; extract 2 bits
0N/A OptoReg::Name hi = lrg.reg(); // Get hi register
0N/A lrg.Remove(hi); // Yank from mask
0N/A int lo = lrg.mask().find_first_elem(); // Find lo
3970N/A set_pair(i, hi, lo);
0N/A }
0N/A }
0N/A if( lrg._is_oop ) _node_oops.set(i);
0N/A } else {
3970N/A set_bad(i);
0N/A }
0N/A }
0N/A
0N/A // Done!
0N/A _live = NULL;
0N/A _ifg = NULL;
0N/A C->set_indexSet_arena(NULL); // ResourceArea is at end of scope
0N/A}
0N/A
0N/A//------------------------------de_ssa-----------------------------------------
0N/Avoid PhaseChaitin::de_ssa() {
0N/A // Set initial Names for all Nodes. Most Nodes get the virtual register
0N/A // number. A few get the ZERO live range number. These do not
0N/A // get allocated, but instead rely on correct scheduling to ensure that
0N/A // only one instance is simultaneously live at a time.
0N/A uint lr_counter = 1;
0N/A for( uint i = 0; i < _cfg._num_blocks; i++ ) {
0N/A Block *b = _cfg._blocks[i];
0N/A uint cnt = b->_nodes.size();
0N/A
0N/A // Handle all the normal Nodes in the block
0N/A for( uint j = 0; j < cnt; j++ ) {
0N/A Node *n = b->_nodes[j];
0N/A // Pre-color to the zero live range, or pick virtual register
0N/A const RegMask &rm = n->out_RegMask();
0N/A _names.map( n->_idx, rm.is_NotEmpty() ? lr_counter++ : 0 );
0N/A }
0N/A }
0N/A // Reset the Union-Find mapping to be identity
0N/A reset_uf_map(lr_counter);
0N/A}
0N/A
0N/A
0N/A//------------------------------gather_lrg_masks-------------------------------
0N/A// Gather LiveRanGe information, including register masks. Modification of
0N/A// cisc spillable in_RegMasks should not be done before AggressiveCoalesce.
0N/Avoid PhaseChaitin::gather_lrg_masks( bool after_aggressive ) {
0N/A
0N/A // Nail down the frame pointer live range
0N/A uint fp_lrg = n2lidx(_cfg._root->in(1)->in(TypeFunc::FramePtr));
0N/A lrgs(fp_lrg)._cost += 1e12; // Cost is infinite
0N/A
0N/A // For all blocks
0N/A for( uint i = 0; i < _cfg._num_blocks; i++ ) {
0N/A Block *b = _cfg._blocks[i];
0N/A
0N/A // For all instructions
0N/A for( uint j = 1; j < b->_nodes.size(); j++ ) {
0N/A Node *n = b->_nodes[j];
0N/A uint input_edge_start =1; // Skip control most nodes
0N/A if( n->is_Mach() ) input_edge_start = n->as_Mach()->oper_input_base();
0N/A uint idx = n->is_Copy();
0N/A
0N/A // Get virtual register number, same as LiveRanGe index
0N/A uint vreg = n2lidx(n);
0N/A LRG &lrg = lrgs(vreg);
0N/A if( vreg ) { // No vreg means un-allocable (e.g. memory)
0N/A
0N/A // Collect has-copy bit
0N/A if( idx ) {
0N/A lrg._has_copy = 1;
0N/A uint clidx = n2lidx(n->in(idx));
0N/A LRG &copy_src = lrgs(clidx);
0N/A copy_src._has_copy = 1;
0N/A }
0N/A
0N/A // Check for float-vs-int live range (used in register-pressure
0N/A // calculations)
0N/A const Type *n_type = n->bottom_type();
3845N/A if (n_type->is_floatingpoint())
0N/A lrg._is_float = 1;
0N/A
0N/A // Check for twice prior spilling. Once prior spilling might have
0N/A // spilled 'soft', 2nd prior spill should have spilled 'hard' and
0N/A // further spilling is unlikely to make progress.
0N/A if( _spilled_once.test(n->_idx) ) {
0N/A lrg._was_spilled1 = 1;
0N/A if( _spilled_twice.test(n->_idx) )
0N/A lrg._was_spilled2 = 1;
0N/A }
0N/A
0N/A#ifndef PRODUCT
0N/A if (trace_spilling() && lrg._def != NULL) {
0N/A // collect defs for MultiDef printing
0N/A if (lrg._defs == NULL) {
1605N/A lrg._defs = new (_ifg->_arena) GrowableArray<Node*>(_ifg->_arena, 2, 0, NULL);
0N/A lrg._defs->append(lrg._def);
0N/A }
0N/A lrg._defs->append(n);
0N/A }
0N/A#endif
0N/A
0N/A // Check for a single def LRG; these can spill nicely
0N/A // via rematerialization. Flag as NULL for no def found
0N/A // yet, or 'n' for single def or -1 for many defs.
0N/A lrg._def = lrg._def ? NodeSentinel : n;
0N/A
0N/A // Limit result register mask to acceptable registers
0N/A const RegMask &rm = n->out_RegMask();
0N/A lrg.AND( rm );
0N/A
0N/A int ireg = n->ideal_reg();
0N/A assert( !n->bottom_type()->isa_oop_ptr() || ireg == Op_RegP,
0N/A "oops must be in Op_RegP's" );
3845N/A
3845N/A // Check for vector live range (only if vector register is used).
3845N/A // On SPARC vector uses RegD which could be misaligned so it is not
3845N/A // processes as vector in RA.
3845N/A if (RegMask::is_vector(ireg))
3845N/A lrg._is_vector = 1;
3845N/A assert(n_type->isa_vect() == NULL || lrg._is_vector || ireg == Op_RegD,
3845N/A "vector must be in vector registers");
3845N/A
3845N/A // Check for bound register masks
3845N/A const RegMask &lrgmask = lrg.mask();
3845N/A if (lrgmask.is_bound(ireg))
3845N/A lrg._is_bound = 1;
3845N/A
3845N/A // Check for maximum frequency value
3845N/A if (lrg._maxfreq < b->_freq)
3845N/A lrg._maxfreq = b->_freq;
3845N/A
0N/A // Check for oop-iness, or long/double
0N/A // Check for multi-kill projection
0N/A switch( ireg ) {
0N/A case MachProjNode::fat_proj:
0N/A // Fat projections have size equal to number of registers killed
0N/A lrg.set_num_regs(rm.Size());
0N/A lrg.set_reg_pressure(lrg.num_regs());
0N/A lrg._fat_proj = 1;
0N/A lrg._is_bound = 1;
0N/A break;
0N/A case Op_RegP:
0N/A#ifdef _LP64
0N/A lrg.set_num_regs(2); // Size is 2 stack words
0N/A#else
0N/A lrg.set_num_regs(1); // Size is 1 stack word
0N/A#endif
0N/A // Register pressure is tracked relative to the maximum values
0N/A // suggested for that platform, INTPRESSURE and FLOATPRESSURE,
0N/A // and relative to other types which compete for the same regs.
0N/A //
0N/A // The following table contains suggested values based on the
0N/A // architectures as defined in each .ad file.
0N/A // INTPRESSURE and FLOATPRESSURE may be tuned differently for
0N/A // compile-speed or performance.
0N/A // Note1:
0N/A // SPARC and SPARCV9 reg_pressures are at 2 instead of 1
0N/A // since .ad registers are defined as high and low halves.
0N/A // These reg_pressure values remain compatible with the code
0N/A // in is_high_pressure() which relates get_invalid_mask_size(),
0N/A // Block::_reg_pressure and INTPRESSURE, FLOATPRESSURE.
0N/A // Note2:
0N/A // SPARC -d32 has 24 registers available for integral values,
0N/A // but only 10 of these are safe for 64-bit longs.
0N/A // Using set_reg_pressure(2) for both int and long means
0N/A // the allocator will believe it can fit 26 longs into
0N/A // registers. Using 2 for longs and 1 for ints means the
0N/A // allocator will attempt to put 52 integers into registers.
0N/A // The settings below limit this problem to methods with
0N/A // many long values which are being run on 32-bit SPARC.
0N/A //
0N/A // ------------------- reg_pressure --------------------
0N/A // Each entry is reg_pressure_per_value,number_of_regs
0N/A // RegL RegI RegFlags RegF RegD INTPRESSURE FLOATPRESSURE
0N/A // IA32 2 1 1 1 1 6 6
0N/A // IA64 1 1 1 1 1 50 41
0N/A // SPARC 2 2 2 2 2 48 (24) 52 (26)
0N/A // SPARCV9 2 2 2 2 2 48 (24) 52 (26)
0N/A // AMD64 1 1 1 1 1 14 15
0N/A // -----------------------------------------------------
0N/A#if defined(SPARC)
0N/A lrg.set_reg_pressure(2); // use for v9 as well
0N/A#else
0N/A lrg.set_reg_pressure(1); // normally one value per register
0N/A#endif
0N/A if( n_type->isa_oop_ptr() ) {
0N/A lrg._is_oop = 1;
0N/A }
0N/A break;
0N/A case Op_RegL: // Check for long or double
0N/A case Op_RegD:
0N/A lrg.set_num_regs(2);
0N/A // Define platform specific register pressure
2248N/A#if defined(SPARC) || defined(ARM)
0N/A lrg.set_reg_pressure(2);
0N/A#elif defined(IA32)
0N/A if( ireg == Op_RegL ) {
0N/A lrg.set_reg_pressure(2);
0N/A } else {
0N/A lrg.set_reg_pressure(1);
0N/A }
0N/A#else
0N/A lrg.set_reg_pressure(1); // normally one value per register
0N/A#endif
0N/A // If this def of a double forces a mis-aligned double,
0N/A // flag as '_fat_proj' - really flag as allowing misalignment
0N/A // AND changes how we count interferences. A mis-aligned
0N/A // double can interfere with TWO aligned pairs, or effectively
0N/A // FOUR registers!
3845N/A if (rm.is_misaligned_pair()) {
0N/A lrg._fat_proj = 1;
0N/A lrg._is_bound = 1;
0N/A }
0N/A break;
0N/A case Op_RegF:
0N/A case Op_RegI:
113N/A case Op_RegN:
0N/A case Op_RegFlags:
0N/A case 0: // not an ideal register
0N/A lrg.set_num_regs(1);
0N/A#ifdef SPARC
0N/A lrg.set_reg_pressure(2);
0N/A#else
0N/A lrg.set_reg_pressure(1);
0N/A#endif
0N/A break;
3845N/A case Op_VecS:
3845N/A assert(Matcher::vector_size_supported(T_BYTE,4), "sanity");
3845N/A assert(RegMask::num_registers(Op_VecS) == RegMask::SlotsPerVecS, "sanity");
3845N/A lrg.set_num_regs(RegMask::SlotsPerVecS);
3845N/A lrg.set_reg_pressure(1);
3845N/A break;
3845N/A case Op_VecD:
3845N/A assert(Matcher::vector_size_supported(T_FLOAT,RegMask::SlotsPerVecD), "sanity");
3845N/A assert(RegMask::num_registers(Op_VecD) == RegMask::SlotsPerVecD, "sanity");
3845N/A assert(lrgmask.is_aligned_sets(RegMask::SlotsPerVecD), "vector should be aligned");
3845N/A lrg.set_num_regs(RegMask::SlotsPerVecD);
3845N/A lrg.set_reg_pressure(1);
3845N/A break;
3845N/A case Op_VecX:
3845N/A assert(Matcher::vector_size_supported(T_FLOAT,RegMask::SlotsPerVecX), "sanity");
3845N/A assert(RegMask::num_registers(Op_VecX) == RegMask::SlotsPerVecX, "sanity");
3845N/A assert(lrgmask.is_aligned_sets(RegMask::SlotsPerVecX), "vector should be aligned");
3845N/A lrg.set_num_regs(RegMask::SlotsPerVecX);
3845N/A lrg.set_reg_pressure(1);
3845N/A break;
3845N/A case Op_VecY:
3845N/A assert(Matcher::vector_size_supported(T_FLOAT,RegMask::SlotsPerVecY), "sanity");
3845N/A assert(RegMask::num_registers(Op_VecY) == RegMask::SlotsPerVecY, "sanity");
3845N/A assert(lrgmask.is_aligned_sets(RegMask::SlotsPerVecY), "vector should be aligned");
3845N/A lrg.set_num_regs(RegMask::SlotsPerVecY);
3845N/A lrg.set_reg_pressure(1);
3845N/A break;
0N/A default:
0N/A ShouldNotReachHere();
0N/A }
0N/A }
0N/A
0N/A // Now do the same for inputs
0N/A uint cnt = n->req();
0N/A // Setup for CISC SPILLING
0N/A uint inp = (uint)AdlcVMDeps::Not_cisc_spillable;
0N/A if( UseCISCSpill && after_aggressive ) {
0N/A inp = n->cisc_operand();
0N/A if( inp != (uint)AdlcVMDeps::Not_cisc_spillable )
0N/A // Convert operand number to edge index number
0N/A inp = n->as_Mach()->operand_index(inp);
0N/A }
0N/A // Prepare register mask for each input
0N/A for( uint k = input_edge_start; k < cnt; k++ ) {
0N/A uint vreg = n2lidx(n->in(k));
0N/A if( !vreg ) continue;
0N/A
0N/A // If this instruction is CISC Spillable, add the flags
0N/A // bit to its appropriate input
0N/A if( UseCISCSpill && after_aggressive && inp == k ) {
0N/A#ifndef PRODUCT
0N/A if( TraceCISCSpill ) {
0N/A tty->print(" use_cisc_RegMask: ");
0N/A n->dump();
0N/A }
0N/A#endif
0N/A n->as_Mach()->use_cisc_RegMask();
0N/A }
0N/A
0N/A LRG &lrg = lrgs(vreg);
0N/A // // Testing for floating point code shape
0N/A // Node *test = n->in(k);
0N/A // if( test->is_Mach() ) {
0N/A // MachNode *m = test->as_Mach();
0N/A // int op = m->ideal_Opcode();
0N/A // if (n->is_Call() && (op == Op_AddF || op == Op_MulF) ) {
0N/A // int zzz = 1;
0N/A // }
0N/A // }
0N/A
0N/A // Limit result register mask to acceptable registers.
0N/A // Do not limit registers from uncommon uses before
0N/A // AggressiveCoalesce. This effectively pre-virtual-splits
0N/A // around uncommon uses of common defs.
0N/A const RegMask &rm = n->in_RegMask(k);
0N/A if( !after_aggressive &&
0N/A _cfg._bbs[n->in(k)->_idx]->_freq > 1000*b->_freq ) {
0N/A // Since we are BEFORE aggressive coalesce, leave the register
0N/A // mask untrimmed by the call. This encourages more coalescing.
0N/A // Later, AFTER aggressive, this live range will have to spill
0N/A // but the spiller handles slow-path calls very nicely.
0N/A } else {
0N/A lrg.AND( rm );
0N/A }
3845N/A
0N/A // Check for bound register masks
0N/A const RegMask &lrgmask = lrg.mask();
3845N/A int kreg = n->in(k)->ideal_reg();
3845N/A bool is_vect = RegMask::is_vector(kreg);
3845N/A assert(n->in(k)->bottom_type()->isa_vect() == NULL ||
3845N/A is_vect || kreg == Op_RegD,
3845N/A "vector must be in vector registers");
3845N/A if (lrgmask.is_bound(kreg))
0N/A lrg._is_bound = 1;
3845N/A
0N/A // If this use of a double forces a mis-aligned double,
0N/A // flag as '_fat_proj' - really flag as allowing misalignment
0N/A // AND changes how we count interferences. A mis-aligned
0N/A // double can interfere with TWO aligned pairs, or effectively
0N/A // FOUR registers!
3845N/A#ifdef ASSERT
3845N/A if (is_vect) {
3845N/A assert(lrgmask.is_aligned_sets(lrg.num_regs()), "vector should be aligned");
3845N/A assert(!lrg._fat_proj, "sanity");
3845N/A assert(RegMask::num_registers(kreg) == lrg.num_regs(), "sanity");
3845N/A }
3845N/A#endif
3845N/A if (!is_vect && lrg.num_regs() == 2 && !lrg._fat_proj && rm.is_misaligned_pair()) {
0N/A lrg._fat_proj = 1;
0N/A lrg._is_bound = 1;
0N/A }
0N/A // if the LRG is an unaligned pair, we will have to spill
0N/A // so clear the LRG's register mask if it is not already spilled
3845N/A if (!is_vect && !n->is_SpillCopy() &&
3845N/A (lrg._def == NULL || lrg.is_multidef() || !lrg._def->is_SpillCopy()) &&
3845N/A lrgmask.is_misaligned_pair()) {
0N/A lrg.Clear();
0N/A }
0N/A
0N/A // Check for maximum frequency value
0N/A if( lrg._maxfreq < b->_freq )
0N/A lrg._maxfreq = b->_freq;
0N/A
0N/A } // End for all allocated inputs
0N/A } // end for all instructions
0N/A } // end for all blocks
0N/A
0N/A // Final per-liverange setup
3845N/A for (uint i2=0; i2<_maxlrg; i2++) {
0N/A LRG &lrg = lrgs(i2);
3845N/A assert(!lrg._is_vector || !lrg._fat_proj, "sanity");
3845N/A if (lrg.num_regs() > 1 && !lrg._fat_proj) {
3845N/A lrg.clear_to_sets();
3845N/A }
0N/A lrg.compute_set_mask_size();
3845N/A if (lrg.not_free()) { // Handle case where we lose from the start
0N/A lrg.set_reg(OptoReg::Name(LRG::SPILL_REG));
0N/A lrg._direct_conflict = 1;
0N/A }
0N/A lrg.set_degree(0); // no neighbors in IFG yet
0N/A }
0N/A}
0N/A
0N/A//------------------------------set_was_low------------------------------------
0N/A// Set the was-lo-degree bit. Conservative coalescing should not change the
0N/A// colorability of the graph. If any live range was of low-degree before
0N/A// coalescing, it should Simplify. This call sets the was-lo-degree bit.
0N/A// The bit is checked in Simplify.
0N/Avoid PhaseChaitin::set_was_low() {
0N/A#ifdef ASSERT
0N/A for( uint i = 1; i < _maxlrg; i++ ) {
0N/A int size = lrgs(i).num_regs();
0N/A uint old_was_lo = lrgs(i)._was_lo;
0N/A lrgs(i)._was_lo = 0;
0N/A if( lrgs(i).lo_degree() ) {
0N/A lrgs(i)._was_lo = 1; // Trivially of low degree
0N/A } else { // Else check the Brigg's assertion
0N/A // Brigg's observation is that the lo-degree neighbors of a
0N/A // hi-degree live range will not interfere with the color choices
0N/A // of said hi-degree live range. The Simplify reverse-stack-coloring
0N/A // order takes care of the details. Hence you do not have to count
0N/A // low-degree neighbors when determining if this guy colors.
0N/A int briggs_degree = 0;
0N/A IndexSet *s = _ifg->neighbors(i);
0N/A IndexSetIterator elements(s);
0N/A uint lidx;
0N/A while((lidx = elements.next()) != 0) {
0N/A if( !lrgs(lidx).lo_degree() )
0N/A briggs_degree += MAX2(size,lrgs(lidx).num_regs());
0N/A }
0N/A if( briggs_degree < lrgs(i).degrees_of_freedom() )
0N/A lrgs(i)._was_lo = 1; // Low degree via the briggs assertion
0N/A }
0N/A assert(old_was_lo <= lrgs(i)._was_lo, "_was_lo may not decrease");
0N/A }
0N/A#endif
0N/A}
0N/A
0N/A#define REGISTER_CONSTRAINED 16
0N/A
0N/A//------------------------------cache_lrg_info---------------------------------
0N/A// Compute cost/area ratio, in case we spill. Build the lo-degree list.
0N/Avoid PhaseChaitin::cache_lrg_info( ) {
0N/A
0N/A for( uint i = 1; i < _maxlrg; i++ ) {
0N/A LRG &lrg = lrgs(i);
0N/A
0N/A // Check for being of low degree: means we can be trivially colored.
0N/A // Low degree, dead or must-spill guys just get to simplify right away
0N/A if( lrg.lo_degree() ||
0N/A !lrg.alive() ||
0N/A lrg._must_spill ) {
0N/A // Split low degree list into those guys that must get a
0N/A // register and those that can go to register or stack.
0N/A // The idea is LRGs that can go register or stack color first when
0N/A // they have a good chance of getting a register. The register-only
0N/A // lo-degree live ranges always get a register.
0N/A OptoReg::Name hi_reg = lrg.mask().find_last_elem();
0N/A if( OptoReg::is_stack(hi_reg)) { // Can go to stack?
0N/A lrg._next = _lo_stk_degree;
0N/A _lo_stk_degree = i;
0N/A } else {
0N/A lrg._next = _lo_degree;
0N/A _lo_degree = i;
0N/A }
0N/A } else { // Else high degree
0N/A lrgs(_hi_degree)._prev = i;
0N/A lrg._next = _hi_degree;
0N/A lrg._prev = 0;
0N/A _hi_degree = i;
0N/A }
0N/A }
0N/A}
0N/A
0N/A//------------------------------Pre-Simplify-----------------------------------
0N/A// Simplify the IFG by removing LRGs of low degree that have NO copies
0N/Avoid PhaseChaitin::Pre_Simplify( ) {
0N/A
0N/A // Warm up the lo-degree no-copy list
0N/A int lo_no_copy = 0;
0N/A for( uint i = 1; i < _maxlrg; i++ ) {
0N/A if( (lrgs(i).lo_degree() && !lrgs(i)._has_copy) ||
0N/A !lrgs(i).alive() ||
0N/A lrgs(i)._must_spill ) {
0N/A lrgs(i)._next = lo_no_copy;
0N/A lo_no_copy = i;
0N/A }
0N/A }
0N/A
0N/A while( lo_no_copy ) {
0N/A uint lo = lo_no_copy;
0N/A lo_no_copy = lrgs(lo)._next;
0N/A int size = lrgs(lo).num_regs();
0N/A
0N/A // Put the simplified guy on the simplified list.
0N/A lrgs(lo)._next = _simplified;
0N/A _simplified = lo;
0N/A
0N/A // Yank this guy from the IFG.
0N/A IndexSet *adj = _ifg->remove_node( lo );
0N/A
0N/A // If any neighbors' degrees fall below their number of
0N/A // allowed registers, then put that neighbor on the low degree
0N/A // list. Note that 'degree' can only fall and 'numregs' is
0N/A // unchanged by this action. Thus the two are equal at most once,
0N/A // so LRGs hit the lo-degree worklists at most once.
0N/A IndexSetIterator elements(adj);
0N/A uint neighbor;
0N/A while ((neighbor = elements.next()) != 0) {
0N/A LRG *n = &lrgs(neighbor);
0N/A assert( _ifg->effective_degree(neighbor) == n->degree(), "" );
0N/A
0N/A // Check for just becoming of-low-degree
0N/A if( n->just_lo_degree() && !n->_has_copy ) {
0N/A assert(!(*_ifg->_yanked)[neighbor],"Cannot move to lo degree twice");
0N/A // Put on lo-degree list
0N/A n->_next = lo_no_copy;
0N/A lo_no_copy = neighbor;
0N/A }
0N/A }
0N/A } // End of while lo-degree no_copy worklist not empty
0N/A
0N/A // No more lo-degree no-copy live ranges to simplify
0N/A}
0N/A
0N/A//------------------------------Simplify---------------------------------------
0N/A// Simplify the IFG by removing LRGs of low degree.
0N/Avoid PhaseChaitin::Simplify( ) {
0N/A
0N/A while( 1 ) { // Repeat till simplified it all
0N/A // May want to explore simplifying lo_degree before _lo_stk_degree.
0N/A // This might result in more spills coloring into registers during
0N/A // Select().
0N/A while( _lo_degree || _lo_stk_degree ) {
0N/A // If possible, pull from lo_stk first
0N/A uint lo;
0N/A if( _lo_degree ) {
0N/A lo = _lo_degree;
0N/A _lo_degree = lrgs(lo)._next;
0N/A } else {
0N/A lo = _lo_stk_degree;
0N/A _lo_stk_degree = lrgs(lo)._next;
0N/A }
0N/A
0N/A // Put the simplified guy on the simplified list.
0N/A lrgs(lo)._next = _simplified;
0N/A _simplified = lo;
0N/A // If this guy is "at risk" then mark his current neighbors
0N/A if( lrgs(lo)._at_risk ) {
0N/A IndexSetIterator elements(_ifg->neighbors(lo));
0N/A uint datum;
0N/A while ((datum = elements.next()) != 0) {
0N/A lrgs(datum)._risk_bias = lo;
0N/A }
0N/A }
0N/A
0N/A // Yank this guy from the IFG.
0N/A IndexSet *adj = _ifg->remove_node( lo );
0N/A
0N/A // If any neighbors' degrees fall below their number of
0N/A // allowed registers, then put that neighbor on the low degree
0N/A // list. Note that 'degree' can only fall and 'numregs' is
0N/A // unchanged by this action. Thus the two are equal at most once,
0N/A // so LRGs hit the lo-degree worklist at most once.
0N/A IndexSetIterator elements(adj);
0N/A uint neighbor;
0N/A while ((neighbor = elements.next()) != 0) {
0N/A LRG *n = &lrgs(neighbor);
0N/A#ifdef ASSERT
550N/A if( VerifyOpto || VerifyRegisterAllocator ) {
0N/A assert( _ifg->effective_degree(neighbor) == n->degree(), "" );
0N/A }
0N/A#endif
0N/A
0N/A // Check for just becoming of-low-degree just counting registers.
0N/A // _must_spill live ranges are already on the low degree list.
0N/A if( n->just_lo_degree() && !n->_must_spill ) {
0N/A assert(!(*_ifg->_yanked)[neighbor],"Cannot move to lo degree twice");
0N/A // Pull from hi-degree list
0N/A uint prev = n->_prev;
0N/A uint next = n->_next;
0N/A if( prev ) lrgs(prev)._next = next;
0N/A else _hi_degree = next;
0N/A lrgs(next)._prev = prev;
0N/A n->_next = _lo_degree;
0N/A _lo_degree = neighbor;
0N/A }
0N/A }
0N/A } // End of while lo-degree/lo_stk_degree worklist not empty
0N/A
0N/A // Check for got everything: is hi-degree list empty?
0N/A if( !_hi_degree ) break;
0N/A
0N/A // Time to pick a potential spill guy
0N/A uint lo_score = _hi_degree;
0N/A double score = lrgs(lo_score).score();
0N/A double area = lrgs(lo_score)._area;
1008N/A double cost = lrgs(lo_score)._cost;
1008N/A bool bound = lrgs(lo_score)._is_bound;
0N/A
0N/A // Find cheapest guy
0N/A debug_only( int lo_no_simplify=0; );
1012N/A for( uint i = _hi_degree; i; i = lrgs(i)._next ) {
0N/A assert( !(*_ifg->_yanked)[i], "" );
0N/A // It's just vaguely possible to move hi-degree to lo-degree without
0N/A // going through a just-lo-degree stage: If you remove a double from
0N/A // a float live range it's degree will drop by 2 and you can skip the
0N/A // just-lo-degree stage. It's very rare (shows up after 5000+ methods
0N/A // in -Xcomp of Java2Demo). So just choose this guy to simplify next.
0N/A if( lrgs(i).lo_degree() ) {
0N/A lo_score = i;
0N/A break;
0N/A }
0N/A debug_only( if( lrgs(i)._was_lo ) lo_no_simplify=i; );
0N/A double iscore = lrgs(i).score();
0N/A double iarea = lrgs(i)._area;
1008N/A double icost = lrgs(i)._cost;
1008N/A bool ibound = lrgs(i)._is_bound;
0N/A
0N/A // Compare cost/area of i vs cost/area of lo_score. Smaller cost/area
0N/A // wins. Ties happen because all live ranges in question have spilled
0N/A // a few times before and the spill-score adds a huge number which
0N/A // washes out the low order bits. We are choosing the lesser of 2
0N/A // evils; in this case pick largest area to spill.
1008N/A // Ties also happen when live ranges are defined and used only inside
1008N/A // one block. In which case their area is 0 and score set to max.
1008N/A // In such case choose bound live range over unbound to free registers
1008N/A // or with smaller cost to spill.
0N/A if( iscore < score ||
1008N/A (iscore == score && iarea > area && lrgs(lo_score)._was_spilled2) ||
1008N/A (iscore == score && iarea == area &&
1008N/A ( (ibound && !bound) || ibound == bound && (icost < cost) )) ) {
0N/A lo_score = i;
0N/A score = iscore;
0N/A area = iarea;
1008N/A cost = icost;
1008N/A bound = ibound;
0N/A }
0N/A }
0N/A LRG *lo_lrg = &lrgs(lo_score);
0N/A // The live range we choose for spilling is either hi-degree, or very
0N/A // rarely it can be low-degree. If we choose a hi-degree live range
0N/A // there better not be any lo-degree choices.
0N/A assert( lo_lrg->lo_degree() || !lo_no_simplify, "Live range was lo-degree before coalesce; should simplify" );
0N/A
0N/A // Pull from hi-degree list
0N/A uint prev = lo_lrg->_prev;
0N/A uint next = lo_lrg->_next;
0N/A if( prev ) lrgs(prev)._next = next;
0N/A else _hi_degree = next;
0N/A lrgs(next)._prev = prev;
0N/A // Jam him on the lo-degree list, despite his high degree.
0N/A // Maybe he'll get a color, and maybe he'll spill.
0N/A // Only Select() will know.
0N/A lrgs(lo_score)._at_risk = true;
0N/A _lo_degree = lo_score;
0N/A lo_lrg->_next = 0;
0N/A
0N/A } // End of while not simplified everything
0N/A
0N/A}
0N/A
3970N/A//------------------------------is_legal_reg-----------------------------------
3970N/A// Is 'reg' register legal for 'lrg'?
3970N/Astatic bool is_legal_reg(LRG &lrg, OptoReg::Name reg, int chunk) {
3970N/A if (reg >= chunk && reg < (chunk + RegMask::CHUNK_SIZE) &&
3970N/A lrg.mask().Member(OptoReg::add(reg,-chunk))) {
3970N/A // RA uses OptoReg which represent the highest element of a registers set.
3970N/A // For example, vectorX (128bit) on x86 uses [XMM,XMMb,XMMc,XMMd] set
3970N/A // in which XMMd is used by RA to represent such vectors. A double value
3970N/A // uses [XMM,XMMb] pairs and XMMb is used by RA for it.
3970N/A // The register mask uses largest bits set of overlapping register sets.
3970N/A // On x86 with AVX it uses 8 bits for each XMM registers set.
3970N/A //
3970N/A // The 'lrg' already has cleared-to-set register mask (done in Select()
3970N/A // before calling choose_color()). Passing mask.Member(reg) check above
3970N/A // indicates that the size (num_regs) of 'reg' set is less or equal to
3970N/A // 'lrg' set size.
3970N/A // For set size 1 any register which is member of 'lrg' mask is legal.
3970N/A if (lrg.num_regs()==1)
3970N/A return true;
3970N/A // For larger sets only an aligned register with the same set size is legal.
3970N/A int mask = lrg.num_regs()-1;
3970N/A if ((reg&mask) == mask)
3970N/A return true;
3970N/A }
3970N/A return false;
3970N/A}
3970N/A
0N/A//------------------------------bias_color-------------------------------------
0N/A// Choose a color using the biasing heuristic
0N/AOptoReg::Name PhaseChaitin::bias_color( LRG &lrg, int chunk ) {
0N/A
0N/A // Check for "at_risk" LRG's
0N/A uint risk_lrg = Find(lrg._risk_bias);
0N/A if( risk_lrg != 0 ) {
0N/A // Walk the colored neighbors of the "at_risk" candidate
0N/A // Choose a color which is both legal and already taken by a neighbor
0N/A // of the "at_risk" candidate in order to improve the chances of the
0N/A // "at_risk" candidate of coloring
0N/A IndexSetIterator elements(_ifg->neighbors(risk_lrg));
0N/A uint datum;
0N/A while ((datum = elements.next()) != 0) {
0N/A OptoReg::Name reg = lrgs(datum).reg();
0N/A // If this LRG's register is legal for us, choose it
3970N/A if (is_legal_reg(lrg, reg, chunk))
0N/A return reg;
0N/A }
0N/A }
0N/A
0N/A uint copy_lrg = Find(lrg._copy_bias);
0N/A if( copy_lrg != 0 ) {
0N/A // If he has a color,
0N/A if( !(*(_ifg->_yanked))[copy_lrg] ) {
0N/A OptoReg::Name reg = lrgs(copy_lrg).reg();
0N/A // And it is legal for you,
3970N/A if (is_legal_reg(lrg, reg, chunk))
0N/A return reg;
0N/A } else if( chunk == 0 ) {
0N/A // Choose a color which is legal for him
0N/A RegMask tempmask = lrg.mask();
0N/A tempmask.AND(lrgs(copy_lrg).mask());
3845N/A tempmask.clear_to_sets(lrg.num_regs());
3845N/A OptoReg::Name reg = tempmask.find_first_set(lrg.num_regs());
3845N/A if (OptoReg::is_valid(reg))
0N/A return reg;
0N/A }
0N/A }
0N/A
0N/A // If no bias info exists, just go with the register selection ordering
3845N/A if (lrg._is_vector || lrg.num_regs() == 2) {
3845N/A // Find an aligned set
3845N/A return OptoReg::add(lrg.mask().find_first_set(lrg.num_regs()),chunk);
0N/A }
0N/A
0N/A // CNC - Fun hack. Alternate 1st and 2nd selection. Enables post-allocate
0N/A // copy removal to remove many more copies, by preventing a just-assigned
0N/A // register from being repeatedly assigned.
0N/A OptoReg::Name reg = lrg.mask().find_first_elem();
0N/A if( (++_alternate & 1) && OptoReg::is_valid(reg) ) {
0N/A // This 'Remove; find; Insert' idiom is an expensive way to find the
0N/A // SECOND element in the mask.
0N/A lrg.Remove(reg);
0N/A OptoReg::Name reg2 = lrg.mask().find_first_elem();
0N/A lrg.Insert(reg);
0N/A if( OptoReg::is_reg(reg2))
0N/A reg = reg2;
0N/A }
0N/A return OptoReg::add( reg, chunk );
0N/A}
0N/A
0N/A//------------------------------choose_color-----------------------------------
0N/A// Choose a color in the current chunk
0N/AOptoReg::Name PhaseChaitin::choose_color( LRG &lrg, int chunk ) {
0N/A assert( C->in_preserve_stack_slots() == 0 || chunk != 0 || lrg._is_bound || lrg.mask().is_bound1() || !lrg.mask().Member(OptoReg::Name(_matcher._old_SP-1)), "must not allocate stack0 (inside preserve area)");
0N/A assert(C->out_preserve_stack_slots() == 0 || chunk != 0 || lrg._is_bound || lrg.mask().is_bound1() || !lrg.mask().Member(OptoReg::Name(_matcher._old_SP+0)), "must not allocate stack0 (inside preserve area)");
0N/A
0N/A if( lrg.num_regs() == 1 || // Common Case
0N/A !lrg._fat_proj ) // Aligned+adjacent pairs ok
0N/A // Use a heuristic to "bias" the color choice
0N/A return bias_color(lrg, chunk);
0N/A
3845N/A assert(!lrg._is_vector, "should be not vector here" );
0N/A assert( lrg.num_regs() >= 2, "dead live ranges do not color" );
0N/A
0N/A // Fat-proj case or misaligned double argument.
0N/A assert(lrg.compute_mask_size() == lrg.num_regs() ||
0N/A lrg.num_regs() == 2,"fat projs exactly color" );
0N/A assert( !chunk, "always color in 1st chunk" );
0N/A // Return the highest element in the set.
0N/A return lrg.mask().find_last_elem();
0N/A}
0N/A
0N/A//------------------------------Select-----------------------------------------
0N/A// Select colors by re-inserting LRGs back into the IFG. LRGs are re-inserted
0N/A// in reverse order of removal. As long as nothing of hi-degree was yanked,
0N/A// everything going back is guaranteed a color. Select that color. If some
0N/A// hi-degree LRG cannot get a color then we record that we must spill.
0N/Auint PhaseChaitin::Select( ) {
0N/A uint spill_reg = LRG::SPILL_REG;
0N/A _max_reg = OptoReg::Name(0); // Past max register used
0N/A while( _simplified ) {
0N/A // Pull next LRG from the simplified list - in reverse order of removal
0N/A uint lidx = _simplified;
0N/A LRG *lrg = &lrgs(lidx);
0N/A _simplified = lrg->_next;
0N/A
0N/A
0N/A#ifndef PRODUCT
0N/A if (trace_spilling()) {
0N/A ttyLocker ttyl;
0N/A tty->print_cr("L%d selecting degree %d degrees_of_freedom %d", lidx, lrg->degree(),
0N/A lrg->degrees_of_freedom());
0N/A lrg->dump();
0N/A }
0N/A#endif
0N/A
0N/A // Re-insert into the IFG
0N/A _ifg->re_insert(lidx);
0N/A if( !lrg->alive() ) continue;
0N/A // capture allstackedness flag before mask is hacked
0N/A const int is_allstack = lrg->mask().is_AllStack();
0N/A
0N/A // Yeah, yeah, yeah, I know, I know. I can refactor this
0N/A // to avoid the GOTO, although the refactored code will not
0N/A // be much clearer. We arrive here IFF we have a stack-based
0N/A // live range that cannot color in the current chunk, and it
0N/A // has to move into the next free stack chunk.
0N/A int chunk = 0; // Current chunk is first chunk
0N/A retry_next_chunk:
0N/A
0N/A // Remove neighbor colors
0N/A IndexSet *s = _ifg->neighbors(lidx);
0N/A
0N/A debug_only(RegMask orig_mask = lrg->mask();)
0N/A IndexSetIterator elements(s);
0N/A uint neighbor;
0N/A while ((neighbor = elements.next()) != 0) {
0N/A // Note that neighbor might be a spill_reg. In this case, exclusion
0N/A // of its color will be a no-op, since the spill_reg chunk is in outer
0N/A // space. Also, if neighbor is in a different chunk, this exclusion
0N/A // will be a no-op. (Later on, if lrg runs out of possible colors in
0N/A // its chunk, a new chunk of color may be tried, in which case
0N/A // examination of neighbors is started again, at retry_next_chunk.)
0N/A LRG &nlrg = lrgs(neighbor);
0N/A OptoReg::Name nreg = nlrg.reg();
0N/A // Only subtract masks in the same chunk
0N/A if( nreg >= chunk && nreg < chunk + RegMask::CHUNK_SIZE ) {
0N/A#ifndef PRODUCT
0N/A uint size = lrg->mask().Size();
0N/A RegMask rm = lrg->mask();
0N/A#endif
0N/A lrg->SUBTRACT(nlrg.mask());
0N/A#ifndef PRODUCT
0N/A if (trace_spilling() && lrg->mask().Size() != size) {
0N/A ttyLocker ttyl;
0N/A tty->print("L%d ", lidx);
0N/A rm.dump();
0N/A tty->print(" intersected L%d ", neighbor);
0N/A nlrg.mask().dump();
0N/A tty->print(" removed ");
0N/A rm.SUBTRACT(lrg->mask());
0N/A rm.dump();
0N/A tty->print(" leaving ");
0N/A lrg->mask().dump();
0N/A tty->cr();
0N/A }
0N/A#endif
0N/A }
0N/A }
0N/A //assert(is_allstack == lrg->mask().is_AllStack(), "nbrs must not change AllStackedness");
0N/A // Aligned pairs need aligned masks
3845N/A assert(!lrg->_is_vector || !lrg->_fat_proj, "sanity");
3845N/A if (lrg->num_regs() > 1 && !lrg->_fat_proj) {
3845N/A lrg->clear_to_sets();
3845N/A }
0N/A
0N/A // Check if a color is available and if so pick the color
0N/A OptoReg::Name reg = choose_color( *lrg, chunk );
0N/A#ifdef SPARC
0N/A debug_only(lrg->compute_set_mask_size());
3845N/A assert(lrg->num_regs() < 2 || lrg->is_bound() || is_even(reg-1), "allocate all doubles aligned");
0N/A#endif
0N/A
0N/A //---------------
0N/A // If we fail to color and the AllStack flag is set, trigger
0N/A // a chunk-rollover event
0N/A if(!OptoReg::is_valid(OptoReg::add(reg,-chunk)) && is_allstack) {
0N/A // Bump register mask up to next stack chunk
0N/A chunk += RegMask::CHUNK_SIZE;
0N/A lrg->Set_All();
0N/A
0N/A goto retry_next_chunk;
0N/A }
0N/A
0N/A //---------------
0N/A // Did we get a color?
0N/A else if( OptoReg::is_valid(reg)) {
0N/A#ifndef PRODUCT
0N/A RegMask avail_rm = lrg->mask();
0N/A#endif
0N/A
0N/A // Record selected register
0N/A lrg->set_reg(reg);
0N/A
0N/A if( reg >= _max_reg ) // Compute max register limit
0N/A _max_reg = OptoReg::add(reg,1);
0N/A // Fold reg back into normal space
0N/A reg = OptoReg::add(reg,-chunk);
0N/A
0N/A // If the live range is not bound, then we actually had some choices
0N/A // to make. In this case, the mask has more bits in it than the colors
605N/A // chosen. Restrict the mask to just what was picked.
3845N/A int n_regs = lrg->num_regs();
3845N/A assert(!lrg->_is_vector || !lrg->_fat_proj, "sanity");
3845N/A if (n_regs == 1 || !lrg->_fat_proj) {
3845N/A assert(!lrg->_is_vector || n_regs <= RegMask::SlotsPerVecY, "sanity");
0N/A lrg->Clear(); // Clear the mask
0N/A lrg->Insert(reg); // Set regmask to match selected reg
3845N/A // For vectors and pairs, also insert the low bit of the pair
3845N/A for (int i = 1; i < n_regs; i++)
3845N/A lrg->Insert(OptoReg::add(reg,-i));
3845N/A lrg->set_mask_size(n_regs);
0N/A } else { // Else fatproj
0N/A // mask must be equal to fatproj bits, by definition
0N/A }
0N/A#ifndef PRODUCT
0N/A if (trace_spilling()) {
0N/A ttyLocker ttyl;
0N/A tty->print("L%d selected ", lidx);
0N/A lrg->mask().dump();
0N/A tty->print(" from ");
0N/A avail_rm.dump();
0N/A tty->cr();
0N/A }
0N/A#endif
0N/A // Note that reg is the highest-numbered register in the newly-bound mask.
0N/A } // end color available case
0N/A
0N/A //---------------
0N/A // Live range is live and no colors available
0N/A else {
0N/A assert( lrg->alive(), "" );
295N/A assert( !lrg->_fat_proj || lrg->is_multidef() ||
0N/A lrg->_def->outcnt() > 0, "fat_proj cannot spill");
0N/A assert( !orig_mask.is_AllStack(), "All Stack does not spill" );
0N/A
0N/A // Assign the special spillreg register
0N/A lrg->set_reg(OptoReg::Name(spill_reg++));
0N/A // Do not empty the regmask; leave mask_size lying around
0N/A // for use during Spilling
0N/A#ifndef PRODUCT
0N/A if( trace_spilling() ) {
0N/A ttyLocker ttyl;
0N/A tty->print("L%d spilling with neighbors: ", lidx);
0N/A s->dump();
0N/A debug_only(tty->print(" original mask: "));
0N/A debug_only(orig_mask.dump());
0N/A dump_lrg(lidx);
0N/A }
0N/A#endif
0N/A } // end spill case
0N/A
0N/A }
0N/A
0N/A return spill_reg-LRG::SPILL_REG; // Return number of spills
0N/A}
0N/A
0N/A
0N/A//------------------------------copy_was_spilled-------------------------------
0N/A// Copy 'was_spilled'-edness from the source Node to the dst Node.
0N/Avoid PhaseChaitin::copy_was_spilled( Node *src, Node *dst ) {
0N/A if( _spilled_once.test(src->_idx) ) {
0N/A _spilled_once.set(dst->_idx);
0N/A lrgs(Find(dst))._was_spilled1 = 1;
0N/A if( _spilled_twice.test(src->_idx) ) {
0N/A _spilled_twice.set(dst->_idx);
0N/A lrgs(Find(dst))._was_spilled2 = 1;
0N/A }
0N/A }
0N/A}
0N/A
0N/A//------------------------------set_was_spilled--------------------------------
0N/A// Set the 'spilled_once' or 'spilled_twice' flag on a node.
0N/Avoid PhaseChaitin::set_was_spilled( Node *n ) {
0N/A if( _spilled_once.test_set(n->_idx) )
0N/A _spilled_twice.set(n->_idx);
0N/A}
0N/A
0N/A//------------------------------fixup_spills-----------------------------------
0N/A// Convert Ideal spill instructions into proper FramePtr + offset Loads and
0N/A// Stores. Use-def chains are NOT preserved, but Node->LRG->reg maps are.
0N/Avoid PhaseChaitin::fixup_spills() {
0N/A // This function does only cisc spill work.
0N/A if( !UseCISCSpill ) return;
0N/A
0N/A NOT_PRODUCT( Compile::TracePhase t3("fixupSpills", &_t_fixupSpills, TimeCompiler); )
0N/A
0N/A // Grab the Frame Pointer
0N/A Node *fp = _cfg._broot->head()->in(1)->in(TypeFunc::FramePtr);
0N/A
0N/A // For all blocks
0N/A for( uint i = 0; i < _cfg._num_blocks; i++ ) {
0N/A Block *b = _cfg._blocks[i];
0N/A
0N/A // For all instructions in block
0N/A uint last_inst = b->end_idx();
0N/A for( uint j = 1; j <= last_inst; j++ ) {
0N/A Node *n = b->_nodes[j];
0N/A
0N/A // Dead instruction???
0N/A assert( n->outcnt() != 0 ||// Nothing dead after post alloc
0N/A C->top() == n || // Or the random TOP node
0N/A n->is_Proj(), // Or a fat-proj kill node
0N/A "No dead instructions after post-alloc" );
0N/A
0N/A int inp = n->cisc_operand();
0N/A if( inp != AdlcVMDeps::Not_cisc_spillable ) {
0N/A // Convert operand number to edge index number
0N/A MachNode *mach = n->as_Mach();
0N/A inp = mach->operand_index(inp);
0N/A Node *src = n->in(inp); // Value to load or store
0N/A LRG &lrg_cisc = lrgs( Find_const(src) );
0N/A OptoReg::Name src_reg = lrg_cisc.reg();
0N/A // Doubles record the HIGH register of an adjacent pair.
0N/A src_reg = OptoReg::add(src_reg,1-lrg_cisc.num_regs());
0N/A if( OptoReg::is_stack(src_reg) ) { // If input is on stack
0N/A // This is a CISC Spill, get stack offset and construct new node
0N/A#ifndef PRODUCT
0N/A if( TraceCISCSpill ) {
0N/A tty->print(" reg-instr: ");
0N/A n->dump();
0N/A }
0N/A#endif
0N/A int stk_offset = reg2offset(src_reg);
0N/A // Bailout if we might exceed node limit when spilling this instruction
0N/A C->check_node_count(0, "out of nodes fixing spills");
0N/A if (C->failing()) return;
0N/A // Transform node
0N/A MachNode *cisc = mach->cisc_version(stk_offset, C)->as_Mach();
0N/A cisc->set_req(inp,fp); // Base register is frame pointer
0N/A if( cisc->oper_input_base() > 1 && mach->oper_input_base() <= 1 ) {
0N/A assert( cisc->oper_input_base() == 2, "Only adding one edge");
0N/A cisc->ins_req(1,src); // Requires a memory edge
0N/A }
0N/A b->_nodes.map(j,cisc); // Insert into basic block
4123N/A n->subsume_by(cisc, C); // Correct graph
0N/A //
0N/A ++_used_cisc_instructions;
0N/A#ifndef PRODUCT
0N/A if( TraceCISCSpill ) {
0N/A tty->print(" cisc-instr: ");
0N/A cisc->dump();
0N/A }
0N/A#endif
0N/A } else {
0N/A#ifndef PRODUCT
0N/A if( TraceCISCSpill ) {
0N/A tty->print(" using reg-instr: ");
0N/A n->dump();
0N/A }
0N/A#endif
0N/A ++_unused_cisc_instructions; // input can be on stack
0N/A }
0N/A }
0N/A
0N/A } // End of for all instructions
0N/A
0N/A } // End of for all blocks
0N/A}
0N/A
0N/A//------------------------------find_base_for_derived--------------------------
0N/A// Helper to stretch above; recursively discover the base Node for a
0N/A// given derived Node. Easy for AddP-related machine nodes, but needs
0N/A// to be recursive for derived Phis.
0N/ANode *PhaseChaitin::find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg ) {
0N/A // See if already computed; if so return it
0N/A if( derived_base_map[derived->_idx] )
0N/A return derived_base_map[derived->_idx];
0N/A
0N/A // See if this happens to be a base.
0N/A // NOTE: we use TypePtr instead of TypeOopPtr because we can have
0N/A // pointers derived from NULL! These are always along paths that
0N/A // can't happen at run-time but the optimizer cannot deduce it so
0N/A // we have to handle it gracefully.
729N/A assert(!derived->bottom_type()->isa_narrowoop() ||
729N/A derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
0N/A const TypePtr *tj = derived->bottom_type()->isa_ptr();
0N/A // If its an OOP with a non-zero offset, then it is derived.
729N/A if( tj == NULL || tj->_offset == 0 ) {
0N/A derived_base_map[derived->_idx] = derived;
0N/A return derived;
0N/A }
0N/A // Derived is NULL+offset? Base is NULL!
0N/A if( derived->is_Con() ) {
729N/A Node *base = _matcher.mach_null();
729N/A assert(base != NULL, "sanity");
729N/A if (base->in(0) == NULL) {
729N/A // Initialize it once and make it shared:
729N/A // set control to _root and place it into Start block
729N/A // (where top() node is placed).
729N/A base->init_req(0, _cfg._root);
729N/A Block *startb = _cfg._bbs[C->top()->_idx];
729N/A startb->_nodes.insert(startb->find_node(C->top()), base );
729N/A _cfg._bbs.map( base->_idx, startb );
729N/A assert (n2lidx(base) == 0, "should not have LRG yet");
729N/A }
729N/A if (n2lidx(base) == 0) {
729N/A new_lrg(base, maxlrg++);
729N/A }
729N/A assert(base->in(0) == _cfg._root &&
729N/A _cfg._bbs[base->_idx] == _cfg._bbs[C->top()->_idx], "base NULL should be shared");
0N/A derived_base_map[derived->_idx] = base;
0N/A return base;
0N/A }
0N/A
0N/A // Check for AddP-related opcodes
0N/A if( !derived->is_Phi() ) {
3934N/A assert(derived->as_Mach()->ideal_Opcode() == Op_AddP, err_msg_res("but is: %s", derived->Name()));
0N/A Node *base = derived->in(AddPNode::Base);
0N/A derived_base_map[derived->_idx] = base;
0N/A return base;
0N/A }
0N/A
0N/A // Recursively find bases for Phis.
0N/A // First check to see if we can avoid a base Phi here.
0N/A Node *base = find_base_for_derived( derived_base_map, derived->in(1),maxlrg);
0N/A uint i;
0N/A for( i = 2; i < derived->req(); i++ )
0N/A if( base != find_base_for_derived( derived_base_map,derived->in(i),maxlrg))
0N/A break;
0N/A // Went to the end without finding any different bases?
0N/A if( i == derived->req() ) { // No need for a base Phi here
0N/A derived_base_map[derived->_idx] = base;
0N/A return base;
0N/A }
0N/A
0N/A // Now we see we need a base-Phi here to merge the bases
729N/A const Type *t = base->bottom_type();
4022N/A base = new (C) PhiNode( derived->in(0), t );
729N/A for( i = 1; i < derived->req(); i++ ) {
0N/A base->init_req(i, find_base_for_derived(derived_base_map, derived->in(i), maxlrg));
729N/A t = t->meet(base->in(i)->bottom_type());
729N/A }
729N/A base->as_Phi()->set_type(t);
0N/A
0N/A // Search the current block for an existing base-Phi
0N/A Block *b = _cfg._bbs[derived->_idx];
0N/A for( i = 1; i <= b->end_idx(); i++ ) {// Search for matching Phi
0N/A Node *phi = b->_nodes[i];
0N/A if( !phi->is_Phi() ) { // Found end of Phis with no match?
0N/A b->_nodes.insert( i, base ); // Must insert created Phi here as base
0N/A _cfg._bbs.map( base->_idx, b );
0N/A new_lrg(base,maxlrg++);
0N/A break;
0N/A }
0N/A // See if Phi matches.
0N/A uint j;
0N/A for( j = 1; j < base->req(); j++ )
0N/A if( phi->in(j) != base->in(j) &&
0N/A !(phi->in(j)->is_Con() && base->in(j)->is_Con()) ) // allow different NULLs
0N/A break;
0N/A if( j == base->req() ) { // All inputs match?
0N/A base = phi; // Then use existing 'phi' and drop 'base'
0N/A break;
0N/A }
0N/A }
0N/A
0N/A
0N/A // Cache info for later passes
0N/A derived_base_map[derived->_idx] = base;
0N/A return base;
0N/A}
0N/A
0N/A
0N/A//------------------------------stretch_base_pointer_live_ranges---------------
0N/A// At each Safepoint, insert extra debug edges for each pair of derived value/
0N/A// base pointer that is live across the Safepoint for oopmap building. The
0N/A// edge pairs get added in after sfpt->jvmtail()->oopoff(), but are in the
0N/A// required edge set.
0N/Abool PhaseChaitin::stretch_base_pointer_live_ranges( ResourceArea *a ) {
0N/A int must_recompute_live = false;
0N/A uint maxlrg = _maxlrg;
0N/A Node **derived_base_map = (Node**)a->Amalloc(sizeof(Node*)*C->unique());
0N/A memset( derived_base_map, 0, sizeof(Node*)*C->unique() );
0N/A
0N/A // For all blocks in RPO do...
0N/A for( uint i=0; i<_cfg._num_blocks; i++ ) {
0N/A Block *b = _cfg._blocks[i];
0N/A // Note use of deep-copy constructor. I cannot hammer the original
0N/A // liveout bits, because they are needed by the following coalesce pass.
0N/A IndexSet liveout(_live->live(b));
0N/A
0N/A for( uint j = b->end_idx() + 1; j > 1; j-- ) {
0N/A Node *n = b->_nodes[j-1];
0N/A
0N/A // Pre-split compares of loop-phis. Loop-phis form a cycle we would
0N/A // like to see in the same register. Compare uses the loop-phi and so
0N/A // extends its live range BUT cannot be part of the cycle. If this
0N/A // extended live range overlaps with the update of the loop-phi value
0N/A // we need both alive at the same time -- which requires at least 1
0N/A // copy. But because Intel has only 2-address registers we end up with
0N/A // at least 2 copies, one before the loop-phi update instruction and
0N/A // one after. Instead we split the input to the compare just after the
0N/A // phi.
0N/A if( n->is_Mach() && n->as_Mach()->ideal_Opcode() == Op_CmpI ) {
0N/A Node *phi = n->in(1);
0N/A if( phi->is_Phi() && phi->as_Phi()->region()->is_Loop() ) {
0N/A Block *phi_block = _cfg._bbs[phi->_idx];
0N/A if( _cfg._bbs[phi_block->pred(2)->_idx] == b ) {
0N/A const RegMask *mask = C->matcher()->idealreg2spillmask[Op_RegI];
0N/A Node *spill = new (C) MachSpillCopyNode( phi, *mask, *mask );
0N/A insert_proj( phi_block, 1, spill, maxlrg++ );
0N/A n->set_req(1,spill);
0N/A must_recompute_live = true;
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Get value being defined
0N/A uint lidx = n2lidx(n);
0N/A if( lidx && lidx < _maxlrg /* Ignore the occasional brand-new live range */) {
0N/A // Remove from live-out set
0N/A liveout.remove(lidx);
0N/A
0N/A // Copies do not define a new value and so do not interfere.
0N/A // Remove the copies source from the liveout set before interfering.
0N/A uint idx = n->is_Copy();
0N/A if( idx ) liveout.remove( n2lidx(n->in(idx)) );
0N/A }
0N/A
0N/A // Found a safepoint?
0N/A JVMState *jvms = n->jvms();
0N/A if( jvms ) {
0N/A // Now scan for a live derived pointer
0N/A IndexSetIterator elements(&liveout);
0N/A uint neighbor;
0N/A while ((neighbor = elements.next()) != 0) {
0N/A // Find reaching DEF for base and derived values
0N/A // This works because we are still in SSA during this call.
0N/A Node *derived = lrgs(neighbor)._def;
0N/A const TypePtr *tj = derived->bottom_type()->isa_ptr();
729N/A assert(!derived->bottom_type()->isa_narrowoop() ||
729N/A derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
0N/A // If its an OOP with a non-zero offset, then it is derived.
0N/A if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
0N/A Node *base = find_base_for_derived( derived_base_map, derived, maxlrg );
0N/A assert( base->_idx < _names.Size(), "" );
0N/A // Add reaching DEFs of derived pointer and base pointer as a
0N/A // pair of inputs
0N/A n->add_req( derived );
0N/A n->add_req( base );
0N/A
0N/A // See if the base pointer is already live to this point.
0N/A // Since I'm working on the SSA form, live-ness amounts to
0N/A // reaching def's. So if I find the base's live range then
0N/A // I know the base's def reaches here.
0N/A if( (n2lidx(base) >= _maxlrg ||// (Brand new base (hence not live) or
0N/A !liveout.member( n2lidx(base) ) ) && // not live) AND
0N/A (n2lidx(base) > 0) && // not a constant
0N/A _cfg._bbs[base->_idx] != b ) { // base not def'd in blk)
0N/A // Base pointer is not currently live. Since I stretched
0N/A // the base pointer to here and it crosses basic-block
0N/A // boundaries, the global live info is now incorrect.
0N/A // Recompute live.
0N/A must_recompute_live = true;
0N/A } // End of if base pointer is not live to debug info
0N/A }
0N/A } // End of scan all live data for derived ptrs crossing GC point
0N/A } // End of if found a GC point
0N/A
0N/A // Make all inputs live
0N/A if( !n->is_Phi() ) { // Phi function uses come from prior block
0N/A for( uint k = 1; k < n->req(); k++ ) {
0N/A uint lidx = n2lidx(n->in(k));
0N/A if( lidx < _maxlrg )
0N/A liveout.insert( lidx );
0N/A }
0N/A }
0N/A
0N/A } // End of forall instructions in block
0N/A liveout.clear(); // Free the memory used by liveout.
0N/A
0N/A } // End of forall blocks
0N/A _maxlrg = maxlrg;
0N/A
0N/A // If I created a new live range I need to recompute live
0N/A if( maxlrg != _ifg->_maxlrg )
0N/A must_recompute_live = true;
0N/A
0N/A return must_recompute_live != 0;
0N/A}
0N/A
0N/A
0N/A//------------------------------add_reference----------------------------------
0N/A// Extend the node to LRG mapping
0N/Avoid PhaseChaitin::add_reference( const Node *node, const Node *old_node ) {
0N/A _names.extend( node->_idx, n2lidx(old_node) );
0N/A}
0N/A
0N/A//------------------------------dump-------------------------------------------
0N/A#ifndef PRODUCT
0N/Avoid PhaseChaitin::dump( const Node *n ) const {
0N/A uint r = (n->_idx < _names.Size() ) ? Find_const(n) : 0;
0N/A tty->print("L%d",r);
0N/A if( r && n->Opcode() != Op_Phi ) {
0N/A if( _node_regs ) { // Got a post-allocation copy of allocation?
0N/A tty->print("[");
0N/A OptoReg::Name second = get_reg_second(n);
0N/A if( OptoReg::is_valid(second) ) {
0N/A if( OptoReg::is_reg(second) )
0N/A tty->print("%s:",Matcher::regName[second]);
0N/A else
0N/A tty->print("%s+%d:",OptoReg::regname(OptoReg::c_frame_pointer), reg2offset_unchecked(second));
0N/A }
0N/A OptoReg::Name first = get_reg_first(n);
0N/A if( OptoReg::is_reg(first) )
0N/A tty->print("%s]",Matcher::regName[first]);
0N/A else
0N/A tty->print("%s+%d]",OptoReg::regname(OptoReg::c_frame_pointer), reg2offset_unchecked(first));
0N/A } else
0N/A n->out_RegMask().dump();
0N/A }
0N/A tty->print("/N%d\t",n->_idx);
0N/A tty->print("%s === ", n->Name());
0N/A uint k;
0N/A for( k = 0; k < n->req(); k++) {
0N/A Node *m = n->in(k);
0N/A if( !m ) tty->print("_ ");
0N/A else {
0N/A uint r = (m->_idx < _names.Size() ) ? Find_const(m) : 0;
0N/A tty->print("L%d",r);
0N/A // Data MultiNode's can have projections with no real registers.
0N/A // Don't die while dumping them.
0N/A int op = n->Opcode();
0N/A if( r && op != Op_Phi && op != Op_Proj && op != Op_SCMemProj) {
0N/A if( _node_regs ) {
0N/A tty->print("[");
0N/A OptoReg::Name second = get_reg_second(n->in(k));
0N/A if( OptoReg::is_valid(second) ) {
0N/A if( OptoReg::is_reg(second) )
0N/A tty->print("%s:",Matcher::regName[second]);
0N/A else
0N/A tty->print("%s+%d:",OptoReg::regname(OptoReg::c_frame_pointer),
0N/A reg2offset_unchecked(second));
0N/A }
0N/A OptoReg::Name first = get_reg_first(n->in(k));
0N/A if( OptoReg::is_reg(first) )
0N/A tty->print("%s]",Matcher::regName[first]);
0N/A else
0N/A tty->print("%s+%d]",OptoReg::regname(OptoReg::c_frame_pointer),
0N/A reg2offset_unchecked(first));
0N/A } else
0N/A n->in_RegMask(k).dump();
0N/A }
0N/A tty->print("/N%d ",m->_idx);
0N/A }
0N/A }
0N/A if( k < n->len() && n->in(k) ) tty->print("| ");
0N/A for( ; k < n->len(); k++ ) {
0N/A Node *m = n->in(k);
0N/A if( !m ) break;
0N/A uint r = (m->_idx < _names.Size() ) ? Find_const(m) : 0;
0N/A tty->print("L%d",r);
0N/A tty->print("/N%d ",m->_idx);
0N/A }
0N/A if( n->is_Mach() ) n->as_Mach()->dump_spec(tty);
0N/A else n->dump_spec(tty);
0N/A if( _spilled_once.test(n->_idx ) ) {
0N/A tty->print(" Spill_1");
0N/A if( _spilled_twice.test(n->_idx ) )
0N/A tty->print(" Spill_2");
0N/A }
0N/A tty->print("\n");
0N/A}
0N/A
0N/Avoid PhaseChaitin::dump( const Block * b ) const {
0N/A b->dump_head( &_cfg._bbs );
0N/A
0N/A // For all instructions
0N/A for( uint j = 0; j < b->_nodes.size(); j++ )
0N/A dump(b->_nodes[j]);
0N/A // Print live-out info at end of block
0N/A if( _live ) {
0N/A tty->print("Liveout: ");
0N/A IndexSet *live = _live->live(b);
0N/A IndexSetIterator elements(live);
0N/A tty->print("{");
0N/A uint i;
0N/A while ((i = elements.next()) != 0) {
0N/A tty->print("L%d ", Find_const(i));
0N/A }
0N/A tty->print_cr("}");
0N/A }
0N/A tty->print("\n");
0N/A}
0N/A
0N/Avoid PhaseChaitin::dump() const {
0N/A tty->print( "--- Chaitin -- argsize: %d framesize: %d ---\n",
0N/A _matcher._new_SP, _framesize );
0N/A
0N/A // For all blocks
0N/A for( uint i = 0; i < _cfg._num_blocks; i++ )
0N/A dump(_cfg._blocks[i]);
0N/A // End of per-block dump
0N/A tty->print("\n");
0N/A
0N/A if (!_ifg) {
0N/A tty->print("(No IFG.)\n");
0N/A return;
0N/A }
0N/A
0N/A // Dump LRG array
0N/A tty->print("--- Live RanGe Array ---\n");
0N/A for(uint i2 = 1; i2 < _maxlrg; i2++ ) {
0N/A tty->print("L%d: ",i2);
0N/A if( i2 < _ifg->_maxlrg ) lrgs(i2).dump( );
1923N/A else tty->print_cr("new LRG");
0N/A }
0N/A tty->print_cr("");
0N/A
0N/A // Dump lo-degree list
0N/A tty->print("Lo degree: ");
0N/A for(uint i3 = _lo_degree; i3; i3 = lrgs(i3)._next )
0N/A tty->print("L%d ",i3);
0N/A tty->print_cr("");
0N/A
0N/A // Dump lo-stk-degree list
0N/A tty->print("Lo stk degree: ");
0N/A for(uint i4 = _lo_stk_degree; i4; i4 = lrgs(i4)._next )
0N/A tty->print("L%d ",i4);
0N/A tty->print_cr("");
0N/A
0N/A // Dump lo-degree list
0N/A tty->print("Hi degree: ");
0N/A for(uint i5 = _hi_degree; i5; i5 = lrgs(i5)._next )
0N/A tty->print("L%d ",i5);
0N/A tty->print_cr("");
0N/A}
0N/A
0N/A//------------------------------dump_degree_lists------------------------------
0N/Avoid PhaseChaitin::dump_degree_lists() const {
0N/A // Dump lo-degree list
0N/A tty->print("Lo degree: ");
0N/A for( uint i = _lo_degree; i; i = lrgs(i)._next )
0N/A tty->print("L%d ",i);
0N/A tty->print_cr("");
0N/A
0N/A // Dump lo-stk-degree list
0N/A tty->print("Lo stk degree: ");
0N/A for(uint i2 = _lo_stk_degree; i2; i2 = lrgs(i2)._next )
0N/A tty->print("L%d ",i2);
0N/A tty->print_cr("");
0N/A
0N/A // Dump lo-degree list
0N/A tty->print("Hi degree: ");
0N/A for(uint i3 = _hi_degree; i3; i3 = lrgs(i3)._next )
0N/A tty->print("L%d ",i3);
0N/A tty->print_cr("");
0N/A}
0N/A
0N/A//------------------------------dump_simplified--------------------------------
0N/Avoid PhaseChaitin::dump_simplified() const {
0N/A tty->print("Simplified: ");
0N/A for( uint i = _simplified; i; i = lrgs(i)._next )
0N/A tty->print("L%d ",i);
0N/A tty->print_cr("");
0N/A}
0N/A
0N/Astatic char *print_reg( OptoReg::Name reg, const PhaseChaitin *pc, char *buf ) {
0N/A if ((int)reg < 0)
0N/A sprintf(buf, "<OptoReg::%d>", (int)reg);
0N/A else if (OptoReg::is_reg(reg))
0N/A strcpy(buf, Matcher::regName[reg]);
0N/A else
0N/A sprintf(buf,"%s + #%d",OptoReg::regname(OptoReg::c_frame_pointer),
0N/A pc->reg2offset(reg));
0N/A return buf+strlen(buf);
0N/A}
0N/A
0N/A//------------------------------dump_register----------------------------------
0N/A// Dump a register name into a buffer. Be intelligent if we get called
0N/A// before allocation is complete.
0N/Achar *PhaseChaitin::dump_register( const Node *n, char *buf ) const {
0N/A if( !this ) { // Not got anything?
0N/A sprintf(buf,"N%d",n->_idx); // Then use Node index
0N/A } else if( _node_regs ) {
0N/A // Post allocation, use direct mappings, no LRG info available
0N/A print_reg( get_reg_first(n), this, buf );
0N/A } else {
0N/A uint lidx = Find_const(n); // Grab LRG number
0N/A if( !_ifg ) {
0N/A sprintf(buf,"L%d",lidx); // No register binding yet
0N/A } else if( !lidx ) { // Special, not allocated value
0N/A strcpy(buf,"Special");
3845N/A } else {
3845N/A if (lrgs(lidx)._is_vector) {
3845N/A if (lrgs(lidx).mask().is_bound_set(lrgs(lidx).num_regs()))
3845N/A print_reg( lrgs(lidx).reg(), this, buf ); // a bound machine register
3845N/A else
3845N/A sprintf(buf,"L%d",lidx); // No register binding yet
3845N/A } else if( (lrgs(lidx).num_regs() == 1)
3845N/A ? lrgs(lidx).mask().is_bound1()
3845N/A : lrgs(lidx).mask().is_bound_pair() ) {
3845N/A // Hah! We have a bound machine register
3845N/A print_reg( lrgs(lidx).reg(), this, buf );
3845N/A } else {
3845N/A sprintf(buf,"L%d",lidx); // No register binding yet
3845N/A }
0N/A }
0N/A }
0N/A return buf+strlen(buf);
0N/A}
0N/A
0N/A//----------------------dump_for_spill_split_recycle--------------------------
0N/Avoid PhaseChaitin::dump_for_spill_split_recycle() const {
0N/A if( WizardMode && (PrintCompilation || PrintOpto) ) {
0N/A // Display which live ranges need to be split and the allocator's state
0N/A tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
0N/A for( uint bidx = 1; bidx < _maxlrg; bidx++ ) {
0N/A if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
0N/A tty->print("L%d: ", bidx);
0N/A lrgs(bidx).dump();
0N/A }
0N/A }
0N/A tty->cr();
0N/A dump();
0N/A }
0N/A}
0N/A
0N/A//------------------------------dump_frame------------------------------------
0N/Avoid PhaseChaitin::dump_frame() const {
0N/A const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
0N/A const TypeTuple *domain = C->tf()->domain();
0N/A const int argcnt = domain->cnt() - TypeFunc::Parms;
0N/A
0N/A // Incoming arguments in registers dump
0N/A for( int k = 0; k < argcnt; k++ ) {
0N/A OptoReg::Name parmreg = _matcher._parm_regs[k].first();
0N/A if( OptoReg::is_reg(parmreg)) {
0N/A const char *reg_name = OptoReg::regname(parmreg);
0N/A tty->print("#r%3.3d %s", parmreg, reg_name);
0N/A parmreg = _matcher._parm_regs[k].second();
0N/A if( OptoReg::is_reg(parmreg)) {
0N/A tty->print(":%s", OptoReg::regname(parmreg));
0N/A }
0N/A tty->print(" : parm %d: ", k);
0N/A domain->field_at(k + TypeFunc::Parms)->dump();
0N/A tty->print_cr("");
0N/A }
0N/A }
0N/A
0N/A // Check for un-owned padding above incoming args
0N/A OptoReg::Name reg = _matcher._new_SP;
0N/A if( reg > _matcher._in_arg_limit ) {
0N/A reg = OptoReg::add(reg, -1);
0N/A tty->print_cr("#r%3.3d %s+%2d: pad0, owned by CALLER", reg, fp, reg2offset_unchecked(reg));
0N/A }
0N/A
0N/A // Incoming argument area dump
0N/A OptoReg::Name begin_in_arg = OptoReg::add(_matcher._old_SP,C->out_preserve_stack_slots());
0N/A while( reg > begin_in_arg ) {
0N/A reg = OptoReg::add(reg, -1);
0N/A tty->print("#r%3.3d %s+%2d: ",reg,fp,reg2offset_unchecked(reg));
0N/A int j;
0N/A for( j = 0; j < argcnt; j++) {
0N/A if( _matcher._parm_regs[j].first() == reg ||
0N/A _matcher._parm_regs[j].second() == reg ) {
0N/A tty->print("parm %d: ",j);
0N/A domain->field_at(j + TypeFunc::Parms)->dump();
0N/A tty->print_cr("");
0N/A break;
0N/A }
0N/A }
0N/A if( j >= argcnt )
0N/A tty->print_cr("HOLE, owned by SELF");
0N/A }
0N/A
0N/A // Old outgoing preserve area
0N/A while( reg > _matcher._old_SP ) {
0N/A reg = OptoReg::add(reg, -1);
0N/A tty->print_cr("#r%3.3d %s+%2d: old out preserve",reg,fp,reg2offset_unchecked(reg));
0N/A }
0N/A
0N/A // Old SP
0N/A tty->print_cr("# -- Old %s -- Framesize: %d --",fp,
0N/A reg2offset_unchecked(OptoReg::add(_matcher._old_SP,-1)) - reg2offset_unchecked(_matcher._new_SP)+jintSize);
0N/A
0N/A // Preserve area dump
3239N/A int fixed_slots = C->fixed_slots();
3239N/A OptoReg::Name begin_in_preserve = OptoReg::add(_matcher._old_SP, -(int)C->in_preserve_stack_slots());
3239N/A OptoReg::Name return_addr = _matcher.return_addr();
3239N/A
0N/A reg = OptoReg::add(reg, -1);
3239N/A while (OptoReg::is_stack(reg)) {
0N/A tty->print("#r%3.3d %s+%2d: ",reg,fp,reg2offset_unchecked(reg));
3239N/A if (return_addr == reg) {
0N/A tty->print_cr("return address");
3239N/A } else if (reg >= begin_in_preserve) {
3239N/A // Preserved slots are present on x86
3239N/A if (return_addr == OptoReg::add(reg, VMRegImpl::slots_per_word))
3239N/A tty->print_cr("saved fp register");
3239N/A else if (return_addr == OptoReg::add(reg, 2*VMRegImpl::slots_per_word) &&
3239N/A VerifyStackAtCalls)
3239N/A tty->print_cr("0xBADB100D +VerifyStackAtCalls");
3239N/A else
3239N/A tty->print_cr("in_preserve");
3239N/A } else if ((int)OptoReg::reg2stack(reg) < fixed_slots) {
0N/A tty->print_cr("Fixed slot %d", OptoReg::reg2stack(reg));
3239N/A } else {
3239N/A tty->print_cr("pad2, stack alignment");
3239N/A }
0N/A reg = OptoReg::add(reg, -1);
0N/A }
0N/A
0N/A // Spill area dump
0N/A reg = OptoReg::add(_matcher._new_SP, _framesize );
0N/A while( reg > _matcher._out_arg_limit ) {
0N/A reg = OptoReg::add(reg, -1);
0N/A tty->print_cr("#r%3.3d %s+%2d: spill",reg,fp,reg2offset_unchecked(reg));
0N/A }
0N/A
0N/A // Outgoing argument area dump
0N/A while( reg > OptoReg::add(_matcher._new_SP, C->out_preserve_stack_slots()) ) {
0N/A reg = OptoReg::add(reg, -1);
0N/A tty->print_cr("#r%3.3d %s+%2d: outgoing argument",reg,fp,reg2offset_unchecked(reg));
0N/A }
0N/A
0N/A // Outgoing new preserve area
0N/A while( reg > _matcher._new_SP ) {
0N/A reg = OptoReg::add(reg, -1);
0N/A tty->print_cr("#r%3.3d %s+%2d: new out preserve",reg,fp,reg2offset_unchecked(reg));
0N/A }
0N/A tty->print_cr("#");
0N/A}
0N/A
0N/A//------------------------------dump_bb----------------------------------------
0N/Avoid PhaseChaitin::dump_bb( uint pre_order ) const {
0N/A tty->print_cr("---dump of B%d---",pre_order);
0N/A for( uint i = 0; i < _cfg._num_blocks; i++ ) {
0N/A Block *b = _cfg._blocks[i];
0N/A if( b->_pre_order == pre_order )
0N/A dump(b);
0N/A }
0N/A}
0N/A
0N/A//------------------------------dump_lrg---------------------------------------
1923N/Avoid PhaseChaitin::dump_lrg( uint lidx, bool defs_only ) const {
0N/A tty->print_cr("---dump of L%d---",lidx);
0N/A
0N/A if( _ifg ) {
0N/A if( lidx >= _maxlrg ) {
0N/A tty->print("Attempt to print live range index beyond max live range.\n");
0N/A return;
0N/A }
0N/A tty->print("L%d: ",lidx);
1923N/A if( lidx < _ifg->_maxlrg ) lrgs(lidx).dump( );
1923N/A else tty->print_cr("new LRG");
0N/A }
1923N/A if( _ifg && lidx < _ifg->_maxlrg) {
1923N/A tty->print("Neighbors: %d - ", _ifg->neighbor_cnt(lidx));
0N/A _ifg->neighbors(lidx)->dump();
0N/A tty->cr();
0N/A }
0N/A // For all blocks
0N/A for( uint i = 0; i < _cfg._num_blocks; i++ ) {
0N/A Block *b = _cfg._blocks[i];
0N/A int dump_once = 0;
0N/A
0N/A // For all instructions
0N/A for( uint j = 0; j < b->_nodes.size(); j++ ) {
0N/A Node *n = b->_nodes[j];
0N/A if( Find_const(n) == lidx ) {
0N/A if( !dump_once++ ) {
0N/A tty->cr();
0N/A b->dump_head( &_cfg._bbs );
0N/A }
0N/A dump(n);
0N/A continue;
0N/A }
1923N/A if (!defs_only) {
1923N/A uint cnt = n->req();
1923N/A for( uint k = 1; k < cnt; k++ ) {
1923N/A Node *m = n->in(k);
1923N/A if (!m) continue; // be robust in the dumper
1923N/A if( Find_const(m) == lidx ) {
1923N/A if( !dump_once++ ) {
1923N/A tty->cr();
1923N/A b->dump_head( &_cfg._bbs );
1923N/A }
1923N/A dump(n);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A } // End of per-block dump
0N/A tty->cr();
0N/A}
0N/A#endif // not PRODUCT
0N/A
0N/A//------------------------------print_chaitin_statistics-------------------------------
0N/Aint PhaseChaitin::_final_loads = 0;
0N/Aint PhaseChaitin::_final_stores = 0;
0N/Aint PhaseChaitin::_final_memoves= 0;
0N/Aint PhaseChaitin::_final_copies = 0;
0N/Adouble PhaseChaitin::_final_load_cost = 0;
0N/Adouble PhaseChaitin::_final_store_cost = 0;
0N/Adouble PhaseChaitin::_final_memove_cost= 0;
0N/Adouble PhaseChaitin::_final_copy_cost = 0;
0N/Aint PhaseChaitin::_conserv_coalesce = 0;
0N/Aint PhaseChaitin::_conserv_coalesce_pair = 0;
0N/Aint PhaseChaitin::_conserv_coalesce_trie = 0;
0N/Aint PhaseChaitin::_conserv_coalesce_quad = 0;
0N/Aint PhaseChaitin::_post_alloc = 0;
0N/Aint PhaseChaitin::_lost_opp_pp_coalesce = 0;
0N/Aint PhaseChaitin::_lost_opp_cflow_coalesce = 0;
0N/Aint PhaseChaitin::_used_cisc_instructions = 0;
0N/Aint PhaseChaitin::_unused_cisc_instructions = 0;
0N/Aint PhaseChaitin::_allocator_attempts = 0;
0N/Aint PhaseChaitin::_allocator_successes = 0;
0N/A
0N/A#ifndef PRODUCT
0N/Auint PhaseChaitin::_high_pressure = 0;
0N/Auint PhaseChaitin::_low_pressure = 0;
0N/A
0N/Avoid PhaseChaitin::print_chaitin_statistics() {
0N/A tty->print_cr("Inserted %d spill loads, %d spill stores, %d mem-mem moves and %d copies.", _final_loads, _final_stores, _final_memoves, _final_copies);
0N/A tty->print_cr("Total load cost= %6.0f, store cost = %6.0f, mem-mem cost = %5.2f, copy cost = %5.0f.", _final_load_cost, _final_store_cost, _final_memove_cost, _final_copy_cost);
0N/A tty->print_cr("Adjusted spill cost = %7.0f.",
0N/A _final_load_cost*4.0 + _final_store_cost * 2.0 +
0N/A _final_copy_cost*1.0 + _final_memove_cost*12.0);
0N/A tty->print("Conservatively coalesced %d copies, %d pairs",
0N/A _conserv_coalesce, _conserv_coalesce_pair);
0N/A if( _conserv_coalesce_trie || _conserv_coalesce_quad )
0N/A tty->print(", %d tries, %d quads", _conserv_coalesce_trie, _conserv_coalesce_quad);
0N/A tty->print_cr(", %d post alloc.", _post_alloc);
0N/A if( _lost_opp_pp_coalesce || _lost_opp_cflow_coalesce )
0N/A tty->print_cr("Lost coalesce opportunity, %d private-private, and %d cflow interfered.",
0N/A _lost_opp_pp_coalesce, _lost_opp_cflow_coalesce );
0N/A if( _used_cisc_instructions || _unused_cisc_instructions )
0N/A tty->print_cr("Used cisc instruction %d, remained in register %d",
0N/A _used_cisc_instructions, _unused_cisc_instructions);
0N/A if( _allocator_successes != 0 )
0N/A tty->print_cr("Average allocation trips %f", (float)_allocator_attempts/(float)_allocator_successes);
0N/A tty->print_cr("High Pressure Blocks = %d, Low Pressure Blocks = %d", _high_pressure, _low_pressure);
0N/A}
0N/A#endif // not PRODUCT