Skip to content

Commit 39ffd9a

Browse files
committed
Allow switching the regalloc algorithm from the commandline
1 parent f8c2a7e commit 39ffd9a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ pub struct BackendConfig {
4848
/// Can be set using `-Cllvm-args=display_cg_time=...`.
4949
pub display_cg_time: bool,
5050

51+
/// The register allocator to use.
52+
///
53+
/// Defaults to the value of `CG_CLIF_REGALLOC` or `backtracking` otherwise. Can be set using
54+
/// `-Cllvm-args=regalloc=...`.
55+
pub regalloc: String,
56+
5157
/// Enable the Cranelift ir verifier for all compilation passes. If not set it will only run
5258
/// once before passing the clif ir to Cranelift for compilation.
5359
///
@@ -74,6 +80,8 @@ impl Default for BackendConfig {
7480
args.split(' ').map(|arg| arg.to_string()).collect()
7581
},
7682
display_cg_time: bool_env_var("CG_CLIF_DISPLAY_CG_TIME"),
83+
regalloc: std::env::var("CG_CLIF_REGALLOC")
84+
.unwrap_or_else(|_| "backtracking".to_string()),
7785
enable_verifier: cfg!(debug_assertions) || bool_env_var("CG_CLIF_ENABLE_VERIFIER"),
7886
disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"),
7987
}
@@ -93,6 +101,7 @@ impl BackendConfig {
93101
match name {
94102
"mode" => config.codegen_mode = value.parse()?,
95103
"display_cg_time" => config.display_cg_time = parse_bool(name, value)?,
104+
"regalloc" => config.regalloc = value.to_string(),
96105
"enable_verifier" => config.enable_verifier = parse_bool(name, value)?,
97106
"disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?,
98107
_ => return Err(format!("Unknown option `{}`", name)),

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box<dyn isa::Tar
256256

257257
flags_builder.set("enable_llvm_abi_extensions", "true").unwrap();
258258

259+
flags_builder.set("regalloc", &backend_config.regalloc).unwrap();
260+
259261
use rustc_session::config::OptLevel;
260262
match sess.opts.optimize {
261263
OptLevel::No => {

0 commit comments

Comments
 (0)