Skip to main content

luaur_code_gen/methods/
remove_dead_store_state_def_reg.rs

1use crate::records::remove_dead_store_state::RemoveDeadStoreState;
2use crate::records::store_reg_info::StoreRegInfo;
3
4impl RemoveDeadStoreState {
5    // When a register value is being defined, it kills previous stores
6    pub fn def_reg(&mut self, reg: u8) {
7        // Stores to captured registers are not removed since we don't track their uses outside of function
8        let function = unsafe { &*self.function };
9        if (function.cfg.captured.regs[reg as usize / 64] & (1u64 << (reg as usize % 64))) != 0 {
10            return;
11        }
12
13        let reg_info: &mut StoreRegInfo =
14            unsafe { &mut *(&mut self.info[reg as usize] as *mut StoreRegInfo) };
15
16        self.kill_tag_and_value_store_pair(reg_info);
17        self.kill_t_value_store(reg_info);
18
19        reg_info.tag_inst_idx = !0u32;
20        reg_info.value_inst_idx = !0u32;
21        reg_info.tvalue_inst_idx = !0u32;
22
23        // Opaque register definition removes the knowledge of the actual tag value
24        reg_info.known_tag = 0xff;
25
26        // New value defined, before MARK_DEAD is used again, it might be used in a VM exit
27        reg_info.ignore_at_exit = false;
28    }
29}