@@ -370,6 +370,13 @@ fn get_pgo_use_path(config: &ModuleConfig) -> Option<CString> {
370
370
. map ( |path_buf| CString :: new ( path_buf. to_string_lossy ( ) . as_bytes ( ) ) . unwrap ( ) )
371
371
}
372
372
373
+ fn get_pgo_sample_use_path ( config : & ModuleConfig ) -> Option < CString > {
374
+ config
375
+ . pgo_sample_use
376
+ . as_ref ( )
377
+ . map ( |path_buf| CString :: new ( path_buf. to_string_lossy ( ) . as_bytes ( ) ) . unwrap ( ) )
378
+ }
379
+
373
380
pub ( crate ) fn should_use_new_llvm_pass_manager ( config : & ModuleConfig ) -> bool {
374
381
// The new pass manager is enabled by default for LLVM >= 13.
375
382
// This matches Clang, which also enables it since Clang 13.
@@ -389,6 +396,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
389
396
let using_thin_buffers = opt_stage == llvm:: OptStage :: PreLinkThinLTO || config. bitcode_needed ( ) ;
390
397
let pgo_gen_path = get_pgo_gen_path ( config) ;
391
398
let pgo_use_path = get_pgo_use_path ( config) ;
399
+ let pgo_sample_use_path = get_pgo_sample_use_path ( config) ;
392
400
let is_lto = opt_stage == llvm:: OptStage :: ThinLTO || opt_stage == llvm:: OptStage :: FatLTO ;
393
401
// Sanitizer instrumentation is only inserted during the pre-link optimization stage.
394
402
let sanitizer_options = if !is_lto {
@@ -439,6 +447,8 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
439
447
pgo_use_path. as_ref ( ) . map_or ( std:: ptr:: null ( ) , |s| s. as_ptr ( ) ) ,
440
448
config. instrument_coverage ,
441
449
config. instrument_gcov ,
450
+ pgo_sample_use_path. as_ref ( ) . map_or ( std:: ptr:: null ( ) , |s| s. as_ptr ( ) ) ,
451
+ config. debug_info_for_profiling ,
442
452
llvm_selfprofiler,
443
453
selfprofile_before_pass_callback,
444
454
selfprofile_after_pass_callback,
@@ -544,6 +554,9 @@ pub(crate) unsafe fn optimize(
544
554
if config. instrument_coverage {
545
555
llvm:: LLVMRustAddPass ( mpm, find_pass ( "instrprof" ) . unwrap ( ) ) ;
546
556
}
557
+ if config. debug_info_for_profiling {
558
+ llvm:: LLVMRustAddPass ( mpm, find_pass ( "add-discriminators" ) . unwrap ( ) ) ;
559
+ }
547
560
548
561
add_sanitizer_passes ( config, & mut extra_passes) ;
549
562
@@ -1001,6 +1014,7 @@ pub unsafe fn with_llvm_pmb(
1001
1014
let inline_threshold = config. inline_threshold ;
1002
1015
let pgo_gen_path = get_pgo_gen_path ( config) ;
1003
1016
let pgo_use_path = get_pgo_use_path ( config) ;
1017
+ let pgo_sample_use_path = get_pgo_sample_use_path ( config) ;
1004
1018
1005
1019
llvm:: LLVMRustConfigurePassManagerBuilder (
1006
1020
builder,
@@ -1011,6 +1025,7 @@ pub unsafe fn with_llvm_pmb(
1011
1025
prepare_for_thin_lto,
1012
1026
pgo_gen_path. as_ref ( ) . map_or ( ptr:: null ( ) , |s| s. as_ptr ( ) ) ,
1013
1027
pgo_use_path. as_ref ( ) . map_or ( ptr:: null ( ) , |s| s. as_ptr ( ) ) ,
1028
+ pgo_sample_use_path. as_ref ( ) . map_or ( ptr:: null ( ) , |s| s. as_ptr ( ) ) ,
1014
1029
) ;
1015
1030
1016
1031
llvm:: LLVMPassManagerBuilderSetSizeLevel ( builder, opt_size as u32 ) ;
0 commit comments