Skip to content

Commit 30edd33

Browse files
committed
rustc_codegen_llvm: take an Instance in attributes::from_fn_attrs.
1 parent 8be241f commit 30edd33

File tree

3 files changed

+24
-36
lines changed

3 files changed

+24
-36
lines changed

src/librustc_codegen_llvm/attributes.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
33
use std::ffi::CString;
44

5-
use rustc::hir::{CodegenFnAttrFlags, CodegenFnAttrs};
5+
use rustc::hir::CodegenFnAttrFlags;
66
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
77
use rustc::session::Session;
88
use rustc::session::config::{Sanitizer, OptLevel};
9-
use rustc::ty::TyCtxt;
9+
use rustc::ty::{self, TyCtxt};
1010
use rustc::ty::layout::HasTyCtxt;
1111
use rustc::ty::query::Providers;
1212
use rustc_data_structures::small_c_str::SmallCStr;
@@ -202,11 +202,9 @@ pub(crate) fn default_optimisation_attrs(sess: &Session, llfn: &'ll Value) {
202202
pub fn from_fn_attrs(
203203
cx: &CodegenCx<'ll, 'tcx>,
204204
llfn: &'ll Value,
205-
id: Option<DefId>,
206-
abi: Abi,
205+
instance: ty::Instance<'tcx>,
207206
) {
208-
let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id))
209-
.unwrap_or_else(|| CodegenFnAttrs::new());
207+
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
210208

211209
match codegen_fn_attrs.optimize {
212210
OptimizeAttr::None => {
@@ -224,6 +222,11 @@ pub fn from_fn_attrs(
224222
}
225223
}
226224

225+
// FIXME(eddyb) consolidate these two `inline` calls (and avoid overwrites).
226+
if instance.def.is_inline(cx.tcx) {
227+
inline(cx, llfn, attributes::InlineAttr::Hint);
228+
}
229+
227230
inline(cx, llfn, codegen_fn_attrs.inline);
228231

229232
// The `uwtable` attribute according to LLVM is:
@@ -276,6 +279,9 @@ pub fn from_fn_attrs(
276279
// Special attribute for allocator functions, which can't unwind.
277280
false
278281
} else {
282+
// FIXME(eddyb) avoid this `Instance::fn_sig` call.
283+
// Perhaps store the relevant information in `FnAbi`?
284+
let abi = instance.fn_sig(cx.tcx()).abi();
279285
if abi == Abi::Rust || abi == Abi::RustCall {
280286
// Any Rust method (or `extern "Rust" fn` or `extern
281287
// "rust-call" fn`) is explicitly allowed to unwind
@@ -330,16 +336,14 @@ pub fn from_fn_attrs(
330336
// Note that currently the `wasm-import-module` doesn't do anything, but
331337
// eventually LLVM 7 should read this and ferry the appropriate import
332338
// module to the output file.
333-
if let Some(id) = id {
334-
if cx.tcx.sess.target.target.arch == "wasm32" {
335-
if let Some(module) = wasm_import_module(cx.tcx, id) {
336-
llvm::AddFunctionAttrStringValue(
337-
llfn,
338-
llvm::AttributePlace::Function,
339-
const_cstr!("wasm-import-module"),
340-
&module,
341-
);
342-
}
339+
if cx.tcx.sess.target.target.arch == "wasm32" {
340+
if let Some(module) = wasm_import_module(cx.tcx, instance.def_id()) {
341+
llvm::AddFunctionAttrStringValue(
342+
llfn,
343+
llvm::AttributePlace::Function,
344+
const_cstr!("wasm-import-module"),
345+
&module,
346+
);
343347
}
344348
}
345349
}

src/librustc_codegen_llvm/callee.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,7 @@ pub fn get_fn(
8080
let llfn = cx.declare_fn(&sym, &fn_abi);
8181
debug!("get_fn: not casting pointer!");
8282

83-
if instance.def.is_inline(tcx) {
84-
attributes::inline(cx, llfn, attributes::InlineAttr::Hint);
85-
}
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);
83+
attributes::from_fn_attrs(cx, llfn, instance);
9084

9185
let instance_def_id = instance.def_id();
9286

src/librustc_codegen_llvm/mono_item.rs

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

1313
pub use rustc::mir::mono::MonoItem;
@@ -69,18 +69,8 @@ impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> {
6969
}
7070

7171
debug!("predefine_fn: instance = {:?}", instance);
72-
if instance.def.is_inline(self.tcx) {
73-
attributes::inline(self, lldecl, attributes::InlineAttr::Hint);
74-
}
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();
78-
attributes::from_fn_attrs(
79-
self,
80-
lldecl,
81-
Some(instance.def.def_id()),
82-
mono_sig_abi,
83-
);
72+
73+
attributes::from_fn_attrs(self, lldecl, instance);
8474

8575
self.instances.borrow_mut().insert(instance, lldecl);
8676
}

0 commit comments

Comments
 (0)