mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: omit racefuncentry/exit when they are not needed
When compiling with -race, we insert calls to racefuncentry, into every function. Add a rule that removes them in leaf functions, without instrumented loads/stores. Shaves ~30kb from "-race" version of go tool: file difference: go_old 15626192 go_new 15597520 [-28672 bytes] section differences: global text (code) = -24513 bytes (-0.358598%) read-only data = -5849 bytes (-0.167064%) Total difference -30362 bytes (-0.097928%) Fixes #24662 Change-Id: Ia63bf1827f4cf2c25e3e28dcd097c150994ade0a Reviewed-on: https://go-review.googlesource.com/121235 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
f76eaeb2c8
commit
4201c2077e
6 changed files with 51 additions and 1 deletions
|
|
@ -1026,3 +1026,31 @@ func registerizable(b *Block, t interface{}) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// needRaceCleanup reports whether this call to racefuncenter/exit isn't needed.
|
||||
func needRaceCleanup(sym interface{}, v *Value) bool {
|
||||
f := v.Block.Func
|
||||
if !f.Config.Race {
|
||||
return false
|
||||
}
|
||||
if !isSameSym(sym, "runtime.racefuncenter") && !isSameSym(sym, "runtime.racefuncexit") {
|
||||
return false
|
||||
}
|
||||
for _, b := range f.Blocks {
|
||||
for _, v := range b.Values {
|
||||
if v.Op == OpStaticCall {
|
||||
switch v.Aux.(fmt.Stringer).String() {
|
||||
case "runtime.racefuncenter", "runtime.racefuncexit", "runtime.panicindex",
|
||||
"runtime.panicslice", "runtime.panicdivide", "runtime.panicwrap":
|
||||
// Check for racefuncenter will encounter racefuncexit and vice versa.
|
||||
// Allow calls to panic*
|
||||
default:
|
||||
// If we encounterd any call, we need to keep racefunc*,
|
||||
// for accurate stacktraces.
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue