rust/compiler/rustc_codegen_llvm/src
Jacob Pratt 6912c676cd
Rollup merge of #150607 - dispatch-ptr-intrinsic, r=workingjubilee
Add amdgpu_dispatch_ptr intrinsic

There is an ongoing discussion in rust-lang/rust#150452 about using address spaces from the Rust language in some way.
As that discussion will likely not conclude soon, this PR adds one rustc_intrinsic with an addrspacecast to unblock getting basic information like launch and workgroup size and make it possible to implement something like `core::gpu`.

Add a rustc intrinsic `amdgpu_dispatch_ptr` to access the kernel dispatch packet on amdgpu.
The HSA kernel dispatch packet contains important information like the launch size and workgroup size.

The Rust intrinsic lowers to the `llvm.amdgcn.dispatch.ptr` LLVM intrinsic, which returns a `ptr addrspace(4)`, plus an addrspacecast to `addrspace(0)`, so it can be returned as a Rust reference.
The returned pointer/reference is valid for the whole program lifetime, and is therefore `'static`.
The return type of the intrinsic (`&'static ()`) does not mention the struct so that rustc does not need to know the exact struct type. An alternative would be to define the struct as lang item or add a generic argument to the function.
Is this ok or is there a better way (also, should it return a pointer instead of a reference)?

Short version:
```rust
#[cfg(target_arch = "amdgpu")]
pub fn amdgpu_dispatch_ptr() -> *const ();
```

Tracking issue: rust-lang/rust#135024
2026-01-15 19:35:46 -05:00
..
back Cleanup debuginfo_compression unstable flag 2026-01-01 19:30:02 -06:00
builder Update test and verify that tgt_(un)register_lib have the right type 2026-01-04 06:58:31 -08:00
coverageinfo Use the embeddable filename for coverage artifacts 2025-12-15 22:09:07 +01:00
debuginfo Remove useless call to erase_and_anonymize_regions. 2026-01-12 09:22:58 +11:00
llvm Modified to output error messages appropriate to the situation 2026-01-07 00:33:57 +09:00
abi.rs Add -Zannotate-moves for profiler visibility of move/copy operations 2025-11-06 15:39:45 -08:00
allocator.rs Remove -Zoom=panic 2025-11-28 19:30:39 +00:00
asm.rs Allow PowerPC spe_acc as clobber-only register 2025-12-03 12:37:22 -06:00
attributes.rs Revert "avoid phi node for pointers flowing into Vec appends #130998" 2026-01-15 09:37:16 +08:00
base.rs Update test and verify that tgt_(un)register_lib have the right type 2026-01-04 06:58:31 -08:00
builder.rs Inline BuilderMethods::call for intrinsics 2025-12-27 17:46:26 +00:00
callee.rs rustc_target: introduce Env 2025-11-11 18:34:47 -05:00
common.rs Fix ICE on offsetted ZST pointer 2025-10-15 20:06:46 -04:00
consts.rs Fix dso_local for external statics with linkage 2025-12-29 19:26:34 +00:00
context.rs rustc_codegen_llvm: update alignment for double on AIX 2026-01-05 14:08:51 -05:00
declare.rs refactor: Remove LLVMRustInsertPrivateGlobal and define_private_global 2025-10-08 21:59:48 +02:00
errors.rs Modified to output error messages appropriate to the situation 2026-01-07 00:33:57 +09:00
intrinsic.rs Rollup merge of #150607 - dispatch-ptr-intrinsic, r=workingjubilee 2026-01-15 19:35:46 -05:00
lib.rs Remove Deref/DerefMut impl for Providers. 2026-01-14 15:55:59 +11:00
llvm_util.rs llvm: Update reliable_f16 configuration for LLVM22 2026-01-09 19:44:24 -06:00
macros.rs use declarative macro for #[derive(TryFromU32)] 2025-10-06 14:54:38 +00:00
mono_item.rs rustc_target: Remove unused Arch::PowerPC64LE 2026-01-14 23:12:57 +09:00
type_.rs Remove inherent methods from llvm::TypeKind 2025-12-19 12:32:49 +11:00
type_of.rs codegen: implement repr(scalable) 2025-12-16 11:00:12 +00:00
typetree.rs remove llvm_enzyme and enzyme fallbacks from most places, enable the autodiff frontend on nightly 2025-12-19 11:02:57 -08:00
va_arg.rs rustc_target: Remove unused Arch::PowerPC64LE 2026-01-14 23:12:57 +09:00
value.rs Consistently import llvm::Type and llvm::Value 2025-10-06 13:09:16 +11:00