Commit c626fc25 authored by qinsoon's avatar qinsoon

[wip] keep refactoring

parent 76504d0b
build_targets=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\n<build_targets xmlns\="com.github.rustdt.ide.core">\n<target auto_enabled\="false" config\="build" n_enabled\="true" version2\="true"/>\n<target auto_enabled\="true" config\="check" n_enabled\="false" version2\="true">\n<command_invocation append_env\="true" command_arguments\="${CARGO_TOOL_PATH} build">\n<env_vars/>\n</command_invocation>\n</target>\n</build_targets>\n
build_targets=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\n<build_targets xmlns\="com.github.rustdt.ide.core">\n<target auto_enabled\="true" config\="build" n_enabled\="true" version2\="true"/>\n<target auto_enabled\="false" config\="check" n_enabled\="false" version2\="true">\n<command_invocation append_env\="true" command_arguments\="${CARGO_TOOL_PATH} build">\n<env_vars/>\n</command_invocation>\n</target>\n</build_targets>\n
eclipse.preferences.version=1
......@@ -346,7 +346,7 @@ impl ResumptionData {
#[derive(Clone, Debug)]
pub struct Destination {
pub target: MuName,
pub target: MuID,
pub args: Vec<DestArg>
}
......
......@@ -19,16 +19,19 @@ pub type OpIndex = usize;
#[derive(Debug)]
pub struct MuFunction {
pub fn_name: MuName,
pub id: MuID,
pub name: Option<MuName>,
pub sig: P<MuFuncSig>,
pub cur_ver: Option<MuName>,
pub all_vers: Vec<MuName>
pub cur_ver: Option<MuID>,
pub all_vers: Vec<MuID>
}
impl MuFunction {
pub fn new(fn_name: MuName, sig: P<MuFuncSig>) -> MuFunction {
pub fn new(id: MuID, sig: P<MuFuncSig>) -> MuFunction {
MuFunction {
fn_name: fn_name,
id: id,
name: None,
sig: sig,
cur_ver: None,
all_vers: vec![]
......@@ -36,25 +39,47 @@ impl MuFunction {
}
}
impl fmt::Display for MuFunction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.name.is_none() {
write!(f, "Func #{}", self.id)
} else {
write!(f, "Func {}#{}", self.name.unwrap(), self.id)
}
}
}
#[derive(Debug)]
pub struct MuFunctionVersion {
pub fn_name: MuName,
pub version: MuName,
pub id: MuID,
pub name: Option<MuName>,
pub func_id: MuID,
pub sig: P<MuFuncSig>,
pub content: Option<FunctionContent>,
pub context: FunctionContext,
pub block_trace: Option<Vec<MuName>> // only available after Trace Generation Pass
pub block_trace: Option<Vec<MuID>> // only available after Trace Generation Pass
}
impl fmt::Display for MuFunctionVersion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.name.is_none() {
write!(f, "FuncVer #{} of Func#{}", self.id, self.func_id)
} else {
write!(f, "FuncVer {}#{} of Func#{}", self.name.unwrap(), self.id, self.func_id)
}
}
}
pub const RESERVED_NODE_IDS_FOR_MACHINE : usize = 100;
impl MuFunctionVersion {
pub fn new(fn_name: MuName, ver: MuName, sig: P<MuFuncSig>) -> MuFunctionVersion {
pub fn new(id: MuID, func: MuID, sig: P<MuFuncSig>) -> MuFunctionVersion {
MuFunctionVersion{
fn_name: fn_name,
version: ver,
id: id,
name: None,
func_id: func,
sig: sig,
content: None,
context: FunctionContext::new(),
......@@ -71,6 +96,7 @@ impl MuFunctionVersion {
P(TreeNode {
id: id,
name: None,
op: pick_op_code_for_ssa(&ty),
v: TreeNode_::Value(P(Value{
tag: tag,
......@@ -83,6 +109,7 @@ impl MuFunctionVersion {
pub fn new_constant(&mut self, id: MuID, v: P<Value>) -> P<TreeNode> {
P(TreeNode{
id: id,
name: None,
op: pick_op_code_for_value(&v.ty),
v: TreeNode_::Value(v)
})
......@@ -91,6 +118,7 @@ impl MuFunctionVersion {
pub fn new_global(&mut self, id: MuID, v: P<Value>) -> P<TreeNode> {
P(TreeNode{
id: id,
name: None,
op: pick_op_code_for_value(&v.ty),
v: TreeNode_::Value(v)
})
......@@ -99,6 +127,7 @@ impl MuFunctionVersion {
pub fn new_inst(&mut self, id: MuID, v: Instruction) -> P<TreeNode> {
P(TreeNode{
id: id,
name: None,
op: pick_op_code_for_inst(&v),
v: TreeNode_::Instruction(v),
})
......@@ -107,33 +136,33 @@ impl MuFunctionVersion {
#[derive(Debug)]
pub struct FunctionContent {
pub entry: MuName,
pub blocks: HashMap<MuName, Block>
pub entry: MuID,
pub blocks: HashMap<MuID, Block>
}
impl FunctionContent {
pub fn get_entry_block(&self) -> &Block {
self.get_block(self.entry)
}
}
pub fn get_entry_block_mut(&mut self) -> &mut Block {
let entry = self.entry;
self.get_block_mut(entry)
}
pub fn get_block(&self, tag: MuName) -> &Block {
let ret = self.blocks.get(tag);
pub fn get_block(&self, id: MuID) -> &Block {
let ret = self.blocks.get(&id);
match ret {
Some(b) => b,
None => panic!("cannot find block {}", tag)
None => panic!("cannot find block #{}", id)
}
}
pub fn get_block_mut(&mut self, tag: MuName) -> &mut Block {
let ret = self.blocks.get_mut(tag);
pub fn get_block_mut(&mut self, id: MuID) -> &mut Block {
let ret = self.blocks.get_mut(&id);
match ret {
Some(b) => b,
None => panic!("cannot find block {}", tag)
None => panic!("cannot find block #{}", id)
}
}
}
......@@ -179,25 +208,26 @@ impl FunctionContext {
#[derive(Debug)]
pub struct Block {
pub label: MuName,
pub id: MuID,
pub name: Option<MuName>,
pub content: Option<BlockContent>,
pub control_flow: ControlFlow
}
impl Block {
pub fn new(label: MuName) -> Block {
Block{label: label, content: None, control_flow: ControlFlow::default()}
pub fn new(id: MuID) -> Block {
Block{id: id, name: None, content: None, control_flow: ControlFlow::default()}
}
}
#[derive(Debug)]
pub struct ControlFlow {
pub preds : Vec<MuName>,
pub preds : Vec<MuID>,
pub succs : Vec<BlockEdge>
}
impl ControlFlow {
pub fn get_hottest_succ(&self) -> Option<MuName> {
pub fn get_hottest_succ(&self) -> Option<MuID> {
if self.succs.len() == 0 {
None
} else {
......@@ -231,7 +261,7 @@ impl default::Default for ControlFlow {
#[derive(Copy, Clone, Debug)]
pub struct BlockEdge {
pub target: MuName,
pub target: MuID,
pub kind: EdgeKind,
pub is_exception: bool,
pub probability: f32
......@@ -330,6 +360,7 @@ impl BlockContent {
/// always use with P<TreeNode>
pub struct TreeNode {
pub id: MuID,
pub name: Option<MuName>,
pub op: OpCode,
pub v: TreeNode_,
}
......@@ -339,6 +370,7 @@ impl TreeNode {
pub fn new_inst(id: MuID, v: Instruction) -> P<TreeNode> {
P(TreeNode{
id: id,
name: None,
op: pick_op_code_for_inst(&v),
v: TreeNode_::Instruction(v),
})
......
......@@ -920,82 +920,93 @@ impl CodeGenerator for ASMCodeGen {
unimplemented!()
}
fn emit_jmp(&mut self, dest: &Destination) {
trace!("emit: jmp {}", dest.target);
fn emit_jmp(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: jmp {}", dest_name);
// symbolic label, we dont need to patch it
let asm = format!("jmp {}", self.asm_block_label(dest.target));
self.add_asm_branch(asm, dest.target)
let asm = format!("jmp {}", self.asm_block_label(dest_name));
self.add_asm_branch(asm, dest_name)
}
fn emit_je(&mut self, dest: &Destination) {
trace!("emit: je {}", dest.target);
fn emit_je(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: je {}", dest_name);
let asm = format!("je {}", self.asm_block_label(dest.target));
self.add_asm_branch2(asm, dest.target);
let asm = format!("je {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest_name);
}
fn emit_jne(&mut self, dest: &Destination) {
trace!("emit: jne {}", dest.target);
fn emit_jne(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: jne {}", dest_name);
let asm = format!("jne {}", self.asm_block_label(dest.target));
self.add_asm_branch2(asm, dest.target);
let asm = format!("jne {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest_name);
}
fn emit_ja(&mut self, dest: &Destination) {
trace!("emit: ja {}", dest.target);
fn emit_ja(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: ja {}", dest_name);
let asm = format!("ja {}", self.asm_block_label(dest.target));
self.add_asm_branch2(asm, dest.target);
let asm = format!("ja {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest_name);
}
fn emit_jae(&mut self, dest: &Destination) {
trace!("emit: jae {}", dest.target);
fn emit_jae(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: jae {}", dest_name);
let asm = format!("jae {}", self.asm_block_label(dest.target));
self.add_asm_branch2(asm, dest.target);
let asm = format!("jae {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest_name);
}
fn emit_jb(&mut self, dest: &Destination) {
trace!("emit: jb {}", dest.target);
fn emit_jb(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: jb {}", dest_name);
let asm = format!("jb {}", self.asm_block_label(dest.target));
self.add_asm_branch2(asm, dest.target);
let asm = format!("jb {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest_name);
}
fn emit_jbe(&mut self, dest: &Destination) {
trace!("emit: jbe {}", dest.target);
fn emit_jbe(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: jbe {}", dest_name);
let asm = format!("jbe {}", self.asm_block_label(dest.target));
self.add_asm_branch2(asm, dest.target);
let asm = format!("jbe {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest_name);
}
fn emit_jg(&mut self, dest: &Destination) {
trace!("emit: jg {}", dest.target);
fn emit_jg(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: jg {}", dest_name);
let asm = format!("jg {}", self.asm_block_label(dest.target));
self.add_asm_branch2(asm, dest.target);
let asm = format!("jg {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest_name);
}
fn emit_jge(&mut self, dest: &Destination) {
trace!("emit: jge {}", dest.target);
fn emit_jge(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: jge {}", dest_name);
let asm = format!("jge {}", self.asm_block_label(dest.target));
self.add_asm_branch2(asm, dest.target);
let asm = format!("jge {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest_name);
}
fn emit_jl(&mut self, dest: &Destination) {
trace!("emit: jl {}", dest.target);
fn emit_jl(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: jl {}", dest_name);
let asm = format!("jl {}", self.asm_block_label(dest.target));
self.add_asm_branch2(asm, dest.target);
let asm = format!("jl {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest_name);
}
fn emit_jle(&mut self, dest: &Destination) {
trace!("emit: jle {}", dest.target);
fn emit_jle(&mut self, dest: &Block) {
let dest_name = dest.name.unwrap();
trace!("emit: jle {}", dest_name);
let asm = format!("jle {}", self.asm_block_label(dest.target));
self.add_asm_branch2(asm, dest.target);
let asm = format!("jle {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest_name);
}
fn emit_call_near_rel32(&mut self, func: MuName) {
......@@ -1077,7 +1088,7 @@ pub fn emit_code(func: &mut MuFunctionVersion, vm: &VM) {
use std::path;
let compiled_funcs = vm.compiled_funcs().read().unwrap();
let cf = compiled_funcs.get(func.fn_name).unwrap().borrow();
let cf = compiled_funcs.get(&func.id).unwrap().borrow();
let code = cf.mc.emit();
......@@ -1086,7 +1097,7 @@ pub fn emit_code(func: &mut MuFunctionVersion, vm: &VM) {
let mut file_path = path::PathBuf::new();
file_path.push(EMIT_DIR);
file_path.push(func.fn_name.to_string() + ".s");
file_path.push(func.name.unwrap().to_string() + ".s");
let mut file = match File::create(file_path.as_path()) {
Err(why) => panic!("couldn't create emission file {}: {}", file_path.to_str().unwrap(), why),
Ok(file) => file
......
......@@ -36,17 +36,17 @@ pub trait CodeGenerator {
fn emit_mul_r64(&mut self, src: &P<Value>);
fn emit_mul_mem64(&mut self, src: &P<Value>);
fn emit_jmp(&mut self, dest: &Destination);
fn emit_je(&mut self, dest: &Destination);
fn emit_jne(&mut self, dest: &Destination);
fn emit_ja(&mut self, dest: &Destination);
fn emit_jae(&mut self, dest: &Destination);
fn emit_jb(&mut self, dest: &Destination);
fn emit_jbe(&mut self, dest: &Destination);
fn emit_jg(&mut self, dest: &Destination);
fn emit_jge(&mut self, dest: &Destination);
fn emit_jl(&mut self, dest: &Destination);
fn emit_jle(&mut self, dest: &Destination);
fn emit_jmp(&mut self, dest: &Block);
fn emit_je(&mut self, dest: &Block);
fn emit_jne(&mut self, dest: &Block);
fn emit_ja(&mut self, dest: &Block);
fn emit_jae(&mut self, dest: &Block);
fn emit_jb(&mut self, dest: &Block);
fn emit_jbe(&mut self, dest: &Block);
fn emit_jg(&mut self, dest: &Block);
fn emit_jge(&mut self, dest: &Block);
fn emit_jl(&mut self, dest: &Block);
fn emit_jle(&mut self, dest: &Block);
fn emit_call_near_rel32(&mut self, func: MuName);
fn emit_call_near_r64(&mut self, func: &P<Value>);
......
......@@ -59,22 +59,24 @@ impl <'a> InstructionSelection {
self.process_dest(&ops, fallthrough_dest, cur_func, vm);
self.process_dest(&ops, branch_dest, cur_func, vm);
let branch_target = cur_func.content.as_ref().unwrap().get_block(branch_dest.target);
let ref cond = ops[cond];
if self.match_cmp_res(cond) {
trace!("emit cmp_eq-branch2");
match self.emit_cmp_res(cond, cur_func, vm) {
op::CmpOp::EQ => self.backend.emit_je(branch_dest),
op::CmpOp::NE => self.backend.emit_jne(branch_dest),
op::CmpOp::UGE => self.backend.emit_jae(branch_dest),
op::CmpOp::UGT => self.backend.emit_ja(branch_dest),
op::CmpOp::ULE => self.backend.emit_jbe(branch_dest),
op::CmpOp::ULT => self.backend.emit_jb(branch_dest),
op::CmpOp::SGE => self.backend.emit_jge(branch_dest),
op::CmpOp::SGT => self.backend.emit_jg(branch_dest),
op::CmpOp::SLE => self.backend.emit_jle(branch_dest),
op::CmpOp::SLT => self.backend.emit_jl(branch_dest),
op::CmpOp::EQ => self.backend.emit_je(branch_target),
op::CmpOp::NE => self.backend.emit_jne(branch_target),
op::CmpOp::UGE => self.backend.emit_jae(branch_target),
op::CmpOp::UGT => self.backend.emit_ja(branch_target),
op::CmpOp::ULE => self.backend.emit_jbe(branch_target),
op::CmpOp::ULT => self.backend.emit_jb(branch_target),
op::CmpOp::SGE => self.backend.emit_jge(branch_target),
op::CmpOp::SGT => self.backend.emit_jg(branch_target),
op::CmpOp::SLE => self.backend.emit_jle(branch_target),
op::CmpOp::SLT => self.backend.emit_jl(branch_target),
_ => unimplemented!()
}
} else if self.match_ireg(cond) {
......@@ -85,7 +87,7 @@ impl <'a> InstructionSelection {
// emit: cmp cond_reg 1
self.backend.emit_cmp_r64_imm32(&cond_reg, 1);
// emit: je #branch_dest
self.backend.emit_je(branch_dest);
self.backend.emit_je(branch_target);
} else {
unimplemented!();
}
......@@ -96,9 +98,11 @@ impl <'a> InstructionSelection {
self.process_dest(&ops, dest, cur_func, vm);
let target = cur_func.content.as_ref().unwrap().get_block(dest.target);
trace!("emit branch1");
// jmp
self.backend.emit_jmp(dest);
self.backend.emit_jmp(target);
},
Instruction_::ExprCall{ref data, is_abort} => {
......@@ -779,7 +783,7 @@ impl CompilerPass for InstructionSelection {
fn start_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
debug!("{}", self.name());
self.backend.start_code(func.fn_name);
self.backend.start_code(func.name.unwrap());
// prologue (get arguments from entry block first)
let entry_block = func.content.as_ref().unwrap().get_entry_block();
......@@ -789,25 +793,26 @@ impl CompilerPass for InstructionSelection {
#[allow(unused_variables)]
fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
for block_label in func.block_trace.as_ref().unwrap() {
let block = func.content.as_ref().unwrap().get_block(block_label);
for block_id in func.block_trace.as_ref().unwrap() {
let block = func.content.as_ref().unwrap().get_block(*block_id);
let block_label = block.name.unwrap();
self.backend.start_block(block.label);
self.backend.start_block(block_label);
let block_content = block.content.as_ref().unwrap();
// live in is args of the block
self.backend.set_block_livein(block.label, &block_content.args);
self.backend.set_block_livein(block_label, &block_content.args);
// live out is the union of all branch args of this block
let live_out = block_content.get_out_arguments();
self.backend.set_block_liveout(block.label, &live_out);
self.backend.set_block_liveout(block_label, &live_out);
for inst in block_content.body.iter() {
self.instruction_select(inst, func, vm);
}
self.backend.end_block(block.label);
self.backend.end_block(block_label);
}
}
......@@ -817,7 +822,7 @@ impl CompilerPass for InstructionSelection {
let mc = self.backend.finish_code();
let compiled_func = CompiledFunction {
fn_name: func.fn_name,
func_ver_id: func.id,
temps: HashMap::new(),
mc: mc
};
......
......@@ -57,7 +57,7 @@ impl CompilerPass for PeepholeOptimization {
fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
let compiled_funcs = vm.compiled_funcs().read().unwrap();
let mut cf = compiled_funcs.get(func.fn_name).unwrap().borrow_mut();
let mut cf = compiled_funcs.get(&func.id).unwrap().borrow_mut();
for i in 0..cf.mc.number_of_insts() {
self.remove_redundant_move(i, &mut cf);
......
......@@ -25,7 +25,7 @@ impl RegisterAllocation {
// returns true if we spill registers (which requires another instruction selection)
fn coloring(&mut self, vm: &VM, func: &mut MuFunctionVersion) -> bool {
let compiled_funcs = vm.compiled_funcs().read().unwrap();
let mut cf = compiled_funcs.get(func.fn_name).unwrap().borrow_mut();
let mut cf = compiled_funcs.get(&func.id).unwrap().borrow_mut();
cf.mc.trace_mc();
......@@ -73,7 +73,7 @@ impl CompilerPass for RegisterAllocation {
}
fn execute(&mut self, vm: &VM, func: &mut MuFunctionVersion) -> PassExecutionResult {
debug!("---CompilerPass {} for {}---", self.name(), func.fn_name);
debug!("---CompilerPass {} for {}---", self.name(), func);
if self.coloring(vm, func) {
debug!("---finish---");
......
......@@ -34,7 +34,8 @@ impl Compiler {
}
pub fn compile(&self, func: &mut MuFunctionVersion) {
let _p = hprof::enter(func.fn_name);
// FIXME: should use function name here (however hprof::enter only accept &'static str)
let _p = hprof::enter("Function Compilation");
let mut cur_pass = 0;
let n_passes = self.policy.borrow().passes.len();
......
......@@ -15,7 +15,7 @@ impl ControlFlowAnalysis {
}
}
fn check_edge_kind(target: MuName, stack: &Vec<MuName>) -> EdgeKind {
fn check_edge_kind(target: MuID, stack: &Vec<MuID>) -> EdgeKind {
if stack.contains(&target) {
EdgeKind::Backward
} else {
......@@ -23,7 +23,7 @@ fn check_edge_kind(target: MuName, stack: &Vec<MuName>) -> EdgeKind {
}
}
fn new_edge(cur: MuName, edge: BlockEdge, stack: &mut Vec<MuName>, visited: &mut Vec<MuName>, func: &mut MuFunctionVersion) {
fn new_edge(cur: MuID, edge: BlockEdge, stack: &mut Vec<MuID>, visited: &mut Vec<MuID>, func: &mut MuFunctionVersion) {
// add current block to target's predecessors
{
let target = func.content.as_mut().unwrap().get_block_mut(edge.target);
......@@ -47,7 +47,7 @@ const WATCHPOINT_DISABLED_CHANCE : f32 = 0.9f32;
const NORMAL_RESUME_CHANCE : f32 = 0.6f32;
const EXN_RESUME_CHANCE : f32 = 1f32 - NORMAL_RESUME_CHANCE;
fn dfs(cur: MuName, stack: &mut Vec<MuName>, visited: &mut Vec<MuName>, func: &mut MuFunctionVersion) {
fn dfs(cur: MuID, stack: &mut Vec<MuID>, visited: &mut Vec<MuID>, func: &mut MuFunctionVersion) {
trace!("dfs visiting block {}", cur);
trace!("current stack: {:?}", stack);
trace!("current visited: {:?}", visited);
......@@ -197,15 +197,15 @@ impl CompilerPass for ControlFlowAnalysis {
#[allow(unused_variables)]
fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
let mut stack : Vec<MuName> = vec![];
let mut visited : Vec<MuName> = vec![];
let mut stack : Vec<MuID> = vec![];
let mut visited : Vec<MuID> = vec![];
dfs(func.content.as_ref().unwrap().entry, &mut stack, &mut visited, func);
}
#[allow(unused_variables)]
fn finish_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
debug!("check control flow for {}", func.fn_name);
debug!("check control flow for {}", func);
for entry in func.content.as_ref().unwrap().blocks.iter() {
debug!("block {}", entry.0);
......
......@@ -30,7 +30,7 @@ pub trait CompilerPass {
fn name(&self) -> &'static str;
fn execute(&mut self, vm: &VM, func: &mut MuFunctionVersion) -> PassExecutionResult {
debug!("---CompilerPass {} for {}---", self.name(), func.fn_name);
debug!("---CompilerPass {} for {}---", self.name(), func);
self.start_function(vm, func);
self.visit_function(vm, func);
......
......@@ -22,15 +22,15 @@ impl CompilerPass for TraceGen {
// we put the high probability edge into a hot trace, and others into cold paths
// and traverse cold_path later
let trace = {
let mut trace : Vec<MuName> = vec![];
let mut work_stack : Vec<MuName> = vec![];
let mut trace : Vec<MuID> = vec![];
let mut work_stack : Vec<MuID> = vec![];
let entry = func.content.as_ref().unwrap().entry;
work_stack.push(entry);
while !work_stack.is_empty() {
let cur = work_stack.pop().unwrap();
let cur_block = func.content.as_ref().unwrap().get_block(&cur);
let cur_block = func.content.as_ref().unwrap().get_block(cur);
trace!("check block {}", cur);
......@@ -46,8 +46,8 @@ impl CompilerPass for TraceGen {
// push cold paths (that are not in the trace and not in the work_stack) to work_stack
let mut cold_edges = cur_block.control_flow.succs.clone();
cold_edges.retain(|x| !x.target.eq(hot_edge) && !trace.contains(&x.target) &&!work_stack.contains(&x.target));
let mut cold_edge_tags = cold_edges.iter().map(|x| x.target).collect::<Vec<MuName>>();
cold_edges.retain(|x| !x.target.eq(&hot_edge) && !trace.contains(&x.target) &&!work_stack.contains(&x.target));
let mut cold_edge_tags = cold_edges.iter().map(|x| x.target).collect::<Vec<MuID>>();
trace!("push cold edges {:?} to work stack", cold_edge_tags);
work_stack.append(&mut cold_edge_tags);
......@@ -70,7 +70,7 @@ impl CompilerPass for TraceGen {
#[allow(unused_variables)]
fn finish_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
debug!("trace for {}", func.fn_name);
debug!("trace for {}", func);
debug!("{:?}", func.block_trace.as_ref().unwrap());
}
}
......@@ -26,7 +26,7 @@ impl CompilerPass for TreeGen {
}
fn execute(&mut self, vm: &VM, func: &mut MuFunctionVersion) -> PassExecutionResult {
debug!("---CompilerPass {} for {}---", self.name(), func.fn_name);
debug!("---CompilerPass {} for {}---", self.name(), func);
{
let ref mut func_content = func.content;
......@@ -123,7 +123,7 @@ impl CompilerPass for TreeGen {
#[allow(unused_variables)]
fn finish_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
debug!("check depth tree for {}", func.fn_name);
debug!("check depth tree for {}", func);
for entry in func.content.as_ref().unwrap().blocks.iter() {
debug!("block {}", entry.0);
......
......@@ -4,8 +4,7 @@ use ast::ptr::*;
use ast::ir::*;
use ast::types::*;
use vm::VM;
use vm::bundle::MuBundle;
use vm::bundle::TopLevelDefNode;
use vm::bundle::*;
use std::mem;
use std::os::raw;
......@@ -78,7 +77,7 @@ pub type MuArraySize = usize;
pub type MuIntValue = P<Value>;
pub type MuBundleNode = *mut MuBundle;
pub type MuChildNode = TopLevelDefNode;
pub type MuChildNode = MuIRNode;
pub type MuTypeNode = P<MuType>;
pub type MuFuncSigNode= P<MuFuncSig>;