Skip to content

Commit c2e62c7

Browse files
authored
[llvm-reduce] Remove DIGlobalVariableExpressions from DICompileUnit's globals (#94497)
The 'metadata' delta pass will remove !dbg attachments from globals (which are DIGlobalVariableExpression nodes). The DIGlobalVariableExpressions don't get eliminated from the IR however if they are still referenced by the globals field in DICompileUnit. Teach the 'di-metadata' pass to try removing global variable operands from metadata tuples as well as DINodes.
1 parent f1e78f7 commit c2e62c7

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; DICompileUnit and DISuprogram.
33
;
44
; RUN: llvm-reduce --delta-passes=di-metadata --abort-on-invalid-reduction --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
5-
; RUN: FileCheck <%t --enable-var-scope %s
5+
; RUN: FileCheck <%t --enable-var-scope %s --implicit-check-not=DIGlobalVariableExpression
66

77
; CHECK-INTERESTINGNESS: define void @test() !dbg [[SUBPROG:![0-9]+]]
88
; CHECK-INTERESTINGNESS: !llvm.module.flags = !{
@@ -21,12 +21,10 @@
2121

2222
; CHECK: !llvm.dbg.cu = !{[[CU:.+]]}
2323

24-
; CHECK-DAG: [[CU]] = distinct !DICompileUnit(language: DW_LANG_C99,{{.*}}, retainedTypes: [[TYPES:![0-9]+]], globals: [[GLOBALS:![0-9]+]]
25-
; CHECK-DAG: [[EMPTY:![0-9]+]] = !{}
24+
; CHECK-DAG: [[CU]] = distinct !DICompileUnit(language: DW_LANG_C99,{{.*}}, retainedTypes: [[TYPES:![0-9]+]], globals: [[EMPTY:![0-9]+]]
25+
; CHECK-DAG: [[EMPTY]] = !{}
2626
; CHECK-DAG: [[TYPES]] = !{[[T0:![0-9]+]]
2727
; CHECK-DAG: [[T0]] = !DIBasicType(name: "unsigned int",
28-
; CHECK-DAG: [[GLOBALS]] = !{{{![0-9]+}}
29-
3028
; CHECK-DAG: [[SUBPROG]] = distinct !DISubprogram(name: "test", {{.*}}retainedNodes: [[EMPTY]])
3129

3230
define void @test() !dbg !17 {

llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ void identifyUninterestingMDNodes(Oracle &O, MDNodeList &MDs) {
6565
SmallVector<Metadata *, 16> TN;
6666
for (size_t I = 0; I < Tup->getNumOperands(); ++I) {
6767
// Ignore any operands that are not DebugInfo metadata nodes.
68-
if (isa_and_nonnull<DINode>(Tup->getOperand(I)))
69-
// Don't add uninteresting operands to the tuple.
70-
if (!O.shouldKeep())
71-
continue;
72-
73-
TN.push_back(Tup->getOperand(I));
68+
if (Metadata *Op = Tup->getOperand(I).get()) {
69+
if (isa<DINode>(Op) || isa<DIGlobalVariableExpression>(Op))
70+
// Don't add uninteresting operands to the tuple.
71+
if (!O.shouldKeep())
72+
continue;
73+
TN.push_back(Op);
74+
}
7475
}
7576
if (TN.size() != Tup->getNumOperands())
7677
DbgNode->replaceOperandWith(OpIdx, DbgNode->get(DbgNode->getContext(), TN));

0 commit comments

Comments
 (0)