Commit a1db31ea authored by qinsoon's avatar qinsoon

[wip] reg alloc validate

parent 3785c313
extern crate hprof;
use ast::ptr::*;
use ast::ir::*;
use compiler::backend;
use compiler::backend::reg_alloc::graph_coloring;
......@@ -43,6 +44,7 @@ pub struct GraphColoring<'a> {
worklist_spill: Vec<NodeIndex>,
spillable: LinkedHashMap<MuID, bool>,
spilled_nodes: Vec<NodeIndex>,
spill_history: LinkedHashMap<MuID, P<Value>>, // for validation, we need to log all registers get spilled
worklist_freeze: LinkedHashSet<NodeIndex>,
frozen_moves: LinkedHashSet<Move>,
......@@ -53,6 +55,10 @@ pub struct GraphColoring<'a> {
impl <'a> GraphColoring<'a> {
pub fn start (func: &'a mut MuFunctionVersion, cf: &'a mut CompiledFunction, vm: &'a VM) -> GraphColoring<'a> {
GraphColoring::start_with_spill_history(LinkedHashMap::new(), func, cf, vm)
}
fn start_with_spill_history(spill_history: LinkedHashMap<MuID, P<Value>>, func: &'a mut MuFunctionVersion, cf: &'a mut CompiledFunction, vm: &'a VM) -> GraphColoring<'a> {
trace!("Initializing coloring allocator...");
cf.mc().trace_mc();
......@@ -73,10 +79,10 @@ impl <'a> GraphColoring<'a> {
map
},
colored_nodes: Vec::new(),
initial: Vec::new(),
degree: LinkedHashMap::new(),
worklist_moves: Vec::new(),
movelist: LinkedHashMap::new(),
active_moves: LinkedHashSet::new(),
......@@ -84,18 +90,19 @@ impl <'a> GraphColoring<'a> {
coalesced_moves: LinkedHashSet::new(),
constrained_moves: LinkedHashSet::new(),
alias: LinkedHashMap::new(),
worklist_spill: Vec::new(),
spillable: LinkedHashMap::new(),
spilled_nodes: Vec::new(),
spill_history: spill_history,
worklist_freeze: LinkedHashSet::new(),
frozen_moves: LinkedHashSet::new(),
worklist_simplify: LinkedHashSet::new(),
select_stack: Vec::new()
select_stack: Vec::new(),
};
coloring.regalloc()
}
......@@ -177,7 +184,7 @@ impl <'a> GraphColoring<'a> {
self.rewrite_program();
return GraphColoring::start(self.func, self.cf, self.vm);
return GraphColoring::start_with_spill_history(self.spill_history.clone(), self.func, self.cf, self.vm);
}
self
......@@ -664,7 +671,8 @@ impl <'a> GraphColoring<'a> {
};
let mem = self.cf.frame.alloc_slot_for_spilling(ssa_entry.value().clone(), self.vm);
spilled_mem.insert(*reg_id, mem);
spilled_mem.insert(*reg_id, mem.clone());
self.spill_history.insert(*reg_id, mem);
}
// though we are not using this right now
......
......@@ -37,6 +37,10 @@ impl RegisterAllocation {
let coloring = GraphColoring::start(func, &mut cf, vm);
if !vm.vm_options.flag_disable_regalloc_validate {
}
// replace regs
trace!("Replacing Registers...");
for node in coloring.ig.nodes() {
......
pub mod graph_coloring;
//mod regalloc_validate;
pub use compiler::backend::reg_alloc::graph_coloring::RegisterAllocation;
pub fn validate_regalloc(spilled: LinkedHashMap<MuID, P<Value>>, ) {
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ VM:
Compiler:
--disable-inline disable compiler function inlining
--disable-regalloc-validate disable register allocation validation
AOT Compiler:
--aot-emit-dir=<dir> the emit directory for ahead-of-time compiling [default: emit]
......@@ -33,6 +34,7 @@ Garbage Collection:
pub struct VMOptions {
pub flag_log_level: MuLogLevel,
pub flag_disable_inline: bool,
pub flag_disable_regalloc_validate: bool,
pub flag_aot_emit_dir: String,
pub flag_bootimage_external_lib: Vec<String>,
......@@ -52,7 +54,7 @@ impl VMOptions {
pub fn init(str: &str) -> VMOptions {
info!("init vm options with: {:?}", str);
let ret : VMOptions = Docopt::new(USAGE)
let mut ret : VMOptions = Docopt::new(USAGE)
.and_then(|d| d.argv(str.split_whitespace().into_iter()).parse())
.unwrap_or_else(|e| e.exit()).decode().unwrap();
......
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