Skip to content

Commit 2228bac

Browse files
committed
Auto merge of #29943 - brson:inline-threshold, r=nrc
Corresponds directly to llvm's inline-threshold. I want this so I can experiment out-of-tree with tweaking optimization settings, and this is the most important value that isn't exposed. I can't get it to work either via `-C llvm-args`. cc @rust-lang/compiler
2 parents e5c69b1 + 5c88a1c commit 2228bac

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
513513
"optimize with possible levels 0-3"),
514514
debug_assertions: Option<bool> = (None, parse_opt_bool,
515515
"explicitly enable the cfg(debug_assertions) directive"),
516+
inline_threshold: Option<usize> = (None, parse_opt_uint,
517+
"set the inlining threshold for"),
516518
}
517519

518520

src/librustc_trans/back/write.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ pub struct ModuleConfig {
263263
vectorize_loop: bool,
264264
vectorize_slp: bool,
265265
merge_functions: bool,
266+
inline_threshold: Option<usize>
266267
}
267268

268269
unsafe impl Send for ModuleConfig { }
@@ -288,6 +289,7 @@ impl ModuleConfig {
288289
vectorize_loop: false,
289290
vectorize_slp: false,
290291
merge_functions: false,
292+
inline_threshold: None
291293
}
292294
}
293295

@@ -296,6 +298,7 @@ impl ModuleConfig {
296298
self.no_prepopulate_passes = sess.opts.cg.no_prepopulate_passes;
297299
self.no_builtins = trans.no_builtins;
298300
self.time_passes = sess.time_passes();
301+
self.inline_threshold = sess.opts.cg.inline_threshold;
299302

300303
// Copy what clang does by turning on loop vectorization at O2 and
301304
// slp vectorization at O3. Otherwise configure other optimization aspects
@@ -1004,6 +1007,7 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef,
10041007
// manager.
10051008
let builder = llvm::LLVMPassManagerBuilderCreate();
10061009
let opt = config.opt_level.unwrap_or(llvm::CodeGenLevelNone);
1010+
let inline_threshold = config.inline_threshold;
10071011

10081012
llvm::LLVMRustConfigurePassManagerBuilder(builder, opt,
10091013
config.merge_functions,
@@ -1016,17 +1020,20 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef,
10161020
// always-inline functions (but don't add lifetime intrinsics), at O1 we
10171021
// inline with lifetime intrinsics, and O2+ we add an inliner with a
10181022
// thresholds copied from clang.
1019-
match opt {
1020-
llvm::CodeGenLevelNone => {
1023+
match (opt, inline_threshold) {
1024+
(_, Some(t)) => {
1025+
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, t as u32);
1026+
}
1027+
(llvm::CodeGenLevelNone, _) => {
10211028
llvm::LLVMRustAddAlwaysInlinePass(builder, false);
10221029
}
1023-
llvm::CodeGenLevelLess => {
1030+
(llvm::CodeGenLevelLess, _) => {
10241031
llvm::LLVMRustAddAlwaysInlinePass(builder, true);
10251032
}
1026-
llvm::CodeGenLevelDefault => {
1033+
(llvm::CodeGenLevelDefault, _) => {
10271034
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 225);
10281035
}
1029-
llvm::CodeGenLevelAggressive => {
1036+
(llvm::CodeGenLevelAggressive, _) => {
10301037
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 275);
10311038
}
10321039
}

0 commit comments

Comments
 (0)