To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit a1db31ea authored by qinsoon's avatar qinsoon
Browse files

[wip] reg alloc validate

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