mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.regabi] cmd/compile: separate ssa from other phases
isIntrinsicCall and ssaDumpInline are the only two "forward references" to ssa by earlier phases. Make them a bit more explicit so that the uses and the definitions can end up in different packages. Change-Id: I02c7a27464fbedef9fee43c0e4094fa08b4d7a5c Reviewed-on: https://go-review.googlesource.com/c/go/+/279300 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>
This commit is contained in:
parent
4836e28ac0
commit
e999c17022
5 changed files with 28 additions and 14 deletions
|
|
@ -39,6 +39,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IsIntrinsicCall reports whether the compiler back end will treat the call as an intrinsic operation.
|
||||||
|
var IsIntrinsicCall = func(*ir.CallExpr) bool { return false }
|
||||||
|
|
||||||
// Inlining budget parameters, gathered in one place
|
// Inlining budget parameters, gathered in one place
|
||||||
const (
|
const (
|
||||||
inlineMaxBudget = 80
|
inlineMaxBudget = 80
|
||||||
|
|
@ -339,7 +342,7 @@ func (v *hairyVisitor) doNode(n ir.Node) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if isIntrinsicCall(n) {
|
if IsIntrinsicCall(n) {
|
||||||
// Treat like any other node.
|
// Treat like any other node.
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -593,7 +596,7 @@ func inlnode(n ir.Node, maxCost int32, inlMap map[*ir.Func]bool, edit func(ir.No
|
||||||
if base.Flag.LowerM > 3 {
|
if base.Flag.LowerM > 3 {
|
||||||
fmt.Printf("%v:call to func %+v\n", ir.Line(n), call.Left())
|
fmt.Printf("%v:call to func %+v\n", ir.Line(n), call.Left())
|
||||||
}
|
}
|
||||||
if isIntrinsicCall(call) {
|
if IsIntrinsicCall(call) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if fn := inlCallee(call.Left()); fn != nil && fn.Inl != nil {
|
if fn := inlCallee(call.Left()); fn != nil && fn.Inl != nil {
|
||||||
|
|
@ -768,6 +771,10 @@ func inlParam(t *types.Field, as ir.Node, inlvars map[*ir.Name]ir.Node) ir.Node
|
||||||
|
|
||||||
var inlgen int
|
var inlgen int
|
||||||
|
|
||||||
|
// SSADumpInline gives the SSA back end a chance to dump the function
|
||||||
|
// when producing output for debugging the compiler itself.
|
||||||
|
var SSADumpInline = func(*ir.Func) {}
|
||||||
|
|
||||||
// If n is a call node (OCALLFUNC or OCALLMETH), and fn is an ONAME node for a
|
// If n is a call node (OCALLFUNC or OCALLMETH), and fn is an ONAME node for a
|
||||||
// function with an inlinable body, return an OINLCALL node that can replace n.
|
// function with an inlinable body, return an OINLCALL node that can replace n.
|
||||||
// The returned node's Ninit has the parameter assignments, the Nbody is the
|
// The returned node's Ninit has the parameter assignments, the Nbody is the
|
||||||
|
|
@ -835,9 +842,7 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
|
||||||
fmt.Printf("%v: Before inlining: %+v\n", ir.Line(n), n)
|
fmt.Printf("%v: Before inlining: %+v\n", ir.Line(n), n)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ssaDump != "" && ssaDump == ir.FuncName(Curfn) {
|
SSADumpInline(fn)
|
||||||
ssaDumpInlined = append(ssaDumpInlined, fn)
|
|
||||||
}
|
|
||||||
|
|
||||||
ninit := n.Init()
|
ninit := n.Init()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,9 @@ func Main(archInit func(*Arch)) {
|
||||||
logopt.LogJsonOption(base.Flag.JSON)
|
logopt.LogJsonOption(base.Flag.JSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IsIntrinsicCall = isIntrinsicCall
|
||||||
|
SSADumpInline = ssaDumpInline
|
||||||
|
|
||||||
ssaDump = os.Getenv("GOSSAFUNC")
|
ssaDump = os.Getenv("GOSSAFUNC")
|
||||||
ssaDir = os.Getenv("GOSSADIR")
|
ssaDir = os.Getenv("GOSSADIR")
|
||||||
if ssaDump != "" {
|
if ssaDump != "" {
|
||||||
|
|
|
||||||
|
|
@ -1233,10 +1233,10 @@ func (lv *Liveness) emit() (argsSym, liveSym *obj.LSym) {
|
||||||
// pointer variables in the function and emits a runtime data
|
// pointer variables in the function and emits a runtime data
|
||||||
// structure read by the garbage collector.
|
// structure read by the garbage collector.
|
||||||
// Returns a map from GC safe points to their corresponding stack map index.
|
// Returns a map from GC safe points to their corresponding stack map index.
|
||||||
func liveness(e *ssafn, f *ssa.Func, pp *Progs) LivenessMap {
|
func liveness(curfn *ir.Func, f *ssa.Func, stkptrsize int64, pp *Progs) LivenessMap {
|
||||||
// Construct the global liveness state.
|
// Construct the global liveness state.
|
||||||
vars, idx := getvariables(e.curfn)
|
vars, idx := getvariables(curfn)
|
||||||
lv := newliveness(e.curfn, f, vars, idx, e.stkptrsize)
|
lv := newliveness(curfn, f, vars, idx, stkptrsize)
|
||||||
|
|
||||||
// Run the dataflow framework.
|
// Run the dataflow framework.
|
||||||
lv.prologue()
|
lv.prologue()
|
||||||
|
|
@ -1271,7 +1271,7 @@ func liveness(e *ssafn, f *ssa.Func, pp *Progs) LivenessMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit the live pointer map data structures
|
// Emit the live pointer map data structures
|
||||||
ls := e.curfn.LSym
|
ls := curfn.LSym
|
||||||
fninfo := ls.Func()
|
fninfo := ls.Func()
|
||||||
fninfo.GCArgs, fninfo.GCLocals = lv.emit()
|
fninfo.GCArgs, fninfo.GCLocals = lv.emit()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,12 @@ const maxOpenDefers = 8
|
||||||
// ssaDumpInlined holds all inlined functions when ssaDump contains a function name.
|
// ssaDumpInlined holds all inlined functions when ssaDump contains a function name.
|
||||||
var ssaDumpInlined []*ir.Func
|
var ssaDumpInlined []*ir.Func
|
||||||
|
|
||||||
|
func ssaDumpInline(fn *ir.Func) {
|
||||||
|
if ssaDump != "" && ssaDump == ir.FuncName(fn) {
|
||||||
|
ssaDumpInlined = append(ssaDumpInlined, fn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func initssaconfig() {
|
func initssaconfig() {
|
||||||
types_ := ssa.NewTypes()
|
types_ := ssa.NewTypes()
|
||||||
|
|
||||||
|
|
@ -1135,7 +1141,7 @@ func (s *state) stmt(n ir.Node) {
|
||||||
// Expression statements
|
// Expression statements
|
||||||
case ir.OCALLFUNC:
|
case ir.OCALLFUNC:
|
||||||
n := n.(*ir.CallExpr)
|
n := n.(*ir.CallExpr)
|
||||||
if isIntrinsicCall(n) {
|
if IsIntrinsicCall(n) {
|
||||||
s.intrinsicCall(n)
|
s.intrinsicCall(n)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -1204,7 +1210,7 @@ func (s *state) stmt(n ir.Node) {
|
||||||
case ir.OAS2FUNC:
|
case ir.OAS2FUNC:
|
||||||
// We come here only when it is an intrinsic call returning two values.
|
// We come here only when it is an intrinsic call returning two values.
|
||||||
call := n.Rlist().First().(*ir.CallExpr)
|
call := n.Rlist().First().(*ir.CallExpr)
|
||||||
if !isIntrinsicCall(call) {
|
if !IsIntrinsicCall(call) {
|
||||||
s.Fatalf("non-intrinsic AS2FUNC not expanded %v", call)
|
s.Fatalf("non-intrinsic AS2FUNC not expanded %v", call)
|
||||||
}
|
}
|
||||||
v := s.intrinsicCall(call)
|
v := s.intrinsicCall(call)
|
||||||
|
|
@ -2826,7 +2832,7 @@ func (s *state) expr(n ir.Node) *ssa.Value {
|
||||||
|
|
||||||
case ir.OCALLFUNC:
|
case ir.OCALLFUNC:
|
||||||
n := n.(*ir.CallExpr)
|
n := n.(*ir.CallExpr)
|
||||||
if isIntrinsicCall(n) {
|
if IsIntrinsicCall(n) {
|
||||||
return s.intrinsicCall(n)
|
return s.intrinsicCall(n)
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
@ -6375,7 +6381,7 @@ func genssa(f *ssa.Func, pp *Progs) {
|
||||||
|
|
||||||
e := f.Frontend().(*ssafn)
|
e := f.Frontend().(*ssafn)
|
||||||
|
|
||||||
s.livenessMap = liveness(e, f, pp)
|
s.livenessMap = liveness(e.curfn, f, e.stkptrsize, pp)
|
||||||
emitStackObjects(e, pp)
|
emitStackObjects(e, pp)
|
||||||
|
|
||||||
openDeferInfo := e.curfn.LSym.Func().OpenCodedDeferInfo
|
openDeferInfo := e.curfn.LSym.Func().OpenCodedDeferInfo
|
||||||
|
|
|
||||||
|
|
@ -769,7 +769,7 @@ func walkexpr1(n ir.Node, init *ir.Nodes) ir.Node {
|
||||||
walkexprlistsafe(n.List().Slice(), init)
|
walkexprlistsafe(n.List().Slice(), init)
|
||||||
r = walkexpr(r, init)
|
r = walkexpr(r, init)
|
||||||
|
|
||||||
if isIntrinsicCall(r.(*ir.CallExpr)) {
|
if IsIntrinsicCall(r.(*ir.CallExpr)) {
|
||||||
n.PtrRlist().Set1(r)
|
n.PtrRlist().Set1(r)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue