ssa

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MinInt65 = Int65{0, 1}
	MaxInt65 = Int65{math.MaxUint64, 0}
)
View Source
var ArchRegNames = map[x86_64.Register64]string{
	x86_64.RAX: "rax",
	x86_64.RCX: "rcx",
	x86_64.RDX: "rdx",
	x86_64.RBX: "rbx",
	x86_64.RSP: "rsp",
	x86_64.RBP: "rbp",
	x86_64.RSI: "rsi",
	x86_64.RDI: "rdi",
	x86_64.R8:  "r8",
	x86_64.R9:  "r9",
	x86_64.R10: "r10",
	x86_64.R11: "r11",
	x86_64.R12: "r12",
	x86_64.R13: "r13",
	x86_64.R14: "r14",
	x86_64.R15: "r15",
}
View Source
var Passes = [...]PassDescriptor{
	{Desc: "Constant Propagation", Pass: new(ConstProp)},
	{Desc: "Common Sub-expression Elimination", Pass: new(CSE)},
	{Desc: "Early Phi Elimination", Pass: new(PhiElim)},
	{Desc: "Early Copy Elimination", Pass: new(CopyElim)},
	{Desc: "Early Trivial Dead Code Elimination", Pass: new(TDCE)},
	{Desc: "Branch Elimination", Pass: new(BranchElim)},
	{Desc: "Late Phi Elimination", Pass: new(PhiElim)},
	{Desc: "Late Copy Elimination", Pass: new(CopyElim)},
	{Desc: "Late Trivial Dead Code Elimination", Pass: new(TDCE)},
	{Desc: "Intermediate Block Merging", Pass: new(BlockMerge)},
}

Functions

This section is empty.

Types

type BasicBlock

type BasicBlock struct {
	Id   int
	Phi  []*IrPhi
	Ins  []IrNode
	Pred []*BasicBlock
	Term IrTerminator
}

func Unreachable

func Unreachable(bb *BasicBlock, id int) (ret *BasicBlock)

type BlockMerge

type BlockMerge struct{}

BlockMerge merges redundant intermediate blocks (blocks with a single outgoing edge which goes to another block with a single incoming edge).

func (BlockMerge) Apply

func (BlockMerge) Apply(cfg *CFG)

type BranchElim

type BranchElim struct{}

BranchElim removes branches that can be proved unreachable.

func (BranchElim) Apply

func (self BranchElim) Apply(cfg *CFG)

type CFG

type CFG struct {
	DominatorTree
}

func Compile

func Compile(p hir.Program) (cfg *CFG)

func (*CFG) MaxBlock

func (self *CFG) MaxBlock() int

func (*CFG) PostOrder

func (self *CFG) PostOrder(action func(bb *BasicBlock))

func (*CFG) Rebuild

func (self *CFG) Rebuild()

func (*CFG) ReversePostOrder

func (self *CFG) ReversePostOrder(action func(bb *BasicBlock))

type CSE

type CSE struct{}

CSE performs the Common Sub-expression Elimintation optimization.

func (CSE) Apply

func (self CSE) Apply(cfg *CFG)

type ConstProp

type ConstProp struct{}

ConstProp propagates constant through the expression tree.

func (ConstProp) Apply

func (self ConstProp) Apply(cfg *CFG)

type CopyElim

type CopyElim struct{}

CopyElim removes unnessecery register copies.

func (CopyElim) Apply

func (self CopyElim) Apply(cfg *CFG)

type DominatorTree

type DominatorTree struct {
	Root              *BasicBlock
	DominatedBy       map[int]*BasicBlock
	DominatorOf       map[int][]*BasicBlock
	DominanceFrontier map[int][]*BasicBlock
}

type Int65

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

func Int65i

func Int65i(v int64) Int65

func (Int65) Compare

func (self Int65) Compare(other Int65) int

func (Int65) CompareZero

func (self Int65) CompareZero() int

func (Int65) OneLess

func (self Int65) OneLess() (r Int65)

func (Int65) OneMore

func (self Int65) OneMore() (r Int65)

func (Int65) String

func (self Int65) String() string

type IrAMD64_ADDQ

type IrAMD64_ADDQ struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_ADDQ) Definations

func (self *IrAMD64_ADDQ) Definations() []*Reg

func (*IrAMD64_ADDQ) String

func (self *IrAMD64_ADDQ) String() string

func (*IrAMD64_ADDQ) Usages

func (self *IrAMD64_ADDQ) Usages() []*Reg

type IrAMD64_ANDQ

type IrAMD64_ANDQ struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_ANDQ) Definations

func (self *IrAMD64_ANDQ) Definations() []*Reg

