@@ -240,6 +240,9 @@ pub struct ModuleConfig {
240
240
/// Some(level) to optimize binary size, or None to not affect program size.
241
241
opt_size : Option < llvm:: CodeGenOptSize > ,
242
242
243
+ pgo_gen : Option < String > ,
244
+ pgo_use : String ,
245
+
243
246
// Flags indicating which outputs to produce.
244
247
emit_no_opt_bc : bool ,
245
248
emit_bc : bool ,
@@ -274,6 +277,9 @@ impl ModuleConfig {
274
277
opt_level : None ,
275
278
opt_size : None ,
276
279
280
+ pgo_gen : None ,
281
+ pgo_use : String :: new ( ) ,
282
+
277
283
emit_no_opt_bc : false ,
278
284
emit_bc : false ,
279
285
emit_bc_compressed : false ,
@@ -932,6 +938,9 @@ pub fn start_async_translation(tcx: TyCtxt,
932
938
modules_config. passes . push ( "insert-gcov-profiling" . to_owned ( ) )
933
939
}
934
940
941
+ modules_config. pgo_gen = sess. opts . cg . pgo_gen . clone ( ) ;
942
+ modules_config. pgo_use = sess. opts . cg . pgo_use . clone ( ) ;
943
+
935
944
modules_config. opt_level = Some ( get_llvm_opt_level ( sess. opts . optimize ) ) ;
936
945
modules_config. opt_size = Some ( get_llvm_opt_size ( sess. opts . optimize ) ) ;
937
946
@@ -2046,18 +2055,36 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef,
2046
2055
config : & ModuleConfig ,
2047
2056
opt_level : llvm:: CodeGenOptLevel ,
2048
2057
f : & mut FnMut ( llvm:: PassManagerBuilderRef ) ) {
2058
+ use std:: ptr;
2059
+
2049
2060
// Create the PassManagerBuilder for LLVM. We configure it with
2050
2061
// reasonable defaults and prepare it to actually populate the pass
2051
2062
// manager.
2052
2063
let builder = llvm:: LLVMPassManagerBuilderCreate ( ) ;
2053
2064
let opt_size = config. opt_size . unwrap_or ( llvm:: CodeGenOptSizeNone ) ;
2054
2065
let inline_threshold = config. inline_threshold ;
2055
2066
2056
- llvm:: LLVMRustConfigurePassManagerBuilder ( builder,
2057
- opt_level,
2058
- config. merge_functions ,
2059
- config. vectorize_slp ,
2060
- config. vectorize_loop ) ;
2067
+ let pgo_gen_path = config. pgo_gen . as_ref ( ) . map ( |s| {
2068
+ let s = if s. is_empty ( ) { "default_%m.profraw" } else { s } ;
2069
+ CString :: new ( s. as_bytes ( ) ) . unwrap ( )
2070
+ } ) ;
2071
+
2072
+ let pgo_use_path = if config. pgo_use . is_empty ( ) {
2073
+ None
2074
+ } else {
2075
+ Some ( CString :: new ( config. pgo_use . as_bytes ( ) ) . unwrap ( ) )
2076
+ } ;
2077
+
2078
+ llvm:: LLVMRustConfigurePassManagerBuilder (
2079
+ builder,
2080
+ opt_level,
2081
+ config. merge_functions ,
2082
+ config. vectorize_slp ,
2083
+ config. vectorize_loop ,
2084
+ pgo_gen_path. as_ref ( ) . map_or ( ptr:: null ( ) , |s| s. as_ptr ( ) ) ,
2085
+ pgo_use_path. as_ref ( ) . map_or ( ptr:: null ( ) , |s| s. as_ptr ( ) ) ,
2086
+ ) ;
2087
+
2061
2088
llvm:: LLVMPassManagerBuilderSetSizeLevel ( builder, opt_size as u32 ) ;
2062
2089
2063
2090
if opt_size != llvm:: CodeGenOptSizeNone {
0 commit comments