Commit 3d1b37f7 authored by qinsoon's avatar qinsoon

prioritize using callee-saved regs. If any caller-saved reg is used, panic

parent 9ebbb02c
...@@ -194,21 +194,23 @@ lazy_static! { ...@@ -194,21 +194,23 @@ lazy_static! {
XMM15.clone() XMM15.clone()
]; ];
// put callee saved regs first
pub static ref ALL_USABLE_MACHINE_REGs : Vec<P<Value>> = vec![ pub static ref ALL_USABLE_MACHINE_REGs : Vec<P<Value>> = vec![
RBX.clone(),
R12.clone(),
R13.clone(),
R14.clone(),
R15.clone(),
RAX.clone(), RAX.clone(),
RCX.clone(), RCX.clone(),
RDX.clone(), RDX.clone(),
RBX.clone(),
RSI.clone(), RSI.clone(),
RDI.clone(), RDI.clone(),
R8.clone(), R8.clone(),
R9.clone(), R9.clone(),
R10.clone(), R10.clone(),
R11.clone(), R11.clone(),
R12.clone(),
R13.clone(),
R14.clone(),
R15.clone(),
XMM0.clone(), XMM0.clone(),
XMM1.clone(), XMM1.clone(),
XMM2.clone(), XMM2.clone(),
...@@ -273,6 +275,16 @@ pub fn pick_group_for_reg(reg_id: MuID) -> RegGroup { ...@@ -273,6 +275,16 @@ pub fn pick_group_for_reg(reg_id: MuID) -> RegGroup {
} }
} }
pub fn is_callee_saved(reg_id: MuID) -> bool {
for reg in CALLEE_SAVED_GPRs.iter() {
if reg_id == reg.extract_ssa_id().unwrap() {
return true;
}
}
false
}
pub fn is_valid_x86_imm(op: &P<Value>) -> bool { pub fn is_valid_x86_imm(op: &P<Value>) -> bool {
use std::u32; use std::u32;
match op.v { match op.v {
......
...@@ -22,6 +22,8 @@ pub use compiler::backend::x86_64::all_regs; ...@@ -22,6 +22,8 @@ pub use compiler::backend::x86_64::all_regs;
pub use compiler::backend::x86_64::all_usable_regs; pub use compiler::backend::x86_64::all_usable_regs;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub use compiler::backend::x86_64::pick_group_for_reg; pub use compiler::backend::x86_64::pick_group_for_reg;
#[cfg(target_arch = "x86_64")]
pub use compiler::backend::x86_64::is_callee_saved;
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
#[path = "arch/arm/mod.rs"] #[path = "arch/arm/mod.rs"]
......
...@@ -559,6 +559,11 @@ impl GraphColoring { ...@@ -559,6 +559,11 @@ impl GraphColoring {
} else { } else {
let first_available_color = ok_colors.pop_front().unwrap(); let first_available_color = ok_colors.pop_front().unwrap();
trace!("Color {} as {}", self.node_info(n), first_available_color); trace!("Color {} as {}", self.node_info(n), first_available_color);
if !backend::is_callee_saved(first_available_color) {
panic!("using a non-callee-saved register. need to go to compiler slowpath. Unimplemented");
}
self.colored_nodes.push(n); self.colored_nodes.push(n);
self.ig.color_node(n, first_available_color); self.ig.color_node(n, first_available_color);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment