Skip to content

Commit 836d326

Browse files
pratikasharsys_zuul
authored andcommitted
Decode DIExpression operation in SPIRV reader
Change-Id: Ic385642ef9799d5a2f983ff7b4141e43f3fd6ecf
1 parent cb3ed54 commit 836d326

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,47 @@ class SPIRVToLLVMDbgTran {
241241
if (auto n = getExistingNode<DIExpression*>(inst))
242242
return n;
243243

244-
return addMDNode(inst, Builder.createExpression());
244+
OpDebugExpression dbgExpr(inst);
245+
246+
auto numOperations = dbgExpr.getNumOperations();
247+
248+
llvm::SmallVector<uint64_t, 5> Exprs;
249+
for (unsigned int i = 0; i != numOperations; ++i)
250+
{
251+
OpDebugOperation operation(BM->get<SPIRVExtInst>(dbgExpr.getOperation(i)));
252+
switch (operation.getOperation())
253+
{
254+
case SPIRVDebug::ExpressionOpCode::Deref:
255+
Exprs.push_back(llvm::dwarf::DW_OP_deref); break;
256+
case SPIRVDebug::ExpressionOpCode::Plus:
257+
Exprs.push_back(llvm::dwarf::DW_OP_plus); break;
258+
case SPIRVDebug::ExpressionOpCode::Minus:
259+
Exprs.push_back(llvm::dwarf::DW_OP_minus); break;
260+
case SPIRVDebug::ExpressionOpCode::PlusUconst:
261+
Exprs.push_back(llvm::dwarf::DW_OP_plus_uconst); break;
262+
case SPIRVDebug::ExpressionOpCode::BitPiece:
263+
Exprs.push_back(llvm::dwarf::DW_OP_bit_piece); break;
264+
case SPIRVDebug::ExpressionOpCode::Swap:
265+
Exprs.push_back(llvm::dwarf::DW_OP_swap); break;
266+
case SPIRVDebug::ExpressionOpCode::Xderef:
267+
Exprs.push_back(llvm::dwarf::DW_OP_xderef); break;
268+
case SPIRVDebug::ExpressionOpCode::StackValue:
269+
Exprs.push_back(llvm::dwarf::DW_OP_stack_value); break;
270+
case SPIRVDebug::ExpressionOpCode::Constu:
271+
Exprs.push_back(llvm::dwarf::DW_OP_constu); break;
272+
case SPIRVDebug::ExpressionOpCode::Fragment:
273+
Exprs.push_back(llvm::dwarf::DW_OP_LLVM_fragment); break;
274+
default:
275+
break;
276+
}
277+
278+
for (unsigned int j = 0; j != operation.getNumLiterals(); ++j)
279+
{
280+
Exprs.push_back(operation.getLiteral(j));
281+
}
282+
}
283+
284+
return addMDNode(inst, Builder.createExpression(Exprs));
245285
}
246286

247287
DIType* createTypeBasic(SPIRVExtInst* inst)

IGC/AdaptorOCL/SPIRV/libSPIRV/SPIRVDebugInfoExt.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,5 +871,22 @@ namespace spv {
871871
SPIRVWord getLine() { return arg<SPIRVWord>(SPIRVDebug::Operand::TemplateTemplateParameter::LineIdx); }
872872
SPIRVWord getColumn() { return arg<SPIRVWord>(SPIRVDebug::Operand::TemplateTemplateParameter::ColumnIdx); }
873873
};
874+
875+
class OpDebugExpression : OpDebugInfoBase
876+
{
877+
public:
878+
OpDebugExpression(SPIRVExtInst* extInst) : OpDebugInfoBase(extInst) {}
879+
SPIRVId getOperation(unsigned int idx) { return arg<SPIRVId>(idx); }
880+
unsigned int getNumOperations() { return getNumArgs(); }
881+
};
882+
883+
class OpDebugOperation : OpDebugInfoBase
884+
{
885+
public:
886+
OpDebugOperation(SPIRVExtInst* extInst) : OpDebugInfoBase(extInst) {}
887+
unsigned int getNumLiterals() { return getNumArgs() - SPIRVDebug::Operand::Operation::OpCodeIdx - 1; }
888+
unsigned int getLiteral(unsigned int idx) { return arg<SPIRVWord>(idx + SPIRVDebug::Operand::Operation::OpCodeIdx + 1); }
889+
SPIRVWord getOperation() { return arg<SPIRVWord>(SPIRVDebug::Operand::Operation::OpCodeIdx); }
890+
};
874891
}
875892
#endif

0 commit comments

Comments
 (0)