Rollup merge of #147936 - Sa4dUs:offload-intrinsic, r=ZuseZ4

Offload intrinsic

This PR implements the minimal mechanisms required to run a small subset of arbitrary offload kernels without relying on hardcoded names or metadata.

- `offload(kernel, (..args))`: an intrinsic that generates the necessary host-side LLVM-IR code.
- `rustc_offload_kernel`: a builtin attribute that marks device kernels to be handled appropriately.

Example usage (pseudocode):
```rust
fn kernel(x: *mut [f64; 128]) {
    core::intrinsics::offload(kernel_1, (x,))
}

#[cfg(target_os = "linux")]
extern "C" {
    pub fn kernel_1(array_b: *mut [f64; 128]);
}

#[cfg(not(target_os = "linux"))]
#[rustc_offload_kernel]
extern "gpu-kernel" fn kernel_1(x: *mut [f64; 128]) {
    unsafe { (*x)[0] = 21.0 };
}
```
This commit is contained in:
Stuart Cook 2025-11-26 23:32:03 +11:00 committed by GitHub
commit 2b150f2c65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 529 additions and 178 deletions

View file

@ -1436,6 +1436,39 @@ extern "C" void LLVMRustPositionAfter(LLVMBuilderRef B, LLVMValueRef Instr) {
}
}
extern "C" LLVMValueRef LLVMRustGetInsertPoint(LLVMBuilderRef B) {
llvm::IRBuilderBase &IRB = *unwrap(B);
llvm::IRBuilderBase::InsertPoint ip = IRB.saveIP();
llvm::BasicBlock *BB = ip.getBlock();
if (!BB)
return nullptr;
auto it = ip.getPoint();
if (it == BB->end())
return nullptr;
llvm::Instruction *I = &*it;
return wrap(I);
}
extern "C" void LLVMRustRestoreInsertPoint(LLVMBuilderRef B,
LLVMValueRef Instr) {
llvm::IRBuilderBase &IRB = *unwrap(B);
if (!Instr) {
llvm::BasicBlock *BB = IRB.GetInsertBlock();
if (BB)
IRB.SetInsertPoint(BB);
return;
}
llvm::Instruction *I = unwrap<llvm::Instruction>(Instr);
IRB.SetInsertPoint(I);
}
extern "C" LLVMValueRef
LLVMRustGetFunctionCall(LLVMValueRef Fn, const char *Name, size_t NameLen) {
auto targetName = StringRef(Name, NameLen);