spiglet.translate.graph
Class RegisterAlloc<T,R>

java.lang.Object
  extended by spiglet.translate.graph.RegisterAlloc<T,R>
Type Parameters:
T - the type of the variables in an interference graph
R - the type of the registers that variables are allocated to
Direct Known Subclasses:
LinearScanAlloc

public abstract class RegisterAlloc<T,R>
extends java.lang.Object

This abstract class specifies the interface to analyze an interference graph and the metadata of the variables contained therein to allocate those variables to a pool of registers.

Author:
Santoso Wijaya
See Also:
InterferenceGraph

Field Summary
protected  java.util.Set<R> registers
          An unmodifiable set of general-purpose registers, for lookup reference.
 
Constructor Summary
RegisterAlloc(java.util.Set<R> pool)
          Construct an allocator with a given pool of general purpose registers.
 
Method Summary
 java.util.Map<T,R> getAllocation(FlowGraph<T> graph)
          Returns the mapping of all variables to their allocated registers, given a control flow graph from which to infer.
abstract  java.util.Map<T,R> getAllocation(FlowGraph<T> graph, java.util.Map<T,R> preAlloc)
          Returns the mapping of all variables to their allocated registers, given a control flow graph from which to infer.
 java.util.Map<T,R> getRegAllocation(FlowGraph<T> graph)
          Returns the mapping of only those variables that are mapped to registers, given a control flow graph from which to infer.
abstract  java.util.Map<T,R> getRegAllocation(FlowGraph<T> graph, java.util.Map<T,R> preAlloc)
          Returns the mapping of only those variables that are mapped to registers, given a control flow graph from which to infer.
abstract  java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

registers

protected java.util.Set<R> registers
An unmodifiable set of general-purpose registers, for lookup reference.

Constructor Detail

RegisterAlloc

public RegisterAlloc(java.util.Set<R> pool)
Construct an allocator with a given pool of general purpose registers.

Parameters:
pool - the set of general registers
Method Detail

getAllocation

public java.util.Map<T,R> getAllocation(FlowGraph<T> graph)
Returns the mapping of all variables to their allocated registers, given a control flow graph from which to infer. If a variable is mapped to null, that means the variable is spilled.

Parameters:
graph - the control flow graph
Returns:
the mapping of variables to their allocated registers (null if spilled)

getAllocation

public abstract java.util.Map<T,R> getAllocation(FlowGraph<T> graph,
                                                 java.util.Map<T,R> preAlloc)
Returns the mapping of all variables to their allocated registers, given a control flow graph from which to infer. If a variable is mapped to null, that means the variable is spilled. A pre-allocation of variables to registers is also given, to indicate to the allocator that such a mapping must remain in the final allocation result. The returned allocation mapping also includes the mapping in preAlloc.

Parameters:
graph - the control flow graph
preAlloc - the pre-allocation mapping
Returns:
the mapping of variables to their allocated registers (null if spilled)

getRegAllocation

public java.util.Map<T,R> getRegAllocation(FlowGraph<T> graph)
Returns the mapping of only those variables that are mapped to registers, given a control flow graph from which to infer. Spilled variables do not appear in the key set of the returned map.

Parameters:
graph - the control flow graph
Returns:
the mapping of variables to their allocated registers; no variable is mapped to null

getRegAllocation

public abstract java.util.Map<T,R> getRegAllocation(FlowGraph<T> graph,
                                                    java.util.Map<T,R> preAlloc)
Returns the mapping of only those variables that are mapped to registers, given a control flow graph from which to infer. Spilled variables do not appear in the key set of the returned map. A pre-allocation of variables to registers is also given, to indicate to the allocator that such a mapping must remain in the final allocation result. The returned allocation mapping also includes the mapping in preAlloc.

Parameters:
graph - the control flow graph
preAlloc - the pre-allocation mapping
Returns:
the mapping of variables to their allocated registers; no variable is mapped to null

toString

public abstract java.lang.String toString()
Overrides:
toString in class java.lang.Object