Skip to content

Commit 8e65158

Browse files
authored
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.
1 parent cc57c3a commit 8e65158

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ SPIRVType *LLVMToSPIRVBase::transPointerType(SPIRVType *ET, unsigned AddrSpc) {
755755
return transPointerType(ET, SPIRAS_Private);
756756
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers) &&
757757
!(ET->isTypeArray() || ET->isTypeVector() || ET->isTypeStruct() ||
758-
ET->isTypeImage() || ET->isTypeSampler() || ET->isTypePipe())) {
758+
ET->isSPIRVOpaqueType())) {
759759
TranslatedTy = BM->addUntypedPointerKHRType(
760760
SPIRSPIRVAddrSpaceMap::map(static_cast<SPIRAddressSpace>(AddrSpc)));
761761
} else {
@@ -2220,11 +2220,11 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
22202220
MemoryAccess.clear();
22212221
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers)) {
22222222
SPIRVValue *Source = transValue(LD->getPointerOperand(), BB);
2223+
SPIRVType *PtrElTy = Source->getType()->getPointerElementType();
22232224
SPIRVType *LoadTy = transType(LD->getType());
2224-
// For images do not use explicit load type, but rather use the source
2225-
// type (calculated in SPIRVLoad constructor)
2226-
if (LoadTy->isTypeUntypedPointerKHR() &&
2227-
(Source->getType()->getPointerElementType()->isTypeImage())) {
2225+
// For special types (images, pipes, etc.) do not use explicit load type,
2226+
// but rather use the source type (calculated in SPIRVLoad constructor)
2227+
if (LoadTy->isTypeUntypedPointerKHR() && PtrElTy->isSPIRVOpaqueType()) {
22282228
LoadTy = nullptr;
22292229
}
22302230
return mapValue(V, BM->addLoadInst(Source, MemoryAccess, BB, LoadTy));

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
}

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 {

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;

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]]

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)