postaloc.cpp revision 1472
948N/A * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 * 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 * 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 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A#
include "incls/_precompiled.incl" 0N/A// see if this register kind does not requires two registers 0N/A//---------------------------may_be_copy_of_callee----------------------------- 0N/A// Check to see if we can possibly be a copy of a callee-save value. 0N/A // Short circuit if there are no callee save registers 0N/A // Expect only a spill-down and reload on exit for callee-save spills. 0N/A // Chains of copies cannot be deep. 0N/A // 5008997 - This is wishful thinking. Register allocator seems to 0N/A // be splitting live ranges for callee save registers to such 0N/A // an extent that in large methods the chains can be very long 0N/A // (50+). The conservative answer is to return true if we don't 0N/A // know as this prevents optimizations from occurring. 0N/A return true;
// Direct use of callee-save proj 0N/A else if(
def->
is_Phi() )
// Phis can merge it from any direction 0N/A // If we reached the end and didn't find a callee save proj 0N/A // then this may be a callee save proj so we return true 0N/A // as the conservative answer. If we didn't reach then end 0N/A // we must have discovered that it was not a callee save 0N/A // else we would have returned. 0N/A//------------------------------yank_if_dead----------------------------------- 0N/A// Removed an edge from 'old'. Yank if dead. Return adjustment counts to 0N/A// iterators in the current block. 0N/A // Count 1 if deleting an instruction from the current block 0N/A//------------------------------use_prior_register----------------------------- 0N/A// Use the prior value instead of the current value, in an effort to make 0N/A// the current value go dead. Return block iterator adjustment, in case 0N/A// we yank some instructions from this block. 0N/A // Def is currently dead and can be removed? Do not resurrect 0N/A // Not every pair of physical registers are assignment compatible, 0N/A // e.g. on sparc floating point registers are not assignable to integer 0N/A // Check for a copy to or from a misaligned pair. 0N/A // Capture the old def in case it goes dead... 0N/A // Save-on-call copies can only be elided if the entire copy chain can go 0N/A // away, lest we get the same callee-save value alive in 2 locations at 0N/A // once. We check for the obvious trivial case here. Although it can 0N/A // sometimes be elided with cooperation outside our scope, here we will just 0N/A // miss the opportunity. :-( 0N/A if(
old->
outcnt() >
1 )
return 0;
// We're the not last user 0N/A if( !
idx2 )
return 0;
// Not a chain of 2 copies 0N/A // Is old def now dead? We successfully yanked a copy? 0N/A//------------------------------skip_copies------------------------------------ 0N/A// Skip through any number of copies (that don't mod oop-i-ness) 0N/A break;
// casting copy, not the same value 0N/A//------------------------------elide_copy------------------------------------- 0N/A// Remove (bypass) copies along Node n, edge k. 0N/A // Remove obvious same-register copies 0N/A if( n->
in(k) !=
copy )
break;
// Failed for some cutout? 0N/A // Phis and 2-address instructions cannot change registers so easily - their 0N/A // outputs must match their input. 0N/A // Loop backedges won't have a value-mapping yet 0N/A // Skip through all copies to the _value_ being used. Do not change from 0N/A // int to pointer. This attempts to jump through a chain of copies, where 0N/A // intermediate copies might be illegal, i.e., value is stored down to stack 0N/A // then reloaded BUT survives in a register the whole way. 0N/A // See if it happens to already be in the correct register! 0N/A // (either Phi's direct register, or the common case of the name 0N/A // never-clobbered original-def register) 0N/A // Doubles check both halves 0N/A // See if we can skip the copy by changing registers. Don't change from 0N/A // using a register to using the stack unless we know we can remove a 0N/A // copy-load. Otherwise we might end up making a pile of Intel cisc-spill 0N/A // ops reading from memory instead of just loading once and using the 0N/A // Also handle duplicate copies here. 0N/A // Scan all registers to see if this value is around already 0N/A // Found ourselves so check if there is only one user of this 0N/A // copy and keep on searching for a better copy if so. 0N/A if( !
single ) {
// Doubles check for aligned-adjacent pair 0N/A if( (
reg&
1)==0 )
continue;
// Wrong half of a pair 0N/A }
// End of if not degrading to a stack 0N/A }
// End of if found value in another register 0N/A }
// End of scan all machine registers 0N/A// Check if nreg already contains the constant value val. Normal copy 0N/A// elimination doesn't doesn't work on constants because multiple 0N/A// nodes can represent the same constant so the type and rule of the 0N/A// MachNode must be checked to ensure equivalence. 0N/A // This code assumes that two MachNodes representing constants 0N/A // which have the same rule and the same bottom type will produce 0N/A // identical effects into a register. This seems like it must be 0N/A // objectively true unless there are hidden inputs to the nodes 0N/A // but if that were to change this code would need to updated. 0N/A // Since they are equivalent the second one if redundant and can 0N/A // n will be replaced with the old value but n might have 0N/A // kills projections associated with it so remove them now so that 0N/A // yank_if_dead will be able to eliminate the copy once the uses 0N/A // have been transferred to the old[value]. 0N/A // Kill projections have no users and one input 0N/A//------------------------------post_allocate_copy_removal--------------------- 0N/A// Post-Allocation peephole copy removal. We do this in 1 pass over the 0N/A// basic blocks. We maintain a mapping of registers to Nodes (an array of 0N/A// Nodes indexed by machine register or stack slot number). NULL means that a 0N/A// register is not mapped to any Node. We can (want to have!) have several 1409N/A// registers map to the same Node. We walk forward over the instructions 0N/A// updating the mapping as we go. At merge points we force a NULL if we have 0N/A// to merge 2 different Nodes into the same register. Phi functions will give 0N/A// us a new Node if there is a proper value merging. Since the blocks are 0N/A// arranged in some RPO, we will visit all parent blocks before visiting any 0N/A// successor blocks (except at loops). 0N/A// If we find a Copy we look to see if the Copy's source register is a stack 0N/A// slot and that value has already been loaded into some machine register; if 0N/A// so we use machine register directly. This turns a Load into a reg-reg 0N/A// Move. We also look for reloads of identical constants. 0N/A// When we see a use from a reg-reg Copy, we will attempt to use the copy's 0N/A// source directly and make the copy go dead. 0N/A // Need a mapping from basic block Node_Lists. We need a Node_List to 0N/A // map from register number to value-producing Node. 0N/A // Need a mapping from basic block Node_Lists. We need a Node_List to 0N/A // map from register number to register-defining Node. 0N/A // We keep unused Node_Lists on a free_list to avoid wasting 0N/A // If any predecessor has not been visited, we do not know the state 0N/A // of registers at the start. Check for this, while updating copies 0N/A // along Phi input edges 0N/A // Remove copies along phi edges 0N/A // See if this predecessor's mappings have been used by everybody 0N/A // who wants them. If so, free 'em. 0N/A break;
// Found a future user 0N/A }
else {
// This block has unvisited (loopback) inputs 0N/A // Extract Node_List mappings. If 'freed' is non-zero, we just popped 0N/A // 'freed's blocks off the list 0N/A // Set mappings as OUR mappings 0N/A // Initialize value & regnd for this block 0N/A // Some predecessor has not yet been visited; zap map to empty 0N/A if( !
freed ) {
// Didn't get a freebie prior block 0N/A // Must clone some data 0N/A // Merge all inputs together, setting to NULL any conflicts. 0N/A if(
pb ==
freed )
continue;
// Did self already via freelist 0N/A // Remove copies remaining on edges. Check for junk phi. 0N/A if(
phi != x && u != x )
// Found a different input 0N/A u = u ?
NodeSentinel : x;
// Capture unique input, or NodeSentinel for 2nd input 73N/A // Note that if value[pidx] exists, then we merged no new values here 73N/A // and the phi is useless. This can happen even with the above phi 73N/A // removal for complex flows. I cannot keep the better known value here 73N/A // because locally the phi appears to define a new merged value. If I 73N/A // keep the better value then a copy of the phi, being unable to use the 73N/A // global flow analysis, can't "peek through" the phi to the original 851N/A // reaching value and so will act like it's defining a new value. This 851N/A // can lead to situations where some uses are from the old and some from 113N/A // the new values. Not illegal by itself but throws the over-strong 113N/A // assert in scheduling. 0N/A // For all remaining instructions 0N/A n != C->
top() &&
// (ignore TOP, it has no du info) 0N/A // Improve reaching-def info. Occasionally post-alloc's liveness gives 0N/A // up (at loop backedges, because we aren't doing a full flow pass). 0N/A // The presence of a live use essentially asserts that the use's def is 0N/A // alive and well at the use (or else the allocator fubar'd). Take 0N/A // advantage of this info to set a reaching def for the use-reg. 0N/A for( k =
1; k < n->
req(); k++ ) {
0N/A Node *
def = n->
in(k);
// n->in(k) is a USE; def is the DEF for this USE 0N/A int idx;
// Skip occasional useless copy 0N/A // Record other half of doubles 0N/A // Remove copies along input edges 0N/A for( k =
1; k < n->
req(); k++ )
0N/A // Unallocated Nodes define no registers 0N/A // Update the register defined by this instruction 0N/A // Skip through all copies to the _value_ being defined. 0N/A // Do not change from int to pointer 0N/A // Clear out a dead definition before starting so that the 0N/A // elimination code doesn't have to guard against it. The 0N/A // definition could in fact be a kill projection with a count of 0N/A // 0 which is safe but since those are uninteresting for copy // elimination just delete them as well. // If Node 'n' does not change the value mapped by the register, // then 'n' is a useless copy. Do not update the register->node // mapping so 'n' will go dead. // Update the mapping: record new Node defined by the register // Update mapping for defined *value*, which is the defined // Node after skipping all copies. // If the value occupies a register pair, record same info // Sparc occasionally has non-adjacent pairs. // Find the actual other value // Fat projections kill many registers // wow, what an expensive iterator... }
// End of for all instructions in the block