From c81c0279827545b20f81797bb263ae696d9c235f Mon Sep 17 00:00:00 2001 From: David Chase Date: Tue, 25 Oct 2022 23:01:44 -0400 Subject: [PATCH] cmd/compile: add ability to indicate 'concurrentOk' for debug flags Also removes no-longer-needed "Any" field from compiler's DebugFlags. Test/use case for this is the fmahash CL. Change-Id: I214f02c91f30fc2ce53caf75fa5e2b905dd33429 Reviewed-on: https://go-review.googlesource.com/c/go/+/445495 TryBot-Result: Gopher Robot Reviewed-by: Keith Randall Reviewed-by: Keith Randall Run-TryBot: David Chase --- src/cmd/compile/internal/base/debug.go | 2 +- src/cmd/compile/internal/base/flag.go | 3 ++- src/cmd/internal/objabi/flag.go | 36 ++++++++++++++++---------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/cmd/compile/internal/base/debug.go b/src/cmd/compile/internal/base/debug.go index ba2149175d..9bd6dce403 100644 --- a/src/cmd/compile/internal/base/debug.go +++ b/src/cmd/compile/internal/base/debug.go @@ -50,7 +50,7 @@ type DebugFlags struct { InlineHotBudget int `help:"inline budget for hot functions"` PGOInline int `help:"debug profile-guided inlining"` - Any bool // set when any of the debug flags have been set + ConcurrentOk bool // true if only concurrentOk flags seen } // DebugSSA is called to set a -d ssa/... option. diff --git a/src/cmd/compile/internal/base/flag.go b/src/cmd/compile/internal/base/flag.go index e6df6b680b..020514556c 100644 --- a/src/cmd/compile/internal/base/flag.go +++ b/src/cmd/compile/internal/base/flag.go @@ -165,6 +165,7 @@ func ParseFlags() { Flag.Shared = &Ctxt.Flag_shared Flag.WB = true + Debug.ConcurrentOk = true Debug.InlFuncsWithClosures = 1 if buildcfg.Experiment.Unified { Debug.Unified = 1 @@ -373,7 +374,7 @@ func concurrentBackendAllowed() bool { // while writing the object file, and that is non-concurrent. // Adding Debug_vlog, however, causes Debug.S to also print // while flushing the plist, which happens concurrently. - if Ctxt.Debugvlog || Debug.Any || Flag.Live > 0 { + if Ctxt.Debugvlog || !Debug.ConcurrentOk || Flag.Live > 0 { return false } // TODO: Test and delete this condition. diff --git a/src/cmd/internal/objabi/flag.go b/src/cmd/internal/objabi/flag.go index 858976e645..847ed48cfb 100644 --- a/src/cmd/internal/objabi/flag.go +++ b/src/cmd/internal/objabi/flag.go @@ -203,16 +203,16 @@ func DecodeArg(arg string) string { } type debugField struct { - name string - help string - val interface{} // *int or *string + name string + help string + concurrentOk bool // true if this field/flag is compatible with concurrent compilation + val interface{} // *int or *string } type DebugFlag struct { - tab map[string]debugField - any *bool - - debugSSA DebugSSA + tab map[string]debugField + concurrentOk *bool // this is non-nil only for compiler's DebugFlags, but only compiler has concurrent:ok fields + debugSSA DebugSSA // this is non-nil only for compiler's DebugFlags. } // A DebugSSA function is called to set a -d ssa/... option. @@ -244,12 +244,12 @@ func NewDebugFlag(debug interface{}, debugSSA DebugSSA) *DebugFlag { for i := 0; i < t.NumField(); i++ { f := t.Field(i) ptr := v.Field(i).Addr().Interface() - if f.Name == "Any" { + if f.Name == "ConcurrentOk" { switch ptr := ptr.(type) { default: - panic("debug.Any must have type bool") + panic("debug.ConcurrentOk must have type bool") case *bool: - flag.any = ptr + flag.concurrentOk = ptr } continue } @@ -258,13 +258,15 @@ func NewDebugFlag(debug interface{}, debugSSA DebugSSA) *DebugFlag { if help == "" { panic(fmt.Sprintf("debug.%s is missing help text", f.Name)) } + concurrent := f.Tag.Get("concurrent") + switch ptr.(type) { default: panic(fmt.Sprintf("debug.%s has invalid type %v (must be int or string)", f.Name, f.Type)) case *int, *string: // ok } - flag.tab[name] = debugField{name, help, ptr} + flag.tab[name] = debugField{name, help, concurrent == "ok", ptr} } return flag @@ -274,9 +276,6 @@ func (f *DebugFlag) Set(debugstr string) error { if debugstr == "" { return nil } - if f.any != nil { - *f.any = true - } for _, name := range strings.Split(debugstr, ",") { if name == "" { continue @@ -332,6 +331,10 @@ func (f *DebugFlag) Set(debugstr string) error { default: panic("bad debugtab type") } + // assembler DebugFlags don't have a ConcurrentOk field to reset, so check against that. + if !t.concurrentOk && f.concurrentOk != nil { + *f.concurrentOk = false + } } else if f.debugSSA != nil && strings.HasPrefix(name, "ssa/") { // expect form ssa/phase/flag // e.g. -d=ssa/generic_cse/time @@ -346,6 +349,11 @@ func (f *DebugFlag) Set(debugstr string) error { if err != "" { log.Fatalf(err) } + // Setting this false for -d=ssa/... preserves old behavior + // of turning off concurrency for any debug flags. + // It's not known for sure if this is necessary, but it is safe. + *f.concurrentOk = false + } else { return fmt.Errorf("unknown debug key %s\n", name) } -- 2.50.0