Skip to content

Commit f009df5

Browse files
MrSidimssys-ce-bb
authored andcommitted
Fix translation of some cases of mem2reged local variables (#3103)
We should translate null/undef declare records to DebugDeclare with OpDebugInfoNone instruction referenced in OpVariableId operand. TODO: currently the specification says, that only OpVariable can be referenced by this operand. This seem to be a spec bug, we should allow OpDebugInfoNone there. Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com> Original commit: KhronosGroup/SPIRV-LLVM-Translator@367ede2461181ae
1 parent 2557995 commit f009df5

File tree

5 files changed

+71
-13
lines changed

5 files changed

+71
-13
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ void LLVMToSPIRVDbgTran::finalizeDebugDeclare(
127127
using namespace SPIRVDebug::Operand::DebugDeclare;
128128
SPIRVWordVec Ops(OperandCount);
129129
Ops[DebugLocalVarIdx] = transDbgEntry(DbgDecl->getVariable())->getId();
130-
Ops[VariableIdx] = Alloca ? SPIRVWriter->transValue(Alloca, BB)->getId()
131-
: getDebugInfoNoneId();
130+
unsigned OpVariableId = getDebugInfoNoneId();
131+
if (Alloca && !(isa<ConstantPointerNull>(Alloca) || isa<UndefValue>(Alloca)))
132+
OpVariableId = SPIRVWriter->transValue(Alloca, BB)->getId();
133+
Ops[VariableIdx] = OpVariableId;
132134
Ops[ExpressionIdx] = transDbgEntry(DbgDecl->getExpression())->getId();
133135
DD->setArguments(Ops);
134136
}

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,12 +2678,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
26782678
return mapValue(
26792679
BV, cast<Instruction *>(DbgTran->transDebugIntrinsic(ExtInst, BB)));
26802680
} else {
2681-
auto MaybeRecord = DbgTran->transDebugIntrinsic(ExtInst, BB);
2682-
if (!MaybeRecord.isNull()) {
2683-
auto *Record = cast<DbgRecord *>(MaybeRecord);
2684-
Record->setDebugLoc(
2685-
DbgTran->transDebugScope(static_cast<SPIRVInstruction *>(BV)));
2686-
}
2681+
DbgTran->transDebugIntrinsic(ExtInst, BB);
26872682
return mapValue(BV, nullptr);
26882683
}
26892684
default:

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,17 +1592,19 @@ SPIRVToLLVMDbgTran::transDebugIntrinsic(const SPIRVExtInst *DebugInst,
15921592
AI->eraseFromParent();
15931593
return DbgDeclare;
15941594
}
1595+
DebugLoc Loc = transDebugScope(DebugInst);
15951596
return DIB.insertDeclare(GetValue(Ops[VariableIdx]), LocalVar.first,
1596-
GetExpression(Ops[ExpressionIdx]), LocalVar.second,
1597+
GetExpression(Ops[ExpressionIdx]), Loc,
15971598
BB);
15981599
}
15991600
case SPIRVDebug::Value: {
16001601
using namespace SPIRVDebug::Operand::DebugValue;
16011602
auto LocalVar = GetLocalVar(Ops[DebugLocalVarIdx]);
16021603
Value *Val = GetValue(Ops[ValueIdx]);
16031604
DIExpression *Expr = GetExpression(Ops[ExpressionIdx]);
1605+
DebugLoc Loc = transDebugScope(DebugInst);
16041606
DbgInstPtr DbgValIntr = getDIBuilder(DebugInst).insertDbgValueIntrinsic(
1605-
Val, LocalVar.first, Expr, LocalVar.second, BB);
1607+
Val, LocalVar.first, Expr, Loc, BB);
16061608

