Skip to content

Commit c81c027

Browse files
committed
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 <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Run-TryBot: David Chase <[email protected]>
1 parent 5619dd0 commit c81c027

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type DebugFlags struct {
5050
InlineHotBudget int `help:"inline budget for hot functions"`
5151
PGOInline int `help:"debug profile-guided inlining"`
5252

53-
Any bool // set when any of the debug flags have been set
53+
ConcurrentOk bool // true if only concurrentOk flags seen
5454
}
5555

5656
// DebugSSA is called to set a -d ssa/... option.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func ParseFlags() {
165165
Flag.Shared = &Ctxt.Flag_shared
166166
Flag.WB = true
167167

168+
Debug.ConcurrentOk = true
168169
Debug.InlFuncsWithClosures = 1
169170
if buildcfg.Experiment.Unified {
170171
Debug.Unified = 1
@@ -373,7 +374,7 @@ func concurrentBackendAllowed() bool {
373374
// while writing the object file, and that is non-concurrent.
374375
// Adding Debug_vlog, however, causes Debug.S to also print
375376
// while flushing the plist, which happens concurrently.
376-
if Ctxt.Debugvlog || Debug.Any || Flag.Live > 0 {
377+
if Ctxt.Debugvlog || !Debug.ConcurrentOk || Flag.Live > 0 {
377378
return false
378379
}
379380
// TODO: Test and delete this condition.

src/cmd/internal/objabi/flag.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,16 @@ func DecodeArg(arg string) string {
203203
}
204204

205205
type debugField struct {
206-
name string
207-
help string
208-
val interface{} // *int or *string
206+
name string
207+
help string
208+
concurrentOk bool // true if this field/flag is compatible with concurrent compilation
209+
val interface{} // *int or *string
209210
}
210211

211212
type DebugFlag struct {
212-
tab map[string]debugField
213-
any *bool
214-
215-
debugSSA DebugSSA
213+
tab map[string]debugField
214+
concurrentOk *bool // this is non-nil only for compiler's DebugFlags, but only compiler has concurrent:ok fields
215+
debugSSA DebugSSA // this is non-nil only for compiler's DebugFlags.
216216
}
217217

218218
// A DebugSSA function is called to set a -d ssa/... option.
@@ -244,12 +244,12 @@ func NewDebugFlag(debug interface{}, debugSSA DebugSSA) *DebugFlag {
244244
for i := 0; i < t.NumField(); i++ {
245245
f := t.Field(i)
246246
ptr := v.Field(i).Addr().Interface()
247-
if f.Name == "Any" {
247+
if f.Name == "ConcurrentOk" {
248248
switch ptr := ptr.(type) {
249249
default:
250-
panic("debug.Any must have type bool")
250+
panic("debug.ConcurrentOk must have type bool")
251251
case *bool:
252-
flag.any = ptr
252+
flag.concurrentOk = ptr
253253
}
254254
continue
255255
}
@@ -258,13 +258,15 @@ func NewDebugFlag(debug interface{}, debugSSA DebugSSA) *DebugFlag {
258258
if help == "" {
259259
panic(fmt.Sprintf("debug.%s is missing help text", f.Name))
260260
}
261+
concurrent := f.Tag.Get("concurrent")
262+
261263
switch ptr.(type) {
262264
default:
263265
panic(fmt.Sprintf("debug.%s has invalid type %v (must be int or string)", f.Name, f.Type))
264266
case *int, *string:
265267
// ok
266268
}
267-
flag.tab[name] = debugField{name, help, ptr}
269+
flag.tab[name] = debugField{name, help, concurrent == "ok", ptr}
268270
}
269271

270272
return flag
@@ -274,9 +276,6 @@ func (f *DebugFlag) Set(debugstr string) error {
274276
if debugstr == "" {
275277
return nil
276278
}
277-
if f.any != nil {
278-
*f.any = true
279-
}
280279
for _, name := range strings.Split(debugstr, ",") {
281280
if name == "" {
282281
continue
@@ -332,6 +331,10 @@ func (f *DebugFlag) Set(debugstr string) error {
332331
default:
333332
panic("bad debugtab type")
334333
}
334+
// assembler DebugFlags don't have a ConcurrentOk field to reset, so check against that.
335+
if !t.concurrentOk && f.concurrentOk != nil {
336+
*f.concurrentOk = false
337+
}
335338
} else if f.debugSSA != nil && strings.HasPrefix(name, "ssa/") {
336339
// expect form ssa/phase/flag
337340
// e.g. -d=ssa/generic_cse/time
@@ -346,6 +349,11 @@ func (f *DebugFlag) Set(debugstr string) error {
346349
if err != "" {
347350
log.Fatalf(err)
348351
}
352+
// Setting this false for -d=ssa/... preserves old behavior
353+
// of turning off concurrency for any debug flags.
354+
// It's not known for sure if this is necessary, but it is safe.
355+
*f.concurrentOk = false
356+
349357
} else {
350358
return fmt.Errorf("unknown debug key %s\n", name)
351359
}

0 commit comments

Comments
 (0)