Skip to content

Commit

Permalink
cmd/compile: merge Node.Opt and Node.Val behind access methods
Browse files Browse the repository at this point in the history
$ sizeof -p cmd/compile/internal/gc Node
Node 144
$

Change-Id: I688e3790964fe42f48c19f697ec38094a92fe1c1
Reviewed-on: https://go-review.googlesource.com/10531
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
rsc committed Jun 4, 2015
1 parent a53710f commit 81d5810
Show file tree
Hide file tree
Showing 23 changed files with 345 additions and 300 deletions.
64 changes: 32 additions & 32 deletions src/cmd/compile/internal/gc/cgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func cgen_wb(n, res *Node, wb bool) {
var n1 Node
Regalloc(&n1, Types[Tptr], res)
p1 := Thearch.Gins(Thearch.Optoas(OAS, n1.Type), nil, &n1)
Datastring(nl.Val.U.(string), &p1.From)
Datastring(nl.Val().U.(string), &p1.From)
p1.From.Type = obj.TYPE_ADDR
Thearch.Gmove(&n1, res)
Regfree(&n1)
Expand Down Expand Up @@ -1036,7 +1036,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Fatal("constant string constant index")
}
v := uint64(Mpgetfix(nr.Val.U.(*Mpint)))
v := uint64(Mpgetfix(nr.Val().U.(*Mpint)))
var n2 Node
if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
if Debug['B'] == 0 && !n.Bounded {
Expand Down Expand Up @@ -1072,7 +1072,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Debug['B'] == 0 && !n.Bounded {
// check bounds
if Isconst(nl, CTSTR) {
Nodconst(&n4, Types[TUINT32], int64(len(nl.Val.U.(string))))
Nodconst(&n4, Types[TUINT32], int64(len(nl.Val().U.(string))))
} else if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
n1 = n3
n1.Op = OINDREG
Expand All @@ -1097,7 +1097,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Regalloc(&n3, Types[Tptr], res)
p1 := Thearch.Gins(Thearch.Optoas(OAS, Types[Tptr]), nil, &n3)
Datastring(nl.Val.U.(string), &p1.From)
Datastring(nl.Val().U.(string), &p1.From)
p1.From.Type = obj.TYPE_ADDR
} else if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
n1 = n3
Expand Down Expand Up @@ -1188,7 +1188,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Fatal("constant string constant index") // front end should handle
}
v := uint64(Mpgetfix(nr.Val.U.(*Mpint)))
v := uint64(Mpgetfix(nr.Val().U.(*Mpint)))
if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
if Debug['B'] == 0 && !n.Bounded {
nlen := n3
Expand Down Expand Up @@ -1233,7 +1233,7 @@ func Agenr(n *Node, a *Node, res *Node) {

var nlen Node
if Isconst(nl, CTSTR) {
Nodconst(&nlen, t, int64(len(nl.Val.U.(string))))
Nodconst(&nlen, t, int64(len(nl.Val().U.(string))))
} else if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
nlen = n3
nlen.Type = t
Expand All @@ -1253,7 +1253,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Regalloc(&n3, Types[Tptr], res)
p1 := Thearch.Gins(Thearch.Optoas(OAS, Types[Tptr]), nil, &n3)
Datastring(nl.Val.U.(string), &p1.From)
Datastring(nl.Val().U.(string), &p1.From)
p1.From.Type = obj.TYPE_ADDR
Thearch.Gins(Thearch.Optoas(OADD, n3.Type), &n2, &n3)
goto indexdone1
Expand Down Expand Up @@ -1378,7 +1378,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Fatal("constant string constant index") // front end should handle
}
v := uint64(Mpgetfix(nr.Val.U.(*Mpint)))
v := uint64(Mpgetfix(nr.Val().U.(*Mpint)))
if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
if Debug['B'] == 0 && !n.Bounded {
p1 := Thearch.Ginscmp(OGT, Types[Simtype[TUINT]], &nlen, Nodintconst(int64(v)), +1)
Expand Down Expand Up @@ -1416,7 +1416,7 @@ func Agenr(n *Node, a *Node, res *Node) {
t = Types[TUINT64]
}
if Isconst(nl, CTSTR) {
Nodconst(&nlen, t, int64(len(nl.Val.U.(string))))
Nodconst(&nlen, t, int64(len(nl.Val().U.(string))))
} else if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
// nlen already initialized
} else {
Expand All @@ -1431,7 +1431,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Regalloc(&n3, Types[Tptr], res)
p1 := Thearch.Gins(Thearch.Optoas(OAS, n3.Type), nil, &n3) // XXX was LEAQ!
Datastring(nl.Val.U.(string), &p1.From)
Datastring(nl.Val().U.(string), &p1.From)
p1.From.Type = obj.TYPE_ADDR
Thearch.Gins(Thearch.Optoas(OADD, n3.Type), &n2, &n3)
goto indexdone
Expand Down Expand Up @@ -1718,7 +1718,7 @@ func Igen(n *Node, a *Node, res *Node) {
// Compute &a[i] as &a + i*width.
a.Type = n.Type

a.Xoffset += Mpgetfix(n.Right.Val.U.(*Mpint)) * n.Type.Width
a.Xoffset += Mpgetfix(n.Right.Val().U.(*Mpint)) * n.Type.Width
Fixlargeoffset(a)
return
}
Expand Down Expand Up @@ -1868,11 +1868,11 @@ func bgenx(n, res *Node, wantTrue bool, likely int, to *obj.Prog) {
Fatal("bgen: non-bool const %v\n", Nconv(n, obj.FmtLong))
}
if genval {
Cgen(Nodbool(wantTrue == n.Val.U.(bool)), res)
Cgen(Nodbool(wantTrue == n.Val().U.(bool)), res)
return
}
// If n == wantTrue, jump; otherwise do nothing.
if wantTrue == n.Val.U.(bool) {
if wantTrue == n.Val().U.(bool) {
Patch(Gbranch(obj.AJMP, nil, likely), to)
}
return
Expand Down Expand Up @@ -2206,7 +2206,7 @@ func stkof(n *Node) int64 {
return off
}
if Isconst(n.Right, CTINT) {
return off + t.Type.Width*Mpgetfix(n.Right.Val.U.(*Mpint))
return off + t.Type.Width*Mpgetfix(n.Right.Val().U.(*Mpint))
}
return +1000 // on stack but not sure exactly where

Expand Down Expand Up @@ -2661,7 +2661,7 @@ func cgen_div(op int, nl *Node, nr *Node, res *Node) {
case TUINT64:
var m Magic
m.W = w
m.Ud = uint64(Mpgetfix(nr.Val.U.(*Mpint)))
m.Ud = uint64(Mpgetfix(nr.Val().U.(*Mpint)))
Umagic(&m)
if m.Bad != 0 {
break
Expand Down Expand Up @@ -2699,7 +2699,7 @@ func cgen_div(op int, nl *Node, nr *Node, res *Node) {
case TINT64:
var m Magic
m.W = w
m.Sd = Mpgetfix(nr.Val.U.(*Mpint))
m.Sd = Mpgetfix(nr.Val().U.(*Mpint))
Smagic(&m)
if m.Bad != 0 {
break
Expand Down Expand Up @@ -3048,7 +3048,7 @@ func cgen_slice(n, res *Node, wb bool) {
return
}
if n.Op == OSLICESTR && Isconst(n.Left, CTSTR) {
Nodconst(&xlen, indexRegType, int64(len(n.Left.Val.U.(string))))
Nodconst(&xlen, indexRegType, int64(len(n.Left.Val().U.(string))))
return
}
regalloc(&xlen, indexRegType, nil)
Expand Down Expand Up @@ -3204,20 +3204,20 @@ func cgen_slice(n, res *Node, wb bool) {
if n.Op == OSLICEARR || n.Op == OSLICE3ARR {
bound = n.Left.Type.Type.Bound
} else if n.Op == OSLICESTR && Isconst(n.Left, CTSTR) {
bound = int64(len(n.Left.Val.U.(string)))
bound = int64(len(n.Left.Val().U.(string)))
}
if Isconst(&i, CTINT) {
if mpcmpfixc(i.Val.U.(*Mpint), 0) < 0 || bound >= 0 && mpcmpfixc(i.Val.U.(*Mpint), bound) > 0 {
if mpcmpfixc(i.Val().U.(*Mpint), 0) < 0 || bound >= 0 && mpcmpfixc(i.Val().U.(*Mpint), bound) > 0 {
Yyerror("slice index out of bounds")
}
}
if Isconst(&j, CTINT) {
if mpcmpfixc(j.Val.U.(*Mpint), 0) < 0 || bound >= 0 && mpcmpfixc(j.Val.U.(*Mpint), bound) > 0 {
if mpcmpfixc(j.Val().U.(*Mpint), 0) < 0 || bound >= 0 && mpcmpfixc(j.Val().U.(*Mpint), bound) > 0 {
Yyerror("slice index out of bounds")
}
}
if Isconst(&k, CTINT) {
if mpcmpfixc(k.Val.U.(*Mpint), 0) < 0 || bound >= 0 && mpcmpfixc(k.Val.U.(*Mpint), bound) > 0 {
if mpcmpfixc(k.Val().U.(*Mpint), 0) < 0 || bound >= 0 && mpcmpfixc(k.Val().U.(*Mpint), bound) > 0 {
Yyerror("slice index out of bounds")
}
}
Expand All @@ -3226,7 +3226,7 @@ func cgen_slice(n, res *Node, wb bool) {
same := func(n1, n2 *Node) bool {
return n1.Op == OREGISTER && n2.Op == OREGISTER && n1.Reg == n2.Reg ||
n1.Op == ONAME && n2.Op == ONAME && n1.Orig == n2.Orig && n1.Type == n2.Type && n1.Xoffset == n2.Xoffset ||
n1.Op == OLITERAL && n2.Op == OLITERAL && Mpcmpfixfix(n1.Val.U.(*Mpint), n2.Val.U.(*Mpint)) == 0
n1.Op == OLITERAL && n2.Op == OLITERAL && Mpcmpfixfix(n1.Val().U.(*Mpint), n2.Val().U.(*Mpint)) == 0
}

// obvious reports whether n1 <= n2 is obviously true,
Expand All @@ -3245,7 +3245,7 @@ func cgen_slice(n, res *Node, wb bool) {
return true // len(x) <= cap(x) always true
}
if Isconst(n1, CTINT) && Isconst(n2, CTINT) {
if Mpcmpfixfix(n1.Val.U.(*Mpint), n2.Val.U.(*Mpint)) <= 0 {
if Mpcmpfixfix(n1.Val().U.(*Mpint), n2.Val().U.(*Mpint)) <= 0 {
return true // n1, n2 constants such that n1 <= n2
}
Yyerror("slice index out of bounds")
Expand All @@ -3258,11 +3258,11 @@ func cgen_slice(n, res *Node, wb bool) {
// n1 might be a 64-bit constant, even on 32-bit architectures,
// but it will be represented in 32 bits.
if Ctxt.Arch.Regsize == 4 && Is64(n1.Type) {
if mpcmpfixc(n1.Val.U.(*Mpint), 1<<31) >= 0 {
if mpcmpfixc(n1.Val().U.(*Mpint), 1<<31) >= 0 {
Fatal("missed slice out of bounds check")
}
var tmp Node
Nodconst(&tmp, indexRegType, Mpgetfix(n1.Val.U.(*Mpint)))
Nodconst(&tmp, indexRegType, Mpgetfix(n1.Val().U.(*Mpint)))
n1 = &tmp
}
p := Thearch.Ginscmp(OGT, indexRegType, n1, n2, -1)
Expand Down Expand Up @@ -3346,9 +3346,9 @@ func cgen_slice(n, res *Node, wb bool) {
switch j.Op {
case OLITERAL:
if Isconst(&i, CTINT) {
Nodconst(&j, indexRegType, Mpgetfix(j.Val.U.(*Mpint))-Mpgetfix(i.Val.U.(*Mpint)))
Nodconst(&j, indexRegType, Mpgetfix(j.Val().U.(*Mpint))-Mpgetfix(i.Val().U.(*Mpint)))
if Debug_slice > 0 {
Warn("slice: result len == %d", Mpgetfix(j.Val.U.(*Mpint)))
Warn("slice: result len == %d", Mpgetfix(j.Val().U.(*Mpint)))
}
break
}
Expand All @@ -3363,7 +3363,7 @@ func cgen_slice(n, res *Node, wb bool) {
fallthrough
case OREGISTER:
if i.Op == OLITERAL {
v := Mpgetfix(i.Val.U.(*Mpint))
v := Mpgetfix(i.Val().U.(*Mpint))
if v != 0 {
ginscon(Thearch.Optoas(OSUB, indexRegType), v, &j)
}
Expand Down Expand Up @@ -3406,9 +3406,9 @@ func cgen_slice(n, res *Node, wb bool) {
switch k.Op {
case OLITERAL:
if Isconst(&i, CTINT) {
Nodconst(&k, indexRegType, Mpgetfix(k.Val.U.(*Mpint))-Mpgetfix(i.Val.U.(*Mpint)))
Nodconst(&k, indexRegType, Mpgetfix(k.Val().U.(*Mpint))-Mpgetfix(i.Val().U.(*Mpint)))
if Debug_slice > 0 {
Warn("slice: result cap == %d", Mpgetfix(k.Val.U.(*Mpint)))
Warn("slice: result cap == %d", Mpgetfix(k.Val().U.(*Mpint)))
}
break
}
Expand All @@ -3429,7 +3429,7 @@ func cgen_slice(n, res *Node, wb bool) {
Warn("slice: result cap == 0")
}
} else if i.Op == OLITERAL {
v := Mpgetfix(i.Val.U.(*Mpint))
v := Mpgetfix(i.Val().U.(*Mpint))
if v != 0 {
ginscon(Thearch.Optoas(OSUB, indexRegType), v, &k)
}
Expand Down Expand Up @@ -3512,7 +3512,7 @@ func cgen_slice(n, res *Node, wb bool) {
w = res.Type.Type.Width // res is []T, elem size is T.width
}
if Isconst(&i, CTINT) {
ginscon(Thearch.Optoas(OADD, xbase.Type), Mpgetfix(i.Val.U.(*Mpint))*w, &xbase)
ginscon(Thearch.Optoas(OADD, xbase.Type), Mpgetfix(i.Val().U.(*Mpint))*w, &xbase)
} else if Thearch.AddIndex != nil && Thearch.AddIndex(&i, w, &xbase) {
// done by back end
} else if w == 1 {
Expand Down
Loading

0 comments on commit 81d5810

Please sign in to comment.