Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit de713a8

Browse files
committed
Replace all uses of PassMode with ArgAbi
1 parent ff33042 commit de713a8

File tree

4 files changed

+232
-159
lines changed

4 files changed

+232
-159
lines changed

src/abi/comments.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::borrow::Cow;
55

66
use rustc_middle::mir;
7+
use rustc_target::abi::call::ArgAbi;
78

89
use cranelift_codegen::entity::EntityRef;
910

@@ -22,7 +23,7 @@ pub(super) fn add_arg_comment<'tcx>(
2223
local: Option<mir::Local>,
2324
local_field: Option<usize>,
2425
params: EmptySinglePair<Value>,
25-
pass_mode: PassMode,
26+
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
2627
ty: Ty<'tcx>,
2728
) {
2829
let local = if let Some(local) = local {
@@ -42,7 +43,7 @@ pub(super) fn add_arg_comment<'tcx>(
4243
Pair(param_a, param_b) => Cow::Owned(format!("= {:?}, {:?}", param_a, param_b)),
4344
};
4445

45-
let pass_mode = format!("{:?}", pass_mode);
46+
let pass_mode = format!("{:?}", arg_abi.mode);
4647
fx.add_global_comment(format!(
4748
"{kind:5}{local:>3}{local_field:<5} {params:10} {pass_mode:36} {ty:?}",
4849
kind = kind,

src/abi/mod.rs

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ mod pass_mode;
66
mod returning;
77

88
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
9+
use rustc_target::abi::call::PassMode as RustcPassMode;
910
use rustc_target::spec::abi::Abi;
1011

11-
use cranelift_codegen::ir::{AbiParam, ArgumentPurpose};
12+
use cranelift_codegen::ir::AbiParam;
1213

1314
use self::pass_mode::*;
1415
use crate::prelude::*;
@@ -96,7 +97,6 @@ fn clif_sig_from_fn_sig<'tcx>(
9697
tcx: TyCtxt<'tcx>,
9798
triple: &target_lexicon::Triple,
9899
sig: FnSig<'tcx>,
99-
span: Span,
100100
is_vtable_fn: bool,
101101
requires_caller_location: bool,
102102
) -> Signature {
@@ -147,54 +147,26 @@ fn clif_sig_from_fn_sig<'tcx>(
147147
.layout_of(ParamEnv::reveal_all().and(tcx.mk_mut_ptr(tcx.mk_unit())))
148148
.unwrap();
149149
}
150-
let pass_mode = get_pass_mode(tcx, layout);
150+
let mut arg_abi = get_arg_abi(tcx, layout);
151151
if abi != Abi::Rust && abi != Abi::RustCall && abi != Abi::RustIntrinsic {
152-
match pass_mode {
153-
PassMode::NoPass | PassMode::ByVal(_) => {}
154-
PassMode::ByRef { size: Some(size) } => {
155-
let purpose = ArgumentPurpose::StructArgument(u32::try_from(size.bytes()).expect("struct too big to pass on stack"));
156-
return EmptySinglePair::Single(AbiParam::special(pointer_ty(tcx), purpose)).into_iter();
157-
}
158-
PassMode::ByValPair(_, _) | PassMode::ByRef { size: None } => {
159-
tcx.sess.span_warn(
160-
span,
161-
&format!(
162-
"Argument of type `{:?}` with pass mode `{:?}` is not yet supported \
163-
for non-rust abi `{}`. Calling this function may result in a crash.",
164-
layout.ty,
165-
pass_mode,
166-
abi,
167-
),
168-
);
169-
}
152+
match arg_abi.mode {
153+
RustcPassMode::Indirect {
154+
ref mut on_stack, ..
155+
} => *on_stack = true,
156+
_ => {}
170157
}
171158
}
172-
pass_mode.get_param_ty(tcx).map(AbiParam::new).into_iter()
159+
arg_abi.get_abi_param(tcx).into_iter()
173160
})
174161
.flatten();
175162

176-
let (mut params, returns): (Vec<_>, Vec<_>) = match get_pass_mode(
163+
let return_arg_abi = get_arg_abi(
177164
tcx,
178165
tcx.layout_of(ParamEnv::reveal_all().and(output)).unwrap(),
179-
) {
180-
PassMode::NoPass => (inputs.collect(), vec![]),
181-
PassMode::ByVal(ret_ty) => (inputs.collect(), vec![AbiParam::new(ret_ty)]),
182-
PassMode::ByValPair(ret_ty_a, ret_ty_b) => (
183-
inputs.collect(),
184-
vec![AbiParam::new(ret_ty_a), AbiParam::new(ret_ty_b)],
185-
),
186-
PassMode::ByRef { size: Some(_) } => {
187-
(
188-
Some(pointer_ty(tcx)) // First param is place to put return val
189-
.into_iter()
190-
.map(|ty| AbiParam::special(ty, ArgumentPurpose::StructReturn))
191-
.chain(inputs)
192-
.collect(),
193-
vec![],
194-
)
195-
}
196-
PassMode::ByRef { size: None } => todo!(),
197-
};
166+
);
167+
let (return_ptr, returns) = return_arg_abi.get_abi_return(tcx);
168+
// Sometimes the first param is an pointer to the place where the return value needs to be stored.
169+
let mut params: Vec<_> = return_ptr.into_iter().chain(inputs).collect();
198170

199171
if requires_caller_location {
200172
params.push(AbiParam::new(pointer_ty(tcx)));
@@ -226,7 +198,6 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
226198
tcx,
227199
triple,
228200
fn_sig,
229-
tcx.def_span(inst.def_id()),
230201
false,
231202
inst.def.requires_caller_location(tcx),
232203
);
@@ -584,7 +555,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
584555
nop_inst,
585556
format!(
586557
"virtual call; self arg pass mode: {:?}",
587-
get_pass_mode(fx.tcx, args[0].layout())
558+
get_arg_abi(fx.tcx, args[0].layout()).mode,
588559
),
589560
);
590561
}
@@ -647,7 +618,6 @@ pub(crate) fn codegen_terminator_call<'tcx>(
647618
fx.tcx,
648619
fx.triple(),
649620
fn_sig,
650-
span,
651621
is_virtual_call,
652622
false, // calls through function pointers never pass the caller location
653623
);
@@ -723,7 +693,6 @@ pub(crate) fn codegen_drop<'tcx>(
723693
fx.tcx,
724694
fx.triple(),
725695
fn_sig,
726-
span,
727696
true,
728697
false, // `drop_in_place` is never `#[track_caller]`
729698
);

0 commit comments

Comments
 (0)