diff options
author | Keith Randall <khr@golang.org> | 2016-01-21 13:27:01 -0800 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2016-01-22 22:12:12 +0000 |
commit | 3c26c0db3923451f1340e10524e985597da5bba2 (patch) | |
tree | a4b2d3a30b71eada624b458c65a17a058fec767a /src/cmd/compile/internal/ssa/trim.go | |
parent | 7730880f7ceda51c025a3c6bd296e1fa2de52318 (diff) | |
download | go-3c26c0db3923451f1340e10524e985597da5bba2.tar.gz go-3c26c0db3923451f1340e10524e985597da5bba2.zip |
[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>
Diffstat (limited to 'src/cmd/compile/internal/ssa/trim.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/trim.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/trim.go b/src/cmd/compile/internal/ssa/trim.go new file mode 100644 index 0000000000..594d2aa372 --- /dev/null +++ b/src/cmd/compile/internal/ssa/trim.go @@ -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] +} |