From 601bc41da2378b342ea3bb2f0e7ab961dfe508a4 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 27 Apr 2020 20:42:00 -0400 Subject: [PATCH] cmd/compile: don't emit stack maps for write barrier calls These are necessarily deeply non-preemptible, so there's no point in emitting stack maps for them. We already mark them as unsafe points, so this only affects the runtime, since user code does not emit stack maps at unsafe points. SSAGenState.PrepareCall also excludes them when it's sanity checking call stack maps. Right now this only drops a handful of unnecessary stack maps from the runtime, but we're about to start emitting stack maps only at calls for user code, too. At that point, this will matter much more. For #36365. Change-Id: Ib3abfedfddc8e724d933a064fa4d573500627990 Reviewed-on: https://go-review.googlesource.com/c/go/+/230542 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/gc/plive.go | 11 ++++++++++- src/cmd/compile/internal/gc/ssa.go | 4 +--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/gc/plive.go b/src/cmd/compile/internal/gc/plive.go index 61c01f5b9d..707ceca33a 100644 --- a/src/cmd/compile/internal/gc/plive.go +++ b/src/cmd/compile/internal/gc/plive.go @@ -838,7 +838,16 @@ func (lv *Liveness) hasStackMap(v *ssa.Value) bool { // we only need stack maps at call sites. go:nosplit functions // are similar. if compiling_runtime || lv.f.NoSplit { - return v.Op.IsCall() + if !v.Op.IsCall() { + return false + } + // typedmemclr and typedmemmove are write barriers and + // deeply non-preemptible. They are unsafe points and + // hence should not have liveness maps. + if sym, _ := v.Aux.(*obj.LSym); sym == typedmemclr || sym == typedmemmove { + return false + } + return true } switch v.Op { diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index e99221c217..70f6dd6e18 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -6572,9 +6572,7 @@ func (s *SSAGenState) Call(v *ssa.Value) *obj.Prog { func (s *SSAGenState) PrepareCall(v *ssa.Value) { idx := s.livenessMap.Get(v) if !idx.StackMapValid() { - // typedmemclr and typedmemmove are write barriers and - // deeply non-preemptible. They are unsafe points and - // hence should not have liveness maps. + // See Liveness.hasStackMap. if sym, _ := v.Aux.(*obj.LSym); !(sym == typedmemclr || sym == typedmemmove) { Fatalf("missing stack map index for %v", v.LongString()) } -- 2.50.0