2020-11-16 01:17:25 -05:00
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
2020-11-16 01:44:47 -05:00
// Debug arguments, set by -d flag.
2020-11-19 20:49:23 -05:00
package base
2020-11-16 01:17:25 -05:00
2020-11-16 01:44:47 -05:00
// Debug holds the parsed debugging configuration values.
2021-03-16 17:06:25 -04:00
var Debug DebugFlags
2020-11-16 01:44:47 -05:00
// DebugFlags defines the debugging configuration values (see var Debug).
// Each struct field is a different value, named for the lower-case of the field name.
// Each field must be an int or string and must have a `help` struct tag.
//
// The -d option takes a comma-separated list of settings.
// Each setting is name=value; for ints, name is short for name=1.
type DebugFlags struct {
2024-04-02 11:12:44 -04:00
AlignHot int ` help:"enable hot block alignment (currently requires -pgo)" concurrent:"ok" `
2022-11-10 11:33:00 -05:00
Append int ` help:"print information about append compilation" `
Checkptr int ` help:"instrument unsafe pointer conversions\n0: instrumentation disabled\n1: conversions involving unsafe.Pointer are instrumented\n2: conversions to unsafe.Pointer force heap allocation" concurrent:"ok" `
Closure int ` help:"print information about closure compilation" `
Defer int ` help:"print information about defer compilation" `
DisableNil int ` help:"disable nil checks" concurrent:"ok" `
2023-06-29 15:37:26 -04:00
DumpInlFuncProps string ` help:"dump function properties from inl heuristics to specified file" `
2023-07-24 10:58:26 -04:00
DumpInlCallSiteScores int ` help:"dump scored callsites during inlining" `
2023-09-28 14:07:29 -04:00
InlScoreAdj string ` help:"set inliner score adjustments (ex: -d=inlscoreadj=panicPathAdj:10/passConstToNestedIfAdj:-90)" `
InlBudgetSlack int ` help:"amount to expand the initial inline budget when new inliner enabled. Defaults to 80 if option not set." concurrent:"ok" `
2022-11-10 11:33:00 -05:00
DumpPtrs int ` help:"show Node pointers values in dump output" `
DwarfInl int ` help:"print information about DWARF inlined function creation" `
2023-08-17 14:15:04 -07:00
EscapeMutationsCalls int ` help:"print extra escape analysis diagnostics about mutations and calls" concurrent:"ok" `
2022-11-10 11:33:00 -05:00
Export int ` help:"print export data" `
Fmahash string ` help:"hash value for use in debugging platform-dependent multiply-add use" concurrent:"ok" `
GCAdjust int ` help:"log adjustments to GOGC" concurrent:"ok" `
2022-11-02 17:23:47 -04:00
GCCheck int ` help:"check heap/gc use by compiler" concurrent:"ok" `
2022-11-10 11:33:00 -05:00
GCProg int ` help:"print dump of GC programs" `
Gossahash string ` help:"hash value for use in debugging the compiler" `
InlFuncsWithClosures int ` help:"allow functions with closures to be inlined" concurrent:"ok" `
2022-11-22 13:28:51 -05:00
InlStaticInit int ` help:"allow static initialization of inlined calls" concurrent:"ok" `
2022-11-10 11:33:00 -05:00
Libfuzzer int ` help:"enable coverage instrumentation for libfuzzer" `
cmd/compile: experimental loop iterator capture semantics change
Adds:
GOEXPERIMENT=loopvar (expected way of invoking)
-d=loopvar={-1,0,1,2,11,12} (for per-package control and/or logging)
-d=loopvarhash=... (for hash debugging)
loopvar=11,12 are for testing, benchmarking, and debugging.
If enabled,for loops of the form `for x,y := range thing`, if x and/or
y are addressed or captured by a closure, are transformed by renaming
x/y to a temporary and prepending an assignment to the body of the
loop x := tmp_x. This changes the loop semantics by making each
iteration's instance of x be distinct from the others (currently they
are all aliased, and when this matters, it is almost always a bug).
3-range with captured iteration variables are also transformed,
though it is a more complex transformation.
"Optimized" to do a simpler transformation for
3-clause for where the increment is empty.
(Prior optimization of address-taking under Return disabled, because
it was incorrect; returns can have loops for children. Restored in
a later CL.)
Includes support for -d=loopvarhash=<binary string> intended for use
with hash search and GOCOMPILEDEBUG=loopvarhash=<binary string>
(use `gossahash -e loopvarhash command-that-fails`).
Minor feature upgrades to hash-triggered features; clients can specify
that file-position hashes use only the most-inline position, and/or that
they use only the basenames of source files (not the full directory path).
Most-inlined is the right choice for debugging loop-iteration change
once the semantics are linked to the package across inlining; basename-only
makes it tractable to write tests (which, otherwise, depend on the full
pathname of the source file and thus vary).
Updates #57969.
Change-Id: I180a51a3f8d4173f6210c861f10de23de8a1b1db
Reviewed-on: https://go-review.googlesource.com/c/go/+/411904
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-12 15:33:57 -04:00
LoopVar int ` help:"shared (0, default), 1 (private loop variables), 2, private + log" `
LoopVarHash string ` help:"for debugging changes in loop behavior. Overrides experiment and loopvar flag." `
2022-11-10 11:33:00 -05:00
LocationLists int ` help:"print information about DWARF location list creation" `
2024-01-09 15:06:15 +00:00
MaxShapeLen int ` help:"hash shape names longer than this threshold (default 500)" concurrent:"ok" `
2024-04-03 15:51:42 +00:00
MergeLocals int ` help:"merge together non-interfering local stack slots" concurrent:"ok" `
MergeLocalsDumpFunc string ` help:"dump specified func in merge locals" `
MergeLocalsHash string ` help:"hash value for debugging stack slot merging of local variables" concurrent:"ok" `
MergeLocalsTrace int ` help:"trace debug output for locals merging" `
cmd/compile/internal/liveness: enhance mergelocals for addr-taken candidates
It is possible to have situations where a given ir.Name is
non-address-taken at the source level, but whose address is
materialized in order to accommodate the needs of arch-dependent
memory ops. The issue here is that the SymAddr op will show up as
touching a variable of interest, but the subsequent memory op will
not. This is generally not an issue for computing whether something is
live across a call, but it is problematic for collecting the more
fine-grained live interval info that drives stack slot merging.
As an example, consider this Go code:
package p
type T struct {
x [10]int
f float64
}
func ABC(i, j int) int {
var t T
t.x[i&3] = j
return t.x[j&3]
}
On amd64 the code sequences we'll see for accesses to "t" might look like
v10 = VarDef <mem> {t} v1
v5 = MOVOstoreconst <mem> {t} [val=0,off=0] v2 v10
v23 = LEAQ <*T> {t} [8] v2 : DI
v12 = DUFFZERO <mem> [80] v23 v5
v14 = ANDQconst <int> [3] v7 : AX
v19 = MOVQstoreidx8 <mem> {t} v2 v14 v8 v12
v22 = ANDQconst <int> [3] v8 : BX
v24 = MOVQloadidx8 <int> {t} v2 v22 v19 : AX
v25 = MakeResult <int,mem> v24 v19 : <>
Note that the the loads and stores (ex: v19, v24) all refer directly
to "t", which means that regular live analysis will work fine for
identifying variable lifetimes. The DUFFZERO is (in effect) an
indirect write, but since there are accesses immediately after it we
wind up with the same live intervals.
Now the same code with GOARCH=ppc64:
v10 = VarDef <mem> {t} v1
v20 = MOVDaddr <*T> {t} v2 : R20
v12 = LoweredZero <mem> [88] v20 v10
v3 = CLRLSLDI <int> [212543] v7 : R5
v15 = MOVDaddr <*T> {t} v2 : R6
v19 = MOVDstoreidx <mem> v15 v3 v8 v12
v29 = CLRLSLDI <int> [212543] v8 : R4
v24 = MOVDloadidx <int> v15 v29 v19 : R3
v25 = MakeResult <int,mem> v24 v19 : <>
Here instead of memory ops that refer directly to the symbol, we take
the address of "t" (ex: v15) and then pass the address to memory ops
(where the ops themselves no longer refer to the symbol).
This patch enhances the stack slot merging liveness analysis to handle
cases like the PPC64 one above. We add a new phase in candidate
selection that collects more precise use information for merge
candidates, and screens out candidates that are too difficult to
analyze. The phase make a forward pass over each basic block looking
for instructions of the form vK := SymAddr(N) where N is a raw
candidate. It then creates an entry in a map with key vK and value
holding name and the vK use count. As the walk continues, we check for
uses of of vK: when we see one, record it in a side table as an
upwards exposed use of N. At each vK use we also decrement the use
count in the map entry, and if we hit zero, remove the map entry. If
we hit the end of the basic block and we still have map entries, this
implies that the address in question "escapes" the block -- at that
point to be conservative we just evict the name in question from the
candidate set.
Although this CL fixes the issues that forced a revert of the original
merging CL, this CL doesn't enable stack slot merging by default; a
subsequent CL will do that.
Updates #62737.
Updates #65532.
Updates #65495.
Change-Id: Id41d359a677767a8e7ac1e962ae23f7becb4031f
Reviewed-on: https://go-review.googlesource.com/c/go/+/576735
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-03 16:06:23 +00:00
MergeLocalsHTrace int ` help:"hash-selected trace debug output for locals merging" `
2022-11-10 11:33:00 -05:00
Nil int ` help:"print information about nil checks" `
NoOpenDefer int ` help:"disable open-coded defers" concurrent:"ok" `
NoRefName int ` help:"do not include referenced symbol names in object file" concurrent:"ok" `
PCTab string ` help:"print named pc-value table\nOne of: pctospadj, pctofile, pctoline, pctoinline, pctopcdata" `
Panic int ` help:"show all compiler panics" `
Reshape int ` help:"print information about expression reshaping" `
Shapify int ` help:"print information about shaping recursive types" `
Slice int ` help:"print information about slice compilation" `
SoftFloat int ` help:"force compiler to emit soft-float code" concurrent:"ok" `
2022-03-24 12:27:39 -07:00
StaticCopy int ` help:"print information about missed static copies" concurrent:"ok" `
2022-11-10 11:33:00 -05:00
SyncFrames int ` help:"how many writer stack frames to include at sync points in unified export data" `
TypeAssert int ` help:"print information about type assertion inlining" `
WB int ` help:"print information about write barriers" `
ABIWrap int ` help:"print information about ABI wrapper generation" `
MayMoreStack string ` help:"call named function before all stack growth checks" concurrent:"ok" `
2023-05-12 15:36:37 -04:00
PGODebug int ` help:"debug profile-guided optimizations" `
2023-09-15 12:13:09 -04:00
PGOHash string ` help:"hash value for debugging profile-guided optimizations" concurrent:"ok" `
2023-05-12 15:36:37 -04:00
PGOInline int ` help:"enable profile-guided inlining" concurrent:"ok" `
2023-03-09 13:20:01 -05:00
PGOInlineCDFThreshold string ` help:"cumulative threshold percentage for determining call sites as hot candidates for inlining" concurrent:"ok" `
2022-11-10 11:33:00 -05:00
PGOInlineBudget int ` help:"inline budget for hot functions" concurrent:"ok" `
2023-11-16 13:00:55 -05:00
PGODevirtualize int ` help:"enable profile-guided devirtualization; 0 to disable, 1 to enable interface devirtualization, 2 to enable function devirtualization" concurrent:"ok" `
2023-11-11 15:32:45 -05:00
RangeFuncCheck int ` help:"insert code to check behavior of range iterator functions" concurrent:"ok" `
2023-03-09 13:20:01 -05:00
WrapGlobalMapDbg int ` help:"debug trace output for global map init wrapping" `
WrapGlobalMapCtl int ` help:"global map init wrap control (0 => default, 1 => off, 2 => stress mode, no size cutoff)" `
2023-08-17 14:15:04 -07:00
ZeroCopy int ` help:"enable zero-copy string->[]byte conversions" concurrent:"ok" `
2020-11-16 01:44:47 -05:00
2022-10-25 23:01:44 -04:00
ConcurrentOk bool // true if only concurrentOk flags seen
2020-11-16 01:17:25 -05:00
}
2020-11-16 01:44:47 -05:00
// DebugSSA is called to set a -d ssa/... option.
// If nil, those options are reported as invalid options.
// If DebugSSA returns a non-empty string, that text is reported as a compiler error.
var DebugSSA func ( phase , flag string , val int , valString string ) string