]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/coverage: merge Fixup{Vars,Init} into Fixup
authorMatthew Dempsky <mdempsky@google.com>
Wed, 9 Aug 2023 16:21:56 +0000 (09:21 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 11 Aug 2023 18:12:10 +0000 (18:12 +0000)
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>

src/cmd/compile/internal/coverage/cover.go
src/cmd/compile/internal/gc/main.go

index d17940fd4013c027d94db373b21120079b7a07e2..5320f004da60bddeb417ea853befe36f5a8aeb4b 100644 (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)
index 39505a37b1121351aab3e47ba2eaa69d2c9d3fac..c1090c58c17c3a7eb4c798d12e22d0941f04281f 100644 (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]