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 1 commit
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
23 changes: 14 additions & 9 deletions crates/rustc_codegen_spirv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,15 +621,20 @@ fn get_env_dump_dir(env_var: &str) -> Option<PathBuf> {
/// This is the entrypoint for a hot plugged `rustc_codegen_spirv`
#[no_mangle]
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
// Override rustc's panic hook with our own to override the ICE error
// message, and direct people to `rust-gpu`.
std::panic::set_hook(Box::new(|panic_info| {
rustc_driver::report_ice(
panic_info,
"https://github.com/EmbarkStudios/rust-gpu/issues/new",
);
eprintln!("note: `rust-gpu` version {}\n", env!("CARGO_PKG_VERSION"));
}));
// Setting the hook nukes the backtrace, so give developers an escape hatch to see the crash,
// even if the message is wrong.
// TODO: Figure out a way to print both the backtrace and override the bug report URL.
if env::var_os("NO_PANIC_HOOK").is_none() {
// Override rustc's panic hook with our own to override the ICE error
// message, and direct people to `rust-gpu`.
std::panic::set_hook(Box::new(|panic_info| {
rustc_driver::report_ice(
panic_info,
"https://github.com/EmbarkStudios/rust-gpu/issues/new",
);
eprintln!("note: `rust-gpu` version {}\n", env!("CARGO_PKG_VERSION"));
}));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be dropped now, or at least after #732 lands.


Box::new(SpirvCodegenBackend)
}
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