-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/compile: lookup indirect callees from export data for devirtualiz…
…ation Today, the PGO IR graph only contains entries for ir.Func loaded into the package. This can include functions from transitive dependencies, but only if they happen to be referenced by something in the current package. If they are not referenced, noder never bothers to load them. This leads to a deficiency in PGO devirtualization: some callee methods are available in transitive dependencies but do not devirtualize because they happen to not get loaded from export data. Resolve this by adding an explicit lookup from export data of callees mentioned in the profile. I have chosen to do this during loading of the profile for simplicity: the PGO IR graph always contains all of the functions we might need. That said, it isn't strictly necessary. PGO devirtualization could do the lookup lazily if it decides it actually needs a method. This saves work at the expense of a bit more complexity, but I've chosen the simpler approach for now as I measured the cost of this as significantly less than the rest of PGO loading. For #61577. Change-Id: Ieafb2a549510587027270ee6b4c3aefd149a901f Reviewed-on: https://go-review.googlesource.com/c/go/+/497175 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
- Loading branch information
Showing
12 changed files
with
367 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package ir | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSplitPkg(t *testing.T) { | ||
tests := []struct { | ||
in string | ||
pkg string | ||
sym string | ||
}{ | ||
{ | ||
in: "foo.Bar", | ||
pkg: "foo", | ||
sym: "Bar", | ||
}, | ||
{ | ||
in: "foo/bar.Baz", | ||
pkg: "foo/bar", | ||
sym: "Baz", | ||
}, | ||
{ | ||
in: "memeqbody", | ||
pkg: "", | ||
sym: "memeqbody", | ||
}, | ||
{ | ||
in: `example%2ecom.Bar`, | ||
pkg: `example%2ecom`, | ||
sym: "Bar", | ||
}, | ||
{ | ||
// Not a real generated symbol name, but easier to catch the general parameter form. | ||
in: `foo.Bar[sync/atomic.Uint64]`, | ||
pkg: `foo`, | ||
sym: "Bar[sync/atomic.Uint64]", | ||
}, | ||
{ | ||
in: `example%2ecom.Bar[sync/atomic.Uint64]`, | ||
pkg: `example%2ecom`, | ||
sym: "Bar[sync/atomic.Uint64]", | ||
}, | ||
{ | ||
in: `gopkg.in/yaml%2ev3.Bar[sync/atomic.Uint64]`, | ||
pkg: `gopkg.in/yaml%2ev3`, | ||
sym: "Bar[sync/atomic.Uint64]", | ||
}, | ||
{ | ||
// This one is a real symbol name. | ||
in: `foo.Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]`, | ||
pkg: `foo`, | ||
sym: "Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]", | ||
}, | ||
{ | ||
in: `example%2ecom.Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]`, | ||
pkg: `example%2ecom`, | ||
sym: "Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]", | ||
}, | ||
{ | ||
in: `gopkg.in/yaml%2ev3.Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]`, | ||
pkg: `gopkg.in/yaml%2ev3`, | ||
sym: "Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.in, func(t *testing.T) { | ||
pkg, sym := splitPkg(tc.in) | ||
if pkg != tc.pkg { | ||
t.Errorf("splitPkg(%q) got pkg %q want %q", tc.in, pkg, tc.pkg) | ||
} | ||
if sym != tc.sym { | ||
t.Errorf("splitPkg(%q) got sym %q want %q", tc.in, sym, tc.sym) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.