package pass

import "github.com/mmcloughlin/avo/pass"

Package pass implements processing passes on avo Files.

Index

Variables

var Compile = Concat(
	Verify,
	FunctionPass(PruneJumpToFollowingLabel),
	FunctionPass(PruneDanglingLabels),
	FunctionPass(LabelTarget),
	FunctionPass(CFG),
	InstructionPass(ZeroExtend32BitOutputs),
	FunctionPass(Liveness),
	FunctionPass(AllocateRegisters),
	FunctionPass(BindRegisters),
	FunctionPass(VerifyAllocation),
	FunctionPass(EnsureBasePointerCalleeSaved),
	Func(IncludeTextFlagHeader),
	FunctionPass(PruneSelfMoves),
	FunctionPass(RequiredISAExtensions),
)

Compile pass compiles an avo file. Upon successful completion the avo file may be printed to Go assembly.

var Verify = Concat(
	InstructionPass(VerifyMemOperands),
)

Verify pass validates an avo file.

Functions

func AllocateRegisters

func AllocateRegisters(fn *ir.Function) error

AllocateRegisters performs register allocation.

func BindRegisters

func BindRegisters(fn *ir.Function) error

BindRegisters applies the result of register allocation, replacing all virtual registers with their assigned physical registers.

func CFG

func CFG(fn *ir.Function) error

CFG constructs the call-flow-graph for the function.

func EnsureBasePointerCalleeSaved

func EnsureBasePointerCalleeSaved(fn *ir.Function) error

EnsureBasePointerCalleeSaved ensures that the base pointer register will be saved and restored if it has been clobbered by the function.

func IncludeTextFlagHeader

func IncludeTextFlagHeader(f *ir.File) error

IncludeTextFlagHeader includes textflag.h if necessary.

func LabelTarget

func LabelTarget(fn *ir.Function) error

LabelTarget populates the LabelTarget of the given function. This maps from label name to the following instruction.

func Liveness

func Liveness(fn *ir.Function) error

Liveness computes register liveness.

func PruneDanglingLabels

func PruneDanglingLabels(fn *ir.Function) error

PruneDanglingLabels removes labels that are not referenced by any branches.

func PruneJumpToFollowingLabel

func PruneJumpToFollowingLabel(fn *ir.Function) error

PruneJumpToFollowingLabel removes jump instructions that target an immediately following label.

func PruneSelfMoves

func PruneSelfMoves(fn *ir.Function) error

PruneSelfMoves removes move instructions from one register to itself.

func RequiredISAExtensions

func RequiredISAExtensions(fn *ir.Function) error

RequiredISAExtensions determines ISA extensions required for the given function. Populates the ISA field.

func VerifyAllocation

func VerifyAllocation(fn *ir.Function) error

VerifyAllocation performs sanity checks following register allocation.

func VerifyMemOperands

func VerifyMemOperands(i *ir.Instruction) error

VerifyMemOperands checks the instruction's memory operands.

func ZeroExtend32BitOutputs

func ZeroExtend32BitOutputs(i *ir.Instruction) error

ZeroExtend32BitOutputs applies the rule that "32-bit operands generate a 32-bit result, zero-extended to a 64-bit result in the destination general-purpose register" (Intel Software Developer’s Manual, Volume 1, 3.4.1.1).

Types

type Allocator

type Allocator struct {
	// contains filtered or unexported fields
}

Allocator is a graph-coloring register allocator.

func NewAllocator

func NewAllocator(rs []reg.Physical) (*Allocator, error)

NewAllocator builds an allocator for the given physical registers.

func NewAllocatorForKind

func NewAllocatorForKind(k reg.Kind) (*Allocator, error)

NewAllocatorForKind builds an allocator for the given kind of registers.

func (*Allocator) Add

func (a *Allocator) Add(v reg.ID)

Add adds a register to be allocated. Does nothing if the register has already been added.

func (*Allocator) AddInterference

func (a *Allocator) AddInterference(x, y reg.ID)

AddInterference records that x and y must be assigned to non-conflicting physical registers.

func (*Allocator) AddInterferenceSet

func (a *Allocator) AddInterferenceSet(r reg.Register, s reg.MaskSet)

AddInterferenceSet records that r interferes with every register in s. Convenience wrapper around AddInterference.

func (*Allocator) Allocate

func (a *Allocator) Allocate() (reg.Allocation, error)

Allocate allocates physical registers.

func (*Allocator) SetPriority

func (a *Allocator) SetPriority(id reg.ID, p int)

SetPriority sets the priority of the given regiser to p. Higher priority registers are preferred in allocations. By default all registers have 0 priority. Priority will only apply to subsequent Add() calls, therefore typically all SetPriority calls should happen at allocator initialization.

type Func

type Func func(*ir.File) error

Func adapts a function to the pass Interface.

func (Func) Execute

func (p Func) Execute(f *ir.File) error

Execute calls p.

type FunctionPass

type FunctionPass func(*ir.Function) error

FunctionPass is a convenience for implementing a full file pass with a function that operates on each avo Function independently.

func (FunctionPass) Execute

func (p FunctionPass) Execute(f *ir.File) error

Execute calls p on every function in the file. Exits on the first error.

type InstructionPass

type InstructionPass func(*ir.Instruction) error

InstructionPass is a convenience for implementing a full file pass with a function that operates on each Instruction independently.

func (InstructionPass) Execute

func (p InstructionPass) Execute(f *ir.File) error

Execute calls p on every instruction in the file. Exits on the first error.

type Interface

type Interface interface {
	Execute(*ir.File) error
}

Interface for a processing pass.

func Concat

func Concat(passes ...Interface) Interface

Concat returns a pass that executes the given passes in order, stopping on the first error.

type Output

type Output struct {
	Writer  io.WriteCloser
	Printer printer.Printer
}

Output pass prints a file.

func (*Output) Execute

func (o *Output) Execute(f *ir.File) error

Execute prints f with the configured Printer and writes output to Writer.

Source Files

alloc.go cfg.go cleanup.go isa.go pass.go reg.go textflag.go verify.go

Version
v0.6.0 (latest)
Published
Jan 7, 2024
Platform
linux/amd64
Imports
11 packages
Last checked
4 weeks ago

Tools for package owners.