[dev.ssa] cmd/compile: short-circuit empty blocks

Empty blocks are introduced to remove critical edges.
After regalloc, we can remove any of the added blocks
that are still empty.

Change-Id: I0b40e95ac3a6cc1e632a479443479532b6c5ccd9
Reviewed-on: https://go-review.googlesource.com/18833
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Keith Randall 2016-01-21 13:27:01 -08:00
parent 7730880f7c
commit 3c26c0db39
6 changed files with 63 additions and 8 deletions

View file

@ -0,0 +1,37 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ssa
// trim removes blocks with no code in them.
// These blocks were inserted to remove critical edges.
func trim(f *Func) {
i := 0
for _, b := range f.Blocks {
if b.Kind != BlockPlain || len(b.Values) != 0 || len(b.Preds) != 1 {
f.Blocks[i] = b
i++
continue
}
// TODO: handle len(b.Preds)>1 case.
// Splice b out of the graph.
pred := b.Preds[0]
succ := b.Succs[0]
for j, s := range pred.Succs {
if s == b {
pred.Succs[j] = succ
}
}
for j, p := range succ.Preds {
if p == b {
succ.Preds[j] = pred
}
}
}
for j := i; j < len(f.Blocks); j++ {
f.Blocks[j] = nil
}
f.Blocks = f.Blocks[:i]
}