about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-11-20 05:09:24 +0000
committerbors <bors@rust-lang.org>2015-11-20 05:09:24 +0000
commit2228bacd62ca8970a7a59401e78d0c5a34fc0f87 (patch)
treeb67451c50d22fc666391f9dce7286e55bca0f0e4
parente5c69b10c33990c14a239cf53d25763013dc84a4 (diff)
parent5c88a1cd54f709823431cd5eac67fc24d3d59b30 (diff)
downloadrust-2228bacd62ca8970a7a59401e78d0c5a34fc0f87.tar.gz
rust-2228bacd62ca8970a7a59401e78d0c5a34fc0f87.zip
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
-rw-r--r--src/librustc/session/config.rs2
-rw-r--r--src/librustc_trans/back/write.rs17
2 files changed, 14 insertions, 5 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index 808a63982c2..4781992b987 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -513,6 +513,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
         "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"),
 }
 
 
diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs
index 1a4007026fb..5ac27d61227 100644
--- a/src/librustc_trans/back/write.rs
+++ b/src/librustc_trans/back/write.rs
@@ -263,6 +263,7 @@ pub struct ModuleConfig {
     vectorize_loop: bool,
     vectorize_slp: bool,
     merge_functions: bool,
+    inline_threshold: Option<usize>
 }
 
 unsafe impl Send for ModuleConfig { }
@@ -288,6 +289,7 @@ impl ModuleConfig {
             vectorize_loop: false,
             vectorize_slp: false,
             merge_functions: false,
+            inline_threshold: None
         }
     }
 
@@ -296,6 +298,7 @@ impl ModuleConfig {
         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
@@ -1004,6 +1007,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,
@@ -1016,17 +1020,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);
         }
     }