]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: separate ssa from other phases
authorRuss Cox <rsc@golang.org>
Mon, 21 Dec 2020 06:44:49 +0000 (01:44 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 21 Dec 2020 19:23:31 +0000 (19:23 +0000)
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>
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/plive.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/walk.go

index 6c8f380d87318b8fd2e08ea857a7708b954d71dc..15df2584f0db5d7f7c8954ba97ca65e79a83c295 100644 (file)
@@ -39,6 +39,9 @@ import (
        "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
 const (
        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.
                        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 {
                        fmt.Printf("%v:call to func %+v\n", ir.Line(n), call.Left())
                }
-               if isIntrinsicCall(call) {
+               if IsIntrinsicCall(call) {
                        break
                }
                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
 
+// 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
 // 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
@@ -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)
        }
 
-       if ssaDump != "" && ssaDump == ir.FuncName(Curfn) {
-               ssaDumpInlined = append(ssaDumpInlined, fn)
-       }
+       SSADumpInline(fn)
 
        ninit := n.Init()
 
index 45880c5cde5dd3e2e72b41b562d6b8847efa2940..afb47cf15de9d12a8f47f0ad8a80a3b214cd86e4 100644 (file)
@@ -191,6 +191,9 @@ func Main(archInit func(*Arch)) {
                logopt.LogJsonOption(base.Flag.JSON)
        }
 
+       IsIntrinsicCall = isIntrinsicCall
+       SSADumpInline = ssaDumpInline
+
        ssaDump = os.Getenv("GOSSAFUNC")
        ssaDir = os.Getenv("GOSSADIR")
        if ssaDump != "" {
index 8e266d6599eca884257fe01b3a686533506f2299..77cd9c5b19758d4a2844767e0da7be61dfc88478 100644 (file)
@@ -1233,10 +1233,10 @@ func (lv *Liveness) emit() (argsSym, liveSym *obj.LSym) {
 // pointer variables in the function and emits a runtime data
 // structure read by the garbage collector.
 // 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.
-       vars, idx := getvariables(e.curfn)
-       lv := newliveness(e.curfn, f, vars, idx, e.stkptrsize)
+       vars, idx := getvariables(curfn)
+       lv := newliveness(curfn, f, vars, idx, stkptrsize)
 
        // Run the dataflow framework.
        lv.prologue()
@@ -1271,7 +1271,7 @@ func liveness(e *ssafn, f *ssa.Func, pp *Progs) LivenessMap {
        }
 
        // Emit the live pointer map data structures
-       ls := e.curfn.LSym
+       ls := curfn.LSym
        fninfo := ls.Func()
        fninfo.GCArgs, fninfo.GCLocals = lv.emit()
 
index fbfed0640d844a8c5dc81bed678a0d2c2e83bc2d..4f4860869caa37f8a2bb2777dfcf5de9351fc48a 100644 (file)
@@ -42,6 +42,12 @@ const maxOpenDefers = 8
 // ssaDumpInlined holds all inlined functions when ssaDump contains a function name.
 var ssaDumpInlined []*ir.Func
 
+func ssaDumpInline(fn *ir.Func) {
+       if ssaDump != "" && ssaDump == ir.FuncName(fn) {
+               ssaDumpInlined = append(ssaDumpInlined, fn)
+       }
+}
+
 func initssaconfig() {
        types_ := ssa.NewTypes()
 
@@ -1135,7 +1141,7 @@ func (s *state) stmt(n ir.Node) {
        // Expression statements
        case ir.OCALLFUNC:
                n := n.(*ir.CallExpr)
-               if isIntrinsicCall(n) {
+               if IsIntrinsicCall(n) {
                        s.intrinsicCall(n)
                        return
                }
@@ -1204,7 +1210,7 @@ func (s *state) stmt(n ir.Node) {
        case ir.OAS2FUNC:
                // We come here only when it is an intrinsic call returning two values.
                call := n.Rlist().First().(*ir.CallExpr)
-               if !isIntrinsicCall(call) {
+               if !IsIntrinsicCall(call) {
                        s.Fatalf("non-intrinsic AS2FUNC not expanded %v", call)
                }
                v := s.intrinsicCall(call)
@@ -2826,7 +2832,7 @@ func (s *state) expr(n ir.Node) *ssa.Value {
 
        case ir.OCALLFUNC:
                n := n.(*ir.CallExpr)
-               if isIntrinsicCall(n) {
+               if IsIntrinsicCall(n) {
                        return s.intrinsicCall(n)
                }
                fallthrough
@@ -6375,7 +6381,7 @@ func genssa(f *ssa.Func, pp *Progs) {
 
        e := f.Frontend().(*ssafn)
 
-       s.livenessMap = liveness(e, f, pp)
+       s.livenessMap = liveness(e.curfn, f, e.stkptrsize, pp)
        emitStackObjects(e, pp)
 
        openDeferInfo := e.curfn.LSym.Func().OpenCodedDeferInfo
index 657a744e68d46b7a7a370784d0344277891b13ce..7651bbca1052418f4988b31abc6ea43af35ef7cd 100644 (file)
@@ -769,7 +769,7 @@ func walkexpr1(n ir.Node, init *ir.Nodes) ir.Node {
                walkexprlistsafe(n.List().Slice(), init)
                r = walkexpr(r, init)
 
-               if isIntrinsicCall(r.(*ir.CallExpr)) {
+               if IsIntrinsicCall(r.(*ir.CallExpr)) {
                        n.PtrRlist().Set1(r)
                        return n
                }