main

Imports

Imports #

"strings"
"bytes"
"flag"
"fmt"
"go/format"
"log"
"math/bits"
"os"
"path"
"regexp"
"runtime"
"runtime/pprof"
"runtime/trace"
"slices"
"sort"
"strings"
"sync"
"strings"
"strings"
"strings"
"bytes"
"fmt"
"go/format"
"io"
"log"
"os"
"strings"
"strings"
"bufio"
"bytes"
"flag"
"fmt"
"go/ast"
"go/format"
"go/parser"
"go/printer"
"go/token"
"io"
"log"
"os"
"path"
"regexp"
"sort"
"strconv"
"strings"
"golang.org/x/tools/go/ast/astutil"
"strings"
"strings"
"fmt"
"strings"
"strings"

Constants & Variables

addLine var #

var addLine = *ast.CallExpr

archs var #

var archs []arch

cpuprofile var #

var cpuprofile = *ast.CallExpr

dec64Blocks var #

var dec64Blocks = []blockData{...}

dec64Ops var #

var dec64Ops = []opData{...}

decBlocks var #

var decBlocks = []blockData{...}

decOps var #

var decOps = []opData{...}

emptyFset var #

var emptyFset = *ast.CallExpr

findAllOpcode var #

findAllOpcode is a function to find the opcode portion of s-expressions.

var findAllOpcode = *ast.CallExpr.FindAllStringIndex

genLog var #

var genLog = *ast.CallExpr

genericBlocks var #

var genericBlocks = []blockData{...}

genericOps var #

var genericOps = []opData{...}

memprofile var #

var memprofile = *ast.CallExpr

predeclared var #

predeclared contains globally known tokens that should not be redefined.

var predeclared = map[string]bool{...}

printConfig var #

var printConfig = printer.Config{...}

regNames386 var #

copied from ../../x86/reg.go

var regNames386 = []string{...}

regNamesAMD64 var #

copied from ../../amd64/reg.go

var regNamesAMD64 = []string{...}

regNamesARM var #

var regNamesARM = []string{...}

regNamesARM64 var #

Note: registers not used in regalloc are not included in this list, so that regmask stays within int64 Be careful when hand coding regmasks.

var regNamesARM64 = []string{...}

regNamesLOONG64 var #

Note: registers not used in regalloc are not included in this list, so that regmask stays within int64 Be careful when hand coding regmasks.

var regNamesLOONG64 = []string{...}

regNamesMIPS var #

Note: registers not used in regalloc are not included in this list, so that regmask stays within int64 Be careful when hand coding regmasks.

var regNamesMIPS = []string{...}

regNamesMIPS64 var #

Note: registers not used in regalloc are not included in this list, so that regmask stays within int64 Be careful when hand coding regmasks.

var regNamesMIPS64 = []string{...}

regNamesPPC64 var #

var regNamesPPC64 = []string{...}

regNamesS390X var #

copied from ../../s390x/reg.go

var regNamesS390X = []string{...}

regNamesWasm var #

var regNamesWasm = []string{...}

reservedNames var #

var reservedNames = map[string]bool{...}

riscv64REG_CTXT const #

const riscv64REG_CTXT = 26

riscv64REG_G const #

const riscv64REG_G = 27

riscv64REG_GP const #

const riscv64REG_GP = 3

riscv64REG_LR const #

const riscv64REG_LR = 1

riscv64REG_SP const #

const riscv64REG_SP = 2

riscv64REG_TMP const #

const riscv64REG_TMP = 31

riscv64REG_TP const #

const riscv64REG_TP = 4

riscv64REG_ZERO const #

const riscv64REG_ZERO = 0

tracefile var #

var tracefile = *ast.CallExpr

Type Aliases

byKey type #

type byKey []intPair

regMask type #

type regMask uint64

Interfaces

Node interface #

Node can be a Statement or an ast.Expr.

type Node interface {

}

Statement interface #

