Skip to content

Commit de641ae

Browse files
author
Raj Barik
committed
Rename variables and update comments
1 parent e66786e commit de641ae

File tree

5 files changed

+27
-50
lines changed

5 files changed

+27
-50
lines changed

api/go1.19.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ pkg pgo/inline, func A() #43724
248248
pkg pgo/inline, func D(uint) int #43724
249249
pkg pgo/inline, func N(uint) *BS #43724
250250
pkg pgo/inline, func T(uint64) uint #43724
251+
pkg pgo/inline, type BS struct #43724
251252
pkg pgo/inline, method (*BS) NS(uint) (uint, bool) #43724
252253
pkg pgo/inline, method (*BS) S(uint) *BS #43724
253-
pkg pgo/inline, type BS struct #43724
254254
pkg regexp/syntax, const ErrNestingDepth = "expression nests too deeply" #51684
255255
pkg regexp/syntax, const ErrNestingDepth ErrorCode #51684
256256
pkg runtime/debug, func SetMemoryLimit(int64) int64 #48409

src/cmd/compile/internal/base/flag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ type CmdFlags struct {
122122
TrimPath string "help:\"remove `prefix` from recorded source file paths\""
123123
WB bool "help:\"enable write barrier\"" // TODO: remove
124124
ProfileUse string "help:\"read profile from `file`\""
125-
InlineHotThreshold string "help:\"Threshold percentage for determining hot methods for inlining\""
126-
HotCostThreshold int "help:\"Cost threshold for inlining hot methods\""
125+
InlineHotThreshold string "help:\"threshold percentage for determining hot methods and callsites for inlining\""
126+
InlineHotBudget int "help:\"inline budget for hot methods\""
127127

128128
// Configuration derived from flags; not a flag itself.
129129
Cfg struct {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,16 @@ func Main(archInit func(*ssagen.ArchInfo)) {
234234
typecheck.AllImportedBodies()
235235
}
236236

237-
// Read cpu profile file and build cross-package pprof-graph and per-package weighted-call-graph. Pprof-graph is built one-time.
237+
// Read cpu profile file and build cross-package pprof-graph and per-package weighted-call-graph.
238238
base.Timer.Start("fe", "profileuse")
239239
if base.Flag.ProfileUse != "" {
240240
if pgo.PProfGraph == nil {
241-
pgo.PProfGraph = pgo.BuildGlobalPProfGraph(base.Flag.ProfileUse, &profile.Options{
241+
pgo.PProfGraph = pgo.BuildPProfGraph(base.Flag.ProfileUse, &profile.Options{
242242
CallTree: false,
243243
SampleValue: func(v []int64) int64 { return v[1] },
244244
})
245245
}
246-
pgo.WeightedCG = pgo.BuildWeightedCallGraphPerPkg()
246+
pgo.WeightedCG = pgo.BuildWeightedCallGraph()
247247
}
248248

249249
// Inlining

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ import (
4646
const (
4747
inlineMaxBudget = 80
4848
// Budget increased due to hotness.
49-
inlineHotCalleeMaxBudget = 100
50-
inlineExtraAppendCost = 0
49+
inlineExtraAppendCost = 0
5150
// default is to inline if there's at most one call. -l=4 overrides this by using 1 instead.
5251
inlineExtraCallCost = 57 // 57 was benchmarked to provided most benefit with no bad surprises; see https://github.com/golang/go/issues/19348#issuecomment-439370742
5352
inlineExtraPanicCost = 1 // do not penalize inlining panics.
@@ -72,7 +71,7 @@ var (
7271
inlineHotThresholdPercent = float64(2)
7372

7473
// Budget increased due to hotness.
75-
inlineHotCalleeMaxBudget int32 = 160
74+
inlineHotMaxBudget int32 = 160
7675
)
7776

7877
// InlinePrologue records the hot callsites from ir-graph.
@@ -84,8 +83,8 @@ func InlinePrologue() {
8483
}
8584
}
8685

87-
if base.Flag.HotCostThreshold != 0 {
88-
inlineHotCalleeMaxBudget = int32(base.Flag.HotCostThreshold)
86+
if base.Flag.InlineHotBudget != 0 {
87+
inlineHotMaxBudget = int32(base.Flag.InlineHotBudget)
8988
}
9089

9190
ir.VisitFuncsBottomUp(typecheck.Target.Decls, func(list []*ir.Func, recursive bool) {
@@ -95,9 +94,6 @@ func InlinePrologue() {
9594
nodeweight := pgo.WeightInPercentage(n.Flat, pgo.GlobalTotalNodeWeight)
9695
if nodeweight > inlineHotThresholdPercent {
9796
n.HotNode = true
98-
if base.Flag.LowerM > 1 {
99-
fmt.Printf("hot-node=%v\n", name)
100-
}
10197
}
10298
for _, e := range pgo.WeightedCG.OutEdges[n] {
10399
if e.Weight != 0 {
@@ -109,18 +105,15 @@ func InlinePrologue() {
109105
canonicalName := ir.PkgFuncName(n.AST) + "-" + lineno + "-" + ir.PkgFuncName(e.Dst.AST)
110106
if _, ok := candHotEdgeMap[canonicalName]; !ok {
111107
candHotEdgeMap[canonicalName] = struct{}{}
112-
if base.Flag.LowerM > 1 {
113-
fmt.Printf("hot-inline cand=%v\n", canonicalName)
114-
}
115108
}
116109
}
117110
}
118111
}
119112
}
120113
}
121114
})
122-
if base.Flag.LowerM > 1 {
123-
fmt.Printf("hot-cg before inline in dot:")
115+
if base.Flag.LowerM > 4 {
116+
fmt.Printf("hot-cg before inline in dot format:")
124117
pgo.PrintWeightedCallGraphDOT(inlineHotThresholdPercent)
125118
}
126119
}
@@ -135,13 +128,13 @@ func InlineEpilogue() {
135128
}
136129
}
137130
})
138-
if base.Flag.LowerM > 1 {
131+
if base.Flag.LowerM > 4 {
139132
fmt.Printf("hot-cg after inline in dot:")
140133
pgo.PrintWeightedCallGraphDOT(inlineHotThresholdPercent)
141134
}
142135
}
143136

144-
// InlinePackage finds functions that can be inlined and clones them before walk expands them.
137+
// InlinePackage finds functions that can be inlined and clones them.
145138
func InlinePackage() {
146139
ir.VisitFuncsBottomUp(typecheck.Target.Decls, func(list []*ir.Func, recursive bool) {
147140
numfns := numNonClosures(list)
@@ -348,11 +341,11 @@ func (v *hairyVisitor) tooHairy(fn *ir.Func) bool {
348341
}
349342
if v.budget < 0 {
350343
if pgo.WeightedCG != nil {
351-
// Find the existing node in IRGraph.
344+
// Find the existing node in WeightedCallGraph.
352345
if n, ok := pgo.WeightedCG.IRNodes[ir.PkgFuncName(fn)]; ok {
353-
// If the cost of hot function is greater than inlineHotCalleeMaxBudget,
346+
// If the cost of hot function is greater than inlineHotMaxBudget,
354347
// the inliner won't inline this function.
355-
if inlineMaxBudget-v.budget < inlineHotCalleeMaxBudget && n.HotNode == true {
348+
if inlineMaxBudget-v.budget < inlineHotMaxBudget && n.HotNode == true {
356349
if base.Flag.LowerM > 1 {
357350
fmt.Printf("hot-node enabled increased budget for func=%v\n", ir.PkgFuncName(fn))
358351
}
@@ -844,9 +837,9 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlCalls *[]*ir.Inlin
844837
fmt.Sprintf("cost %d of %s exceeds max large caller cost %d", fn.Inl.Cost, ir.PkgFuncName(fn), maxCost))
845838
}
846839

847-
// If the callsite is hot and it is under the inlineHotCalleeMaxBudget budget, then inline it, or else bail.
840+
// If the callsite is hot and it is under the inlineHotMaxBudget budget, then inline it, or else bail.
848841
if _, ok := listOfHotCallSites[pgo.CallSiteInfo{ir.Line(n), ir.CurFunc}]; ok {
849-
if fn.Inl.Cost > inlineHotCalleeMaxBudget {
842+
if fn.Inl.Cost > inlineHotMaxBudget {
850843
return n
851844
}
852845
if base.Flag.LowerM > 1 {

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ var (
8181
PProfGraph *profile.Graph = nil
8282
)
8383

84-
// BuildGlobalPProfGraph generates a global pprof-graph from cpu-profile.
85-
func BuildGlobalPProfGraph(profileFile string, opt *profile.Options) *profile.Graph {
86-
// PProfGraph is built once.
84+
// BuildPProfGraph generates a pprof-graph from cpu-profile.
85+
func BuildPProfGraph(profileFile string, opt *profile.Options) *profile.Graph {
86+
8787
if PProfGraph != nil {
8888
return PProfGraph
8989
}
@@ -108,8 +108,8 @@ func BuildGlobalPProfGraph(profileFile string, opt *profile.Options) *profile.Gr
108108
return pProfGraph
109109
}
110110

111-
// BuildWeightedCallGraphPerPkg generates a weighted callgraph from the pprof profile.
112-
func BuildWeightedCallGraphPerPkg() *IRGraph {
111+
// BuildWeightedCallGraph generates a weighted callgraph from the pprof profile for the current package.
112+
func BuildWeightedCallGraph() *IRGraph {
113113

114114
// Bail if there is no pprof-graph available.
115115
if PProfGraph == nil {
@@ -119,7 +119,7 @@ func BuildWeightedCallGraphPerPkg() *IRGraph {
119119
// Create package-level call graph with weights from pprof profile and IR.
120120
weightedCG := createIRGraph()
121121

122-
if weightedCG != nil && base.Flag.LowerM > 2 {
122+
if weightedCG != nil && base.Flag.LowerM > 1 {
123123
log.Println("weighted call graph created successfully!")
124124
}
125125

@@ -179,14 +179,6 @@ func preprocessPProfGraph(pProfGraph *profile.Graph) {
179179
}
180180
}
181181
}
182-
183-
if base.Flag.LowerM > 4 {
184-
fmt.Printf("map of nodes with weights=[\n")
185-
for k, v := range GlobalNodeMap {
186-
fmt.Printf("(%v, %v, %v) --> (%v, %v)\n", k.FuncName, k.DstName, k.CallSite, v.NWeight, v.EWeight)
187-
}
188-
fmt.Printf("]\n")
189-
}
190182
}
191183

192184
// createIRGraph builds the IRGraph by visting all the ir.Func in decl list of a package.
@@ -271,9 +263,7 @@ func (g *IRGraph) addEdge(node1 *IRNode, f *ir.Func, n *ir.Node, name string, li
271263
if weights, ok := GlobalNodeMap[nodeinfo]; ok {
272264
node1.Flat = weights.NWeight
273265
node1.Cum = weights.NTotalWeight
274-
if base.Flag.LowerM > 4 {
275-
fmt.Printf("addEdge with Src=%v Dst=%v, CallSite=%v, weight=%v\n", ir.PkgFuncName(node1.AST), ir.PkgFuncName(g.IRNodes[name2].AST), line, weights.EWeight)
276-
}
266+
277267
// Add edge in the IRGraph from caller to callee [callee is an interface type here which can have multiple targets].
278268
info := &IREdge{Src: node1, Dst: g.IRNodes[name2], DstNode: n, Weight: weights.EWeight, CallSite: line}
279269
g.OutEdges[node1] = append(g.OutEdges[node1], info)
@@ -284,16 +274,10 @@ func (g *IRGraph) addEdge(node1 *IRNode, f *ir.Func, n *ir.Node, name string, li
284274
if weights, ok := GlobalNodeMap[nodeinfo]; ok {
285275
node1.Flat = weights.NWeight
286276
node1.Cum = weights.NTotalWeight
287-
if base.Flag.LowerM > 4 {
288-
fmt.Printf("addEdge with Src=%v Dst=%v, CallSite=%v, weight=%v\n", ir.PkgFuncName(node1.AST), ir.PkgFuncName(g.IRNodes[name2].AST), line, 0)
289-
}
290277
info := &IREdge{Src: node1, Dst: g.IRNodes[name2], DstNode: n, Weight: 0, CallSite: line}
291278
g.OutEdges[node1] = append(g.OutEdges[node1], info)
292279
g.InEdges[g.IRNodes[name2]] = append(g.InEdges[g.IRNodes[name2]], info)
293280
} else {
294-
if base.Flag.LowerM > 4 {
295-
fmt.Printf("addEdge with Src=%v Dst=%v, CallSite=%v, weight=%v\n", ir.PkgFuncName(node1.AST), ir.PkgFuncName(g.IRNodes[name2].AST), line, 0)
296-
}
297281
info := &IREdge{Src: node1, Dst: g.IRNodes[name2], DstNode: n, Weight: 0, CallSite: line}
298282
g.OutEdges[node1] = append(g.OutEdges[node1], info)
299283
g.InEdges[g.IRNodes[name2]] = append(g.InEdges[g.IRNodes[name2]], info)
@@ -417,7 +401,7 @@ func redirectEdges(g *IRGraph, parent *IRNode, cur *IRNode) {
417401
delete(g.OutEdges, cur)
418402
}
419403

420-
// RedirectEdges deletes and redirects out-edges from node cur based on inlining information via inlinedCallSites..
404+
// RedirectEdges deletes and redirects out-edges from node cur based on inlining information via inlinedCallSites.
421405
func RedirectEdges(cur *IRNode, inlinedCallSites map[CallSiteInfo]struct{}) {
422406
g := WeightedCG
423407
for i, outEdge := range g.OutEdges[cur] {

0 commit comments

Comments
 (0)