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:
@@ -1,7 +1,7 @@
|
||||
//! Naming well-known routines in the runtime library.
|
||||
|
||||
use crate::{
|
||||
ir::{types, AbiParam, ExternalName, FuncRef, Function, Opcode, Signature, Type},
|
||||
ir::{types, AbiParam, ExternalName, FuncRef, Function, Signature},
|
||||
isa::CallConv,
|
||||
};
|
||||
use core::fmt;
|
||||
@@ -23,20 +23,6 @@ pub enum LibCall {
|
||||
/// probe for stack overflow. These are emitted for functions which need
|
||||
/// when the `enable_probestack` setting is true.
|
||||
Probestack,
|
||||
/// udiv.i64
|
||||
UdivI64,
|
||||
/// sdiv.i64
|
||||
SdivI64,
|
||||
/// urem.i64
|
||||
UremI64,
|
||||
/// srem.i64
|
||||
SremI64,
|
||||
/// ishl.i64
|
||||
IshlI64,
|
||||
/// ushr.i64
|
||||
UshrI64,
|
||||
/// sshr.i64
|
||||
SshrI64,
|
||||
/// ceil.f32
|
||||
CeilF32,
|
||||
/// ceil.f64
|
||||
@@ -85,13 +71,6 @@ impl FromStr for LibCall {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"Probestack" => Ok(Self::Probestack),
|
||||
"UdivI64" => Ok(Self::UdivI64),
|
||||
"SdivI64" => Ok(Self::SdivI64),
|
||||
"UremI64" => Ok(Self::UremI64),
|
||||
"SremI64" => Ok(Self::SremI64),
|
||||
"IshlI64" => Ok(Self::IshlI64),
|
||||
"UshrI64" => Ok(Self::UshrI64),
|
||||
"SshrI64" => Ok(Self::SshrI64),
|
||||
"CeilF32" => Ok(Self::CeilF32),
|
||||
"CeilF64" => Ok(Self::CeilF64),
|
||||
"FloorF32" => Ok(Self::FloorF32),
|
||||
@@ -115,54 +94,11 @@ impl FromStr for LibCall {
|
||||
}
|
||||
|
||||
impl LibCall {
|
||||
/// Get the well-known library call name to use as a replacement for an instruction with the
|
||||
/// given opcode and controlling type variable.
|
||||
///
|
||||
/// Returns `None` if no well-known library routine name exists for that instruction.
|
||||
pub fn for_inst(opcode: Opcode, ctrl_type: Type) -> Option<Self> {
|
||||
Some(match ctrl_type {
|
||||
types::I64 => match opcode {
|
||||
Opcode::Udiv => Self::UdivI64,
|
||||
Opcode::Sdiv => Self::SdivI64,
|
||||
Opcode::Urem => Self::UremI64,
|
||||
Opcode::Srem => Self::SremI64,
|
||||
Opcode::Ishl => Self::IshlI64,
|
||||
Opcode::Ushr => Self::UshrI64,
|
||||
Opcode::Sshr => Self::SshrI64,
|
||||
_ => return None,
|
||||
},
|
||||
types::F32 => match opcode {
|
||||
Opcode::Ceil => Self::CeilF32,
|
||||
Opcode::Floor => Self::FloorF32,
|
||||
Opcode::Trunc => Self::TruncF32,
|
||||
Opcode::Nearest => Self::NearestF32,
|
||||
Opcode::Fma => Self::FmaF32,
|
||||
_ => return None,
|
||||
},
|
||||
types::F64 => match opcode {
|
||||
Opcode::Ceil => Self::CeilF64,
|
||||
Opcode::Floor => Self::FloorF64,
|
||||
Opcode::Trunc => Self::TruncF64,
|
||||
Opcode::Nearest => Self::NearestF64,
|
||||
Opcode::Fma => Self::FmaF64,
|
||||
_ => return None,
|
||||
},
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get a list of all known `LibCall`'s.
|
||||
pub fn all_libcalls() -> &'static [LibCall] {
|
||||
use LibCall::*;
|
||||
&[
|
||||
Probestack,
|
||||
UdivI64,
|
||||
SdivI64,
|
||||
UremI64,
|
||||
SremI64,
|
||||
IshlI64,
|
||||
UshrI64,
|
||||
SshrI64,
|
||||
CeilF32,
|
||||
CeilF64,
|
||||
FloorF32,
|
||||
@@ -188,17 +124,6 @@ impl LibCall {
|
||||
let mut sig = Signature::new(call_conv);
|
||||
|
||||
match self {
|
||||
LibCall::UdivI64
|
||||
| LibCall::SdivI64
|
||||
| LibCall::UremI64
|
||||
| LibCall::SremI64
|
||||
| LibCall::IshlI64
|
||||
| LibCall::UshrI64
|
||||
| LibCall::SshrI64 => {
|
||||
sig.params.push(AbiParam::new(I64));
|
||||
sig.params.push(AbiParam::new(I64));
|
||||
sig.returns.push(AbiParam::new(I64));
|
||||
}
|
||||
LibCall::CeilF32 | LibCall::FloorF32 | LibCall::TruncF32 | LibCall::NearestF32 => {
|
||||
sig.params.push(AbiParam::new(F32));
|
||||
sig.returns.push(AbiParam::new(F32));
|
||||
|
||||
Reference in New Issue
Block a user