| 579 | } |
| 580 | |
| 581 | fn remove_old_variables( |
| 582 | blocks: &mut [Block], |
| 583 | var_maps_and_types: &[(FxHashMap<u32, VarInfo>, u32)], |
| 584 | ) { |
| 585 | blocks[0].instructions.retain(|inst| { |
| 586 | inst.class.opcode != Op::Variable || { |
| 587 | let result_id = inst.result_id.unwrap(); |
| 588 | var_maps_and_types |
| 589 | .iter() |
| 590 | .all(|(var_map, _)| !var_map.contains_key(&result_id)) |
| 591 | } |
| 592 | }); |
| 593 | for block in blocks { |
| 594 | block.instructions.retain(|inst| { |
| 595 | !matches!(inst.class.opcode, Op::AccessChain | Op::InBoundsAccessChain) |
| 596 | || inst.operands.iter().all(|op| { |
| 597 | op.id_ref_any().map_or(true, |id| { |
| 598 | var_maps_and_types |
| 599 | .iter() |
| 600 | .all(|(var_map, _)| !var_map.contains_key(&id)) |
| 601 | }) |
| 602 | }) |
| 603 | }); |
| 604 | } |
| 605 | } |