Skip to content

Commit

Permalink
[dev.regabi] cmd/compile: move helpers into package ir [generated]
Browse files Browse the repository at this point in the history
[git-generate]
cd src/cmd/compile/internal/gc
sed -i '' 's/TestBuiltin.*/& t.Skip("mkbuiltin needs fixing")/' builtin_test.go
gofmt -w builtin_test.go
rf '
	# Inline a few little-used constructors to avoid bringing them.
	ex {
		import "cmd/compile/internal/base"
		import "cmd/compile/internal/ir"
		import "cmd/compile/internal/types"
		import "cmd/internal/src"

		var typ *types.Type
		var sym *types.Sym
		var str string
		symfield(sym, typ) -> ir.NewField(base.Pos, sym, nil, typ)
		anonfield(typ) -> ir.NewField(base.Pos, nil, nil, typ)
		namedfield(str, typ) -> ir.NewField(base.Pos, lookup(str), nil, typ)

		var cp *ir.CallPartExpr
		callpartMethod(cp) -> cp.Method
		var n ir.Node
		callpartMethod(n) -> n.(*ir.CallPartExpr).Method

		var ns []ir.Node
		liststmt(ns) -> ir.NewBlockStmt(src.NoXPos, ns)
	}
	rm symfield anonfield namedfield liststmt callpartMethod

	mv maxStackVarSize MaxStackVarSize
	mv maxImplicitStackVarSize MaxImplicitStackVarSize
	mv smallArrayBytes MaxSmallArraySize
	mv MaxStackVarSize cfg.go

	mv nodbool NewBool
	mv nodintconst NewInt
	mv nodstr NewString
	mv NewBool NewInt NewString const.go

	mv Mpprec ConstPrec
	mv bigFloatVal BigFloat
	mv doesoverflow ConstOverflow
	mv isGoConst IsConstNode
	mv smallintconst IsSmallIntConst

	mv isZero IsZero
	mv islvalue IsAssignable
	mv staticValue StaticValue
	mv samesafeexpr SameSafeExpr
	mv checkPtr ShouldCheckPtr
	mv isReflectHeaderDataField IsReflectHeaderDataField
	mv paramNnames ParamNames
	mv methodSym MethodSym
	mv methodSymSuffix MethodSymSuffix
	mv methodExprFunc MethodExprFunc
	mv methodExprName MethodExprName
	mv IsZero IsAssignable StaticValue staticValue1 reassigned \
		IsIntrinsicCall \
		SameSafeExpr ShouldCheckPtr IsReflectHeaderDataField \
		ParamNames MethodSym MethodSymSuffix \
		MethodExprName MethodExprFunc \
		expr.go

	mv Curfn CurFunc
	mv funcsymname FuncSymName
	mv newFuncNameAt NewFuncNameAt
	mv setNodeNameFunc MarkFunc
	mv CurFunc FuncSymName NewFuncNameAt MarkFunc func.go

	mv isParamStackCopy IsParamStackCopy
	mv isParamHeapCopy IsParamHeapCopy
	mv nodfp RegFP
	mv IsParamStackCopy IsParamHeapCopy RegFP name.go

	mv hasUniquePos HasUniquePos
	mv setlineno SetPos
	mv initExpr InitExpr
	mv hasNamedResults HasNamedResults
	mv outervalue OuterValue
	mv HasNamedResults HasUniquePos SetPos InitExpr OuterValue EscNever node.go

	mv visitBottomUp VisitFuncsBottomUp # scc.go

	mv cfg.go \
		NewBool NewInt NewString \ # parts of const.go
		ConstPrec BigFloat ConstOverflow IsConstNode IsSmallIntConst \
		expr.go func.go name.go node.go scc.go \
		cmd/compile/internal/ir

'

Change-Id: I13402c5a2cedbf78d993a1eae2940718f23ac166
Reviewed-on: https://go-review.googlesource.com/c/go/+/279421
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
  • Loading branch information
rsc committed Dec 23, 2020
1 parent 65c4c6d commit 527a189
Show file tree
Hide file tree
Showing 38 changed files with 1,255 additions and 1,261 deletions.
52 changes: 26 additions & 26 deletions src/cmd/compile/internal/gc/alg.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ func genhash(t *types.Type) *obj.LSym {

// func sym(p *T, h uintptr) uintptr
args := []*ir.Field{
namedfield("p", types.NewPtr(t)),
namedfield("h", types.Types[types.TUINTPTR]),
ir.NewField(base.Pos, lookup("p"), nil, types.NewPtr(t)),
ir.NewField(base.Pos, lookup("h"), nil, types.Types[types.TUINTPTR]),
}
results := []*ir.Field{anonfield(types.Types[types.TUINTPTR])}
results := []*ir.Field{ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR])}
tfn := ir.NewFuncType(base.Pos, nil, args, results)

fn := dclfunc(sym, tfn)
Expand All @@ -166,9 +166,9 @@ func genhash(t *types.Type) *obj.LSym {

// for i := 0; i < nelem; i++
ni := temp(types.Types[types.TINT])
init := ir.NewAssignStmt(base.Pos, ni, nodintconst(0))
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, ni, nodintconst(t.NumElem()))
post := ir.NewAssignStmt(base.Pos, ni, ir.NewBinaryExpr(base.Pos, ir.OADD, ni, nodintconst(1)))
init := ir.NewAssignStmt(base.Pos, ni, ir.NewInt(0))
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, ni, ir.NewInt(t.NumElem()))
post := ir.NewAssignStmt(base.Pos, ni, ir.NewBinaryExpr(base.Pos, ir.OADD, ni, ir.NewInt(1)))
loop := ir.NewForStmt(base.Pos, nil, cond, post, nil)
loop.PtrInit().Append(init)

