]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: enable deadcode of unreferenced large global maps
authorThan McIntosh <thanm@google.com>
Tue, 10 Jan 2023 15:21:16 +0000 (10:21 -0500)
committerThan McIntosh <thanm@google.com>
Mon, 6 Feb 2023 20:53:29 +0000 (20:53 +0000)
commitb46e44a399045d0177dd063dc192168f0b5b3f55
tree43aafa46b76ee6f8d1302475e4a331c83c6716ff
parent103f37497f2927eeb510789f63fe2a0319b6a49a
cmd/compile: enable deadcode of unreferenced large global maps

This patch changes the compiler's pkg init machinery to pick out large
initialization assignments to global maps (e.g.

   var mymap = map[string]int{"foo":1, "bar":2, ... }

and extract the map init code into a separate outlined function, which is
then called from the main init function with a weak relocation:

   var mymap map[string]int   // KEEP reloc -> map.init.0

   func init() {
      map.init.0() // weak relocation
   }

   func map.init.0() {
     mymap = map[string]int{"foo":1, "bar":2}
   }

The map init outlining is done selectively (only in the case where the
RHS code exceeds a size limit of 20 IR nodes).

In order to ensure that a given map.init.NNN function is included when
its corresponding map is live, we add dummy R_KEEP relocation from the
map variable to the map init function.

This first patch includes the main compiler compiler changes, and with
the weak relocation addition disabled. Subsequent patch includes the
requred linker changes along with switching to the call to the
outlined routine to a weak relocation. See the later linker change for
associated compile time performance numbers.

Updates #2559.
Updates #36021.
Updates #14840.

Change-Id: I1fd6fd6397772be1ebd3eb397caf68ae9a3147e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/461315
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/base/debug.go
src/cmd/compile/internal/base/flag.go
src/cmd/compile/internal/gc/compile.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/pkginit/init.go
src/cmd/compile/internal/ssagen/pgen.go
src/cmd/compile/internal/staticinit/sched.go