Skip to content

Commit 724956f

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 de921ab commit 724956f

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::type_of::LayoutLlvmExt;
77
use crate::va_arg::emit_va_arg;
88
use crate::value::Value;
99

10+
use libc::c_char;
11+
1012
use rustc_ast as ast;
1113
use rustc_codegen_ssa::base::{compare_simd_types, wants_msvc_seh};
1214
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
@@ -25,6 +27,7 @@ use rustc_target::abi::{self, HasDataLayout, LayoutOf, Primitive};
2527
use rustc_target::spec::PanicStrategy;
2628

2729
use std::cmp::Ordering;
30+
use std::ffi::CStr;
2831
use std::iter;
2932

3033
fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: Symbol) -> Option<&'ll Value> {
@@ -78,6 +81,9 @@ fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: Symbol) -> Option<&'ll Va
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,
@@ -757,6 +763,26 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
757763
// this is where the signed magic happens (notice the `s` in `exactsdiv`)
758764
self.exactsdiv(d, pointee_size)
759765
}
766+
sym::amdgcn_dispatch_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.dispatch.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+
}
776+
sym::amdgcn_queue_ptr => {
777+
// This intrinsic returns a pointer in the const addr space
778+
// which can't be encoded in source level Rust.
779+
780+
let f = self.cx().get_intrinsic("llvm.amdgcn.queue.ptr");
781+
let val = self.call(f, &[], None);
782+
// XXX Needs the proper address space patch
783+
unsafe { llvm::LLVMBuildAddrSpaceCast(self.llbuilder, val,
784+
llret_ty, UNNAMED) }
785+
}
760786

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

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,12 @@ extern "C" {
14751475
DestTy: &'a Type,
14761476
Name: *const c_char,
14771477
) -> &'a Value;
1478+
pub fn LLVMBuildAddrSpaceCast(
1479+
B: &Builder<'a>,
1480+
Val: &'a Value,
1481+
DestTy: &'a Type,
1482+
Name: *const c_char,
1483+
) -> &'a Value;
14781484
pub fn LLVMRustBuildIntCast(
14791485
B: &Builder<'a>,
14801486
Val: &'a Value,

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ symbols! {
250250
allow_internal_unstable_backcompat_hack,
251251
allowed,
252252
always,
253+
amdgcn_dispatch_ptr,
254+
amdgcn_queue_ptr,
253255
and,
254256
and_then,
255257
any,

compiler/rustc_typeck/src/check/intrinsic.rs

+7
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
379379

380380
sym::nontemporal_store => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()),
381381

382+
sym::amdgcn_dispatch_ptr => {
383+
(0, vec![], tcx.mk_imm_ptr(tcx.types.u8))
384+
}
385+
sym::amdgcn_queue_ptr => {
386+
(0, vec![], tcx.mk_imm_ptr(tcx.types.u8))
387+
}
388+
382389
other => {
383390
struct_span_err!(
384391
tcx.sess,

0 commit comments

Comments
 (0)