Skip to content

Commit 19c4544

Browse files
AmdGcn intrinsics which return values in the constant address space.
This is separate because these intrinsics need to be used in the Geobacter patch and also "fixed" after the proper address spaces patch.
1 parent 1b521f5 commit 19c4544

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/librustc_codegen_llvm/intrinsic.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::type_of::LayoutLlvmExt;
88
use crate::va_arg::emit_va_arg;
99
use crate::value::Value;
1010

11+
use libc::c_char;
12+
1113
use rustc_ast::ast;
1214
use rustc_codegen_ssa::base::{compare_simd_types, to_immediate, wants_msvc_seh};
1315
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
@@ -25,6 +27,7 @@ use rustc_span::Span;
2527
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Primitive};
2628

2729
use std::cmp::Ordering;
30+
use std::ffi::CStr;
2831
use std::{i128, iter, u128};
2932

3033
fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: &str) -> Option<&'ll Value> {
@@ -78,6 +81,9 @@ fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: &str) -> Option<&'ll Valu
7881
Some(cx.get_intrinsic(&llvm_name))
7982
}
8083

84+
const EMPTY_C_STR: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"\0") };
85+
const UNNAMED: *const c_char = EMPTY_C_STR.as_ptr();
86+
8187
impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
8288
fn codegen_intrinsic_call(
8389
&mut self,
@@ -747,6 +753,26 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
747753
// this is where the signed magic happens (notice the `s` in `exactsdiv`)
748754
self.exactsdiv(d, pointee_size)
749755
}
756+
"amdgcn_dispatch_ptr" => {
757+
// This intrinsic returns a pointer in the const addr space
758+
// which can't be encoded in source level Rust.
759+
760+
let f = self.cx().get_intrinsic("llvm.amdgcn.dispatch.ptr");
761+
let val = self.call(f, &[], None);
762+
// XXX Needs the proper address space patch
763+
unsafe { llvm::LLVMBuildAddrSpaceCast(self.llbuilder, val,
764+
llret_ty, UNNAMED) }
765+
}
766+
"amdgcn_queue_ptr" => {
767+
// This intrinsic returns a pointer in the const addr space
768+
// which can't be encoded in source level Rust.
769+
770+
let f = self.cx().get_intrinsic("llvm.amdgcn.queue.ptr");
771+
let val = self.call(f, &[], None);
772+
// XXX Needs the proper address space patch
773+
unsafe { llvm::LLVMBuildAddrSpaceCast(self.llbuilder, val,
774+
llret_ty, UNNAMED) }
775+
}
750776

751777
_ => bug!("unknown intrinsic '{}'", name),
752778
};

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,12 @@ extern "C" {
13231323
DestTy: &'a Type,
13241324
Name: *const c_char,
13251325
) -> &'a Value;
1326+
pub fn LLVMBuildAddrSpaceCast(
1327+
B: &Builder<'a>,
1328+
Val: &'a Value,
1329+
DestTy: &'a Type,
1330+
Name: *const c_char,
1331+
) -> &'a Value;
13261332
pub fn LLVMRustBuildIntCast(
13271333
B: &Builder<'a>,
13281334
Val: &'a Value,

src/librustc_typeck/check/intrinsic.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
338338
// so it's not trivial to check this
339339
return;
340340
}
341+
"amdgcn_dispatch_ptr" => {
342+
(0, vec![], tcx.mk_imm_ptr(tcx.types.u8))
343+
}
344+
"amdgcn_queue_ptr" => {
345+
(0, vec![], tcx.mk_imm_ptr(tcx.types.u8))
346+
}
341347

342348
ref other => {
343349
struct_span_err!(

0 commit comments

Comments
 (0)