]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/inlheur: minor debug trace changes
authorThan McIntosh <thanm@google.com>
Wed, 16 Aug 2023 15:15:08 +0000 (11:15 -0400)
committerThan McIntosh <thanm@google.com>
Fri, 15 Sep 2023 12:45:47 +0000 (12:45 +0000)
Minor changes to debug tracing and to the -d=dumpinlfuncprops
debug flag implementation.

Change-Id: Ibaefd489c94675ac7f5a04ec0331b7f888c15a49
Reviewed-on: https://go-review.googlesource.com/c/go/+/521818
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/inline/inlheur/analyze.go

index 325063fed5833a22984cf4ebdf248098e85f65c9..04d0af68d72382daa76562d330e242bb4097f8d3 100644 (file)
@@ -7,6 +7,7 @@ package inlheur
 import (
        "cmd/compile/internal/base"
        "cmd/compile/internal/ir"
+       "cmd/compile/internal/types"
        "encoding/json"
        "fmt"
        "internal/goexperiment"
@@ -150,8 +151,8 @@ func UnitTesting() bool {
 // primarily in unit testing.
 func DumpFuncProps(fn *ir.Func, dumpfile string, canInline func(*ir.Func)) {
        if fn != nil {
+               enableDebugTraceIfEnv()
                dmp := func(fn *ir.Func) {
-
                        if !goexperiment.NewInliner {
                                ScoreCalls(fn)
                        }
@@ -164,6 +165,7 @@ func DumpFuncProps(fn *ir.Func, dumpfile string, canInline func(*ir.Func)) {
                                dmp(clo.Func)
                        }
                })
+               disableDebugTrace()
        } else {
                emitDumpToFile(dumpfile)
        }
@@ -174,7 +176,18 @@ func DumpFuncProps(fn *ir.Func, dumpfile string, canInline func(*ir.Func)) {
 // definition line, and due to generics we need to account for the
 // possibility that several ir.Func's will have the same def line.
 func emitDumpToFile(dumpfile string) {
-       outf, err := os.OpenFile(dumpfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
+       mode := os.O_WRONLY | os.O_CREATE | os.O_TRUNC
+       if dumpfile[0] == '+' {
+               dumpfile = dumpfile[1:]
+               mode = os.O_WRONLY | os.O_APPEND | os.O_CREATE
+       }
+       if dumpfile[0] == '%' {
+               dumpfile = dumpfile[1:]
+               d, b := filepath.Dir(dumpfile), filepath.Base(dumpfile)
+               ptag := strings.ReplaceAll(types.LocalPkg.Path, "/", ":")
+               dumpfile = d + "/" + ptag + "." + b
+       }
+       outf, err := os.OpenFile(dumpfile, mode, 0644)
        if err != nil {
                base.Fatalf("opening function props dump file %q: %v\n", dumpfile, err)
        }
@@ -219,12 +232,9 @@ func captureFuncDumpEntry(fn *ir.Func, canInline func(*ir.Func)) {
                return
        }
        fih, ok := fpmap[fn]
-       if goexperiment.NewInliner {
-               // Props object should already be present.
-               if !ok {
-                       panic("unexpected missing props")
-               }
-       } else {
+       // Props object should already be present, unless this is a
+       // directly recursive routine.
+       if !ok {
                AnalyzeFunc(fn, canInline)
                fih = fpmap[fn]
                if fn.Inl != nil && fn.Inl.Properties == "" {