Skip to content

Commit adaf4c7

Browse files
svenvhvmaksimo
authored andcommitted
Set capabilities for BuiltIn Decorations
BuiltIn Decorations have their own Enabling Capabilities, so report those capabilities when emitting a BuiltIn Decoration.
1 parent 30a4e14 commit adaf4c7

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,16 @@ class SPIRVDecorateGeneric : public SPIRVAnnotationGeneric {
8181
void setOwner(SPIRVDecorationGroup *Owner) { this->Owner = Owner; }
8282

8383
SPIRVCapVec getRequiredCapability() const override {
84-
return getCapability(Dec);
84+
switch (Dec) {
85+
case DecorationBuiltIn: {
86+
// Return the BuiltIn's capabilities.
87+
BuiltIn BI = static_cast<BuiltIn>(Literals.back());
88+
return getCapability(BI);
89+
}
90+
91+
default:
92+
return getCapability(Dec);
93+
}
8594
}
8695

8796
SPIRVWord getRequiredSPIRVVersion() const override {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 %s -triple spir -cl-std=CL2.0 -emit-llvm-bc -o %t.bc
2+
3+
// RUN: llvm-spirv %t.bc -o %t.spv
4+
// RUN: spirv-val %t.spv
5+
// RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
6+
// RUN: llvm-spirv %t.spv -r -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-LLVM
7+
8+
// Taken from clang/lib/Headers/opencl-c{,-base}.h
9+
// TODO: remove these and switch to -fdeclare-opencl-builtins
10+
typedef unsigned int uint4 __attribute__((ext_vector_type(4)));
11+
uint4 __attribute__((overloadable)) get_sub_group_gt_mask(void);
12+
13+
// CHECK-SPIRV: Capability GroupNonUniformBallot
14+
// CHECK-SPIRV: Decorate {{[0-9]+}} BuiltIn 4418
15+
16+
// CHECK-LLVM: test_mask
17+
// CHECK-LLVM: call spir_func <4 x i32> @_Z21get_sub_group_gt_maskv()
18+
19+
kernel void test_mask(global uint4 *out)
20+
{
21+
*out = get_sub_group_gt_mask();
22+
}

0 commit comments

Comments
 (0)