Skip to content

Commit 6b55f04

Browse files
authored
Rollup merge of rust-lang#52514 - DiamondLovesYou:amdgpu-fixes, r=eddyb
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 5806389 + 66e8e19 commit 6b55f04

File tree

7 files changed

+63
-6
lines changed

7 files changed

+63
-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;
@@ -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);
@@ -143,7 +148,7 @@ pub fn from_fn_attrs(
143148
let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id))
144149
.unwrap_or(CodegenFnAttrs::new());
145150

146-
inline(llfn, codegen_fn_attrs.inline);
151+
inline(cx, llfn, codegen_fn_attrs.inline);
147152

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

src/librustc_codegen_llvm/builder.rs

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

497497

498498
pub fn range_metadata(&self, load: &'ll Value, range: Range<u128>) {
499+
if self.sess().target.target.arch == "amdgpu" {
500+
// amdgpu/LLVM does something weird and thinks a i64 value is
501+
// split into a v2i32, halving the bitwidth LLVM expects,
502+
// tripping an assertion. So, for now, just disable this
503+
// optimization.
504+
return;
505+
}
506+
499507
unsafe {
500508
let llty = val_ty(load);
501509
let v = [

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

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;
@@ -503,6 +504,7 @@ impl<'a, Ty> FnType<'a, Ty> {
503504
x86_64::compute_abi_info(cx, self);
504505
},
505506
"aarch64" => aarch64::compute_abi_info(cx, self),
507+
"amdgpu" => amdgpu::compute_abi_info(cx, self),
506508
"arm" => arm::compute_abi_info(cx, self),
507509
"mips" => mips::compute_abi_info(cx, self),
508510
"mips64" => mips64::compute_abi_info(cx, self),

0 commit comments

Comments
 (0)