1
0
mirror of https://github.com/golang/go synced 2024-09-29 11:34:32 -06:00

cmd/compile/internal/gc: use bool in racewalk

Replace int variables with 0/1 as only possible values with bools,
where possible.

Change-Id: I958c082e703bbc1540309da3e17612fc8e247932
Reviewed-on: https://go-review.googlesource.com/105036
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Ilya Tocar 2018-04-05 14:15:56 -05:00
parent eda22a06fb
commit b0d437f866

View File

@ -95,7 +95,7 @@ func instrumentlist(l Nodes, init *Nodes) {
s := l.Slice() s := l.Slice()
for i := range s { for i := range s {
var instr Nodes var instr Nodes
instrumentnode(&s[i], &instr, 0, 0) instrumentnode(&s[i], &instr, flagRead, flagRun)
if init == nil { if init == nil {
s[i].Ninit.AppendNodes(&instr) s[i].Ninit.AppendNodes(&instr)
} else { } else {
@ -107,7 +107,7 @@ func instrumentlist(l Nodes, init *Nodes) {
// walkexpr and walkstmt combined // walkexpr and walkstmt combined
// walks the tree and adds calls to the // walks the tree and adds calls to the
// instrumentation code to top-level (statement) nodes' init // instrumentation code to top-level (statement) nodes' init
func instrumentnode(np **Node, init *Nodes, wr int, skip int) { func instrumentnode(np **Node, init *Nodes, wr, skip bool) {
n := *np n := *np
if n == nil { if n == nil {
@ -142,8 +142,8 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
Fatalf("instrument: unknown node type %v", n.Op) Fatalf("instrument: unknown node type %v", n.Op)
case OAS, OAS2FUNC: case OAS, OAS2FUNC:
instrumentnode(&n.Left, init, 1, 0) instrumentnode(&n.Left, init, flagWrite, flagRun)
instrumentnode(&n.Right, init, 0, 0) instrumentnode(&n.Right, init, flagRead, flagRun)
// can't matter // can't matter
case OCFUNC, OVARKILL, OVARLIVE: case OCFUNC, OVARKILL, OVARLIVE:
@ -161,15 +161,15 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
if afterCall && op == OAS && iscallret(ls[i].Right) { if afterCall && op == OAS && iscallret(ls[i].Right) {
continue continue
} }
instrumentnode(&ls[i], &ls[i].Ninit, 0, 0) instrumentnode(&ls[i], &ls[i].Ninit, flagRead, flagRun)
afterCall = (op == OCALLFUNC || op == OCALLMETH || op == OCALLINTER) afterCall = (op == OCALLFUNC || op == OCALLMETH || op == OCALLINTER)
} }
case ODEFER, OPROC: case ODEFER, OPROC:
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, flagRead, flagRun)
case OCALLINTER: case OCALLINTER:
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, flagRead, flagRun)
case OCALLFUNC: case OCALLFUNC:
// Note that runtime.typedslicecopy is the only // Note that runtime.typedslicecopy is the only
@ -179,7 +179,7 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
// instrumented in runtime. Calls to the write barrier // instrumented in runtime. Calls to the write barrier
// and typedmemmove are created later by SSA, so those // and typedmemmove are created later by SSA, so those
// still appear as OAS nodes at this point. // still appear as OAS nodes at this point.
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, flagRead, flagRun)
case ONOT, case ONOT,
OMINUS, OMINUS,
@ -187,94 +187,94 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
OREAL, OREAL,
OIMAG, OIMAG,
OCOM: OCOM:
instrumentnode(&n.Left, init, wr, 0) instrumentnode(&n.Left, init, wr, flagRun)
case ODOTINTER: case ODOTINTER:
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, flagRead, flagRun)
case ODOT: case ODOT:
instrumentnode(&n.Left, init, 0, 1) instrumentnode(&n.Left, init, flagRead, flagSkip)
callinstr(&n, init, wr, skip) callinstr(&n, init, wr, skip)
case ODOTPTR, // dst = (*x).f with implicit *; otherwise it's ODOT+OIND case ODOTPTR, // dst = (*x).f with implicit *; otherwise it's ODOT+OIND
OIND: // *p OIND: // *p
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, flagRead, flagRun)
callinstr(&n, init, wr, skip) callinstr(&n, init, wr, skip)
case OSPTR, OLEN, OCAP: case OSPTR, OLEN, OCAP:
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, flagRead, flagRun)
if n.Left.Type.IsMap() { if n.Left.Type.IsMap() {
n1 := nod(OCONVNOP, n.Left, nil) n1 := nod(OCONVNOP, n.Left, nil)
n1.Type = types.NewPtr(types.Types[TUINT8]) n1.Type = types.NewPtr(types.Types[TUINT8])
n1 = nod(OIND, n1, nil) n1 = nod(OIND, n1, nil)
n1 = typecheck(n1, Erv) n1 = typecheck(n1, Erv)
callinstr(&n1, init, 0, skip) callinstr(&n1, init, flagRead, skip)
} }
case OLSH, ORSH, OAND, OANDNOT, OOR, OXOR, OSUB, case OLSH, ORSH, OAND, OANDNOT, OOR, OXOR, OSUB,
OMUL, OEQ, ONE, OLT, OLE, OGE, OGT, OADD, OCOMPLEX: OMUL, OEQ, ONE, OLT, OLE, OGE, OGT, OADD, OCOMPLEX:
instrumentnode(&n.Left, init, wr, 0) instrumentnode(&n.Left, init, wr, flagRun)
instrumentnode(&n.Right, init, wr, 0) instrumentnode(&n.Right, init, wr, flagRun)
case OANDAND, OOROR: case OANDAND, OOROR:
instrumentnode(&n.Left, init, wr, 0) instrumentnode(&n.Left, init, wr, flagRun)
// walk has ensured the node has moved to a location where // walk has ensured the node has moved to a location where
// side effects are safe. // side effects are safe.
// n->right may not be executed, // n->right may not be executed,
// so instrumentation goes to n->right->ninit, not init. // so instrumentation goes to n->right->ninit, not init.
instrumentnode(&n.Right, &n.Right.Ninit, wr, 0) instrumentnode(&n.Right, &n.Right.Ninit, wr, flagRun)
case ONAME: case ONAME:
callinstr(&n, init, wr, skip) callinstr(&n, init, wr, skip)
case OCONV, OCONVNOP: case OCONV, OCONVNOP:
instrumentnode(&n.Left, init, wr, 0) instrumentnode(&n.Left, init, wr, flagRun)
case ODIV, OMOD: case ODIV, OMOD:
instrumentnode(&n.Left, init, wr, 0) instrumentnode(&n.Left, init, wr, flagRun)
instrumentnode(&n.Right, init, wr, 0) instrumentnode(&n.Right, init, wr, flagRun)
case OINDEX: case OINDEX:
if !n.Left.Type.IsArray() { if !n.Left.Type.IsArray() {
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, flagRead, flagRun)
} else if !islvalue(n.Left) { } else if !islvalue(n.Left) {
// index of unaddressable array, like Map[k][i]. // index of unaddressable array, like Map[k][i].
instrumentnode(&n.Left, init, wr, 0) instrumentnode(&n.Left, init, wr, flagRun)
instrumentnode(&n.Right, init, 0, 0) instrumentnode(&n.Right, init, flagRead, flagRun)
break break
} }
instrumentnode(&n.Right, init, 0, 0) instrumentnode(&n.Right, init, flagRead, flagRun)
if !n.Left.Type.IsString() { if !n.Left.Type.IsString() {
callinstr(&n, init, wr, skip) callinstr(&n, init, wr, skip)
} }
case OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR, OSLICESTR: case OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR, OSLICESTR:
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, flagRead, flagRun)
low, high, max := n.SliceBounds() low, high, max := n.SliceBounds()
instrumentnode(&low, init, 0, 0) instrumentnode(&low, init, flagRead, flagRun)
instrumentnode(&high, init, 0, 0) instrumentnode(&high, init, flagRead, flagRun)
instrumentnode(&max, init, 0, 0) instrumentnode(&max, init, flagRead, flagRun)
n.SetSliceBounds(low, high, max) n.SetSliceBounds(low, high, max)
case OADDR: case OADDR:
instrumentnode(&n.Left, init, 0, 1) instrumentnode(&n.Left, init, flagRead, flagSkip)
// n->left is Type* which is not interesting. // n->left is Type* which is not interesting.
case OEFACE: case OEFACE:
instrumentnode(&n.Right, init, 0, 0) instrumentnode(&n.Right, init, flagRead, flagRun)
case OITAB, OIDATA, OSTRARRAYBYTETMP: case OITAB, OIDATA, OSTRARRAYBYTETMP:
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, flagRead, flagRun)
case OAS2DOTTYPE: case OAS2DOTTYPE:
instrumentnode(&n.Left, init, 1, 0) instrumentnode(&n.Left, init, flagWrite, flagRun)
instrumentnode(&n.Right, init, 0, 0) instrumentnode(&n.Right, init, flagRead, flagRun)
case ODOTTYPE, ODOTTYPE2: case ODOTTYPE, ODOTTYPE2:
instrumentnode(&n.Left, init, 0, 0) instrumentnode(&n.Left, init, flagRead, flagRun)
// should not appear in AST by now // should not appear in AST by now
case OSEND, case OSEND,
@ -321,15 +321,15 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
case OFOR, OFORUNTIL: case OFOR, OFORUNTIL:
if n.Left != nil { if n.Left != nil {
instrumentnode(&n.Left, &n.Left.Ninit, 0, 0) instrumentnode(&n.Left, &n.Left.Ninit, flagRead, flagRun)
} }
if n.Right != nil { if n.Right != nil {
instrumentnode(&n.Right, &n.Right.Ninit, 0, 0) instrumentnode(&n.Right, &n.Right.Ninit, flagRead, flagRun)
} }
case OIF, OSWITCH: case OIF, OSWITCH:
if n.Left != nil { if n.Left != nil {
instrumentnode(&n.Left, &n.Left.Ninit, 0, 0) instrumentnode(&n.Left, &n.Left.Ninit, flagRead, flagRun)
} }
// just do generic traversal // just do generic traversal
@ -396,13 +396,20 @@ func isartificial(n *Node) bool {
return false return false
} }
func callinstr(np **Node, init *Nodes, wr int, skip int) { const (
flagWrite = true
flagRead = !flagWrite
flagSkip = true
flagRun = !flagSkip
)
func callinstr(np **Node, init *Nodes, wr, skip bool) {
n := *np n := *np
//fmt.Printf("callinstr for %v [ %v ] etype=%v class=%v\n", //fmt.Printf("callinstr for %v [ %v ] etype=%v class=%v\n",
// n, n.Op, n.Type.Etype, n.Class) // n, n.Op, n.Type.Etype, n.Class)
if skip != 0 || n.Type == nil || n.Type.Etype >= TIDEAL { if skip || n.Type == nil || n.Type.Etype >= TIDEAL {
return return
} }
t := n.Type t := n.Type
@ -450,7 +457,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) {
var f *Node var f *Node
if flag_msan { if flag_msan {
name := "msanread" name := "msanread"
if wr != 0 { if wr {
name = "msanwrite" name = "msanwrite"
} }
f = mkcall(name, nil, init, uintptraddr(n), nodintconst(w)) f = mkcall(name, nil, init, uintptraddr(n), nodintconst(w))
@ -459,7 +466,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) {
// because a write might happen to any subobject. // because a write might happen to any subobject.
// composites with only one element don't have subobjects, though. // composites with only one element don't have subobjects, though.
name := "racereadrange" name := "racereadrange"
if wr != 0 { if wr {
name = "racewriterange" name = "racewriterange"
} }
f = mkcall(name, nil, init, uintptraddr(n), nodintconst(w)) f = mkcall(name, nil, init, uintptraddr(n), nodintconst(w))
@ -467,7 +474,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) {
// for non-composite objects we can write just the start // for non-composite objects we can write just the start
// address, as any write must write the first byte. // address, as any write must write the first byte.
name := "raceread" name := "raceread"
if wr != 0 { if wr {
name = "racewrite" name = "racewrite"
} }
f = mkcall(name, nil, init, uintptraddr(n)) f = mkcall(name, nil, init, uintptraddr(n))