1 use crate::abi
::call
::{ArgAbi, FnAbi, Uniform}
;
2 use crate::abi
::{HasDataLayout, TyAbiInterface}
;
4 fn unwrap_trivial_aggregate
<'a
, Ty
, C
>(cx
: &C
, val
: &mut ArgAbi
<'a
, Ty
>) -> bool
6 Ty
: TyAbiInterface
<'a
, C
> + Copy
,
9 if val
.layout
.is_aggregate() {
10 if let Some(unit
) = val
.layout
.homogeneous_aggregate(cx
).ok().and_then(|ha
| ha
.unit()) {
11 let size
= val
.layout
.size
;
12 if unit
.size
== size
{
13 val
.cast_to(Uniform { unit, total: size }
);
21 fn classify_ret
<'a
, Ty
, C
>(cx
: &C
, ret
: &mut ArgAbi
<'a
, Ty
>)
23 Ty
: TyAbiInterface
<'a
, C
> + Copy
,
26 ret
.extend_integer_width_to(32);
27 if ret
.layout
.is_aggregate() && !unwrap_trivial_aggregate(cx
, ret
) {
32 fn classify_arg
<'a
, Ty
, C
>(cx
: &C
, arg
: &mut ArgAbi
<'a
, Ty
>)
34 Ty
: TyAbiInterface
<'a
, C
> + Copy
,
37 arg
.extend_integer_width_to(32);
38 if arg
.layout
.is_aggregate() && !unwrap_trivial_aggregate(cx
, arg
) {
39 arg
.make_indirect_byval();
43 /// The purpose of this ABI is to match the C ABI (aka clang) exactly.
44 pub fn compute_c_abi_info
<'a
, Ty
, C
>(cx
: &C
, fn_abi
: &mut FnAbi
<'a
, Ty
>)
46 Ty
: TyAbiInterface
<'a
, C
> + Copy
,
49 if !fn_abi
.ret
.is_ignore() {
50 classify_ret(cx
, &mut fn_abi
.ret
);
53 for arg
in &mut fn_abi
.args
{
57 classify_arg(cx
, arg
);
61 /// The purpose of this ABI is for matching the WebAssembly standard. This
62 /// intentionally diverges from the C ABI and is specifically crafted to take
63 /// advantage of LLVM's support of multiple returns in WebAssembly.
64 pub fn compute_wasm_abi_info
<Ty
>(fn_abi
: &mut FnAbi
<'_
, Ty
>) {
65 if !fn_abi
.ret
.is_ignore() {
66 classify_ret(&mut fn_abi
.ret
);
69 for arg
in &mut fn_abi
.args
{
76 fn classify_ret
<Ty
>(ret
: &mut ArgAbi
<'_
, Ty
>) {
77 ret
.extend_integer_width_to(32);
80 fn classify_arg
<Ty
>(arg
: &mut ArgAbi
<'_
, Ty
>) {
81 arg
.extend_integer_width_to(32);