@@ -370,6 +370,13 @@ fn get_pgo_use_path(config: &ModuleConfig) -> Option<CString> {
370370 . map ( |path_buf| CString :: new ( path_buf. to_string_lossy ( ) . as_bytes ( ) ) . unwrap ( ) )
371371}
372372
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+
373380pub ( crate ) fn should_use_new_llvm_pass_manager ( config : & ModuleConfig ) -> bool {
374381 // The new pass manager is enabled by default for LLVM >= 13.
375382 // This matches Clang, which also enables it since Clang 13.
@@ -389,6 +396,7 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
389396 let using_thin_buffers = opt_stage == llvm:: OptStage :: PreLinkThinLTO || config. bitcode_needed ( ) ;
390397 let pgo_gen_path = get_pgo_gen_path ( config) ;
391398 let pgo_use_path = get_pgo_use_path ( config) ;
399+ let pgo_sample_use_path = get_pgo_sample_use_path ( config) ;
392400 let is_lto = opt_stage == llvm:: OptStage :: ThinLTO || opt_stage == llvm:: OptStage :: FatLTO ;
393401 // Sanitizer instrumentation is only inserted during the pre-link optimization stage.
394402 let sanitizer_options = if !is_lto {
@@ -439,6 +447,8 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
439447 pgo_use_path. as_ref ( ) . map_or ( std:: ptr:: null ( ) , |s| s. as_ptr ( ) ) ,
440448 config. instrument_coverage ,
441449 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 ,
442452 llvm_selfprofiler,
443453 selfprofile_before_pass_callback,
444454 selfprofile_after_pass_callback,
@@ -544,6 +554,9 @@ pub(crate) unsafe fn optimize(
544554 if config. instrument_coverage {
545555 llvm:: LLVMRustAddPass ( mpm, find_pass ( "instrprof" ) . unwrap ( ) ) ;
546556 }
557+ if config. debug_info_for_profiling {
558+ llvm:: LLVMRustAddPass ( mpm, find_pass ( "add-discriminators" ) . unwrap ( ) ) ;
559+ }
547560
548561 add_sanitizer_passes ( config, & mut extra_passes) ;
549562
@@ -1001,6 +1014,7 @@ pub unsafe fn with_llvm_pmb(
10011014 let inline_threshold = config. inline_threshold ;
10021015 let pgo_gen_path = get_pgo_gen_path ( config) ;
10031016 let pgo_use_path = get_pgo_use_path ( config) ;
1017+ let pgo_sample_use_path = get_pgo_sample_use_path ( config) ;
10041018
10051019 llvm:: LLVMRustConfigurePassManagerBuilder (
10061020 builder,
@@ -1011,6 +1025,7 @@ pub unsafe fn with_llvm_pmb(
10111025 prepare_for_thin_lto,
10121026 pgo_gen_path. as_ref ( ) . map_or ( ptr:: null ( ) , |s| s. as_ptr ( ) ) ,
10131027 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 ( ) ) ,
10141029 ) ;
10151030
10161031 llvm:: LLVMPassManagerBuilderSetSizeLevel ( builder, opt_size as u32 ) ;
0 commit comments