Skip to content

Commit b5f38f0

Browse files
committed
rustc_codegen_ssa: use FnAbi::of_instance wherever possible.
1 parent 26b5097 commit b5f38f0

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

src/librustc_codegen_llvm/callee.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::context::CodegenCx;
1111
use crate::value::Value;
1212
use rustc_codegen_ssa::traits::*;
1313

14-
use rustc::ty::{self, TypeFoldable, Instance};
14+
use rustc::ty::{TypeFoldable, Instance};
1515
use rustc::ty::layout::{FnAbiExt, LayoutOf, HasTyCtxt};
1616

1717
/// Codegens a reference to a fn/method item, monomorphizing and
@@ -37,12 +37,12 @@ pub fn get_fn(
3737
return llfn;
3838
}
3939

40-
let sig = instance.fn_sig(cx.tcx());
4140
let sym = tcx.symbol_name(instance).name.as_str();
42-
debug!("get_fn({:?}: {:?}) => {}", instance, sig, sym);
41+
debug!("get_fn({:?}: {:?}) => {}", instance, instance.fn_sig(cx.tcx()), sym);
4342

4443
let llfn = if let Some(llfn) = cx.get_declared_value(&sym) {
4544
// Create a fn pointer with the substituted signature.
45+
let sig = instance.fn_sig(cx.tcx());
4646
let fn_ptr_ty = tcx.mk_fn_ptr(sig);
4747
let llptrty = cx.backend_type(cx.layout_of(fn_ptr_ty));
4848

@@ -77,15 +77,17 @@ pub fn get_fn(
7777
llfn
7878
}
7979
} else {
80-
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
81-
let fn_abi = FnAbi::new(cx, sig, &[]);
80+
let fn_abi = FnAbi::of_instance(cx, instance);
8281
let llfn = cx.declare_fn(&sym, &fn_abi);
8382
debug!("get_fn: not casting pointer!");
8483

8584
if instance.def.is_inline(tcx) {
8685
attributes::inline(cx, llfn, attributes::InlineAttr::Hint);
8786
}
88-
attributes::from_fn_attrs(cx, llfn, Some(instance.def.def_id()), sig.abi);
87+
// FIXME(eddyb) avoid this `Instance::fn_sig` call.
88+
// Perhaps store the relevant information in `FnAbi`?
89+
let sig_abi = instance.fn_sig(cx.tcx()).abi();
90+
attributes::from_fn_attrs(cx, llfn, Some(instance.def.def_id()), sig_abi);
8991

9092
let instance_def_id = instance.def_id();
9193

src/librustc_codegen_llvm/mono_item.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::llvm;
66
use crate::type_of::LayoutLlvmExt;
77
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
88
use rustc::mir::mono::{Linkage, Visibility};
9-
use rustc::ty::{self, TypeFoldable, Instance};
9+
use rustc::ty::{TypeFoldable, Instance};
1010
use rustc::ty::layout::{FnAbiExt, LayoutOf, HasTyCtxt};
1111
use rustc_codegen_ssa::traits::*;
1212

@@ -43,12 +43,7 @@ impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> {
4343
assert!(!instance.substs.needs_infer() &&
4444
!instance.substs.has_param_types());
4545

46-
let mono_sig = instance.fn_sig(self.tcx());
47-
let mono_sig = self.tcx().normalize_erasing_late_bound_regions(
48-
ty::ParamEnv::reveal_all(),
49-
&mono_sig,
50-
);
51-
let fn_abi = FnAbi::new(self, mono_sig, &[]);
46+
let fn_abi = FnAbi::of_instance(self, instance);
5247
let lldecl = self.declare_fn(symbol_name, &fn_abi);
5348
unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) };
5449
let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
@@ -73,15 +68,18 @@ impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> {
7368
}
7469
}
7570

76-
debug!("predefine_fn: mono_sig = {:?} instance = {:?}", mono_sig, instance);
71+
debug!("predefine_fn: instance = {:?}", instance);
7772
if instance.def.is_inline(self.tcx) {
7873
attributes::inline(self, lldecl, attributes::InlineAttr::Hint);
7974
}
75+
// FIXME(eddyb) avoid this `Instance::fn_sig` call.
76+
// Perhaps store the relevant information in `FnAbi`?
77+
let mono_sig_abi = instance.fn_sig(self.tcx()).abi();
8078
attributes::from_fn_attrs(
8179
self,
8280
lldecl,
8381
Some(instance.def.def_id()),
84-
mono_sig.abi,
82+
mono_sig_abi,
8583
);
8684

8785
self.instances.borrow_mut().insert(instance, lldecl);

src/librustc_codegen_ssa/mir/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,16 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
127127

128128
let mir = cx.tcx().instance_mir(instance.def);
129129

130-
let sig = instance.fn_sig(cx.tcx());
131-
let sig = cx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
132-
let fn_abi = FnAbi::new(cx, sig, &[]);
130+
let fn_abi = FnAbi::of_instance(cx, instance);
133131
debug!("fn_abi: {:?}", fn_abi);
134132

135-
let debug_context =
136-
cx.create_function_debug_context(instance, sig, llfn, mir);
133+
let debug_context = {
134+
// FIXME(eddyb) avoid this `Instance::fn_sig` call.
135+
// Perhaps pass `fn_abi` to `create_function_debug_context`?
136+
let sig = instance.fn_sig(cx.tcx());
137+
let sig = cx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
138+
cx.create_function_debug_context(instance, sig, llfn, mir)
139+
};
137140

138141
let mut bx = Bx::new_block(cx, llfn, "start");
139142

0 commit comments

Comments
 (0)