@@ -91,7 +91,8 @@ SPIRVExtInst *SPIRVToLLVMDbgTran::getDbgInst(const SPIRVId Id) {
91
91
if (isa<OpExtInst>(E)) {
92
92
SPIRVExtInst *EI = static_cast <SPIRVExtInst *>(E);
93
93
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)
95
96
return EI;
96
97
}
97
98
return nullptr ;
@@ -192,6 +193,14 @@ DIType *SPIRVToLLVMDbgTran::transTypePointer(const SPIRVExtInst *DebugInst) {
192
193
193
194
DICompositeType *
194
195
SPIRVToLLVMDbgTran::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) {
195
204
using namespace SPIRVDebug ::Operand::TypeArray;
196
205
const SPIRVWordVec &Ops = DebugInst->getArguments ();
197
206
assert (Ops.size () >= MinOperandCount && " Invalid number of operands" );
@@ -246,6 +255,28 @@ SPIRVToLLVMDbgTran::transTypeArray(const SPIRVExtInst *DebugInst) {
246
255
return Builder.createArrayType (Size , 0 /* align*/ , BaseTy, SubscriptArray);
247
256
}
248
257
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
+
249
280
DICompositeType *
250
281
SPIRVToLLVMDbgTran::transTypeVector (const SPIRVExtInst *DebugInst) {
251
282
using namespace SPIRVDebug ::Operand::TypeVector;
@@ -286,6 +317,8 @@ SPIRVToLLVMDbgTran::transTypeComposite(const SPIRVExtInst *DebugInst) {
286
317
SPIRVEntry *SizeEntry = BM->getEntry (Ops[SizeIdx]);
287
318
if (!(SizeEntry->isExtInst (SPIRVEIS_Debug, SPIRVDebug::DebugInfoNone) ||
288
319
SizeEntry->isExtInst (SPIRVEIS_OpenCL_DebugInfo_100,
320
+ SPIRVDebug::DebugInfoNone) ||
321
+ SizeEntry->isExtInst (SPIRVEIS_NonSemantic_Kernel_DebugInfo_100,
289
322
SPIRVDebug::DebugInfoNone))) {
290
323
Size = BM->get <SPIRVConstant>(Ops[SizeIdx])->getZExtIntValue ();
291
324
}
@@ -341,6 +374,36 @@ SPIRVToLLVMDbgTran::transTypeComposite(const SPIRVExtInst *DebugInst) {
341
374
return CT;
342
375
}
343
376
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
+
344
407
DINode *SPIRVToLLVMDbgTran::transTypeMember (const SPIRVExtInst *DebugInst) {
345
408
using namespace SPIRVDebug ::Operand::TypeMember;
346
409
const SPIRVWordVec &Ops = DebugInst->getArguments ();
@@ -887,6 +950,9 @@ MDNode *SPIRVToLLVMDbgTran::transDebugInstImpl(const SPIRVExtInst *DebugInst) {
887
950
case SPIRVDebug::TypeArray:
888
951
return transTypeArray (DebugInst);
889
952
953
+ case SPIRVDebug::TypeSubrange:
954
+ return transTypeSubrange (DebugInst);
955
+
890
956
case SPIRVDebug::TypeVector:
891
957
return transTypeVector (DebugInst);
892
958
0 commit comments