1
Fork 0

Rollup merge of #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.
This commit is contained in:
kennytm 2018-09-12 12:17:22 +08:00 committed by GitHub
commit 6b55f04725
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 6 deletions

View file

@ -16,6 +16,7 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::session::Session; use rustc::session::Session;
use rustc::session::config::Sanitizer; use rustc::session::config::Sanitizer;
use rustc::ty::TyCtxt; use rustc::ty::TyCtxt;
use rustc::ty::layout::HasTyCtxt;
use rustc::ty::query::Providers; use rustc::ty::query::Providers;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
@ -32,12 +33,16 @@ use value::Value;
/// Mark LLVM function to use provided inline heuristic. /// Mark LLVM function to use provided inline heuristic.
#[inline] #[inline]
pub fn inline(val: &'ll Value, inline: InlineAttr) { pub fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr) {
use self::InlineAttr::*; use self::InlineAttr::*;
match inline { match inline {
Hint => Attribute::InlineHint.apply_llfn(Function, val), Hint => Attribute::InlineHint.apply_llfn(Function, val),
Always => Attribute::AlwaysInline.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 => { None => {
Attribute::InlineHint.unapply_llfn(Function, val); Attribute::InlineHint.unapply_llfn(Function, val);
Attribute::AlwaysInline.unapply_llfn(Function, val); Attribute::AlwaysInline.unapply_llfn(Function, val);
@ -143,7 +148,7 @@ pub fn from_fn_attrs(
let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id)) let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id))
.unwrap_or(CodegenFnAttrs::new()); .unwrap_or(CodegenFnAttrs::new());
inline(llfn, codegen_fn_attrs.inline); inline(cx, llfn, codegen_fn_attrs.inline);
// The `uwtable` attribute according to LLVM is: // The `uwtable` attribute according to LLVM is:
// //

View file

@ -496,6 +496,14 @@ impl Builder<'a, 'll, 'tcx> {
pub fn range_metadata(&self, load: &'ll Value, range: Range<u128>) { pub fn range_metadata(&self, load: &'ll Value, range: Range<u128>) {
if self.sess().target.target.arch == "amdgpu" {
// amdgpu/LLVM does something weird and thinks a i64 value is
// split into a v2i32, halving the bitwidth LLVM expects,
// tripping an assertion. So, for now, just disable this
// optimization.
return;
}
unsafe { unsafe {
let llty = val_ty(load); let llty = val_ty(load);
let v = [ let v = [

View file

@ -96,7 +96,7 @@ pub fn get_fn(
debug!("get_fn: not casting pointer!"); debug!("get_fn: not casting pointer!");
if instance.def.is_inline(tcx) { 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())); attributes::from_fn_attrs(cx, llfn, Some(instance.def.def_id()));

View file

@ -180,7 +180,7 @@ fn predefine_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
debug!("predefine_fn: mono_ty = {:?} instance = {:?}", mono_ty, instance); debug!("predefine_fn: mono_ty = {:?} instance = {:?}", mono_ty, instance);
if instance.def.is_inline(cx.tcx) { 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())); attributes::from_fn_attrs(cx, lldecl, Some(instance.def.def_id()));

View file

@ -81,7 +81,7 @@ fn main() {
let is_crossed = target != host; let is_crossed = target != host;
let mut optional_components = let mut optional_components =
vec!["x86", "arm", "aarch64", "mips", "powerpc", vec!["x86", "arm", "aarch64", "amdgpu", "mips", "powerpc",
"systemz", "jsbackend", "webassembly", "msp430", "sparc", "nvptx"]; "systemz", "jsbackend", "webassembly", "msp430", "sparc", "nvptx"];
let mut version_cmd = Command::new(&llvm_config); let mut version_cmd = Command::new(&llvm_config);

View file

@ -0,0 +1,42 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use abi::call::{ArgType, FnType, };
use abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods};
fn classify_ret_ty<'a, Ty, C>(_tuncx: C, ret: &mut ArgType<'a, Ty>)
where Ty: TyLayoutMethods<'a, C> + Copy,
C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
{
ret.extend_integer_width_to(32);
}
fn classify_arg_ty<'a, Ty, C>(_cx: C, arg: &mut ArgType<'a, Ty>)
where Ty: TyLayoutMethods<'a, C> + Copy,
C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
{
arg.extend_integer_width_to(32);
}
pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>)
where Ty: TyLayoutMethods<'a, C> + Copy,
C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
{
if !fty.ret.is_ignore() {
classify_ret_ty(cx, &mut fty.ret);
}
for arg in &mut fty.args {
if arg.is_ignore() {
continue;
}
classify_arg_ty(cx, arg);
}
}

View file

@ -13,6 +13,7 @@ use abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods};
use spec::HasTargetSpec; use spec::HasTargetSpec;
mod aarch64; mod aarch64;
mod amdgpu;
mod arm; mod arm;
mod asmjs; mod asmjs;
mod hexagon; mod hexagon;
@ -503,6 +504,7 @@ impl<'a, Ty> FnType<'a, Ty> {
x86_64::compute_abi_info(cx, self); x86_64::compute_abi_info(cx, self);
}, },
"aarch64" => aarch64::compute_abi_info(cx, self), "aarch64" => aarch64::compute_abi_info(cx, self),
"amdgpu" => amdgpu::compute_abi_info(cx, self),
"arm" => arm::compute_abi_info(cx, self), "arm" => arm::compute_abi_info(cx, self),
"mips" => mips::compute_abi_info(cx, self), "mips" => mips::compute_abi_info(cx, self),
"mips64" => mips64::compute_abi_info(cx, self), "mips64" => mips64::compute_abi_info(cx, self),