Statement can be one of our high-level statement struct types, or an ast.Stmt under some limited circumstances.

type Statement interface {

}

Structs

BodyBase struct #

BodyBase is shared by all of our statement pseudo-node types which can contain other statements.

type BodyBase struct {
List []Statement
CanFail bool
}

Case struct #

These types define some high-level statement struct types, which can be used as a Statement. This allows us to keep some node structs simpler, and have higher-level nodes such as an entire rule rewrite. Note that ast.Expr is always used as-is; we don't declare our own expression nodes.

type Case struct {
BodyBase
Expr ast.Expr
}

CondBreak struct #

These types define some high-level statement struct types, which can be used as a Statement. This allows us to keep some node structs simpler, and have higher-level nodes such as an entire rule rewrite. Note that ast.Expr is always used as-is; we don't declare our own expression nodes.

type CondBreak struct {
Cond ast.Expr
InsideCommuteLoop bool
}

Declare struct #

These types define some high-level statement struct types, which can be used as a Statement. This allows us to keep some node structs simpler, and have higher-level nodes such as an entire rule rewrite. Note that ast.Expr is always used as-is; we don't declare our own expression nodes.

type Declare struct {
Name string
Value ast.Expr
}

File struct #

These types define some high-level statement struct types, which can be used as a Statement. This allows us to keep some node structs simpler, and have higher-level nodes such as an entire rule rewrite. Note that ast.Expr is always used as-is; we don't declare our own expression nodes.

type File struct {
BodyBase
Arch arch
Suffix string
}

Func struct #

These types define some high-level statement struct types, which can be used as a Statement. This allows us to keep some node structs simpler, and have higher-level nodes such as an entire rule rewrite. Note that ast.Expr is always used as-is; we don't declare our own expression nodes.

type Func struct {
BodyBase
Kind string
Suffix string
ArgLen int32
}

Rule struct #

type Rule struct {
Rule string
Loc string
}

RuleRewrite struct #

These types define some high-level statement struct types, which can be used as a Statement. This allows us to keep some node structs simpler, and have higher-level nodes such as an entire rule rewrite. Note that ast.Expr is always used as-is; we don't declare our own expression nodes.

type RuleRewrite struct {
BodyBase
Match string
Cond string
Result string
Check string
Alloc int
Loc string
CommuteDepth int
}

StartCommuteLoop struct #

These types define some high-level statement struct types, which can be used as a Statement. This allows us to keep some node structs simpler, and have higher-level nodes such as an entire rule rewrite. Note that ast.Expr is always used as-is; we don't declare our own expression nodes.

type StartCommuteLoop struct {
Depth int
V string
}

Switch struct #

These types define some high-level statement struct types, which can be used as a Statement. This allows us to keep some node structs simpler, and have higher-level nodes such as an entire rule rewrite. Note that ast.Expr is always used as-is; we don't declare our own expression nodes.

type Switch struct {
BodyBase
Expr ast.Expr
}

allocator struct #

type allocator struct {
name string
typ string
mak string
capacity string
resize string
clear string
minLog int
maxLog int
}

arch struct #

type arch struct {
name string
pkg string
genfile string
ops []opData
blocks []blockData
regnames []string
ParamIntRegNames string
ParamFloatRegNames string
gpregmask regMask
fpregmask regMask
fp32regmask regMask
fp64regmask regMask
specialregmask regMask
framepointerreg int8
linkreg int8
generic bool
imports []string
}

blockData struct #

type blockData struct {
name string
controls int
aux string
}

derived struct #

type derived struct {
name string
typ string
base string
}

intPair struct #

for sorting a pair of integers by key

type intPair struct {
key int
val int
}

object struct #

object keeps track of a declared name, such as a variable or import.

type object struct {
name string
pos token.Pos
numUses int
used []*object
}

opData struct #

