Handle signature() for more libcalls (#6174)
* Handle signature() for more libcalls This is necessary to be able to call them in the interpreter. All the remaining libcalls which signature() doesn't handle are never used in clif ir. Only in code compiled by a backend. * Fix libcall declarations in cranelift-frontend * Add function signatures * Use correct pointer type instead of I64
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, Signature},
|
||||
ir::{types, AbiParam, ExternalName, FuncRef, Function, Signature, Type},
|
||||
isa::CallConv,
|
||||
};
|
||||
use core::fmt;
|
||||
@@ -119,7 +119,7 @@ impl LibCall {
|
||||
}
|
||||
|
||||
/// Get a [Signature] for the function targeted by this [LibCall].
|
||||
pub fn signature(&self, call_conv: CallConv) -> Signature {
|
||||
pub fn signature(&self, call_conv: CallConv, pointer_type: Type) -> Signature {
|
||||
use types::*;
|
||||
let mut sig = Signature::new(call_conv);
|
||||
|
||||
@@ -140,13 +140,32 @@ impl LibCall {
|
||||
sig.params.push(AbiParam::new(ty));
|
||||
sig.returns.push(AbiParam::new(ty));
|
||||
}
|
||||
LibCall::Probestack
|
||||
| LibCall::Memcpy
|
||||
| LibCall::Memset
|
||||
| LibCall::Memmove
|
||||
| LibCall::Memcmp
|
||||
| LibCall::ElfTlsGetAddr
|
||||
| LibCall::ElfTlsGetOffset => unimplemented!(),
|
||||
LibCall::Memcpy | LibCall::Memmove => {
|
||||
// void* memcpy(void *dest, const void *src, size_t count);
|
||||
// void* memmove(void* dest, const void* src, size_t count);
|
||||
sig.params.push(AbiParam::new(pointer_type));
|
||||
sig.params.push(AbiParam::new(pointer_type));
|
||||
sig.params.push(AbiParam::new(pointer_type));
|
||||
sig.returns.push(AbiParam::new(pointer_type));
|
||||
}
|
||||
LibCall::Memset => {
|
||||
// void *memset(void *dest, int ch, size_t count);
|
||||
sig.params.push(AbiParam::new(pointer_type));
|
||||
sig.params.push(AbiParam::new(I32));
|
||||
sig.params.push(AbiParam::new(pointer_type));
|
||||
sig.returns.push(AbiParam::new(pointer_type));
|
||||
}
|
||||
LibCall::Memcmp => {
|
||||
// void* memcpy(void *dest, const void *src, size_t count);
|
||||
sig.params.push(AbiParam::new(pointer_type));
|
||||
sig.params.push(AbiParam::new(pointer_type));
|
||||
sig.params.push(AbiParam::new(pointer_type));
|
||||
sig.returns.push(AbiParam::new(I32))
|
||||
}
|
||||
|
||||
LibCall::Probestack | LibCall::ElfTlsGetAddr | LibCall::ElfTlsGetOffset => {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
sig
|
||||
|
||||
@@ -150,7 +150,7 @@ fn emit_vm_call(
|
||||
|
||||
// TODO avoid recreating signatures for every single Libcall function.
|
||||
let call_conv = CallConv::for_libcall(flags, CallConv::triple_default(triple));
|
||||
let sig = libcall.signature(call_conv);
|
||||
let sig = libcall.signature(call_conv, types::I64);
|
||||
let caller_conv = ctx.abi().call_conv(ctx.sigs());
|
||||
|
||||
if !ctx.sigs().have_abi_sig_for_signature(&sig) {
|
||||
|
||||
@@ -629,7 +629,7 @@ impl Context for IsleContext<'_, '_, MInst, X64Backend> {
|
||||
|
||||
fn libcall_1(&mut self, libcall: &LibCall, a: Reg) -> Reg {
|
||||
let call_conv = self.lower_ctx.abi().call_conv(self.lower_ctx.sigs());
|
||||
let ret_ty = libcall.signature(call_conv).returns[0].value_type;
|
||||
let ret_ty = libcall.signature(call_conv, I64).returns[0].value_type;
|
||||
let output_reg = self.lower_ctx.alloc_tmp(ret_ty).only_reg().unwrap();
|
||||
|
||||
emit_vm_call(
|
||||
@@ -647,7 +647,7 @@ impl Context for IsleContext<'_, '_, MInst, X64Backend> {
|
||||
|
||||
fn libcall_3(&mut self, libcall: &LibCall, a: Reg, b: Reg, c: Reg) -> Reg {
|
||||
let call_conv = self.lower_ctx.abi().call_conv(self.lower_ctx.sigs());
|
||||
let ret_ty = libcall.signature(call_conv).returns[0].value_type;
|
||||
let ret_ty = libcall.signature(call_conv, I64).returns[0].value_type;
|
||||
let output_reg = self.lower_ctx.alloc_tmp(ret_ty).only_reg().unwrap();
|
||||
|
||||
emit_vm_call(
|
||||
|
||||
Reference in New Issue
Block a user