cmd/link: run generator functions along with symbol writing

Like we do for applying relocations, for generator symbols, run
the generator function along with symbol writing. This will
probably have better locality and parallelism.

Linking cmd/compile,

Asmb          29.9ms ± 5%    19.1ms ±12%  -36.18%  (p=0.000 n=10+9)
TotalTime      351ms ± 3%     339ms ± 2%   -3.51%  (p=0.000 n=11+10)

Change-Id: I9cda6718bf70b3bcf1b7a501a845d6136234d2ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/263640
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2020-10-17 14:00:35 -04:00
parent 2ff9e01d72
commit 06839e3c9a
2 changed files with 3 additions and 12 deletions

View File

@ -951,6 +951,9 @@ func writeBlock(ctxt *Link, out *OutBuf, ldr *loader.Loader, syms []loader.Sym,
}
P := out.WriteSym(ldr, s)
st.relocsym(s, P)
if f, ok := ctxt.generatorSyms[s]; ok {
f(ctxt, s)
}
addr += int64(len(P))
siz := ldr.SymSize(s)
if addr < val+siz {

View File

@ -36,14 +36,12 @@ import (
"cmd/internal/objabi"
"cmd/internal/sys"
"cmd/link/internal/benchmark"
"cmd/link/internal/loader"
"flag"
"log"
"os"
"runtime"
"runtime/pprof"
"strings"
"sync"
)
var (
@ -331,16 +329,6 @@ func Main(arch *sys.Arch, theArch Arch) {
// will be applied directly there.
bench.Start("Asmb")
asmb(ctxt)
// Generate large symbols.
var wg sync.WaitGroup
for s, f := range ctxt.generatorSyms {
wg.Add(1)
go func(f generatorFunc, s loader.Sym) {
defer wg.Done()
f(ctxt, s)
}(f, s)
}
wg.Wait()
// Generate additional symbols for the native symbol table just prior
// to code generation.