type opData struct {
name string
reg regInfo
asm string
typ string
aux string
rematerializeable bool
argLength int32
commutative bool
resultInArg0 bool
resultNotInArgs bool
clobberFlags bool
needIntTemp bool
call bool
tailCall bool
nilCheck bool
faultOnNilArg0 bool
faultOnNilArg1 bool
hasSideEffects bool
zeroWidth bool
unsafePoint bool
symEffect string
scale uint8
}

regInfo struct #

type regInfo struct {
inputs []regMask
clobbers regMask
outputs []regMask
}

scope struct #

scope keeps track of a certain scope and its declared names, as well as the outer (parent) scope.

type scope struct {
outer *scope
objects map[string]*object
}

unusedInspector struct #

unusedInspector can be used to detect unused variables and imports in an ast.Node via its node method. The result is available in the "unused" map. note that unusedInspector is lazy and best-effort; it only supports the node types and patterns used by the rulegen program.

type unusedInspector struct {
scope *scope
unused map[token.Pos]bool
defining *object
}

Functions

Len method #

func (a byKey) Len() int

Less method #

func (a byKey) Less(i int, j int) bool

Lookup method #

func (s *scope) Lookup(name string) *object

Name method #

Name returns the name of the architecture for use in Op* and Block* enumerations.

func (a arch) Name() string

String method #

func (r Rule) String() string

Swap method #

func (a byKey) Swap(i int, j int)

add method #

func (w *BodyBase) add(node Statement)

auxIntType method #

auxIntType returns the Go type that this operation should store in its auxInt field.

func (op opData) auxIntType() string

auxIntType method #

auxIntType returns the Go type that this block should store in its auxInt field.

func (b blockData) auxIntType() string

auxType method #

auxType returns the Go type that this operation should store in its aux field.

func (op opData) auxType() string

auxType method #

auxType returns the Go type that this block should store in its aux field.

func (b blockData) auxType() string

balance function #

balance returns the number of unclosed '(' characters in s. If a ')' appears without a corresponding '(', balance returns -1.

func balance(s string) int

breakf function #

breakf constructs a simple "if cond { break }" statement, using exprf for its condition.

func breakf(format string, a ...interface{}) *CondBreak

checkEllipsisRuleCandidate function #

func checkEllipsisRuleCandidate(rule Rule, arch arch)

countRegs function #

countRegs returns the number of set bits in the register mask.

func countRegs(r regMask) int

declReserved function #

declReserved is like declf, but the name must be one of reservedNames. Calls to declReserved should generally be static and top-level.

func declReserved(name string, value string) *Declare

declared method #

declared reports if the body contains a Declare with the given name.

func (w *BodyBase) declared(name string) bool

declf function #

declf constructs a simple "name := value" declaration, using exprf for its value. name must not be one of reservedNames. This helps prevent unintended shadowing and name clashes. To declare a reserved name, use declReserved.

func declf(loc string, name string, format string, a ...interface{}) *Declare

excludeFromExpansion function #

excludeFromExpansion reports whether the substring s[idx[0]:idx[1]] in a rule should be disregarded as a candidate for | expansion. It uses simple syntactic checks to see whether the substring is inside an AuxInt expression or inside the && conditions.

func excludeFromExpansion(s string, idx []int) bool

expandOr function #

expandOr converts a rule into multiple rules by expanding | ops.

func expandOr(r string) []string

exprf function #

exprf parses a Go expression generated from fmt.Sprintf, panicking if an error occurs.

func exprf(format string, a ...interface{}) ast.Expr

exprs method #

func (u *unusedInspector) exprs(list []ast.Expr)

extract function #

func extract(val string) (op string, typ string, auxint string, aux string, args []string)

fprint function #

func fprint(w io.Writer, n Node)

genAllocator function #

func genAllocator(w io.Writer, a allocator)

genAllocators function #

func genAllocators()

genBlockRewrite function #

func genBlockRewrite(rule Rule, arch arch, data blockData) *RuleRewrite

genDerived function #

func genDerived(w io.Writer, d derived, base allocator)

