Skip to content

Commit 5c88a1c

Browse files
committed
Add -C inline-threshold
Corresponds directly to llvm's inline-threshold
1 parent 6861c51 commit 5c88a1c

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
@@ -264,6 +264,7 @@ pub struct ModuleConfig {
264264
vectorize_loop: bool,
265265
vectorize_slp: bool,
266266
merge_functions: bool,
267+
inline_threshold: Option<usize>
267268
}
268269

269270
unsafe impl Send for ModuleConfig { }
@@ -289,6 +290,7 @@ impl ModuleConfig {
289290
vectorize_loop: false,
290291
vectorize_slp: false,
291292
merge_functions: false,
293+
inline_threshold: None
292294
}
293295
}
294296

@@ -297,6 +299,7 @@ impl ModuleConfig {
297299
self.no_prepopulate_passes = sess.opts.cg.no_prepopulate_passes;
298300
self.no_builtins = trans.no_builtins;
299301
self.time_passes = sess.time_passes();
302+
self.inline_threshold = sess.opts.cg.inline_threshold;
300303

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

10091013
llvm::LLVMRustConfigurePassManagerBuilder(builder, opt,
10101014
config.merge_functions,
@@ -1017,17 +1021,20 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef,
10171021
// always-inline functions (but don't add lifetime intrinsics), at O1 we
10181022
// inline with lifetime intrinsics, and O2+ we add an inliner with a
10191023
// thresholds copied from clang.
1020-
match opt {
1021-
llvm::CodeGenLevelNone => {
1024+
match (opt, inline_threshold) {
1025+
(_, Some(t)) => {
1026+
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, t as u32);
1027+
}
1028+
(llvm::CodeGenLevelNone, _) => {
10221029
llvm::LLVMRustAddAlwaysInlinePass(builder, false);
10231030
}
1024-
llvm::CodeGenLevelLess => {
1031+
(llvm::CodeGenLevelLess, _) => {
10251032
llvm::LLVMRustAddAlwaysInlinePass(builder, true);
10261033
}
1027-
llvm::CodeGenLevelDefault => {
1034+
(llvm::CodeGenLevelDefault, _) => {
10281035
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 225);
10291036
}
1030-
llvm::CodeGenLevelAggressive => {
1037+
(llvm::CodeGenLevelAggressive, _) => {
10311038
llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 275);
10321039
}
10331040
}

0 commit comments

Comments
 (0)