Skip to content

Commit 2f75ef0

Browse files
svenvhjsji
authored andcommitted
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`. Original commit: KhronosGroup/SPIRV-LLVM-Translator@04b546550077c4f
1 parent 2070a4b commit 2f75ef0

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

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

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

llvm-spirv/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)