]> git.lizzy.rs Git - rust.git/commitdiff
Add -C inline-threshold
authorBrian Anderson <banderson@mozilla.com>
Fri, 20 Nov 2015 00:07:09 +0000 (16:07 -0800)
committerBrian Anderson <banderson@mozilla.com>
Fri, 20 Nov 2015 01:01:07 +0000 (17:01 -0800)
Corresponds directly to llvm's inline-threshold

src/librustc/session/config.rs
src/librustc_trans/back/write.rs

index 808a63982c263ad10bc74e926763c78c06ed4e08..4781992b9875d76a215ad67b5af1636ceb9da87f 100644 (file)
@@ -513,6 +513,8 @@ fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
         "optimize with possible levels 0-3"),
     debug_assertions: Option<bool> = (None, parse_opt_bool,
         "explicitly enable the cfg(debug_assertions) directive"),
+    inline_threshold: Option<usize> = (None, parse_opt_uint,
+        "set the inlining threshold for"),
 }
 
 
index 17c8d9aa9e1daf1a571e65b2c99cf20860047ff9..f2047814f27b19195bc6a12d8ca8ed8a4d53779f 100644 (file)
@@ -264,6 +264,7 @@ pub struct ModuleConfig {
     vectorize_loop: bool,
     vectorize_slp: bool,
     merge_functions: bool,
+    inline_threshold: Option<usize>
 }
 
 unsafe impl Send for ModuleConfig { }
@@ -289,6 +290,7 @@ fn new(tm: TargetMachineRef, passes: Vec<String>) -> ModuleConfig {
             vectorize_loop: false,
             vectorize_slp: false,
             merge_functions: false,
+            inline_threshold: None
         }
     }
 
@@ -297,6 +299,7 @@ fn set_flags(&mut self, sess: &Session, trans: &CrateTranslation) {
         self.no_prepopulate_passes = sess.opts.cg.no_prepopulate_passes;
         self.no_builtins = trans.no_builtins;
         self.time_passes = sess.time_passes();
+        self.inline_threshold = sess.opts.cg.inline_threshold;
 
         // Copy what clang does by turning on loop vectorization at O2 and
         // slp vectorization at O3. Otherwise configure other optimization aspects
@@ -1005,6 +1008,7 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef,
     // manager.
     let builder = llvm::LLVMPassManagerBuilderCreate();
     let opt = config.opt_level.unwrap_or(llvm::CodeGenLevelNone);
+    let inline_threshold = config.inline_threshold;
 
     llvm::LLVMRustConfigurePassManagerBuilder(builder, opt,
                                               config.merge_functions,
@@ -1017,17 +1021,20 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef,
     // always-inline functions (but don't add lifetime intrinsics), at O1 we
     // inline with lifetime intrinsics, and O2+ we add an inliner with a
     // thresholds copied from clang.
-    match opt {
-        llvm::CodeGenLevelNone => {
+    match (opt, inline_threshold) {
+        (_, Some(t)) => {
+            llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, t as u32);
+        }
+        (llvm::CodeGenLevelNone, _) => {
             llvm::LLVMRustAddAlwaysInlinePass(builder, false);
         }
-        llvm::CodeGenLevelLess => {
+        (llvm::CodeGenLevelLess, _) => {
             llvm::LLVMRustAddAlwaysInlinePass(builder, true);
         }
-        llvm::CodeGenLevelDefault => {
+        (llvm::CodeGenLevelDefault, _) => {
             llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 225);
         }
-        llvm::CodeGenLevelAggressive => {
+        (llvm::CodeGenLevelAggressive, _) => {
             llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 275);
         }
     }