Class FlowGraphBuilder
A mutable view of an immutable control-flow graph.
Inheritance
Inherited Members
Namespace: Flame.Compiler
Assembly: Flame.Compiler.dll
Syntax
public sealed class FlowGraphBuilder
Constructors
| Improve this Doc View SourceFlowGraphBuilder()
Creates a control-flow graph builder that contains only an empty entry point block.
Declaration
public FlowGraphBuilder()
FlowGraphBuilder(FlowGraph)
Creates a control-flow graph builder from an immutable control-flow graph.
Declaration
public FlowGraphBuilder(FlowGraph graph)
Parameters
| Type | Name | Description |
|---|---|---|
| FlowGraph | graph | An immutable control-flow graph. |
Properties
| Improve this Doc View SourceAnonymousInstructions
Gets a sequence of all anonymous instructions defined by block flow in this control-flow graph.
Declaration
public IEnumerable<InstructionBuilder> AnonymousInstructions { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<InstructionBuilder> | All anonymous instructions. |
BasicBlocks
Gets a sequence of all basic blocks in this control-flow graph.
Declaration
public IEnumerable<BasicBlockBuilder> BasicBlocks { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<BasicBlockBuilder> | 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 BasicBlockBuilder EntryPoint { get; }
Property Value
| Type | Description |
|---|---|
| BasicBlockBuilder | The entry point block. |
EntryPointTag
Gets the tag of the entry point block.
Declaration
public BasicBlockTag EntryPointTag { get; set; }
Property Value
| Type | Description |
|---|---|
| BasicBlockTag | The tag of the entry point block. |
Instructions
Gets a sequence of all instructions defined in this control-flow graph, including both named and anonymous instructions.
Declaration
public IEnumerable<InstructionBuilder> Instructions { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<InstructionBuilder> | All instructions in this control-flow graph. |
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<NamedInstructionBuilder> NamedInstructions { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<NamedInstructionBuilder> | 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 SourceAddAnalysis<T>(IFlowGraphAnalysis<T>)
Registers a flow graph analysis with this graph.
Declaration
public void AddAnalysis<T>(IFlowGraphAnalysis<T> analysis)
Parameters
| Type | Name | Description |
|---|---|---|
| IFlowGraphAnalysis<T> | analysis | The analysis to register. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of result produced by the analysis. |
AddBasicBlock()
Adds an empty basic block to this flow-graph builder.
Declaration
public BasicBlockBuilder AddBasicBlock()
Returns
| Type | Description |
|---|---|
| BasicBlockBuilder | An empty basic block builder. |
AddBasicBlock(String)
Adds an empty basic block to this flow-graph builder.
Declaration
public BasicBlockBuilder AddBasicBlock(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The (preferred) name of the basic block's tag. |
Returns
| Type | Description |
|---|---|
| BasicBlockBuilder | An empty basic block builder. |
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 BasicBlockBuilder GetBasicBlock(BasicBlockTag tag)
Parameters
| Type | Name | Description |
|---|---|---|
| BasicBlockTag | tag | The basic block's tag. |
Returns
| Type | Description |
|---|---|
| BasicBlockBuilder | A basic block. |
GetInstruction(InstructionBuilder)
Gets this control flow graph builder's equivalent of a shared instruction in another control flow graph.
Declaration
public InstructionBuilder GetInstruction(InstructionBuilder instruction)
Parameters
| Type | Name | Description |
|---|---|---|
| InstructionBuilder | instruction | The instruction builder to find an equivalent for. |
Returns
| Type | Description |
|---|---|
| InstructionBuilder | An instruction builder. |
GetInstruction(ValueTag)
Gets the instruction with a particular tag.
Declaration
public NamedInstructionBuilder GetInstruction(ValueTag tag)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTag | tag | The instruction's tag. |
Returns
| Type | Description |
|---|---|
| NamedInstructionBuilder | A named instruction. |
GetValueParent(ValueTag)
Gets basic block that defines a value with a particular tag.
Declaration
public BasicBlockBuilder GetValueParent(ValueTag tag)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTag | tag | The tag of the value to look for. |
Returns
| Type | Description |
|---|---|
| BasicBlockBuilder | 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. |
Include(FlowGraph, Func<ReturnFlow, BasicBlockBuilder, BlockFlow>)
Includes a control-flow graph in this control-flow graph. Any values and blocks defined by the graph to include are renamed in order to avoid conflicts with tags in this graph.
Declaration
public BasicBlockTag Include(FlowGraph graph, Func<ReturnFlow, BasicBlockBuilder, BlockFlow> rewriteReturnFlow)
Parameters
| Type | Name | Description |
|---|---|---|
| FlowGraph | graph | The graph to include in this graph. |
| System.Func<ReturnFlow, BasicBlockBuilder, BlockFlow> | rewriteReturnFlow | Rewrites 'return' flow. |
Returns
| Type | Description |
|---|---|
| BasicBlockTag | The tag of the imported graph's entry point. |
Include(FlowGraph, Func<ReturnFlow, BasicBlockBuilder, BlockFlow>, Branch)
Includes a control-flow graph in this control-flow graph. Any values and blocks defined by the graph to include are renamed in order to avoid conflicts with tags in this graph. Instructions that may throw an exception are wrapped in 'try' flow.
Declaration
public BasicBlockTag Include(FlowGraph graph, Func<ReturnFlow, BasicBlockBuilder, BlockFlow> rewriteReturnFlow, Branch exceptionBranch)
Parameters
| Type | Name | Description |
|---|---|---|
| FlowGraph | graph | The graph to include in this graph. |
| System.Func<ReturnFlow, BasicBlockBuilder, BlockFlow> | rewriteReturnFlow | Rewrites 'return' flow. |
| Branch | exceptionBranch | The branch to take when an exception is thrown by an instruction
in |
Returns
| Type | Description |
|---|---|
| BasicBlockTag | The tag of the imported graph's entry point. |
RemoveBasicBlock(BasicBlockTag)
Removes the basic block with a particular tag from this control-flow graph.
Declaration
public void RemoveBasicBlock(BasicBlockTag tag)
Parameters
| Type | Name | Description |
|---|---|---|
| BasicBlockTag | tag | The basic block's tag. |
RemoveDefinitions(IEnumerable<ValueTag>)
Removes the definitions for a set of values from this flow graph.
Declaration
public void 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. |
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 void RemoveInstruction(ValueTag instructionTag)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTag | instructionTag | The tag of the instruction to remove. |
RemoveInstructionDefinitions(IEnumerable<ValueTag>)
Removes the definitions for a set of instructions from this flow graph.
Declaration
public void 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. |
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 void ReplaceUses(IReadOnlyDictionary<ValueTag, ValueTag> replacementMap)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IReadOnlyDictionary<ValueTag, ValueTag> | replacementMap | A mapping of values to replacement values. |
ToImmutable()
Turns this control-flow graph builder into an immutable control-flow graph.
Declaration
public FlowGraph ToImmutable()
Returns
| Type | Description |
|---|---|
| FlowGraph | An immutable control-flow graph. |
Transform(IntraproceduralOptimization)
Applies an intraprocedural optimization to this flow graph.
Declaration
public void Transform(IntraproceduralOptimization optimization)
Parameters
| Type | Name | Description |
|---|---|---|
| IntraproceduralOptimization | optimization | The transform to apply. |
Transform(IntraproceduralOptimization[])
Applies a sequence of intraprocedural optimizations to this flow graph.
Declaration
public void Transform(params IntraproceduralOptimization[] optimizations)
Parameters
| Type | Name | Description |
|---|---|---|
| IntraproceduralOptimization[] | optimizations | The transforms to apply. |
Transform(IEnumerable<IntraproceduralOptimization>)
Applies a sequence of intraprocedural optimizations to this flow graph.
Declaration
public void Transform(IEnumerable<IntraproceduralOptimization> optimizations)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<IntraproceduralOptimization> | optimizations | The transforms to apply. |
TryForkAndMerge(Func<FlowGraphBuilder, Boolean>)
Applies a function to a copy of this control-flow graph and either incorporates those changes into this control-flow graph or discards them, depending on the Boolean value returned by the transforming function.
Declaration
public bool TryForkAndMerge(Func<FlowGraphBuilder, bool> transform)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Func<FlowGraphBuilder, System.Boolean> | transform | A function that takes a copy of this control-flow graph and modifies it.
If the function returns |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
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 NamedInstructionBuilder)
Tries to get an instruction with a particular tag, if it exists in this control-flow graph.
Declaration
public bool TryGetInstruction(ValueTag tag, out NamedInstructionBuilder result)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTag | tag | The instruction's tag. |
| NamedInstructionBuilder | result | The named instruction, if it exists in this control-flow graph. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|