@@ -66,20 +66,32 @@ fn init_compiler_benchmarks(
66
66
. workdir ( & env. rustc_perf_dir ( ) )
67
67
}
68
68
69
+ /// Describes which `llvm-profdata` binary should be used for merging PGO profiles.
70
+ enum LlvmProfdata {
71
+ /// Use llvm-profdata from the host toolchain (i.e. from LLVM provided externally).
72
+ Host ,
73
+ /// Use llvm-profdata from the target toolchain (i.e. from LLVM built from `src/llvm-project`).
74
+ Target ,
75
+ }
76
+
69
77
fn merge_llvm_profiles (
70
78
env : & dyn Environment ,
71
79
merged_path : & Utf8Path ,
72
80
profile_dir : & Utf8Path ,
81
+ profdata : LlvmProfdata ,
73
82
) -> anyhow:: Result < ( ) > {
74
- cmd ( & [
75
- env. downloaded_llvm_dir ( ) . join ( "bin/llvm-profdata" ) . as_str ( ) ,
76
- "merge" ,
77
- "-o" ,
78
- merged_path. as_str ( ) ,
79
- profile_dir. as_str ( ) ,
80
- ] )
81
- . run ( )
82
- . context ( "Cannot merge LLVM profiles" ) ?;
83
+ let llvm_profdata = match profdata {
84
+ LlvmProfdata :: Host => env. downloaded_llvm_dir ( ) . join ( "bin/llvm-profdata" ) ,
85
+ LlvmProfdata :: Target => env
86
+ . build_artifacts ( )
87
+ . join ( "llvm" )
88
+ . join ( "build" )
89
+ . join ( format ! ( "bin/llvm-profdata{}" , env. executable_extension( ) ) ) ,
90
+ } ;
91
+
92
+ cmd ( & [ llvm_profdata. as_str ( ) , "merge" , "-o" , merged_path. as_str ( ) , profile_dir. as_str ( ) ] )
93
+ . run ( )
94
+ . context ( "Cannot merge LLVM profiles" ) ?;
83
95
Ok ( ( ) )
84
96
}
85
97
@@ -118,7 +130,7 @@ pub fn gather_llvm_profiles(
118
130
let merged_profile = env. opt_artifacts ( ) . join ( "llvm-pgo.profdata" ) ;
119
131
log:: info!( "Merging LLVM PGO profiles to {merged_profile}" ) ;
120
132
121
- merge_llvm_profiles ( env, & merged_profile, profile_root) ?;
133
+ merge_llvm_profiles ( env, & merged_profile, profile_root, LlvmProfdata :: Host ) ?;
122
134
log_profile_stats ( "LLVM" , & merged_profile, profile_root) ?;
123
135
124
136
// We don't need the individual .profraw files now that they have been merged
@@ -154,7 +166,7 @@ pub fn gather_rustc_profiles(
154
166
let merged_profile = env. opt_artifacts ( ) . join ( "rustc-pgo.profdata" ) ;
155
167
log:: info!( "Merging Rustc PGO profiles to {merged_profile}" ) ;
156
168
157
- merge_llvm_profiles ( env, & merged_profile, profile_root) ?;
169
+ merge_llvm_profiles ( env, & merged_profile, profile_root, LlvmProfdata :: Target ) ?;
158
170
log_profile_stats ( "Rustc" , & merged_profile, profile_root) ?;
159
171
160
172
// We don't need the individual .profraw files now that they have been merged
0 commit comments