]> git.lizzy.rs Git - rust.git/blob - src/abi.rs
Add some more clif comments
[rust.git] / src / abi.rs
1 use std::borrow::Cow;
2 use std::iter;
3
4 use rustc::hir;
5 use rustc_target::spec::abi::Abi;
6
7 use crate::prelude::*;
8
9 #[derive(Copy, Clone, Debug)]
10 enum PassMode {
11     NoPass,
12     ByVal(Type),
13     ByRef,
14 }
15
16 impl PassMode {
17     fn get_param_ty(self, fx: &FunctionCx<impl Backend>) -> Type {
18         match self {
19             PassMode::NoPass => unimplemented!("pass mode nopass"),
20             PassMode::ByVal(clif_type) => clif_type,
21             PassMode::ByRef => fx.pointer_type,
22         }
23     }
24 }
25
26 fn get_pass_mode<'a, 'tcx: 'a>(
27     tcx: TyCtxt<'a, 'tcx, 'tcx>,
28     abi: Abi,
29     ty: Ty<'tcx>,
30     is_return: bool,
31 ) -> PassMode {
32     assert!(!tcx
33         .layout_of(ParamEnv::reveal_all().and(ty))
34         .unwrap()
35         .is_unsized());
36     if let ty::Never = ty.sty {
37         if is_return {
38             PassMode::NoPass
39         } else {
40             PassMode::ByRef
41         }
42     } else if ty.sty == tcx.mk_unit().sty {
43         if is_return {
44             PassMode::NoPass
45         } else {
46             PassMode::ByRef
47         }
48     } else if let Some(ret_ty) = crate::common::clif_type_from_ty(tcx, ty) {
49         PassMode::ByVal(ret_ty)
50     } else {
51         if abi == Abi::C {
52             unimpl!(
53                 "Non scalars are not yet supported for \"C\" abi ({:?}) is_return: {:?}",
54                 ty,
55                 is_return
56             );
57         }
58         PassMode::ByRef
59     }
60 }
61
62 fn adjust_arg_for_abi<'a, 'tcx: 'a>(
63     fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
64     sig: FnSig<'tcx>,
65     arg: CValue<'tcx>,
66 ) -> Value {
67     match get_pass_mode(fx.tcx, sig.abi, arg.layout().ty, false) {
68         PassMode::NoPass => unimplemented!("pass mode nopass"),
69         PassMode::ByVal(_) => arg.load_value(fx),
70         PassMode::ByRef => arg.force_stack(fx),
71     }
72 }
73
74 fn clif_sig_from_fn_ty<'a, 'tcx: 'a>(
75     tcx: TyCtxt<'a, 'tcx, 'tcx>,
76     fn_ty: Ty<'tcx>,
77 ) -> Signature {
78     let sig = ty_fn_sig(tcx, fn_ty);
79     if sig.variadic {
80         unimpl!("Variadic function are not yet supported");
81     }
82     let (call_conv, inputs, output): (CallConv, Vec<Ty>, Ty) = match sig.abi {
83         Abi::Rust => (CallConv::SystemV, sig.inputs().to_vec(), sig.output()),
84         Abi::C => (CallConv::SystemV, sig.inputs().to_vec(), sig.output()),
85         Abi::RustCall => {
86             assert_eq!(sig.inputs().len(), 2);
87             let extra_args = match sig.inputs().last().unwrap().sty {
88                 ty::Tuple(ref tupled_arguments) => tupled_arguments,
89                 _ => bug!("argument to function with \"rust-call\" ABI is not a tuple"),
90             };
91             let mut inputs: Vec<Ty> = vec![sig.inputs()[0]];
92             inputs.extend(extra_args.into_iter());
93             (CallConv::SystemV, inputs, sig.output())
94         }
95         Abi::System => bug!("system abi should be selected elsewhere"),
96         Abi::RustIntrinsic => (CallConv::SystemV, sig.inputs().to_vec(), sig.output()),
97         _ => unimplemented!("unsupported abi {:?}", sig.abi),
98     };
99
100     let inputs = inputs
101         .into_iter()
102         .filter_map(|ty| match get_pass_mode(tcx, sig.abi, ty, false) {
103             PassMode::ByVal(clif_ty) => Some(clif_ty),
104             PassMode::NoPass => unimplemented!("pass mode nopass"),
105             PassMode::ByRef => Some(pointer_ty(tcx)),
106         });
107
108     let (params, returns) = match get_pass_mode(tcx, sig.abi, output, true) {
109         PassMode::NoPass => (inputs.map(AbiParam::new).collect(), vec![]),
110         PassMode::ByVal(ret_ty) => (
111             inputs.map(AbiParam::new).collect(),
112             vec![AbiParam::new(ret_ty)],
113         ),
114         PassMode::ByRef => {
115             (
116                 Some(pointer_ty(tcx)) // First param is place to put return val
117                     .into_iter()
118                     .chain(inputs)
119                     .map(AbiParam::new)
120                     .collect(),
121                 vec![],
122             )
123         }
124     };
125
126     Signature {
127         params,
128         returns,
129         call_conv,
130     }
131 }
132
133 pub fn ty_fn_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> ty::FnSig<'tcx> {
134     let sig = match ty.sty {
135         ty::FnDef(..) |
136         // Shims currently have type TyFnPtr. Not sure this should remain.
137         ty::FnPtr(_) => ty.fn_sig(tcx),
138         ty::Closure(def_id, substs) => {
139             let sig = substs.closure_sig(def_id, tcx);
140
141             let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
142             sig.map_bound(|sig| tcx.mk_fn_sig(
143                 iter::once(*env_ty.skip_binder()).chain(sig.inputs().iter().cloned()),
144                 sig.output(),
145                 sig.variadic,
146                 sig.unsafety,
147                 sig.abi
148             ))
149         }
150         ty::Generator(def_id, substs, _) => {
151             let sig = substs.poly_sig(def_id, tcx);
152
153             let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
154             let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
155
156             sig.map_bound(|sig| {
157                 let state_did = tcx.lang_items().gen_state().unwrap();
158                 let state_adt_ref = tcx.adt_def(state_did);
159                 let state_substs = tcx.intern_substs(&[
160                     sig.yield_ty.into(),
161                     sig.return_ty.into(),
162                 ]);
163                 let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
164
165                 tcx.mk_fn_sig(iter::once(env_ty),
166                     ret_ty,
167                     false,
168                     hir::Unsafety::Normal,
169                     Abi::Rust
170                 )
171             })
172         }
173         _ => bug!("unexpected type {:?} to ty_fn_sig", ty)
174     };
175     tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &sig)
176 }
177
178 pub fn get_function_name_and_sig<'a, 'tcx>(
179     tcx: TyCtxt<'a, 'tcx, 'tcx>,
180     inst: Instance<'tcx>,
181 ) -> (String, Signature) {
182     assert!(!inst.substs.needs_infer() && !inst.substs.has_param_types());
183     let fn_ty = inst.ty(tcx);
184     let sig = clif_sig_from_fn_ty(tcx, fn_ty);
185     (tcx.symbol_name(inst).as_str().to_string(), sig)
186 }
187
188 impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
189     /// Instance must be monomorphized
190     pub fn get_function_id(&mut self, inst: Instance<'tcx>) -> FuncId {
191         let (name, sig) = get_function_name_and_sig(self.tcx, inst);
192         self.module
193             .declare_function(&name, Linkage::Import, &sig)
194             .unwrap()
195     }
196
197     /// Instance must be monomorphized
198     pub fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
199         let func_id = self.get_function_id(inst);
200         let func_ref = self.module
201             .declare_func_in_func(func_id, &mut self.bcx.func);
202         self.add_entity_comment(func_ref, format!("{:?}", inst));
203         func_ref
204     }
205
206     fn lib_call(
207         &mut self,
208         name: &str,
209         input_tys: Vec<types::Type>,
210         output_ty: Option<types::Type>,
211         args: &[Value],
212     ) -> Option<Value> {
213         let sig = Signature {
214             params: input_tys.iter().cloned().map(AbiParam::new).collect(),
215             returns: output_ty
216                 .map(|output_ty| vec![AbiParam::new(output_ty)])
217                 .unwrap_or(Vec::new()),
218             call_conv: CallConv::SystemV,
219         };
220         let func_id = self
221             .module
222             .declare_function(&name, Linkage::Import, &sig)
223             .unwrap();
224         let func_ref = self
225             .module
226             .declare_func_in_func(func_id, &mut self.bcx.func);
227         let call_inst = self.bcx.ins().call(func_ref, args);
228         if output_ty.is_none() {
229             return None;
230         }
231         let results = self.bcx.inst_results(call_inst);
232         assert_eq!(results.len(), 1);
233         Some(results[0])
234     }
235
236     pub fn easy_call(
237         &mut self,
238         name: &str,
239         args: &[CValue<'tcx>],
240         return_ty: Ty<'tcx>,
241     ) -> CValue<'tcx> {
242         let (input_tys, args): (Vec<_>, Vec<_>) = args
243             .into_iter()
244             .map(|arg| {
245                 (
246                     self.clif_type(arg.layout().ty).unwrap(),
247                     arg.load_value(self),
248                 )
249             })
250             .unzip();
251         let return_layout = self.layout_of(return_ty);
252         let return_ty = if let ty::Tuple(tup) = return_ty.sty {
253             if !tup.is_empty() {
254                 bug!("easy_call( (...) -> <non empty tuple> ) is not allowed");
255             }
256             None
257         } else {
258             Some(self.clif_type(return_ty).unwrap())
259         };
260         if let Some(val) = self.lib_call(name, input_tys, return_ty, &args) {
261             CValue::ByVal(val, return_layout)
262         } else {
263             CValue::ByRef(self.bcx.ins().iconst(self.pointer_type, 0), return_layout)
264         }
265     }
266
267     fn self_sig(&self) -> FnSig<'tcx> {
268         ty_fn_sig(self.tcx, self.instance.ty(self.tcx))
269     }
270
271     fn return_type(&self) -> Ty<'tcx> {
272         self.self_sig().output()
273     }
274 }
275
276 fn add_arg_comment<'a, 'tcx: 'a>(
277     fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
278     msg: &str,
279     local: mir::Local,
280     local_field: Option<usize>,
281     param: Option<Value>,
282     pass_mode: PassMode,
283     ssa: crate::analyze::Flags,
284     ty: Ty<'tcx>,
285 ) {
286     let local_field = if let Some(local_field) = local_field {
287         Cow::Owned(format!(".{}", local_field))
288     } else {
289         Cow::Borrowed("")
290     };
291     let param = if let Some(param) = param {
292         Cow::Owned(format!("= {:?}", param))
293     } else {
294         Cow::Borrowed("-")
295     };
296     let pass_mode = format!("{:?}", pass_mode);
297     fx.add_global_comment(format!(
298         "{msg:5} {local:>3}{local_field:<5} {param:10} {pass_mode:20} {ssa:10} {ty:?}",
299         msg=msg, local=format!("{:?}", local), local_field=local_field, param=param, pass_mode=pass_mode, ssa=format!("{:?}", ssa), ty=ty,
300     ));
301 }
302
303 fn add_local_header_comment(fx: &mut FunctionCx<impl Backend>) {
304     fx.add_global_comment(format!("msg   loc.idx    param    pass mode            ssa flags  ty"));
305 }
306
307 fn local_place<'a, 'tcx: 'a>(
308     fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
309     local: Local,
310     layout: TyLayout<'tcx>,
311     is_ssa: bool,
312 ) -> CPlace<'tcx> {
313     let place = if is_ssa {
314         fx.bcx.declare_var(mir_var(local), fx.clif_type(layout.ty).unwrap());
315         CPlace::Var(local, layout)
316     } else {
317         let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
318             kind: StackSlotKind::ExplicitSlot,
319             size: layout.size.bytes() as u32,
320             offset: None,
321         });
322
323         let TyLayout { ty, details } = layout;
324         let ty::layout::LayoutDetails { size, align, abi: _, variants: _, fields: _ } = details;
325         fx.add_entity_comment(stack_slot, format!(
326             "{:?}: {:?} size={} align={},{}",
327             local, ty, size.bytes(), align.abi.bytes(), align.pref.bytes(),
328         ));
329
330         CPlace::from_stack_slot(fx, stack_slot, layout.ty)
331     };
332
333     debug_assert!(fx.local_map.insert(local, place).is_none());
334     fx.local_map[&local]
335 }
336
337 fn cvalue_for_param<'a, 'tcx: 'a>(
338     fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
339     start_ebb: Ebb,
340     local: mir::Local,
341     local_field: Option<usize>,
342     arg_ty: Ty<'tcx>,
343     ssa_flags: crate::analyze::Flags,
344 ) -> CValue<'tcx> {
345     let layout = fx.layout_of(arg_ty);
346     let pass_mode = get_pass_mode(fx.tcx, fx.self_sig().abi, arg_ty, false);
347     let clif_type = pass_mode.get_param_ty(fx);
348     let ebb_param = fx.bcx.append_ebb_param(start_ebb, clif_type);
349     add_arg_comment(fx, "arg", local, local_field, Some(ebb_param), pass_mode, ssa_flags, arg_ty);
350     match pass_mode {
351         PassMode::NoPass => unimplemented!("pass mode nopass"),
352         PassMode::ByVal(_) => CValue::ByVal(ebb_param, layout),
353         PassMode::ByRef => CValue::ByRef(ebb_param, layout),
354     }
355 }
356
357 pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
358     fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
359     start_ebb: Ebb,
360 ) {
361     let ssa_analyzed = crate::analyze::analyze(fx);
362     fx.add_global_comment(format!("ssa {:?}", ssa_analyzed));
363
364     let ret_layout = fx.layout_of(fx.return_type());
365     let output_pass_mode = get_pass_mode(fx.tcx, fx.self_sig().abi, fx.return_type(), true);
366     let ret_param = match output_pass_mode {
367         PassMode::NoPass => None,
368         PassMode::ByVal(_) => None,
369         PassMode::ByRef => Some(fx.bcx.append_ebb_param(start_ebb, fx.pointer_type)),
370     };
371
372     add_local_header_comment(fx);
373     add_arg_comment(fx, "ret", RETURN_PLACE, None, ret_param, output_pass_mode, ssa_analyzed[&RETURN_PLACE], ret_layout.ty);
374
375     enum ArgKind<'tcx> {
376         Normal(CValue<'tcx>),
377         Spread(Vec<CValue<'tcx>>),
378     }
379
380     let func_params = fx
381         .mir
382         .args_iter()
383         .map(|local| {
384             let arg_ty = fx.monomorphize(&fx.mir.local_decls[local].ty);
385
386             // Adapted from https://github.com/rust-lang/rust/blob/145155dc96757002c7b2e9de8489416e2fdbbd57/src/librustc_codegen_llvm/mir/mod.rs#L442-L482
387             if Some(local) == fx.mir.spread_arg {
388                 // This argument (e.g. the last argument in the "rust-call" ABI)
389                 // is a tuple that was spread at the ABI level and now we have
390                 // to reconstruct it into a tuple local variable, from multiple
391                 // individual function arguments.
392
393                 let tupled_arg_tys = match arg_ty.sty {
394                     ty::Tuple(ref tys) => tys,
395                     _ => bug!("spread argument isn't a tuple?! but {:?}", arg_ty),
396                 };
397
398                 let mut params = Vec::new();
399                 for (i, arg_ty) in tupled_arg_tys.iter().enumerate() {
400                     let param = cvalue_for_param(fx, start_ebb, local, Some(i), arg_ty, ssa_analyzed[&local]);
401                     params.push(param);
402                 }
403
404                 (local, ArgKind::Spread(params), arg_ty)
405             } else {
406                 let param = cvalue_for_param(fx, start_ebb, local, None, arg_ty, ssa_analyzed[&local]);
407                 (
408                     local,
409                     ArgKind::Normal(param),
410                     arg_ty,
411                 )
412             }
413         })
414         .collect::<Vec<(Local, ArgKind, Ty)>>();
415
416     fx.bcx.switch_to_block(start_ebb);
417
418     match output_pass_mode {
419         PassMode::NoPass => {
420             let null = fx.bcx.ins().iconst(fx.pointer_type, 0);
421             fx.local_map.insert(
422                 RETURN_PLACE,
423                 CPlace::Addr(null, None, fx.layout_of(fx.return_type())),
424             );
425         }
426         PassMode::ByVal(ret_ty) => {
427             fx.bcx.declare_var(mir_var(RETURN_PLACE), ret_ty);
428             fx.local_map
429                 .insert(RETURN_PLACE, CPlace::Var(RETURN_PLACE, ret_layout));
430         }
431         PassMode::ByRef => {
432             fx.local_map.insert(
433                 RETURN_PLACE,
434                 CPlace::Addr(ret_param.unwrap(), None, ret_layout),
435             );
436         }
437     }
438
439     for (local, arg_kind, ty) in func_params {
440         let layout = fx.layout_of(ty);
441
442         let is_ssa = !ssa_analyzed
443             .get(&local)
444             .unwrap()
445             .contains(crate::analyze::Flags::NOT_SSA);
446
447         let place = local_place(fx, local, layout, is_ssa);
448
449         match arg_kind {
450             ArgKind::Normal(param) => {
451                 place.write_cvalue(fx, param);
452             }
453             ArgKind::Spread(params) => {
454                 for (i, param) in params.into_iter().enumerate() {
455                     place.place_field(fx, mir::Field::new(i)).write_cvalue(fx, param);
456                 }
457             }
458         }
459     }
460
461     for local in fx.mir.vars_and_temps_iter() {
462         let ty = fx.mir.local_decls[local].ty;
463         let layout = fx.layout_of(ty);
464
465         let is_ssa = !ssa_analyzed
466             .get(&local)
467             .unwrap()
468             .contains(crate::analyze::Flags::NOT_SSA);
469
470         local_place(fx, local, layout, is_ssa);
471     }
472
473     fx.bcx
474         .ins()
475         .jump(*fx.ebb_map.get(&START_BLOCK).unwrap(), &[]);
476 }
477
478 pub fn codegen_terminator_call<'a, 'tcx: 'a>(
479     fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
480     func: &Operand<'tcx>,
481     args: &[Operand<'tcx>],
482     destination: &Option<(Place<'tcx>, BasicBlock)>,
483 ) {
484     let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.tcx));
485     let sig = ty_fn_sig(fx.tcx, fn_ty);
486
487     // Unpack arguments tuple for closures
488     let args = if sig.abi == Abi::RustCall {
489         assert_eq!(args.len(), 2, "rust-call abi requires two arguments");
490         let self_arg = trans_operand(fx, &args[0]);
491         let pack_arg = trans_operand(fx, &args[1]);
492         let mut args = Vec::new();
493         args.push(self_arg);
494         match pack_arg.layout().ty.sty {
495             ty::Tuple(ref tupled_arguments) => {
496                 for (i, _) in tupled_arguments.iter().enumerate() {
497                     args.push(pack_arg.value_field(fx, mir::Field::new(i)));
498                 }
499             }
500             _ => bug!("argument to function with \"rust-call\" ABI is not a tuple"),
501         }
502         args
503     } else {
504         args.into_iter()
505             .map(|arg| trans_operand(fx, arg))
506             .collect::<Vec<_>>()
507     };
508
509     let destination = destination
510         .as_ref()
511         .map(|&(ref place, bb)| (trans_place(fx, place), bb));
512
513     if let ty::FnDef(def_id, substs) = fn_ty.sty {
514         let instance = ty::Instance::resolve(
515             fx.tcx,
516             ty::ParamEnv::reveal_all(),
517             def_id,
518             substs,
519         ).unwrap();
520
521         match instance.def {
522             InstanceDef::Intrinsic(_) => {
523                 crate::intrinsics::codegen_intrinsic_call(fx, def_id, substs, args, destination);
524                 return;
525             }
526             InstanceDef::DropGlue(_, None) => {
527                 // empty drop glue - a nop.
528                 let (_, dest) = destination.expect("Non terminating drop_in_place_real???");
529                 let ret_ebb = fx.get_ebb(dest);
530                 fx.bcx.ins().jump(ret_ebb, &[]);
531                 return;
532             }
533             _ => {}
534         }
535     }
536
537     codegen_call_inner(
538         fx,
539         Some(func),
540         fn_ty,
541         args,
542         destination.map(|(place, _)| place),
543     );
544
545     if let Some((_, dest)) = destination {
546         let ret_ebb = fx.get_ebb(dest);
547         fx.bcx.ins().jump(ret_ebb, &[]);
548     } else {
549         trap_unreachable(&mut fx.bcx);
550     }
551 }
552
553 pub fn codegen_call_inner<'a, 'tcx: 'a>(
554     fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
555     func: Option<&Operand<'tcx>>,
556     fn_ty: Ty<'tcx>,
557     args: Vec<CValue<'tcx>>,
558     ret_place: Option<CPlace<'tcx>>,
559 ) {
560     let sig = ty_fn_sig(fx.tcx, fn_ty);
561
562     let ret_layout = fx.layout_of(sig.output());
563
564     let output_pass_mode = get_pass_mode(fx.tcx, sig.abi, sig.output(), true);
565     let return_ptr = match output_pass_mode {
566         PassMode::NoPass => None,
567         PassMode::ByRef => match ret_place {
568             Some(ret_place) => Some(ret_place.expect_addr()),
569             None => Some(fx.bcx.ins().iconst(fx.pointer_type, 0)),
570         },
571         PassMode::ByVal(_) => None,
572     };
573
574     let instance = match fn_ty.sty {
575         ty::FnDef(def_id, substs) => {
576             Some(Instance::resolve(fx.tcx, ParamEnv::reveal_all(), def_id, substs).unwrap())
577         }
578         _ => None,
579     };
580
581     let func_ref: Option<Value>; // Indirect call target
582
583     let first_arg = {
584         if let Some(Instance {
585             def: InstanceDef::Virtual(_, idx),
586             ..
587         }) = instance
588         {
589             let (ptr, method) = crate::vtable::get_ptr_and_method_ref(fx, args[0], idx);
590             func_ref = Some(method);
591             Some(ptr)
592         } else {
593             func_ref = if instance.is_none() {
594                 let func = trans_operand(fx, func.expect("indirect call without func Operand"));
595                 Some(func.load_value(fx))
596             } else {
597                 None
598             };
599
600             args.get(0).map(|arg| adjust_arg_for_abi(fx, sig, *arg))
601         }
602         .into_iter()
603     };
604
605     let call_args: Vec<Value> = return_ptr
606         .into_iter()
607         .chain(first_arg)
608         .chain(
609             args.into_iter()
610                 .skip(1)
611                 .map(|arg| adjust_arg_for_abi(fx, sig, arg)),
612         )
613         .collect::<Vec<_>>();
614
615     let sig = fx.bcx.import_signature(clif_sig_from_fn_ty(fx.tcx, fn_ty));
616     let call_inst = if let Some(func_ref) = func_ref {
617         fx.bcx.ins().call_indirect(sig, func_ref, &call_args)
618     } else {
619         let func_ref = fx.get_function_ref(instance.expect("non-indirect call on non-FnDef type"));
620         fx.bcx.ins().call(func_ref, &call_args)
621     };
622
623     match output_pass_mode {
624         PassMode::NoPass => {}
625         PassMode::ByVal(_) => {
626             if let Some(ret_place) = ret_place {
627                 let results = fx.bcx.inst_results(call_inst);
628                 ret_place.write_cvalue(fx, CValue::ByVal(results[0], ret_layout));
629             }
630         }
631         PassMode::ByRef => {}
632     }
633 }
634
635 pub fn codegen_return(fx: &mut FunctionCx<impl Backend>) {
636     match get_pass_mode(fx.tcx, fx.self_sig().abi, fx.return_type(), true) {
637         PassMode::NoPass | PassMode::ByRef => {
638             fx.bcx.ins().return_(&[]);
639         }
640         PassMode::ByVal(_) => {
641             let place = fx.get_local_place(RETURN_PLACE);
642             let ret_val = place.to_cvalue(fx).load_value(fx);
643             fx.bcx.ins().return_(&[ret_val]);
644         }
645     }
646 }