Skip to content

Commit

Permalink
cmd/go: enable -pgo=auto by default
Browse files Browse the repository at this point in the history
Updates #58099.
Updates #55022.

Change-Id: I32eacdf9f008d16566e0b30230ecc25d110a9811
Reviewed-on: https://go-review.googlesource.com/c/go/+/474236
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
  • Loading branch information
cherrymui committed Mar 22, 2023
1 parent 3d28e0e commit 0aa14fc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cmd/go/alldocs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2939,8 +2939,6 @@ func PackagesAndErrors(ctx context.Context, opts PackageOpts, patterns []string)
// In -pgo=auto mode, it finds the default PGO profile.
func setPGOProfilePath(pkgs []*Package) {
switch cfg.BuildPGO {
case "":
fallthrough // default to "off"
case "off":
return

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/internal/work/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ and test commands:
build, the go command selects a file named "default.pgo" in the package's
directory if that file exists, and applies it to the (transitive)
dependencies of the main package (other packages are not affected).
Special name "off" turns off PGO.
Special name "off" turns off PGO. The default is "auto".
-pkgdir dir
install and load all packages from dir instead of the usual locations.
For example, when building with a non-standard configuration,
Expand Down Expand Up @@ -318,7 +318,7 @@ func AddBuildFlags(cmd *base.Command, mask BuildFlagMask) {
cmd.Flag.StringVar(&cfg.BuildContext.InstallSuffix, "installsuffix", "", "")
cmd.Flag.Var(&load.BuildLdflags, "ldflags", "")
cmd.Flag.BoolVar(&cfg.BuildLinkshared, "linkshared", false, "")
cmd.Flag.StringVar(&cfg.BuildPGO, "pgo", "", "")
cmd.Flag.StringVar(&cfg.BuildPGO, "pgo", "auto", "")
cmd.Flag.StringVar(&cfg.BuildPkgdir, "pkgdir", "", "")
cmd.Flag.BoolVar(&cfg.BuildRace, "race", false, "")
cmd.Flag.BoolVar(&cfg.BuildMSan, "msan", false, "")
Expand Down
15 changes: 15 additions & 0 deletions src/cmd/go/testdata/script/build_pgo_auto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ go list -test -pgo=auto ./a/a1

go list -deps -pgo=auto ./a/a1

# -pgo=auto is the default. Commands without explicit -pgo=auto
# should work as -pgo=auto.
go build -n ./a/a1
stderr 'compile.*-pgoprofile=.*default\.pgo.*a1.go'
stderr 'compile.*-p test/dep.*-pgoprofile=.*default\.pgo'

go build -n -o nopgo.exe ./nopgo
stderr 'compile.*nopgo.go'
! stderr '-pgoprofile'

# -pgo=off should turn off PGO.
go build -n -pgo=off ./a/a1
stderr 'compile.*a1.go'
! stderr '-pgoprofile'

-- go.mod --
module test
go 1.20
Expand Down

0 comments on commit 0aa14fc

Please sign in to comment.