Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Aug 9, 2022
1 parent e52d616 commit 19c0f10
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
3 changes: 1 addition & 2 deletions cranelift/codegen/src/isa/aarch64/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
}

if let ir::ArgumentPurpose::StructReturn = param.purpose {
// FIXME add assert_eq!(args_or_rets, ArgsOrRets::Args); once
// ensure_struct_return_ptr_is_returned is gone.
assert_eq!(args_or_rets, ArgsOrRets::Args);
assert!(
param.value_type == types::I64,
"StructReturn must be a pointer sized integer"
Expand Down
32 changes: 5 additions & 27 deletions cranelift/codegen/src/machinst/abi_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
use super::abi::*;
use crate::binemit::StackMap;
use crate::ir::types::*;
use crate::ir::{ArgumentExtension, ArgumentPurpose, DynamicStackSlot, Signature, StackSlot};
use crate::ir::{ArgumentExtension, DynamicStackSlot, Signature, StackSlot};
use crate::isa::TargetIsa;
use crate::settings;
use crate::CodegenResult;
Expand Down Expand Up @@ -548,8 +548,6 @@ impl ABISig {
sig: &ir::Signature,
flags: &settings::Flags,
) -> CodegenResult<ABISig> {
let sig = ensure_struct_return_ptr_is_returned(sig);

// Compute args and retvals from signature. Handle retvals first,
// because we may need to add a return-area arg to the args.
let (rets, sized_stack_ret_space, _) = M::compute_arg_locs(
Expand Down Expand Up @@ -778,8 +776,7 @@ impl<M: ABIMachineSpec> ABICalleeImpl<M> {
trace!("ABI: func signature {:?}", f.signature);

let flags = isa.flags().clone();
let ir_sig = ensure_struct_return_ptr_is_returned(&f.signature);
let sig = ABISig::from_func_sig::<M>(&ir_sig, &flags)?;
let sig = ABISig::from_func_sig::<M>(&f.signature, &flags)?;

let call_conv = f.signature.call_conv;
// Only these calling conventions are supported.
Expand Down Expand Up @@ -854,7 +851,7 @@ impl<M: ABIMachineSpec> ABICalleeImpl<M> {
};

Ok(Self {
ir_sig,
ir_sig: f.signature.clone(),
sig,
dynamic_stackslots,
dynamic_type_sizes,
Expand Down Expand Up @@ -1031,23 +1028,6 @@ fn gen_store_stack_multi<M: ABIMachineSpec>(
ret
}

fn ensure_struct_return_ptr_is_returned(sig: &ir::Signature) -> ir::Signature {
let params_structret = sig
.params
.iter()
.find(|p| p.purpose == ArgumentPurpose::StructReturn);
let rets_have_structret = sig.returns.len() > 0
&& sig
.returns
.iter()
.any(|arg| arg.purpose == ArgumentPurpose::StructReturn);
let mut sig = sig.clone();
if params_structret.is_some() && !rets_have_structret {
sig.returns.insert(0, params_structret.unwrap().clone());
}
sig
}

impl<M: ABIMachineSpec> ABICallee for ABICalleeImpl<M> {
type I = M::I;

Expand Down Expand Up @@ -1639,8 +1619,7 @@ impl<M: ABIMachineSpec> ABICallerImpl<M> {
caller_conv: isa::CallConv,
flags: &settings::Flags,
) -> CodegenResult<ABICallerImpl<M>> {
let ir_sig = ensure_struct_return_ptr_is_returned(sig);
let sig = ABISig::from_func_sig::<M>(&ir_sig, flags)?;
let sig = ABISig::from_func_sig::<M>(sig, flags)?;
let (uses, defs, clobbers) = sig.call_uses_defs_clobbers::<M>();
Ok(ABICallerImpl {
sig,
Expand All @@ -1664,8 +1643,7 @@ impl<M: ABIMachineSpec> ABICallerImpl<M> {
caller_conv: isa::CallConv,
flags: &settings::Flags,
) -> CodegenResult<ABICallerImpl<M>> {
let ir_sig = ensure_struct_return_ptr_is_returned(sig);
let sig = ABISig::from_func_sig::<M>(&ir_sig, flags)?;
let sig = ABISig::from_func_sig::<M>(sig, flags)?;
let (uses, defs, clobbers) = sig.call_uses_defs_clobbers::<M>();
Ok(ABICallerImpl {
sig,
Expand Down
8 changes: 8 additions & 0 deletions cranelift/filetests/filetests/isa/x64/struct-ret.clif
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ block0(v0: i64):
; popq %rbp
; ret


function %f1(i64) -> i64 {
fn0 = %f2(i64 sret) -> i64

block0(v0: i64):
v1 = call fn0(v0)
return v1
}

0 comments on commit 19c0f10

Please sign in to comment.