Page MenuHomePhabricator

[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

Unit TestsFailed

40 msx64 debian > Clang.CodeGenSPIRV::spirv-builtin-lookup-win.cpp
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -cc1 -internal-isystem /var/lib/buildkite-agent/builds/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc -triple x86_64-windows-msvc -fdeclare-spirv-builtins -fsyntax-only -emit-llvm /var/lib/buildkite-agent/builds/llvm-project/clang/test/CodeGenSPIRV/spirv-builtin-lookup-win.cpp -o - | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/clang/test/CodeGenSPIRV/spirv-builtin-lookup-win.cpp
40 msx64 debian > Clang.CodeGenSPIRV::spirv-builtin-lookup.cpp
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -cc1 -internal-isystem /var/lib/buildkite-agent/builds/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -fdeclare-spirv-builtins -fsyntax-only -emit-llvm /var/lib/buildkite-agent/builds/llvm-project/clang/test/CodeGenSPIRV/spirv-builtin-lookup.cpp -o - | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/clang/test/CodeGenSPIRV/spirv-builtin-lookup.cpp
590 msx64 debian > Clang.Index::annotate-comments.cpp
Script: -- : 'RUN: at line 259'; rm -rf /var/lib/buildkite-agent/builds/llvm-project/build/tools/clang/test/Index/Output/annotate-comments.cpp.tmp
430 msx64 debian > Clang.Index::comment-c-decls.c
Script: -- : 'RUN: at line 1'; rm -rf /var/lib/buildkite-agent/builds/llvm-project/build/tools/clang/test/Index/Output/comment-c-decls.c.tmp
430 msx64 debian > Clang.Index::comment-cplus-decls.cpp
Script: -- : 'RUN: at line 1'; rm -rf /var/lib/buildkite-agent/builds/llvm-project/build/tools/clang/test/Index/Output/comment-cplus-decls.cpp.tmp
View Full Test Results (30 Failed)

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