Commit bdb9b945 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: eliminate OASWB

Instead we can just call needwritebarrier when constructing the SSA
representation.

Change-Id: I6fefaad49daada9cdb3050f112889e49dca0047b
Reviewed-on: https://go-review.googlesource.com/34566Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent e7ec06e0
...@@ -1432,7 +1432,7 @@ func (p *exporter) stmt(n *Node) { ...@@ -1432,7 +1432,7 @@ func (p *exporter) stmt(n *Node) {
// case ODCLFIELD: // case ODCLFIELD:
// unimplemented - handled by default case // unimplemented - handled by default case
case OAS, OASWB: case OAS:
// Don't export "v = <N>" initializing statements, hope they're always // Don't export "v = <N>" initializing statements, hope they're always
// preceded by the DCL which will be re-parsed and typecheck to reproduce // preceded by the DCL which will be re-parsed and typecheck to reproduce
// the "v = <N>" again. // the "v = <N>" again.
......
...@@ -761,7 +761,7 @@ func (e *EscState) esc(n *Node, parent *Node) { ...@@ -761,7 +761,7 @@ func (e *EscState) esc(n *Node, parent *Node) {
// This assignment is a no-op for escape analysis, // This assignment is a no-op for escape analysis,
// it does not store any new pointers into b that were not already there. // it does not store any new pointers into b that were not already there.
// However, without this special case b will escape, because we assign to OIND/ODOTPTR. // However, without this special case b will escape, because we assign to OIND/ODOTPTR.
case OAS, OASOP, OASWB: case OAS, OASOP:
if (n.Left.Op == OIND || n.Left.Op == ODOTPTR) && n.Left.Left.Op == ONAME && // dst is ONAME dereference if (n.Left.Op == OIND || n.Left.Op == ODOTPTR) && n.Left.Left.Op == ONAME && // dst is ONAME dereference
(n.Right.Op == OSLICE || n.Right.Op == OSLICE3 || n.Right.Op == OSLICESTR) && // src is slice operation (n.Right.Op == OSLICE || n.Right.Op == OSLICE3 || n.Right.Op == OSLICESTR) && // src is slice operation
(n.Right.Left.Op == OIND || n.Right.Left.Op == ODOTPTR) && n.Right.Left.Left.Op == ONAME && // slice is applied to ONAME dereference (n.Right.Left.Op == OIND || n.Right.Left.Op == ODOTPTR) && n.Right.Left.Left.Op == ONAME && // slice is applied to ONAME dereference
......
...@@ -837,7 +837,7 @@ func (n *Node) stmtfmt(s fmt.State) { ...@@ -837,7 +837,7 @@ func (n *Node) stmtfmt(s fmt.State) {
// Don't export "v = <N>" initializing statements, hope they're always // Don't export "v = <N>" initializing statements, hope they're always
// preceded by the DCL which will be re-parsed and typechecked to reproduce // preceded by the DCL which will be re-parsed and typechecked to reproduce
// the "v = <N>" again. // the "v = <N>" again.
case OAS, OASWB: case OAS:
if n.Colas && !complexinit { if n.Colas && !complexinit {
fmt.Fprintf(s, "%v := %v", n.Left, n.Right) fmt.Fprintf(s, "%v := %v", n.Left, n.Right)
} else { } else {
......
...@@ -41,7 +41,7 @@ func anyinit(n []*Node) bool { ...@@ -41,7 +41,7 @@ func anyinit(n []*Node) bool {
case ODCLFUNC, ODCLCONST, ODCLTYPE, OEMPTY: case ODCLFUNC, ODCLCONST, ODCLTYPE, OEMPTY:
break break
case OAS, OASWB: case OAS:
if isblank(ln.Left) && candiscard(ln.Right) { if isblank(ln.Left) && candiscard(ln.Right) {
break break
} }
......
...@@ -33,7 +33,6 @@ var opnames = []string{ ...@@ -33,7 +33,6 @@ var opnames = []string{
OAS2MAPR: "AS2MAPR", OAS2MAPR: "AS2MAPR",
OAS2DOTTYPE: "AS2DOTTYPE", OAS2DOTTYPE: "AS2DOTTYPE",
OASOP: "ASOP", OASOP: "ASOP",
OASWB: "ASWB",
OCALL: "CALL", OCALL: "CALL",
OCALLFUNC: "CALLFUNC", OCALLFUNC: "CALLFUNC",
OCALLMETH: "CALLMETH", OCALLMETH: "CALLMETH",
......
...@@ -136,7 +136,7 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) { ...@@ -136,7 +136,7 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
default: default:
Fatalf("instrument: unknown node type %v", n.Op) Fatalf("instrument: unknown node type %v", n.Op)
case OAS, OASWB, OAS2FUNC: case OAS, OAS2FUNC:
instrumentnode(&n.Left, init, 1, 0) instrumentnode(&n.Left, init, 1, 0)
instrumentnode(&n.Right, init, 0, 0) instrumentnode(&n.Right, init, 0, 0)
goto ret goto ret
......
...@@ -752,11 +752,6 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes) ...@@ -752,11 +752,6 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes)
switch kind { switch kind {
case initKindStatic: case initKindStatic:
a = walkexpr(a, init) // add any assignments in r to top a = walkexpr(a, init) // add any assignments in r to top
if a.Op == OASWB {
// Static initialization never needs
// write barriers.
a.Op = OAS
}
if a.Op != OAS { if a.Op != OAS {
Fatalf("fixedlit: not as, is %v", a) Fatalf("fixedlit: not as, is %v", a)
} }
......
...@@ -641,7 +641,7 @@ func (s *state) stmt(n *Node) { ...@@ -641,7 +641,7 @@ func (s *state) stmt(n *Node) {
b := s.endBlock() b := s.endBlock()
b.AddEdgeTo(lab.target) b.AddEdgeTo(lab.target)
case OAS, OASWB: case OAS:
// Generate static data rather than code, if possible. // Generate static data rather than code, if possible.
if n.IsStatic { if n.IsStatic {
if !genAsInitNoCheck(n) { if !genAsInitNoCheck(n) {
...@@ -704,7 +704,7 @@ func (s *state) stmt(n *Node) { ...@@ -704,7 +704,7 @@ func (s *state) stmt(n *Node) {
} }
var r *ssa.Value var r *ssa.Value
var isVolatile bool var isVolatile bool
needwb := n.Op == OASWB needwb := n.Right != nil && needwritebarrier(n.Left, n.Right)
deref := !canSSAType(t) deref := !canSSAType(t)
if deref { if deref {
if rhs == nil { if rhs == nil {
...@@ -728,6 +728,9 @@ func (s *state) stmt(n *Node) { ...@@ -728,6 +728,9 @@ func (s *state) stmt(n *Node) {
// They get similar wb-removal treatment in walk.go:OAS. // They get similar wb-removal treatment in walk.go:OAS.
needwb = true needwb = true
} }
if needwb && Debug_wb > 1 {
Warnl(n.Pos, "marking %v for barrier", n.Left)
}
var skip skipMask var skip skipMask
if rhs != nil && (rhs.Op == OSLICE || rhs.Op == OSLICE3 || rhs.Op == OSLICESTR) && samesafeexpr(rhs.Left, n.Left) { if rhs != nil && (rhs.Op == OSLICE || rhs.Op == OSLICE3 || rhs.Op == OSLICESTR) && samesafeexpr(rhs.Left, n.Left) {
......
...@@ -1169,7 +1169,12 @@ func ullmancalc(n *Node) { ...@@ -1169,7 +1169,12 @@ func ullmancalc(n *Node) {
} }
goto out goto out
case OCALL, OCALLFUNC, OCALLMETH, OCALLINTER, OASWB: case OAS:
if !needwritebarrier(n.Left, n.Right) {
break
}
fallthrough
case OCALL, OCALLFUNC, OCALLMETH, OCALLINTER:
ul = UINF ul = UINF
goto out goto out
......
...@@ -361,7 +361,6 @@ const ( ...@@ -361,7 +361,6 @@ const (
OAS2MAPR // List = Rlist (x, ok = m["foo"]) OAS2MAPR // List = Rlist (x, ok = m["foo"])
OAS2DOTTYPE // List = Rlist (x, ok = I.(int)) OAS2DOTTYPE // List = Rlist (x, ok = I.(int))
OASOP // Left Etype= Right (x += y) OASOP // Left Etype= Right (x += y)
OASWB // Left = Right (with write barrier)
OCALL // Left(List) (function call, method call or type conversion) OCALL // Left(List) (function call, method call or type conversion)
OCALLFUNC // Left(List) (function call f(args)) OCALLFUNC // Left(List) (function call f(args))
OCALLMETH // Left(List) (direct method call x.Method(args)) OCALLMETH // Left(List) (direct method call x.Method(args))
......
...@@ -338,10 +338,6 @@ func walkstmt(n *Node) *Node { ...@@ -338,10 +338,6 @@ func walkstmt(n *Node) *Node {
ll := ascompatee(n.Op, rl, n.List.Slice(), &n.Ninit) ll := ascompatee(n.Op, rl, n.List.Slice(), &n.Ninit)
n.List.Set(reorder3(ll)) n.List.Set(reorder3(ll))
ls := n.List.Slice()
for i, n := range ls {
ls[i] = applywritebarrier(n)
}
break break
} }
...@@ -683,7 +679,7 @@ opswitch: ...@@ -683,7 +679,7 @@ opswitch:
break break
} }
if !instrumenting && iszero(n.Right) && !needwritebarrier(n.Left, n.Right) { if !instrumenting && iszero(n.Right) {
break break
} }
...@@ -727,7 +723,6 @@ opswitch: ...@@ -727,7 +723,6 @@ opswitch:
static := n.IsStatic static := n.IsStatic
n = convas(n, init) n = convas(n, init)
n.IsStatic = static n.IsStatic = static
n = applywritebarrier(n)
} }
case OAS2: case OAS2:
...@@ -736,9 +731,6 @@ opswitch: ...@@ -736,9 +731,6 @@ opswitch:
walkexprlistsafe(n.Rlist.Slice(), init) walkexprlistsafe(n.Rlist.Slice(), init)
ll := ascompatee(OAS, n.List.Slice(), n.Rlist.Slice(), init) ll := ascompatee(OAS, n.List.Slice(), n.Rlist.Slice(), init)
ll = reorder3(ll) ll = reorder3(ll)
for i, n := range ll {
ll[i] = applywritebarrier(n)
}
n = liststmt(ll) n = liststmt(ll)
// a,b,... = fn() // a,b,... = fn()
...@@ -756,9 +748,6 @@ opswitch: ...@@ -756,9 +748,6 @@ opswitch:
init.Append(r) init.Append(r)
ll := ascompatet(n.Op, n.List, r.Type) ll := ascompatet(n.Op, n.List, r.Type)
for i, n := range ll {
ll[i] = applywritebarrier(n)
}
n = liststmt(ll) n = liststmt(ll)
// x, y = <-c // x, y = <-c
...@@ -2124,19 +2113,6 @@ func needwritebarrier(l *Node, r *Node) bool { ...@@ -2124,19 +2113,6 @@ func needwritebarrier(l *Node, r *Node) bool {
return true return true
} }
// TODO(rsc): Perhaps componentgen should run before this.
func applywritebarrier(n *Node) *Node {
if n.Left != nil && n.Right != nil && needwritebarrier(n.Left, n.Right) {
if Debug_wb > 1 {
Warnl(n.Pos, "marking %v for barrier", n.Left)
}
n.Op = OASWB
return n
}
return n
}
func convas(n *Node, init *Nodes) *Node { func convas(n *Node, init *Nodes) *Node {
if n.Op != OAS { if n.Op != OAS {
Fatalf("convas: not OAS %v", n.Op) Fatalf("convas: not OAS %v", n.Op)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment