Commit 7d10a2c0 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

[dev.ssa] cmd/compile/ssa: implement constant booleans

The removal of if false { ... } blocks in the opt
pass exposed that removePredecessor needed
to do more cleaning, on pain of failing later
consistency checks.

Change-Id: I45d4ff7e1f7f1486fdd99f867867ce6ea006a288
Reviewed-on: https://go-review.googlesource.com/11879Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent cc3f031a
...@@ -464,7 +464,7 @@ func (s *state) expr(n *Node) *ssa.Value { ...@@ -464,7 +464,7 @@ func (s *state) expr(n *Node) *ssa.Value {
switch n.Val().Ctype() { switch n.Val().Ctype() {
case CTINT: case CTINT:
return s.constInt(n.Type, Mpgetfix(n.Val().U.(*Mpint))) return s.constInt(n.Type, Mpgetfix(n.Val().U.(*Mpint)))
case CTSTR: case CTSTR, CTBOOL:
return s.entryNewValue0A(ssa.OpConst, n.Type, n.Val().U) return s.entryNewValue0A(ssa.OpConst, n.Type, n.Val().U)
default: default:
s.Unimplementedf("unhandled OLITERAL %v", n.Val().Ctype()) s.Unimplementedf("unhandled OLITERAL %v", n.Val().Ctype())
......
...@@ -98,38 +98,51 @@ func deadcode(f *Func) { ...@@ -98,38 +98,51 @@ func deadcode(f *Func) {
// There was an edge b->c. It has been removed from b's successors. // There was an edge b->c. It has been removed from b's successors.
// Fix up c to handle that fact. // Fix up c to handle that fact.
func removePredecessor(b, c *Block) { func (f *Func) removePredecessor(b, c *Block) {
n := len(c.Preds) - 1 work := [][2]*Block{{b, c}}
if n == 0 {
// c is now dead - don't bother working on it for len(work) > 0 {
if c.Preds[0] != b { b, c := work[0][0], work[0][1]
b.Fatalf("%s.Preds[0]==%s, want %s", c, c.Preds[0], b) work = work[1:]
}
return n := len(c.Preds) - 1
}
// find index of b in c's predecessor list // find index of b in c's predecessor list
var i int var i int
for j, p := range c.Preds { for j, p := range c.Preds {
if p == b { if p == b {
i = j i = j
break break
}
} }
}
c.Preds[i] = c.Preds[n] c.Preds[i] = c.Preds[n]
c.Preds[n] = nil // aid GC c.Preds[n] = nil // aid GC
c.Preds = c.Preds[:n] c.Preds = c.Preds[:n]
// rewrite phi ops to match the new predecessor list
for _, v := range c.Values { // rewrite phi ops to match the new predecessor list
if v.Op != OpPhi { for _, v := range c.Values {
continue if v.Op != OpPhi {
continue
}
v.Args[i] = v.Args[n]
v.Args[n] = nil // aid GC
v.Args = v.Args[:n]
if n == 1 {
v.Op = OpCopy
}
} }
v.Args[i] = v.Args[n]
v.Args[n] = nil // aid GC if n == 0 {
v.Args = v.Args[:n] // c is now dead--recycle its values
if n == 1 { for _, v := range c.Values {
v.Op = OpCopy f.vid.put(v.ID)
}
c.Values = nil
// Also kill any successors of c now, to spare later processing.
for _, succ := range c.Succs {
work = append(work, [2]*Block{c, succ})
}
} }
} }
} }
...@@ -232,7 +232,7 @@ func genRules(arch arch) { ...@@ -232,7 +232,7 @@ func genRules(arch arch) {
// Modify predecessor lists for no-longer-reachable blocks // Modify predecessor lists for no-longer-reachable blocks
for succ := range m { for succ := range m {
fmt.Fprintf(w, "removePredecessor(b, %s)\n", succ) fmt.Fprintf(w, "v.Block.Func.removePredecessor(b, %s)\n", succ)
} }
fmt.Fprintf(w, "b.Kind = %s\n", blockName(t[0], arch)) fmt.Fprintf(w, "b.Kind = %s\n", blockName(t[0], arch))
......
...@@ -46,7 +46,7 @@ func nilcheckelim(f *Func) { ...@@ -46,7 +46,7 @@ func nilcheckelim(f *Func) {
// and the fuse pass will join this block with its successor. // and the fuse pass will join this block with its successor.
b.Kind = BlockPlain b.Kind = BlockPlain
b.Control = nil b.Control = nil
removePredecessor(b, b.Succs[1]) f.removePredecessor(b, b.Succs[1])
b.Succs = b.Succs[:1] b.Succs = b.Succs[:1]
} }
} }
......
...@@ -403,7 +403,7 @@ func rewriteBlockgeneric(b *Block) bool { ...@@ -403,7 +403,7 @@ func rewriteBlockgeneric(b *Block) bool {
if !(c.(bool)) { if !(c.(bool)) {
goto end915e334b6388fed7d63e09aa69ecb05c goto end915e334b6388fed7d63e09aa69ecb05c
} }
removePredecessor(b, no) v.Block.Func.removePredecessor(b, no)
b.Kind = BlockPlain b.Kind = BlockPlain
b.Control = nil b.Control = nil
b.Succs = b.Succs[:1] b.Succs = b.Succs[:1]
...@@ -427,7 +427,7 @@ func rewriteBlockgeneric(b *Block) bool { ...@@ -427,7 +427,7 @@ func rewriteBlockgeneric(b *Block) bool {
if !(!c.(bool)) { if !(!c.(bool)) {
goto end6452ee3a5bb02c708bddc3181c3ea3cb goto end6452ee3a5bb02c708bddc3181c3ea3cb
} }
removePredecessor(b, yes) v.Block.Func.removePredecessor(b, yes)
b.Kind = BlockPlain b.Kind = BlockPlain
b.Control = nil b.Control = nil
b.Succs = b.Succs[:1] b.Succs = b.Succs[:1]
......
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