Documentation ¶
Overview ¶
Package loop provides utilities for loop representation and detection.
Loop detection works by inspecting the SSA block comments to determine the state of loop, and tracks the transition between the states. Combining the state information and instructions encountered, the loop parameters (e.g. index variable, bounds, increment) are extracted if possible.
A condition graph is built from the transition between short-circuited loop conditions so to reconstruct the loop conditions.
Index ¶
- Variables
- type BinTree
- type BinTreeVisitor
- type Detector
- type Info
- func (i *Info) AddFalse(cond ssa.Value)
- func (i *Info) AddTrue(cond ssa.Value)
- func (i *Info) BodyIdx() int
- func (i *Info) DoneIdx() int
- func (i *Info) MarkTarget()
- func (i *Info) ParamsOK() bool
- func (i *Info) SetBodyBlock(index int)
- func (i *Info) SetCond(cond ssa.Value)
- func (i *Info) SetDoneBlock(index int)
- func (i *Info) SetParentCond(prevCond ssa.Value)
- func (i *Info) String() string
- type Stack
- type State
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyStack = errors.New("error: empty stack")
var ErrIdxNotInt = errors.New("index is not int")
Functions ¶
This section is empty.
Types ¶
type BinTree ¶
type BinTree struct { Cond ssa.Value True *BinTree False *BinTree Target bool // contains filtered or unexported fields }
BinTree is a binary tree for conditions.
func (*BinTree) FalseString ¶
func (*BinTree) TrueString ¶
type BinTreeVisitor ¶
type BinTreeVisitor struct {
// contains filtered or unexported fields
}
func NewBinTreeVisitor ¶
func NewBinTreeVisitor() *BinTreeVisitor
func (*BinTreeVisitor) CalcPrefix ¶
func (v *BinTreeVisitor) CalcPrefix()
CalcPrefix propagates all conditions prefix to the 'prefix' so that String() will give the string representation of the whole conditional expression.
func (*BinTreeVisitor) VisitRoot ¶
func (v *BinTreeVisitor) VisitRoot(t *BinTree)
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
func NewDetector ¶
func NewDetector() *Detector
func (*Detector) Detect ¶
func (d *Detector) Detect(from, to *ssa.BasicBlock)
func (*Detector) ExtractCond ¶
func (*Detector) ExtractIndex ¶
ExtractIndex takes a Phi inside an Enter state work out the initial value and increment.
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info is a data structure to hold loop information, for tracking condition variables, index variable.
func (*Info) MarkTarget ¶
func (i *Info) MarkTarget()
MarkTarget points a part of a loop condition to an existing subtree.
func (*Info) SetBodyBlock ¶
SetBodyBlock sets the body block index of the for-loop.
func (*Info) SetDoneBlock ¶
SetDoneBlock sets the done block index of the for-loop.
func (*Info) SetParentCond ¶
SetParentCond is for adjusting the BinTree so it points to the correct conditional subtree root.