func (*IrAMD64_ANDQ) String

func (self *IrAMD64_ANDQ) String() string

func (*IrAMD64_ANDQ) Usages

func (self *IrAMD64_ANDQ) Usages() []*Reg

type IrAMD64_BSWAP

type IrAMD64_BSWAP struct {
	R Reg
	V Reg
	S uint8
}

func (*IrAMD64_BSWAP) Definations

func (self *IrAMD64_BSWAP) Definations() []*Reg

func (*IrAMD64_BSWAP) String

func (self *IrAMD64_BSWAP) String() string

func (*IrAMD64_BSWAP) Usages

func (self *IrAMD64_BSWAP) Usages() []*Reg

type IrAMD64_BTSQ

type IrAMD64_BTSQ struct {
	T Reg
	S Reg
	X Reg
	Y Reg
}

func (*IrAMD64_BTSQ) Definations

func (self *IrAMD64_BTSQ) Definations() []*Reg

func (*IrAMD64_BTSQ) String

func (self *IrAMD64_BTSQ) String() string

func (*IrAMD64_BTSQ) Usages

func (self *IrAMD64_BTSQ) Usages() []*Reg

type IrAMD64_CMPQ_eq

type IrAMD64_CMPQ_eq struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_CMPQ_eq) Definations

func (self *IrAMD64_CMPQ_eq) Definations() []*Reg

func (*IrAMD64_CMPQ_eq) String

func (self *IrAMD64_CMPQ_eq) String() string

func (*IrAMD64_CMPQ_eq) Usages

func (self *IrAMD64_CMPQ_eq) Usages() []*Reg

type IrAMD64_CMPQ_geu

type IrAMD64_CMPQ_geu struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_CMPQ_geu) Definations

func (self *IrAMD64_CMPQ_geu) Definations() []*Reg

func (*IrAMD64_CMPQ_geu) String

func (self *IrAMD64_CMPQ_geu) String() string

func (*IrAMD64_CMPQ_geu) Usages

func (self *IrAMD64_CMPQ_geu) Usages() []*Reg

type IrAMD64_CMPQ_lt

type IrAMD64_CMPQ_lt struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_CMPQ_lt) Definations

func (self *IrAMD64_CMPQ_lt) Definations() []*Reg

func (*IrAMD64_CMPQ_lt) String

func (self *IrAMD64_CMPQ_lt) String() string

func (*IrAMD64_CMPQ_lt) Usages

func (self *IrAMD64_CMPQ_lt) Usages() []*Reg

type IrAMD64_CMPQ_ltu

type IrAMD64_CMPQ_ltu struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_CMPQ_ltu) Definations

func (self *IrAMD64_CMPQ_ltu) Definations() []*Reg

func (*IrAMD64_CMPQ_ltu) String

func (self *IrAMD64_CMPQ_ltu) String() string

func (*IrAMD64_CMPQ_ltu) Usages

func (self *IrAMD64_CMPQ_ltu) Usages() []*Reg

type IrAMD64_CMPQ_ne

type IrAMD64_CMPQ_ne struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_CMPQ_ne) Definations

func (self *IrAMD64_CMPQ_ne) Definations() []*Reg

func (*IrAMD64_CMPQ_ne) String

func (self *IrAMD64_CMPQ_ne) String() string

func (*IrAMD64_CMPQ_ne) Usages

func (self *IrAMD64_CMPQ_ne) Usages() []*Reg

type IrAMD64_IMULQ

type IrAMD64_IMULQ struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_IMULQ) Definations

func (self *IrAMD64_IMULQ) Definations() []*Reg

func (*IrAMD64_IMULQ) String

func (self *IrAMD64_IMULQ) String() string

func (*IrAMD64_IMULQ) Usages

func (self *IrAMD64_IMULQ) Usages() []*Reg

type IrAMD64_INT

type IrAMD64_INT struct {
	I uint8
}

func (*IrAMD64_INT) String

func (self *IrAMD64_INT) String() string

type IrAMD64_JE_imm

type IrAMD64_JE_imm struct {
	R  Reg
	V  int64
	To *BasicBlock
	Ln *BasicBlock
}

func (*IrAMD64_JE_imm) String

func (self *IrAMD64_JE_imm) String() string

func (*IrAMD64_JE_imm) Successors

func (self *IrAMD64_JE_imm) Successors() IrSuccessors

func (*IrAMD64_JE_imm) Usages

func (self *IrAMD64_JE_imm) Usages() []*Reg

type IrAMD64_JMP

type IrAMD64_JMP struct {
	To *BasicBlock
}

func (*IrAMD64_JMP) String

