diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 31e667095fa..416ed3ebe49 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -75,6 +75,7 @@ pub fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> t fn clif_sig_from_fn_sig<'tcx>( tcx: TyCtxt<'tcx>, + triple: &target_lexicon::Triple, sig: FnSig<'tcx>, is_vtable_fn: bool, ) -> Signature { @@ -89,8 +90,8 @@ fn clif_sig_from_fn_sig<'tcx>( abi => abi, }; let (call_conv, inputs, output): (CallConv, Vec, Ty) = match abi { - Abi::Rust => (crate::default_call_conv(tcx.sess), sig.inputs().to_vec(), sig.output()), - Abi::C => (crate::default_call_conv(tcx.sess), sig.inputs().to_vec(), sig.output()), + Abi::Rust => (CallConv::triple_default(triple), sig.inputs().to_vec(), sig.output()), + Abi::C => (CallConv::triple_default(triple), sig.inputs().to_vec(), sig.output()), Abi::RustCall => { assert_eq!(sig.inputs().len(), 2); let extra_args = match sig.inputs().last().unwrap().kind { @@ -99,10 +100,10 @@ fn clif_sig_from_fn_sig<'tcx>( }; let mut inputs: Vec = vec![sig.inputs()[0]]; inputs.extend(extra_args.types()); - (crate::default_call_conv(tcx.sess), inputs, sig.output()) + (CallConv::triple_default(triple), inputs, sig.output()) } Abi::System => unreachable!(), - Abi::RustIntrinsic => (crate::default_call_conv(tcx.sess), sig.inputs().to_vec(), sig.output()), + Abi::RustIntrinsic => (CallConv::triple_default(triple), sig.inputs().to_vec(), sig.output()), _ => unimplemented!("unsupported abi {:?}", sig.abi), }; @@ -156,6 +157,7 @@ fn clif_sig_from_fn_sig<'tcx>( pub fn get_function_name_and_sig<'tcx>( tcx: TyCtxt<'tcx>, + triple: &target_lexicon::Triple, inst: Instance<'tcx>, support_vararg: bool, ) -> (String, Signature) { @@ -165,7 +167,7 @@ pub fn get_function_name_and_sig<'tcx>( if fn_sig.c_variadic && !support_vararg { unimpl!("Variadic function definitions are not yet supported"); } - let sig = clif_sig_from_fn_sig(tcx, fn_sig, false); + let sig = clif_sig_from_fn_sig(tcx, triple, fn_sig, false); (tcx.symbol_name(inst).name.as_str().to_string(), sig) } @@ -175,7 +177,7 @@ pub fn import_function<'tcx>( module: &mut Module, inst: Instance<'tcx>, ) -> FuncId { - let (name, sig) = get_function_name_and_sig(tcx, inst, true); + let (name, sig) = get_function_name_and_sig(tcx, module.isa().triple(), inst, true); module .declare_function(&name, Linkage::Import, &sig) .unwrap() @@ -205,7 +207,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> { let sig = Signature { params: input_tys.iter().cloned().map(AbiParam::new).collect(), returns: output_tys.iter().cloned().map(AbiParam::new).collect(), - call_conv: crate::default_call_conv(self.tcx.sess), + call_conv: CallConv::triple_default(self.triple()), }; let func_id = self .module @@ -579,8 +581,8 @@ fn codegen_call_inner<'tcx>( let call_inst = if let Some(func_ref) = func_ref { let sig = - fx.bcx - .import_signature(clif_sig_from_fn_sig(fx.tcx, fn_sig, is_virtual_call)); + clif_sig_from_fn_sig(fx.tcx, fx.triple(), fn_sig, is_virtual_call); + let sig = fx.bcx.import_signature(sig); fx.bcx.ins().call_indirect(sig, func_ref, &call_args) } else { let func_ref = @@ -632,9 +634,8 @@ pub fn codegen_drop<'tcx>(fx: &mut FunctionCx<'_, 'tcx, impl Backend>, drop_plac assert_eq!(fn_sig.output(), fx.tcx.mk_unit()); - let sig = fx - .bcx - .import_signature(clif_sig_from_fn_sig(fx.tcx, fn_sig, true)); + let sig = clif_sig_from_fn_sig(fx.tcx, fx.triple(), fn_sig, true); + let sig = fx.bcx.import_signature(sig); fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]); } _ => { diff --git a/src/allocator.rs b/src/allocator.rs index 8031367b23b..df0f5d15434 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -55,7 +55,7 @@ pub fn codegen_inner(sess: &Session, module: &mut Module }; let sig = Signature { - call_conv: crate::default_call_conv(sess), + call_conv: CallConv::triple_default(module.isa().triple()), params: arg_tys.iter().cloned().map(AbiParam::new).collect(), returns: output.into_iter().map(AbiParam::new).collect(), }; diff --git a/src/base.rs b/src/base.rs index 243852f1d2b..16a90becd62 100644 --- a/src/base.rs +++ b/src/base.rs @@ -12,7 +12,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( let mir = *tcx.instance_mir(instance.def); // Declare function - let (name, sig) = get_function_name_and_sig(tcx, instance, false); + let (name, sig) = get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false); let func_id = cx.module.declare_function(&name, linkage, &sig).unwrap(); let mut debug_context = cx .debug_context diff --git a/src/common.rs b/src/common.rs index f3b7fc925ee..455bc99ff22 100644 --- a/src/common.rs +++ b/src/common.rs @@ -364,4 +364,8 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> { )); crate::constant::trans_const_value(self, const_loc) } + + pub fn triple(&self) -> &target_lexicon::Triple { + self.module.isa().triple() + } } diff --git a/src/driver.rs b/src/driver.rs index 0166f9ea5ba..0a5916a552f 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -54,7 +54,7 @@ fn run_jit(tcx: TyCtxt<'_>) -> ! { returns: vec![AbiParam::new( jit_module.target_config().pointer_type(), /*isize*/ )], - call_conv: crate::default_call_conv(tcx.sess), + call_conv: CallConv::triple_default(&crate::target_triple(tcx.sess)), }; let main_func_id = jit_module .declare_function("main", Linkage::Import, &sig) @@ -298,7 +298,8 @@ fn codegen_mono_items<'tcx>( for (&mono_item, &(linkage, visibility)) in &mono_items { match mono_item { MonoItem::Fn(instance) => { - let (name, sig) = get_function_name_and_sig(tcx, instance, false); + let (name, sig) = + get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false); let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility); cx.module.declare_function(&name, linkage, &sig).unwrap(); } diff --git a/src/intrinsics.rs b/src/intrinsics.rs index 840b4bf0db2..e609abee1e8 100644 --- a/src/intrinsics.rs +++ b/src/intrinsics.rs @@ -1085,7 +1085,7 @@ pub fn codegen_intrinsic_call<'tcx>( try, (v f, v data, v _local_ptr) { // FIXME once unwinding is supported, change this to actually catch panics let f_sig = fx.bcx.func.import_signature(Signature { - call_conv: crate::default_call_conv(fx.tcx.sess), + call_conv: CallConv::triple_default(fx.triple()), params: vec![AbiParam::new(fx.bcx.func.dfg.value_type(data))], returns: vec![], }); diff --git a/src/lib.rs b/src/lib.rs index cc8216f0efa..5b1b9239687 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -245,10 +245,6 @@ fn target_triple(sess: &Session) -> target_lexicon::Triple { sess.target.target.llvm_target.parse().unwrap() } -fn default_call_conv(sess: &Session) -> CallConv { - CallConv::triple_default(&target_triple(sess)) -} - fn build_isa(sess: &Session, enable_pic: bool) -> Box { let mut flags_builder = settings::builder(); if enable_pic { diff --git a/src/main_shim.rs b/src/main_shim.rs index 17783b01d26..8577845037d 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -41,7 +41,7 @@ pub fn maybe_create_entry_wrapper(tcx: TyCtxt<'_>, module: &mut Module, module: &mut Module, ms "puts", Linkage::Import, &Signature { - call_conv: crate::default_call_conv(fx.tcx.sess), + call_conv: CallConv::triple_default(fx.triple()), params: vec![AbiParam::new(pointer_ty(fx.tcx))], returns: vec![], },