3
3
4
4
set -euxo pipefail
5
5
6
+ ci_dir=` cd $( dirname $0 ) && pwd`
7
+ source " $ci_dir /shared.sh"
8
+
9
+ # The root checkout, where the source is located
10
+ CHECKOUT=/checkout
11
+
12
+ DOWNLOADED_LLVM=/rustroot
13
+
14
+ # The main directory where the build occurs, which can be different between linux and windows
15
+ BUILD_ROOT=$CHECKOUT /obj
16
+
17
+ # The various build artifacts used in other commands: to launch rustc builds, build the perf
18
+ # collector, and run benchmarks to gather profiling data
19
+ BUILD_ARTIFACTS=$BUILD_ROOT /build/$PGO_HOST
20
+ RUSTC_STAGE_0=$BUILD_ARTIFACTS /stage0/bin/rustc
21
+ CARGO_STAGE_0=$BUILD_ARTIFACTS /stage0/bin/cargo
22
+ RUSTC_STAGE_2=$BUILD_ARTIFACTS /stage2/bin/rustc
23
+
24
+ # Make sure we have a temporary PGO work folder
25
+ PGO_TMP=/tmp/tmp-pgo
26
+ mkdir -p $PGO_TMP
27
+ rm -rf $PGO_TMP /*
28
+
29
+ RUSTC_PERF=$PGO_TMP /rustc-perf
30
+
6
31
# Compile several crates to gather execution PGO profiles.
7
32
# Arg0 => profiles (Debug, Opt)
8
33
# Arg1 => scenarios (Full, IncrFull, All)
9
34
# Arg2 => crates (syn, cargo, ...)
10
35
gather_profiles () {
11
- cd /checkout/obj
36
+ cd $BUILD_ROOT
12
37
13
38
# Compile libcore, both in opt-level=0 and opt-level=3
14
- RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST /stage2/bin/rustc \
15
- --edition=2021 --crate-type=lib ../library/core/src/lib.rs
16
- RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST /stage2/bin/rustc \
17
- --edition=2021 --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs
39
+ RUSTC_BOOTSTRAP=1 $RUSTC_STAGE_2 \
40
+ --edition=2021 --crate-type=lib $CHECKOUT /library/core/src/lib.rs \
41
+ --out-dir $PGO_TMP
42
+ RUSTC_BOOTSTRAP=1 $RUSTC_STAGE_2 \
43
+ --edition=2021 --crate-type=lib -Copt-level=3 $CHECKOUT /library/core/src/lib.rs \
44
+ --out-dir $PGO_TMP
18
45
19
- cd rustc-perf
46
+ cd $RUSTC_PERF
20
47
21
48
# Run rustc-perf benchmarks
22
49
# Benchmark using profile_local with eprintln, which essentially just means
23
50
# don't actually benchmark -- just make sure we run rustc a bunch of times.
24
51
RUST_LOG=collector=debug \
25
- RUSTC=/checkout/obj/build/ $PGO_HOST /stage0/bin/rustc \
52
+ RUSTC=$RUSTC_STAGE_0 \
26
53
RUSTC_BOOTSTRAP=1 \
27
- /checkout/obj/build/ $PGO_HOST /stage0/bin/cargo run -p collector --bin collector -- \
28
- profile_local \
29
- eprintln \
30
- /checkout/obj/build/ $PGO_HOST /stage2/bin/rustc \
31
- --id Test \
32
- --profiles $1 \
33
- --cargo /checkout/obj/build/ $PGO_HOST /stage0/bin/cargo \
34
- --scenarios $2 \
35
- --include $3
36
-
37
- cd /checkout/obj
54
+ $CARGO_STAGE_0 run -p collector --bin collector -- \
55
+ profile_local \
56
+ eprintln \
57
+ $RUSTC_STAGE_2 \
58
+ --id Test \
59
+ --profiles $1 \
60
+ --cargo $CARGO_STAGE_0 \
61
+ --scenarios $2 \
62
+ --include $3
63
+
64
+ cd $BUILD_ROOT
38
65
}
39
66
40
- rm -rf /tmp/rustc-pgo
41
-
42
67
# This path has to be absolute
43
- LLVM_PROFILE_DIRECTORY_ROOT=/tmp /llvm-pgo
68
+ LLVM_PROFILE_DIRECTORY_ROOT=$PGO_TMP /llvm-pgo
44
69
45
70
# We collect LLVM profiling information and rustc profiling information in
46
71
# separate phases. This increases build time -- though not by a huge amount --
@@ -49,52 +74,55 @@ LLVM_PROFILE_DIRECTORY_ROOT=/tmp/llvm-pgo
49
74
# LLVM IR PGO does not respect LLVM_PROFILE_FILE, so we have to set the profiling file
50
75
# path through our custom environment variable. We include the PID in the directory path
51
76
# to avoid updates to profile files being lost because of race conditions.
52
- LLVM_PROFILE_DIR=${LLVM_PROFILE_DIRECTORY_ROOT} /prof-%p python3 .. /x.py build \
77
+ LLVM_PROFILE_DIR=${LLVM_PROFILE_DIRECTORY_ROOT} /prof-%p python3 $CHECKOUT /x.py build \
53
78
--target=$PGO_HOST \
54
79
--host=$PGO_HOST \
55
80
--stage 2 library/std \
56
81
--llvm-profile-generate
57
82
58
83
# Compile rustc perf
59
- cp -r /tmp/rustc-perf ./
60
- chown -R $( whoami) : ./rustc-perf
61
- cd rustc-perf
84
+ cp -r /tmp/rustc-perf $RUSTC_PERF
85
+ chown -R $( whoami) : $RUSTC_PERF
86
+ cd $RUSTC_PERF
62
87
63
- # Build the collector ahead of time, which is needed to make sure the rustc-fake
88
+ # Build rustc-perf's collector ahead of time, which is needed to make sure the rustc-fake
64
89
# binary used by the collector is present.
65
- RUSTC=/checkout/obj/build/ $PGO_HOST /stage0/bin/rustc \
90
+ RUSTC=$RUSTC_STAGE_0 \
66
91
RUSTC_BOOTSTRAP=1 \
67
- /checkout/obj/build/ $PGO_HOST /stage0/bin/cargo build -p collector
92
+ $CARGO_STAGE_0 build -p collector
68
93
69
94
# Here we're profiling LLVM, so we only care about `Debug` and `Opt`, because we want to stress
70
95
# codegen. We also profile some of the most prolific crates.
71
96
gather_profiles " Debug,Opt" " Full" \
72
- " 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"
97
+ " 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"
73
98
74
- LLVM_PROFILE_MERGED_FILE=/tmp /llvm-pgo.profdata
99
+ LLVM_PROFILE_MERGED_FILE=$PGO_TMP /llvm-pgo.profdata
75
100
76
101
# Merge the profile data we gathered for LLVM
77
102
# Note that this uses the profdata from the clang we used to build LLVM,
78
103
# which likely has a different version than our in-tree clang.
79
- /rustroot /bin/llvm-profdata merge -o ${LLVM_PROFILE_MERGED_FILE} ${LLVM_PROFILE_DIRECTORY_ROOT}
104
+ $DOWNLOADED_LLVM /bin/llvm-profdata merge -o ${LLVM_PROFILE_MERGED_FILE} ${LLVM_PROFILE_DIRECTORY_ROOT}
80
105
81
106
echo " LLVM PGO statistics"
82
107
du -sh ${LLVM_PROFILE_MERGED_FILE}
83
108
du -sh ${LLVM_PROFILE_DIRECTORY_ROOT}
84
109
echo " Profile file count"
85
110
find ${LLVM_PROFILE_DIRECTORY_ROOT} -type f | wc -l
86
111
112
+ # We don't need the individual .profraw files now that they have been merged into a final .profdata
113
+ rm -r $LLVM_PROFILE_DIRECTORY_ROOT
114
+
87
115
# Rustbuild currently doesn't support rebuilding LLVM when PGO options
88
116
# change (or any other llvm-related options); so just clear out the relevant
89
117
# directories ourselves.
90
- rm -r ./build/ $PGO_HOST /llvm ./build/ $PGO_HOST /lld
118
+ rm -r $BUILD_ARTIFACTS /llvm $BUILD_ARTIFACTS /lld
91
119
92
120
# Okay, LLVM profiling is done, switch to rustc PGO.
93
121
94
122
# The path has to be absolute
95
- RUSTC_PROFILE_DIRECTORY_ROOT=/tmp /rustc-pgo
123
+ RUSTC_PROFILE_DIRECTORY_ROOT=$PGO_TMP /rustc-pgo
96
124
97
- python3 .. /x.py build --target=$PGO_HOST --host=$PGO_HOST \
125
+ python3 $CHECKOUT /x.py build --target=$PGO_HOST --host=$PGO_HOST \
98
126
--stage 2 library/std \
99
127
--rust-profile-generate=${RUSTC_PROFILE_DIRECTORY_ROOT}
100
128
@@ -105,13 +133,13 @@ python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
105
133
# That's why we override the profile path to include the PID. This will produce many more profiling
106
134
# files, but the resulting profile will produce a slightly faster rustc binary.
107
135
LLVM_PROFILE_FILE=${RUSTC_PROFILE_DIRECTORY_ROOT} /default_%m_%p.profraw gather_profiles \
108
- " Check,Debug,Opt" " All" \
109
- " externs,ctfe-stress-5,cargo-0.60.0,token-stream-stress,match-stress,tuple-stress,diesel-1.4.8,bitmaps-3.1.0"
136
+ " Check,Debug,Opt" " All" \
137
+ " externs,ctfe-stress-5,cargo-0.60.0,token-stream-stress,match-stress,tuple-stress,diesel-1.4.8,bitmaps-3.1.0"
110
138
111
- RUSTC_PROFILE_MERGED_FILE=/tmp /rustc-pgo.profdata
139
+ RUSTC_PROFILE_MERGED_FILE=$PGO_TMP /rustc-pgo.profdata
112
140
113
141
# Merge the profile data we gathered
114
- ./build/ $PGO_HOST /llvm/bin/llvm-profdata \
142
+ $BUILD_ARTIFACTS /llvm/bin/llvm-profdata \
115
143
merge -o ${RUSTC_PROFILE_MERGED_FILE} ${RUSTC_PROFILE_DIRECTORY_ROOT}
116
144
117
145
echo " Rustc PGO statistics"
@@ -120,10 +148,13 @@ du -sh ${RUSTC_PROFILE_DIRECTORY_ROOT}
120
148
echo " Profile file count"
121
149
find ${RUSTC_PROFILE_DIRECTORY_ROOT} -type f | wc -l
122
150
151
+ # We don't need the individual .profraw files now that they have been merged into a final .profdata
152
+ rm -r $RUSTC_PROFILE_DIRECTORY_ROOT
153
+
123
154
# Rustbuild currently doesn't support rebuilding LLVM when PGO options
124
155
# change (or any other llvm-related options); so just clear out the relevant
125
156
# directories ourselves.
126
- rm -r ./build/ $PGO_HOST /llvm ./build/ $PGO_HOST /lld
157
+ rm -r $BUILD_ARTIFACTS /llvm $BUILD_ARTIFACTS /lld
127
158
128
159
# This produces the actual final set of artifacts, using both the LLVM and rustc
129
160
# collected profiling data.
0 commit comments