Skip to content

Commit 2d4e714

Browse files
Rollup merge of rust-lang#52514 - DiamondLovesYou:amdgpu-fixes, r=nagisa
Fix a few AMDGPU related issues * AMDGPU ignores `noinline` and sadly doesn't clear the attribute when it slaps `alwaysinline` on everything, * an AMDGPU related load bit range metadata assertion, * I didn't enable the `amdgpu` component in the `librustc_llvm` build script, * Add AMDGPU call abi info.
2 parents e427459 + d992a94 commit 2d4e714

File tree

8 files changed

+72
-6
lines changed

8 files changed

+72
-6
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/builder.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
565565

566566

567567
pub fn range_metadata(&self, load: ValueRef, range: Range<u128>) {
568+
if self.sess().target.target.arch == "amdgpu" {
569+
// amdgpu/LLVM does something weird and thinks a i64 value is
570+
// split into a v2i32, halving the bitwidth LLVM expects,
571+
// tripping an assertion. So, for now, just disable this
572+
// optimization.
573+
return;
574+
}
575+
568576
unsafe {
569577
let llty = val_ty(load);
570578
let v = [

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_llvm/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn main() {
8181
let is_crossed = target != host;
8282

8383
let mut optional_components =
84-
vec!["x86", "arm", "aarch64", "mips", "powerpc",
84+
vec!["x86", "arm", "aarch64", "amdgpu", "mips", "powerpc",
8585
"systemz", "jsbackend", "webassembly", "msp430", "sparc", "nvptx"];
8686

8787
let mut version_cmd = Command::new(&llvm_config);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use abi::call::{ArgType, FnType, };
12+
use abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods};
13+
14+
fn classify_ret_ty<'a, Ty, C>(_tuncx: C, ret: &mut ArgType<'a, Ty>)
15+
where Ty: TyLayoutMethods<'a, C> + Copy,
16+
C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
17+
{
18+
ret.extend_integer_width_to(32);
19+
}
20+
21+
fn classify_arg_ty<'a, Ty, C>(_cx: C, arg: &mut ArgType<'a, Ty>)
22+
where Ty: TyLayoutMethods<'a, C> + Copy,
23+
C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
24+
{
25+
arg.extend_integer_width_to(32);
26+
}
27+
28+
pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>)
29+
where Ty: TyLayoutMethods<'a, C> + Copy,
30+
C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
31+
{
32+
if !fty.ret.is_ignore() {
33+
classify_ret_ty(cx, &mut fty.ret);
34+
}
35+
36+
for arg in &mut fty.args {
37+
if arg.is_ignore() {
38+
continue;
39+
}
40+
classify_arg_ty(cx, arg);
41+
}
42+
}

src/librustc_target/abi/call/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods};
1313
use spec::HasTargetSpec;
1414

1515
mod aarch64;
16+
mod amdgpu;
1617
mod arm;
1718
mod asmjs;
1819
mod hexagon;
@@ -480,6 +481,7 @@ impl<'a, Ty> FnType<'a, Ty> {
480481
x86_64::compute_abi_info(cx, self);
481482
},
482483
"aarch64" => aarch64::compute_abi_info(cx, self),
484+
"amdgpu" => amdgpu::compute_abi_info(cx, self),
483485
"arm" => arm::compute_abi_info(cx, self),
484486
"mips" => mips::compute_abi_info(cx, self),
485487
"mips64" => mips64::compute_abi_info(cx, self),

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)