Skip to content

Commit 5354c97

Browse files
eddybLegNeato
authored andcommitted
update spirt to 0.4.0
1 parent d2eb777 commit 5354c97

File tree

11 files changed

+175
-202
lines changed

11 files changed

+175
-202
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustc_codegen_spirv/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ rustc_codegen_spirv-types.workspace = true
5555
rustc-demangle = "0.1.21"
5656
sanitize-filename = "0.4"
5757
smallvec = { version = "1.6.1", features = ["union"] }
58-
spirt = "0.3.0"
58+
spirt = "0.4.0"
5959
spirv-tools.workspace = true
6060
lazy_static = "1.4.0"
6161
itertools = "0.10.5"

crates/rustc_codegen_spirv/src/codegen_cx/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ impl CodegenArgs {
460460
"spirt-keep-debug-sources-in-dumps",
461461
"keep file contents debuginfo when dumping SPIR-T",
462462
);
463+
opts.optflag(
464+
"",
465+
"spirt-keep-unstructured-cfg-in-dumps",
466+
"include initial unstructured CFG when dumping SPIR-T",
467+
);
463468
opts.optflag(
464469
"",
465470
"specializer-debug",
@@ -629,6 +634,8 @@ impl CodegenArgs {
629634
.opt_present("spirt-strip-custom-debuginfo-from-dumps"),
630635
spirt_keep_debug_sources_in_dumps: matches
631636
.opt_present("spirt-keep-debug-sources-in-dumps"),
637+
spirt_keep_unstructured_cfg_in_dumps: matches
638+
.opt_present("spirt-keep-unstructured-cfg-in-dumps"),
632639
specializer_debug: matches.opt_present("specializer-debug"),
633640
specializer_dump_instances: matches_opt_path("specializer-dump-instances"),
634641
print_all_zombie: matches.opt_present("print-all-zombie"),

crates/rustc_codegen_spirv/src/linker/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub struct Options {
6262
pub dump_spirt_passes: Option<PathBuf>,
6363
pub spirt_strip_custom_debuginfo_from_dumps: bool,
6464
pub spirt_keep_debug_sources_in_dumps: bool,
65+
pub spirt_keep_unstructured_cfg_in_dumps: bool,
6566
pub specializer_debug: bool,
6667
pub specializer_dump_instances: Option<PathBuf>,
6768
pub print_all_zombie: bool,
@@ -434,7 +435,11 @@ pub fn link(
434435
}
435436
}
436437
};
437-
after_pass("lower_from_spv", &module);
438+
// HACK(eddyb) don't dump the unstructured state if not requested, as
439+
// after SPIR-T 0.4.0 it's extremely verbose (due to def-use hermeticity).
440+
if opts.spirt_keep_unstructured_cfg_in_dumps || !opts.structurize {
441+
after_pass("lower_from_spv", &module);
442+
}
438443

439444
// NOTE(eddyb) this *must* run on unstructured CFGs, to do its job.
440445
{

crates/rustc_codegen_spirv/src/linker/spirt_passes/controlflow.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::custom_insts::{self, CustomInst, CustomOp};
44
use smallvec::SmallVec;
55
use spirt::func_at::FuncAt;
66
use spirt::{
7-
cfg, spv, Attr, AttrSet, ConstCtor, ConstDef, ControlNodeKind, DataInstFormDef, DataInstKind,
8-
DeclDef, EntityDefs, ExportKey, Exportee, Module, Type, TypeCtor, TypeCtorArg, TypeDef, Value,
7+
cfg, spv, Attr, AttrSet, ConstDef, ConstKind, ControlNodeKind, DataInstFormDef, DataInstKind,
8+
DeclDef, EntityDefs, ExportKey, Exportee, Module, Type, TypeDef, TypeKind, TypeOrConst, Value,
99
};
1010
use std::fmt::Write as _;
1111

@@ -66,8 +66,8 @@ pub fn convert_custom_aborts_to_unstructured_returns_in_entry_points(
6666
};
6767

6868
let func_decl = &mut module.funcs[func];
69-
assert!(match &cx[func_decl.ret_type].ctor {
70-
TypeCtor::SpvInst(spv_inst) => spv_inst.opcode == wk.OpTypeVoid,
69+
assert!(match &cx[func_decl.ret_type].kind {
70+
TypeKind::SpvInst { spv_inst, .. } => spv_inst.opcode == wk.OpTypeVoid,
7171
_ => false,
7272
});
7373

@@ -112,7 +112,7 @@ pub fn convert_custom_aborts_to_unstructured_returns_in_entry_points(
112112
if let DataInstKind::SpvInst(spv_inst) = &data_inst_form_def.kind {
113113
if spv_inst.opcode == wk.OpLoad {
114114
if let Value::Const(ct) = data_inst_def.inputs[0] {
115-
if let ConstCtor::PtrToGlobalVar(gv) = cx[ct].ctor {
115+
if let ConstKind::PtrToGlobalVar(gv) = cx[ct].kind {
116116
if interface_global_vars.contains(&gv) {
117117
return Some((
118118
gv,
@@ -129,8 +129,8 @@ pub fn convert_custom_aborts_to_unstructured_returns_in_entry_points(
129129
if inputs {
130130
let mut first_input = true;
131131
for (gv, ty, value) in loaded_inputs {
132-
let scalar_type = |ty: Type| match &cx[ty].ctor {
133-
TypeCtor::SpvInst(spv_inst) => match spv_inst.imms[..] {
132+
let scalar_type = |ty: Type| match &cx[ty].kind {
133+
TypeKind::SpvInst { spv_inst, .. } => match spv_inst.imms[..] {
134134
[spv::Imm::Short(_, 32), spv::Imm::Short(_, signedness)]
135135
if spv_inst.opcode == wk.OpTypeInt =>
136136
{
@@ -145,14 +145,16 @@ pub fn convert_custom_aborts_to_unstructured_returns_in_entry_points(
145145
};
146146
let vector_or_scalar_type = |ty: Type| {
147147
let ty_def = &cx[ty];
148-
match (&ty_def.ctor, &ty_def.ctor_args[..]) {
149-
(TypeCtor::SpvInst(spv_inst), &[TypeCtorArg::Type(elem)])
150-
if spv_inst.opcode == wk.OpTypeVector =>
151-
{
152-
match spv_inst.imms[..] {
153-
[spv::Imm::Short(_, vlen @ 2..=4)] => {
154-
Some((scalar_type(elem)?, Some(vlen)))
155-
}
148+
match &ty_def.kind {
149+
TypeKind::SpvInst {
150+
spv_inst,
151+
type_and_const_inputs,
152+
} if spv_inst.opcode == wk.OpTypeVector => {
153+
match (&type_and_const_inputs[..], &spv_inst.imms[..]) {
154+
(
155+
&[TypeOrConst::Type(elem)],
156+
&[spv::Imm::Short(_, vlen @ 2..=4)],
157+
) => Some((scalar_type(elem)?, Some(vlen))),
156158
_ => None,
157159
}
158160
}
@@ -260,16 +262,19 @@ pub fn convert_custom_aborts_to_unstructured_returns_in_entry_points(
260262
inputs: _,
261263
backtrace,
262264
}) => {
263-
let const_ctor = |v: Value| match v {
264-
Value::Const(ct) => &cx[ct].ctor,
265+
let const_kind = |v: Value| match v {
266+
Value::Const(ct) => &cx[ct].kind,
265267
_ => unreachable!(),
266268
};
267-
let const_str = |v: Value| match const_ctor(v) {
268-
&ConstCtor::SpvStringLiteralForExtInst(s) => s,
269+
let const_str = |v: Value| match const_kind(v) {
270+
&ConstKind::SpvStringLiteralForExtInst(s) => s,
269271
_ => unreachable!(),
270272
};
271-
let const_u32 = |v: Value| match const_ctor(v) {
272-
ConstCtor::SpvInst(spv_inst) => {
273+
let const_u32 = |v: Value| match const_kind(v) {
274+
ConstKind::SpvInst {
275+
spv_inst_and_const_inputs,
276+
} => {
277+
let (spv_inst, _const_inputs) = &**spv_inst_and_const_inputs;
273278
assert!(spv_inst.opcode == wk.OpConstant);
274279
match spv_inst.imms[..] {
275280
[spv::Imm::Short(_, x)] => x,
@@ -283,11 +288,9 @@ pub fn convert_custom_aborts_to_unstructured_returns_in_entry_points(
283288
attrs: Default::default(),
284289
ty: cx.intern(TypeDef {
285290
attrs: Default::default(),
286-
ctor: TypeCtor::SpvStringLiteralForExtInst,
287-
ctor_args: Default::default(),
291+
kind: TypeKind::SpvStringLiteralForExtInst,
288292
}),
289-
ctor: ConstCtor::SpvStringLiteralForExtInst(s),
290-
ctor_args: Default::default(),
293+
kind: ConstKind::SpvStringLiteralForExtInst(s),
291294
})
292295
};
293296

crates/rustc_codegen_spirv/src/linker/spirt_passes/debuginfo.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use smallvec::SmallVec;
66
use spirt::transform::{InnerInPlaceTransform, Transformer};
77
use spirt::visit::InnerVisit;
88
use spirt::{
9-
spv, Attr, AttrSetDef, ConstCtor, Context, ControlNode, ControlNodeKind, DataInstKind,
9+
spv, Attr, AttrSetDef, ConstKind, Context, ControlNode, ControlNodeKind, DataInstKind,
1010
InternedStr, Module, OrdAssertEq, Value,
1111
};
1212

@@ -95,16 +95,20 @@ impl Transformer for CustomDebuginfoToSpv<'_> {
9595
col_start: col,
9696
col_end: _,
9797
} => {
98-
let const_ctor = |v: Value| match v {
99-
Value::Const(ct) => &self.cx[ct].ctor,
98+
let const_kind = |v: Value| match v {
99+
Value::Const(ct) => &self.cx[ct].kind,
100100
_ => unreachable!(),
101101
};
102-
let const_str = |v: Value| match const_ctor(v) {
103-
&ConstCtor::SpvStringLiteralForExtInst(s) => s,
102+
let const_str = |v: Value| match const_kind(v) {
103+
&ConstKind::SpvStringLiteralForExtInst(s) => s,
104104
_ => unreachable!(),
105105
};
106-
let const_u32 = |v: Value| match const_ctor(v) {
107-
ConstCtor::SpvInst(spv_inst) => {
106+
let const_u32 = |v: Value| match const_kind(v) {
107+
ConstKind::SpvInst {
108+
spv_inst_and_const_inputs,
109+
} => {
110+
let (spv_inst, _const_inputs) =
111+
&**spv_inst_and_const_inputs;
108112
assert!(spv_inst.opcode == self.wk.OpConstant);
109113
match spv_inst.imms[..] {
110114
[spv::Imm::Short(_, x)] => x,

crates/rustc_codegen_spirv/src/linker/spirt_passes/diagnostics.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use smallvec::SmallVec;
1010
use spirt::func_at::FuncAt;
1111
use spirt::visit::{InnerVisit, Visitor};
1212
use spirt::{
13-
spv, Attr, AttrSet, AttrSetDef, Const, ConstCtor, Context, ControlNode, ControlNodeKind,
13+
spv, Attr, AttrSet, AttrSetDef, Const, ConstKind, Context, ControlNode, ControlNodeKind,
1414
DataInstDef, DataInstForm, DataInstKind, Diag, DiagLevel, ExportKey, Exportee, Func, FuncDecl,
1515
GlobalVar, InternedStr, Module, Type, Value,
1616
};
@@ -275,16 +275,19 @@ impl UseOrigin<'_> {
275275
} => (file, line_start, line_end, col_start, col_end),
276276
_ => unreachable!(),
277277
};
278-
let const_ctor = |v: Value| match v {
279-
Value::Const(ct) => &cx[ct].ctor,
278+
let const_kind = |v: Value| match v {
279+
Value::Const(ct) => &cx[ct].kind,
280280
_ => unreachable!(),
281281
};
282-
let const_str = |v: Value| match const_ctor(v) {
283-
&ConstCtor::SpvStringLiteralForExtInst(s) => s,
282+
let const_str = |v: Value| match const_kind(v) {
283+
&ConstKind::SpvStringLiteralForExtInst(s) => s,
284284
_ => unreachable!(),
285285
};
286-
let const_u32 = |v: Value| match const_ctor(v) {
287-
ConstCtor::SpvInst(spv_inst) => {
286+
let const_u32 = |v: Value| match const_kind(v) {
287+
ConstKind::SpvInst {
288+
spv_inst_and_const_inputs,
289+
} => {
290+
let (spv_inst, _const_inputs) = &**spv_inst_and_const_inputs;
288291
assert!(spv_inst.opcode == wk.OpConstant);
289292
match spv_inst.imms[..] {
290293
[spv::Imm::Short(_, x)] => x,
@@ -505,9 +508,9 @@ impl<'a> Visitor<'a> for DiagnosticReporter<'a> {
505508
fn visit_const_use(&mut self, ct: Const) {
506509
if self.seen_consts.insert(ct) {
507510
let ct_def = &self.cx[ct];
508-
match ct_def.ctor {
511+
match ct_def.kind {
509512
// HACK(eddyb) don't push an `UseOrigin` for `GlobalVar` pointers.
510-
ConstCtor::PtrToGlobalVar(_) if ct_def.attrs == AttrSet::default() => {
513+
ConstKind::PtrToGlobalVar(_) if ct_def.attrs == AttrSet::default() => {
511514
self.visit_const_def(ct_def);
512515
}
513516
_ => {
@@ -642,12 +645,12 @@ impl<'a> Visitor<'a> for DiagnosticReporter<'a> {
642645
// Treat this like a call, in the caller.
643646
replace_origin(self, IntraFuncUseOrigin::CallCallee);
644647

645-
let const_ctor = |v: Value| match v {
646-
Value::Const(ct) => &self.cx[ct].ctor,
648+
let const_kind = |v: Value| match v {
649+
Value::Const(ct) => &self.cx[ct].kind,
647650
_ => unreachable!(),
648651
};
649-
let const_str = |v: Value| match const_ctor(v) {
650-
&ConstCtor::SpvStringLiteralForExtInst(s) => s,
652+
let const_str = |v: Value| match const_kind(v) {
653+
&ConstKind::SpvStringLiteralForExtInst(s) => s,
651654
_ => unreachable!(),
652655
};
653656
self.use_stack.push(UseOrigin::IntraFunc {

0 commit comments

Comments
 (0)