regalloc

package
v0.0.0-...-ecbd380 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCriticalEdges = errors.New("the CFG has critical edges")
View Source
var ErrEntryLiveIns = errors.New("entry block has live in values")
View Source
var ErrTooManyRequiredRegisters = errors.New("too many required registers")

Functions

func DumpLivenessChart

func DumpLivenessChart(ra *RegAlloc)

func WriteGraphvizCFG

func WriteGraphvizCFG(ra *RegAlloc)

WriteGraphvizCFG emits a Graphviz dot file of the CFG

func WriteGraphvizInterferenceGraph

func WriteGraphvizInterferenceGraph(ra *RegAlloc)

WriteGraphvizInterferenceGraph emits a Graphviz dot file of the Interference Graph

func WriteGraphvizLivenessGraph

func WriteGraphvizLivenessGraph(ra *RegAlloc)

Types

type RegAlloc

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

func NewRegAlloc

func NewRegAlloc(fn *ir.Func) *RegAlloc

NewRegAlloc returns a new register allocator, ready to have the registers allocated for the given function.

func (*RegAlloc) Allocate

func (ra *RegAlloc) Allocate() error

Allocate will run the allocator and assign a physical register or stack slot to each Value that needs one.

This uses a graph colouring algorithm designed for use on SSA code. The SSA code should have copies added for block defs/args such that the allocator is free to choose different registers as it crosses that boundary. Attempts will be made to strongly prefer choosing the same register across a copy and across block args/defs to minimize the number of copies in the resultant code.

A simpler algorithm is chosen rather than a fast algorithm because this can easily be a very complex piece of code and simpler code is easier to ensure is correct. It's extremely important that the register allocator produces correct code or else pretty much anything can happen.

To that end, there is a verifier in the verify sub-package which will double check the work of the allocator. See that code for more information on how it works.

func (*RegAlloc) CheckInput

func (ra *RegAlloc) CheckInput() error

CheckInput will verify the structure of the input code, which is useful in tests and fuzzing.

Directories

Path Synopsis
Package verify contains a symbolic verifier to check if registers are allocated correctly
Package verify contains a symbolic verifier to check if registers are allocated correctly

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL