Skip to content

Various fixes and cleanup #726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions crates/rustc_codegen_spirv/src/linker/dce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ pub fn collect_roots(module: &Module) -> FxHashSet<Word> {
rooted
}

// Exactly the same as Function::all_inst_iter, except return type is `impl DoubleEndedIterator`
// instead of `impl Iterator`
fn all_inst_iter(func: &Function) -> impl DoubleEndedIterator<Item = &Instruction> {
func.def
.iter()
.chain(func.parameters.iter())
.chain(
func.blocks
.iter()
.flat_map(|b| b.label.iter().chain(b.instructions.iter())),
)
.chain(func.end.iter())
}

fn spread_roots(module: &Module, rooted: &mut FxHashSet<Word>) -> bool {
let mut any = false;
for inst in module.global_inst_iter() {
Expand All @@ -40,18 +54,7 @@ fn spread_roots(module: &Module, rooted: &mut FxHashSet<Word>) -> bool {
// earlier insts, by reversing the iteration order, we're more likely to root the
// entire relevant function at once.
// See https://github.com/EmbarkStudios/rust-gpu/pull/691#discussion_r681477091
for inst in func
.end
.iter()
.chain(
func.blocks
.iter()
.rev()
.flat_map(|b| b.instructions.iter().rev().chain(b.label.iter())),
)
.chain(func.parameters.iter().rev())
.chain(func.def.iter())
{
for inst in all_inst_iter(func).rev() {
if !instruction_is_pure(inst) {
any |= root(inst, rooted);
} else if let Some(id) = inst.result_id {
Expand Down Expand Up @@ -111,13 +114,13 @@ fn kill_unrooted(module: &mut Module, rooted: &FxHashSet<Word>) {
module
.functions
.retain(|f| is_rooted(f.def.as_ref().unwrap(), rooted));
module.functions.iter_mut().for_each(|fun| {
fun.blocks.iter_mut().for_each(|block| {
for fun in &mut module.functions {
for block in &mut fun.blocks {
block
.instructions
.retain(|inst| !instruction_is_pure(inst) || is_rooted(inst, rooted));
});
});
}
}
}

pub fn dce_phi(func: &mut Function) {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/image/gather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn main(
#[cfg(not(any(
target_env = "vulkan1.0",
target_env = "vulkan1.1",
target_env = "vulkan1.1spv1.4",
target_env = "vulkan1.2"
)))]
#[spirv(fragment)]
Expand Down