From 8f1fdf33ded3511f9d150c5b5e931ceccbf81762 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 21 Nov 2013 14:19:38 -0500 Subject: [PATCH] =?UTF-8?q?go.tools/ssa:=20opt:=20improve=20the=20"unused?= =?UTF-8?q?=20=CF=86-node"=20check=20to=20eliminate=20self-refs,=20debug-r?= =?UTF-8?q?efs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- oracle/testdata/src/main/describe-json.go | 2 +- oracle/testdata/src/main/describe-json.golden | 2 +- oracle/testdata/src/main/describe.go | 2 +- ssa/lift.go | 17 +++++++++++++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/oracle/testdata/src/main/describe-json.go b/oracle/testdata/src/main/describe-json.go index 56c29321a95..906bfaf8f0f 100644 --- a/oracle/testdata/src/main/describe-json.go +++ b/oracle/testdata/src/main/describe-json.go @@ -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" } diff --git a/oracle/testdata/src/main/describe-json.golden b/oracle/testdata/src/main/describe-json.golden index 48b85f0b687..db917ee90a4 100644 --- a/oracle/testdata/src/main/describe-json.golden +++ b/oracle/testdata/src/main/describe-json.golden @@ -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", diff --git a/oracle/testdata/src/main/describe.go b/oracle/testdata/src/main/describe.go index ed4eea6b1fe..20a04b16d53 100644 --- a/oracle/testdata/src/main/describe.go +++ b/oracle/testdata/src/main/describe.go @@ -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" diff --git a/ssa/lift.go b/ssa/lift.go index 3a68c129bd4..3cf1e041962 100644 --- a/ssa/lift.go +++ b/ssa/lift.go @@ -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.