github.com/mh-cbon/go@v0.0.0-20160603070303-9e112a3fe4c0/src/cmd/compile/internal/ssa/trim.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package ssa 6 7 // trim removes blocks with no code in them. 8 // These blocks were inserted to remove critical edges. 9 func trim(f *Func) { 10 n := 0 11 for _, b := range f.Blocks { 12 if b.Kind != BlockPlain || len(b.Values) != 0 || len(b.Preds) != 1 { 13 f.Blocks[n] = b 14 n++ 15 continue 16 } 17 // TODO: handle len(b.Preds)>1 case. 18 19 // Splice b out of the graph. 20 p := b.Preds[0].b 21 i := b.Preds[0].i 22 s := b.Succs[0].b 23 j := b.Succs[0].i 24 p.Succs[i] = Edge{s, j} 25 s.Preds[j] = Edge{p, i} 26 } 27 tail := f.Blocks[n:] 28 for i := range tail { 29 tail[i] = nil 30 } 31 f.Blocks = f.Blocks[:n] 32 }