@@ -10,8 +10,8 @@ use crate::exec::{Bootstrap, cmd};
1010use  crate :: tests:: run_tests; 
1111use  crate :: timer:: Timer ; 
1212use  crate :: training:: { 
13-     gather_bolt_profiles,  gather_llvm_profiles,  gather_rustc_profiles,  llvm_benchmarks , 
14-     rustc_benchmarks, 
13+     LlvmPGOProfile ,   gather_bolt_profiles,  gather_llvm_profiles,  gather_rustc_profiles, 
14+     llvm_benchmarks ,   rustc_benchmarks, 
1515} ; 
1616use  crate :: utils:: artifact_size:: print_binary_sizes; 
1717use  crate :: utils:: io:: { copy_directory,  reset_directory} ; 
@@ -98,6 +98,10 @@ enum EnvironmentCmd {
9898        /// Perform tests after final build if it's not a fast try build 
9999#[ arg( long) ]  
100100        run_tests :  bool , 
101+ 
102+         /// Will be LLVM built during the run? 
103+ #[ arg( long,  default_value_t = true ,  action( clap:: ArgAction :: Set ) ) ]  
104+         build_llvm :  bool , 
101105    } , 
102106    /// Perform an optimized build on Linux CI, from inside Docker. 
103107LinuxCi  { 
@@ -133,6 +137,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
133137            benchmark_cargo_config, 
134138            shared, 
135139            run_tests, 
140+             build_llvm, 
136141        }  => { 
137142            let  env = EnvironmentBuilder :: default ( ) 
138143                . host_tuple ( target_triple) 
@@ -148,6 +153,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
148153                . benchmark_cargo_config ( benchmark_cargo_config) 
149154                . run_tests ( run_tests) 
150155                . fast_try_build ( is_fast_try_build) 
156+                 . build_llvm ( build_llvm) 
151157                . build ( ) ?; 
152158
153159            ( env,  shared. build_args ) 
@@ -172,6 +178,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
172178                . skipped_tests ( vec ! [ ] ) 
173179                . run_tests ( true ) 
174180                . fast_try_build ( is_fast_try_build) 
181+                 . build_llvm ( true ) 
175182                . build ( ) ?; 
176183
177184            ( env,  shared. build_args ) 
@@ -193,6 +200,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
193200                . skipped_tests ( vec ! [ ] ) 
194201                . run_tests ( true ) 
195202                . fast_try_build ( is_fast_try_build) 
203+                 . build_llvm ( true ) 
196204                . build ( ) ?; 
197205
198206            ( env,  shared. build_args ) 
@@ -255,32 +263,37 @@ fn execute_pipeline(
255263    // Stage 2: Gather LLVM PGO profiles 
256264    // Here we build a PGO instrumented LLVM, reusing the previously PGO optimized rustc. 
257265    // Then we use the instrumented LLVM to gather LLVM PGO profiles. 
258-     let  llvm_pgo_profile = timer. section ( "Stage 2 (LLVM PGO)" ,  |stage| { 
259-         // Remove the previous, uninstrumented build of LLVM. 
260-         clear_llvm_files ( env) ?; 
266+     let  llvm_pgo_profile = if  env. build_llvm ( )  { 
267+         timer. section ( "Stage 2 (LLVM PGO)" ,  |stage| { 
268+             // Remove the previous, uninstrumented build of LLVM. 
269+             clear_llvm_files ( env) ?; 
261270
262-         let  llvm_profile_dir_root = env. artifact_dir ( ) . join ( "llvm-pgo" ) ; 
271+              let  llvm_profile_dir_root = env. artifact_dir ( ) . join ( "llvm-pgo" ) ; 
263272
264-         stage. section ( "Build PGO instrumented LLVM" ,  |section| { 
265-             Bootstrap :: build ( env) 
266-                 . llvm_pgo_instrument ( & llvm_profile_dir_root) 
267-                 . avoid_rustc_rebuild ( ) 
268-                 . run ( section) 
269-         } ) ?; 
273+              stage. section ( "Build PGO instrumented LLVM" ,  |section| { 
274+                  Bootstrap :: build ( env) 
275+                      . llvm_pgo_instrument ( & llvm_profile_dir_root) 
276+                      . avoid_rustc_rebuild ( ) 
277+                      . run ( section) 
278+              } ) ?; 
270279
271-         let  profile = stage
272-             . section ( "Gather profiles" ,  |_| gather_llvm_profiles ( env,  & llvm_profile_dir_root) ) ?; 
280+             let  profile = stage. section ( "Gather profiles" ,  |_| { 
281+                 gather_llvm_profiles ( env,  & llvm_profile_dir_root) 
282+             } ) ?; 
273283
274-         print_free_disk_space ( ) ?; 
284+              print_free_disk_space ( ) ?; 
275285
276-         // Proactively delete the instrumented artifacts, to avoid using them by accident in 
277-         // follow-up stages. 
278-         clear_llvm_files ( env) ?; 
286+              // Proactively delete the instrumented artifacts, to avoid using them by accident in 
287+              // follow-up stages. 
288+              clear_llvm_files ( env) ?; 
279289
280-         Ok ( profile) 
281-     } ) ?; 
290+             Ok ( profile) 
291+         } ) ?
292+     }  else  { 
293+         LlvmPGOProfile ( Utf8PathBuf :: new ( ) ) 
294+     } ; 
282295
283-     let  bolt_profiles = if  env. use_bolt ( )  { 
296+     let  bolt_profiles = if  env. build_llvm ( )  && env . use_bolt ( )  { 
284297        // Stage 3: Build BOLT instrumented LLVM 
285298        // We build a PGO optimized LLVM in this step, then instrument it with BOLT and gather BOLT profiles. 
286299        // Note that we don't remove LLVM artifacts after this step, so that they are reused in the final dist build. 
0 commit comments