Skip to content

Commit 14c347f

Browse files
committed
cmd/compile/internal/pgo: readability refactor
Construction of Profile is getting more complex. Currently, we construct a partial Profile and then use methods to slowly complete the structure. This can hide dependencies and make refactoring fragile as the requirements and outputs of the methods is not clearly specified. Refactor construction to build the Profile only once all of the parts are complete. The intermediate states explicitly pass input and outputs as arguments. Additionally, rename Profile.NodeMap to NamedEdgeMap to make its contents more clear (edges, specified by caller/callee name rather than IR). Remove the node flat/cumulative weight from this map; they are unused. Change-Id: I2079cd991daac6398d74375b04dfe120b473d908 Reviewed-on: https://go-review.googlesource.com/c/go/+/529558 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent bfb8924 commit 14c347f

File tree

2 files changed

+124
-156
lines changed

2 files changed

+124
-156
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func pgoInlinePrologue(p *pgo.Profile, funcs []*ir.Func) {
8686
base.Fatalf("invalid PGOInlineCDFThreshold, must be between 0 and 100")
8787
}
8888
}
89-
var hotCallsites []pgo.NodeMapKey
89+
var hotCallsites []pgo.NamedCallEdge
9090
inlineHotCallSiteThresholdPercent, hotCallsites = hotNodesFromCDF(p)
9191
if base.Debug.PGODebug > 0 {
9292
fmt.Printf("hot-callsite-thres-from-CDF=%v\n", inlineHotCallSiteThresholdPercent)
@@ -120,19 +120,19 @@ func pgoInlinePrologue(p *pgo.Profile, funcs []*ir.Func) {
120120
// (currently only used in debug prints) (in case of equal weights,
121121
// comparing with the threshold may not accurately reflect which nodes are
122122
// considiered hot).
123-
func hotNodesFromCDF(p *pgo.Profile) (float64, []pgo.NodeMapKey) {
123+
func hotNodesFromCDF(p *pgo.Profile) (float64, []pgo.NamedCallEdge) {
124124
cum := int64(0)
125-
for i, n := range p.NodesByWeight {
126-
w := p.NodeMap[n].EWeight
125+
for i, n := range p.NamedEdgeMap.ByWeight {
126+
w := p.NamedEdgeMap.Weight[n]
127127
cum += w
128-
if pgo.WeightInPercentage(cum, p.TotalEdgeWeight) > inlineCDFHotCallSiteThresholdPercent {
128+
if pgo.WeightInPercentage(cum, p.TotalWeight) > inlineCDFHotCallSiteThresholdPercent {
129129
// nodes[:i+1] to include the very last node that makes it to go over the threshold.
130130
// (Say, if the CDF threshold is 50% and one hot node takes 60% of weight, we want to
131131
// include that node instead of excluding it.)
132-
return pgo.WeightInPercentage(w, p.TotalEdgeWeight), p.NodesByWeight[:i+1]
132+
return pgo.WeightInPercentage(w, p.TotalWeight), p.NamedEdgeMap.ByWeight[:i+1]
133133
}
134134
}
135-
return 0, p.NodesByWeight
135+
return 0, p.NamedEdgeMap.ByWeight
136136
}
137137

138138
// InlinePackage finds functions that can be inlined and clones them before walk expands them.

0 commit comments

Comments
 (0)