mirror of
https://github.com/golang/go
synced 2024-09-30 03:24:39 -06:00
cmd/compile: add ssa.Block.truncateValues
It is a common operation. Passes toolstash-check. Change-Id: Icc34600b0f79d0ecb19f257e3c7f23b6f01a26ab Reviewed-on: https://go-review.googlesource.com/c/go/+/229599 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
806318d6ad
commit
e354309e1e
@ -256,6 +256,17 @@ func (b *Block) resetWithControl2(kind BlockKind, v, w *Value) {
|
||||
w.Uses++
|
||||
}
|
||||
|
||||
// truncateValues truncates b.Values at the ith element, zeroing subsequent elements.
|
||||
// The values in b.Values after i must already have had their args reset,
|
||||
// to maintain correct value uses counts.
|
||||
func (b *Block) truncateValues(i int) {
|
||||
tail := b.Values[i:]
|
||||
for j := range tail {
|
||||
tail[j] = nil
|
||||
}
|
||||
b.Values = b.Values[:i]
|
||||
}
|
||||
|
||||
// AddEdgeTo adds an edge from block b to block c. Used during building of the
|
||||
// SSA graph; do not use on an already-completed SSA graph.
|
||||
func (b *Block) AddEdgeTo(c *Block) {
|
||||
|
@ -296,12 +296,7 @@ func deadcode(f *Func) {
|
||||
f.freeValue(v)
|
||||
}
|
||||
}
|
||||
// aid GC
|
||||
tail := b.Values[i:]
|
||||
for j := range tail {
|
||||
tail[j] = nil
|
||||
}
|
||||
b.Values = b.Values[:i]
|
||||
b.truncateValues(i)
|
||||
}
|
||||
|
||||
// Remove dead blocks from WBLoads list.
|
||||
|
@ -171,10 +171,7 @@ func nilcheckelim(f *Func) {
|
||||
b.Pos = b.Pos.WithIsStmt()
|
||||
pendingLines.remove(b.Pos)
|
||||
}
|
||||
for j := i; j < len(b.Values); j++ {
|
||||
b.Values[j] = nil
|
||||
}
|
||||
b.Values = b.Values[:i]
|
||||
b.truncateValues(i)
|
||||
|
||||
// Add all dominated blocks to the work list.
|
||||
for w := sdom[node.block.ID].child; w != nil; w = sdom[w.ID].sibling {
|
||||
@ -331,10 +328,7 @@ func nilcheckelim2(f *Func) {
|
||||
b.Pos = b.Pos.WithIsStmt()
|
||||
}
|
||||
|
||||
for j := i; j < len(b.Values); j++ {
|
||||
b.Values[j] = nil
|
||||
}
|
||||
b.Values = b.Values[:i]
|
||||
b.truncateValues(i)
|
||||
|
||||
// TODO: if b.Kind == BlockPlain, start the analysis in the subsequent block to find
|
||||
// more unnecessary nil checks. Would fix test/nilptr3.go:159.
|
||||
|
@ -152,13 +152,7 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter) {
|
||||
b.Pos = b.Pos.WithIsStmt()
|
||||
pendingLines.remove(b.Pos)
|
||||
}
|
||||
if j != len(b.Values) {
|
||||
tail := b.Values[j:]
|
||||
for j := range tail {
|
||||
tail[j] = nil
|
||||
}
|
||||
b.Values = b.Values[:j]
|
||||
}
|
||||
b.truncateValues(j)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user