Expand Down Expand Up @@ -219,7 +219,7 @@ func genhash(t *types.Type) *obj.LSym {
na := nodAddr(nx)
call.Args.Append(na)
call.Args.Append(nh)
call.Args.Append(nodintconst(size))
call.Args.Append(ir.NewInt(size))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nh, call))

i = next
Expand All @@ -239,9 +239,9 @@ func genhash(t *types.Type) *obj.LSym {
fn.SetDupok(true)
typecheckFunc(fn)

Curfn = fn
ir.CurFunc = fn
typecheckslice(fn.Body, ctxStmt)
Curfn = nil
ir.CurFunc = nil

if base.Debug.DclStack != 0 {
types.CheckDclstack()
Expand Down Expand Up @@ -285,12 +285,12 @@ func hashfor(t *types.Type) ir.Node {
}

n := NewName(sym)
setNodeNameFunc(n)
ir.MarkFunc(n)
n.SetType(functype(nil, []*ir.Field{
anonfield(types.NewPtr(t)),
anonfield(types.Types[types.TUINTPTR]),
ir.NewField(base.Pos, nil, nil, types.NewPtr(t)),
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
}, []*ir.Field{
anonfield(types.Types[types.TUINTPTR]),
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
}))
return n
}
Expand Down Expand Up @@ -376,8 +376,8 @@ func geneq(t *types.Type) *obj.LSym {

// func sym(p, q *T) bool
tfn := ir.NewFuncType(base.Pos, nil,
[]*ir.Field{namedfield("p", types.NewPtr(t)), namedfield("q", types.NewPtr(t))},
[]*ir.Field{namedfield("r", types.Types[types.TBOOL])})
[]*ir.Field{ir.NewField(base.Pos, lookup("p"), nil, types.NewPtr(t)), ir.NewField(base.Pos, lookup("q"), nil, types.NewPtr(t))},
[]*ir.Field{ir.NewField(base.Pos, lookup("r"), nil, types.Types[types.TBOOL])})

fn := dclfunc(sym, tfn)
np := ir.AsNode(tfn.Type().Params().Field(0).Nname)
Expand Down Expand Up @@ -440,20 +440,20 @@ func geneq(t *types.Type) *obj.LSym {
// Generate a series of checks.
for i := int64(0); i < nelem; i++ {
// if check {} else { goto neq }
nif := ir.NewIfStmt(base.Pos, checkIdx(nodintconst(i)), nil, nil)
nif := ir.NewIfStmt(base.Pos, checkIdx(ir.NewInt(i)), nil, nil)
nif.Else.Append(ir.NewBranchStmt(base.Pos, ir.OGOTO, neq))
fn.Body.Append(nif)
}
if last {
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, checkIdx(nodintconst(nelem))))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, checkIdx(ir.NewInt(nelem))))
}
} else {
// Generate a for loop.
// for i := 0; i < nelem; i++
i := temp(types.Types[types.TINT])
init := ir.NewAssignStmt(base.Pos, i, nodintconst(0))
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, i, nodintconst(nelem))
post := ir.NewAssignStmt(base.Pos, i, ir.NewBinaryExpr(base.Pos, ir.OADD, i, nodintconst(1)))
init := ir.NewAssignStmt(base.Pos, i, ir.NewInt(0))
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, i, ir.NewInt(nelem))
post := ir.NewAssignStmt(base.Pos, i, ir.NewBinaryExpr(base.Pos, ir.OADD, i, ir.NewInt(1)))
loop := ir.NewForStmt(base.Pos, nil, cond, post, nil)
loop.PtrInit().Append(init)
// if eq(pi, qi) {} else { goto neq }
Expand All @@ -462,7 +462,7 @@ func geneq(t *types.Type) *obj.LSym {
loop.Body.Append(nif)
fn.Body.Append(loop)
if last {
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, nodbool(true)))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(true)))
}
}
}
Expand Down Expand Up @@ -572,7 +572,7 @@ func geneq(t *types.Type) *obj.LSym {
}

if len(flatConds) == 0 {
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, nodbool(true)))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(true)))
} else {
for _, c := range flatConds[:len(flatConds)-1] {
// if cond {} else { goto neq }
Expand All @@ -594,7 +594,7 @@ func geneq(t *types.Type) *obj.LSym {
// r = false
// return (or goto ret)
fn.Body.Append(ir.NewLabelStmt(base.Pos, neq))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, nodbool(false)))
fn.Body.Append(ir.NewAssignStmt(base.Pos, nr, ir.NewBool(false)))
if EqCanPanic(t) || anyCall(fn) {
// Epilogue is large, so share it with the equal case.
fn.Body.Append(ir.NewBranchStmt(base.Pos, ir.OGOTO, ret))
Expand All @@ -615,9 +615,9 @@ func geneq(t *types.Type) *obj.LSym {
fn.SetDupok(true)
typecheckFunc(fn)

Curfn = fn
ir.CurFunc = fn
typecheckslice(fn.Body, ctxStmt)
Curfn = nil
ir.CurFunc = nil

if base.Debug.DclStack != 0 {
types.CheckDclstack()
Expand Down Expand Up @@ -726,7 +726,7 @@ func eqmem(p ir.Node, q ir.Node, field *types.Sym, size int64) ir.Node {
call.Args.Append(nx)
call.Args.Append(ny)
if needsize {
call.Args.Append(nodintconst(size))
call.Args.Append(ir.NewInt(size))
}

return call
Expand Down
Loading

0 comments on commit 527a189

Please sign in to comment.