From d9e871ae7e694dc2e7bb3b78b79a02631f83aed1 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Tue, 14 Jan 2025 16:29:53 +0100 Subject: [PATCH 1/3] Update for deprecation of llvm::PointerUnion::get (#2961) Update for llvm-project commit abba01adad5d ("[ADT] Deprecate PointerUnion::{is,get} (NFC) (#122623)", 2025-01-13). --- lib/SPIRV/SPIRVToLLVMDbgTran.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/SPIRV/SPIRVToLLVMDbgTran.cpp b/lib/SPIRV/SPIRVToLLVMDbgTran.cpp index 7b94b2ae..5ec5ed28 100644 --- a/lib/SPIRV/SPIRVToLLVMDbgTran.cpp +++ b/lib/SPIRV/SPIRVToLLVMDbgTran.cpp @@ -421,7 +421,7 @@ SPIRVToLLVMDbgTran::transTypeArrayNonSemantic(const SPIRVExtInst *DebugInst) { if (DebugInst->getExtOp() == SPIRVDebug::TypeArray) { for (size_t I = SubrangesIdx; I < Ops.size(); ++I) { auto *SR = transDebugInst(BM->get(Ops[I])); - if (auto *Count = SR->getCount().get()) + if (auto *Count = cast(SR->getCount())) TotalCount *= Count->getSExtValue() > 0 ? Count->getSExtValue() : 0; Subscripts.push_back(SR); } @@ -444,7 +444,7 @@ SPIRVToLLVMDbgTran::transTypeArrayDynamic(const SPIRVExtInst *DebugInst) { SmallVector Subscripts; for (size_t I = SubrangesIdx; I < Ops.size(); ++I) { auto *SR = transDebugInst(BM->get(Ops[I])); - if (auto *Count = SR->getCount().get()) + if (auto *Count = cast(SR->getCount())) TotalCount *= Count->getSExtValue() > 0 ? Count->getSExtValue() : 0; Subscripts.push_back(SR); } @@ -1607,10 +1607,10 @@ SPIRVToLLVMDbgTran::transDebugIntrinsic(const SPIRVExtInst *DebugInst, if (!MDs.empty()) { DIArgList *AL = DIArgList::get(M->getContext(), MDs); if (M->IsNewDbgInfoFormat) { - cast(DbgValIntr.get()) + cast(cast(DbgValIntr)) ->setRawLocation(AL); } else { - cast(DbgValIntr.get()) + cast(cast(DbgValIntr)) ->setRawLocation(AL); } } From c8e8867efd44034b9f4b520a1df2caf572694d70 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Thu, 16 Jan 2025 13:31:01 +0100 Subject: [PATCH 2/3] Update more llvm::PointerUnion::get calls (#2962) Update for llvm-project commit abba01adad5d ("[ADT] Deprecate PointerUnion::{is,get} (NFC) (#122623)", 2025-01-13). --- lib/SPIRV/LLVMToSPIRVDbgTran.cpp | 14 +++++++------- lib/SPIRV/SPIRVReader.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/SPIRV/LLVMToSPIRVDbgTran.cpp b/lib/SPIRV/LLVMToSPIRVDbgTran.cpp index 1ef24467..2cd56e31 100644 --- a/lib/SPIRV/LLVMToSPIRVDbgTran.cpp +++ b/lib/SPIRV/LLVMToSPIRVDbgTran.cpp @@ -689,7 +689,7 @@ LLVMToSPIRVDbgTran::transDbgArrayTypeOpenCL(const DICompositeType *AT) { SPIRVWordVec LowerBounds(N); for (unsigned I = 0; I < N; ++I) { DISubrange *SR = cast(AR[I]); - ConstantInt *Count = SR->getCount().get(); + ConstantInt *Count = cast(SR->getCount()); if (AT->isVector()) { assert(N == 1 && "Multidimensional vector is not expected!"); Ops[ComponentCountIdx] = static_cast(Count->getZExtValue()); @@ -710,7 +710,7 @@ LLVMToSPIRVDbgTran::transDbgArrayTypeOpenCL(const DICompositeType *AT) { if (auto *DIExprLB = dyn_cast(RawLB)) LowerBounds[I] = transDbgEntry(DIExprLB)->getId(); else { - ConstantInt *ConstIntLB = SR->getLowerBound().get(); + ConstantInt *ConstIntLB = cast(SR->getLowerBound()); LowerBounds[I] = SPIRVWriter->transValue(ConstIntLB, nullptr)->getId(); } } else { @@ -733,7 +733,7 @@ LLVMToSPIRVDbgTran::transDbgArrayTypeNonSemantic(const DICompositeType *AT) { Ops.resize(SubrangesIdx + N); for (unsigned I = 0; I < N; ++I) { DISubrange *SR = cast(AR[I]); - ConstantInt *Count = SR->getCount().get(); + ConstantInt *Count = cast(SR->getCount()); if (AT->isVector()) { assert(N == 1 && "Multidimensional vector is not expected!"); Ops[ComponentCountIdx] = static_cast(Count->getZExtValue()); @@ -809,13 +809,13 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgSubrangeType(const DISubrange *ST) { ConstantInt *IntNode = nullptr; switch (Idx) { case LowerBoundIdx: - IntNode = ST->getLowerBound().get(); + IntNode = cast(ST->getLowerBound()); break; case UpperBoundIdx: - IntNode = ST->getUpperBound().get(); + IntNode = cast(ST->getUpperBound()); break; case CountIdx: - IntNode = ST->getCount().get(); + IntNode = cast(ST->getCount()); break; } Ops[Idx] = IntNode ? SPIRVWriter->transValue(IntNode, nullptr)->getId() @@ -830,7 +830,7 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgSubrangeType(const DISubrange *ST) { Ops[StrideIdx] = transDbgEntry(Node)->getId(); else Ops[StrideIdx] = - SPIRVWriter->transValue(ST->getStride().get(), nullptr) + SPIRVWriter->transValue(cast(ST->getStride()), nullptr) ->getId(); } return BM->addDebugInfo(SPIRVDebug::TypeSubrange, getVoidTy(), Ops); diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index 0d7161cd..d90642da 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -2644,11 +2644,11 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F, case SPIRVEIS_NonSemantic_Shader_DebugInfo_200: if (!M->IsNewDbgInfoFormat) { return mapValue( - BV, DbgTran->transDebugIntrinsic(ExtInst, BB).get()); + BV, cast(DbgTran->transDebugIntrinsic(ExtInst, BB))); } else { auto MaybeRecord = DbgTran->transDebugIntrinsic(ExtInst, BB); if (!MaybeRecord.isNull()) { - auto *Record = MaybeRecord.get(); + auto *Record = cast(MaybeRecord); Record->setDebugLoc( DbgTran->transDebugScope(static_cast(BV))); } From 197a800558787c938b325bc7df1cfffbb1a88cf9 Mon Sep 17 00:00:00 2001 From: Viktoria Maximova Date: Fri, 17 Jan 2025 17:27:57 +0100 Subject: [PATCH 3/3] Align translation of `OpCooperativeMatrixLengthKHR` to match the spec (#2964) `SPV_KHR_cooperative_matrix` extension defines that the only argument accepted in this instruction is `Matrix Type `, not the pointer to an actual matrix. This resolves #2963 --- lib/SPIRV/SPIRVReader.cpp | 3 +-- lib/SPIRV/SPIRVWriter.cpp | 4 ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp | 11 +++++++++++ lib/SPIRV/libSPIRV/SPIRVModule.h | 3 +++ .../cooperative_matrix_checked.ll | 3 +-- .../cooperative_matrix_prefetch.ll | 3 +-- .../SPV_KHR_cooperative_matrix/cooperative_matrix.ll | 3 +-- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index d90642da..12983d67 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -3624,8 +3624,7 @@ Instruction *SPIRVToLLVM::transBuiltinFromInst(const std::string &FuncName, Func->addFnAttr(Attribute::Convergent); } CallInst *Call; - if (OC == OpCooperativeMatrixLengthKHR && - Ops[0]->getOpCode() == OpTypeCooperativeMatrixKHR) { + if (OC == OpCooperativeMatrixLengthKHR) { // OpCooperativeMatrixLengthKHR needs special handling as its operand is // a Type instead of a Value. llvm::Type *MatTy = transType(reinterpret_cast(Ops[0])); diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index 594844e9..65eaa207 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -6792,6 +6792,10 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI, transValue(CI->getArgOperand(2), BB), BB); return BM->addStoreInst(transValue(CI->getArgOperand(0), BB), V, {}, BB); } + case OpCooperativeMatrixLengthKHR: { + return BM->addCooperativeMatrixLengthKHRInst( + transScavengedType(CI), transType(CI->getArgOperand(0)->getType()), BB); + } case OpGroupNonUniformShuffleDown: { Function *F = CI->getCalledFunction(); if (F->arg_size() && F->getArg(0)->hasStructRetAttr()) { diff --git a/lib/SPIRV/libSPIRV/SPIRVModule.cpp b/lib/SPIRV/libSPIRV/SPIRVModule.cpp index f1b210cc..753d5c03 100644 --- a/lib/SPIRV/libSPIRV/SPIRVModule.cpp +++ b/lib/SPIRV/libSPIRV/SPIRVModule.cpp @@ -279,6 +279,9 @@ class SPIRVModuleImpl : public SPIRVModule { SPIRVTypeTaskSequenceINTEL *addTaskSequenceINTELType() override; SPIRVInstruction *addTaskSequenceGetINTELInst(SPIRVType *, SPIRVValue *, SPIRVBasicBlock *) override; + SPIRVInstruction * + addCooperativeMatrixLengthKHRInst(SPIRVType *, SPIRVType *, + SPIRVBasicBlock *) override; SPIRVType *addOpaqueGenericType(Op) override; SPIRVTypeDeviceEvent *addDeviceEventType() override; SPIRVTypeQueue *addQueueType() override; @@ -1094,6 +1097,14 @@ SPIRVInstruction *SPIRVModuleImpl::addTaskSequenceGetINTELInst( BB); } +SPIRVInstruction *SPIRVModuleImpl::addCooperativeMatrixLengthKHRInst( + SPIRVType *RetTy, SPIRVType *MatTy, SPIRVBasicBlock *BB) { + return addInstruction( + SPIRVInstTemplateBase::create(OpCooperativeMatrixLengthKHR, RetTy, + getId(), getVec(MatTy->getId()), BB, this), + BB); +} + SPIRVType *SPIRVModuleImpl::addOpaqueGenericType(Op TheOpCode) { return addType(new SPIRVTypeOpaqueGeneric(TheOpCode, this, getId())); } diff --git a/lib/SPIRV/libSPIRV/SPIRVModule.h b/lib/SPIRV/libSPIRV/SPIRVModule.h index 41932cce..8b2b0462 100644 --- a/lib/SPIRV/libSPIRV/SPIRVModule.h +++ b/lib/SPIRV/libSPIRV/SPIRVModule.h @@ -272,6 +272,9 @@ class SPIRVModule { virtual SPIRVTypeTaskSequenceINTEL *addTaskSequenceINTELType() = 0; virtual SPIRVInstruction * addTaskSequenceGetINTELInst(SPIRVType *, SPIRVValue *, SPIRVBasicBlock *) = 0; + virtual SPIRVInstruction * + addCooperativeMatrixLengthKHRInst(SPIRVType *, SPIRVType *, + SPIRVBasicBlock *) = 0; virtual SPIRVTypeVoid *addVoidType() = 0; virtual SPIRVType *addOpaqueGenericType(Op) = 0; virtual SPIRVTypeDeviceEvent *addDeviceEventType() = 0; diff --git a/test/extensions/INTEL/SPV_INTEL_joint_matrix/cooperative_matrix_checked.ll b/test/extensions/INTEL/SPV_INTEL_joint_matrix/cooperative_matrix_checked.ll index 1c43d2f3..1cebf53c 100644 --- a/test/extensions/INTEL/SPV_INTEL_joint_matrix/cooperative_matrix_checked.ll +++ b/test/extensions/INTEL/SPV_INTEL_joint_matrix/cooperative_matrix_checked.ll @@ -32,8 +32,7 @@ ; CHECK-SPIRV-DAG: TypeCooperativeMatrixKHR [[#MatTy3:]] [[#Int8Ty]] [[#Const2]] [[#Const48]] [[#Const12]] [[#Const1]] ; CHECK-SPIRV: CooperativeMatrixConstructCheckedINTEL [[#MatTy1]] ; CHECK-SPIRV: CooperativeMatrixLoadCheckedINTEL [[#MatTy2]] [[#Load1:]] -; TODO: Pass Matrix Type Id instead of Matrix Id to CooperativeMatrixLengthKHR. -; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#Load1]] +; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#MatTy2]] ; CHECK-SPIRV: CooperativeMatrixLoadCheckedINTEL [[#MatTy3]] ; CHECK-SPIRV: CooperativeMatrixMulAddKHR [[#MatTy1]] ; CHECK-SPIRV: CooperativeMatrixStoreCheckedINTEL diff --git a/test/extensions/INTEL/SPV_INTEL_joint_matrix/cooperative_matrix_prefetch.ll b/test/extensions/INTEL/SPV_INTEL_joint_matrix/cooperative_matrix_prefetch.ll index 53f6a51a..480832d6 100644 --- a/test/extensions/INTEL/SPV_INTEL_joint_matrix/cooperative_matrix_prefetch.ll +++ b/test/extensions/INTEL/SPV_INTEL_joint_matrix/cooperative_matrix_prefetch.ll @@ -32,8 +32,7 @@ ; CHECK-SPIRV-DAG: TypeCooperativeMatrixKHR [[#MatTy3:]] [[#Int8Ty]] [[#Const2]] [[#Const48]] [[#Const12]] [[#Const1]] ; CHECK-SPIRV: CompositeConstruct [[#MatTy1]] ; CHECK-SPIRV: CooperativeMatrixLoadKHR [[#MatTy2]] [[#Load1:]] -; TODO: Pass Matrix Type Id instead of Matrix Id to CooperativeMatrixLengthKHR. -; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#Load1]] +; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#MatTy2]] ; CHECK-SPIRV: CooperativeMatrixPrefetchINTEL ; CHECK-SPIRV: CooperativeMatrixLoadKHR [[#MatTy3]] ; CHECK-SPIRV: CooperativeMatrixMulAddKHR [[#MatTy1]] diff --git a/test/extensions/KHR/SPV_KHR_cooperative_matrix/cooperative_matrix.ll b/test/extensions/KHR/SPV_KHR_cooperative_matrix/cooperative_matrix.ll index 71d7139e..4e99ab4c 100644 --- a/test/extensions/KHR/SPV_KHR_cooperative_matrix/cooperative_matrix.ll +++ b/test/extensions/KHR/SPV_KHR_cooperative_matrix/cooperative_matrix.ll @@ -30,8 +30,7 @@ ; CHECK-SPIRV-DAG: TypeCooperativeMatrixKHR [[#MatTy3:]] [[#Int8Ty]] [[#Const2]] [[#Const48]] [[#Const12]] [[#Const1]] ; CHECK-SPIRV: CompositeConstruct [[#MatTy1]] ; CHECK-SPIRV: CooperativeMatrixLoadKHR [[#MatTy2]] [[#Load1:]] -; TODO: Pass Matrix Type Id instead of Matrix Id to CooperativeMatrixLengthKHR. -; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#Load1]] +; CHECK-SPIRV: CooperativeMatrixLengthKHR [[#Int32Ty]] [[#]] [[#MatTy2]] ; CHECK-SPIRV: CooperativeMatrixLoadKHR [[#MatTy3]] ; CHECK-SPIRV: CooperativeMatrixMulAddKHR [[#MatTy1]] ; CHECK-SPIRV: CooperativeMatrixStoreKHR