1
0
mirror of https://github.com/golang/go synced 2024-11-27 02:31:18 -07:00

cmd/compile/internal/coverage: merge Fixup{Vars,Init} into Fixup

There's no need for separate fixups phases anymore.

Change-Id: Ie30a75bda4d326aa9811db3b3bd1dade0b242706
Reviewed-on: https://go-review.googlesource.com/c/go/+/517858
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Matthew Dempsky 2023-08-09 09:21:56 -07:00 committed by Gopher Robot
parent e7e5913161
commit 3378adc517
2 changed files with 17 additions and 27 deletions

View File

@ -22,9 +22,9 @@ import (
"strings"
)
// Names records state information collected in the first fixup
// names records state information collected in the first fixup
// phase so that it can be passed to the second fixup phase.
type Names struct {
type names struct {
MetaVar *ir.Name
PkgIdVar *ir.Name
InitFn *ir.Func
@ -32,13 +32,17 @@ type Names struct {
CounterGran coverage.CounterGranularity
}
// FixupVars is the first of two entry points for coverage compiler
// fixup. It collects and returns the package ID and meta-data
// variables being used for this "-cover" build, along with the
// coverage counter mode and granularity. It also reclassifies selected
// variables (for example, tagging coverage counter variables with
// flags so that they can be handled properly downstream).
func FixupVars() Names {
// Fixup adds calls to the pkg init function as appropriate to
// register coverage-related variables with the runtime.
//
// It also reclassifies selected variables (for example, tagging
// coverage counter variables with flags so that they can be handled
// properly downstream).
func Fixup() {
if base.Flag.Cfg.CoverageInfo == nil {
return // not using coverage
}
metaVarName := base.Flag.Cfg.CoverageInfo.MetaVar
pkgIdVarName := base.Flag.Cfg.CoverageInfo.PkgIdVar
counterMode := base.Flag.Cfg.CoverageInfo.CounterMode
@ -92,18 +96,13 @@ func FixupVars() Names {
counterGran)
}
return Names{
cnames := names{
MetaVar: metavar,
PkgIdVar: pkgidvar,
CounterMode: cm,
CounterGran: cg,
}
}
// FixupInit is the second main entry point for coverage compiler
// fixup. It adds calls to the pkg init function as appropriate to
// register coverage-related variables with the runtime.
func FixupInit(cnames Names) {
for _, fn := range typecheck.Target.Funcs {
if ir.FuncName(fn) == "init" {
cnames.InitFn = fn
@ -144,7 +143,7 @@ func metaHashAndLen() ([16]byte, int) {
return hv, base.Flag.Cfg.CoverageInfo.MetaLen
}
func registerMeta(cnames Names, hashv [16]byte, mdlen int) {
func registerMeta(cnames names, hashv [16]byte, mdlen int) {
// Materialize expression for hash (an array literal)
pos := cnames.InitFn.Pos()
elist := make([]ir.Node, 0, 16)

View File

@ -211,21 +211,12 @@ func Main(archInit func(*ssagen.ArchInfo)) {
// because it generates itabs for initializing global variables.
ssagen.InitConfig()
// First part of coverage fixup (if applicable).
var cnames coverage.Names
if base.Flag.Cfg.CoverageInfo != nil {
cnames = coverage.FixupVars()
}
// Create "init" function for package-scope variable initialization
// statements, if any.
pkginit.MakeInit()
// Second part of code coverage fixup (init func modification),
// if applicable.
if base.Flag.Cfg.CoverageInfo != nil {
coverage.FixupInit(cnames)
}
// Apply coverage fixups, if applicable.
coverage.Fixup()
// Compute Addrtaken for names.
// We need to wait until typechecking is done so that when we see &x[i]