[PATCH] D127579: [clang][WIP] add option to keep types of ptr args for non-kernel functions in metadata
Ilia Diachkov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 11 14:26:25 PDT 2022
iliya-diyachkov created this revision.
iliya-diyachkov added reviewers: Anastasia, bader, svenvh.
Herald added a subscriber: Naghasan.
Herald added a project: All.
iliya-diyachkov requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.
It's a draft for the patch we discussed in the thread of opaque pointer support in the SPIR-V translator <https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/1444>. The final decision on whether we will use this approach has not yet been made, so the patch is uploaded for convenience and concertizing of the discussion.
The types are already in metadata for kernel functions by default. Alexey Bader shared the code example <https://godbolt.org/z/WzYYhTYe3> with non-kernel functions which lost the info. The patch fixes this case. To enable the feature you need to pass `-cl-extra-ptr-info` to clang.
TODO:
- emit only ptr type info metadata if EmitOpenCLExtraPtrInfo is enabled,
- maybe add the same info to function declarations,
- maybe add the same options to other languages (SYCL, HLSL ...) or make one common option for all languages.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127579
Files:
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Driver/ToolChains/Clang.cpp
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3447,6 +3447,7 @@
options::OPT_cl_single_precision_constant,
options::OPT_cl_finite_math_only,
options::OPT_cl_kernel_arg_info,
+ options::OPT_cl_extra_ptr_info,
options::OPT_cl_unsafe_math_optimizations,
options::OPT_cl_fast_relaxed_math,
options::OPT_cl_mad_enable,
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -600,8 +600,11 @@
void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
llvm::Function *Fn)
{
- if (!FD->hasAttr<OpenCLKernelAttr>())
+ if (!FD->hasAttr<OpenCLKernelAttr>()) {
+ if (CGM.getCodeGenOpts().EmitOpenCLExtraPtrInfo)
+ CGM.GenOpenCLArgMetadata(Fn, FD, this);
return;
+ }
llvm::LLVMContext &Context = getLLVMContext();
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -896,6 +896,9 @@
HelpText<"OpenCL only. Enable or disable OpenCL extensions/optional features. The argument is a comma-separated "
"sequence of one or more extension names, each prefixed by '+' or '-'.">,
MarshallingInfoStringVector<TargetOpts<"OpenCLExtensionsAsWritten">>;
+def cl_extra_ptr_info : Flag<["-"], "cl-extra-ptr-info">, Group<opencl_Group>, Flags<[CC1Option]>,
+ HelpText<"OpenCL only. Generate type hints for pointers.">,
+ MarshallingInfoFlag<CodeGenOpts<"EmitOpenCLExtraPtrInfo">>;
def client__name : JoinedOrSeparate<["-"], "client_name">;
def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, Unsupported]>;
Index: clang/include/clang/Basic/CodeGenOptions.def
===================================================================
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -87,6 +87,7 @@
CODEGENOPT(EmitGcovArcs , 1, 0) ///< Emit coverage data files, aka. GCDA.
CODEGENOPT(EmitGcovNotes , 1, 0) ///< Emit coverage "notes" files, aka GCNO.
CODEGENOPT(EmitOpenCLArgMetadata , 1, 0) ///< Emit OpenCL kernel arg metadata.
+CODEGENOPT(EmitOpenCLExtraPtrInfo , 1, 0) ///< Emit OpenCL extra pointer info.
CODEGENOPT(EmulatedTLS , 1, 0) ///< Set by default or -f[no-]emulated-tls.
CODEGENOPT(ExplicitEmulatedTLS , 1, 0) ///< Set if -f[no-]emulated-tls is used.
/// Embed Bitcode mode (off/all/bitcode/marker).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127579.436056.patch
Type: text/x-patch
Size: 2768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220611/bd8043a2/attachment.bin>
More information about the cfe-commits
mailing list