genLateLowerRules function #

func genLateLowerRules(arch arch)

genMatch function #

genMatch returns the variable whose source position should be used for the result (or "" if no opinion), and a boolean that reports whether the match can fail.

func genMatch(rr *RuleRewrite, arch arch, match string, pregenTop bool) (pos string, checkOp string)

genMatch0 function #

func genMatch0(rr *RuleRewrite, arch arch, match string, v string, cnt map[string]int, pregenTop bool) (pos string, checkOp string)

genOp function #

func genOp()

genResult function #

func genResult(rr *RuleRewrite, arch arch, result string, pos string)

genResult0 function #

func genResult0(rr *RuleRewrite, arch arch, result string, top bool, move bool, pos string, cse map[string]string) string

genRules function #

func genRules(arch arch)

genRulesSuffix function #

func genRulesSuffix(arch arch, suff string)

genSplitLoadRules function #

func genSplitLoadRules(arch arch)

getBlockInfo function #

func getBlockInfo(op string, arch arch) (name string, data blockData)

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

init function #

func init()

isBlock function #

isBlock reports whether this op is a block opcode.

func isBlock(name string, arch arch) bool

isEllipsisValue function #

isEllipsisValue reports whether s is of the form (OpX ...).

func isEllipsisValue(s string) bool

main function #

func main()

node method #

func (u *unusedInspector) node(node ast.Node)

normalizeMatch function #

func normalizeMatch(m string, arch arch) string

normalizeSpaces function #

func normalizeSpaces(s string) string

normalizeWhitespace function #

normalizeWhitespace replaces 2+ whitespace sequences with a single space.

func normalizeWhitespace(x string) string

opByName function #

func opByName(arch arch, name string) opData

opHasAux function #

func opHasAux(op opData) bool

opHasAuxInt function #

func opHasAuxInt(op opData) bool

opIsCommutative function #

opIsCommutative reports whether op s is commutative.

func opIsCommutative(op string, arch arch) bool

parse method #

parse returns the matching part of the rule, additional conditions, and the result.

func (r Rule) parse() (match string, cond string, result string)

parseEllipsisRules function #

func parseEllipsisRules(rules []Rule, arch arch) (newop string, ok bool)

parseValue function #

parseValue parses a parenthesized value from a rule. The value can be from the match or the result side. It returns the op and unparsed strings for typ, auxint, and aux restrictions and for all args. oparch is the architecture that op is located in, or "" for generic.

func parseValue(val string, arch arch, loc string) (op opData, oparch string, typ string, auxint string, aux string, args []string)

regMaskComment method #

func (a arch) regMaskComment(r regMask) string

riscv64RegName function #

func riscv64RegName(r int) string

scoped method #

scoped opens a new scope when called, and returns a function which closes that same scope. When a scope is closed, unused variables are recorded.

func (u *unusedInspector) scoped() func()

split function #

func split(s string) []string

splitNameExpr function #

splitNameExpr splits s-expr arg, possibly prefixed by "name:", into name and the unprefixed expression. For example, "x:(Foo)" yields "x", "(Foo)", and "(Foo)" yields "", "(Foo)".

func splitNameExpr(arg string) (name string, expr string)

stmtf function #

stmtf parses a Go statement generated from fmt.Sprintf. This function is only meant for simple statements that don't have a custom Statement node declared in this package, such as ast.ReturnStmt or ast.ExprStmt.

func stmtf(format string, a ...interface{}) Statement

title function #

func title(s string) string

typeName function #

typeName returns the string to use to generate a type.

func typeName(typ string) string

unTitle function #

func unTitle(s string) string

varCount function #

varCount returns a map which counts the number of occurrences of Value variables in the s-expression rr.Match and the Go expression rr.Cond.

func varCount(rr *RuleRewrite) map[string]int

varCount1 function #

func varCount1(loc string, m string, cnt map[string]int)

Generated with Arrow