Skip to content

Commit 376fcf3

Browse files
MrSidimssys-ce-bb
authored andcommitted
Continue fixing translation of debug info for mem2reged vars (#3119)
It's a follow up to 367ede2 with the following additions: 1. don't create unnecessary temporary alloca, instead create nullptr const - this helps tooling later on as it won't deal with poison; 2. partially revert a change in reverse translation resetting debug location for debug declarations - we should always try to get location information from DebugScope, and fall back to LocalVar only if DebugScope doesn't provide such information. Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com> --------- Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com> Original commit: KhronosGroup/SPIRV-LLVM-Translator@610059c3e287d71
1 parent 59fd9db commit 376fcf3

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,25 +1574,17 @@ SPIRVToLLVMDbgTran::transDebugIntrinsic(const SPIRVExtInst *DebugInst,
15741574
case SPIRVDebug::Declare: {
15751575
using namespace SPIRVDebug::Operand::DebugDeclare;
15761576
auto LocalVar = GetLocalVar(Ops[DebugLocalVarIdx]);
1577+
DebugLoc Loc = transDebugScope(DebugInst);
1578+
if (!Loc)
1579+
Loc = LocalVar.second;
15771580
DIBuilder &DIB = getDIBuilder(DebugInst);
15781581
if (getDbgInst<SPIRVDebug::DebugInfoNone>(Ops[VariableIdx])) {
1579-
// If we don't have the variable(e.g. alloca might be promoted by mem2reg)
1580-
// we should generate the following IR:
1581-
// call void @llvm.dbg.declare(metadata !4, metadata !14, metadata !5)
1582-
// !4 = !{}
1583-
// DIBuilder::insertDeclare doesn't allow to pass nullptr for the Storage
1584-
// parameter. To work around this limitation we create a dummy temp
1585-
// alloca, use it to create llvm.dbg.declare, and then remove the alloca.
1586-
auto *AI =
1587-
new AllocaInst(Type::getInt8Ty(M->getContext()),
1588-
M->getDataLayout().getAllocaAddrSpace(), "tmp", BB);
1582+
auto *Null =
1583+
ConstantPointerNull::get(PointerType::get(M->getContext(), 0));
15891584
DbgInstPtr DbgDeclare = DIB.insertDeclare(
1590-
AI, LocalVar.first, GetExpression(Ops[ExpressionIdx]),
1591-
LocalVar.second, BB);
1592-
AI->eraseFromParent();
1585+
Null, LocalVar.first, GetExpression(Ops[ExpressionIdx]), Loc, BB);
15931586
return DbgDeclare;
15941587
}
1595-
DebugLoc Loc = transDebugScope(DebugInst);
15961588
return DIB.insertDeclare(GetValue(Ops[VariableIdx]), LocalVar.first,
15971589
GetExpression(Ops[ExpressionIdx]), Loc,
15981590
BB);

llvm-spirv/test/DebugInfo/DebugDeclareUnused.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ void foo() {
1616

1717
// CHECK-SPIRV: ExtInst [[#]] [[#InfoNone:]] [[#]] DebugInfoNone
1818
// CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugDeclare [[#]] [[#InfoNone]] [[#]]
19-
// CHECK-LLVM: #dbg_declare(ptr poison, ![[#]], !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), ![[#]])
19+
// CHECK-LLVM: #dbg_declare(ptr null, ![[#]], !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), ![[#]])

llvm-spirv/test/DebugInfo/mem2reged_local_var.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
; CHECK-SPIRV: ExtInst [[#]] [[#LocalVar:]] [[#]] DebugLocalVariable
2626
; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugDeclare [[#LocalVar]] [[#None]] [[#]]
2727

28-
; CHECK-LLVM: #dbg_declare(ptr poison, ![[#LocalVar:]], !DIExpression(DW_OP_constu, 4, DW_OP_swap, DW_OP_xderef), ![[#Loc:]])
28+
; CHECK-LLVM: #dbg_declare(ptr null, ![[#LocalVar:]], !DIExpression(DW_OP_constu, 4, DW_OP_swap, DW_OP_xderef), ![[#Loc:]])
2929
; CHECK-LLVM-DAG: ![[#LocalVar]] = !DILocalVariable(name: "bar"
3030
; CHECK-LLVM-DAG: ![[#Loc]] = !DILocation(line: 23
3131

0 commit comments

Comments
 (0)