mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-11-24 15:54:57 +00:00
linker/dce: use FxIndexSet
instead of FxHashSet
for the "roots" set.
This commit is contained in:
parent
0160d1dc75
commit
69349b1b9d
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
use rspirv::dr::{Function, Instruction, Module, Operand};
|
use rspirv::dr::{Function, Instruction, Module, Operand};
|
||||||
use rspirv::spirv::{Decoration, LinkageType, Op, StorageClass, Word};
|
use rspirv::spirv::{Decoration, LinkageType, Op, StorageClass, Word};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
|
|
||||||
pub fn dce(module: &mut Module) {
|
pub fn dce(module: &mut Module) {
|
||||||
let mut rooted = collect_roots(module);
|
let mut rooted = collect_roots(module);
|
||||||
@ -17,8 +17,8 @@ pub fn dce(module: &mut Module) {
|
|||||||
kill_unrooted(module, &rooted);
|
kill_unrooted(module, &rooted);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_roots(module: &Module) -> FxHashSet<Word> {
|
pub fn collect_roots(module: &Module) -> FxIndexSet<Word> {
|
||||||
let mut rooted = FxHashSet::default();
|
let mut rooted = FxIndexSet::default();
|
||||||
|
|
||||||
for inst in &module.entry_points {
|
for inst in &module.entry_points {
|
||||||
root(inst, &mut rooted);
|
root(inst, &mut rooted);
|
||||||
@ -53,7 +53,7 @@ fn all_inst_iter(func: &Function) -> impl DoubleEndedIterator<Item = &Instructio
|
|||||||
.chain(func.end.iter())
|
.chain(func.end.iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spread_roots(module: &Module, rooted: &mut FxHashSet<Word>) -> bool {
|
fn spread_roots(module: &Module, rooted: &mut FxIndexSet<Word>) -> bool {
|
||||||
let mut any = false;
|
let mut any = false;
|
||||||
for inst in module.global_inst_iter() {
|
for inst in module.global_inst_iter() {
|
||||||
if let Some(id) = inst.result_id {
|
if let Some(id) = inst.result_id {
|
||||||
@ -82,7 +82,7 @@ fn spread_roots(module: &Module, rooted: &mut FxHashSet<Word>) -> bool {
|
|||||||
any
|
any
|
||||||
}
|
}
|
||||||
|
|
||||||
fn root(inst: &Instruction, rooted: &mut FxHashSet<Word>) -> bool {
|
fn root(inst: &Instruction, rooted: &mut FxIndexSet<Word>) -> bool {
|
||||||
let mut any = false;
|
let mut any = false;
|
||||||
if let Some(id) = inst.result_type {
|
if let Some(id) = inst.result_type {
|
||||||
any |= rooted.insert(id);
|
any |= rooted.insert(id);
|
||||||
@ -95,7 +95,7 @@ fn root(inst: &Instruction, rooted: &mut FxHashSet<Word>) -> bool {
|
|||||||
any
|
any
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_rooted(inst: &Instruction, rooted: &FxHashSet<Word>) -> bool {
|
fn is_rooted(inst: &Instruction, rooted: &FxIndexSet<Word>) -> bool {
|
||||||
if let Some(result_id) = inst.result_id {
|
if let Some(result_id) = inst.result_id {
|
||||||
rooted.contains(&result_id)
|
rooted.contains(&result_id)
|
||||||
} else {
|
} else {
|
||||||
@ -107,7 +107,7 @@ fn is_rooted(inst: &Instruction, rooted: &FxHashSet<Word>) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn kill_unrooted(module: &mut Module, rooted: &FxHashSet<Word>) {
|
fn kill_unrooted(module: &mut Module, rooted: &FxIndexSet<Word>) {
|
||||||
module
|
module
|
||||||
.ext_inst_imports
|
.ext_inst_imports
|
||||||
.retain(|inst| is_rooted(inst, rooted));
|
.retain(|inst| is_rooted(inst, rooted));
|
||||||
@ -138,7 +138,7 @@ fn kill_unrooted(module: &mut Module, rooted: &FxHashSet<Word>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn dce_phi(func: &mut Function) {
|
pub fn dce_phi(func: &mut Function) {
|
||||||
let mut used = FxHashSet::default();
|
let mut used = FxIndexSet::default();
|
||||||
loop {
|
loop {
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
for inst in func.all_inst_iter() {
|
for inst in func.all_inst_iter() {
|
||||||
|
@ -1,22 +1,3 @@
|
|||||||
error: cannot cast between pointer types
|
|
||||||
from `*struct (usize, usize) { u32, u32 }`
|
|
||||||
to `*struct B { }`
|
|
||||||
--> $DIR/zst_member_ref_arg-broken.rs:33:5
|
|
||||||
|
|
|
||||||
33 | f(&s.y);
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
note: used from within `zst_member_ref_arg_broken::main_scalar_scalar_pair_nested`
|
|
||||||
--> $DIR/zst_member_ref_arg-broken.rs:33:5
|
|
||||||
|
|
|
||||||
33 | f(&s.y);
|
|
||||||
| ^
|
|
||||||
note: called by `main_scalar_scalar_pair_nested`
|
|
||||||
--> $DIR/zst_member_ref_arg-broken.rs:31:1
|
|
||||||
|
|
|
||||||
31 | #[spirv(fragment)]
|
|
||||||
| ^
|
|
||||||
|
|
||||||
error: cannot cast between pointer types
|
error: cannot cast between pointer types
|
||||||
from `*u32`
|
from `*u32`
|
||||||
to `*struct B { }`
|
to `*struct B { }`
|
||||||
@ -55,5 +36,24 @@ note: called by `main_scalar_pair`
|
|||||||
26 | #[spirv(fragment)]
|
26 | #[spirv(fragment)]
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
|
error: cannot cast between pointer types
|
||||||
|
from `*struct (usize, usize) { u32, u32 }`
|
||||||
|
to `*struct B { }`
|
||||||
|
--> $DIR/zst_member_ref_arg-broken.rs:33:5
|
||||||
|
|
|
||||||
|
33 | f(&s.y);
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
note: used from within `zst_member_ref_arg_broken::main_scalar_scalar_pair_nested`
|
||||||
|
--> $DIR/zst_member_ref_arg-broken.rs:33:5
|
||||||
|
|
|
||||||
|
33 | f(&s.y);
|
||||||
|
| ^
|
||||||
|
note: called by `main_scalar_scalar_pair_nested`
|
||||||
|
--> $DIR/zst_member_ref_arg-broken.rs:31:1
|
||||||
|
|
|
||||||
|
31 | #[spirv(fragment)]
|
||||||
|
| ^
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user