@@ -91,7 +91,8 @@ SPIRVExtInst *SPIRVToLLVMDbgTran::getDbgInst(const SPIRVId Id) {
9191 if (isa<OpExtInst>(E)) {
9292 SPIRVExtInst *EI = static_cast <SPIRVExtInst *>(E);
9393 if (EI->getExtSetKind () == SPIRV::SPIRVEIS_Debug ||
94- EI->getExtSetKind () == SPIRV::SPIRVEIS_OpenCL_DebugInfo_100)
94+ EI->getExtSetKind () == SPIRV::SPIRVEIS_OpenCL_DebugInfo_100 ||
95+ EI->getExtSetKind () == SPIRV::SPIRVEIS_NonSemantic_Kernel_DebugInfo_100)
9596 return EI;
9697 }
9798 return nullptr ;
@@ -192,6 +193,14 @@ DIType *SPIRVToLLVMDbgTran::transTypePointer(const SPIRVExtInst *DebugInst) {
192193
193194DICompositeType *
194195SPIRVToLLVMDbgTran::transTypeArray (const SPIRVExtInst *DebugInst) {
196+ if (DebugInst->getExtSetKind () == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100)
197+ return transTypeArrayNonSemantic (DebugInst);
198+
199+ return transTypeArrayOpenCL (DebugInst);
200+ }
201+
202+ DICompositeType *
203+ SPIRVToLLVMDbgTran::transTypeArrayOpenCL (const SPIRVExtInst *DebugInst) {
195204 using namespace SPIRVDebug ::Operand::TypeArray;
196205 const SPIRVWordVec &Ops = DebugInst->getArguments ();
197206 assert (Ops.size () >= MinOperandCount && " Invalid number of operands" );
@@ -246,6 +255,28 @@ SPIRVToLLVMDbgTran::transTypeArray(const SPIRVExtInst *DebugInst) {
246255 return Builder.createArrayType (Size, 0 /* align*/ , BaseTy, SubscriptArray);
247256}
248257
258+ DICompositeType *
259+ SPIRVToLLVMDbgTran::transTypeArrayNonSemantic (const SPIRVExtInst *DebugInst) {
260+ using namespace SPIRVDebug ::Operand::TypeArray;
261+ const SPIRVWordVec &Ops = DebugInst->getArguments ();
262+ assert (Ops.size () >= MinOperandCount && " Invalid number of operands" );
263+ DIType *BaseTy =
264+ transDebugInst<DIType>(BM->get <SPIRVExtInst>(Ops[BaseTypeIdx]));
265+ size_t TotalCount = 1 ;
266+ SmallVector<llvm::Metadata *, 8 > Subscripts;
267+ if (DebugInst->getExtOp () == SPIRVDebug::TypeArray) {
268+ for (size_t I = SubrangesIdx; I < Ops.size (); ++I) {
269+ auto *SR = transDebugInst<DISubrange>(BM->get <SPIRVExtInst>(Ops[I]));
270+ if (auto *Count = SR->getCount ().get <ConstantInt *>())
271+ TotalCount *= Count->getZExtValue () > 0 ? Count->getZExtValue () : 0 ;
272+ Subscripts.push_back (SR);
273+ }
274+ }
275+ DINodeArray SubscriptArray = Builder.getOrCreateArray (Subscripts);
276+ size_t Size = getDerivedSizeInBits (BaseTy) * TotalCount;
277+ return Builder.createArrayType (Size, 0 /* align*/ , BaseTy, SubscriptArray);
278+ }
279+
249280DICompositeType *
250281SPIRVToLLVMDbgTran::transTypeVector (const SPIRVExtInst *DebugInst) {
251282 using namespace SPIRVDebug ::Operand::TypeVector;
@@ -286,6 +317,8 @@ SPIRVToLLVMDbgTran::transTypeComposite(const SPIRVExtInst *DebugInst) {
286317 SPIRVEntry *SizeEntry = BM->getEntry (Ops[SizeIdx]);
287318 if (!(SizeEntry->isExtInst (SPIRVEIS_Debug, SPIRVDebug::DebugInfoNone) ||
288319 SizeEntry->isExtInst (SPIRVEIS_OpenCL_DebugInfo_100,
320+ SPIRVDebug::DebugInfoNone) ||
321+ SizeEntry->isExtInst (SPIRVEIS_NonSemantic_Kernel_DebugInfo_100,
289322 SPIRVDebug::DebugInfoNone))) {
290323 Size = BM->get <SPIRVConstant>(Ops[SizeIdx])->getZExtIntValue ();
291324 }
@@ -341,6 +374,36 @@ SPIRVToLLVMDbgTran::transTypeComposite(const SPIRVExtInst *DebugInst) {
341374 return CT;
342375}
343376
377+ DISubrange *
378+ SPIRVToLLVMDbgTran::transTypeSubrange (const SPIRVExtInst *DebugInst) {
379+ using namespace SPIRVDebug ::Operand::TypeSubrange;
380+ const SPIRVWordVec &Ops = DebugInst->getArguments ();
381+ assert (Ops.size () == OperandCount && " Invalid number of operands" );
382+ std::vector<Metadata *> TranslatedOps (OperandCount, nullptr );
383+ auto TransOperand = [&Ops, &TranslatedOps, this ](int Idx) -> void {
384+ if (!getDbgInst<SPIRVDebug::DebugInfoNone>(Ops[Idx])) {
385+ if (auto *GlobalVar = getDbgInst<SPIRVDebug::GlobalVariable>(Ops[Idx])) {
386+ TranslatedOps[Idx] =
387+ cast<Metadata>(transDebugInst<DIGlobalVariable>(GlobalVar));
388+ } else if (auto *LocalVar =
389+ getDbgInst<SPIRVDebug::LocalVariable>(Ops[Idx])) {
390+ TranslatedOps[Idx] =
391+ cast<Metadata>(transDebugInst<DILocalVariable>(LocalVar));
392+ } else if (auto *Expr = getDbgInst<SPIRVDebug::Expression>(Ops[Idx])) {
393+ TranslatedOps[Idx] = cast<Metadata>(transDebugInst<DIExpression>(Expr));
394+ } else if (auto *Const = BM->get <SPIRVConstant>(Ops[Idx])) {
395+ int64_t ConstantAsInt = static_cast <int64_t >(Const->getZExtIntValue ());
396+ TranslatedOps[Idx] = cast<Metadata>(ConstantAsMetadata::get (
397+ ConstantInt::get (M->getContext (), APInt (64 , ConstantAsInt))));
398+ }
399+ }
400+ };
401+ for (int Idx = CountIdx; Idx < OperandCount; ++Idx)
402+ TransOperand (Idx);
403+ return Builder.getOrCreateSubrange (TranslatedOps[0 ], TranslatedOps[1 ],
404+ TranslatedOps[2 ], TranslatedOps[3 ]);
405+ }
406+
344407DINode *SPIRVToLLVMDbgTran::transTypeMember (const SPIRVExtInst *DebugInst) {
345408 using namespace SPIRVDebug ::Operand::TypeMember;
346409 const SPIRVWordVec &Ops = DebugInst->getArguments ();
@@ -887,6 +950,9 @@ MDNode *SPIRVToLLVMDbgTran::transDebugInstImpl(const SPIRVExtInst *DebugInst) {
887950 case SPIRVDebug::TypeArray:
888951 return transTypeArray (DebugInst);
889952
953+ case SPIRVDebug::TypeSubrange:
954+ return transTypeSubrange (DebugInst);
955+
890956 case SPIRVDebug::TypeVector:
891957 return transTypeVector (DebugInst);
892958
0 commit comments