test_regalloc.rs 2.4 KB
Newer Older
1
2
3
extern crate mu;
extern crate log;
extern crate simple_logger;
4
extern crate libloading;
5
6
7

use test_ir::test_ir::factorial;
use self::mu::compiler::*;
8
9
use self::mu::utils::vec_utils;
use self::mu::ast::ir::*;
10
11
12

use std::sync::Arc;

13
14
15
16
#[test]
fn test_ir_liveness_fac() {
    simple_logger::init_with_level(log::LogLevel::Trace).ok();
    
qinsoon's avatar
qinsoon committed
17
    let vm = Arc::new(factorial());
18
19
20
21
22
23
24
    
    let compiler = Compiler::new(CompilerPolicy::new(vec![
            Box::new(passes::DefUse::new()),
            Box::new(passes::TreeGen::new()),
            Box::new(passes::ControlFlowAnalysis::new()),
            Box::new(passes::TraceGen::new()),
            Box::new(backend::inst_sel::InstructionSelection::new()),
qinsoon's avatar
qinsoon committed
25
    ]), vm.clone());
26
    
qinsoon's avatar
qinsoon committed
27
    let func_id = vm.id_of("fac");
qinsoon's avatar
qinsoon committed
28
    let funcs = vm.funcs().read().unwrap();
29
    let func = funcs.get(&func_id).unwrap().read().unwrap();
qinsoon's avatar
qinsoon committed
30
    let func_vers = vm.func_vers().read().unwrap();
qinsoon's avatar
qinsoon committed
31
    let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
32
    
qinsoon's avatar
qinsoon committed
33
    compiler.compile(&mut func_ver);
34
    
qinsoon's avatar
qinsoon committed
35
    let cf_lock = vm.compiled_funcs().read().unwrap();
36
    let cf = cf_lock.get(&func_ver.id()).unwrap().read().unwrap();
37
38
39
    
    // block 0
    
qinsoon's avatar
qinsoon committed
40
    let block_0_livein = cf.mc().get_ir_block_livein("blk_0").unwrap();
qinsoon's avatar
qinsoon committed
41
    let blk_0_n_3 = vm.id_of("blk_0_n_3");;
42
43
    assert!(vec_utils::is_identical_to_str_ignore_order(block_0_livein, vec![blk_0_n_3]));
    
qinsoon's avatar
qinsoon committed
44
    let block_0_liveout = cf.mc().get_ir_block_liveout("blk_0").unwrap();
45
46
47
48
    assert!(vec_utils::is_identical_to_str_ignore_order(block_0_liveout, vec![blk_0_n_3]));
    
    // block 1
    
qinsoon's avatar
qinsoon committed
49
    let block_1_livein = cf.mc().get_ir_block_livein("blk_1").unwrap();
qinsoon's avatar
qinsoon committed
50
    let blk_1_n_3 = vm.id_of("blk_1_n_3");
51
52
    assert!(vec_utils::is_identical_to_str_ignore_order(block_1_livein, vec![blk_1_n_3]));
    
qinsoon's avatar
qinsoon committed
53
    let block_1_liveout = cf.mc().get_ir_block_liveout("blk_1").unwrap();
qinsoon's avatar
qinsoon committed
54
    let blk_1_v52 = vm.id_of("blk_1_v52");
55
56
57
58
    assert!(vec_utils::is_identical_to_str_ignore_order(block_1_liveout, vec![blk_1_v52]));
    
    // block 2
    
qinsoon's avatar
qinsoon committed
59
    let block_2_livein = cf.mc().get_ir_block_livein("blk_2").unwrap();
qinsoon's avatar
qinsoon committed
60
    let blk_2_v53 = vm.id_of("blk_2_v53");
61
62
    assert!(vec_utils::is_identical_to_str_ignore_order(block_2_livein, vec![blk_2_v53]));
    
qinsoon's avatar
qinsoon committed
63
    let block_2_liveout = cf.mc().get_ir_block_liveout("blk_2").unwrap();
64
65
    let expect : Vec<MuID> = vec![];
    assert!(vec_utils::is_identical_to_str_ignore_order(block_2_liveout, expect));
66
}