Skip to content

Commit 04b5465

Browse files
authored
SPIRVReader: Support OpConstantComposite for cooperative matrix (#2826)
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`.
1 parent cf69733 commit 04b5465

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,21 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
15111511

15121512
return mapValue(BV, ConstantStruct::get(BCCTy, CV));
15131513
}
1514+
case OpTypeCooperativeMatrixKHR: {
1515+
assert(CV.size() == 1 &&
1516+
"expecting exactly one operand for cooperative matrix types");
1517+
llvm::Type *RetTy = transType(BCC->getType());
1518+
llvm::Type *EltTy = transType(
1519+
static_cast<const SPIRVTypeCooperativeMatrixKHR *>(BV->getType())
1520+
->getCompType());
1521+
auto *FTy = FunctionType::get(RetTy, {EltTy}, false);
1522+
FunctionCallee Func =
1523+
M->getOrInsertFunction(getSPIRVFuncName(OC, RetTy), FTy);
1524+
IRBuilder<> Builder(BB);
1525+
CallInst *Call = Builder.CreateCall(Func, CV.front());
1526+
Call->setCallingConv(CallingConv::SPIR_FUNC);
1527+
return Call;
1528+
}
15141529
default:
15151530
llvm_unreachable("not implemented");
15161531
return nullptr;

lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ SPIRVToLLVMDbgTran::getStringSourceContinued(const SPIRVId Id,
152152
}
153153

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

159161
if (Instruction *I = dyn_cast<Instruction>(V)) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; REQUIRES: spirv-as
2+
; RUN: spirv-as --target-env spv1.0 -o %t.spv %s
3+
; TODO: re-enable spirv-val
4+
; R/U/N: spirv-val %t.spv
5+
; RUN: llvm-spirv -r -o - %t.spv | llvm-dis | FileCheck %s
6+
7+
OpCapability Addresses
8+
OpCapability Kernel
9+
OpCapability CooperativeMatrixKHR
10+
OpExtension "SPV_KHR_cooperative_matrix"
11+
OpMemoryModel Physical64 OpenCL
12+
OpEntryPoint Kernel %1 "testCoopMat"
13+
%void = OpTypeVoid
14+
%uint = OpTypeInt 32 0
15+
%_ptr_CrossWorkgroup_uint = OpTypePointer CrossWorkgroup %uint
16+
%fnTy = OpTypeFunction %void %_ptr_CrossWorkgroup_uint
17+
%uint_0 = OpConstant %uint 0
18+
%uint_3 = OpConstant %uint 3
19+
%uint_8 = OpConstant %uint 8
20+
%uint_42 = OpConstant %uint 42
21+
%matTy = OpTypeCooperativeMatrixKHR %uint %uint_3 %uint_8 %uint_8 %uint_0
22+
%matConst = OpConstantComposite %matTy %uint_42
23+
%1 = OpFunction %void None %fnTy
24+
%outPtr = OpFunctionParameter %_ptr_CrossWorkgroup_uint
25+
%2 = OpLabel
26+
OpCooperativeMatrixStoreKHR %outPtr %matConst %uint_0 %uint_8
27+
OpReturn
28+
OpFunctionEnd
29+
30+
; CHECK: call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 8, 8, 0) @__spirv_ConstantComposite_RPU3AS142__spirv_CooperativeMatrixKHR__uint_3_8_8_0(i32 42)

0 commit comments

Comments
 (0)