WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

peephole_opt.rs 2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use compiler::CompilerPass;
use ast::ir::*;
use vm::context::VMContext;
use vm::machine_code::CompiledFunction;

pub struct PeepholeOptimization {
    name: &'static str
}

impl PeepholeOptimization {
    pub fn new() -> PeepholeOptimization {
        PeepholeOptimization {
            name: "Peephole Optimization"
        }
    }
    
    pub fn remove_redundant_move(&mut self, inst: usize, cf: &mut CompiledFunction) {
        if cf.mc.is_move(inst) {
            cf.mc.trace_inst(inst);
            
            let src : MuID = {
                let uses = cf.mc.get_inst_reg_uses(inst);
                if uses.len() != 1 {
                    // moving immediate to register, its not redundant
                    return;
                }                
                uses[0]
            };
            let dst : MuID = cf.mc.get_inst_reg_defines(inst)[0];
            
            let src_machine_reg : MuID = {
                match cf.temps.get(&src) {
                    Some(reg) => *reg,
                    None => src
                }
            };
            let dst_machine_reg : MuID = {
                match cf.temps.get(&dst) {
                    Some(reg) => *reg,
                    None => dst
                }
            };
            
            if src_machine_reg == dst_machine_reg {
                trace!("Redundant! removed");
                // redundant, remove this move
                cf.mc.set_inst_nop(inst);
            }
        }
    }
}

impl CompilerPass for PeepholeOptimization {
    fn name(&self) -> &'static str {
        self.name
    }
    
    fn visit_function(&mut self, vm_context: &VMContext, func: &mut MuFunction) {
        let compiled_funcs = vm_context.compiled_funcs().read().unwrap();
        let mut cf = compiled_funcs.get(func.fn_name).unwrap().borrow_mut();
        
        for i in 0..cf.mc.number_of_insts() {
            self.remove_redundant_move(i, &mut cf);
        }
        
        trace!("after peephole optimization:");
        cf.mc.trace_mc();
    }
}