Skip to content

Commit

Permalink
SPV_KHR_untyped_pointers - fix enqueue marker (#2820)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vmaksimo authored Nov 4, 2024
1 parent cc57c3a commit 8e65158
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ SPIRVType *LLVMToSPIRVBase::transPointerType(SPIRVType *ET, unsigned AddrSpc) {
return transPointerType(ET, SPIRAS_Private);
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers) &&
!(ET->isTypeArray() || ET->isTypeVector() || ET->isTypeStruct() ||
ET->isTypeImage() || ET->isTypeSampler() || ET->isTypePipe())) {
ET->isSPIRVOpaqueType())) {
TranslatedTy = BM->addUntypedPointerKHRType(
SPIRSPIRVAddrSpaceMap::map(static_cast<SPIRAddressSpace>(AddrSpc)));
} else {
Expand Down Expand Up @@ -2220,11 +2220,11 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
MemoryAccess.clear();
if (BM->isAllowedToUseExtension(ExtensionID::SPV_KHR_untyped_pointers)) {
SPIRVValue *Source = transValue(LD->getPointerOperand(), BB);
SPIRVType *PtrElTy = Source->getType()->getPointerElementType();
SPIRVType *LoadTy = transType(LD->getType());
// For images do not use explicit load type, but rather use the source
// type (calculated in SPIRVLoad constructor)
if (LoadTy->isTypeUntypedPointerKHR() &&
(Source->getType()->getPointerElementType()->isTypeImage())) {
// For special types (images, pipes, etc.) do not use explicit load type,
// but rather use the source type (calculated in SPIRVLoad constructor)
if (LoadTy->isTypeUntypedPointerKHR() && PtrElTy->isSPIRVOpaqueType()) {
LoadTy = nullptr;
}
return mapValue(V, BM->addLoadInst(Source, MemoryAccess, BB, LoadTy));
Expand Down
8 changes: 8 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ bool SPIRVType::isTypeVectorOrScalarFloat() const {
return isTypeFloat() || isTypeVectorFloat();
}

bool SPIRVType::isSPIRVOpaqueType() const {
return isTypeDeviceEvent() || isTypeEvent() || isTypeImage() ||
isTypePipe() || isTypeReserveId() || isTypeSampler() ||
isTypeSampledImage() || isTypePipeStorage() ||
isTypeCooperativeMatrixKHR() || isTypeJointMatrixINTEL() ||
isTypeTaskSequenceINTEL();
}

bool SPIRVTypeStruct::isPacked() const {
return hasDecorate(DecorationCPacked);
}
Expand Down
1 change: 1 addition & 0 deletions lib/SPIRV/libSPIRV/SPIRVType.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class SPIRVType : public SPIRVEntry {
bool isTypeSubgroupAvcINTEL() const;
bool isTypeSubgroupAvcMceINTEL() const;
bool isTypeTaskSequenceINTEL() const;
bool isSPIRVOpaqueType() const;
};

class SPIRVTypeVoid : public SPIRVType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
; RUN: llvm-dis %t.rev.bc
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_task_sequence,+SPV_KHR_untyped_pointers -o %t.spv
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV

; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis %t.rev.bc
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; Source SYCL code example
; int mult(int a, int b) {
; return a * b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
; RUN: llvm-dis %t.rev.bc
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_task_sequence,+SPV_KHR_untyped_pointers -o %t.spv
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV

; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis %t.rev.bc
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; CHECK-SPIRV: TypeInt [[#IntTy:]] 32 0
; CHECK-SPIRV: TypeTaskSequenceINTEL [[#TypeTS:]]
; CHECK-SPIRV: TypeFunction [[#FuncTy:]] [[#IntTy]] [[#IntTy]] [[#IntTy]]
Expand Down
13 changes: 13 additions & 0 deletions test/transcoding/enqueue_marker.cl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
// RUN: llvm-spirv %t.rev.bc -spirv-text -o %t.spv.txt
// RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV

// RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.bc -spirv-text -o %t.spv.txt
// RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV
// RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.bc -o %t.spv
// RUN: spirv-val %t.spv
// RUN: llvm-spirv -r %t.spv -o %t.rev.bc
// RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM
// RUN: llvm-spirv -r -spirv-target-env="SPV-IR" %t.spv -o %t.rev.bc
// RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-SPV-IR

// Check that SPIR-V friendly IR is correctly recognized
// RUN: llvm-spirv --spirv-ext=+SPV_KHR_untyped_pointers %t.rev.bc -spirv-text -o %t.spv.txt
// RUN: FileCheck < %t.spv.txt %s --check-prefix=CHECK-SPIRV

kernel void test_enqueue_marker(global int *out) {
queue_t queue = get_default_queue();

Expand Down

0 comments on commit 8e65158

Please sign in to comment.