diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-01-01 01:32:46 -0800 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-01-01 10:52:39 +0000 |
commit | 6ddbc75efd4bc2757e7684e7760ee411ec721e15 (patch) | |
tree | d61da828fa5a1af03d37bc756c11c61cdd7d0a46 /src/cmd/compile/internal/gc/main.go | |
parent | 68e6fa4f6852b4ef0fe61789618c093f4e2185c9 (diff) | |
download | go-6ddbc75efd4bc2757e7684e7760ee411ec721e15.tar.gz go-6ddbc75efd4bc2757e7684e7760ee411ec721e15.zip |
[dev.regabi] cmd/compile: earlier deadcode removal
This CL moves the general deadcode-removal pass to before computing
Addrtaken, which allows variables to still be converted to SSA if
their address is only taken in unreachable code paths (e.g., the "&mp"
expression in the "if false" block in runtime/os_linux.go:newosproc).
This doesn't pass toolstash -cmp, because it allows SSA to better
optimize some code.
Change-Id: I43e54acc02fdcbad8eb6493283f355aa1ee0de84
Reviewed-on: https://go-review.googlesource.com/c/go/+/280992
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/gc/main.go')
-rw-r--r-- | src/cmd/compile/internal/gc/main.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index c1f51e4f1d..2ea614e17f 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -213,6 +213,14 @@ func Main(archInit func(*ssagen.ArchInfo)) { typecheck.Export(initTask) } + // Eliminate some obviously dead code. + // Must happen after typechecking. + for _, n := range typecheck.Target.Decls { + if n.Op() == ir.ODCLFUNC { + deadcode.Func(n.(*ir.Func)) + } + } + // Compute Addrtaken for names. // We need to wait until typechecking is done so that when we see &x[i] // we know that x has its address taken if x is an array, but not if x is a slice. @@ -224,14 +232,6 @@ func Main(archInit func(*ssagen.ArchInfo)) { } typecheck.IncrementalAddrtaken = true - // Eliminate some obviously dead code. - // Must happen after typechecking. - for _, n := range typecheck.Target.Decls { - if n.Op() == ir.ODCLFUNC { - deadcode.Func(n.(*ir.Func)) - } - } - // Decide how to capture closed variables. // This needs to run before escape analysis, // because variables captured by value do not escape. |