Skip to content

Commit 0c56120

Browse files
committed
cmd/compile: rename cmd/compile/internal/pgo to cmd/compile/internal/pgoir
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 63deaf0 commit 0c56120

File tree

9 files changed

+36
-34
lines changed

9 files changed

+36
-34
lines changed

src/cmd/compile/internal/devirtualize/pgo.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"cmd/compile/internal/inline"
1010
"cmd/compile/internal/ir"
1111
"cmd/compile/internal/logopt"
12-
"cmd/compile/internal/pgo"
12+
"cmd/compile/internal/pgoir"
1313
"cmd/compile/internal/typecheck"
1414
"cmd/compile/internal/types"
1515
"cmd/internal/obj"
@@ -102,7 +102,7 @@ type CallStat struct {
102102
//
103103
// The primary benefit of this transformation is enabling inlining of the
104104
// direct call.
105-
func ProfileGuided(fn *ir.Func, p *pgo.Profile) {
105+
func ProfileGuided(fn *ir.Func, p *pgoir.Profile) {
106106
ir.CurFunc = fn
107107

108108
name := ir.LinkFuncName(fn)
@@ -184,7 +184,7 @@ func ProfileGuided(fn *ir.Func, p *pgo.Profile) {
184184
// Devirtualize interface call if possible and eligible. Returns the new
185185
// ir.Node if call was devirtualized, and if so also the callee and weight of
186186
// the devirtualized edge.
187-
func maybeDevirtualizeInterfaceCall(p *pgo.Profile, fn *ir.Func, call *ir.CallExpr) (ir.Node, *ir.Func, int64) {
187+
func maybeDevirtualizeInterfaceCall(p *pgoir.Profile, fn *ir.Func, call *ir.CallExpr) (ir.Node, *ir.Func, int64) {
188188
if base.Debug.PGODevirtualize < 1 {
189189
return nil, nil, 0
190190
}
@@ -214,13 +214,13 @@ func maybeDevirtualizeInterfaceCall(p *pgo.Profile, fn *ir.Func, call *ir.CallEx
214214
// Devirtualize an indirect function call if possible and eligible. Returns the new
215215
// ir.Node if call was devirtualized, and if so also the callee and weight of
216216
// the devirtualized edge.
217-
func maybeDevirtualizeFunctionCall(p *pgo.Profile, fn *ir.Func, call *ir.CallExpr) (ir.Node, *ir.Func, int64) {
217+
func maybeDevirtualizeFunctionCall(p *pgoir.Profile, fn *ir.Func, call *ir.CallExpr) (ir.Node, *ir.Func, int64) {
218218
if base.Debug.PGODevirtualize < 2 {
219219
return nil, nil, 0
220220
}
221221

222222
// Bail if this is a direct call; no devirtualization necessary.
223-
callee := pgo.DirectCallee(call.Fun)
223+
callee := pgoir.DirectCallee(call.Fun)
224224
if callee != nil {
225225
return nil, nil, 0
226226
}
@@ -309,7 +309,7 @@ func shouldPGODevirt(fn *ir.Func) bool {
309309
fmt.Printf("%v: should not PGO devirtualize %v: %s\n", ir.Line(fn), ir.FuncName(fn), reason)
310310
}
311311
if logopt.Enabled() {
312-
logopt.LogOpt(fn.Pos(), ": should not PGO devirtualize function", "pgo-devirtualize", ir.FuncName(fn), reason)
312+
logopt.LogOpt(fn.Pos(), ": should not PGO devirtualize function", "pgoir-devirtualize", ir.FuncName(fn), reason)
313313
}
314314
}
315315
}()
@@ -336,7 +336,7 @@ func shouldPGODevirt(fn *ir.Func) bool {
336336
// constructCallStat builds an initial CallStat describing this call, for
337337
// logging. If the call is devirtualized, the devirtualization fields should be
338338
// updated.
339-
func constructCallStat(p *pgo.Profile, fn *ir.Func, name string, call *ir.CallExpr) *CallStat {
339+
func constructCallStat(p *pgoir.Profile, fn *ir.Func, name string, call *ir.CallExpr) *CallStat {
340340
switch call.Op() {
341341
case ir.OCALLFUNC, ir.OCALLINTER, ir.OCALLMETH:
342342
default:
@@ -350,9 +350,9 @@ func constructCallStat(p *pgo.Profile, fn *ir.Func, name string, call *ir.CallEx
350350
Caller: name,
351351
}
352352

353-
offset := pgo.NodeLineOffset(call, fn)
353+
offset := pgoir.NodeLineOffset(call, fn)
354354

355-
hotter := func(e *pgo.IREdge) bool {
355+
hotter := func(e *pgoir.IREdge) bool {
356356
if stat.Hottest == "" {
357357
return true
358358
}
@@ -384,7 +384,7 @@ func constructCallStat(p *pgo.Profile, fn *ir.Func, name string, call *ir.CallEx
384384
case ir.OCALLFUNC:
385385
stat.Interface = false
386386

387-
callee := pgo.DirectCallee(call.Fun)
387+
callee := pgoir.DirectCallee(call.Fun)
388388
if callee != nil {
389389
stat.Direct = true
390390
if stat.Hottest == "" {
@@ -651,20 +651,20 @@ func interfaceCallRecvTypeAndMethod(call *ir.CallExpr) (*types.Type, *types.Sym)
651651
// if available, and its edge weight. extraFn can perform additional
652652
// applicability checks on each candidate edge. If extraFn returns false,
653653
// candidate will not be considered a valid callee candidate.
654-
func findHotConcreteCallee(p *pgo.Profile, caller *ir.Func, call *ir.CallExpr, extraFn func(callerName string, callOffset int, candidate *pgo.IREdge) bool) (*ir.Func, int64) {
654+
func findHotConcreteCallee(p *pgoir.Profile, caller *ir.Func, call *ir.CallExpr, extraFn func(callerName string, callOffset int, candidate *pgoir.IREdge) bool) (*ir.Func, int64) {
655655
callerName := ir.LinkFuncName(caller)
656656
callerNode := p.WeightedCG.IRNodes[callerName]
657-
callOffset := pgo.NodeLineOffset(call, caller)
657+
callOffset := pgoir.NodeLineOffset(call, caller)
658658

659-
var hottest *pgo.IREdge
659+
var hottest *pgoir.IREdge
660660

661661
// Returns true if e is hotter than hottest.
662662
//
663663
// Naively this is just e.Weight > hottest.Weight, but because OutEdges
664664
// has arbitrary iteration order, we need to apply additional sort
665665
// criteria when e.Weight == hottest.Weight to ensure we have stable
666666
// selection.
667-
hotter := func(e *pgo.IREdge) bool {
667+
hotter := func(e *pgoir.IREdge) bool {
668668
if hottest == nil {
669669
return true
670670
}
@@ -747,10 +747,10 @@ func findHotConcreteCallee(p *pgo.Profile, caller *ir.Func, call *ir.CallExpr, e
747747

748748
// findHotConcreteInterfaceCallee returns the *ir.Func of the hottest callee of an
749749
// interface call, if available, and its edge weight.
750-
func findHotConcreteInterfaceCallee(p *pgo.Profile, caller *ir.Func, call *ir.CallExpr) (*ir.Func, int64) {
750+
func findHotConcreteInterfaceCallee(p *pgoir.Profile, caller *ir.Func, call *ir.CallExpr) (*ir.Func, int64) {
751751
inter, method := interfaceCallRecvTypeAndMethod(call)
752752

753-
return findHotConcreteCallee(p, caller, call, func(callerName string, callOffset int, e *pgo.IREdge) bool {
753+
return findHotConcreteCallee(p, caller, call, func(callerName string, callOffset int, e *pgoir.IREdge) bool {
754754
ctyp := methodRecvType(e.Dst.AST)
755755
if ctyp == nil {
756756
// Not a method.
@@ -795,10 +795,10 @@ func findHotConcreteInterfaceCallee(p *pgo.Profile, caller *ir.Func, call *ir.Ca
795795

796796
// findHotConcreteFunctionCallee returns the *ir.Func of the hottest callee of an
797797
// indirect function call, if available, and its edge weight.
798-
func findHotConcreteFunctionCallee(p *pgo.Profile, caller *ir.Func, call *ir.CallExpr) (*ir.Func, int64) {
798+
func findHotConcreteFunctionCallee(p *pgoir.Profile, caller *ir.Func, call *ir.CallExpr) (*ir.Func, int64) {
799799
typ := call.Fun.Type().Underlying()
800800

801-
return findHotConcreteCallee(p, caller, call, func(callerName string, callOffset int, e *pgo.IREdge) bool {
801+
return findHotConcreteCallee(p, caller, call, func(callerName string, callOffset int, e *pgoir.IREdge) bool {
802802
ctyp := e.Dst.AST.Type().Underlying()
803803

804804
// If ctyp doesn't match typ it is most likely from a different

src/cmd/compile/internal/devirtualize/pgo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package devirtualize
77
import (
88
"cmd/compile/internal/base"
99
"cmd/compile/internal/ir"
10-
pgoir "cmd/compile/internal/pgo"
10+
"cmd/compile/internal/pgoir"
1111
"cmd/compile/internal/typecheck"
1212
"cmd/compile/internal/types"
1313
"cmd/internal/obj"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"cmd/compile/internal/logopt"
1818
"cmd/compile/internal/loopvar"
1919
"cmd/compile/internal/noder"
20-
"cmd/compile/internal/pgo"
20+
"cmd/compile/internal/pgoir"
2121
"cmd/compile/internal/pkginit"
2222
"cmd/compile/internal/reflectdata"
2323
"cmd/compile/internal/rttype"
@@ -215,10 +215,10 @@ func Main(archInit func(*ssagen.ArchInfo)) {
215215

216216
// Read profile file and build profile-graph and weighted-call-graph.
217217
base.Timer.Start("fe", "pgo-load-profile")
218-
var profile *pgo.Profile
218+
var profile *pgoir.Profile
219219
if base.Flag.PgoProfile != "" {
220220
var err error
221-
profile, err = pgo.New(base.Flag.PgoProfile)
221+
profile, err = pgoir.New(base.Flag.PgoProfile)
222222
if err != nil {
223223
log.Fatalf("%s: PGO error: %v", base.Flag.PgoProfile, err)
224224
}

src/cmd/compile/internal/inline/inl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"cmd/compile/internal/inline/inlheur"
3737
"cmd/compile/internal/ir"
3838
"cmd/compile/internal/logopt"
39-
pgoir "cmd/compile/internal/pgo"
39+
"cmd/compile/internal/pgoir"
4040
"cmd/compile/internal/typecheck"
4141
"cmd/compile/internal/types"
4242
"cmd/internal/obj"

src/cmd/compile/internal/inline/inlheur/analyze_func_callsites.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package inlheur
66

77
import (
88
"cmd/compile/internal/ir"
9-
"cmd/compile/internal/pgo"
9+
"cmd/compile/internal/pgoir"
1010
"cmd/compile/internal/typecheck"
1111
"fmt"
1212
"os"
@@ -220,7 +220,7 @@ func (cstb *callSiteTableBuilder) nodeVisitPre(n ir.Node) {
220220
}
221221
case ir.OCALLFUNC:
222222
ce := n.(*ir.CallExpr)
223-
callee := pgo.DirectCallee(ce.Fun)
223+
callee := pgoir.DirectCallee(ce.Fun)
224224
if callee != nil && callee.Inl != nil {
225225
cstb.addCallSite(callee, ce)
226226
}

src/cmd/compile/internal/inline/inlheur/scoring.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package inlheur
77
import (
88
"cmd/compile/internal/base"
99
"cmd/compile/internal/ir"
10-
"cmd/compile/internal/pgo"
10+
"cmd/compile/internal/pgoir"
1111
"cmd/compile/internal/types"
1212
"fmt"
1313
"os"
@@ -638,7 +638,7 @@ var allCallSites CallSiteTab
638638
// of the function called, "CallerPos" is the position of the
639639
// callsite, and "ScoreFlags" is a digest of the specific properties
640640
// we used to make adjustments to callsite score via heuristics.
641-
func DumpInlCallSiteScores(profile *pgo.Profile, budgetCallback func(fn *ir.Func, profile *pgo.Profile) (int32, bool)) {
641+
func DumpInlCallSiteScores(profile *pgoir.Profile, budgetCallback func(fn *ir.Func, profile *pgoir.Profile) (int32, bool)) {
642642

643643
var indirectlyDueToPromotion func(cs *CallSite) bool
644644
indirectlyDueToPromotion = func(cs *CallSite) bool {

src/cmd/compile/internal/inline/interleaved/interleaved.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212
"cmd/compile/internal/inline"
1313
"cmd/compile/internal/inline/inlheur"
1414
"cmd/compile/internal/ir"
15-
"cmd/compile/internal/pgo"
15+
"cmd/compile/internal/pgoir"
1616
"cmd/compile/internal/typecheck"
1717
"fmt"
1818
)
1919

2020
// DevirtualizeAndInlinePackage interleaves devirtualization and inlining on
2121
// all functions within pkg.
22-
func DevirtualizeAndInlinePackage(pkg *ir.Package, profile *pgo.Profile) {
22+
func DevirtualizeAndInlinePackage(pkg *ir.Package, profile *pgoir.Profile) {
2323
if profile != nil && base.Debug.PGODevirtualize > 0 {
2424
// TODO(mdempsky): Integrate into DevirtualizeAndInlineFunc below.
2525
ir.VisitFuncsBottomUp(typecheck.Target.Funcs, func(list []*ir.Func, recursive bool) {
@@ -34,7 +34,7 @@ func DevirtualizeAndInlinePackage(pkg *ir.Package, profile *pgo.Profile) {
3434
inlheur.SetupScoreAdjustments()
3535
}
3636

37-
var inlProfile *pgo.Profile // copy of profile for inlining
37+
var inlProfile *pgoir.Profile // copy of profile for inlining
3838
if base.Debug.PGOInline != 0 {
3939
inlProfile = profile
4040
}
@@ -66,7 +66,7 @@ func DevirtualizeAndInlinePackage(pkg *ir.Package, profile *pgo.Profile) {
6666

6767
// DevirtualizeAndInlineFunc interleaves devirtualization and inlining
6868
// on a single function.
69-
func DevirtualizeAndInlineFunc(fn *ir.Func, profile *pgo.Profile) {
69+
func DevirtualizeAndInlineFunc(fn *ir.Func, profile *pgoir.Profile) {
7070
ir.WithFunc(fn, func() {
7171
if base.Flag.LowerL != 0 {
7272
if inlheur.Enabled() && !fn.Wrapper() {

src/cmd/compile/internal/noder/unified.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"cmd/compile/internal/base"
1616
"cmd/compile/internal/inline"
1717
"cmd/compile/internal/ir"
18-
"cmd/compile/internal/pgo"
18+
"cmd/compile/internal/pgoir"
1919
"cmd/compile/internal/typecheck"
2020
"cmd/compile/internal/types"
2121
"cmd/compile/internal/types2"
@@ -175,7 +175,7 @@ func lookupMethod(pkg *types.Pkg, symName string) (*ir.Func, error) {
175175
func unified(m posMap, noders []*noder) {
176176
inline.InlineCall = unifiedInlineCall
177177
typecheck.HaveInlineBody = unifiedHaveInlineBody
178-
pgo.LookupFunc = LookupFunc
178+
pgoir.LookupFunc = LookupFunc
179179

180180
data := writePkgStub(m, noders)
181181

src/cmd/compile/internal/pgo/irgraph.go renamed to src/cmd/compile/internal/pgoir/irgraph.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
// //line directives that change line numbers in strange ways should be rare,
3939
// and failing PGO matching on these files is not too big of a loss.
4040

41-
package pgo
41+
// Package pgoir assosciates a PGO profile with the IR of the current package
42+
// compilation.
43+
package pgoir
4244

4345
import (
4446
"bufio"

0 commit comments

Comments
 (0)