Skip to content

Commit

Permalink
[Backport to 14] SPIRVReader: Support OpConstantComposite for coopera…
Browse files Browse the repository at this point in the history
…tive matrix (#2826) (#2850)

This was hitting a "not implemented UNREACHABLE".
Like the other cooperative matrix operations, map this construct to a
SPIR-V friendly IR function call.

Let `transDbgInfo` skip over `OpConstantComposite` because we're
mapping `OpConstantComposite` to an LLVM `Instruction` without having
a corresponding `SPIRVInstruction`.

(cherry picked from commit 04b5465)
  • Loading branch information
svenvh authored Nov 11, 2024
1 parent b42b955 commit e037e10
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,21 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
ConstantStruct::get(
dyn_cast<StructType>(transType(BCC->getType())), CV));
}
case OpTypeCooperativeMatrixKHR: {
assert(CV.size() == 1 &&
"expecting exactly one operand for cooperative matrix types");
llvm::Type *RetTy = transType(BCC->getType());
llvm::Type *EltTy = transType(
static_cast<const SPIRVTypeCooperativeMatrixKHR *>(BV->getType())
->getCompType());
auto *FTy = FunctionType::get(RetTy, {EltTy}, false);
FunctionCallee Func =
M->getOrInsertFunction(getSPIRVFuncName(OC, RetTy), FTy);
IRBuilder<> Builder(BB);
CallInst *Call = Builder.CreateCall(Func, CV.front());
Call->setCallingConv(CallingConv::SPIR_FUNC);
return Call;
}
default:
llvm_unreachable("not implemented");
return nullptr;
Expand Down
6 changes: 4 additions & 2 deletions lib/SPIRV/SPIRVToLLVMDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ SPIRVToLLVMDbgTran::getStringSourceContinued(const SPIRVId Id,
}

void SPIRVToLLVMDbgTran::transDbgInfo(const SPIRVValue *SV, Value *V) {
// A constant sampler does not have a corresponding SPIRVInstruction.
if (SV->getOpCode() == OpConstantSampler)
// Constant samplers and composites do not have a corresponding
// SPIRVInstruction, but they may be mapped to an LLVM Instruction.
if (SV->getOpCode() == OpConstantSampler ||
SV->getOpCode() == OpConstantComposite)
return;

if (Instruction *I = dyn_cast<Instruction>(V)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; REQUIRES: spirv-as
; RUN: spirv-as --target-env spv1.0 -o %t.spv %s
; TODO: re-enable spirv-val
; R/U/N: spirv-val %t.spv
; RUN: llvm-spirv -r -o - %t.spv | llvm-dis | FileCheck %s

OpCapability Addresses
OpCapability Kernel
OpCapability CooperativeMatrixKHR
OpExtension "SPV_KHR_cooperative_matrix"
OpMemoryModel Physical64 OpenCL
OpEntryPoint Kernel %1 "testCoopMat"
%void = OpTypeVoid
%uint = OpTypeInt 32 0
%_ptr_CrossWorkgroup_uint = OpTypePointer CrossWorkgroup %uint
%fnTy = OpTypeFunction %void %_ptr_CrossWorkgroup_uint
%uint_0 = OpConstant %uint 0
%uint_3 = OpConstant %uint 3
%uint_8 = OpConstant %uint 8
%uint_42 = OpConstant %uint 42
%matTy = OpTypeCooperativeMatrixKHR %uint %uint_3 %uint_8 %uint_8 %uint_0
%matConst = OpConstantComposite %matTy %uint_42
%1 = OpFunction %void None %fnTy
%outPtr = OpFunctionParameter %_ptr_CrossWorkgroup_uint
%2 = OpLabel
OpCooperativeMatrixStoreKHR %outPtr %matConst %uint_0 %uint_8
OpReturn
OpFunctionEnd

; CHECK: call spir_func %spirv.CooperativeMatrixKHR._int_3_8_8_0 addrspace(1)* @__spirv_ConstantComposite_RPU3AS141__spirv_CooperativeMatrixKHR__int_3_8_8_0(i32 42)

0 comments on commit e037e10

Please sign in to comment.