func (self *IrAMD64_JMP) String() string

func (*IrAMD64_JMP) Successors

func (self *IrAMD64_JMP) Successors() IrSuccessors

type IrAMD64_LEA

type IrAMD64_LEA struct {
	R Reg
	M Mem
}

func (*IrAMD64_LEA) Definations

func (self *IrAMD64_LEA) Definations() []*Reg

func (*IrAMD64_LEA) String

func (self *IrAMD64_LEA) String() string

func (*IrAMD64_LEA) Usages

func (self *IrAMD64_LEA) Usages() (r []*Reg)

type IrAMD64_MOVBE_load

type IrAMD64_MOVBE_load struct {
	R Reg
	M Mem
	S uint8
}

func (*IrAMD64_MOVBE_load) Definations

func (self *IrAMD64_MOVBE_load) Definations() []*Reg

func (*IrAMD64_MOVBE_load) String

func (self *IrAMD64_MOVBE_load) String() string

func (*IrAMD64_MOVBE_load) Usages

func (self *IrAMD64_MOVBE_load) Usages() (r []*Reg)

type IrAMD64_MOVBE_store

type IrAMD64_MOVBE_store struct {
	R Reg
	M Mem
	S uint8
}

func (*IrAMD64_MOVBE_store) String

func (self *IrAMD64_MOVBE_store) String() string

func (*IrAMD64_MOVBE_store) Usages

func (self *IrAMD64_MOVBE_store) Usages() (r []*Reg)

type IrAMD64_MOVSLQ

type IrAMD64_MOVSLQ struct {
	R Reg
	V Reg
}

func (*IrAMD64_MOVSLQ) Definations

func (self *IrAMD64_MOVSLQ) Definations() []*Reg

func (*IrAMD64_MOVSLQ) String

func (self *IrAMD64_MOVSLQ) String() string

func (*IrAMD64_MOVSLQ) Usages

func (self *IrAMD64_MOVSLQ) Usages() []*Reg

type IrAMD64_MOV_abs

type IrAMD64_MOV_abs struct {
	R Reg
	V int64
}

func (*IrAMD64_MOV_abs) Definations

func (self *IrAMD64_MOV_abs) Definations() []*Reg

func (*IrAMD64_MOV_abs) String

func (self *IrAMD64_MOV_abs) String() string

type IrAMD64_MOV_load

type IrAMD64_MOV_load struct {
	R Reg
	M Mem
	S uint8
}

func (*IrAMD64_MOV_load) Definations

func (self *IrAMD64_MOV_load) Definations() []*Reg

func (*IrAMD64_MOV_load) String

func (self *IrAMD64_MOV_load) String() string

func (*IrAMD64_MOV_load) Usages

func (self *IrAMD64_MOV_load) Usages() (r []*Reg)

type IrAMD64_MOV_ptr

type IrAMD64_MOV_ptr struct {
	R Reg
	P unsafe.Pointer
}

func (*IrAMD64_MOV_ptr) Definations

func (self *IrAMD64_MOV_ptr) Definations() []*Reg

func (*IrAMD64_MOV_ptr) String

func (self *IrAMD64_MOV_ptr) String() string

type IrAMD64_MOV_reg

type IrAMD64_MOV_reg struct {
	R Reg
	V Reg
}

func (*IrAMD64_MOV_reg) Definations

func (self *IrAMD64_MOV_reg) Definations() []*Reg

func (*IrAMD64_MOV_reg) String

func (self *IrAMD64_MOV_reg) String() string

func (*IrAMD64_MOV_reg) Usages

func (self *IrAMD64_MOV_reg) Usages() []*Reg

type IrAMD64_MOV_store

type IrAMD64_MOV_store struct {
	R Reg
	M Mem
	S uint8
}

func (*IrAMD64_MOV_store) String

func (self *IrAMD64_MOV_store) String() string

func (*IrAMD64_MOV_store) Usages

func (self *IrAMD64_MOV_store) Usages() (r []*Reg)

type IrAMD64_NEG

type IrAMD64_NEG struct {
	R Reg
	V Reg
}

func (*IrAMD64_NEG) Definations

func (self *IrAMD64_NEG) Definations() []*Reg

func (*IrAMD64_NEG) String

func (self *IrAMD64_NEG) String() string

func (*IrAMD64_NEG) Usages

func (self *IrAMD64_NEG) Usages() []*Reg

type IrAMD64_ORQ

type IrAMD64_ORQ struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_ORQ) Definations

func (self *IrAMD64_ORQ) Definations() []*Reg

func (*IrAMD64_ORQ) String

func (self *IrAMD64_ORQ) String() string

