Skip to main content

luaur_code_gen/methods/
const_prop_state_get_previous_inst_index.rs

1use crate::functions::has_side_effects::has_side_effects;
2use crate::records::const_prop_state::ConstPropState;
3use crate::records::ir_inst::IrInst;
4
5impl ConstPropState {
6    pub fn get_previous_inst_index(&mut self, inst: &IrInst) -> Option<*mut u32> {
7        let prev_idx = match self.value_map.find_mut(inst) {
8            Some(prev_idx) => prev_idx as *mut u32,
9            None => return None,
10        };
11
12        let prev_inst = unsafe {
13            let function = &*self.function;
14            &function.instructions[*prev_idx as usize]
15        };
16        if prev_inst.use_count != 0 || has_side_effects(prev_inst.cmd) {
17            Some(prev_idx)
18        } else {
19            None
20        }
21    }
22}