| 138 | } |
| 139 | |
| 140 | pub fn dce_phi(func: &mut Function) { |
| 141 | let mut used = FxIndexSet::default(); |
| 142 | loop { |
| 143 | let mut changed = false; |
| 144 | for inst in func.all_inst_iter() { |
| 145 | if inst.class.opcode != Op::Phi || used.contains(&inst.result_id.unwrap()) { |
| 146 | for op in &inst.operands { |
| 147 | if let Some(id) = op.id_ref_any() { |
| 148 | changed |= used.insert(id); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | if !changed { |
| 154 | break; |
| 155 | } |
| 156 | } |
| 157 | for block in &mut func.blocks { |
| 158 | block |
| 159 | .instructions |
| 160 | .retain(|inst| inst.class.opcode != Op::Phi || used.contains(&inst.result_id.unwrap())); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | fn instruction_is_pure(inst: &Instruction) -> bool { |
| 165 | use Op::*; |