Class GreedyRegisterAllocator<TRegister>
An analysis that greedily allocates registers to values. The set of values is assumed to be unbounded: the analysis is allowed to "create" an arbitrarily large amount of registers.
Implements
Inherited Members
Namespace: Flame.Compiler.Analysis
Assembly: Flame.Compiler.dll
Syntax
public abstract class GreedyRegisterAllocator<TRegister> : IFlowGraphAnalysis<RegisterAllocation<TRegister>>
Type Parameters
| Name | Description |
|---|---|
| TRegister | The type of register allocated to values. |
Methods
| Edit this page View SourceAnalyze(FlowGraph)
Analyzes a flow graph from scratch.
Declaration
public RegisterAllocation<TRegister> Analyze(FlowGraph graph)
Parameters
| Type | Name | Description |
|---|---|---|
| FlowGraph | graph | The flow graph to analyze. |
Returns
| Type | Description |
|---|---|
| RegisterAllocation<TRegister> | The analysis' output. |
AnalyzeWithUpdates(FlowGraph, RegisterAllocation<TRegister>, IReadOnlyList<FlowGraphUpdate>)
Analyzes a flow graph based on the flow graph, the previous result, and a list of updates that were applied to the graph since the previous result.
Declaration
public RegisterAllocation<TRegister> AnalyzeWithUpdates(FlowGraph graph, RegisterAllocation<TRegister> previousResult, IReadOnlyList<FlowGraphUpdate> updates)
Parameters
| Type | Name | Description |
|---|---|---|
| FlowGraph | graph | The current version of the flow graph to analyze. |
| RegisterAllocation<TRegister> | previousResult | A previous result produced by this analysis. |
| IReadOnlyList<FlowGraphUpdate> | updates | A list of updates that were applied to the flow graph since the previous result was computed. |
Returns
| Type | Description |
|---|---|
| RegisterAllocation<TRegister> | The analysis' output, which must be equal to a call to
|
CreateRegister(IType)
Creates a brand new register for a value of a particular type.
Declaration
protected abstract TRegister CreateRegister(IType type)
Parameters
| Type | Name | Description |
|---|---|---|
| IType | type | The type of value to create a register for. |
Returns
| Type | Description |
|---|---|
| TRegister | A register suitable for the value. |
RequiresRegister(ValueTag, FlowGraph)
Tells if a register should be allocated for a particular value.
Declaration
protected virtual bool RequiresRegister(ValueTag value, FlowGraph graph)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTag | value | The value for which register allocation may or may not be necessary. |
| FlowGraph | graph | The control flow graph that defines |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
Implementations may override this method to suppress register allocation for values that are, e.g., stored on an evaluation stack.
TryGetPreallocatedRegister(ValueTag, FlowGraph, out TRegister)
Tries to get a preallocated register for a particular value. If it exists, then the preallocated register will be used for the value, no questions asked. The preallocated register may be reused.
Declaration
protected virtual bool TryGetPreallocatedRegister(ValueTag value, FlowGraph graph, out TRegister register)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTag | value | The value that may have a preallocated register. |
| FlowGraph | graph | The graph that defines the value. |
| TRegister | register | A preallocated register, if any. |
Returns
| Type | Description |
|---|---|
| bool |
|
TryRecycleRegister(IType, IEnumerable<TRegister>, out TRegister)
Tries to recycle a register from a set of registers.
Declaration
protected abstract bool TryRecycleRegister(IType type, IEnumerable<TRegister> registers, out TRegister result)
Parameters
| Type | Name | Description |
|---|---|---|
| IType | type | The type of value to store in the recycled register. |
| IEnumerable<TRegister> | registers | A set of registers that are eligible for recycling. |
| TRegister | result | A register to recycle, if any. |
Returns
| Type | Description |
|---|---|
| bool |
|