Skip to content

Commit bfddede

Browse files
AMDGPU ignores noinline when it slaps alwaysinline everywhere.
Allow target specs to disable that attribute.
1 parent 1c0603e commit bfddede

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/librustc_codegen_llvm/attributes.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE};
1616
use rustc::session::Session;
1717
use rustc::session::config::Sanitizer;
1818
use rustc::ty::TyCtxt;
19+
use rustc::ty::layout::HasTyCtxt;
1920
use rustc::ty::query::Providers;
2021
use rustc_data_structures::sync::Lrc;
2122
use rustc_data_structures::fx::FxHashMap;
@@ -32,12 +33,16 @@ use value::Value;
3233

3334
/// Mark LLVM function to use provided inline heuristic.
3435
#[inline]
35-
pub fn inline(val: &'ll Value, inline: InlineAttr) {
36+
pub fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr) {
3637
use self::InlineAttr::*;
3738
match inline {
3839
Hint => Attribute::InlineHint.apply_llfn(Function, val),
3940
Always => Attribute::AlwaysInline.apply_llfn(Function, val),
40-
Never => Attribute::NoInline.apply_llfn(Function, val),
41+
Never => {
42+
if cx.tcx().sess.target.target.arch != "amdgpu" {
43+
Attribute::NoInline.apply_llfn(Function, val);
44+
}
45+
},
4146
None => {
4247
Attribute::InlineHint.unapply_llfn(Function, val);
4348
Attribute::AlwaysInline.unapply_llfn(Function, val);
@@ -142,7 +147,7 @@ pub fn from_fn_attrs(
142147
let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id))
143148
.unwrap_or(CodegenFnAttrs::new());
144149

145-
inline(llfn, codegen_fn_attrs.inline);
150+
inline(cx, llfn, codegen_fn_attrs.inline);
146151

147152
// The `uwtable` attribute according to LLVM is:
148153
//

src/librustc_codegen_llvm/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn get_fn(
9696
debug!("get_fn: not casting pointer!");
9797

9898
if instance.def.is_inline(tcx) {
99-
attributes::inline(llfn, attributes::InlineAttr::Hint);
99+
attributes::inline(cx, llfn, attributes::InlineAttr::Hint);
100100
}
101101
attributes::from_fn_attrs(cx, llfn, Some(instance.def.def_id()));
102102

src/librustc_codegen_llvm/mono_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn predefine_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
180180

181181
debug!("predefine_fn: mono_ty = {:?} instance = {:?}", mono_ty, instance);
182182
if instance.def.is_inline(cx.tcx) {
183-
attributes::inline(lldecl, attributes::InlineAttr::Hint);
183+
attributes::inline(cx, lldecl, attributes::InlineAttr::Hint);
184184
}
185185
attributes::from_fn_attrs(cx, lldecl, Some(instance.def.def_id()));
186186

0 commit comments

Comments
 (0)