Skip to content

Commit 00fc482

Browse files
vmaksimojsji
authored andcommitted
SPV_KHR_untyped_pointers - fix enqueue marker (#2820)
This patch ensures that we are loading image type, not untyped pointer type when the extension is used. This way we also preserve correct mangling during the reverse translation. Original commit: KhronosGroup/SPIRV-LLVM-Translator@8e65158c3250e5c
1 parent e9ebfa5 commit 00fc482

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ SPIRVType *LLVMToSPIRVBase::transPointerType(SPIRVType *ET, unsigned AddrSpc) {
759759
return transPointerType(ET, SPIRAS_Private);
760760
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers) &&
761761
!(ET->isTypeArray() || ET->isTypeVector() || ET->isTypeStruct() ||
762-
ET->isTypeImage() || ET->isTypeSampler() || ET->isTypePipe())) {
762+
ET->isSPIRVOpaqueType())) {
763763
TranslatedTy = BM->addUntypedPointerKHRType(
764764
SPIRSPIRVAddrSpaceMap::map(static_cast<SPIRAddressSpace>(AddrSpc)));
765765
} else {
@@ -2228,11 +2228,11 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
22282228
MemoryAccess.clear();
22292229
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers)) {
22302230
SPIRVValue *Source = transValue(LD->getPointerOperand(), BB);
2231+
SPIRVType *PtrElTy = Source->getType()->getPointerElementType();
22312232
SPIRVType *LoadTy = transType(LD->getType());
2232-
// For images do not use explicit load type, but rather use the source
2233-
// type (calculated in SPIRVLoad constructor)
2234-
if (LoadTy->isTypeUntypedPointerKHR() &&
2235-
(Source->getType()->getPointerElementType()->isTypeImage())) {
2233+
// For special types (images, pipes, etc.) do not use explicit load type,
2234+
// but rather use the source type (calculated in SPIRVLoad constructor)
2235+
if (LoadTy->isTypeUntypedPointerKHR() && PtrElTy->isSPIRVOpaqueType()) {
22362236
LoadTy = nullptr;
22372237
}
22382238
return mapValue(V, BM->addLoadInst(Source, MemoryAccess, BB, LoadTy));

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVType.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ bool SPIRVType::isTypeVectorOrScalarFloat() const {
265265
return isTypeFloat() || isTypeVectorFloat();
266266
}
267267

268+
bool SPIRVType::isSPIRVOpaqueType() const {
269+
return isTypeDeviceEvent() || isTypeEvent() || isTypeImage() ||
270+
isTypePipe() || isTypeReserveId() || isTypeSampler() ||
271+
isTypeSampledImage() || isTypePipeStorage() ||
272+
isTypeCooperativeMatrixKHR() || isTypeJointMatrixINTEL() ||
273+
isTypeTaskSequenceINTEL();
274+
}
275+
268276
bool SPIRVTypeStruct::isPacked() const {
269277
return hasDecorate(DecorationCPacked);
270278
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class SPIRVType : public SPIRVEntry {
109109
bool isTypeSubgroupAvcINTEL() const;
110110
bool isTypeSubgroupAvcMceINTEL() const;
111111
bool isTypeTaskSequenceINTEL() const;
112+
bool isSPIRVOpaqueType() const;
112113
};
113114

114115
class SPIRVTypeVoid : public SPIRVType {

llvm-spirv/test/extensions/INTEL/SPV_INTEL_task_sequence/task_sequence.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
; RUN: llvm-dis %t.rev.bc
88
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
99

10+
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_task_sequence,+SPV_KHR_untyped_pointers -o %t.spv
11+
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
12+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
13+
14+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
15+
; RUN: llvm-dis %t.rev.bc
16+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
17+
1018
; Source SYCL code example
1119
; int mult(int a, int b) {
1220
; return a * b;

llvm-spirv/test/extensions/INTEL/SPV_INTEL_task_sequence/task_sequence_zero_capacity_literals.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
; RUN: llvm-dis %t.rev.bc
88
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
99

10+
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_task_sequence,+SPV_KHR_untyped_pointers -o %t.spv
11+
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
12+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
13+
14+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
15+
; RUN: llvm-dis %t.rev.bc
16+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
17+
1018
; CHECK-SPIRV: TypeInt [[#IntTy:]] 32 0
1119
; CHECK-SPIRV: TypeTaskSequenceINTEL [[#TypeTS:]]
1220
; CHECK-SPIRV: TypeFunction [[#FuncTy:]] [[#IntTy]] [[#IntTy]] [[#IntTy]]

llvm-spirv/test/transcoding/enqueue_marker.cl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
// RUN: llvm-spirv %t.rev.bc -spirv-text -o %t.spv.txt
1313
// RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV
1414

15+
// RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.bc -spirv-text -o %t.spv.txt
16+
// RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV
17+
// RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.bc -o %t.spv
18+
// RUN: spirv-val %t.spv
19+
// RUN: llvm-spirv -r %t.spv -o %t.rev.bc
20+
// RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM
21+
// RUN: llvm-spirv -r -spirv-target-env="SPV-IR" %t.spv -o %t.rev.bc
22+
// RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-SPV-IR
23+
24+
// Check that SPIR-V friendly IR is correctly recognized
25+
// RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.rev.bc -spirv-text -o %t.spv.txt
26+
// RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV
27+
1528
kernel void test_enqueue_marker(global int *out) {
1629
queue_t queue = get_default_queue();
1730

0 commit comments

Comments
 (0)