Commit b9feb91f authored by Dave Cheney's avatar Dave Cheney

cmd/compile: minor cleanups

Some minor scoping cleanups found by a very old version of grind.

Change-Id: I1d373817586445fc87e38305929097b652696fdd
Reviewed-on: https://go-review.googlesource.com/21064
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 633e4143
...@@ -110,22 +110,21 @@ func cgen_wb(n, res *Node, wb bool) { ...@@ -110,22 +110,21 @@ func cgen_wb(n, res *Node, wb bool) {
return return
} }
var f int
if res.Ullman < UINF { if res.Ullman < UINF {
if Complexop(n, res) { if Complexop(n, res) {
Complexgen(n, res) Complexgen(n, res)
return return
} }
f = 1 // gen thru register f := true // gen thru register
switch n.Op { switch n.Op {
case OLITERAL: case OLITERAL:
if Smallintconst(n) { if Smallintconst(n) {
f = 0 f = false
} }
case OREGISTER: case OREGISTER:
f = 0 f = false
} }
if !Iscomplex[n.Type.Etype] && Ctxt.Arch.Regsize == 8 && !wb { if !Iscomplex[n.Type.Etype] && Ctxt.Arch.Regsize == 8 && !wb {
...@@ -133,7 +132,7 @@ func cgen_wb(n, res *Node, wb bool) { ...@@ -133,7 +132,7 @@ func cgen_wb(n, res *Node, wb bool) {
var addr obj.Addr var addr obj.Addr
if Thearch.Sudoaddable(a, res, &addr) { if Thearch.Sudoaddable(a, res, &addr) {
var p1 *obj.Prog var p1 *obj.Prog
if f != 0 { if f {
var n2 Node var n2 Node
Regalloc(&n2, res.Type, nil) Regalloc(&n2, res.Type, nil)
Cgen(n, &n2) Cgen(n, &n2)
......
...@@ -599,7 +599,6 @@ var keywords = map[string]int32{ ...@@ -599,7 +599,6 @@ var keywords = map[string]int32{
} }
func (l *lexer) number(c rune) { func (l *lexer) number(c rune) {
var str string
cp := &lexbuf cp := &lexbuf
cp.Reset() cp.Reset()
...@@ -643,6 +642,7 @@ func (l *lexer) number(c rune) { ...@@ -643,6 +642,7 @@ func (l *lexer) number(c rune) {
} }
// unless we have a hex number, parse fractional part or exponent, if any // unless we have a hex number, parse fractional part or exponent, if any
var str string
if !isInt { if !isInt {
isInt = true // assume int unless proven otherwise isInt = true // assume int unless proven otherwise
......
...@@ -3133,9 +3133,7 @@ func (p *parser) hidden_funarg() *Node { ...@@ -3133,9 +3133,7 @@ func (p *parser) hidden_funarg() *Node {
s3 := p.hidden_type() s3 := p.hidden_type()
s4 := p.oliteral() s4 := p.oliteral()
var t *Type t := typ(TARRAY)
t = typ(TARRAY)
t.Bound = -1 t.Bound = -1
t.Type = s3 t.Type = s3
...@@ -3159,19 +3157,16 @@ func (p *parser) hidden_structdcl() *Node { ...@@ -3159,19 +3157,16 @@ func (p *parser) hidden_structdcl() *Node {
s2 := p.hidden_type() s2 := p.hidden_type()
s3 := p.oliteral() s3 := p.oliteral()
var s *Sym
var pkg *Pkg
var ss *Node var ss *Node
if s1 != nil && s1.Name != "?" { if s1 != nil && s1.Name != "?" {
ss = Nod(ODCLFIELD, newname(s1), typenod(s2)) ss = Nod(ODCLFIELD, newname(s1), typenod(s2))
ss.SetVal(s3) ss.SetVal(s3)
} else { } else {
s = s2.Sym s := s2.Sym
if s == nil && Isptr[s2.Etype] { if s == nil && Isptr[s2.Etype] {
s = s2.Type.Sym s = s2.Type.Sym
} }
pkg = importpkg pkg := importpkg
if s1 != nil { if s1 != nil {
pkg = s1.Pkg pkg = s1.Pkg
} }
......
...@@ -1286,7 +1286,6 @@ loop2: ...@@ -1286,7 +1286,6 @@ loop2:
} }
nregion = 0 nregion = 0
region = region[:0] region = region[:0]
var rgp *Rgn
for f := firstf; f != nil; f = f.Link { for f := firstf; f != nil; f = f.Link {
r := f.Data.(*Reg) r := f.Data.(*Reg)
for z := 0; z < BITS; z++ { for z := 0; z < BITS; z++ {
...@@ -1347,16 +1346,14 @@ loop2: ...@@ -1347,16 +1346,14 @@ loop2:
if Debug['R'] != 0 && Debug['v'] != 0 { if Debug['R'] != 0 && Debug['v'] != 0 {
fmt.Printf("\nregisterizing\n") fmt.Printf("\nregisterizing\n")
} }
var usedreg uint64
var vreg uint64
for i := 0; i < nregion; i++ { for i := 0; i < nregion; i++ {
rgp = &region[i] rgp := &region[i]
if Debug['R'] != 0 && Debug['v'] != 0 { if Debug['R'] != 0 && Debug['v'] != 0 {
fmt.Printf("region %d: cost %d varno %d enter %d\n", i, rgp.cost, rgp.varno, rgp.enter.Prog.Pc) fmt.Printf("region %d: cost %d varno %d enter %d\n", i, rgp.cost, rgp.varno, rgp.enter.Prog.Pc)
} }
bit = blsh(uint(rgp.varno)) bit = blsh(uint(rgp.varno))
usedreg = paint2(rgp.enter, int(rgp.varno), 0) usedreg := paint2(rgp.enter, int(rgp.varno), 0)
vreg = allreg(usedreg, rgp) vreg := allreg(usedreg, rgp)
if rgp.regno != 0 { if rgp.regno != 0 {
if Debug['R'] != 0 && Debug['v'] != 0 { if Debug['R'] != 0 && Debug['v'] != 0 {
v := &vars[rgp.varno] v := &vars[rgp.varno]
......
...@@ -568,16 +568,14 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) { ...@@ -568,16 +568,14 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
index := r.Left index := r.Left
value := r.Right value := r.Right
var a *Node
switch value.Op { switch value.Op {
case OARRAYLIT: case OARRAYLIT:
if value.Type.Bound < 0 { if value.Type.Bound < 0 {
if pass == 1 && ctxt != 0 { if pass == 1 && ctxt != 0 {
a = NodSym(ODOT, var_, index.Sym) a := NodSym(ODOT, var_, index.Sym)
slicelit(ctxt, value, a, init) slicelit(ctxt, value, a, init)
} else if pass == 2 && ctxt == 0 { } else if pass == 2 && ctxt == 0 {
a = NodSym(ODOT, var_, index.Sym) a := NodSym(ODOT, var_, index.Sym)
slicelit(ctxt, value, a, init) slicelit(ctxt, value, a, init)
} else if pass == 3 { } else if pass == 3 {
break break
...@@ -585,12 +583,12 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) { ...@@ -585,12 +583,12 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
continue continue
} }
a = NodSym(ODOT, var_, index.Sym) a := NodSym(ODOT, var_, index.Sym)
arraylit(ctxt, pass, value, a, init) arraylit(ctxt, pass, value, a, init)
continue continue
case OSTRUCTLIT: case OSTRUCTLIT:
a = NodSym(ODOT, var_, index.Sym) a := NodSym(ODOT, var_, index.Sym)
structlit(ctxt, pass, value, a, init) structlit(ctxt, pass, value, a, init)
continue continue
} }
...@@ -605,7 +603,7 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) { ...@@ -605,7 +603,7 @@ func structlit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
// build list of var.field = expr // build list of var.field = expr
setlineno(value) setlineno(value)
a = NodSym(ODOT, var_, index.Sym) a := NodSym(ODOT, var_, index.Sym)
a = Nod(OAS, a, value) a = Nod(OAS, a, value)
a = typecheck(a, Etop) a = typecheck(a, Etop)
...@@ -632,16 +630,14 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) { ...@@ -632,16 +630,14 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
index := r.Left index := r.Left
value := r.Right value := r.Right
var a *Node
switch value.Op { switch value.Op {
case OARRAYLIT: case OARRAYLIT:
if value.Type.Bound < 0 { if value.Type.Bound < 0 {
if pass == 1 && ctxt != 0 { if pass == 1 && ctxt != 0 {
a = Nod(OINDEX, var_, index) a := Nod(OINDEX, var_, index)
slicelit(ctxt, value, a, init) slicelit(ctxt, value, a, init)
} else if pass == 2 && ctxt == 0 { } else if pass == 2 && ctxt == 0 {
a = Nod(OINDEX, var_, index) a := Nod(OINDEX, var_, index)
slicelit(ctxt, value, a, init) slicelit(ctxt, value, a, init)
} else if pass == 3 { } else if pass == 3 {
break break
...@@ -649,12 +645,12 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) { ...@@ -649,12 +645,12 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
continue continue
} }
a = Nod(OINDEX, var_, index) a := Nod(OINDEX, var_, index)
arraylit(ctxt, pass, value, a, init) arraylit(ctxt, pass, value, a, init)
continue continue
case OSTRUCTLIT: case OSTRUCTLIT:
a = Nod(OINDEX, var_, index) a := Nod(OINDEX, var_, index)
structlit(ctxt, pass, value, a, init) structlit(ctxt, pass, value, a, init)
continue continue
} }
...@@ -669,7 +665,7 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) { ...@@ -669,7 +665,7 @@ func arraylit(ctxt int, pass int, n *Node, var_ *Node, init *Nodes) {
// build list of var[index] = value // build list of var[index] = value
setlineno(value) setlineno(value)
a = Nod(OINDEX, var_, index) a := Nod(OINDEX, var_, index)
a = Nod(OAS, a, value) a = Nod(OAS, a, value)
a = typecheck(a, Etop) a = typecheck(a, Etop)
......
...@@ -178,8 +178,7 @@ func (c *Config) Warnl(line int32, msg string, args ...interface{}) { c.fe.Warnl ...@@ -178,8 +178,7 @@ func (c *Config) Warnl(line int32, msg string, args ...interface{}) { c.fe.Warnl
func (c *Config) Debug_checknil() bool { return c.fe.Debug_checknil() } func (c *Config) Debug_checknil() bool { return c.fe.Debug_checknil() }
func (c *Config) logDebugHashMatch(evname, name string) { func (c *Config) logDebugHashMatch(evname, name string) {
var file *os.File file := c.logfiles[evname]
file = c.logfiles[evname]
if file == nil { if file == nil {
file = os.Stdout file = os.Stdout
tmpfile := os.Getenv("GSHS_LOGFILE") tmpfile := os.Getenv("GSHS_LOGFILE")
......
...@@ -96,7 +96,6 @@ blockloop: ...@@ -96,7 +96,6 @@ blockloop:
continue blockloop continue blockloop
} }
} }
b.Fatalf("no block available for layout")
} }
f.Blocks = order f.Blocks = order
} }
...@@ -679,9 +679,8 @@ func (s *regAllocState) regalloc(f *Func) { ...@@ -679,9 +679,8 @@ func (s *regAllocState) regalloc(f *Func) {
} }
a := v.Args[idx] a := v.Args[idx]
m := s.values[a.ID].regs &^ phiUsed m := s.values[a.ID].regs &^ phiUsed
var r register
if m != 0 { if m != 0 {
r = pickReg(m) r := pickReg(m)
s.freeReg(r) s.freeReg(r)
phiUsed |= regMask(1) << r phiUsed |= regMask(1) << r
phiRegs = append(phiRegs, r) phiRegs = append(phiRegs, r)
......
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