Skip to content

Commit 24c1aca

Browse files
authored
Support DISubrange DIExpression upperBound (#1350)
Expand transDbgArrayType to preserve DISubrange lowerBound. And the case when upperBound is DIExpression.
1 parent e8f1964 commit 24c1aca

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgArrayType(const DICompositeType *AT) {
557557
// For N-dimensianal arrays AR.getNumElements() == N
558558
const unsigned N = AR.size();
559559
Ops.resize(ComponentCountIdx + N);
560+
SPIRVWordVec LowerBounds(N);
560561
for (unsigned I = 0; I < N; ++I) {
561562
DISubrange *SR = cast<DISubrange>(AR[I]);
562563
ConstantInt *Count = SR->getCount().get<ConstantInt *>();
@@ -574,7 +575,18 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgArrayType(const DICompositeType *AT) {
574575
else
575576
Ops[ComponentCountIdx + I] = getDebugInfoNoneId();
576577
}
578+
if (auto *RawLB = SR->getRawLowerBound()) {
579+
if (auto *DIExprLB = dyn_cast<MDNode>(RawLB))
580+
LowerBounds[I] = transDbgEntry(DIExprLB)->getId();
581+
else {
582+
ConstantInt *ConstIntLB = SR->getLowerBound().get<ConstantInt *>();
583+
LowerBounds[I] = SPIRVWriter->transValue(ConstIntLB, nullptr)->getId();
584+
}
585+
} else {
586+
LowerBounds[I] = getDebugInfoNoneId();
587+
}
577588
}
589+
Ops.insert(Ops.end(), LowerBounds.begin(), LowerBounds.end());
578590
return BM->addDebugInfo(SPIRVDebug::TypeArray, getVoidTy(), Ops);
579591
}
580592

lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,24 +199,35 @@ SPIRVToLLVMDbgTran::transTypeArray(const SPIRVExtInst *DebugInst) {
199199
transDebugInst<DIType>(BM->get<SPIRVExtInst>(Ops[BaseTypeIdx]));
200200
size_t TotalCount = 1;
201201
SmallVector<llvm::Metadata *, 8> Subscripts;
202-
for (size_t I = ComponentCountIdx, E = Ops.size(); I < E; ++I) {
203-
if (getDbgInst<SPIRVDebug::DebugInfoNone>(Ops[I])) {
204-
Subscripts.push_back(Builder.getOrCreateSubrange(1, nullptr));
202+
// Ops looks like: { BaseType, count1|upperBound1, count2|upperBound2, ...,
203+
// countN|upperBoundN, lowerBound1, lowerBound2, ..., lowerBoundN }
204+
for (size_t I = ComponentCountIdx, E = Ops.size() / 2 + 1; I < E; ++I) {
205+
if (auto *LocalVar = getDbgInst<SPIRVDebug::LocalVariable>(Ops[I])) {
206+
auto *UpperBound = transDebugInst<DILocalVariable>(LocalVar);
207+
SPIRVConstant *C = BM->get<SPIRVConstant>(Ops[Ops.size() / 2 + I]);
208+
int64_t ConstantAsInt = static_cast<int64_t>(C->getZExtIntValue());
209+
auto *LowerBound = ConstantAsMetadata::get(
210+
ConstantInt::get(M->getContext(), APInt(64, ConstantAsInt)));
211+
Subscripts.push_back(Builder.getOrCreateSubrange(nullptr, LowerBound,
212+
UpperBound, nullptr));
205213
continue;
206214
}
207-
if (auto *LocalVar = getDbgInst<SPIRVDebug::LocalVariable>(Ops[I])) {
208-
if (auto *UpperBound = transDebugInst<DILocalVariable>(LocalVar)) {
209-
auto *LowerBound = ConstantAsMetadata::get(
210-
ConstantInt::get(M->getContext(), APInt(32, 1)));
211-
Subscripts.push_back(Builder.getOrCreateSubrange(nullptr, LowerBound,
212-
UpperBound, nullptr));
213-
continue;
214-
}
215+
if (auto *ExprUB = getDbgInst<SPIRVDebug::Expression>(Ops[I])) {
216+
auto *UpperBound = transDebugInst<DIExpression>(ExprUB);
217+
auto *ExprLB =
218+
getDbgInst<SPIRVDebug::Expression>(Ops[Ops.size() / 2 + I]);
219+
auto *LowerBound = transDebugInst<DIExpression>(ExprLB);
220+
Subscripts.push_back(Builder.getOrCreateSubrange(nullptr, LowerBound,
221+
UpperBound, nullptr));
222+
continue;
223+
}
224+
if (!getDbgInst<SPIRVDebug::DebugInfoNone>(Ops[I])) {
225+
SPIRVConstant *C = BM->get<SPIRVConstant>(Ops[I]);
226+
int64_t Count = static_cast<int64_t>(C->getZExtIntValue());
227+
Subscripts.push_back(Builder.getOrCreateSubrange(0, Count));
228+
TotalCount *= static_cast<uint64_t>(Count);
229+
continue;
215230
}
216-
SPIRVConstant *C = BM->get<SPIRVConstant>(Ops[I]);
217-
int64_t Count = static_cast<int64_t>(C->getZExtIntValue());
218-
Subscripts.push_back(Builder.getOrCreateSubrange(0, Count));
219-
TotalCount *= static_cast<uint64_t>(Count);
220231
}
221232
DINodeArray SubscriptArray = Builder.getOrCreateArray(Subscripts);
222233
size_t Size = getDerivedSizeInBits(BaseTy) * TotalCount;

test/DebugInfo/DebugInfoSubrangeUpperBound.ll renamed to test/DebugInfo/DebugInfoSubrange.ll

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,26 @@
99

1010
; CHECK-SPIRV: String [[#VarNameId:]] "A$1$upperbound"
1111
; CHECK-SPIRV: [[#FuncNameId:]] "random_fill_sp"
12+
; CHECK-SPIRV: TypeInt [[#TypeIntId:]] 64 0
13+
; CHECK-SPIRV: Constant [[#TypeIntId]] [[#LowerBoundId:]] 1 0
1214
; CHECK-SPIRV: [[#DbgFuncId:]] [[#]] DebugFunction [[#FuncNameId]]
1315
; CHECK-SPIRV: [[#DbgTemplateId:]] [[#]] DebugTemplate [[#DbgFuncId]]
1416
; CHECK-SPIRV: [[#]] [[#DbgLocVarId:]] [[#]] DebugLocalVariable [[#VarNameId]] [[#]] [[#]] [[#]] [[#]] [[#DbgTemplateId]]
15-
; CHECK-SPIRV: DebugTypeArray [[#]] [[#DbgLocVarId]]
17+
; CHECK-SPIRV: DebugTypeArray [[#]] [[#DbgLocVarId]] [[#LowerBoundId]]
18+
19+
; CHECK-SPIRV: [[#DbgExprId:]] [[#]] DebugExpression
20+
; CHECK-SPIRV: DebugTypeArray [[#]] [[#DbgExprId]] [[#DbgExprId]]
1621

1722
; CHECK-LLVM: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[#BaseType:]], size: 32, elements: ![[#Subrange1:]])
1823
; CHECK-LLVM: [[#BaseType]] = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
1924
; CHECK-LLVM: [[#Subrange1]] = !{![[#Subrange2:]]}
2025
; CHECK-LLVM: [[#Subrange2:]] = !DISubrange(lowerBound: 1, upperBound: ![[#UpperBound:]])
2126
; CHECK-LLVM: [[#UpperBound]] = !DILocalVariable(name: "A$1$upperbound"
2227

28+
; CHECK-LLVM: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[#]], size: 32, elements: ![[#SubrangeExpr1:]])
29+
; CHECK-LLVM: [[#SubrangeExpr1]] = !{![[#SubrangeExpr2:]]}
30+
; CHECK-LLVM: ![[#SubrangeExpr2]] = !DISubrange(lowerBound: !DIExpression(), upperBound: !DIExpression())
31+
2332
; ModuleID = 'DebugInfoSubrangeUpperBound.bc'
2433
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
2534
target triple = "spir64-unknown-unknown"
@@ -33,6 +42,7 @@ define spir_kernel void @__omp_offloading_811_198142f_random_fill_sp_l25(%struct
3342
newFuncRoot:
3443
%.ascast = bitcast %structtype* %"ascast$val" to %"QNCA_a0$float"*
3544
call void @llvm.dbg.value(metadata %"QNCA_a0$float"* %.ascast, metadata !13, metadata !DIExpression(DW_OP_deref)), !dbg !27
45+
call void @llvm.dbg.value(metadata %"QNCA_a0$float"* %.ascast, metadata !28, metadata !DIExpression(DW_OP_deref)), !dbg !42
3646
ret void
3747
}
3848

@@ -81,3 +91,18 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
8191
!25 = !{!23}
8292
!26 = !DIBasicType(name: "INTEGER*8", size: 64, encoding: DW_ATE_signed)
8393
!27 = !DILocation(line: 15, column: 67, scope: !14)
94+
!28 = !DILocalVariable(name: "a", scope: !29, file: !3, line: 15, type: !33)
95+
!29 = distinct !DISubprogram(name: "random_fill_sp.DIR.OMP.TARGET.8.split.split.split.split", scope: null, file: !3, line: 25, type: !30, scopeLine: 25, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !32)
96+
!30 = !DISubroutineType(types: !31)
97+
!31 = !{null}
98+
!32 = !{!28}
99+
!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !34, size: 64)
100+
!34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !35, size: 32, elements: !36)
101+
!35 = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
102+
!36 = !{!37}
103+
!37 = !DISubrange(lowerBound: !DIExpression(), upperBound: !DIExpression())
104+
!38 = !DILocalVariable(name: "A$1$upperbound", scope: !39, type: !41, flags: DIFlagArtificial)
105+
!39 = distinct !DISubprogram(name: "random_fill_sp", linkageName: "random_fill_sp", scope: null, file: !3, line: 15, type: !30, scopeLine: 15, spFlags: DISPFlagDefinition, unit: !2, templateParams: !7, retainedNodes: !40)
106+
!40 = !{!38}
107+
!41 = !DIBasicType(name: "INTEGER*8", size: 64, encoding: DW_ATE_signed)
108+
!42 = !DILocation(line: 15, column: 67, scope: !29)

test/FortranArray.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
; and back to .ll. This causes the LLVM IR verifier to fail as there
1111
; are different rules for valid DISubRange depending on language ID.
1212

13-
; CHECK-LLVM: !DISubrange(lowerBound: 1)
13+
; CHECK-LLVM: !DISubrange(lowerBound: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 64, DW_OP_deref), upperBound: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 64, DW_OP_deref, DW_OP_push_object_address, DW_OP_plus_uconst, 48, DW_OP_deref, DW_OP_plus, DW_OP_constu, 1, DW_OP_minus))
1414

1515
source_filename = "llvm-link"
1616
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"

0 commit comments

Comments
 (0)