Skip to content

Commit

Permalink
AMDGPU ignores noinline when it slaps alwaysinline everywhere.
Browse files Browse the repository at this point in the history
Allow target specs to disable that attribute.
  • Loading branch information
DiamondLovesYou committed Aug 23, 2018
1 parent 1c0603e commit bfddede
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/librustc_codegen_llvm/attributes.rs
Expand Up @@ -16,6 +16,7 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::session::Session;
use rustc::session::config::Sanitizer;
use rustc::ty::TyCtxt;
use rustc::ty::layout::HasTyCtxt;
use rustc::ty::query::Providers;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::fx::FxHashMap;
Expand All @@ -32,12 +33,16 @@ use value::Value;

/// Mark LLVM function to use provided inline heuristic.
#[inline]
pub fn inline(val: &'ll Value, inline: InlineAttr) {
pub fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr) {
use self::InlineAttr::*;
match inline {
Hint => Attribute::InlineHint.apply_llfn(Function, val),
Always => Attribute::AlwaysInline.apply_llfn(Function, val),
Never => Attribute::NoInline.apply_llfn(Function, val),
Never => {
if cx.tcx().sess.target.target.arch != "amdgpu" {
Attribute::NoInline.apply_llfn(Function, val);
}
},
None => {
Attribute::InlineHint.unapply_llfn(Function, val);
Attribute::AlwaysInline.unapply_llfn(Function, val);
Expand Down Expand Up @@ -142,7 +147,7 @@ pub fn from_fn_attrs(
let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id))
.unwrap_or(CodegenFnAttrs::new());

inline(llfn, codegen_fn_attrs.inline);
inline(cx, llfn, codegen_fn_attrs.inline);

// The `uwtable` attribute according to LLVM is:
//
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/callee.rs
Expand Up @@ -96,7 +96,7 @@ pub fn get_fn(
debug!("get_fn: not casting pointer!");

if instance.def.is_inline(tcx) {
attributes::inline(llfn, attributes::InlineAttr::Hint);
attributes::inline(cx, llfn, attributes::InlineAttr::Hint);
}
attributes::from_fn_attrs(cx, llfn, Some(instance.def.def_id()));

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/mono_item.rs
Expand Up @@ -180,7 +180,7 @@ fn predefine_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,

debug!("predefine_fn: mono_ty = {:?} instance = {:?}", mono_ty, instance);
if instance.def.is_inline(cx.tcx) {
attributes::inline(lldecl, attributes::InlineAttr::Hint);
attributes::inline(cx, lldecl, attributes::InlineAttr::Hint);
}
attributes::from_fn_attrs(cx, lldecl, Some(instance.def.def_id()));

Expand Down

0 comments on commit bfddede

Please sign in to comment.