4747
4848#include " llvm/ADT/StringExtras.h"
4949#include " llvm/IR/DIBuilder.h"
50+ #include " llvm/IR/DebugProgramInstruction.h"
5051#include " llvm/IR/IntrinsicInst.h"
5152#include " llvm/IR/Module.h"
5253
@@ -1547,7 +1548,7 @@ MDNode *SPIRVToLLVMDbgTran::transDebugInstImpl(const SPIRVExtInst *DebugInst) {
15471548 }
15481549}
15491550
1550- Instruction *
1551+ DbgInstPtr
15511552SPIRVToLLVMDbgTran::transDebugIntrinsic (const SPIRVExtInst *DebugInst,
15521553 BasicBlock *BB) {
15531554 auto GetLocalVar = [&](SPIRVId Id) -> std::pair<DILocalVariable *, DebugLoc> {
@@ -1572,6 +1573,7 @@ SPIRVToLLVMDbgTran::transDebugIntrinsic(const SPIRVExtInst *DebugInst,
15721573 case SPIRVDebug::Declare: {
15731574 using namespace SPIRVDebug ::Operand::DebugDeclare;
15741575 auto LocalVar = GetLocalVar (Ops[DebugLocalVarIdx]);
1576+ DIBuilder &DIB = getDIBuilder (DebugInst);
15751577 if (getDbgInst<SPIRVDebug::DebugInfoNone>(Ops[VariableIdx])) {
15761578 // If we don't have the variable(e.g. alloca might be promoted by mem2reg)
15771579 // we should generate the following IR:
@@ -1581,16 +1583,15 @@ SPIRVToLLVMDbgTran::transDebugIntrinsic(const SPIRVExtInst *DebugInst,
15811583 // parameter. To work around this limitation we create a dummy temp
15821584 // alloca, use it to create llvm.dbg.declare, and then remove the alloca.
15831585 auto *AI = new AllocaInst (Type::getInt8Ty (M->getContext ()), 0 , " tmp" , BB);
1584- DbgInstPtr DbgDeclare = getDIBuilder (DebugInst) .insertDeclare (
1586+ DbgInstPtr DbgDeclare = DIB .insertDeclare (
15851587 AI, LocalVar.first , GetExpression (Ops[ExpressionIdx]),
15861588 LocalVar.second , BB);
15871589 AI->eraseFromParent ();
1588- return DbgDeclare. get <Instruction *>() ;
1590+ return DbgDeclare;
15891591 }
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);
15941595 }
15951596 case SPIRVDebug::Value: {
15961597 using namespace SPIRVDebug ::Operand::DebugValue;
@@ -1606,10 +1607,15 @@ SPIRVToLLVMDbgTran::transDebugIntrinsic(const SPIRVExtInst *DebugInst,
16061607 }
16071608 if (!MDs.empty ()) {
16081609 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+ }
16111617 }
1612- return DbgValIntr. get <Instruction *>() ;
1618+ return DbgValIntr;
16131619 }
16141620 default :
16151621 llvm_unreachable (" Unknown debug intrinsic!" );
0 commit comments