]> git.lizzy.rs Git - rust.git/blob - src/ci/pgo.sh
Split x86_64 apple builder into two
[rust.git] / src / ci / pgo.sh
1 #!/bin/bash
2
3 set -euxo pipefail
4
5 rm -rf /tmp/rustc-pgo
6
7 # We collect LLVM profiling information and rustc profiling information in
8 # separate phases. This increases build time -- though not by a huge amount --
9 # but prevents any problems from arising due to different profiling runtimes
10 # being simultaneously linked in.
11
12 python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
13     --stage 2 library/std \
14     --llvm-profile-generate
15
16 # Profile libcore compilation in opt-level=0 and opt-level=3
17 RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
18     --edition=2021 --crate-type=lib ../library/core/src/lib.rs
19 RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc \
20     --edition=2021 --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs
21
22 # Merge the profile data we gathered for LLVM
23 # Note that this uses the profdata from the clang we used to build LLVM,
24 # which likely has a different version than our in-tree clang.
25 /rustroot/bin/llvm-profdata \
26     merge -o /tmp/llvm-pgo.profdata ./build/$PGO_HOST/llvm/build/profiles
27
28 # Rustbuild currently doesn't support rebuilding LLVM when PGO options
29 # change (or any other llvm-related options); so just clear out the relevant
30 # directories ourselves.
31 rm -r ./build/$PGO_HOST/llvm ./build/$PGO_HOST/lld
32
33 # Okay, LLVM profiling is done, switch to rustc PGO.
34
35 python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
36     --stage 2 library/std \
37     --rust-profile-generate=/tmp/rustc-pgo
38
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
71
72 # Merge the profile data we gathered
73 ./build/$PGO_HOST/llvm/bin/llvm-profdata \
74     merge -o /tmp/rustc-pgo.profdata /tmp/rustc-pgo
75
76 # Rustbuild currently doesn't support rebuilding LLVM when PGO options
77 # change (or any other llvm-related options); so just clear out the relevant
78 # directories ourselves.
79 rm -r ./build/$PGO_HOST/llvm ./build/$PGO_HOST/lld
80
81 # This produces the actual final set of artifacts, using both the LLVM and rustc
82 # collected profiling data.
83 $@ \
84     --rust-profile-use=/tmp/rustc-pgo.profdata \
85     --llvm-profile-use=/tmp/llvm-pgo.profdata