[clang] [AMDGPU] Treat printf as builtin for OpenCL (PR #72554)

Vikram Hegde via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 16 20:46:14 PST 2023


================
@@ -2458,6 +2458,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
     BuiltinID = mutateLongDoubleBuiltin(BuiltinID);
 
+   // Mutate the printf builtin ID so that we use the same CodeGen path for
+   // HIP and OpenCL with AMDGPU targets.
+   if (getTarget().getTriple().isAMDGCN() && BuiltinID == AMDGPU::BIprintf)
+     BuiltinID = Builtin::BIprintf;
----------------
vikramRH wrote:

@jhuber6 , I had your implementation in mind when I wrote this, The printf wont be expanded by clang with "-fno-builtin" and users would still have an option to use a lib variant if need be.  This also makes this more elegant as we would not have to hack the "fno-builtin" handling into the implementation, this is part of clang builtin handling.

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


More information about the cfe-commits mailing list