3 use rustc::ty::layout::{FloatTy, Integer, Primitive, Scalar};
4 use rustc_target::spec::abi::Abi;
8 #[derive(Copy, Clone, Debug)]
12 ByValPair(Type, Type),
16 #[derive(Copy, Clone, Debug)]
17 enum EmptySinglePair<T> {
23 impl<T> EmptySinglePair<T> {
24 fn into_iter(self) -> EmptySinglePairIter<T> {
25 EmptySinglePairIter(self)
28 fn map<U>(self, mut f: impl FnMut(T) -> U) -> EmptySinglePair<U> {
31 Single(v) => Single(f(v)),
32 Pair(a, b) => Pair(f(a), f(b)),
37 struct EmptySinglePairIter<T>(EmptySinglePair<T>);
39 impl<T> Iterator for EmptySinglePairIter<T> {
42 fn next(&mut self) -> Option<T> {
43 match std::mem::replace(&mut self.0, Empty) {
54 impl<T: std::fmt::Debug> EmptySinglePair<T> {
55 fn assert_single(self) -> T {
58 _ => panic!("Called assert_single on {:?}", self)
62 fn assert_pair(self) -> (T, T) {
65 _ => panic!("Called assert_pair on {:?}", self)
70 use EmptySinglePair::*;
73 fn get_param_ty(self, fx: &FunctionCx<impl Backend>) -> EmptySinglePair<Type> {
75 PassMode::NoPass => Empty,
76 PassMode::ByVal(clif_type) => Single(clif_type),
77 PassMode::ByValPair(a, b) => Pair(a, b),
78 PassMode::ByRef => Single(fx.pointer_type),
83 pub fn scalar_to_clif_type(tcx: TyCtxt, scalar: Scalar) -> Type {
85 Primitive::Int(int, _sign) => match int {
86 Integer::I8 => types::I8,
87 Integer::I16 => types::I16,
88 Integer::I32 => types::I32,
89 Integer::I64 => types::I64,
90 Integer::I128 => types::I128,
92 Primitive::Float(flt) => match flt {
93 FloatTy::F32 => types::F32,
94 FloatTy::F64 => types::F64,
96 Primitive::Pointer => pointer_ty(tcx),
100 fn get_pass_mode<'tcx>(
102 layout: TyLayout<'tcx>,
104 assert!(!layout.is_unsized());
107 // WARNING zst arguments must never be passed, as that will break CastKind::ClosureFnPointer
111 layout::Abi::Uninhabited => PassMode::NoPass,
112 layout::Abi::Scalar(scalar) => {
113 PassMode::ByVal(scalar_to_clif_type(tcx, scalar.clone()))
115 layout::Abi::ScalarPair(a, b) => {
116 let a = scalar_to_clif_type(tcx, a.clone());
117 let b = scalar_to_clif_type(tcx, b.clone());
118 if a == types::I128 && b == types::I128 {
119 // Returning (i128, i128) by-val-pair would take 4 regs, while only 3 are
120 // available on x86_64. Cranelift gets confused when too many return params
124 PassMode::ByValPair(a, b)
128 // FIXME implement Vector Abi in a cg_llvm compatible way
129 layout::Abi::Vector { .. } => PassMode::ByRef,
131 layout::Abi::Aggregate { .. } => PassMode::ByRef,
136 fn adjust_arg_for_abi<'tcx>(
137 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
139 ) -> EmptySinglePair<Value> {
140 match get_pass_mode(fx.tcx, arg.layout()) {
141 PassMode::NoPass => Empty,
142 PassMode::ByVal(_) => Single(arg.load_scalar(fx)),
143 PassMode::ByValPair(_, _) => {
144 let (a, b) = arg.load_scalar_pair(fx);
147 PassMode::ByRef => Single(arg.force_stack(fx)),
151 fn clif_sig_from_fn_sig<'tcx>(tcx: TyCtxt<'tcx>, sig: FnSig<'tcx>, is_vtable_fn: bool) -> Signature {
152 let abi = match sig.abi {
154 if tcx.sess.target.target.options.is_like_windows {
162 let (call_conv, inputs, output): (CallConv, Vec<Ty>, Ty) = match abi {
163 Abi::Rust => (CallConv::SystemV, sig.inputs().to_vec(), sig.output()),
164 Abi::C => (CallConv::SystemV, sig.inputs().to_vec(), sig.output()),
166 assert_eq!(sig.inputs().len(), 2);
167 let extra_args = match sig.inputs().last().unwrap().sty {
168 ty::Tuple(ref tupled_arguments) => tupled_arguments,
169 _ => bug!("argument to function with \"rust-call\" ABI is not a tuple"),
171 let mut inputs: Vec<Ty> = vec![sig.inputs()[0]];
172 inputs.extend(extra_args.types());
173 (CallConv::SystemV, inputs, sig.output())
175 Abi::System => unreachable!(),
176 Abi::RustIntrinsic => (CallConv::SystemV, sig.inputs().to_vec(), sig.output()),
177 _ => unimplemented!("unsupported abi {:?}", sig.abi),
184 let mut layout = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap();
185 if i == 0 && is_vtable_fn {
186 // Virtual calls turn their self param into a thin pointer.
187 // See https://github.com/rust-lang/rust/blob/37b6a5e5e82497caf5353d9d856e4eb5d14cbe06/src/librustc/ty/layout.rs#L2519-L2572 for more info
188 layout = tcx.layout_of(ParamEnv::reveal_all().and(tcx.mk_mut_ptr(tcx.mk_unit()))).unwrap();
190 match get_pass_mode(tcx, layout) {
191 PassMode::NoPass => Empty,
192 PassMode::ByVal(clif_ty) => Single(clif_ty),
193 PassMode::ByValPair(clif_ty_a, clif_ty_b) => Pair(clif_ty_a, clif_ty_b),
194 PassMode::ByRef => Single(pointer_ty(tcx)),
198 let (params, returns) = match get_pass_mode(tcx, tcx.layout_of(ParamEnv::reveal_all().and(output)).unwrap()) {
199 PassMode::NoPass => (inputs.map(AbiParam::new).collect(), vec![]),
200 PassMode::ByVal(ret_ty) => (
201 inputs.map(AbiParam::new).collect(),
202 vec![AbiParam::new(ret_ty)],
204 PassMode::ByValPair(ret_ty_a, ret_ty_b) => (
205 inputs.map(AbiParam::new).collect(),
206 vec![AbiParam::new(ret_ty_a), AbiParam::new(ret_ty_b)],
210 Some(pointer_ty(tcx)) // First param is place to put return val
227 pub fn get_function_name_and_sig<'tcx>(
229 inst: Instance<'tcx>,
230 support_vararg: bool,
231 ) -> (String, Signature) {
232 assert!(!inst.substs.needs_infer() && !inst.substs.has_param_types());
233 let fn_sig = tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &inst.fn_sig(tcx));
234 if fn_sig.c_variadic && !support_vararg {
235 unimpl!("Variadic function definitions are not yet supported");
237 let sig = clif_sig_from_fn_sig(tcx, fn_sig, false);
238 (tcx.symbol_name(inst).as_str().to_string(), sig)
241 /// Instance must be monomorphized
242 pub fn import_function<'tcx>(
244 module: &mut Module<impl Backend>,
245 inst: Instance<'tcx>,
247 let (name, sig) = get_function_name_and_sig(tcx, inst, true);
249 .declare_function(&name, Linkage::Import, &sig)
253 impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
254 /// Instance must be monomorphized
255 pub fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
256 let func_id = import_function(self.tcx, self.module, inst);
259 .declare_func_in_func(func_id, &mut self.bcx.func);
261 #[cfg(debug_assertions)]
262 self.add_entity_comment(func_ref, format!("{:?}", inst));
270 input_tys: Vec<types::Type>,
271 output_tys: Vec<types::Type>,
274 let sig = Signature {
275 params: input_tys.iter().cloned().map(AbiParam::new).collect(),
276 returns: output_tys.iter().cloned().map(AbiParam::new).collect(),
277 call_conv: CallConv::SystemV,
281 .declare_function(&name, Linkage::Import, &sig)
285 .declare_func_in_func(func_id, &mut self.bcx.func);
286 let call_inst = self.bcx.ins().call(func_ref, args);
287 #[cfg(debug_assertions)] {
288 self.add_comment(call_inst, format!("easy_call {}", name));
290 let results = self.bcx.inst_results(call_inst);
291 assert!(results.len() <= 2, "{}", results.len());
298 args: &[CValue<'tcx>],
301 let (input_tys, args): (Vec<_>, Vec<_>) = args
305 self.clif_type(arg.layout().ty).unwrap(),
306 arg.load_scalar(self),
310 let return_layout = self.layout_of(return_ty);
311 let return_tys = if let ty::Tuple(tup) = return_ty.sty {
312 tup.types().map(|ty| self.clif_type(ty).unwrap()).collect()
314 vec![self.clif_type(return_ty).unwrap()]
316 let ret_vals = self.lib_call(name, input_tys, return_tys, &args);
318 [] => CValue::by_ref(
321 .iconst(self.pointer_type, self.pointer_type.bytes() as i64),
324 [val] => CValue::by_val(val, return_layout),
325 [val, extra] => CValue::by_val_pair(val, extra, return_layout),
330 fn self_sig(&self) -> FnSig<'tcx> {
331 self.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &self.instance.fn_sig(self.tcx))
334 fn return_layout(&self) -> TyLayout<'tcx> {
335 self.layout_of(self.self_sig().output())
339 #[cfg(debug_assertions)]
340 fn add_arg_comment<'tcx>(
341 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
344 local_field: Option<usize>,
345 params: EmptySinglePair<Value>,
347 ssa: crate::analyze::Flags,
350 let local_field = if let Some(local_field) = local_field {
351 Cow::Owned(format!(".{}", local_field))
355 let params = match params {
356 Empty => Cow::Borrowed("-"),
357 Single(param) => Cow::Owned(format!("= {:?}", param)),
358 Pair(param_a, param_b) => Cow::Owned(format!("= {:?}, {:?}", param_a, param_b)),
360 let pass_mode = format!("{:?}", pass_mode);
361 fx.add_global_comment(format!(
362 "{msg:5} {local:>3}{local_field:<5} {params:10} {pass_mode:36} {ssa:10} {ty:?}",
364 local = format!("{:?}", local),
365 local_field = local_field,
367 pass_mode = pass_mode,
368 ssa = format!("{:?}", ssa),
373 #[cfg(debug_assertions)]
374 fn add_local_header_comment(fx: &mut FunctionCx<impl Backend>) {
375 fx.add_global_comment(format!(
376 "msg loc.idx param pass mode ssa flags ty"
380 fn local_place<'tcx>(
381 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
383 layout: TyLayout<'tcx>,
386 let place = if is_ssa {
387 CPlace::new_var(fx, local, layout)
389 let place = CPlace::new_stack_slot(fx, layout.ty);
391 #[cfg(debug_assertions)]
393 let TyLayout { ty, details } = layout;
394 let ty::layout::LayoutDetails {
403 CPlace::Stack(stack_slot, _) => fx.add_entity_comment(
406 "{:?}: {:?} size={} align={},{}",
414 CPlace::NoPlace(_) => fx.add_global_comment(format!(
415 "zst {:?}: {:?} size={} align={}, {}",
426 // Take stack_addr in advance to avoid many duplicate instructions
427 CPlace::for_addr(place.to_addr(fx), layout)
430 let prev_place = fx.local_map.insert(local, place);
431 debug_assert!(prev_place.is_none());
435 fn cvalue_for_param<'tcx>(
436 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
439 local_field: Option<usize>,
441 ssa_flags: crate::analyze::Flags,
442 ) -> Option<CValue<'tcx>> {
443 let layout = fx.layout_of(arg_ty);
444 let pass_mode = get_pass_mode(fx.tcx, fx.layout_of(arg_ty));
446 if let PassMode::NoPass = pass_mode {
450 let clif_types = pass_mode.get_param_ty(fx);
451 let ebb_params = clif_types.map(|t| fx.bcx.append_ebb_param(start_ebb, t));
453 #[cfg(debug_assertions)]
466 PassMode::NoPass => unreachable!(),
467 PassMode::ByVal(_) => Some(CValue::by_val(ebb_params.assert_single(), layout)),
468 PassMode::ByValPair(_, _) => {
469 let (a, b) = ebb_params.assert_pair();
470 Some(CValue::by_val_pair(a, b, layout))
472 PassMode::ByRef => Some(CValue::by_ref(ebb_params.assert_single(), layout)),
476 pub fn codegen_fn_prelude(
477 fx: &mut FunctionCx<'_, '_, impl Backend>,
480 let ssa_analyzed = crate::analyze::analyze(fx);
482 #[cfg(debug_assertions)]
483 fx.add_global_comment(format!("ssa {:?}", ssa_analyzed));
485 let ret_layout = fx.return_layout();
486 let output_pass_mode = get_pass_mode(fx.tcx, fx.return_layout());
487 let ret_param = match output_pass_mode {
488 PassMode::NoPass | PassMode::ByVal(_) | PassMode::ByValPair(_, _) => None,
489 PassMode::ByRef => Some(fx.bcx.append_ebb_param(start_ebb, fx.pointer_type)),
492 #[cfg(debug_assertions)]
494 add_local_header_comment(fx);
495 let ret_param = match ret_param {
496 Some(param) => Single(param),
506 ssa_analyzed[&RETURN_PLACE],
511 // None means pass_mode == NoPass
513 Normal(Option<CValue<'tcx>>),
514 Spread(Vec<Option<CValue<'tcx>>>),
521 let arg_ty = fx.monomorphize(&fx.mir.local_decls[local].ty);
523 // Adapted from https://github.com/rust-lang/rust/blob/145155dc96757002c7b2e9de8489416e2fdbbd57/src/librustc_codegen_llvm/mir/mod.rs#L442-L482
524 if Some(local) == fx.mir.spread_arg {
525 // This argument (e.g. the last argument in the "rust-call" ABI)
526 // is a tuple that was spread at the ABI level and now we have
527 // to reconstruct it into a tuple local variable, from multiple
528 // individual function arguments.
530 let tupled_arg_tys = match arg_ty.sty {
531 ty::Tuple(ref tys) => tys,
532 _ => bug!("spread argument isn't a tuple?! but {:?}", arg_ty),
535 let mut params = Vec::new();
536 for (i, arg_ty) in tupled_arg_tys.types().enumerate() {
537 let param = cvalue_for_param(
543 ssa_analyzed[&local],
548 (local, ArgKind::Spread(params), arg_ty)
551 cvalue_for_param(fx, start_ebb, local, None, arg_ty, ssa_analyzed[&local]);
552 (local, ArgKind::Normal(param), arg_ty)
555 .collect::<Vec<(Local, ArgKind, Ty)>>();
557 fx.bcx.switch_to_block(start_ebb);
559 match output_pass_mode {
560 PassMode::NoPass => {
562 .insert(RETURN_PLACE, CPlace::no_place(ret_layout));
564 PassMode::ByVal(_) | PassMode::ByValPair(_, _) => {
565 let is_ssa = !ssa_analyzed
568 .contains(crate::analyze::Flags::NOT_SSA);
570 local_place(fx, RETURN_PLACE, ret_layout, is_ssa);
575 CPlace::for_addr(ret_param.unwrap(), ret_layout),
580 for (local, arg_kind, ty) in func_params {
581 let layout = fx.layout_of(ty);
583 let is_ssa = !ssa_analyzed
586 .contains(crate::analyze::Flags::NOT_SSA);
588 let place = local_place(fx, local, layout, is_ssa);
591 ArgKind::Normal(param) => {
592 if let Some(param) = param {
593 place.write_cvalue(fx, param);
596 ArgKind::Spread(params) => {
597 for (i, param) in params.into_iter().enumerate() {
598 if let Some(param) = param {
600 .place_field(fx, mir::Field::new(i))
601 .write_cvalue(fx, param);
608 for local in fx.mir.vars_and_temps_iter() {
609 let ty = fx.mir.local_decls[local].ty;
610 let layout = fx.layout_of(ty);
612 let is_ssa = !ssa_analyzed
615 .contains(crate::analyze::Flags::NOT_SSA);
617 local_place(fx, local, layout, is_ssa);
622 .jump(*fx.ebb_map.get(&START_BLOCK).unwrap(), &[]);
625 pub fn codegen_terminator_call<'tcx>(
626 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
627 func: &Operand<'tcx>,
628 args: &[Operand<'tcx>],
629 destination: &Option<(Place<'tcx>, BasicBlock)>,
631 let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.tcx));
632 let sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
634 let destination = destination
636 .map(|&(ref place, bb)| (trans_place(fx, place), bb));
638 if let ty::FnDef(def_id, substs) = fn_ty.sty {
640 ty::Instance::resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap();
642 if fx.tcx.symbol_name(instance).as_str().starts_with("llvm.") {
643 crate::llvm_intrinsics::codegen_llvm_intrinsic_call(fx, &fx.tcx.symbol_name(instance).as_str(), substs, args, destination);
648 InstanceDef::Intrinsic(_) => {
649 crate::intrinsics::codegen_intrinsic_call(fx, def_id, substs, args, destination);
652 InstanceDef::DropGlue(_, None) => {
653 // empty drop glue - a nop.
654 let (_, dest) = destination.expect("Non terminating drop_in_place_real???");
655 let ret_ebb = fx.get_ebb(dest);
656 fx.bcx.ins().jump(ret_ebb, &[]);
663 // Unpack arguments tuple for closures
664 let args = if sig.abi == Abi::RustCall {
665 assert_eq!(args.len(), 2, "rust-call abi requires two arguments");
666 let self_arg = trans_operand(fx, &args[0]);
667 let pack_arg = trans_operand(fx, &args[1]);
668 let mut args = Vec::new();
670 match pack_arg.layout().ty.sty {
671 ty::Tuple(ref tupled_arguments) => {
672 for (i, _) in tupled_arguments.iter().enumerate() {
673 args.push(pack_arg.value_field(fx, mir::Field::new(i)));
676 _ => bug!("argument to function with \"rust-call\" ABI is not a tuple"),
681 .map(|arg| trans_operand(fx, arg))
690 destination.map(|(place, _)| place),
693 if let Some((_, dest)) = destination {
694 let ret_ebb = fx.get_ebb(dest);
695 fx.bcx.ins().jump(ret_ebb, &[]);
697 trap_unreachable(fx, "[corruption] Diverging function returned");
701 fn codegen_call_inner<'tcx>(
702 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
703 func: Option<&Operand<'tcx>>,
705 args: Vec<CValue<'tcx>>,
706 ret_place: Option<CPlace<'tcx>>,
708 let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
710 let ret_layout = fx.layout_of(fn_sig.output());
712 let output_pass_mode = get_pass_mode(fx.tcx, fx.layout_of(fn_sig.output()));
713 let return_ptr = match output_pass_mode {
714 PassMode::NoPass => None,
715 PassMode::ByRef => match ret_place {
716 Some(ret_place) => Some(ret_place.to_addr(fx)),
717 None => Some(fx.bcx.ins().iconst(fx.pointer_type, 43)),
719 PassMode::ByVal(_) | PassMode::ByValPair(_, _) => None,
722 let instance = match fn_ty.sty {
723 ty::FnDef(def_id, substs) => {
724 Some(Instance::resolve(fx.tcx, ParamEnv::reveal_all(), def_id, substs).unwrap())
729 // | indirect call target
730 // | | the first argument to be passed
731 // v v v virtual calls are special cased below
732 let (func_ref, first_arg, is_virtual_call) = match instance {
735 def: InstanceDef::Virtual(_, idx),
738 #[cfg(debug_assertions)]
740 let nop_inst = fx.bcx.ins().nop();
743 format!("virtual call; self arg pass mode: {:?}", get_pass_mode(fx.tcx, args[0].layout())),
746 let (ptr, method) = crate::vtable::get_ptr_and_method_ref(fx, args[0], idx);
747 (Some(method), Single(ptr), true)
751 Some(_) => (None, args.get(0).map(|arg| adjust_arg_for_abi(fx, *arg)).unwrap_or(Empty), false),
755 #[cfg(debug_assertions)]
757 let nop_inst = fx.bcx.ins().nop();
758 fx.add_comment(nop_inst, "indirect call");
760 let func = trans_operand(fx, func.expect("indirect call without func Operand"))
764 args.get(0).map(|arg| adjust_arg_for_abi(fx, *arg)).unwrap_or(Empty),
770 let call_args: Vec<Value> = return_ptr
772 .chain(first_arg.into_iter())
776 .map(|arg| adjust_arg_for_abi(fx, arg).into_iter())
779 .collect::<Vec<_>>();
781 let call_inst = if let Some(func_ref) = func_ref {
784 .import_signature(clif_sig_from_fn_sig(fx.tcx, fn_sig, is_virtual_call));
785 fx.bcx.ins().call_indirect(sig, func_ref, &call_args)
787 let func_ref = fx.get_function_ref(instance.expect("non-indirect call on non-FnDef type"));
788 fx.bcx.ins().call(func_ref, &call_args)
791 // FIXME find a cleaner way to support varargs
792 if fn_sig.c_variadic {
793 if fn_sig.abi != Abi::C {
794 unimpl!("Variadic call for non-C abi {:?}", fn_sig.abi);
796 let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
797 let abi_params = call_args
800 let ty = fx.bcx.func.dfg.value_type(arg);
802 // FIXME set %al to upperbound on float args once floats are supported
803 unimpl!("Non int ty {:?} for variadic call", ty);
807 .collect::<Vec<AbiParam>>();
808 fx.bcx.func.dfg.signatures[sig_ref].params = abi_params;
811 match output_pass_mode {
812 PassMode::NoPass => {}
813 PassMode::ByVal(_) => {
814 if let Some(ret_place) = ret_place {
815 let ret_val = fx.bcx.inst_results(call_inst)[0];
816 ret_place.write_cvalue(fx, CValue::by_val(ret_val, ret_layout));
819 PassMode::ByValPair(_, _) => {
820 if let Some(ret_place) = ret_place {
821 let ret_val_a = fx.bcx.inst_results(call_inst)[0];
822 let ret_val_b = fx.bcx.inst_results(call_inst)[1];
823 ret_place.write_cvalue(fx, CValue::by_val_pair(ret_val_a, ret_val_b, ret_layout));
826 PassMode::ByRef => {}
830 pub fn codegen_drop<'tcx>(
831 fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
832 drop_place: CPlace<'tcx>,
834 let ty = drop_place.layout().ty;
835 let drop_fn = Instance::resolve_drop_in_place(fx.tcx, ty);
837 if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
838 // we don't actually need to drop anything
840 let drop_fn_ty = drop_fn.ty(fx.tcx);
843 let (ptr, vtable) = drop_place.to_addr_maybe_unsized(fx);
844 let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable.unwrap());
846 let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &drop_fn_ty.fn_sig(fx.tcx));
848 assert_eq!(fn_sig.output(), fx.tcx.mk_unit());
852 .import_signature(clif_sig_from_fn_sig(fx.tcx, fn_sig, true));
853 fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]);
856 let arg_place = CPlace::new_stack_slot(
859 &ty::RegionKind::ReErased,
862 mutbl: crate::rustc::hir::Mutability::MutMutable,
866 drop_place.write_place_ref(fx, arg_place);
867 let arg_value = arg_place.to_cvalue(fx);
880 pub fn codegen_return(fx: &mut FunctionCx<impl Backend>) {
881 match get_pass_mode(fx.tcx, fx.return_layout()) {
882 PassMode::NoPass | PassMode::ByRef => {
883 fx.bcx.ins().return_(&[]);
885 PassMode::ByVal(_) => {
886 let place = fx.get_local_place(RETURN_PLACE);
887 let ret_val = place.to_cvalue(fx).load_scalar(fx);
888 fx.bcx.ins().return_(&[ret_val]);
890 PassMode::ByValPair(_, _) => {
891 let place = fx.get_local_place(RETURN_PLACE);
892 let (ret_val_a, ret_val_b) = place.to_cvalue(fx).load_scalar_pair(fx);
893 fx.bcx.ins().return_(&[ret_val_a, ret_val_b]);