harpoon.Backend.MIPS
Class RegFileInfo

java.lang.Object
  extended by harpoon.Backend.Generic.RegFileInfo
      extended by harpoon.Backend.MIPS.RegFileInfo
All Implemented Interfaces:
LocationFactory, Serializable

public class RegFileInfo
extends RegFileInfo
implements LocationFactory

RegFileInfo encapsulates information about the MIPS register set. This object also implements Generic.LocationFactory, allowing the creation of global registers for the use of the runtime.

Version:
$Id: RegFileInfo.java,v 1.5 2004/02/08 01:57:34 cananian Exp $
Author:
Emmett Witchel <witchel@mit.edu>
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class harpoon.Backend.Generic.RegFileInfo
RegFileInfo.CommonLoc, RegFileInfo.MachineRegLoc, RegFileInfo.SpillException, RegFileInfo.StackOffsetLoc, RegFileInfo.TempLocator
 
Nested classes/interfaces inherited from interface harpoon.Backend.Generic.LocationFactory
LocationFactory.Location
 
Constructor Summary
RegFileInfo()
          Creates a RegFileInfo.
 
Method Summary
 LocationFactory.Location allocateLocation(int type)
          Allocate a global register of the specified type and return a handle to it.
 Set calleeSave()
           
 Set callerSave()
           
 Temp[] getAllRegisters()
          Returns an array of Temps which represent all the available registers on the machine.
 Temp[] getGeneralRegisters()
          Returns an array of Temps for all the registers that the register allocator can feel free to play with
 Set getRegAssignments(Temp t)
          Produces a mutable Set of register assignments that can hold t.
 Temp getRegister(int index)
          Returns a specific register on the machine.
 int getSize(Temp temp)
           
 boolean isRegister(Temp t)
          Checks if t is a element of the register file for this architecture.
 Set liveOnExit()
          Returns the Set of registers live at a method's exit.
 HData makeLocationData(Frame f)
          Create an HData which allocates static space for any LocationFactory.Locations that have been created.
 TempFactory regTempFactory()
           
 Iterator suggestRegAssignment(Temp t, Map regFile, Collection preassigned)
          Analyzes regfile to find free registers that t can be assigned to.
 
Methods inherited from class harpoon.Backend.Generic.RegFileInfo
allRegs, assignment, expand, getAllRegistersC, getGeneralRegistersC, illegal, maxRegIndex, occupancy, pressure
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegFileInfo

public RegFileInfo()
Creates a RegFileInfo.

Method Detail

getAllRegisters

public Temp[] getAllRegisters()
Description copied from class: RegFileInfo
Returns an array of Temps which represent all the available registers on the machine.

Specified by:
getAllRegisters in class RegFileInfo

getRegister

public Temp getRegister(int index)
Description copied from class: RegFileInfo
Returns a specific register on the machine.
getRegister(index)==getAllRegisters()[index]

Overrides:
getRegister in class RegFileInfo

getGeneralRegisters

public Temp[] getGeneralRegisters()
Description copied from class: RegFileInfo
Returns an array of Temps for all the registers that the register allocator can feel free to play with

Specified by:
getGeneralRegisters in class RegFileInfo

regTempFactory

public TempFactory regTempFactory()

isRegister

public boolean isRegister(Temp t)
Description copied from class: RegFileInfo
Checks if t is a element of the register file for this architecture.
effects: If t is an element of the register file, Then returns true, Else returns false.

Specified by:
isRegister in class RegFileInfo
Parameters:
t - Temp that may be part of the register file.

getSize

public int getSize(Temp temp)

getRegAssignments

public Set getRegAssignments(Temp t)
Description copied from class: RegFileInfo
Produces a mutable Set of register assignments that can hold t. FSK: experimental method.
requires: t is not a physical register Temp.
effects: Returns a Set of possible register assignments for t, where each assignment is an unmodifiable List of Register Temps. The elements of each List are ordered according to proper placement of the Register-bitlength words of the value in t, low-order words first. Every list returned will have the same length. The Set returned may be a SortedSet, in which case the earlier assignments are favored over later ones.

Overrides:
getRegAssignments in class RegFileInfo

suggestRegAssignment

public Iterator suggestRegAssignment(Temp t,
                                     Map regFile,
                                     Collection preassigned)
                              throws RegFileInfo.SpillException
Description copied from class: RegFileInfo
Analyzes regfile to find free registers that t can be assigned to. (FSK: Need to update this method to incorporate knowledge of Virtual Register Temps (perhaps it is guaranteed not to throw a SpillException when given a Virtual Register Temp))
effects: Either returns an Iterator of possible assignments (though this is not guaranteed to be a complete list of all possible choices, merely the ones that this RegFileInfo chose to find), or throws a RegFileInfo.SpillException with a set of possible spills.

Note to implementors: Resist the urge to generate an Iterator that produces all possible assignments in series. In general, register allocation algorithms need to, at some point, construct an interference graph to represent how the registers should be assigned. Such a graph would contain a node for each register assignment (and put interference edges between assignments that were not allowed for a given Temp), which means that even if your Iterator did not keep all of the assignments in memory at once, code that USES your Iterator may very well do so. Thus, while there may be many assignments for a Temp that occupies more than one register, and it is possible to write an Iterator that produces all such assignments, such an Iterator would cause an time/space explosion when applied to a decently sized register file.
Also, realize that it is not enough to ensure that any one of the set { of possible Iterators that may be returned } traverses a reasonably small subset of the assignment space; you must ensure that the UNION of all possible traversals is of a reasonable size. This is because the interference graph that is constructed will not be built from just one Suggestion Iterator, but rather from an Suggestion Iterator for each variable that is given a register assignment.

Overrides:
suggestRegAssignment in class RegFileInfo
Parameters:
t - Temp that needs to be assigned to a set of Registers.
regFile - A mapping from Register Temps to NonRegister Temps representing the current state of the register file. Empty Register Temps should simply not have an entry in regfile (as opposed to the alternative of mapping to some NoValue object).
Returns:
A List Iterator of Register Temps. The Iterator is guaranteed to have at least one element. Each List represents a safe place for the value in t to be stored (safe with regard to the architecture targeted and the type of t, not with regard to the current contents of regfile or the data-flow of the procedure being analyzed). The elements of each List in the Iterator returned are ordered according to proper placement of the Register-bitlength words of the value in t, low-order words first.
Throws:
RegFileInfo.SpillException - if the register file represented by regfile does not have any Register Temps free to hold a new value of the type of t. This exception will contain the necessary information to spill some set of registers. After spilling, a second call to suggestRegAssignment() can not throw an exception, as long as no new values have been loaded into the register file since the point of spilling.

liveOnExit

public Set liveOnExit()
Description copied from class: RegFileInfo
Returns the Set of registers live at a method's exit.
effects: Returns an unmodifiable Set of register Temps of the registers that should be considered live at the end of a method.

Specified by:
liveOnExit in class RegFileInfo

callerSave

public Set callerSave()

calleeSave

public Set calleeSave()

allocateLocation

public LocationFactory.Location allocateLocation(int type)
Allocate a global register of the specified type and return a handle to it.

Specified by:
allocateLocation in interface LocationFactory
Parameters:
type - a IR.Tree.Type specifying the type of the register.

makeLocationData

public HData makeLocationData(Frame f)
Create an HData which allocates static space for any LocationFactory.Locations that have been created. As this implementation only allocates global registers, the HData returned is always empty.

Specified by:
makeLocationData in interface LocationFactory
Parameters:
f - the Generic.Frame to which the HData will belong.