1 use crate::abi::pass_mode::*;
4 pub fn codegen_return_param(
5 fx: &mut FunctionCx<impl Backend>,
6 ssa_analyzed: &HashMap<Local, crate::analyze::Flags>,
9 let ret_layout = fx.return_layout();
10 let output_pass_mode = get_pass_mode(fx.tcx, fx.return_layout());
12 let ret_param = match output_pass_mode {
15 .insert(RETURN_PLACE, CPlace::no_place(ret_layout));
18 PassMode::ByVal(_) | PassMode::ByValPair(_, _) => {
19 let is_ssa = !ssa_analyzed
22 .contains(crate::analyze::Flags::NOT_SSA);
24 super::local_place(fx, RETURN_PLACE, ret_layout, is_ssa);
29 let ret_param = fx.bcx.append_ebb_param(start_ebb, fx.pointer_type);
31 .insert(RETURN_PLACE, CPlace::for_addr(ret_param, ret_layout));
37 #[cfg(debug_assertions)]
38 crate::abi::comments::add_arg_comment(
49 pub fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
50 fx: &mut FunctionCx<'_, 'tcx, B>,
52 ret_place: Option<CPlace<'tcx>>,
53 f: impl FnOnce(&mut FunctionCx<'_, 'tcx, B>, Option<Value>) -> (Inst, T),
55 let ret_layout = fx.layout_of(fn_sig.output());
57 let output_pass_mode = get_pass_mode(fx.tcx, ret_layout);
58 let return_ptr = match output_pass_mode {
59 PassMode::NoPass => None,
60 PassMode::ByRef => match ret_place {
61 Some(ret_place) => Some(ret_place.to_addr(fx)),
62 None => Some(fx.bcx.ins().iconst(fx.pointer_type, 43)),
64 PassMode::ByVal(_) | PassMode::ByValPair(_, _) => None,
67 let (call_inst, meta) = f(fx, return_ptr);
69 match output_pass_mode {
70 PassMode::NoPass => {}
71 PassMode::ByVal(_) => {
72 if let Some(ret_place) = ret_place {
73 let ret_val = fx.bcx.inst_results(call_inst)[0];
74 ret_place.write_cvalue(fx, CValue::by_val(ret_val, ret_layout));
77 PassMode::ByValPair(_, _) => {
78 if let Some(ret_place) = ret_place {
79 let ret_val_a = fx.bcx.inst_results(call_inst)[0];
80 let ret_val_b = fx.bcx.inst_results(call_inst)[1];
81 ret_place.write_cvalue(fx, CValue::by_val_pair(ret_val_a, ret_val_b, ret_layout));
90 pub fn codegen_return(fx: &mut FunctionCx<impl Backend>) {
91 match get_pass_mode(fx.tcx, fx.return_layout()) {
92 PassMode::NoPass | PassMode::ByRef => {
93 fx.bcx.ins().return_(&[]);
95 PassMode::ByVal(_) => {
96 let place = fx.get_local_place(RETURN_PLACE);
97 let ret_val = place.to_cvalue(fx).load_scalar(fx);
98 fx.bcx.ins().return_(&[ret_val]);
100 PassMode::ByValPair(_, _) => {
101 let place = fx.get_local_place(RETURN_PLACE);
102 let (ret_val_a, ret_val_b) = place.to_cvalue(fx).load_scalar_pair(fx);
103 fx.bcx.ins().return_(&[ret_val_a, ret_val_b]);