func (*IrAMD64_ORQ) Usages

func (self *IrAMD64_ORQ) Usages() []*Reg

type IrAMD64_SHRQ

type IrAMD64_SHRQ struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_SHRQ) Definations

func (self *IrAMD64_SHRQ) Definations() []*Reg

func (*IrAMD64_SHRQ) String

func (self *IrAMD64_SHRQ) String() string

func (*IrAMD64_SHRQ) Usages

func (self *IrAMD64_SHRQ) Usages() []*Reg

type IrAMD64_SUBQ

type IrAMD64_SUBQ struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_SUBQ) Definations

func (self *IrAMD64_SUBQ) Definations() []*Reg

func (*IrAMD64_SUBQ) String

func (self *IrAMD64_SUBQ) String() string

func (*IrAMD64_SUBQ) Usages

func (self *IrAMD64_SUBQ) Usages() []*Reg

type IrAMD64_XORQ

type IrAMD64_XORQ struct {
	R Reg
	X Reg
	Y Reg
}

func (*IrAMD64_XORQ) Definations

func (self *IrAMD64_XORQ) Definations() []*Reg

func (*IrAMD64_XORQ) String

func (self *IrAMD64_XORQ) String() string

func (*IrAMD64_XORQ) Usages

func (self *IrAMD64_XORQ) Usages() []*Reg

type IrBinaryExpr

type IrBinaryExpr struct {
	R  Reg
	X  Reg
	Y  Reg
	Op IrBinaryOp
}

func IrCopy

func IrCopy(r Reg, v Reg) *IrBinaryExpr

func (*IrBinaryExpr) Definations

func (self *IrBinaryExpr) Definations() []*Reg

func (*IrBinaryExpr) String

func (self *IrBinaryExpr) String() string

func (*IrBinaryExpr) Usages

func (self *IrBinaryExpr) Usages() []*Reg

type IrBinaryOp

type IrBinaryOp uint8
const (
	IrOpAdd IrBinaryOp = iota
	IrOpSub
	IrOpMul
	IrOpAnd
	IrOpOr
	IrOpXor
	IrOpShr
	IrCmpEq
	IrCmpNe
	IrCmpLt
	IrCmpLtu
	IrCmpGeu
)

func (IrBinaryOp) String

func (self IrBinaryOp) String() string

type IrBitTestSet

type IrBitTestSet struct {
	T Reg
	S Reg
	X Reg
	Y Reg
}

func (*IrBitTestSet) Definations

func (self *IrBitTestSet) Definations() []*Reg

func (*IrBitTestSet) String

func (self *IrBitTestSet) String() string

func (*IrBitTestSet) Usages

func (self *IrBitTestSet) Usages() []*Reg

type IrBreakpoint

type IrBreakpoint struct{}

func (IrBreakpoint) String

func (IrBreakpoint) String() string

type IrCall

type IrCall struct {
	Fn  *hir.CallHandle
	Rx  *IrReceiver
	In  []Reg
	Out []Reg
}

func (*IrCall) Definations

func (self *IrCall) Definations() []*Reg

func (*IrCall) String

func (self *IrCall) String() string

func (*IrCall) Usages

func (self *IrCall) Usages() []*Reg

type IrConstInt

type IrConstInt struct {
	R Reg
	V int64
}

func (*IrConstInt) Definations

func (self *IrConstInt) Definations() []*Reg

func (*IrConstInt) String

func (self *IrConstInt) String() string

type IrConstPtr

type IrConstPtr struct {
	R Reg
	P unsafe.Pointer
}

func (*IrConstPtr) Definations

func (self *IrConstPtr) Definations() []*Reg

func (*IrConstPtr) String

func (self *IrConstPtr) String() string

type IrDefinations

type IrDefinations interface {
	IrNode
	Definations() []*Reg
}

type IrLEA

type IrLEA struct {
	R   Reg
	Mem Reg
	Off Reg
}

func (*IrLEA) Definations

func (self *IrLEA) Definations() []*Reg

func (*IrLEA) String

func (self *IrLEA) String() string

func (*IrLEA) Usages

func (self *IrLEA) Usages() []*Reg

type IrLoad

type IrLoad struct {
	R    Reg
	Mem  Reg
	Size uint8
}

func (*IrLoad) Definations

func (self *IrLoad) Definations() []*Reg

func (*IrLoad) String

func (self *IrLoad) String() string

func (*IrLoad) Usages

func (self *IrLoad) Usages() []*Reg

type IrLoadArg

type IrLoadArg struct {
	R  Reg
	Id uint64
}

func (*IrLoadArg) Definations

