Commit ff42dd1e authored by Yi Lin's avatar Yi Lin

Merge branch 'branch-adjustment-bug-fix' into 'develop'

Fix a bug in branch adjustment: when neither label follows a conditional branch, a temporary label is properly created.

See merge request !38
parents 9f41288e c95b39a4
Pipeline #1184 passed with stages
in 54 minutes and 3 seconds
......@@ -249,10 +249,8 @@ impl InterferenceGraph {
}
/// prints current graph for debugging (via trace log)
#[allow(unused_variables)]
pub fn print(&self, context: &FunctionContext) {
use compiler::backend::reg_alloc::graph_coloring::petgraph::dot::Dot;
use compiler::backend::reg_alloc::graph_coloring::petgraph::dot::Config;
trace!("");
trace!("Interference Graph");
......
......@@ -509,7 +509,9 @@ fn branch_adjustment(func: &mut MuFunctionVersion, vm: &VM) {
new_body.push(new_cond_branch);
// add new false block to trace (immediate after this block)
if let Some(next_block_index) = next_block_in_trace {
if let Some(next_block) = next_block_in_trace {
let next_block_index =
trace.iter().position(|x| *x == next_block).unwrap();
trace.insert(next_block_index, new_false_block.id());
} else {
trace.push(new_false_block.id());
......
......@@ -930,7 +930,6 @@ macro_rules! emit_test {
);
consta! (($vm, $tester_name) int64_pass_local = int64_pass);
consta! (($vm, $tester_name) int64_fail_local = int64_fail);
inst! (($vm, $tester_name) blk_entry_inst_ret:
SET_RETVAL int64_pass_local
......
......@@ -26,7 +26,6 @@ use mu::utils::LinkedHashMap;
use std::sync::Arc;
use self::mu::linkutils::aot;
use self::mu::runtime::thread::check_result;
use self::mu::compiler::*;
use std::u64;
......
......@@ -24,7 +24,6 @@ use mu::utils::LinkedHashMap;
use std::sync::Arc;
use mu::linkutils::aot;
use mu::runtime::thread::check_result;
use mu::compiler::*;
#[test]
......@@ -1155,3 +1154,119 @@ fn branch2_high_prob_branch_cannot_fallthrough() -> VM {
vm
}
#[test]
fn test_branch_adjust_follow_by_neither() {
VM::start_logging_trace();
linkutils::aot::compile_fnc(
"branch_adjust_follow_by_neither",
&branch_adjust_follow_by_neither
);
}
fn branch_adjust_follow_by_neither() -> VM {
let vm = VM::new();
typedef! ((vm) int64 = mu_int(64));
typedef! ((vm) int1 = mu_int(1));
constdef! ((vm) <int64> int64_0 = Constant::Int(0));
constdef! ((vm) <int64> int64_1 = Constant::Int(1));
funcsig! ((vm) sig = () -> (int64));
funcdecl! ((vm) <sig> branch_adjust_follow_by_neither);
funcdef! ((vm) <sig> branch_adjust_follow_by_neither
VERSION branch_adjust_follow_by_neither_v1);
// blk_entry
block! ((vm, branch_adjust_follow_by_neither_v1) blk_entry);
block! ((vm, branch_adjust_follow_by_neither_v1) blk_jmp);
// BRANCH blk_jmp
inst! ((vm, branch_adjust_follow_by_neither_v1) blk_entry_branch:
BRANCH blk_jmp ()
);
define_block!((vm, branch_adjust_follow_by_neither_v1) blk_entry() {
blk_entry_branch
});
// blk_jmp
// BRANCH blk_check0 (1)
consta! ((vm, branch_adjust_follow_by_neither_v1) int64_0_local = int64_0);
consta! ((vm, branch_adjust_follow_by_neither_v1) int64_1_local = int64_1);
block! ((vm, branch_adjust_follow_by_neither_v1) blk_check0);
inst! ((vm, branch_adjust_follow_by_neither_v1) blk_jmp_branch:
BRANCH blk_check0 (int64_1_local)
);
define_block!((vm, branch_adjust_follow_by_neither_v1) blk_jmp() {
blk_jmp_branch
});
// blk_check0(a)
ssa! ((vm, branch_adjust_follow_by_neither_v1) <int64> a);
// cond = EQ a 0
ssa! ((vm, branch_adjust_follow_by_neither_v1) <int1> cond);
inst! ((vm, branch_adjust_follow_by_neither_v1) blk_check0_eq:
cond = CMPOP (CmpOp::EQ) a int64_0_local
);
// BRANCH2 cond TRUE: blk_ret0 () FALSE: blk_check1 (0)
block! ((vm, branch_adjust_follow_by_neither_v1) blk_ret0);
block! ((vm, branch_adjust_follow_by_neither_v1) blk_check1);
inst! ((vm, branch_adjust_follow_by_neither_v1) blk_check0_branch2:
BRANCH2 (cond, int64_0_local)
IF (OP 0)
THEN blk_ret0 (vec![]) WITH 0.6f32,
ELSE blk_check1 (vec![1])
);
define_block!((vm, branch_adjust_follow_by_neither_v1) blk_check0(a) {
blk_check0_eq,
blk_check0_branch2
});
// blk_check1(b)
ssa! ((vm, branch_adjust_follow_by_neither_v1) <int64> b);
// cond = EQ b 1
ssa! ((vm, branch_adjust_follow_by_neither_v1) <int1> cond2);
inst! ((vm, branch_adjust_follow_by_neither_v1) blk_check1_eq:
cond2 = CMPOP (CmpOp::EQ) b int64_1_local
);
// BRANCH2 cond2 TRUE: blk_ret1() FALSE: blk_jmp
inst! ((vm, branch_adjust_follow_by_neither_v1) blk_check1_branch2:
BRANCH2 (cond2)
IF (OP 0)
THEN blk_ret0 (vec![]) WITH 0.4f32,
ELSE blk_jmp (vec![])
);
define_block!((vm, branch_adjust_follow_by_neither_v1) blk_check1(b) {
blk_check1_eq,
blk_check1_branch2
});
// blk_ret0
inst! ((vm, branch_adjust_follow_by_neither_v1) blk_ret0_ret:
RET (int64_0_local)
);
define_block!((vm, branch_adjust_follow_by_neither_v1) blk_ret0() {
blk_ret0_ret
});
define_func_ver!((vm) branch_adjust_follow_by_neither_v1 (entry: blk_entry) {
blk_entry,
blk_jmp,
blk_check0,
blk_check1,
blk_ret0
});
vm
}
......@@ -21,12 +21,10 @@ use self::mu::ast::ir::*;
use self::mu::ast::inst::*;
use self::mu::ast::op::*;
use self::mu::vm::*;
use self::mu::linkutils;
use mu::utils::LinkedHashMap;
use std::sync::Arc;
use self::mu::linkutils::aot;
use self::mu::runtime::thread::check_result;
use self::mu::compiler::*;
use std::f32;
......
......@@ -23,11 +23,7 @@ use mu::vm::*;
use mu::compiler::*;
use mu::utils::LinkedHashMap;
use mu::linkutils;
use mu::linkutils::aot;
use test_compiler::test_call::gen_ccall_exit;
use std::sync::Arc;
#[test]
......
......@@ -26,7 +26,6 @@ use mu::utils::LinkedHashMap;
use std::sync::Arc;
use mu::linkutils::aot;
use mu::runtime::thread::check_result;
use mu::compiler::*;
#[test]
......
......@@ -14,17 +14,11 @@
extern crate libloading;
use mu::ast::types::*;
use mu::ast::ir::*;
use mu::ast::ptr::*;
use mu::ast::inst::*;
use mu::ast::op::*;
use mu::vm::*;
use mu::compiler::*;
use std::sync::Arc;
use mu::linkutils;
use mu::linkutils::aot;
use mu::utils::LinkedHashMap;
#[test]
......
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