Class FlowGraph
An immutable control-flow graph that consists of basic blocks.
Inheritance
Inherited Members
Namespace: Flame.Compiler
Assembly: Flame.Compiler.dll
Syntax
public sealed class FlowGraph
Constructors
| Improve this Doc View SourceFlowGraph()
Creates a control-flow graph that contains only an empty entry point block.
Declaration
public FlowGraph()
Properties
| Improve this Doc View SourceBasicBlocks
Gets a sequence of all basic blocks in this control-flow graph.
Declaration
public IEnumerable<BasicBlock> BasicBlocks { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<BasicBlock> | All basic blocks. |
BasicBlockTags
Gets a sequence of all basic block tags in this control-flow graph.
Declaration
public IEnumerable<BasicBlockTag> BasicBlockTags { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<BasicBlockTag> |
EntryPoint
Gets the entry point block.
Declaration
public BasicBlock EntryPoint { get; }
Property Value
Type | Description |
---|---|
BasicBlock | The entry point block. |
EntryPointTag
Gets the tag of the entry point block.
Declaration
public BasicBlockTag EntryPointTag { get; }
Property Value
Type | Description |
---|---|
BasicBlockTag | The tag of the entry point block. |
InstructionTags
Gets a sequence of all instruction tags in this control-flow graph.
Declaration
public IEnumerable<ValueTag> InstructionTags { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ValueTag> |
NamedInstructions
Gets a sequence of all named instructions in this control-flow graph. Anonymous instructions as defined by block flow are not included.
Declaration
public IEnumerable<NamedInstruction> NamedInstructions { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<NamedInstruction> | All named instructions |
ParameterTags
Gets a sequence of all parameter tags in this control-flow graph.
Declaration
public IEnumerable<ValueTag> ParameterTags { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ValueTag> |
ValueTags
Gets a sequence of all value tags in this control-flow graph. This sequence includes both instruction values and basic block parameter values.
Declaration
public IEnumerable<ValueTag> ValueTags { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ValueTag> |
Methods
| Improve this Doc View SourceAddBasicBlock()
Creates a new basic block that includes all basic blocks in this graph plus an empty basic block. The latter basic block is returned.
Declaration
public BasicBlock AddBasicBlock()
Returns
Type | Description |
---|---|
BasicBlock | An empty basic block in a new control-flow graph. |
AddBasicBlock(String)
Creates a new basic block that includes all basic blocks in this graph plus an empty basic block. The latter basic block is returned.
Declaration
public BasicBlock AddBasicBlock(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The (preferred) name of the basic block's tag. |
Returns
Type | Description |
---|---|
BasicBlock | An empty basic block in a new control-flow graph. |
AssertContainsBasicBlock(BasicBlockTag)
Asserts that this control-flow graph must contain a basic block with a particular tag.
Declaration
public void AssertContainsBasicBlock(BasicBlockTag tag)
Parameters
Type | Name | Description |
---|---|---|
BasicBlockTag | tag | The tag of the basic block that must be in the graph. |
AssertContainsBasicBlock(BasicBlockTag, String)
Asserts that this control-flow graph must contain a basic block with a particular tag.
Declaration
public void AssertContainsBasicBlock(BasicBlockTag tag, string message)
Parameters
Type | Name | Description |
---|---|---|
BasicBlockTag | tag | The tag of the basic block that must be in the graph. |
System.String | message | The error message for when no basic block in this control-flow graph has the tag. |
AssertContainsInstruction(ValueTag)
Asserts that this control-flow graph must contain an instruction with a particular tag.
Declaration
public void AssertContainsInstruction(ValueTag tag)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The tag of the instruction that must be in the graph. |
AssertContainsInstruction(ValueTag, String)
Asserts that this control-flow graph must contain an instruction with a particular tag.
Declaration
public void AssertContainsInstruction(ValueTag tag, string message)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The tag of the instruction that must be in the graph. |
System.String | message | The error message for when no instruction in this control-flow graph has the tag. |
AssertContainsValue(ValueTag)
Asserts that this control-flow graph must contain an instruction or basic block parameter with a particular tag.
Declaration
public void AssertContainsValue(ValueTag tag)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The tag of the value that must be in the graph. |
AssertContainsValue(ValueTag, String)
Asserts that this control-flow graph must contain an instruction or basic block parameter with a particular tag.
Declaration
public void AssertContainsValue(ValueTag tag, string message)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The tag of the value that must be in the graph. |
System.String | message | The error message for when no value in this control-flow graph has the tag. |
AssertNotContainsValue(ValueTag)
Asserts that this control-flow graph must not contain an instruction or basic block parameter with a particular tag.
Declaration
public void AssertNotContainsValue(ValueTag tag)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The tag of the value that must not be in the graph. |
AssertNotContainsValue(ValueTag, String)
Asserts that this control-flow graph must not contain an instruction or basic block parameter with a particular tag.
Declaration
public void AssertNotContainsValue(ValueTag tag, string message)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The tag of the value that must not be in the graph. |
System.String | message | The error message for when a value in this control-flow graph has the tag. |
ContainsBasicBlock(BasicBlockTag)
Checks if this control-flow graph contains a basic block with a particular tag.
Declaration
public bool ContainsBasicBlock(BasicBlockTag tag)
Parameters
Type | Name | Description |
---|---|---|
BasicBlockTag | tag | The basic block's tag. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsBlockParameter(ValueTag)
Checks if this control-flow graph contains a basic block parameter with a particular tag.
Declaration
public bool ContainsBlockParameter(ValueTag tag)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The parameter's tag. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsInstruction(ValueTag)
Checks if this control-flow graph contains an instruction with a particular tag.
Declaration
public bool ContainsInstruction(ValueTag tag)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The instruction's tag. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsValue(ValueTag)
Checks if this control-flow graph contains an instruction or basic block parameter with a particular tag.
Declaration
public bool ContainsValue(ValueTag tag)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The value's tag. |
Returns
Type | Description |
---|---|
System.Boolean |
|
GetAnalysisFor<T>()
Gets the analysis, registered with this control-flow graph, that produced a particular type of result.
Declaration
public IFlowGraphAnalysis<T> GetAnalysisFor<T>()
Returns
Type | Description |
---|---|
IFlowGraphAnalysis<T> | An analysis. |
Type Parameters
Name | Description |
---|---|
T | The type of analysis result that is sought. |
GetAnalysisResult<T>()
Gets an analysis result based on its type.
Declaration
public T GetAnalysisResult<T>()
Returns
Type | Description |
---|---|
T | An analysis result. |
Type Parameters
Name | Description |
---|---|
T | The type of analysis result to fetch or compute. |
GetBasicBlock(BasicBlockTag)
Gets the basic block with a particular tag.
Declaration
public BasicBlock GetBasicBlock(BasicBlockTag tag)
Parameters
Type | Name | Description |
---|---|---|
BasicBlockTag | tag | The basic block's tag. |
Returns
Type | Description |
---|---|
BasicBlock | A basic block. |
GetInstruction(ValueTag)
Gets the named instruction with a particular tag.
Declaration
public NamedInstruction GetInstruction(ValueTag tag)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The instruction's tag. |
Returns
Type | Description |
---|---|
NamedInstruction | A named instruction. |
GetValueParent(ValueTag)
Gets basic block that defines a value with a particular tag.
Declaration
public BasicBlock GetValueParent(ValueTag tag)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The tag of the value to look for. |
Returns
Type | Description |
---|---|
BasicBlock | The basic block that defines the value. |
GetValueType(ValueTag)
Gets the type of a value in this graph.
Declaration
public IType GetValueType(ValueTag tag)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The value's tag. |
Returns
Type | Description |
---|---|
IType | The value's type. |
HasAnalysisFor<T>()
Tells if this flow graph has an analysis that produces a particular type of result.
Declaration
public bool HasAnalysisFor<T>()
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
T | The type of analysis result that is sought. |
Map(MemberMapping)
Applies a member mapping to this flow graph.
Declaration
public FlowGraph Map(MemberMapping mapping)
Parameters
Type | Name | Description |
---|---|---|
MemberMapping | mapping | A member mapping. |
Returns
Type | Description |
---|---|
FlowGraph | A transformed flow graph. |
RemoveBasicBlock(BasicBlockTag)
Removes the basic block with a particular tag from this control-flow graph.
Declaration
public FlowGraph RemoveBasicBlock(BasicBlockTag tag)
Parameters
Type | Name | Description |
---|---|---|
BasicBlockTag | tag | The basic block's tag. |
Returns
Type | Description |
---|---|
FlowGraph | A new control-flow graph that does not contain the basic block. |
RemoveDefinitions(IEnumerable<ValueTag>)
Removes the definitions for a set of values from this flow graph.
Declaration
public FlowGraph RemoveDefinitions(IEnumerable<ValueTag> valuesToRemove)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ValueTag> | valuesToRemove | A set of values whose definitions are to be eliminated from the flow graph. These values can refer to instructions and basic block parameters. |
Returns
Type | Description |
---|---|
FlowGraph | A flow graph that does not define any of the values. |
RemoveInstruction(ValueTag)
Removes a particular instruction from this control-flow graph. Returns a new control-flow graph that does not contain the instruction.
Declaration
public FlowGraph RemoveInstruction(ValueTag instructionTag)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | instructionTag | The tag of the instruction to remove. |
Returns
Type | Description |
---|---|
FlowGraph | A control-flow graph that no longer contains the instruction. |
RemoveInstructionDefinitions(IEnumerable<ValueTag>)
Removes the definitions for a set of instructions from this flow graph.
Declaration
public FlowGraph RemoveInstructionDefinitions(IEnumerable<ValueTag> instructionsToRemove)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ValueTag> | instructionsToRemove | A set of values whose definitions are to be eliminated from the flow graph. These values may only refer to instructions. |
Returns
Type | Description |
---|---|
FlowGraph | A flow graph that does not define any of the values. |
ReplaceUses(IReadOnlyDictionary<ValueTag, ValueTag>)
Replaces all uses of values with other values. The values to replace are encoded as keys in a dictionary and the values to replace them with as values in that same dictionary.
Declaration
public FlowGraph ReplaceUses(IReadOnlyDictionary<ValueTag, ValueTag> replacementMap)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IReadOnlyDictionary<ValueTag, ValueTag> | replacementMap | A mapping of values to replacement values. |
Returns
Type | Description |
---|---|
FlowGraph | A new flow graph. |
ToBuilder()
Creates a mutable control-flow graph builder from this immutable control-flow graph.
Declaration
public FlowGraphBuilder ToBuilder()
Returns
Type | Description |
---|---|
FlowGraphBuilder | A mutable control-flow graph builder. |
Transform(IntraproceduralOptimization)
Applies an intraprocedural optimization to this flow graph.
Declaration
public FlowGraph Transform(IntraproceduralOptimization optimization)
Parameters
Type | Name | Description |
---|---|---|
IntraproceduralOptimization | optimization | The transform to apply. |
Returns
Type | Description |
---|---|
FlowGraph | A transformed flow graph. |
Transform(IntraproceduralOptimization[])
Applies a sequence of intraprocedural optimizations to this flow graph.
Declaration
public FlowGraph Transform(params IntraproceduralOptimization[] optimizations)
Parameters
Type | Name | Description |
---|---|---|
IntraproceduralOptimization[] | optimizations | The transforms to apply. |
Returns
Type | Description |
---|---|
FlowGraph | A transformed flow graph. |
Transform(IEnumerable<IntraproceduralOptimization>)
Applies a sequence of intraprocedural optimizations to this flow graph.
Declaration
public FlowGraph Transform(IEnumerable<IntraproceduralOptimization> optimizations)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<IntraproceduralOptimization> | optimizations | The transforms to apply. |
Returns
Type | Description |
---|---|
FlowGraph | A transformed flow graph. |
TryGetAnalysisResult<T>(out T)
Tries to get an analysis result of a particular type.
Declaration
public bool TryGetAnalysisResult<T>(out T result)
Parameters
Type | Name | Description |
---|---|---|
T | result | The analysis result, if one can be fetched or computed. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
T | The type of analysis result to fetch or compute. |
TryGetInstruction(ValueTag, out NamedInstruction)
Tries to get an instruction with a particular tag, if it exists in this control-flow graph.
Declaration
public bool TryGetInstruction(ValueTag tag, out NamedInstruction result)
Parameters
Type | Name | Description |
---|---|---|
ValueTag | tag | The instruction's tag. |
NamedInstruction | result | The named instruction, if it exists in this control-flow graph. |
Returns
Type | Description |
---|---|
System.Boolean |
|
WithAnalysis<T>(IFlowGraphAnalysis<T>)
Registers an analysis on this flow graph.
Declaration
public FlowGraph WithAnalysis<T>(IFlowGraphAnalysis<T> analysis)
Parameters
Type | Name | Description |
---|---|---|
IFlowGraphAnalysis<T> | analysis | The analysis to register. |
Returns
Type | Description |
---|---|
FlowGraph | A new flow graph that includes the analysis. |
Type Parameters
Name | Description |
---|---|
T | The type of result produced by the analysis. |
WithEntryPoint(BasicBlockTag)
Creates a new control-flow graph that takes the basic block with a particular tag as entry point.
Declaration
public FlowGraph WithEntryPoint(BasicBlockTag tag)
Parameters
Type | Name | Description |
---|---|---|
BasicBlockTag | tag | The tag of the new entry point block. |
Returns
Type | Description |
---|---|
FlowGraph | A control-flow graph. |