[PATCH] D138702: support for HIP non hostcall printf

Vikram Hegde via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 25 03:26:41 PST 2022


vikramRH created this revision.
vikramRH added reviewers: sameerds, b-sumner, yaxunl.
vikramRH added a project: LLVM.
Herald added subscribers: kosarev, foad, kerbowa, hiraditya, Anastasia, jvesely, arsenm.
Herald added a project: All.
vikramRH requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added a project: clang.

The patch essentially ports the existing non-hostcall printf support in OpenCL to HIP (to be controlled via new option "-fdelayed-printf"), with following changes

1. Code refactoring -> we now use API's "getConstantStringInfo()" to extract constant string contents at compile time.
2. Support to print non-const null terminated strings, required in HIP context. This is achieved as follows
  - calculate string size using a function "getStrlenWithNull()" and reserve the space in printf buffer using __printf_alloc() (as was the case in OpenCL, but number of bytes allocated could be dynamic now)
  - copy the string contents to buffer using previously calculated size and the pointer to string (a memcpy intrinsic is generated here)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138702

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Builtins.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
  llvm/test/CodeGen/AMDGPU/hip-delayed-printf.ll
  llvm/test/CodeGen/AMDGPU/opencl-printf.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138702.477903.patch
Type: text/x-patch
Size: 27294 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221125/9bd510b1/attachment-0001.bin>


More information about the cfe-commits mailing list