Pick argument and return types based on opcode constraints (#5947)

* Pick argument and return types based on opcode constraints

Co-authored-by: Jamey Sharp <jsharp@fastly.com>

* Lazily build the OPCODE_SIGNATURES list

* Skip unsupported isplit/iconcat cases

* Add an issue reference for the isplit/iconcat exemption

* Refactor the deny lists to use exceptions!, and remove redundant entries

---------

Co-authored-by: Jamey Sharp <jsharp@fastly.com>
This commit is contained in:
Trevor Elliott
2023-03-21 14:52:42 -07:00
committed by GitHub
parent 13be5618a7
commit a24002508d
4 changed files with 809 additions and 1167 deletions

1
Cargo.lock generated
View File

@@ -651,6 +651,7 @@ dependencies = [
"arbitrary",
"cranelift",
"cranelift-native",
"once_cell",
"target-lexicon",
]

View File

@@ -16,4 +16,5 @@ cranelift-native = { workspace = true }
anyhow = { workspace = true }
arbitrary = "1.0.0"
once_cell = { workspace = true }
target-lexicon = { workspace = true, features = ["std"] }

View File

@@ -23,23 +23,26 @@ pub trait CraneliftArbitrary {
fn datavalue(&mut self, ty: Type) -> Result<DataValue>;
}
/// Returns the set of types that are valid for value generation, dependent on architecture.
pub fn types_for_architecture(architecture: Architecture) -> &'static [Type] {
// TODO: It would be nice if we could get these directly from cranelift
// TODO: RISCV does not support SIMD yet
let supports_simd = !matches!(architecture, Architecture::Riscv64(_));
if supports_simd {
&[
I8, I16, I32, I64, I128, // Scalar Integers
F32, F64, // Scalar Floats
I8X16, I16X8, I32X4, I64X2, // SIMD Integers
F32X4, F64X2, // SIMD Floats
]
} else {
&[I8, I16, I32, I64, I128, F32, F64]
}
}
impl<'a> CraneliftArbitrary for &mut Unstructured<'a> {
fn _type(&mut self, architecture: Architecture) -> Result<Type> {
// TODO: It would be nice if we could get these directly from cranelift
// TODO: RISCV does not support SIMD yet
let supports_simd = !matches!(architecture, Architecture::Riscv64(_));
let choices = if supports_simd {
&[
I8, I16, I32, I64, I128, // Scalar Integers
F32, F64, // Scalar Floats
I8X16, I16X8, I32X4, I64X2, // SIMD Integers
F32X4, F64X2, // SIMD Floats
][..]
} else {
&[I8, I16, I32, I64, I128, F32, F64][..]
};
Ok(*self.choose(choices)?)
Ok(*self.choose(types_for_architecture(architecture))?)
}
fn callconv(&mut self) -> Result<CallConv> {

File diff suppressed because it is too large Load Diff