mirror of
https://github.com/golang/go
synced 2024-10-01 05: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:
parent
ef434a14da
commit
8f1fdf33de
2
oracle/testdata/src/main/describe-json.go
vendored
2
oracle/testdata/src/main/describe-json.go
vendored
@ -15,7 +15,7 @@ func main() { //
|
|||||||
if i == nil {
|
if i == nil {
|
||||||
i = new(D)
|
i = new(D)
|
||||||
}
|
}
|
||||||
_ = i // @describe desc-val-i "i"
|
print(i) // @describe desc-val-i "\\bi\\b"
|
||||||
|
|
||||||
go main() // @describe desc-stmt "go"
|
go main() // @describe desc-stmt "go"
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
"mode": "describe",
|
"mode": "describe",
|
||||||
"describe": {
|
"describe": {
|
||||||
"desc": "identifier",
|
"desc": "identifier",
|
||||||
"pos": "testdata/src/main/describe-json.go:18:6",
|
"pos": "testdata/src/main/describe-json.go:18:8",
|
||||||
"detail": "value",
|
"detail": "value",
|
||||||
"value": {
|
"value": {
|
||||||
"type": "I",
|
"type": "I",
|
||||||
|
2
oracle/testdata/src/main/describe.go
vendored
2
oracle/testdata/src/main/describe.go
vendored
@ -45,7 +45,7 @@ func main() { // @describe func-def-main "main"
|
|||||||
if i != nil {
|
if i != nil {
|
||||||
i = D{} // @describe var-ref-i-D "i"
|
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 objects
|
||||||
const localpi = 3.141 // @describe const-local-pi "localpi"
|
const localpi = 3.141 // @describe const-local-pi "localpi"
|
||||||
|
17
ssa/lift.go
17
ssa/lift.go
@ -209,8 +209,8 @@ func lift(fn *Function) {
|
|||||||
nps := newPhis[b]
|
nps := newPhis[b]
|
||||||
j := 0
|
j := 0
|
||||||
for _, np := range nps {
|
for _, np := range nps {
|
||||||
if len(*np.phi.Referrers()) == 0 {
|
if !phiIsLive(np.phi) {
|
||||||
continue // unreferenced phi
|
continue // discard it
|
||||||
}
|
}
|
||||||
nps[j] = np
|
nps[j] = np
|
||||||
j++
|
j++
|
||||||
@ -266,6 +266,19 @@ func lift(fn *Function) {
|
|||||||
fn.Locals = fn.Locals[:j]
|
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)
|
type blockSet struct{ big.Int } // (inherit methods from Int)
|
||||||
|
|
||||||
// add adds b to the set and returns true if the set changed.
|
// add adds b to the set and returns true if the set changed.
|
||||||
|
Loading…
Reference in New Issue
Block a user