16071609
std::vector<ValueAsMetadata *> MDs;
16081610
for (size_t I = 0; I != Expr->getNumLocationOperands(); ++I) {

llvm-spirv/test/DebugInfo/DebugDeclareUnused.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ void foo() {
1414
int a;
1515
}
1616

17-
// CHECK-SPIRV: Undef [[#]] [[#Undef:]]
18-
// CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugDeclare [[#]] [[#Undef]] [[#]]
19-
// CHECK-LLVM: #dbg_declare(ptr undef, ![[#]], !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), ![[#]])
17+
// CHECK-SPIRV: ExtInst [[#]] [[#InfoNone:]] [[#]] DebugInfoNone
18+
// CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugDeclare [[#]] [[#InfoNone]] [[#]]
19+
// CHECK-LLVM: #dbg_declare(ptr poison, ![[#]], !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), ![[#]])
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; Check if the translator handles #dbg_declare(ptr null ...) correctly
2+
3+
; RUN: llvm-as %s -o %t.bc
4+
; RUN: llvm-spirv %t.bc -o %t.spv
5+
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
6+
; RUN: FileCheck < %t.spt %s --check-prefixes=CHECK-SPIRV
7+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
8+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
9+
10+
; RUN: llvm-as %s -o %t.bc
11+
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-debug-info-version=nonsemantic-shader-100
12+
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
13+
; RUN: FileCheck < %t.spt %s --check-prefixes=CHECK-SPIRV
14+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
15+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
16+
17+
; RUN: llvm-as %s -o %t.bc
18+
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-debug-info-version=nonsemantic-shader-200
19+
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
20+
; RUN: FileCheck < %t.spt %s --check-prefixes=CHECK-SPIRV
21+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
22+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
23+
24+
; CHECK-SPIRV: ExtInst [[#]] [[#None:]] [[#]] DebugInfoNone
25+
; CHECK-SPIRV: ExtInst [[#]] [[#LocalVar:]] [[#]] DebugLocalVariable
26+
; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugDeclare [[#LocalVar]] [[#None]] [[#]]
27+
28+
; CHECK-LLVM: #dbg_declare(ptr poison, ![[#LocalVar:]], !DIExpression(DW_OP_constu, 4, DW_OP_swap, DW_OP_xderef), ![[#Loc:]])
29+
; CHECK-LLVM-DAG: ![[#LocalVar]] = !DILocalVariable(name: "bar"
30+
; CHECK-LLVM-DAG: ![[#Loc]] = !DILocation(line: 23
31+
32+
; ModuleID = 'test.bc'
33+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
34+
target triple = "spir64"
35+
36+
define spir_kernel void @__omp_offloading_811_29c0007__Z4main_l28() {
37+
newFuncRoot:
38+
%0 = alloca i32, i32 0, align 4, !dbg !4
39+
store i32 0, ptr null, align 4
40+
%four.ascast.fpriv = alloca i32, align 4, !dbg !4
41+
#dbg_declare(ptr null, !8, !DIExpression(DW_OP_constu, 4, DW_OP_swap, DW_OP_xderef), !10)
42+
ret void
43+
}
44+
45+
!llvm.dbg.cu = !{!0}
46+
!llvm.module.flags = !{!3}
47+
48+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, imports: !2, splitDebugInlining: false, nameTableKind: None)
49+
!1 = !DIFile(filename: "test.cpp", directory: "/path/to")
50+
!2 = !{}
51+
!3 = !{i32 2, !"Debug Info Version", i32 3}
52+
!4 = !DILocation(line: 28, column: 1, scope: !5)
53+
!5 = distinct !DILexicalBlock(scope: !6, file: !1, line: 28, column: 1)
54+
!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 28, type: !7, scopeLine: 28, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0)
55+
!7 = !DISubroutineType(types: !2)
56+
!8 = !DILocalVariable(name: "bar", scope: !5, file: !1, line: 23, type: !9)
57+
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
58+
!10 = !DILocation(line: 23, column: 7, scope: !5)
59+

0 commit comments

Comments
 (0)