@@ -5,61 +5,59 @@ set -euxo pipefail
5
5
rm -rf /tmp/rustc-pgo
6
6
7
7
python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
8
- --stage 2 library/std --rust-profile-generate=/tmp/rustc-pgo
8
+ --stage 2 library/std \
9
+ --rust-profile-generate=/tmp/rustc-pgo \
10
+ --llvm-profile-generate
9
11
12
+ # Profile libcore compilation in opt-level=0 and opt-level=3
10
13
RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST /stage2/bin/rustc --edition=2018 \
11
14
--crate-type=lib ../library/core/src/lib.rs
12
-
13
- # Download and build a single-file stress test benchmark on perf.rust-lang.org.
14
- function pgo_perf_benchmark {
15
- local PERF=1e19fc4c6168d2f7596e512f42f358f245d8f09d
16
- local github_prefix=https://raw.githubusercontent.com/rust-lang/rustc-perf/$PERF
17
- local name=$1
18
- local edition=$2
19
- curl -o /tmp/$name .rs $github_prefix /collector/benchmarks/$name /src/lib.rs
20
-
21
- RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST /stage2/bin/rustc --edition=$edition \
22
- --crate-type=lib /tmp/$name .rs
23
- }
24
-
25
- pgo_perf_benchmark externs 2018
26
- pgo_perf_benchmark ctfe-stress-4 2018
27
- pgo_perf_benchmark inflate 2015
28
-
29
- cp -pri ../src/tools/cargo /tmp/cargo
30
-
31
- # The Cargo repository does not have a Cargo.lock in it, as it relies on the
32
- # lockfile already present in the rust-lang/rust monorepo. This decision breaks
33
- # down when Cargo is built outside the monorepo though (like in this case),
34
- # resulting in a build without any dependency locking.
35
- #
36
- # To ensure Cargo is built with locked dependencies even during PGO profiling
37
- # the following command copies the monorepo's lockfile into the Cargo temporary
38
- # directory. Cargo will *not* keep that lockfile intact, as it will remove all
39
- # the dependencies Cargo itself doesn't rely on. Still, it will prevent
40
- # building Cargo with arbitrary dependency versions.
41
- #
42
- # See #81378 for the bug that prompted adding this.
43
- cp -p ../Cargo.lock /tmp/cargo
44
-
45
- # Build cargo (with some flags)
46
- function pgo_cargo {
47
- RUSTC=./build/$PGO_HOST /stage2/bin/rustc \
48
- ./build/$PGO_HOST /stage0/bin/cargo $@ \
49
- --manifest-path /tmp/cargo/Cargo.toml
50
- }
51
-
52
- # Build a couple different variants of Cargo
53
- CARGO_INCREMENTAL=1 pgo_cargo check
54
- echo ' pub fn barbarbar() {}' >> /tmp/cargo/src/cargo/lib.rs
55
- CARGO_INCREMENTAL=1 pgo_cargo check
56
- touch /tmp/cargo/src/cargo/lib.rs
57
- CARGO_INCREMENTAL=1 pgo_cargo check
58
- pgo_cargo build --release
15
+ RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST /stage2/bin/rustc --edition=2018 \
16
+ --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs
17
+
18
+ cp -r /tmp/rustc-perf ./
19
+ chown -R $( whoami) : ./rustc-perf
20
+ cd rustc-perf
21
+
22
+ # Build the collector ahead of time, which is needed to make sure the rustc-fake
23
+ # binary used by the collector is present.
24
+ RUSTC=/checkout/obj/build/$PGO_HOST /stage0/bin/rustc \
25
+ RUSTC_BOOTSTRAP=1 \
26
+ /checkout/obj/build/$PGO_HOST /stage0/bin/cargo build -p collector
27
+
28
+ # benchmark using profile_local with eprintln, which essentially just means
29
+ # don't actually benchmark -- just make sure we run rustc a bunch of times.
30
+ RUST_LOG=collector=debug \
31
+ RUSTC=/checkout/obj/build/$PGO_HOST /stage0/bin/rustc \
32
+ RUSTC_BOOTSTRAP=1 \
33
+ /checkout/obj/build/$PGO_HOST /stage0/bin/cargo run -p collector --bin collector -- \
34
+ profile_local \
35
+ eprintln \
36
+ /checkout/obj/build/$PGO_HOST /stage2/bin/rustc \
37
+ Test \
38
+ --builds Check,Debug,Opt \
39
+ --cargo /checkout/obj/build/$PGO_HOST /stage0/bin/cargo \
40
+ --runs All \
41
+ --include externs,ctfe-stress-4,inflate,cargo,token-stream-stress,match-stress-enum
42
+
43
+ cd /checkout/obj
59
44
60
45
# Merge the profile data we gathered
61
46
./build/$PGO_HOST /llvm/bin/llvm-profdata \
62
47
merge -o /tmp/rustc-pgo.profdata /tmp/rustc-pgo
63
48
49
+ # Merge the profile data we gathered for LLVM
50
+ # Note that this uses the profdata from the clang we used to build LLVM,
51
+ # which likely has a different version than our in-tree clang.
52
+ /rustroot/bin/llvm-profdata \
53
+ merge -o /tmp/llvm-pgo.profdata ./build/$PGO_HOST /llvm/build/profiles
54
+
55
+ # Rustbuild currently doesn't support rebuilding LLVM when PGO options
56
+ # change (or any other llvm-related options); so just clear out the relevant
57
+ # directories ourselves.
58
+ rm -r ./build/$PGO_HOST /llvm ./build/$PGO_HOST /lld
59
+
64
60
# This produces the actual final set of artifacts.
65
- $@ --rust-profile-use=/tmp/rustc-pgo.profdata
61
+ $@ \
62
+ --rust-profile-use=/tmp/rustc-pgo.profdata \
63
+ --llvm-profile-use=/tmp/llvm-pgo.profdata
0 commit comments