]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: rename cmd/compile/internal/pgo to cmd/compile/internal/pgoir
authorMichael Pratt <mpratt@google.com>
Tue, 5 Mar 2024 16:04:26 +0000 (11:04 -0500)
committerMichael Pratt <mpratt@google.com>
Wed, 27 Mar 2024 20:42:52 +0000 (20:42 +0000)
This helps reduce confusion with cmd/internal/pgo, which performs
compilation-independent analysis. pgoir associates that data with the
IR from the current package compilation.

For #58102.

Change-Id: I9ef1c8bc41db466d3340f41f6d071b95c09566de
Reviewed-on: https://go-review.googlesource.com/c/go/+/569338
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/devirtualize/pgo.go
src/cmd/compile/internal/devirtualize/pgo_test.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/inline/inl.go
src/cmd/compile/internal/inline/inlheur/analyze_func_callsites.go
src/cmd/compile/internal/inline/inlheur/scoring.go
src/cmd/compile/internal/inline/interleaved/interleaved.go
src/cmd/compile/internal/noder/unified.go
src/cmd/compile/internal/pgoir/irgraph.go [moved from src/cmd/compile/internal/pgo/irgraph.go with 99% similarity]

index 5cc9fab54c5c145d78773711a3c2c91a32385a9e..0a43135420b3993c4ca58b91c8af53e2fdf7e2ed 100644 (file)
@@ -9,7 +9,7 @@ import (
        "cmd/compile/internal/inline"
        "cmd/compile/internal/ir"
        "cmd/compile/internal/logopt"
-       "cmd/compile/internal/pgo"
+       "cmd/compile/internal/pgoir"
        "cmd/compile/internal/typecheck"
        "cmd/compile/internal/types"
        "cmd/internal/obj"
@@ -102,7 +102,7 @@ type CallStat struct {
 //
 // The primary benefit of this transformation is enabling inlining of the
 // direct call.
-func ProfileGuided(fn *ir.Func, p *pgo.Profile) {
+func ProfileGuided(fn *ir.Func, p *pgoir.Profile) {
        ir.CurFunc = fn
 
        name := ir.LinkFuncName(fn)
@@ -184,7 +184,7 @@ func ProfileGuided(fn *ir.Func, p *pgo.Profile) {
 // Devirtualize interface call if possible and eligible. Returns the new
 // ir.Node if call was devirtualized, and if so also the callee and weight of
 // the devirtualized edge.
-func maybeDevirtualizeInterfaceCall(p *pgo.Profile, fn *ir.Func, call *ir.CallExpr) (ir.Node, *ir.Func, int64) {
+func maybeDevirtualizeInterfaceCall(p *pgoir.Profile, fn *ir.Func, call *ir.CallExpr) (ir.Node, *ir.Func, int64) {
        if base.Debug.PGODevirtualize < 1 {
                return nil, nil, 0
        }
@@ -214,13 +214,13 @@ func maybeDevirtualizeInterfaceCall(p *pgo.Profile, fn *ir.Func, call *ir.CallEx
 // Devirtualize an indirect function call if possible and eligible. Returns the new
 // ir.Node if call was devirtualized, and if so also the callee and weight of
 // the devirtualized edge.
-func maybeDevirtualizeFunctionCall(p *pgo.Profile, fn *ir.Func, call *ir.CallExpr) (ir.Node, *ir.Func, int64) {
+func maybeDevirtualizeFunctionCall(p *pgoir.Profile, fn *ir.Func, call *ir.CallExpr) (ir.Node, *ir.Func, int64) {
        if base.Debug.PGODevirtualize < 2 {
                return nil, nil, 0
        }
 
        // Bail if this is a direct call; no devirtualization necessary.
-       callee := pgo.DirectCallee(call.Fun)
+       callee := pgoir.DirectCallee(call.Fun)
        if callee != nil {
                return nil, nil, 0
        }
@@ -309,7 +309,7 @@ func shouldPGODevirt(fn *ir.Func) bool {
                                        fmt.Printf("%v: should not PGO devirtualize %v: %s\n", ir.Line(fn), ir.FuncName(fn), reason)
                                }
                                if logopt.Enabled() {
-                                       logopt.LogOpt(fn.Pos(), ": should not PGO devirtualize function", "pgo-devirtualize", ir.FuncName(fn), reason)
+                                       logopt.LogOpt(fn.Pos(), ": should not PGO devirtualize function", "pgoir-devirtualize", ir.FuncName(fn), reason)
                                }
                        }
                }()
@@ -336,7 +336,7 @@ func shouldPGODevirt(fn *ir.Func) bool {
 // constructCallStat builds an initial CallStat describing this call, for
 // logging. If the call is devirtualized, the devirtualization fields should be
 // updated.
-func constructCallStat(p *pgo.Profile, fn *ir.Func, name string, call *ir.CallExpr) *CallStat {
+func constructCallStat(p *pgoir.Profile, fn *ir.Func, name string, call *ir.CallExpr) *CallStat {
        switch call.Op() {
        case ir.OCALLFUNC, ir.OCALLINTER, ir.OCALLMETH:
        default:
@@ -350,9 +350,9 @@ func constructCallStat(p *pgo.Profile, fn *ir.Func, name string, call *ir.CallEx
                Caller: name,
        }
 
-       offset := pgo.NodeLineOffset(call, fn)
+       offset := pgoir.NodeLineOffset(call, fn)
 
-       hotter := func(e *pgo.IREdge) bool {
+       hotter := func(e *pgoir.IREdge) bool {
                if stat.Hottest == "" {
                        return true
                }
@@ -384,7 +384,7 @@ func constructCallStat(p *pgo.Profile, fn *ir.Func, name string, call *ir.CallEx
        case ir.OCALLFUNC:
                stat.Interface = false
 
-               callee := pgo.DirectCallee(call.Fun)
+               callee := pgoir.DirectCallee(call.Fun)
                if callee != nil {
                        stat.Direct = true
                        if stat.Hottest == "" {
@@ -651,12 +651,12 @@ func interfaceCallRecvTypeAndMethod(call *ir.CallExpr) (*types.Type, *types.Sym)
 // if available, and its edge weight. extraFn can perform additional
 // applicability checks on each candidate edge. If extraFn returns false,
 // candidate will not be considered a valid callee candidate.
-func findHotConcreteCallee(p *pgo.Profile, caller *ir.Func, call *ir.CallExpr, extraFn func(callerName string, callOffset int, candidate *pgo.IREdge) bool) (*ir.Func, int64) {
+func findHotConcreteCallee(p *pgoir.Profile, caller *ir.Func, call *ir.CallExpr, extraFn func(callerName string, callOffset int, candidate *pgoir.IREdge) bool) (*ir.Func, int64) {
        callerName := ir.LinkFuncName(caller)
        callerNode := p.WeightedCG.IRNodes[callerName]
-       callOffset := pgo.NodeLineOffset(call, caller)
+       callOffset := pgoir.NodeLineOffset(call, caller)
 
-       var hottest *pgo.IREdge
+       var hottest *pgoir.IREdge
 
        // Returns true if e is hotter than hottest.
        //
@@ -664,7 +664,7 @@ func findHotConcreteCallee(p *pgo.Profile, caller *ir.Func, call *ir.CallExpr, e
        // has arbitrary iteration order, we need to apply additional sort
        // criteria when e.Weight == hottest.Weight to ensure we have stable
        // selection.
-       hotter := func(e *pgo.IREdge) bool {
+       hotter := func(e *pgoir.IREdge) bool {
                if hottest == nil {
                        return true
                }
@@ -747,10 +747,10 @@ func findHotConcreteCallee(p *pgo.Profile, caller *ir.Func, call *ir.CallExpr, e
 
 // findHotConcreteInterfaceCallee returns the *ir.Func of the hottest callee of an
 // interface call, if available, and its edge weight.
-func findHotConcreteInterfaceCallee(p *pgo.Profile, caller *ir.Func, call *ir.CallExpr) (*ir.Func, int64) {
+func findHotConcreteInterfaceCallee(p *pgoir.Profile, caller *ir.Func, call *ir.CallExpr) (*ir.Func, int64) {
        inter, method := interfaceCallRecvTypeAndMethod(call)
 
-       return findHotConcreteCallee(p, caller, call, func(callerName string, callOffset int, e *pgo.IREdge) bool {
+       return findHotConcreteCallee(p, caller, call, func(callerName string, callOffset int, e *pgoir.IREdge) bool {
                ctyp := methodRecvType(e.Dst.AST)
                if ctyp == nil {
                        // Not a method.
@@ -795,10 +795,10 @@ func findHotConcreteInterfaceCallee(p *pgo.Profile, caller *ir.Func, call *ir.Ca
 
 // findHotConcreteFunctionCallee returns the *ir.Func of the hottest callee of an
 // indirect function call, if available, and its edge weight.
-func findHotConcreteFunctionCallee(p *pgo.Profile, caller *ir.Func, call *ir.CallExpr) (*ir.Func, int64) {
+func findHotConcreteFunctionCallee(p *pgoir.Profile, caller *ir.Func, call *ir.CallExpr) (*ir.Func, int64) {
        typ := call.Fun.Type().Underlying()
 
-       return findHotConcreteCallee(p, caller, call, func(callerName string, callOffset int, e *pgo.IREdge) bool {
+       return findHotConcreteCallee(p, caller, call, func(callerName string, callOffset int, e *pgoir.IREdge) bool {
                ctyp := e.Dst.AST.Type().Underlying()
 
                // If ctyp doesn't match typ it is most likely from a different
index 6ba8e9f9072fcd59c47f841cc93bb128c7a1275c..cff4d63d51cc2ad42aedd8b9ca7035f5989ae1d1 100644 (file)
@@ -7,7 +7,7 @@ package devirtualize
 import (
        "cmd/compile/internal/base"
        "cmd/compile/internal/ir"
-       pgoir "cmd/compile/internal/pgo"
+       "cmd/compile/internal/pgoir"
        "cmd/compile/internal/typecheck"
        "cmd/compile/internal/types"
        "cmd/internal/obj"
index 7e5069fcedc26af486c43bbb549ae2c1bd4ed3cb..130feafb24427b0e6539853e73a15776e5761e96 100644 (file)
@@ -17,7 +17,7 @@ import (
        "cmd/compile/internal/logopt"
        "cmd/compile/internal/loopvar"
        "cmd/compile/internal/noder"
-       "cmd/compile/internal/pgo"
+       "cmd/compile/internal/pgoir"
        "cmd/compile/internal/pkginit"
        "cmd/compile/internal/reflectdata"
        "cmd/compile/internal/rttype"
@@ -215,10 +215,10 @@ func Main(archInit func(*ssagen.ArchInfo)) {
 
        // Read profile file and build profile-graph and weighted-call-graph.
        base.Timer.Start("fe", "pgo-load-profile")
-       var profile *pgo.Profile
+       var profile *pgoir.Profile
        if base.Flag.PgoProfile != "" {
                var err error
-               profile, err = pgo.New(base.Flag.PgoProfile)
+               profile, err = pgoir.New(base.Flag.PgoProfile)
                if err != nil {
                        log.Fatalf("%s: PGO error: %v", base.Flag.PgoProfile, err)
                }
index 33f454083f157c5b1fb21045fb555ec85a89512c..a17562596f9adf50e610780fbc6b7750b31c48df 100644 (file)
@@ -36,7 +36,7 @@ import (
        "cmd/compile/internal/inline/inlheur"
        "cmd/compile/internal/ir"
        "cmd/compile/internal/logopt"
-       pgoir "cmd/compile/internal/pgo"
+       "cmd/compile/internal/pgoir"
        "cmd/compile/internal/typecheck"
        "cmd/compile/internal/types"
        "cmd/internal/obj"
index 36ebe18b82f3fd29b01318bf413423e124382a1d..203578726ece4cd65fac7c1160a47eaa2a6ace74 100644 (file)
@@ -6,7 +6,7 @@ package inlheur
 
 import (
        "cmd/compile/internal/ir"
-       "cmd/compile/internal/pgo"
+       "cmd/compile/internal/pgoir"
        "cmd/compile/internal/typecheck"
        "fmt"
        "os"
@@ -220,7 +220,7 @@ func (cstb *callSiteTableBuilder) nodeVisitPre(n ir.Node) {
                }
        case ir.OCALLFUNC:
                ce := n.(*ir.CallExpr)
-               callee := pgo.DirectCallee(ce.Fun)
+               callee := pgoir.DirectCallee(ce.Fun)
                if callee != nil && callee.Inl != nil {
                        cstb.addCallSite(callee, ce)
                }
index 3de95d46b43162abf5f4f84c8f8229965d9a2342..3ef7c9b79af51a4a81eb158eb481fccdf514555f 100644 (file)
@@ -7,7 +7,7 @@ package inlheur
 import (
        "cmd/compile/internal/base"
        "cmd/compile/internal/ir"
-       "cmd/compile/internal/pgo"
+       "cmd/compile/internal/pgoir"
        "cmd/compile/internal/types"
        "fmt"
        "os"
@@ -638,7 +638,7 @@ var allCallSites CallSiteTab
 // of the function called, "CallerPos" is the position of the
 // callsite, and "ScoreFlags" is a digest of the specific properties
 // we used to make adjustments to callsite score via heuristics.
-func DumpInlCallSiteScores(profile *pgo.Profile, budgetCallback func(fn *ir.Func, profile *pgo.Profile) (int32, bool)) {
+func DumpInlCallSiteScores(profile *pgoir.Profile, budgetCallback func(fn *ir.Func, profile *pgoir.Profile) (int32, bool)) {
 
        var indirectlyDueToPromotion func(cs *CallSite) bool
        indirectlyDueToPromotion = func(cs *CallSite) bool {
index e55b0f1aeeb7b71a67fd4520b27c0a896ec34138..9b2efd7f2787cf45273b1507153f0efb2e9ed75a 100644 (file)
@@ -12,14 +12,14 @@ import (
        "cmd/compile/internal/inline"
        "cmd/compile/internal/inline/inlheur"
        "cmd/compile/internal/ir"
-       "cmd/compile/internal/pgo"
+       "cmd/compile/internal/pgoir"
        "cmd/compile/internal/typecheck"
        "fmt"
 )
 
 // DevirtualizeAndInlinePackage interleaves devirtualization and inlining on
 // all functions within pkg.
-func DevirtualizeAndInlinePackage(pkg *ir.Package, profile *pgo.Profile) {
+func DevirtualizeAndInlinePackage(pkg *ir.Package, profile *pgoir.Profile) {
        if profile != nil && base.Debug.PGODevirtualize > 0 {
                // TODO(mdempsky): Integrate into DevirtualizeAndInlineFunc below.
                ir.VisitFuncsBottomUp(typecheck.Target.Funcs, func(list []*ir.Func, recursive bool) {
@@ -34,7 +34,7 @@ func DevirtualizeAndInlinePackage(pkg *ir.Package, profile *pgo.Profile) {
                inlheur.SetupScoreAdjustments()
        }
 
-       var inlProfile *pgo.Profile // copy of profile for inlining
+       var inlProfile *pgoir.Profile // copy of profile for inlining
        if base.Debug.PGOInline != 0 {
                inlProfile = profile
        }
@@ -66,7 +66,7 @@ func DevirtualizeAndInlinePackage(pkg *ir.Package, profile *pgo.Profile) {
 
 // DevirtualizeAndInlineFunc interleaves devirtualization and inlining
 // on a single function.
-func DevirtualizeAndInlineFunc(fn *ir.Func, profile *pgo.Profile) {
+func DevirtualizeAndInlineFunc(fn *ir.Func, profile *pgoir.Profile) {
        ir.WithFunc(fn, func() {
                if base.Flag.LowerL != 0 {
                        if inlheur.Enabled() && !fn.Wrapper() {
index 492b00d256610da8ee0ae045fda8da574236a929..da04ac5a2a244819f7c76a493ea451330b0c1ffa 100644 (file)
@@ -15,7 +15,7 @@ import (
        "cmd/compile/internal/base"
        "cmd/compile/internal/inline"
        "cmd/compile/internal/ir"
-       "cmd/compile/internal/pgo"
+       "cmd/compile/internal/pgoir"
        "cmd/compile/internal/typecheck"
        "cmd/compile/internal/types"
        "cmd/compile/internal/types2"
@@ -175,7 +175,7 @@ func lookupMethod(pkg *types.Pkg, symName string) (*ir.Func, error) {
 func unified(m posMap, noders []*noder) {
        inline.InlineCall = unifiedInlineCall
        typecheck.HaveInlineBody = unifiedHaveInlineBody
-       pgo.LookupFunc = LookupFunc
+       pgoir.LookupFunc = LookupFunc
 
        data := writePkgStub(m, noders)
 
similarity index 99%
rename from src/cmd/compile/internal/pgo/irgraph.go
rename to src/cmd/compile/internal/pgoir/irgraph.go
index 418066f8ff1279dd02653d25bd0b5f2db31552f0..cb4333e6d7c675fd4b943a6f4d069348e0e44982 100644 (file)
@@ -38,7 +38,9 @@
 // //line directives that change line numbers in strange ways should be rare,
 // and failing PGO matching on these files is not too big of a loss.
 
-package pgo
+// Package pgoir assosciates a PGO profile with the IR of the current package
+// compilation.
+package pgoir
 
 import (
        "bufio"