Show / Hide Table of Contents

    Class PeepholeOptimizer<TInstruction, TExternalRef>

    A target-specific peephole optimizer: an optimizer that walks through a linear sequence of target-specific instructions, recognizes patterns and rewrites small batches of instructions.

    Inheritance
    System.Object
    PeepholeOptimizer<TInstruction, TExternalRef>
    CilPeepholeOptimizer
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: Flame.Compiler.Target
    Assembly: Flame.Compiler.dll
    Syntax
    public class PeepholeOptimizer<TInstruction, TExternalRef>
    Type Parameters
    Name Description
    TInstruction

    The type of target-specific instruction to optimize.

    TExternalRef

    The type of an external reference to instructions.

    Constructors

    | Improve this Doc View Source

    PeepholeOptimizer(IReadOnlyList<PeepholeRewriteRule<TInstruction>>)

    Creates a peephole optimizer that applies a set of rewrite rules.

    Declaration
    public PeepholeOptimizer(IReadOnlyList<PeepholeRewriteRule<TInstruction>> rules)
    Parameters
    Type Name Description
    System.Collections.Generic.IReadOnlyList<PeepholeRewriteRule<TInstruction>> rules

    The rewrite rules to apply.

    Properties

    | Improve this Doc View Source

    Rules

    Gets a list of all rewrite rules used by this peephole optimizer.

    Declaration
    public IReadOnlyList<PeepholeRewriteRule<TInstruction>> Rules { get; }
    Property Value
    Type Description
    System.Collections.Generic.IReadOnlyList<PeepholeRewriteRule<TInstruction>>

    A list of rewrite rules.

    Methods

    | Improve this Doc View Source

    GetBranchTargets(TInstruction)

    Gets a list of all instructions to which a particular instruction may branch.

    Declaration
    protected virtual IEnumerable<TInstruction> GetBranchTargets(TInstruction instruction)
    Parameters
    Type Name Description
    TInstruction instruction

    An instruction that may branch to other instructions.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<TInstruction>

    A list of branch targets.

    | Improve this Doc View Source

    GetInstructionReferences(TExternalRef)

    Gets a list of all instructions referenced by a particular external instruction reference.

    Declaration
    protected virtual IEnumerable<TInstruction> GetInstructionReferences(TExternalRef externalRef)
    Parameters
    Type Name Description
    TExternalRef externalRef

    The external reference to examine.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<TInstruction>

    A list of referenced instructions.

    | Improve this Doc View Source

    Optimize(IReadOnlyList<TInstruction>)

    Optimizes a linear sequence of instructions by applying rewrite rules.

    Declaration
    public IReadOnlyList<TInstruction> Optimize(IReadOnlyList<TInstruction> instructions)
    Parameters
    Type Name Description
    System.Collections.Generic.IReadOnlyList<TInstruction> instructions

    The instructions to optimize.

    Returns
    Type Description
    System.Collections.Generic.IReadOnlyList<TInstruction>

    A linear sequence of optimized instructions.

    | Improve this Doc View Source

    Optimize(IReadOnlyList<TInstruction>, IReadOnlyList<TExternalRef>, out IReadOnlyList<TExternalRef>)

    Optimizes a linear sequence of instructions by applying rewrite rules.

    Declaration
    public IReadOnlyList<TInstruction> Optimize(IReadOnlyList<TInstruction> instructions, IReadOnlyList<TExternalRef> externalRefs, out IReadOnlyList<TExternalRef> newExternalRefs)
    Parameters
    Type Name Description
    System.Collections.Generic.IReadOnlyList<TInstruction> instructions

    The instructions to optimize.

    System.Collections.Generic.IReadOnlyList<TExternalRef> externalRefs

    A list of external references to instructions.

    System.Collections.Generic.IReadOnlyList<TExternalRef> newExternalRefs

    A list of rewritten external references to instructions.

    Returns
    Type Description
    System.Collections.Generic.IReadOnlyList<TInstruction>

    A linear sequence of optimized instructions.

    | Improve this Doc View Source

    RewriteBranchTargets(TInstruction, IReadOnlyDictionary<TInstruction, TInstruction>)

    Rewrites an instruction's branch targets.

    Declaration
    protected virtual TInstruction RewriteBranchTargets(TInstruction instruction, IReadOnlyDictionary<TInstruction, TInstruction> branchTargetMap)
    Parameters
    Type Name Description
    TInstruction instruction

    The instruction to rewrite.

    System.Collections.Generic.IReadOnlyDictionary<TInstruction, TInstruction> branchTargetMap

    A mapping of old branch target instructions to new branch target instructions.

    Returns
    Type Description
    TInstruction

    A modified or new instruction.

    | Improve this Doc View Source

    RewriteInstructionReferences(TExternalRef, IReadOnlyDictionary<TInstruction, TInstruction>)

    Rewrites an external reference's referenced instructions.

    Declaration
    protected virtual TExternalRef RewriteInstructionReferences(TExternalRef externalRef, IReadOnlyDictionary<TInstruction, TInstruction> referenceMap)
    Parameters
    Type Name Description
    TExternalRef externalRef

    The reference to rewrite.

    System.Collections.Generic.IReadOnlyDictionary<TInstruction, TInstruction> referenceMap

    A mapping of old referenced instructions to new referenced instructions.

    Returns
    Type Description
    TExternalRef

    A modified or new external reference.

    • Improve this Doc
    • View Source
    Back to top Generated by DocFX