Commit 8f9266c0 authored by qinsoon's avatar qinsoon

[wip] going to refactor TreeNode

parent 2f47b866
......@@ -102,7 +102,6 @@ pub struct MuFunctionVersion {
pub func_id: MuID,
pub sig: P<MuFuncSig>,
pub original_ir: Option<FunctionContent>,
pub content: Option<FunctionContent>,
pub context: FunctionContext,
......@@ -139,7 +138,6 @@ impl MuFunctionVersion {
hdr: MuEntityHeader::unnamed(id),
func_id: func,
sig: sig,
original_ir: None,
content: None,
context: FunctionContext::new(),
block_trace: None
......@@ -147,7 +145,6 @@ impl MuFunctionVersion {
}
pub fn define(&mut self, content: FunctionContent) {
self.original_ir = Some(content.clone());
self.content = Some(content);
}
......@@ -374,9 +371,13 @@ pub struct BlockContent {
impl fmt::Debug for BlockContent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "args: {:?}", self.args).unwrap();
writeln!(f, "exception arg: {:?}", self.args).unwrap();
writeln!(f, "keepalives: {:?}", self.keepalives).unwrap();
writeln!(f, "args: {}", vec_utils::as_str(&self.args)).unwrap();
if self.exn_arg.is_some() {
writeln!(f, "exception arg: {}", self.exn_arg.as_ref().unwrap()).unwrap();
}
if self.keepalives.is_some() {
writeln!(f, "keepalives: {}", vec_utils::as_str(self.keepalives.as_ref().unwrap())).unwrap();
}
for node in self.body.iter() {
writeln!(f, "{}", node).unwrap();
}
......@@ -877,7 +878,7 @@ impl PartialEq for MuEntityHeader {
impl fmt::Display for MuEntityHeader {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.name().is_none() {
write!(f, "#{}", self.id)
write!(f, "UNNAMED #{}", self.id)
} else {
write!(f, "{} #{}", self.name().unwrap(), self.id)
}
......
......@@ -147,7 +147,9 @@ impl ASMCode {
loc.line += inst_offset;
}
}
// 2. we can ignore preds/succs - CFA is required anyway
// 2. we need to delete existing preds/succs - CFA is required later
inst.preds.clear();
inst.succs.clear();
// 3. add the inst
ret.code.push(inst);
......@@ -790,7 +792,7 @@ impl ASMCodeGen {
loc_cursor += str.len();
},
Value_::Constant(Constant::Int(val)) => {
let str = val.to_string();
let str = (val as i32).to_string();
result_str.push_str(&str);
loc_cursor += str.len();
......@@ -828,7 +830,7 @@ impl ASMCodeGen {
loc_cursor += str.len();
},
Value_::Constant(Constant::Int(val)) => {
let str = val.to_string();
let str = (val as i32).to_string();
result_str.push_str(&str);
loc_cursor += str.len();
......@@ -1822,6 +1824,7 @@ pub fn spill_rewrite(
codegen.finish_code_sequence_asm()
};
// record that this load will be inserted at i
trace!("insert before inst #{}", i);
if spill_code_before.contains_key(&i) {
spill_code_before.get_mut(&i).unwrap().push(code);
} else {
......@@ -1853,6 +1856,7 @@ pub fn spill_rewrite(
codegen.finish_code_sequence_asm()
};
trace!("insert after inst #{}", i);
if spill_code_after.contains_key(&i) {
spill_code_after.get_mut(&i).unwrap().push(code);
} else {
......
......@@ -46,6 +46,8 @@ pub struct GraphColoring {
impl GraphColoring {
pub fn start (func: &mut MuFunctionVersion, cf: &mut CompiledFunction, vm: &VM) -> Result<GraphColoring, RegAllocFailure> {
cf.mc().trace_mc();
let mut coloring = GraphColoring {
ig: graph_coloring::build_inteference_graph(cf, func),
......@@ -88,6 +90,13 @@ impl GraphColoring {
fn regalloc(&mut self, func: &mut MuFunctionVersion, cf: &mut CompiledFunction, vm: &VM) -> Result<(), RegAllocFailure> {
trace!("Initializing coloring allocator...");
trace!("---InterenceGraph---");
self.ig.print();
trace!("---All temps---");
for entry in func.context.values.values() {
trace!("{}", entry);
}
// precolor for all machine registers
for reg in backend::all_regs().values() {
......@@ -136,6 +145,13 @@ impl GraphColoring {
if !self.spilled_nodes.is_empty() {
trace!("spill required");
if cfg!(debug_assertions) {
trace!("nodes to be spilled:");
for node in self.spilled_nodes.iter() {
trace!("{:?}: {:?}", node, self.ig.get_temp_of(*node));
}
}
self.rewrite_program(func, cf, vm);
GraphColoring::start(func, cf, vm);
......
......@@ -32,8 +32,6 @@ impl RegisterAllocation {
let compiled_funcs = vm.compiled_funcs().read().unwrap();
let mut cf = compiled_funcs.get(&func.id()).unwrap().write().unwrap();
cf.mc().trace_mc();
// initialize machine registers for the function context
init_machine_regs_for_func(&mut func.context);
......@@ -52,7 +50,13 @@ impl RegisterAllocation {
continue;
} else {
let alias = coloring.get_alias(node);
let machine_reg = coloring.ig.get_color_of(alias).unwrap();
let machine_reg = match coloring.ig.get_color_of(alias) {
Some(reg) => reg,
None => panic!(
"Reg{}/{:?} (aliased as Reg{}/{:?}) is not assigned with a color",
coloring.ig.get_temp_of(node), node,
coloring.ig.get_temp_of(alias), alias)
};
trace!("replacing {} with {}", temp, machine_reg);
cf.mc_mut().replace_reg(temp, machine_reg);
......
......@@ -128,23 +128,23 @@ fn create_spill1() -> VM {
let blk_entry_t1 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t1"));
let blk_entry_t2 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t2"));
vm.set_name(blk_entry_t2.as_entity(), Mu("blk_entry_t2"));
let blk_entry_t3 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t3"));
vm.set_name(blk_entry_t3.as_entity(), Mu("blk_entry_t3"));
let blk_entry_t4 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t4"));
vm.set_name(blk_entry_t4.as_entity(), Mu("blk_entry_t4"));
let blk_entry_t5 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t5"));
vm.set_name(blk_entry_t5.as_entity(), Mu("blk_entry_t5"));
let blk_entry_t6 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t6"));
vm.set_name(blk_entry_t6.as_entity(), Mu("blk_entry_t6"));
let blk_entry_t7 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t7"));
vm.set_name(blk_entry_t7.as_entity(), Mu("blk_entry_t7"));
let blk_entry_t8 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t8"));
vm.set_name(blk_entry_t8.as_entity(), Mu("blk_entry_t8"));
let blk_entry_t9 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t9"));
vm.set_name(blk_entry_t9.as_entity(), Mu("blk_entry_t9"));
let blk_entry_t10= func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t10"));
vm.set_name(blk_entry_t10.as_entity(), Mu("blk_entry_t10"));
// %x = CALL spill1(%t1, %t2, ... t10)
let blk_entry_x = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
......
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