22
33set -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+
539rm -rf /tmp/rustc-pgo
640
741# We collect LLVM profiling information and rustc profiling information in
@@ -19,6 +53,7 @@ RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
1953RUSTC_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
2257cp -r /tmp/rustc-perf ./
2358chown -R $( whoami) : ./rustc-perf
2459cd rustc-perf
@@ -29,23 +64,7 @@ RUSTC=/checkout/obj/build/$PGO_HOST/stage0/bin/rustc \
2964RUSTC_BOOTSTRAP=1 \
3065/checkout/obj/build/$PGO_HOST /stage0/bin/cargo build -p collector
3166
32- # Gather LLVM PGO profiles from real-world crates.
33- # Benchmark using profile_local with eprintln, which essentially just means
34- # don't actually benchmark -- just make sure we run rustc a bunch of times.
35- RUST_LOG=collector=debug \
36- RUSTC=/checkout/obj/build/$PGO_HOST /stage0/bin/rustc \
37- RUSTC_BOOTSTRAP=1 \
38- /checkout/obj/build/$PGO_HOST /stage0/bin/cargo run -p collector --bin collector -- \
39- profile_local \
40- eprintln \
41- /checkout/obj/build/$PGO_HOST /stage2/bin/rustc \
42- Test \
43- --builds Debug,Opt \
44- --cargo /checkout/obj/build/$PGO_HOST /stage0/bin/cargo \
45- --runs All \
46- --include syn,cargo,serde,ripgrep,regex,clap-rs,hyper-2
47-
48- cd /checkout/obj
67+ gather_profiles " Debug,Opt" " Full" " syn,cargo,serde,ripgrep,regex,clap-rs,hyper-2"
4968
5069# Merge the profile data we gathered for LLVM
5170# Note that this uses the profdata from the clang we used to build LLVM,
@@ -64,28 +83,8 @@ python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
6483 --stage 2 library/std \
6584 --rust-profile-generate=/tmp/rustc-pgo
6685
67- # Profile libcore compilation in opt-level=0 and opt-level=3
68- RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST /stage2/bin/rustc \
69- --edition=2021 --crate-type=lib ../library/core/src/lib.rs
70- RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST /stage2/bin/rustc \
71- --edition=2021 --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs
72-
73- cd rustc-perf
74-
75- RUST_LOG=collector=debug \
76- RUSTC=/checkout/obj/build/$PGO_HOST /stage0/bin/rustc \
77- RUSTC_BOOTSTRAP=1 \
78- /checkout/obj/build/$PGO_HOST /stage0/bin/cargo run -p collector --bin collector -- \
79- profile_local \
80- eprintln \
81- /checkout/obj/build/$PGO_HOST /stage2/bin/rustc \
82- Test \
83- --builds Check,Debug,Opt \
84- --cargo /checkout/obj/build/$PGO_HOST /stage0/bin/cargo \
85- --runs All \
86- --include externs,ctfe-stress-4,inflate,cargo,token-stream-stress,match-stress-enum
87-
88- cd /checkout/obj
86+ gather_profiles " Check,Debug,Opt" " All" \
87+ " externs,ctfe-stress-4,inflate,cargo,token-stream-stress,match-stress-enum"
8988
9089# Merge the profile data we gathered
9190./build/$PGO_HOST /llvm/bin/llvm-profdata \
0 commit comments