This is an archive of the discontinued LLVM Phabricator instance.

[SPIR-V] Add SPIR-V builtin functions and types
Needs ReviewPublic

Authored by bader on Aug 13 2021, 6:57 AM.


  • Make the OpenCL Builtin lookup agnostic to programming models

    Rename the OpenCL Builtin lookup system to make it agnostic. The Builtin emitter is now outputting the builtin information into a class so that different programming models can be produced and used.
  • Add SPIR-V variants of TypeSampledImage as clang builtin type.

    This patch adds SPIR-V sampled image types as derivative of the builtin OpenCL Image types. For each OpenCL image type, clang defines a Sampled<image type> variant and lowered as a "spirv.SampledImage.<image>" llvm opaque type.
  • Enable SPIR-V builtin lookup

    Add flag -fdeclare-spirv-builtins to enable lookup of SPIR-V builtins.

    If -fdeclare-spirv-builtins is passed to clang, the compiler will try to lookup for the builtin described in for any match. If a match is found, overloads are build for the match.

    This will enforce a stable way to express SPIR-V builtins and make them closer to how the translator mangles them. This will help ensuring builtin for CUDA does not break easily. This will also support any changes suggested by the SPIRV-LLVM people on how to represent builtins.

    Define SPIRV_BUILTIN_DECLARATIONS when passing -fdeclare-spirv-builtins to clang.

    Added OpenCL SPIR-V extended set builtins bindings and part of the core SPIR-V (mostly missing Images and Pipes)

TODO: Known vendor extensions are not implemented yet.

Signed-off-by: Victor Lomuller <>

Diff Detail

Event Timeline

bader created this revision.Aug 13 2021, 6:57 AM
bader requested review of this revision.Aug 13 2021, 6:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 13 2021, 6:57 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Can you elaborate the overall design flow please? Particularly, it is not clear why we need to duplicate OpenCL types and builtins at source level for SPIR-V... Is there any way to avoid this?

martong removed a subscriber: martong.Aug 30 2021, 5:54 AM