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