about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2021-05-26 14:00:58 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2021-05-26 14:00:58 +0200
commit39ffd9ae4aec7d908dabc9a7b1f384956e197978 (patch)
tree197005e7612b6fb8a6a1d3f7235267d8df85c32c
parentf8c2a7ec00923ce12c14df5e246c665ea445fb6b (diff)
downloadrust-39ffd9ae4aec7d908dabc9a7b1f384956e197978.tar.gz
rust-39ffd9ae4aec7d908dabc9a7b1f384956e197978.zip
Allow switching the regalloc algorithm from the commandline
-rw-r--r--src/config.rs9
-rw-r--r--src/lib.rs2
2 files changed, 11 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index e59a0cb0a23..eef3c8c8d6e 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -48,6 +48,12 @@ pub struct BackendConfig {
     /// Can be set using `-Cllvm-args=display_cg_time=...`.
     pub display_cg_time: bool,
 
+    /// The register allocator to use.
+    ///
+    /// Defaults to the value of `CG_CLIF_REGALLOC` or `backtracking` otherwise. Can be set using
+    /// `-Cllvm-args=regalloc=...`.
+    pub regalloc: String,
+
     /// Enable the Cranelift ir verifier for all compilation passes. If not set it will only run
     /// once before passing the clif ir to Cranelift for compilation.
     ///
@@ -74,6 +80,8 @@ impl Default for BackendConfig {
                 args.split(' ').map(|arg| arg.to_string()).collect()
             },
             display_cg_time: bool_env_var("CG_CLIF_DISPLAY_CG_TIME"),
+            regalloc: std::env::var("CG_CLIF_REGALLOC")
+                .unwrap_or_else(|_| "backtracking".to_string()),
             enable_verifier: cfg!(debug_assertions) || bool_env_var("CG_CLIF_ENABLE_VERIFIER"),
             disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"),
         }
@@ -93,6 +101,7 @@ impl BackendConfig {
                 match name {
                     "mode" => config.codegen_mode = value.parse()?,
                     "display_cg_time" => config.display_cg_time = parse_bool(name, value)?,
+                    "regalloc" => config.regalloc = value.to_string(),
                     "enable_verifier" => config.enable_verifier = parse_bool(name, value)?,
                     "disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?,
                     _ => return Err(format!("Unknown option `{}`", name)),
diff --git a/src/lib.rs b/src/lib.rs
index a9475997f75..4ee887cd5af 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -256,6 +256,8 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box<dyn isa::Tar
 
     flags_builder.set("enable_llvm_abi_extensions", "true").unwrap();
 
+    flags_builder.set("regalloc", &backend_config.regalloc).unwrap();
+
     use rustc_session::config::OptLevel;
     match sess.opts.optimize {
         OptLevel::No => {