[clang] [CIR][AMDGPU] Route printf in device code through the OpenCL runtime (PR #226435)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 25 04:03:32 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Steffen Larsen (steffenlarsen)

<details>
<summary>Changes</summary>

This commit implements CIR support for device-side printf on AMDGPU targets. Previously, any call to printf fell through to a library call, which does not exist on the device, so any kernel calling printf failed to build. For OGCG, the AMDGPU target routes printf calls through the OpenCL printf runtime, which takes the format string and a buffer of appended arguments. This implementation leverages this lowering by first emitting a call to a marker function `__cir_amdgpu_printf` during CIRGen, which is then lowered to the appropriate OpenCL printf runtime call during the LLVM IR lowering, leveraging the existing `llvm::emitAMDGPUPrintfCall` function.

---
Full diff: https://github.com/llvm/llvm-project/pull/226435.diff


7 Files Affected:

- (modified) clang/include/clang/CIR/LowerToLLVM.h (+6) 
- (modified) clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp (+1-1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp (+39) 
- (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (+3) 
- (modified) clang/lib/CIR/FrontendAction/CIRGenAction.cpp (+6-2) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+46) 
- (added) clang/test/CIR/CodeGenHIP/device-printf.hip (+29) 


``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````

</details>


https://github.com/llvm/llvm-project/pull/226435


More information about the cfe-commits mailing list