Skip to content

Commit 2036e3c

Browse files
svenvhvmaksimo
authored andcommitted
Only emit Initializer and Finalizer from SPIR-V 1.1
The Initializer and Finalizer Execution Modes were missing before SPIR-V 1.1.
1 parent b035640 commit 2036e3c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,11 +3028,20 @@ bool LLVMToSPIRV::transExecutionMode() {
30283028

30293029
switch (EMode) {
30303030
case spv::ExecutionModeContractionOff:
3031-
case spv::ExecutionModeInitializer:
3032-
case spv::ExecutionModeFinalizer:
30333031
BF->addExecutionMode(BM->add(
30343032
new SPIRVExecutionMode(BF, static_cast<ExecutionMode>(EMode))));
30353033
break;
3034+
case spv::ExecutionModeInitializer:
3035+
case spv::ExecutionModeFinalizer:
3036+
if (BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_1)) {
3037+
BF->addExecutionMode(BM->add(
3038+
new SPIRVExecutionMode(BF, static_cast<ExecutionMode>(EMode))));
3039+
} else {
3040+
getErrorLog().checkError(false, SPIRVEC_Requires1_1,
3041+
"Initializer/Finalizer Execution Mode");
3042+
return false;
3043+
}
3044+
break;
30363045
case spv::ExecutionModeLocalSize:
30373046
case spv::ExecutionModeLocalSizeHint: {
30383047
unsigned X, Y, Z;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ _SPIRV_OP(FunctionPointers, "Can't translate function pointer:\n")
1616
_SPIRV_OP(InvalidInstruction, "Can't translate llvm instruction:\n")
1717
_SPIRV_OP(InvalidWordCount,
1818
"Can't encode instruction with word count greater than 65535:\n")
19+
_SPIRV_OP(Requires1_1, "Feature requires SPIR-V 1.1 or greater:")

llvm-spirv/test/CXX/global-ctor.cl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: spirv-val %t.spv
44
// RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
55
// RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-LLVM
6+
// RUN: not llvm-spirv %t.bc --spirv-max-version=1.0 2>&1 | FileCheck %s --check-prefix=CHECK-SPV10
67

78
class Something {
89
public:
@@ -23,3 +24,5 @@ void kernel work(global int *out) {
2324

2425
// CHECK-LLVM: llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @[[CTORNAME:_GLOBAL__sub_I[^ ]+]], i8* null }
2526
// CHECK-LLVM: define spir_kernel void @[[CTORNAME]]
27+
28+
// CHECK-SPV10: Feature requires SPIR-V 1.1 or greater: Initializer/Finalizer Execution Mode

0 commit comments

Comments
 (0)