Skip to content

Commit 3170507

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

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-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;
@@ -30,12 +31,16 @@ use context::CodegenCx;
3031

3132
/// Mark LLVM function to use provided inline heuristic.
3233
#[inline]
33-
pub fn inline(val: ValueRef, inline: InlineAttr) {
34+
pub fn inline(cx: &CodegenCx, val: ValueRef, inline: InlineAttr) {
3435
use self::InlineAttr::*;
3536
match inline {
3637
Hint => Attribute::InlineHint.apply_llfn(Function, val),
3738
Always => Attribute::AlwaysInline.apply_llfn(Function, val),
38-
Never => Attribute::NoInline.apply_llfn(Function, val),
39+
Never => {
40+
if !cx.tcx().sess.target.target.options.ignore_inline_never {
41+
Attribute::NoInline.apply_llfn(Function, val);
42+
}
43+
},
3944
None => {
4045
Attribute::InlineHint.unapply_llfn(Function, val);
4146
Attribute::AlwaysInline.unapply_llfn(Function, val);
@@ -126,7 +131,7 @@ pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> {
126131
pub fn from_fn_attrs(cx: &CodegenCx, llfn: ValueRef, id: DefId) {
127132
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(id);
128133

129-
inline(llfn, codegen_fn_attrs.inline);
134+
inline(cx, llfn, codegen_fn_attrs.inline);
130135

131136
set_frame_pointer_elimination(cx, llfn);
132137
set_probestack(cx, llfn);

src/librustc_codegen_llvm/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub fn get_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
9595
debug!("get_fn: not casting pointer!");
9696

9797
if instance.def.is_inline(tcx) {
98-
attributes::inline(llfn, attributes::InlineAttr::Hint);
98+
attributes::inline(cx, llfn, attributes::InlineAttr::Hint);
9999
}
100100
attributes::from_fn_attrs(cx, llfn, instance.def.def_id());
101101

src/librustc_codegen_llvm/mono_item.rs

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

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

src/librustc_target/spec/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,12 @@ pub struct TargetOptions {
635635
/// typically because the platform needs to unwind for things like stack
636636
/// unwinders.
637637
pub requires_uwtable: bool,
638+
639+
/// Targets like AMDGPU add alwaysinline hints everywhere,
640+
/// and basically inline everything regardless of our wishes anyway.
641+
/// This causes LLVM validation errors due to the conflicting attributes.
642+
/// Defaults to false.
643+
pub ignore_inline_never: bool,
638644
}
639645

640646
impl Default for TargetOptions {
@@ -713,6 +719,7 @@ impl Default for TargetOptions {
713719
embed_bitcode: false,
714720
emit_debug_gdb_scripts: true,
715721
requires_uwtable: false,
722+
ignore_inline_never: false,
716723
}
717724
}
718725
}
@@ -972,6 +979,7 @@ impl Target {
972979
key!(embed_bitcode, bool);
973980
key!(emit_debug_gdb_scripts, bool);
974981
key!(requires_uwtable, bool);
982+
key!(ignore_inline_never, bool);
975983

976984
if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
977985
for name in array.iter().filter_map(|abi| abi.as_string()) {
@@ -1181,6 +1189,7 @@ impl ToJson for Target {
11811189
target_option_val!(embed_bitcode);
11821190
target_option_val!(emit_debug_gdb_scripts);
11831191
target_option_val!(requires_uwtable);
1192+
target_option_val!(ignore_inline_never);
11841193

11851194
if default.abi_blacklist != self.options.abi_blacklist {
11861195
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()

0 commit comments

Comments
 (0)