Skip to content

Commit bf402f1

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 2e940ac commit bf402f1

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+27
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_codegen_ssa::base::{compare_simd_types, wants_msvc_seh};
1113
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
1214
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
@@ -22,6 +24,7 @@ use rustc_target::abi::{self, HasDataLayout, LayoutOf, Primitive};
2224
use rustc_target::spec::PanicStrategy;
2325

2426
use std::cmp::Ordering;
27+
use std::ffi::CStr;
2528
use std::iter;
2629

2730
fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: Symbol) -> Option<&'ll Value> {
@@ -73,6 +76,9 @@ fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: Symbol) -> Option<&'ll Va
7376
Some(cx.get_intrinsic(&llvm_name))
7477
}
7578

79+
const EMPTY_C_STR: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"\0") };
80+
const UNNAMED: *const c_char = EMPTY_C_STR.as_ptr();
81+
7682
impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
7783
fn codegen_intrinsic_call(
7884
&mut self,
@@ -303,6 +309,27 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
303309
}
304310
}
305311

312+
sym::amdgcn_dispatch_ptr => {
313+
// This intrinsic returns a pointer in the const addr space
314+
// which can't be encoded in source level Rust.
315+
316+
let f = self.cx().get_intrinsic("llvm.amdgcn.dispatch.ptr");
317+
let val = self.call(f, &[], None);
318+
// XXX Needs the proper address space patch
319+
unsafe { llvm::LLVMBuildAddrSpaceCast(self.llbuilder, val,
320+
llret_ty, UNNAMED) }
321+
}
322+
sym::amdgcn_queue_ptr => {
323+
// This intrinsic returns a pointer in the const addr space
324+
// which can't be encoded in source level Rust.
325+
326+
let f = self.cx().get_intrinsic("llvm.amdgcn.queue.ptr");
327+
let val = self.call(f, &[], None);
328+
// XXX Needs the proper address space patch
329+
unsafe { llvm::LLVMBuildAddrSpaceCast(self.llbuilder, val,
330+
llret_ty, UNNAMED) }
331+
}
332+
306333
_ => bug!("unknown intrinsic '{}'", name),
307334
};
308335

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,12 @@ extern "C" {
14891489
DestTy: &'a Type,
14901490
Name: *const c_char,
14911491
) -> &'a Value;
1492+
pub fn LLVMBuildAddrSpaceCast(
1493+
B: &Builder<'a>,
1494+
Val: &'a Value,
1495+
DestTy: &'a Type,
1496+
Name: *const c_char,
1497+
) -> &'a Value;
14921498
pub fn LLVMRustBuildIntCast(
14931499
B: &Builder<'a>,
14941500
Val: &'a Value,

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ symbols! {
270270
allow_internal_unstable,
271271
allowed,
272272
always,
273+
amdgcn_dispatch_ptr,
274+
amdgcn_queue_ptr,
273275
and,
274276
and_then,
275277
any,

compiler/rustc_typeck/src/check/intrinsic.rs

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

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

370+
sym::amdgcn_dispatch_ptr => {
371+
(0, vec![], tcx.mk_imm_ptr(tcx.types.u8))
372+
}
373+
sym::amdgcn_queue_ptr => {
374+
(0, vec![], tcx.mk_imm_ptr(tcx.types.u8))
375+
}
376+
370377
other => {
371378
tcx.sess.emit_err(UnrecognizedIntrinsicFunction { span: it.span, name: other });
372379
return;

0 commit comments

Comments
 (0)