Skip to content
Draft
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
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion crates/rustc_codegen_spirv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ spirv-std-types = { workspace = true, features = ["std"] }
rustc-demangle = "0.1.21"
sanitize-filename = "0.6.0"
smallvec = { version = "1.6.1", features = ["const_generics", "const_new", "union"] }
spirt = "0.4.0"
# HACK(eddyb) temporary until a new SPIR-T release contains the following:
# - https://github.com/Rust-GPU/spirt/pull/7
# - https://github.com/Rust-GPU/spirt/pull/8
# - https://github.com/Rust-GPU/spirt/pull/9
# - https://github.com/Rust-GPU/spirt/pull/12
# - https://github.com/Rust-GPU/spirt/pull/49
# - https://github.com/Rust-GPU/spirt/pull/52
# - https://github.com/Rust-GPU/spirt/pull/22
# - https://github.com/Rust-GPU/spirt/pull/28
spirt = { git = "https://github.com/LykenSol/spirt", branch = "bypass-merge-blocks" }
spirv-tools.workspace = true
lazy_static = "1.4.0"
itertools = "0.14.0"
Expand Down
13 changes: 0 additions & 13 deletions crates/rustc_codegen_spirv/src/builder_spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,19 +596,6 @@ impl<'tcx> BuilderSpirv<'tcx> {

// FIXME(eddyb) make this an extension method on `rspirv::dr::Builder`?
let const_op = |builder: &mut Builder, op, lhs, maybe_rhs: Option<_>| {
// HACK(eddyb) remove after `OpSpecConstantOp` support gets added to SPIR-T.
let spirt_has_const_op = false;

if !spirt_has_const_op {
let zombie = builder.undef(ty, None);
cx.zombie_with_span(
zombie,
DUMMY_SP,
&format!("unsupported constant of type `{}`", cx.debug_type(ty)),
);
return zombie;
}

let id = builder.id();
builder
.module_mut()
Expand Down
7 changes: 0 additions & 7 deletions crates/rustc_codegen_spirv/src/codegen_cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,6 @@ impl CodegenArgs {
"dump the final SPIR-T module, to a (pair of) file(s) in DIR",
"DIR",
);
opts.optflag(
"",
"spirt-strip-custom-debuginfo-from-dumps",
"strip custom debuginfo instructions when dumping SPIR-T",
);
opts.optflag(
"",
"spirt-keep-debug-sources-in-dumps",
Expand Down Expand Up @@ -670,8 +665,6 @@ impl CodegenArgs {
}
[None, None] => None,
},
spirt_strip_custom_debuginfo_from_dumps: matches
.opt_present("spirt-strip-custom-debuginfo-from-dumps"),
spirt_keep_debug_sources_in_dumps: matches
.opt_present("spirt-keep-debug-sources-in-dumps"),
spirt_keep_unstructured_cfg_in_dumps: matches
Expand Down
65 changes: 31 additions & 34 deletions crates/rustc_codegen_spirv/src/linker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub struct Options {
pub dump_post_inline: Option<PathBuf>,
pub dump_post_split: Option<PathBuf>,
pub dump_spirt: Option<(PathBuf, DumpSpirtMode)>,
pub spirt_strip_custom_debuginfo_from_dumps: bool,
pub spirt_keep_debug_sources_in_dumps: bool,
pub spirt_keep_unstructured_cfg_in_dumps: bool,
pub specializer_dump_instances: Option<PathBuf>,
Expand Down Expand Up @@ -151,9 +150,6 @@ fn get_name<'a>(names: &FxHashMap<Word, &'a str>, id: Word) -> Cow<'a, str> {
impl Options {
// FIXME(eddyb) using a method on this type seems a bit sketchy.
fn spirt_cleanup_for_dumping(&self, module: &mut spirt::Module) {
if self.spirt_strip_custom_debuginfo_from_dumps {
spirt_passes::debuginfo::convert_custom_debuginfo_to_spv(module);
}
if !self.spirt_keep_debug_sources_in_dumps {
const DOTS: &str = "⋯";
let dots_interned_str = module.cx().intern(DOTS);
Expand Down Expand Up @@ -194,22 +190,31 @@ pub fn link(
spirv_tools::binary::from_binary(&spv_words).to_vec()
};

// FIXME(eddyb) should've really been "spirt::Module::lower_from_spv_bytes".
let lower_from_spv_timer = sess.timer("spirt::Module::lower_from_spv_file");
let cx = std::rc::Rc::new(spirt::Context::new());
crate::custom_insts::register_to_spirt_context(&cx);
(
spv_words,
spirt::Module::lower_from_spv_bytes(cx, spv_bytes),
// HACK(eddyb) this is only returned for `SpirtDumpGuard`.
lower_from_spv_timer,
)

// FIXME(eddyb) should've really been "spirt::Module::lower_from_spv_bytes".
let mut module = {
let _timer = sess.timer("spirt::Module::lower_from_spv_file");
spirt::Module::lower_from_spv_bytes(cx, spv_bytes)
};

// Replace our custom debuginfo instructions as early as possible.
if let Ok(module) = &mut module {
let _timer = sess.timer(
"spirt_passes::debuginfo::convert_custom_decorations_and_debuginfo_to_spirt",
);
spirt_passes::debuginfo::convert_custom_decorations_and_debuginfo_to_spirt(
opts, module,
);
}

(spv_words, module)
};

// FIXME(eddyb) deduplicate with `SpirtDumpGuard`.
let dump_spv_and_spirt = |spv_module: &Module, dump_file_path_stem: PathBuf| {
let (spv_words, spirt_module_or_err, _) =
spv_module_to_spv_words_and_spirt_module(spv_module);
let (spv_words, spirt_module_or_err) = spv_module_to_spv_words_and_spirt_module(spv_module);
std::fs::write(
dump_file_path_stem.with_extension("spv"),
spirv_tools::binary::from_binary(&spv_words),
Expand Down Expand Up @@ -494,8 +499,7 @@ pub fn link(

// NOTE(eddyb) SPIR-T pipeline is entirely limited to this block.
{
let (spv_words, module_or_err, lower_from_spv_timer) =
spv_module_to_spv_words_and_spirt_module(&output);
let (spv_words, module_or_err) = spv_module_to_spv_words_and_spirt_module(&output);
let module = &mut module_or_err.map_err(|e| {
let spv_path = outputs.temp_path_for_diagnostic("spirt-lower-from-spv-input.spv");

Expand Down Expand Up @@ -533,8 +537,8 @@ pub fn link(

sess.timer(pass_name)
};
let mut after_pass = |module: Option<&spirt::Module>, timer| {
drop(timer);
let mut after_pass = |module: Option<&spirt::Module>, maybe_timer| {
drop(maybe_timer);
let pass_name = dump_guard.in_progress_pass_name.take().unwrap();
if let Some(module) = module
&& matches!(opts.dump_spirt, Some((_, DumpSpirtMode::AllPasses)))
Expand All @@ -548,7 +552,7 @@ pub fn link(
// after SPIR-T 0.4.0 it's extremely verbose (due to def-use hermeticity).
after_pass(
(opts.spirt_keep_unstructured_cfg_in_dumps || !opts.structurize).then_some(&*module),
lower_from_spv_timer,
None,
);

// NOTE(eddyb) this *must* run on unstructured CFGs, to do its job.
Expand All @@ -560,13 +564,13 @@ pub fn link(
"spirt_passes::controlflow::convert_custom_aborts_to_unstructured_returns_in_entry_points",
);
spirt_passes::controlflow::convert_custom_aborts_to_unstructured_returns_in_entry_points(opts, module);
after_pass(None, timer);
after_pass(None, Some(timer));
}

if opts.structurize {
let timer = before_pass("spirt::legalize::structurize_func_cfgs");
spirt::passes::legalize::structurize_func_cfgs(module);
after_pass(Some(module), timer);
after_pass(Some(module), Some(timer));
}

if !opts.spirt_passes.is_empty() {
Expand All @@ -575,25 +579,25 @@ pub fn link(
module,
&opts.spirt_passes,
|name, _module| before_pass(name),
&mut after_pass,
|module, timer| after_pass(module, Some(timer)),
);
}

{
let timer = before_pass("spirt_passes::explicit_layout::erase_when_invalid");
spirt_passes::explicit_layout::erase_when_invalid(module);
after_pass(Some(module), timer);
after_pass(Some(module), Some(timer));
}

{
let timer = before_pass("spirt_passes::validate");
spirt_passes::validate::validate(module);
after_pass(Some(module), timer);
after_pass(Some(module), Some(timer));
}

{
let timer = before_pass("spirt_passes::diagnostics::report_diagnostics");
spirt_passes::diagnostics::report_diagnostics(sess, opts, module).map_err(
spirt_passes::diagnostics::report_diagnostics(sess, module).map_err(
|spirt_passes::diagnostics::ReportedDiagnostics {
rustc_errors_guarantee,
any_errors_were_spirt_bugs,
Expand All @@ -602,20 +606,13 @@ pub fn link(
rustc_errors_guarantee
},
)?;
after_pass(None, timer);
}

// Replace our custom debuginfo instructions just before lifting to SPIR-V.
{
let timer = before_pass("spirt_passes::debuginfo::convert_custom_debuginfo_to_spv");
spirt_passes::debuginfo::convert_custom_debuginfo_to_spv(module);
after_pass(None, timer);
after_pass(None, Some(timer));
}

let spv_words = {
let timer = before_pass("spirt::Module::lift_to_spv_module_emitter");
let spv_words = module.lift_to_spv_module_emitter().unwrap().words;
after_pass(None, timer);
after_pass(None, Some(timer));
spv_words
};
// FIXME(eddyb) dump both SPIR-T and `spv_words` if there's an error here.
Expand Down
Loading
Loading