Skip to content
Permalink
Browse files

rustc_codegen_llvm: take an Instance in attributes::from_fn_attrs.

  • Loading branch information
eddyb committed Nov 27, 2019
1 parent 8a8749b commit cd3c324b0714ed744220da1419d91a6d9efefc04
@@ -2,11 +2,11 @@

use std::ffi::CString;

use rustc::hir::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc::hir::CodegenFnAttrFlags;
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::session::Session;
use rustc::session::config::{Sanitizer, OptLevel};
use rustc::ty::TyCtxt;
use rustc::ty::{self, TyCtxt};
use rustc::ty::layout::HasTyCtxt;
use rustc::ty::query::Providers;
use rustc_data_structures::small_c_str::SmallCStr;
@@ -202,11 +202,9 @@ pub(crate) fn default_optimisation_attrs(sess: &Session, llfn: &'ll Value) {
pub fn from_fn_attrs(
cx: &CodegenCx<'ll, 'tcx>,
llfn: &'ll Value,
id: Option<DefId>,
abi: Abi,
instance: ty::Instance<'tcx>,
) {
let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id))
.unwrap_or_else(|| CodegenFnAttrs::new());
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());

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

// FIXME(eddyb) consolidate these two `inline` calls (and avoid overwrites).
if instance.def.is_inline(cx.tcx) {
inline(cx, llfn, attributes::InlineAttr::Hint);
}

inline(cx, llfn, codegen_fn_attrs.inline);

// The `uwtable` attribute according to LLVM is:
@@ -276,6 +279,9 @@ pub fn from_fn_attrs(
// Special attribute for allocator functions, which can't unwind.
false
} else {
// FIXME(eddyb) avoid this `Instance::fn_sig` call.
// Perhaps store the relevant information in `FnAbi`?
let abi = instance.fn_sig(cx.tcx()).abi();
if abi == Abi::Rust || abi == Abi::RustCall {
// Any Rust method (or `extern "Rust" fn` or `extern
// "rust-call" fn`) is explicitly allowed to unwind
@@ -330,16 +336,14 @@ pub fn from_fn_attrs(
// Note that currently the `wasm-import-module` doesn't do anything, but
// eventually LLVM 7 should read this and ferry the appropriate import
// module to the output file.
if let Some(id) = id {
if cx.tcx.sess.target.target.arch == "wasm32" {
if let Some(module) = wasm_import_module(cx.tcx, id) {
llvm::AddFunctionAttrStringValue(
llfn,
llvm::AttributePlace::Function,
const_cstr!("wasm-import-module"),
&module,
);
}
if cx.tcx.sess.target.target.arch == "wasm32" {
if let Some(module) = wasm_import_module(cx.tcx, instance.def_id()) {
llvm::AddFunctionAttrStringValue(
llfn,
llvm::AttributePlace::Function,
const_cstr!("wasm-import-module"),
&module,
);
}
}
}
@@ -80,13 +80,7 @@ pub fn get_fn(
let llfn = cx.declare_fn(&sym, &fn_abi);
debug!("get_fn: not casting pointer!");

if instance.def.is_inline(tcx) {
attributes::inline(cx, llfn, attributes::InlineAttr::Hint);
}
// FIXME(eddyb) avoid this `Instance::fn_sig` call.
// Perhaps store the relevant information in `FnAbi`?
let sig_abi = instance.fn_sig(cx.tcx()).abi();
attributes::from_fn_attrs(cx, llfn, Some(instance.def.def_id()), sig_abi);
attributes::from_fn_attrs(cx, llfn, instance);

let instance_def_id = instance.def_id();

@@ -7,7 +7,7 @@ use crate::type_of::LayoutLlvmExt;
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::mir::mono::{Linkage, Visibility};
use rustc::ty::{TypeFoldable, Instance};
use rustc::ty::layout::{FnAbiExt, LayoutOf, HasTyCtxt};
use rustc::ty::layout::{FnAbiExt, LayoutOf};
use rustc_codegen_ssa::traits::*;

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

debug!("predefine_fn: instance = {:?}", instance);
if instance.def.is_inline(self.tcx) {
attributes::inline(self, lldecl, attributes::InlineAttr::Hint);
}
// FIXME(eddyb) avoid this `Instance::fn_sig` call.
// Perhaps store the relevant information in `FnAbi`?
let mono_sig_abi = instance.fn_sig(self.tcx()).abi();
attributes::from_fn_attrs(
self,
lldecl,
Some(instance.def.def_id()),
mono_sig_abi,
);

attributes::from_fn_attrs(self, lldecl, instance);

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

0 comments on commit cd3c324

Please sign in to comment.
You can’t perform that action at this time.