Skip to content

Commit 4b68afe

Browse files
committed
rustc_codegen_ssa: use FnAbi::of_instance wherever possible.
1 parent 5b7d0f3 commit 4b68afe

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

src/librustc_codegen_llvm/callee.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
//! and methods are represented as just a fn ptr and not a full
55
//! closure.
66
7-
use crate::abi::FnAbi;
7+
use crate::abi::{FnAbi, FnAbiLlvmExt};
88
use crate::attributes;
99
use crate::llvm;
1010
use crate::context::CodegenCx;
1111
use crate::value::Value;
1212
use rustc_codegen_ssa::traits::*;
1313

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

1717
/// Codegens a reference to a fn/method item, monomorphizing and
1818
/// inlining as it goes.
@@ -37,14 +37,14 @@ 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.ty(cx.tcx()), sym);
42+
43+
let fn_abi = FnAbi::of_instance(cx, instance);
4344

4445
let llfn = if let Some(llfn) = cx.get_declared_value(&sym) {
45-
// Create a fn pointer with the substituted signature.
46-
let fn_ptr_ty = tcx.mk_fn_ptr(sig);
47-
let llptrty = cx.backend_type(cx.layout_of(fn_ptr_ty));
46+
// Create a fn pointer with the new signature.
47+
let llptrty = fn_abi.ptr_to_llvm_type(cx);
4848

4949
// This is subtle and surprising, but sometimes we have to bitcast
5050
// the resulting fn pointer. The reason has to do with external
@@ -77,15 +77,16 @@ 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, &[]);
8280
let llfn = cx.declare_fn(&sym, &fn_abi);
8381
debug!("get_fn: not casting pointer!");
8482

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

9091
let instance_def_id = instance.def_id();
9192

src/librustc_codegen_llvm/debuginfo/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::hir::CodegenFnAttrFlags;
1616
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
1717
use rustc::ty::subst::{SubstsRef, GenericArgKind};
1818

19-
use crate::abi::Abi;
19+
use crate::abi::{Abi, FnAbi};
2020
use crate::common::CodegenCx;
2121
use crate::builder::Builder;
2222
use crate::value::Value;
@@ -280,7 +280,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
280280
fn create_function_debug_context(
281281
&self,
282282
instance: Instance<'tcx>,
283-
sig: ty::FnSig<'tcx>,
283+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
284284
llfn: &'ll Value,
285285
mir: &mir::Body<'_>,
286286
) -> Option<FunctionDebugContext<&'ll DIScope>> {
@@ -308,6 +308,12 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
308308
let file_metadata = file_metadata(self, &loc.file.name, def_id.krate);
309309

310310
let function_type_metadata = unsafe {
311+
// FIXME(eddyb) avoid this `Instance::fn_sig` call, by
312+
// rewriting `get_function_signature` to use `fn_abi` instead.
313+
let sig = self.tcx().normalize_erasing_late_bound_regions(
314+
ty::ParamEnv::reveal_all(),
315+
&instance.fn_sig(self.tcx()),
316+
);
311317
let fn_signature = get_function_signature(self, sig);
312318
llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(self), file_metadata, fn_signature)
313319
};
@@ -338,7 +344,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
338344

339345
let mut flags = DIFlags::FlagPrototyped;
340346

341-
if self.layout_of(sig.output()).abi.is_uninhabited() {
347+
if fn_abi.ret.layout.abi.is_uninhabited() {
342348
flags |= DIFlags::FlagNoReturn;
343349
}
344350

@@ -390,6 +396,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
390396

391397
return Some(fn_debug_context);
392398

399+
// FIXME(eddyb) rewrite this to be based on `FnAbi` instead of `FnSig`.
393400
fn get_function_signature<'ll, 'tcx>(
394401
cx: &CodegenCx<'ll, 'tcx>,
395402
sig: ty::FnSig<'tcx>,

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: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,10 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
129129

130130
let mir = cx.tcx().instance_mir(instance.def);
131131

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

137-
let debug_context =
138-
cx.create_function_debug_context(instance, sig, llfn, &mir);
135+
let debug_context = cx.create_function_debug_context(instance, &fn_abi, llfn, &mir);
139136

140137
let mut bx = Bx::new_block(cx, llfn, "start");
141138

src/librustc_codegen_ssa/traits/debuginfo.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use super::BackendTypes;
22
use crate::mir::debuginfo::{FunctionDebugContext, VariableKind};
33
use rustc::hir::def_id::CrateNum;
44
use rustc::mir;
5-
use rustc::ty::{self, Ty, Instance};
5+
use rustc::ty::{Ty, Instance};
66
use rustc::ty::layout::Size;
7+
use rustc_target::abi::call::FnAbi;
78
use syntax::ast::Name;
89
use syntax_pos::{SourceFile, Span};
910

@@ -17,7 +18,7 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes {
1718
fn create_function_debug_context(
1819
&self,
1920
instance: Instance<'tcx>,
20-
sig: ty::FnSig<'tcx>,
21+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
2122
llfn: Self::Function,
2223
mir: &mir::Body<'_>,
2324
) -> Option<FunctionDebugContext<Self::DIScope>>;

0 commit comments

Comments
 (0)