1
0
mirror of https://github.com/golang/go synced 2024-10-01 03:18:33 -06:00

go.tools/ssa: opt: improve the "unused φ-node" check to eliminate self-refs, debug-refs.

This removes about 5% of φ-nodes in one large program
and eliminates many zero-value constants.

(This does cause some Idents to no longer map to an ssa.Value.
This is observable in the oracle, whose tests are here updated.)

R=gri, gri
CC=golang-dev
https://golang.org/cl/26980043
This commit is contained in:
Alan Donovan 2013-11-21 14:19:38 -05:00
parent ef434a14da
commit 8f1fdf33de
4 changed files with 18 additions and 5 deletions

View File

@ -15,7 +15,7 @@ func main() { //
if i == nil {
i = new(D)
}
_ = i // @describe desc-val-i "i"
print(i) // @describe desc-val-i "\\bi\\b"
go main() // @describe desc-stmt "go"
}

View File

@ -98,7 +98,7 @@
"mode": "describe",
"describe": {
"desc": "identifier",
"pos": "testdata/src/main/describe-json.go:18:6",
"pos": "testdata/src/main/describe-json.go:18:8",
"detail": "value",
"value": {
"type": "I",

View File

@ -45,7 +45,7 @@ func main() { // @describe func-def-main "main"
if i != nil {
i = D{} // @describe var-ref-i-D "i"
}
_ = i // @describe var-ref-i "i"
print(i) // @describe var-ref-i "\\bi\\b"
// const objects
const localpi = 3.141 // @describe const-local-pi "localpi"

View File

@ -209,8 +209,8 @@ func lift(fn *Function) {
nps := newPhis[b]
j := 0
for _, np := range nps {
if len(*np.phi.Referrers()) == 0 {
continue // unreferenced phi
if !phiIsLive(np.phi) {
continue // discard it
}
nps[j] = np
j++
@ -266,6 +266,19 @@ func lift(fn *Function) {
fn.Locals = fn.Locals[:j]
}
func phiIsLive(phi *Phi) bool {
for _, instr := range *phi.Referrers() {
if instr == phi {
continue // self-refs don't count
}
if _, ok := instr.(*DebugRef); ok {
continue // debug refs don't count
}
return true
}
return false
}
type blockSet struct{ big.Int } // (inherit methods from Int)
// add adds b to the set and returns true if the set changed.