11use crate :: compile:: benchmark:: category:: Category ;
2+ use crate :: compile:: benchmark:: codegen_backend:: CodegenBackend ;
23use crate :: compile:: benchmark:: patch:: Patch ;
34use crate :: compile:: benchmark:: profile:: Profile ;
45use crate :: compile:: benchmark:: scenario:: Scenario ;
@@ -178,6 +179,7 @@ impl Benchmark {
178179 toolchain : & ' a Toolchain ,
179180 cwd : & ' a Path ,
180181 profile : Profile ,
182+ backend : CodegenBackend ,
181183 ) -> CargoProcess < ' a > {
182184 let mut cargo_args = self
183185 . config
@@ -199,6 +201,7 @@ impl Benchmark {
199201 processor_name : self . name . clone ( ) ,
200202 cwd,
201203 profile,
204+ backend,
202205 incremental : false ,
203206 processor_etc : None ,
204207 manifest_path : self
@@ -226,6 +229,7 @@ impl Benchmark {
226229 processor : & mut dyn Processor ,
227230 profiles : & [ Profile ] ,
228231 scenarios : & [ Scenario ] ,
232+ backends : & [ CodegenBackend ] ,
229233 toolchain : & Toolchain ,
230234 iterations : Option < usize > ,
231235 ) -> anyhow:: Result < ( ) > {
@@ -293,11 +297,17 @@ impl Benchmark {
293297 for ( profile, prep_dir) in & profile_dirs {
294298 let server = server. clone ( ) ;
295299 let thread = s. spawn :: < _ , anyhow:: Result < ( ) > > ( move || {
296- wait_for_future (
297- self . mk_cargo_process ( toolchain, prep_dir. path ( ) , * profile)
298- . jobserver ( server)
299- . run_rustc ( false ) ,
300- ) ?;
300+ wait_for_future ( async move {
301+ // Prepare all backend artifacts into the same target directory
302+ for backend in backends {
303+ let server = server. clone ( ) ;
304+ self . mk_cargo_process ( toolchain, prep_dir. path ( ) , * profile, * backend)
305+ . jobserver ( server)
306+ . run_rustc ( false )
307+ . await ?;
308+ }
309+ Ok :: < ( ) , anyhow:: Error > ( ( ) )
310+ } ) ?;
301311 Ok ( ( ) )
302312 } ) ;
303313 threads. push ( thread) ;
@@ -320,77 +330,88 @@ impl Benchmark {
320330 preparation_start. elapsed( ) . as_secs( )
321331 ) ;
322332
323- for ( profile, prep_dir) in profile_dirs {
324- eprintln ! ( "Running {}: {:?} + {:?}" , self . name, profile, scenarios) ;
325-
326- // We want at least two runs for all benchmarks (since we run
327- // self-profile separately).
328- processor. start_first_collection ( ) ;
329- for i in 0 ..std:: cmp:: max ( iterations, 2 ) {
330- if i == 1 {
331- let different = processor. finished_first_collection ( ) ;
332- if iterations == 1 && !different {
333- // Don't run twice if this processor doesn't need it and
334- // we've only been asked to run once.
335- break ;
336- }
337- }
338- log:: debug!( "Benchmark iteration {}/{}" , i + 1 , iterations) ;
339- // Don't delete the directory on error.
340- let timing_dir = ManuallyDrop :: new ( self . make_temp_dir ( prep_dir. path ( ) ) ?) ;
341- let cwd = timing_dir. path ( ) ;
342-
343- // A full non-incremental build.
344- if scenarios. contains ( & Scenario :: Full ) {
345- self . mk_cargo_process ( toolchain, cwd, profile)
346- . processor ( processor, Scenario :: Full , "Full" , None )
347- . run_rustc ( true )
348- . await ?;
349- }
333+ for & backend in backends {
334+ for ( profile, prep_dir) in & profile_dirs {
335+ let profile = * profile;
336+ eprintln ! (
337+ "Running {}: {:?} + {:?} + {:?}" ,
338+ self . name, profile, scenarios, backend
339+ ) ;
350340
351- // Rustdoc does not support incremental compilation
352- if profile != Profile :: Doc {
353- // An incremental from scratch (slowest incremental case).
354- // This is required for any subsequent incremental builds.
355- if scenarios. iter ( ) . any ( |s| s. is_incr ( ) ) {
356- self . mk_cargo_process ( toolchain, cwd, profile)
357- . incremental ( true )
358- . processor ( processor, Scenario :: IncrFull , "IncrFull" , None )
359- . run_rustc ( true )
360- . await ?;
341+ // We want at least two runs for all benchmarks (since we run
342+ // self-profile separately).
343+ processor. start_first_collection ( ) ;
344+ for i in 0 ..std:: cmp:: max ( iterations, 2 ) {
345+ if i == 1 {
346+ let different = processor. finished_first_collection ( ) ;
347+ if iterations == 1 && !different {
348+ // Don't run twice if this processor doesn't need it and
349+ // we've only been asked to run once.
350+ break ;
351+ }
361352 }
362-
363- // An incremental build with no changes (fastest incremental case).
364- if scenarios. contains ( & Scenario :: IncrUnchanged ) {
365- self . mk_cargo_process ( toolchain, cwd, profile)
366- . incremental ( true )
367- . processor ( processor, Scenario :: IncrUnchanged , "IncrUnchanged" , None )
353+ log:: debug!( "Benchmark iteration {}/{}" , i + 1 , iterations) ;
354+ // Don't delete the directory on error.
355+ let timing_dir = ManuallyDrop :: new ( self . make_temp_dir ( prep_dir. path ( ) ) ?) ;
356+ let cwd = timing_dir. path ( ) ;
357+
358+ // A full non-incremental build.
359+ if scenarios. contains ( & Scenario :: Full ) {
360+ self . mk_cargo_process ( toolchain, cwd, profile, backend)
361+ . processor ( processor, Scenario :: Full , "Full" , None )
368362 . run_rustc ( true )
369363 . await ?;
370364 }
371365
372- if scenarios. contains ( & Scenario :: IncrPatched ) {
373- for ( i, patch) in self . patches . iter ( ) . enumerate ( ) {
374- log:: debug!( "applying patch {}" , patch. name) ;
375- patch. apply ( cwd) . map_err ( |s| anyhow:: anyhow!( "{}" , s) ) ?;
366+ // Rustdoc does not support incremental compilation
367+ if profile != Profile :: Doc {
368+ // An incremental from scratch (slowest incremental case).
369+ // This is required for any subsequent incremental builds.
370+ if scenarios. iter ( ) . any ( |s| s. is_incr ( ) ) {
371+ self . mk_cargo_process ( toolchain, cwd, profile, backend)
372+ . incremental ( true )
373+ . processor ( processor, Scenario :: IncrFull , "IncrFull" , None )
374+ . run_rustc ( true )
375+ . await ?;
376+ }
376377
377- // An incremental build with some changes (realistic
378- // incremental case).
379- let scenario_str = format ! ( "IncrPatched{}" , i) ;
380- self . mk_cargo_process ( toolchain, cwd, profile)
378+ // An incremental build with no changes (fastest incremental case).
379+ if scenarios. contains ( & Scenario :: IncrUnchanged ) {
380+ self . mk_cargo_process ( toolchain, cwd, profile, backend)
381381 . incremental ( true )
382382 . processor (
383383 processor,
384- Scenario :: IncrPatched ,
385- & scenario_str ,
386- Some ( patch ) ,
384+ Scenario :: IncrUnchanged ,
385+ "IncrUnchanged" ,
386+ None ,
387387 )
388388 . run_rustc ( true )
389389 . await ?;
390390 }
391+
392+ if scenarios. contains ( & Scenario :: IncrPatched ) {
393+ for ( i, patch) in self . patches . iter ( ) . enumerate ( ) {
394+ log:: debug!( "applying patch {}" , patch. name) ;
395+ patch. apply ( cwd) . map_err ( |s| anyhow:: anyhow!( "{}" , s) ) ?;
396+
397+ // An incremental build with some changes (realistic
398+ // incremental case).
399+ let scenario_str = format ! ( "IncrPatched{}" , i) ;
400+ self . mk_cargo_process ( toolchain, cwd, profile, backend)
401+ . incremental ( true )
402+ . processor (
403+ processor,
404+ Scenario :: IncrPatched ,
405+ & scenario_str,
406+ Some ( patch) ,
407+ )
408+ . run_rustc ( true )
409+ . await ?;
410+ }
411+ }
391412 }
413+ drop ( ManuallyDrop :: into_inner ( timing_dir) ) ;
392414 }
393- drop ( ManuallyDrop :: into_inner ( timing_dir) ) ;
394415 }
395416 }
396417
0 commit comments