Commit 698c71fb authored by qinsoon's avatar qinsoon

instruction selection for branch2 pick fallthrough block based on trace

scheduling result (instead of probability)
parent 5d248afd
...@@ -358,6 +358,16 @@ impl FunctionContent { ...@@ -358,6 +358,16 @@ impl FunctionContent {
None => panic!("cannot find block #{}", id) None => panic!("cannot find block #{}", id)
} }
} }
pub fn get_block_by_name(&self, name: String) -> &Block {
for block in self.blocks.values() {
if block.name().unwrap() == name {
return block;
}
}
panic!("cannot find block {}", name)
}
} }
#[derive(Default, Debug, RustcEncodable, RustcDecodable)] #[derive(Default, Debug, RustcEncodable, RustcDecodable)]
......
...@@ -157,7 +157,11 @@ impl <'a> InstructionSelection { ...@@ -157,7 +157,11 @@ impl <'a> InstructionSelection {
// 'branch_if_true' == true, we emit cjmp the same as CmpOp (je for EQ, jne for NE) // 'branch_if_true' == true, we emit cjmp the same as CmpOp (je for EQ, jne for NE)
// 'branch_if_true' == false, we emit opposite cjmp as CmpOp (jne for EQ, je for NE) // 'branch_if_true' == false, we emit opposite cjmp as CmpOp (jne for EQ, je for NE)
let (fallthrough_dest, branch_dest, branch_if_true) = { let (fallthrough_dest, branch_dest, branch_if_true) = {
if true_prob >= 0.5f32 { // get current block and next block in trace (fallthrough block)
let cur_block = f_content.get_block_by_name(self.current_block.as_ref().unwrap().clone());
let next_block_in_trace = cur_block.control_flow.get_hottest_succ().unwrap();
if next_block_in_trace == true_dest.target {
(true_dest, false_dest, false) (true_dest, false_dest, false)
} else { } else {
(false_dest, true_dest, true) (false_dest, true_dest, true)
......
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