From e0111bb0f495696e78d4d17c0c0e39b294bb32dd Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Thu, 18 May 2017 15:38:44 -0400 Subject: [PATCH] cmd/compile: remove needwritebarrier from the frontend The write barrier insertion has moved to the SSA backend's writebarrier pass. There is still needwritebarrier function left in the frontend. This function is used in two places: - fncall, which is called in ascompatet, which is called in walking OAS2FUNC. For OAS2FUNC, in order pass we've already created temporaries, and there is no write barrier for the assignments of these temporaries. - updateHasCall, which updates the HasCall flag of a node. the HasCall flag is then used in - fncall, mentioned above. - ascompatet. As mentioned above, this is an assignment to a temporary, no write barrier. - reorder1, which is always called with a list produced by ascompatte, which is a list of assignments to stack, which have no write barrier. - vmatch1, which is called in oaslit with r.Op as OSTRUCTLIT, OARRAYLIT, OSLICELIT, or OMAPLIT. There is no write barrier in those literals. Therefore, the needwritebarrier function is unnecessary. This CL removes it. Passes "toolstash -cmp" on std cmd. Updates #17583. Change-Id: I4b87ba8363d6583e4282a9e607a9ec8ce3ab124a Reviewed-on: https://go-review.googlesource.com/43640 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/subr.go | 5 --- src/cmd/compile/internal/gc/walk.go | 49 ----------------------------- 2 files changed, 54 deletions(-) diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index 8faec66aa0..83f160e883 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -1144,11 +1144,6 @@ func updateHasCall(n *Node) { Fatalf("OLITERAL/ONAME/OTYPE should never have calls: %+v", n) } return - case OAS: - if needwritebarrier(n.Left) { - b = true - goto out - } case OCALL, OCALLFUNC, OCALLMETH, OCALLINTER: b = true goto out diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index b7db5b29d4..58c8808eca 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -1805,9 +1805,6 @@ func fncall(l *Node, rt *types.Type) bool { if l.HasCall() || l.Op == OINDEXMAP { return true } - if needwritebarrier(l) { - return true - } if eqtype(l.Type, rt) { return false } @@ -2249,52 +2246,6 @@ func isReflectHeaderDataField(l *Node) bool { return tsym.Name == "SliceHeader" || tsym.Name == "StringHeader" } -// Do we need a write barrier for assigning to l? -func needwritebarrier(l *Node) bool { - if !use_writebarrier { - return false - } - - if l == nil || isblank(l) { - return false - } - - // No write barrier for write to stack. - if isstack(l) { - return false - } - - // Package unsafe's documentation says storing pointers into - // reflect.SliceHeader and reflect.StringHeader's Data fields - // is valid, even though they have type uintptr (#19168). - if isReflectHeaderDataField(l) { - return true - } - - // No write barrier for write of non-pointers. - dowidth(l.Type) - if !types.Haspointers(l.Type) { - return false - } - - // No write barrier if this is a pointer to a go:notinheap - // type, since the write barrier's inheap(ptr) check will fail. - if l.Type.IsPtr() && l.Type.Elem().NotInHeap() { - return false - } - - // TODO: We can eliminate write barriers if we know *both* the - // current and new content of the slot must already be shaded. - // We know a pointer is shaded if it's nil, or points to - // static data, a global (variable or function), or the stack. - // The nil optimization could be particularly useful for - // writes to just-allocated objects. Unfortunately, knowing - // the "current" value of the slot requires flow analysis. - - // Otherwise, be conservative and use write barrier. - return true -} - func convas(n *Node, init *Nodes) *Node { if n.Op != OAS { Fatalf("convas: not OAS %v", n.Op) -- 2.48.1