Skip to content

Commit ebed06f

Browse files
committed
Auto merge of #94704 - Kobzol:llvm-pgo-update-suite, r=Mark-Simulacrum
Gather LLVM PGO profiles from `rustc-perf` suite on real-world crates This PR expands the benchmark suite used to gather LLVM PGO profiles in CI from `libcore` to several real-world crates. I hand-picked a few crates, but the list is up for debate. Previous results that we got from running `syn,cargo,serde` looked pretty [good](https://perf.rust-lang.org/compare.html?start=2631aeef823a9e16d31f999d3f07001e5fcc4b3d&end=abf097afa10dde1aa3d8a1d422724a46aab79bf3). Running `libcore` + `rustc-perf` with some number of crates is repeated now (and for BOLT it will also be needed), so maybe we can extract it to a bash function? r? `@Mark-Simulacrum`
2 parents b2763cc + e90e883 commit ebed06f

File tree

1 file changed

+49
-32
lines changed

1 file changed

+49
-32
lines changed

src/ci/pgo.sh

+49-32
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,40 @@
22

33
set -euxo pipefail
44

5+
# Compile several crates to gather execution PGO profiles.
6+
# Arg0 => builds (Debug, Opt)
7+
# Arg1 => runs (Full, IncrFull, All)
8+
# Arg2 => crates (syn, cargo, ...)
9+
gather_profiles () {
10+
cd /checkout/obj
11+
12+
# Compile libcore, both in opt-level=0 and opt-level=3
13+
RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
14+
--edition=2021 --crate-type=lib ../library/core/src/lib.rs
15+
RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
16+
--edition=2021 --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs
17+
18+
cd rustc-perf
19+
20+
# Run rustc-perf benchmarks
21+
# Benchmark using profile_local with eprintln, which essentially just means
22+
# don't actually benchmark -- just make sure we run rustc a bunch of times.
23+
RUST_LOG=collector=debug \
24+
RUSTC=/checkout/obj/build/$PGO_HOST/stage0/bin/rustc \
25+
RUSTC_BOOTSTRAP=1 \
26+
/checkout/obj/build/$PGO_HOST/stage0/bin/cargo run -p collector --bin collector -- \
27+
profile_local \
28+
eprintln \
29+
/checkout/obj/build/$PGO_HOST/stage2/bin/rustc \
30+
Test \
31+
--builds $1 \
32+
--cargo /checkout/obj/build/$PGO_HOST/stage0/bin/cargo \
33+
--runs $2 \
34+
--include $3
35+
36+
cd /checkout/obj
37+
}
38+
539
rm -rf /tmp/rustc-pgo
640

741
# We collect LLVM profiling information and rustc profiling information in
@@ -19,6 +53,19 @@ RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
1953
RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
2054
--edition=2021 --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs
2155

56+
# Compile rustc perf
57+
cp -r /tmp/rustc-perf ./
58+
chown -R $(whoami): ./rustc-perf
59+
cd rustc-perf
60+
61+
# Build the collector ahead of time, which is needed to make sure the rustc-fake
62+
# binary used by the collector is present.
63+
RUSTC=/checkout/obj/build/$PGO_HOST/stage0/bin/rustc \
64+
RUSTC_BOOTSTRAP=1 \
65+
/checkout/obj/build/$PGO_HOST/stage0/bin/cargo build -p collector
66+
67+
gather_profiles "Debug,Opt" "Full" "syn,cargo,serde,ripgrep,regex,clap-rs,hyper-2"
68+
2269
# Merge the profile data we gathered for LLVM
2370
# Note that this uses the profdata from the clang we used to build LLVM,
2471
# which likely has a different version than our in-tree clang.
@@ -36,38 +83,8 @@ python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
3683
--stage 2 library/std \
3784
--rust-profile-generate=/tmp/rustc-pgo
3885

39-
# Profile libcore compilation in opt-level=0 and opt-level=3
40-
RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
41-
--edition=2021 --crate-type=lib ../library/core/src/lib.rs
42-
RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
43-
--edition=2021 --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs
44-
45-
cp -r /tmp/rustc-perf ./
46-
chown -R $(whoami): ./rustc-perf
47-
cd rustc-perf
48-
49-
# Build the collector ahead of time, which is needed to make sure the rustc-fake
50-
# binary used by the collector is present.
51-
RUSTC=/checkout/obj/build/$PGO_HOST/stage0/bin/rustc \
52-
RUSTC_BOOTSTRAP=1 \
53-
/checkout/obj/build/$PGO_HOST/stage0/bin/cargo build -p collector
54-
55-
# benchmark using profile_local with eprintln, which essentially just means
56-
# don't actually benchmark -- just make sure we run rustc a bunch of times.
57-
RUST_LOG=collector=debug \
58-
RUSTC=/checkout/obj/build/$PGO_HOST/stage0/bin/rustc \
59-
RUSTC_BOOTSTRAP=1 \
60-
/checkout/obj/build/$PGO_HOST/stage0/bin/cargo run -p collector --bin collector -- \
61-
profile_local \
62-
eprintln \
63-
/checkout/obj/build/$PGO_HOST/stage2/bin/rustc \
64-
Test \
65-
--builds Check,Debug,Opt \
66-
--cargo /checkout/obj/build/$PGO_HOST/stage0/bin/cargo \
67-
--runs All \
68-
--include externs,ctfe-stress-4,inflate,cargo,token-stream-stress,match-stress-enum
69-
70-
cd /checkout/obj
86+
gather_profiles "Check,Debug,Opt" "All" \
87+
"externs,ctfe-stress-4,inflate,cargo,token-stream-stress,match-stress-enum"
7188

7289
# Merge the profile data we gathered
7390
./build/$PGO_HOST/llvm/bin/llvm-profdata \

0 commit comments

Comments
 (0)