47
47
48
48
#include " llvm/ADT/StringExtras.h"
49
49
#include " llvm/IR/DIBuilder.h"
50
+ #include " llvm/IR/DebugProgramInstruction.h"
50
51
#include " llvm/IR/IntrinsicInst.h"
51
52
#include " llvm/IR/Module.h"
52
53
@@ -1547,7 +1548,7 @@ MDNode *SPIRVToLLVMDbgTran::transDebugInstImpl(const SPIRVExtInst *DebugInst) {
1547
1548
}
1548
1549
}
1549
1550
1550
- Instruction *
1551
+ DbgInstPtr
1551
1552
SPIRVToLLVMDbgTran::transDebugIntrinsic (const SPIRVExtInst *DebugInst,
1552
1553
BasicBlock *BB) {
1553
1554
auto GetLocalVar = [&](SPIRVId Id) -> std::pair<DILocalVariable *, DebugLoc> {
@@ -1572,6 +1573,7 @@ SPIRVToLLVMDbgTran::transDebugIntrinsic(const SPIRVExtInst *DebugInst,
1572
1573
case SPIRVDebug::Declare: {
1573
1574
using namespace SPIRVDebug ::Operand::DebugDeclare;
1574
1575
auto LocalVar = GetLocalVar (Ops[DebugLocalVarIdx]);
1576
+ DIBuilder &DIB = getDIBuilder (DebugInst);
1575
1577
if (getDbgInst<SPIRVDebug::DebugInfoNone>(Ops[VariableIdx])) {
1576
1578
// If we don't have the variable(e.g. alloca might be promoted by mem2reg)
1577
1579
// we should generate the following IR:
@@ -1581,16 +1583,15 @@ SPIRVToLLVMDbgTran::transDebugIntrinsic(const SPIRVExtInst *DebugInst,
1581
1583
// parameter. To work around this limitation we create a dummy temp
1582
1584
// alloca, use it to create llvm.dbg.declare, and then remove the alloca.
1583
1585
auto *AI = new AllocaInst (Type::getInt8Ty (M->getContext ()), 0 , " tmp" , BB);
1584
- DbgInstPtr DbgDeclare = getDIBuilder (DebugInst) .insertDeclare (
1586
+ DbgInstPtr DbgDeclare = DIB .insertDeclare (
1585
1587
AI, LocalVar.first , GetExpression (Ops[ExpressionIdx]),
1586
1588
LocalVar.second , BB);
1587
1589
AI->eraseFromParent ();
1588
- return DbgDeclare. get <Instruction *>() ;
1590
+ return DbgDeclare;
1589
1591
}
1590
- return getDIBuilder (DebugInst)
1591
- .insertDeclare (GetValue (Ops[VariableIdx]), LocalVar.first ,
1592
- GetExpression (Ops[ExpressionIdx]), LocalVar.second , BB)
1593
- .get <Instruction *>();
1592
+ return DIB.insertDeclare (GetValue (Ops[VariableIdx]), LocalVar.first ,
1593
+ GetExpression (Ops[ExpressionIdx]), LocalVar.second ,
1594
+ BB);
1594
1595
}
1595
1596
case SPIRVDebug::Value: {
1596
1597
using namespace SPIRVDebug ::Operand::DebugValue;
@@ -1606,10 +1607,15 @@ SPIRVToLLVMDbgTran::transDebugIntrinsic(const SPIRVExtInst *DebugInst,
1606
1607
}
1607
1608
if (!MDs.empty ()) {
1608
1609
DIArgList *AL = DIArgList::get (M->getContext (), MDs);
1609
- cast<DbgVariableIntrinsic>(DbgValIntr.get <Instruction *>())
1610
- ->setRawLocation (AL);
1610
+ if (M->IsNewDbgInfoFormat ) {
1611
+ cast<DbgVariableRecord>(DbgValIntr.get <DbgRecord *>())
1612
+ ->setRawLocation (AL);
1613
+ } else {
1614
+ cast<DbgVariableIntrinsic>(DbgValIntr.get <Instruction *>())
1615
+ ->setRawLocation (AL);
1616
+ }
1611
1617
}
1612
- return DbgValIntr. get <Instruction *>() ;
1618
+ return DbgValIntr;
1613
1619
}
1614
1620
default :
1615
1621
llvm_unreachable (" Unknown debug intrinsic!" );
0 commit comments