5 # Compile several crates to gather execution PGO profiles.
6 # Arg0 => profiles (Debug, Opt)
7 # Arg1 => scenarios (Full, IncrFull, All)
8 # Arg2 => crates (syn, cargo, ...)
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
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 \
26 /checkout/obj/build/$PGO_HOST/stage0/bin/cargo run -p collector --bin collector -- \
29 /checkout/obj/build/$PGO_HOST/stage2/bin/rustc \
32 --cargo /checkout/obj/build/$PGO_HOST/stage0/bin/cargo \
41 # We collect LLVM profiling information and rustc profiling information in
42 # separate phases. This increases build time -- though not by a huge amount --
43 # but prevents any problems from arising due to different profiling runtimes
44 # being simultaneously linked in.
46 python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
47 --stage 2 library/std \
48 --llvm-profile-generate
50 # Profile libcore compilation in opt-level=0 and opt-level=3
51 RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
52 --edition=2021 --crate-type=lib ../library/core/src/lib.rs
53 RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
54 --edition=2021 --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs
57 cp -r /tmp/rustc-perf ./
58 chown -R $(whoami): ./rustc-perf
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 \
65 /checkout/obj/build/$PGO_HOST/stage0/bin/cargo build -p collector
67 # Here we're profiling LLVM, so we only care about `Debug` and `Opt`, because we want to stress
68 # codegen. We also profile some of the most prolific crates.
69 gather_profiles "Debug,Opt" "Full" \
70 "syn-1.0.89,cargo-0.60.0,serde-1.0.136,ripgrep-13.0.0,regex-1.5.5,clap-3.1.6,hyper-0.14.18"
72 # Merge the profile data we gathered for LLVM
73 # Note that this uses the profdata from the clang we used to build LLVM,
74 # which likely has a different version than our in-tree clang.
75 /rustroot/bin/llvm-profdata \
76 merge -o /tmp/llvm-pgo.profdata ./build/$PGO_HOST/llvm/build/profiles
78 # Rustbuild currently doesn't support rebuilding LLVM when PGO options
79 # change (or any other llvm-related options); so just clear out the relevant
80 # directories ourselves.
81 rm -r ./build/$PGO_HOST/llvm ./build/$PGO_HOST/lld
83 # Okay, LLVM profiling is done, switch to rustc PGO.
85 python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
86 --stage 2 library/std \
87 --rust-profile-generate=/tmp/rustc-pgo
89 # Here we're profiling the `rustc` frontend, so we also include `Check`.
90 # The benchmark set includes various stress tests that put the frontend under pressure.
91 gather_profiles "Check,Debug,Opt" "All" \
92 "externs,ctfe-stress-4,cargo-0.60.0,token-stream-stress,match-stress,tuple-stress"
94 # Merge the profile data we gathered
95 ./build/$PGO_HOST/llvm/bin/llvm-profdata \
96 merge -o /tmp/rustc-pgo.profdata /tmp/rustc-pgo
98 # Rustbuild currently doesn't support rebuilding LLVM when PGO options
99 # change (or any other llvm-related options); so just clear out the relevant
100 # directories ourselves.
101 rm -r ./build/$PGO_HOST/llvm ./build/$PGO_HOST/lld
103 # This produces the actual final set of artifacts, using both the LLVM and rustc
104 # collected profiling data.
106 --rust-profile-use=/tmp/rustc-pgo.profdata \
107 --llvm-profile-use=/tmp/llvm-pgo.profdata