func (self *IrLoadArg) Definations() []*Reg

func (*IrLoadArg) String

func (self *IrLoadArg) String() string

type IrNode

type IrNode interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

type IrPhi

type IrPhi struct {
	R Reg
	V map[*BasicBlock]*Reg
}

func (*IrPhi) Definations

func (self *IrPhi) Definations() []*Reg

func (*IrPhi) String

func (self *IrPhi) String() string

func (*IrPhi) Usages

func (self *IrPhi) Usages() []*Reg

type IrReceiver

type IrReceiver struct {
	T Reg
	V Reg
}

type IrReturn

type IrReturn struct {
	R []Reg
}

func (*IrReturn) String

func (self *IrReturn) String() string

func (*IrReturn) Successors

func (self *IrReturn) Successors() IrSuccessors

func (*IrReturn) Usages

func (self *IrReturn) Usages() []*Reg

type IrStore

type IrStore struct {
	R    Reg
	Mem  Reg
	Size uint8
}

func (*IrStore) String

func (self *IrStore) String() string

func (*IrStore) Usages

func (self *IrStore) Usages() []*Reg

type IrSuccessors

type IrSuccessors interface {
	Next() bool
	Block() *BasicBlock
	Value() (int64, bool)
}

type IrSwitch

type IrSwitch struct {
	V  Reg
	Ln *BasicBlock
	Br map[int64]*BasicBlock
}

func (*IrSwitch) String

func (self *IrSwitch) String() string

func (*IrSwitch) Successors

func (self *IrSwitch) Successors() IrSuccessors

func (*IrSwitch) Usages

func (self *IrSwitch) Usages() []*Reg

type IrTerminator

type IrTerminator interface {
	IrNode
	Successors() IrSuccessors
	// contains filtered or unexported methods
}

type IrUnaryExpr

type IrUnaryExpr struct {
	R  Reg
	V  Reg
	Op IrUnaryOp
}

func (*IrUnaryExpr) Definations

func (self *IrUnaryExpr) Definations() []*Reg

func (*IrUnaryExpr) String

func (self *IrUnaryExpr) String() string

func (*IrUnaryExpr) Usages

func (self *IrUnaryExpr) Usages() []*Reg

type IrUnaryOp

type IrUnaryOp uint8
const (
	IrOpNegate IrUnaryOp = iota
	IrOpSwap16
	IrOpSwap32
	IrOpSwap64
	IrOpSx32to64
)

func (IrUnaryOp) String

func (self IrUnaryOp) String() string

type IrUsages

type IrUsages interface {
	IrNode
	Usages() []*Reg
}

type IrWriteBarrier

type IrWriteBarrier struct {
	R Reg
	V Reg
}

func (*IrWriteBarrier) String

func (self *IrWriteBarrier) String() string

func (*IrWriteBarrier) Usages

func (self *IrWriteBarrier) Usages() []*Reg

type Lowering

type Lowering struct{}

Lowering lowers generic SSA IR to arch-dependent SSA IR

func (Lowering) Apply

func (Lowering) Apply(cfg *CFG)

type Mem

type Mem struct {
	M Reg
	I Reg
	S uint8
	D int32
}

func (Mem) String

func (self Mem) String() string

type Pass

type Pass interface {
	Apply(*CFG)
}

type PassDescriptor

type PassDescriptor struct {
	Pass Pass
	Desc string
}

type PhiElim

type PhiElim struct{}

PhiElim replaces Phi nodes that are essentially copies with actual copy operaions.

func (PhiElim) Apply

func (PhiElim) Apply(cfg *CFG)

type Reg

type Reg uint64
const (
	Rz Reg = (0 << _B_ptr) | (_K_zero << _B_kind)
	Pn Reg = (1 << _B_ptr) | (_K_zero << _B_kind)
)
const (
	Tr Reg = (0 << _B_ptr) | (_K_temp << _B_kind)
	Pr Reg = (1 << _B_ptr) | (_K_temp << _B_kind)
)

func Rv

func Rv(reg hir.Register) Reg

func (Reg) Index

func (self Reg) Index() int

func (Reg) Ptr

func (self Reg) Ptr() bool

func (Reg) String

func (self Reg) String() string

type TDCE

type TDCE struct{}

TDCE removes trivial dead-code such as unused register definations from CFG.

func (TDCE) Apply

func (TDCE) Apply(cfg *CFG)

type WriteBarrier

type WriteBarrier struct{}

WriteBarrier inserts memory write barrier for pointer stores.

func (WriteBarrier) Apply

func (self WriteBarrier) Apply(cfg *CFG)

Jump to

Keyboard shortcuts

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