linker/test: remove non-SPIR-T codepaths.

This commit is contained in:
Eduard-Mihai Burtescu 2023-04-24 19:50:13 +03:00 committed by Eduard-Mihai Burtescu
parent 9b3eee6b45
commit 6589f07b6f

View File

@ -55,49 +55,18 @@ fn load(bytes: &[u8]) -> Module {
loader.module()
}
struct TestLinkOutputs {
// Old output, equivalent to not passing `--spirt` in codegen args.
without_spirt: Module,
// New output, equivalent to passing `--spirt` in codegen args.
with_spirt: Module,
}
// FIXME(eddyb) shouldn't this be named just `link`? (`assemble_spirv` is separate)
fn assemble_and_link(binaries: &[&[u8]]) -> Result<TestLinkOutputs, PrettyString> {
let link_with_spirt = |spirt: bool| {
link_with_linker_opts(
binaries,
&crate::linker::Options {
compact_ids: true,
dce: true,
keep_link_exports: true,
spirt,
..Default::default()
},
)
};
match [link_with_spirt(false), link_with_spirt(true)] {
[Ok(without_spirt), Ok(with_spirt)] => Ok(TestLinkOutputs {
without_spirt,
with_spirt,
}),
[Err(without_spirt), Err(with_spirt)] if without_spirt == with_spirt => Err(without_spirt),
// Different error, or only one side errored.
[without_spirt, with_spirt] => {
let pretty = |result: Result<Module, _>| {
result.map(|m| {
use rspirv::binary::Disassemble;
PrettyString(m.disassemble())
})
};
// HACK(eddyb) using `assert_eq!` to dump the different `Result`s.
assert_eq!(pretty(without_spirt), pretty(with_spirt));
unreachable!();
}
}
fn assemble_and_link(binaries: &[&[u8]]) -> Result<Module, PrettyString> {
link_with_linker_opts(
binaries,
&crate::linker::Options {
compact_ids: true,
dce: true,
keep_link_exports: true,
spirt: true,
..Default::default()
},
)
}
fn link_with_linker_opts(
@ -193,7 +162,7 @@ fn link_with_linker_opts(
}
#[track_caller]
fn without_header_eq(outputs: TestLinkOutputs, expected: &str) {
fn without_header_eq(output: Module, expected: &str) {
let result = {
let disasm = |mut result: Module| {
use rspirv::binary::Disassemble;
@ -204,21 +173,7 @@ fn without_header_eq(outputs: TestLinkOutputs, expected: &str) {
result.header = None;
result.disassemble()
};
let [without_spirt, with_spirt] =
[disasm(outputs.without_spirt), disasm(outputs.with_spirt)];
// HACK(eddyb) merge the two outputs into a single "dump".
if without_spirt == with_spirt {
without_spirt
} else {
format!(
"=== without SPIR-T ===\n\
{without_spirt}\n\
\n\
=== with SPIR-T ===\n\
{with_spirt}"
)
}
disasm(output)
};
let expected = expected
@ -542,32 +497,7 @@ fn use_exported_func_param_attr() {
let result = assemble_and_link(&[&a, &b]).unwrap();
let expect = r#"=== without SPIR-T ===
OpCapability Kernel
OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 FuncParamAttr Zext
OpDecorate %2 LinkageAttributes "HACK(eddyb) keep function alive" Export
OpDecorate %3 LinkageAttributes "foo" Export
OpDecorate %4 FuncParamAttr Sext
%5 = OpTypeVoid
%6 = OpTypeInt 32 0
%7 = OpTypeFunction %5 %6
%2 = OpFunction %5 None %7
%1 = OpFunctionParameter %6
%8 = OpLabel
%9 = OpLoad %6 %1
OpReturn
OpFunctionEnd
%3 = OpFunction %5 None %7
%4 = OpFunctionParameter %6
%10 = OpLabel
%11 = OpLoad %6 %4
OpReturn
OpFunctionEnd
=== with SPIR-T ===
OpCapability Linkage
let expect = r#"OpCapability Linkage
OpCapability Kernel
OpMemoryModel Logical OpenCL
OpDecorate %1 FuncParamAttr Zext
@ -646,36 +576,7 @@ fn names_and_decorations() {
let result = assemble_and_link(&[&a, &b]).unwrap();
let expect = r#"=== without SPIR-T ===
OpCapability Kernel
OpCapability Linkage
OpMemoryModel Logical OpenCL
OpName %1 "foo"
OpName %2 "param"
OpDecorate %3 Restrict
OpDecorate %3 NonWritable
OpDecorate %4 LinkageAttributes "HACK(eddyb) keep function alive" Export
OpDecorate %1 LinkageAttributes "foo" Export
OpDecorate %2 Restrict
%5 = OpTypeVoid
%6 = OpTypeInt 32 0
%7 = OpTypePointer Function %6
%8 = OpTypeFunction %5 %7
%4 = OpFunction %5 None %8
%3 = OpFunctionParameter %7
%9 = OpLabel
%10 = OpLoad %6 %3
OpReturn
OpFunctionEnd
%1 = OpFunction %5 None %8
%2 = OpFunctionParameter %7
%11 = OpLabel
%12 = OpLoad %6 %2
OpReturn
OpFunctionEnd
=== with SPIR-T ===
OpCapability Linkage
let expect = r#"OpCapability Linkage
OpCapability Kernel
OpMemoryModel Logical OpenCL
OpName %1 "foo"