From a9cfbec17b12166c56aeb9808b5d1b7393e90f43 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Wed, 16 Aug 2023 11:15:08 -0400 Subject: [PATCH] cmd/compile/internal/inlheur: minor debug trace changes 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 Reviewed-by: Matthew Dempsky --- .../internal/inline/inlheur/analyze.go | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/cmd/compile/internal/inline/inlheur/analyze.go b/src/cmd/compile/internal/inline/inlheur/analyze.go index 325063fed5..04d0af68d7 100644 --- a/src/cmd/compile/internal/inline/inlheur/analyze.go +++ b/src/cmd/compile/internal/inline/inlheur/analyze.go @@ -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 == "" { -- 2.50.0