cranelift: Add LibCalls to the interpreter (#4782)

* cranelift: Add libcall handlers to interpreter

* cranelift: Fuzz IshlI64 libcall

* cranelift: Revert back to fuzzing udivi64

* cranelift: Use sdiv as a fuzz libcall

* cranelift: Register Sdiv in fuzzgen

* cranelift: Add multiple libcalls to fuzzer

* cranelift: Register a single libcall handler

* cranelift: Simplify args checking in interpreter

* cranelift: Remove unused LibCalls

* cranelift: Cleanup interpreter libcall types

* cranelift: Fix Interpreter Docs
This commit is contained in:
Afonso Bordado
2022-08-29 21:36:33 +01:00
committed by GitHub
parent a6eb24bd4f
commit 9a8bd5be02
9 changed files with 178 additions and 109 deletions

View File

@@ -465,6 +465,16 @@ const OPCODE_SIGNATURES: &'static [(
(Opcode::Call, &[], &[], insert_call),
];
/// These libcalls need a interpreter implementation in `cranelift-fuzzgen.rs`
const ALLOWED_LIBCALLS: &'static [LibCall] = &[
LibCall::CeilF32,
LibCall::CeilF64,
LibCall::FloorF32,
LibCall::FloorF64,
LibCall::TruncF32,
LibCall::TruncF64,
];
pub struct FunctionGenerator<'r, 'data>
where
'data: 'r,
@@ -506,6 +516,12 @@ where
Ok(CallConv::SystemV)
}
fn system_callconv(&mut self) -> CallConv {
// TODO: This currently only runs on linux, so this is the only choice
// We should improve this once we generate flags and targets
CallConv::SystemV
}
fn generate_type(&mut self) -> Result<Type> {
// TODO: It would be nice if we could get these directly from cranelift
let scalars = [
@@ -833,12 +849,11 @@ where
let signature = self.generate_signature()?;
(name, signature)
} else {
// Use udivi64 as an example of a libcall function.
let mut signature = Signature::new(CallConv::Fast);
signature.params.push(AbiParam::new(I64));
signature.params.push(AbiParam::new(I64));
signature.returns.push(AbiParam::new(I64));
(ExternalName::LibCall(LibCall::UdivI64), signature)
let libcall = *self.u.choose(ALLOWED_LIBCALLS)?;
// TODO: Use [CallConv::for_libcall] once we generate flags.
let callconv = self.system_callconv();
let signature = libcall.signature(callconv);
(ExternalName::LibCall(libcall), signature)
};
let sig_ref = builder.import_signature(sig.clone());