]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add ability to indicate 'concurrentOk' for debug flags
authorDavid Chase <drchase@google.com>
Wed, 26 Oct 2022 03:01:44 +0000 (23:01 -0400)
committerDavid Chase <drchase@google.com>
Mon, 31 Oct 2022 22:19:34 +0000 (22:19 +0000)
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 <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: David Chase <drchase@google.com>

src/cmd/compile/internal/base/debug.go
src/cmd/compile/internal/base/flag.go
src/cmd/internal/objabi/flag.go

index ba2149175db55570dc9b47956e02c13ca231b230..9bd6dce403a4a3fb61cbdf949fb4bfe1e3345f3e 100644 (file)
@@ -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.
index e6df6b680bc75cd438a6d9082de8d580565a8a46..020514556c19c6f566531255bdfbdffd7b47f707 100644 (file)
@@ -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.
index 858976e645d7ea4342af95ebff001371e717f8af..847ed48cfb3054a24ff2f5f2ecdceba7e3ee4691 100644 (file)
@@ -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)
                }