@@ -66,20 +66,32 @@ fn init_compiler_benchmarks(
6666 . workdir ( & env. rustc_perf_dir ( ) )
6767}
6868
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+
6977fn merge_llvm_profiles (
7078 env : & dyn Environment ,
7179 merged_path : & Utf8Path ,
7280 profile_dir : & Utf8Path ,
81+ profdata : LlvmProfdata ,
7382) -> 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" ) ?;
8395 Ok ( ( ) )
8496}
8597
@@ -118,7 +130,7 @@ pub fn gather_llvm_profiles(
118130 let merged_profile = env. opt_artifacts ( ) . join ( "llvm-pgo.profdata" ) ;
119131 log:: info!( "Merging LLVM PGO profiles to {merged_profile}" ) ;
120132
121- merge_llvm_profiles ( env, & merged_profile, profile_root) ?;
133+ merge_llvm_profiles ( env, & merged_profile, profile_root, LlvmProfdata :: Host ) ?;
122134 log_profile_stats ( "LLVM" , & merged_profile, profile_root) ?;
123135
124136 // We don't need the individual .profraw files now that they have been merged
@@ -154,7 +166,7 @@ pub fn gather_rustc_profiles(
154166 let merged_profile = env. opt_artifacts ( ) . join ( "rustc-pgo.profdata" ) ;
155167 log:: info!( "Merging Rustc PGO profiles to {merged_profile}" ) ;
156168
157- merge_llvm_profiles ( env, & merged_profile, profile_root) ?;
169+ merge_llvm_profiles ( env, & merged_profile, profile_root, LlvmProfdata :: Target ) ?;
158170 log_profile_stats ( "Rustc" , & merged_profile, profile_root) ?;
159171
160172 // We don't need the individual .profraw files now that they have been merged
0 commit comments