Skip to content

Commit 1e3881b

Browse files
authored
Various fixes and cleanup (#726)
* Various fixes and cleanup While working on other patches that ended up not being applicable, I've gathered these changes unrelated to the irrelevant patch. So, submitting them as a seperate change, since the bigger change isn't going in. * Revert change superseded by #732
1 parent 44ae441 commit 1e3881b

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

crates/rustc_codegen_spirv/src/linker/dce.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ pub fn collect_roots(module: &Module) -> FxHashSet<Word> {
2525
rooted
2626
}
2727

28+
// Exactly the same as Function::all_inst_iter, except return type is `impl DoubleEndedIterator`
29+
// instead of `impl Iterator`
30+
fn all_inst_iter(func: &Function) -> impl DoubleEndedIterator<Item = &Instruction> {
31+
func.def
32+
.iter()
33+
.chain(func.parameters.iter())
34+
.chain(
35+
func.blocks
36+
.iter()
37+
.flat_map(|b| b.label.iter().chain(b.instructions.iter())),
38+
)
39+
.chain(func.end.iter())
40+
}
41+
2842
fn spread_roots(module: &Module, rooted: &mut FxHashSet<Word>) -> bool {
2943
let mut any = false;
3044
for inst in module.global_inst_iter() {
@@ -40,18 +54,7 @@ fn spread_roots(module: &Module, rooted: &mut FxHashSet<Word>) -> bool {
4054
// earlier insts, by reversing the iteration order, we're more likely to root the
4155
// entire relevant function at once.
4256
// See https://github.com/EmbarkStudios/rust-gpu/pull/691#discussion_r681477091
43-
for inst in func
44-
.end
45-
.iter()
46-
.chain(
47-
func.blocks
48-
.iter()
49-
.rev()
50-
.flat_map(|b| b.instructions.iter().rev().chain(b.label.iter())),
51-
)
52-
.chain(func.parameters.iter().rev())
53-
.chain(func.def.iter())
54-
{
57+
for inst in all_inst_iter(func).rev() {
5558
if !instruction_is_pure(inst) {
5659
any |= root(inst, rooted);
5760
} else if let Some(id) = inst.result_id {
@@ -111,13 +114,13 @@ fn kill_unrooted(module: &mut Module, rooted: &FxHashSet<Word>) {
111114
module
112115
.functions
113116
.retain(|f| is_rooted(f.def.as_ref().unwrap(), rooted));
114-
module.functions.iter_mut().for_each(|fun| {
115-
fun.blocks.iter_mut().for_each(|block| {
117+
for fun in &mut module.functions {
118+
for block in &mut fun.blocks {
116119
block
117120
.instructions
118121
.retain(|inst| !instruction_is_pure(inst) || is_rooted(inst, rooted));
119-
});
120-
});
122+
}
123+
}
121124
}
122125

123126
pub fn dce_phi(func: &mut Function) {

tests/ui/image/gather.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn main(
2020
#[cfg(not(any(
2121
target_env = "vulkan1.0",
2222
target_env = "vulkan1.1",
23+
target_env = "vulkan1.1spv1.4",
2324
target_env = "vulkan1.2"
2425
)))]
2526
#[spirv(fragment)]

0 commit comments

Comments
 (0)