RPO alg already deletes dead blocks

This commit is contained in:
khyperia 2020-09-22 16:02:36 +02:00
parent cc916c784e
commit 31e8d95898
2 changed files with 3 additions and 26 deletions

View File

@ -4,7 +4,7 @@ mod type_;
use crate::builder::ExtInst;
use crate::builder_spirv::{BuilderCursor, BuilderSpirv, SpirvValue, SpirvValueExt};
use crate::finalizing_passes::{block_ordering_pass, delete_dead_blocks, export_zombies};
use crate::finalizing_passes::{block_ordering_pass, export_zombies};
use crate::spirv_type::{SpirvType, SpirvTypePrinter, TypeCache};
use crate::symbols::Symbols;
use rspirv::dr::{Module, Operand};
@ -118,8 +118,6 @@ impl<'tcx> CodegenCx<'tcx> {
// defs go before fns
result.functions.sort_by_key(|f| !f.blocks.is_empty());
for function in &mut result.functions {
// Should delete dead code blocks before zombie pass, in case a dead block references a zombie id.
delete_dead_blocks(function);
block_ordering_pass(function);
}
export_zombies(&mut result, &self.zombie_values.borrow());

View File

@ -34,27 +34,6 @@ fn label_of(block: &Block) -> Word {
block.label.as_ref().unwrap().result_id.unwrap()
}
// TODO: Move this to the linker.
pub fn delete_dead_blocks(func: &mut Function) {
if func.blocks.len() < 2 {
return;
}
let entry_label = label_of(&func.blocks[0]);
let mut stack = Vec::new();
let mut visited = HashSet::new();
stack.push(entry_label);
visited.insert(entry_label);
while let Some(label) = stack.pop() {
let block = func.blocks.iter().find(|b| label_of(b) == label).unwrap();
for outgoing in outgoing_edges(block) {
if visited.insert(outgoing) {
stack.push(outgoing);
}
}
}
func.blocks.retain(|b| visited.contains(&label_of(b)))
}
// TODO: Do we move this to the linker?
pub fn block_ordering_pass(func: &mut Function) {
if func.blocks.len() < 2 {
@ -92,8 +71,8 @@ pub fn block_ordering_pass(func: &mut Function) {
.unwrap();
func.blocks.push(old_blocks.remove(index));
}
assert!(old_blocks.is_empty());
assert_eq!(label_of(&func.blocks[0]), entry_label,);
// Note: if old_blocks isn't empty here, that means there were unreachable blocks that were deleted.
assert_eq!(label_of(&func.blocks[0]), entry_label);
}
fn outgoing_edges(block: &Block) -> Vec<Word> {