Skip to content

Commit d02158d

Browse files
committed
Fix in SPIRV debug info adaptor to emit all dimensions of multi-dimensional array in debug info.
Change-Id: I116fe8bb9c38b33e497b41b7bbca6563c3ac35a3
1 parent acd338e commit d02158d

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,22 @@ class SPIRVToLLVMDbgTran {
318318

319319
OpDebugTypeArray arrayType(inst);
320320

321-
auto size = BM->get<SPIRVConstant>(arrayType.getComponentCount())->getZExtIntValue();
322321
auto baseType = createType(BM->get<SPIRVExtInst>(arrayType.getBaseType()));
322+
auto numDims = arrayType.getNumDims();
323323

324-
auto sr = Builder.getOrCreateSubrange(0, size-1);
325-
auto mds = llvm::makeArrayRef(llvm::cast<llvm::Metadata>(sr));
326-
llvm::DINodeArray subscripts = llvm::MDTuple::get(M->getContext(), mds);
324+
SmallVector<llvm::Metadata *, 8> subscripts;
325+
uint64_t totalCount = 1;
327326

328-
return addMDNode(inst, Builder.createArrayType(size * baseType->getSizeInBits(), 0, baseType, subscripts));
327+
for (unsigned int i = 0; i != numDims; i++)
328+
{
329+
auto val = BM->get<SPIRVConstant>(arrayType.getComponentCount(i))->getZExtIntValue();
330+
subscripts.push_back(Builder.getOrCreateSubrange(0, val));
331+
totalCount *= (uint64_t)(val);
332+
}
333+
334+
DINodeArray subscriptArray = Builder.getOrCreateArray(subscripts);
335+
336+
return addMDNode(inst, Builder.createArrayType(totalCount * baseType->getSizeInBits(), 0, baseType, subscriptArray));
329337
}
330338

331339
DIType* createTypeVector(SPIRVExtInst* inst)
@@ -338,11 +346,11 @@ class SPIRVToLLVMDbgTran {
338346
auto size = vectorType.getNumComponents();
339347
auto type = createType(BM->get<SPIRVExtInst>(vectorType.getBaseType()));
340348

341-
auto sr = Builder.getOrCreateSubrange(0, size);
342-
auto mds = llvm::makeArrayRef(llvm::cast<llvm::Metadata>(sr));
343-
llvm::DINodeArray subscripts = llvm::MDTuple::get(M->getContext(), mds);
349+
SmallVector<llvm::Metadata *, 8> subscripts;
350+
subscripts.push_back(Builder.getOrCreateSubrange(0, size));
351+
DINodeArray subscriptArray = Builder.getOrCreateArray(subscripts);
344352

345-
return addMDNode(inst, Builder.createVectorType(size, 0, type, subscripts));
353+
return addMDNode(inst, Builder.createVectorType(size * type->getSizeInBits(), 0, type, subscriptArray));
346354
}
347355

348356
DIType* createTypeDef(SPIRVExtInst* inst)

IGC/AdaptorOCL/SPIRV/libSPIRV/SPIRVDebugInfoExt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,8 @@ namespace spv {
660660
public:
661661
OpDebugTypeArray(SPIRVExtInst* extInst) : OpDebugInfoBase(extInst) {}
662662
SPIRVId getBaseType() { return arg<SPIRVId>(SPIRVDebug::Operand::TypeArray::BaseTypeIdx); }
663-
SPIRVId getComponentCount() { return arg<SPIRVId>(SPIRVDebug::Operand::TypeArray::ComponentCountIdx); }
663+
SPIRVWord getNumDims() { return (getNumArgs() - SPIRVDebug::Operand::TypeArray::ComponentCountIdx); }
664+
SPIRVId getComponentCount(unsigned int i) { return arg<SPIRVId>(i + SPIRVDebug::Operand::TypeArray::ComponentCountIdx); }
664665
};
665666

666667
class OpDebugTypeVector : OpDebugInfoBase

0 commit comments

Comments
 (0)