[llvm] [llvm-reduce] Remove DIGlobalVariableExpressions from DICompileUnit's globals (PR #94497)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 5 09:39:27 PDT 2024
https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/94497
>From 1bf1bd4fea3232a5b206c0dcaf8bf0e435cb3d6b Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Wed, 5 Jun 2024 16:56:26 +0100
Subject: [PATCH 1/2] [llvm-reduce] Remove DIGlobalVariableExpressions from
DICompileUnit's globals
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.
---
.../tools/llvm-reduce/remove-debug-info-nodes.ll | 7 ++-----
llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp | 14 ++++++++------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll b/llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll
index 1ceeca8b65615..7aa4af35dffe6 100644
--- a/llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll
+++ b/llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll
@@ -2,7 +2,7 @@
; DICompileUnit and DISuprogram.
;
; 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
-; RUN: FileCheck <%t --enable-var-scope %s
+; RUN: FileCheck <%t --enable-var-scope %s --implicit-check-not=DIGlobalVariableExpression
; CHECK-INTERESTINGNESS: define void @test() !dbg [[SUBPROG:![0-9]+]]
; CHECK-INTERESTINGNESS: !llvm.module.flags = !{
@@ -15,18 +15,15 @@
; CHECK-INTERESTINGNESS-DAG: [[SUBPROG]] = distinct !DISubprogram(name: "test",
-
; CHECK: define void @test() !dbg [[SUBPROG:![0-9]+]]
; CHECK: !llvm.module.flags = !{
; CHECK: !llvm.dbg.cu = !{[[CU:.+]]}
-; CHECK-DAG: [[CU]] = distinct !DICompileUnit(language: DW_LANG_C99,{{.*}}, retainedTypes: [[TYPES:![0-9]+]], globals: [[GLOBALS:![0-9]+]]
+; CHECK-DAG: [[CU]] = distinct !DICompileUnit(language: DW_LANG_C99,{{.*}}, retainedTypes: [[TYPES:![0-9]+]], globals: [[EMPTY:![0-9]+]]
; CHECK-DAG: [[EMPTY:![0-9]+]] = !{}
; CHECK-DAG: [[TYPES]] = !{[[T0:![0-9]+]]
; CHECK-DAG: [[T0]] = !DIBasicType(name: "unsigned int",
-; CHECK-DAG: [[GLOBALS]] = !{{{![0-9]+}}
-
; CHECK-DAG: [[SUBPROG]] = distinct !DISubprogram(name: "test", {{.*}}retainedNodes: [[EMPTY]])
define void @test() !dbg !17 {
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp b/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
index f4d8496aba4a7..461776eddedca 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp
@@ -65,12 +65,14 @@ void identifyUninterestingMDNodes(Oracle &O, MDNodeList &MDs) {
SmallVector<Metadata *, 16> TN;
for (size_t I = 0; I < Tup->getNumOperands(); ++I) {
// Ignore any operands that are not DebugInfo metadata nodes.
- if (isa_and_nonnull<DINode>(Tup->getOperand(I)))
- // Don't add uninteresting operands to the tuple.
- if (!O.shouldKeep())
- continue;
-
- TN.push_back(Tup->getOperand(I));
+ if (Metadata *Op = Tup->getOperand(I).get()) {
+ if (isa<DINode>(Op) || isa<DIGlobalVariableExpression>(Op)) {
+ // Don't add uninteresting operands to the tuple.
+ if (!O.shouldKeep())
+ continue;
+ }
+ TN.push_back(Op);
+ }
}
if (TN.size() != Tup->getNumOperands())
DbgNode->replaceOperandWith(OpIdx, DbgNode->get(DbgNode->getContext(), TN));
>From 52499c9540a1332e085915aaad1d8c256c034258 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Wed, 5 Jun 2024 17:39:01 +0100
Subject: [PATCH 2/2] fix review comments
---
llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll b/llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll
index 7aa4af35dffe6..127543c64c330 100644
--- a/llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll
+++ b/llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll
@@ -15,13 +15,14 @@
; CHECK-INTERESTINGNESS-DAG: [[SUBPROG]] = distinct !DISubprogram(name: "test",
+
; CHECK: define void @test() !dbg [[SUBPROG:![0-9]+]]
; CHECK: !llvm.module.flags = !{
; CHECK: !llvm.dbg.cu = !{[[CU:.+]]}
; CHECK-DAG: [[CU]] = distinct !DICompileUnit(language: DW_LANG_C99,{{.*}}, retainedTypes: [[TYPES:![0-9]+]], globals: [[EMPTY:![0-9]+]]
-; CHECK-DAG: [[EMPTY:![0-9]+]] = !{}
+; CHECK-DAG: [[EMPTY]] = !{}
; CHECK-DAG: [[TYPES]] = !{[[T0:![0-9]+]]
; CHECK-DAG: [[T0]] = !DIBasicType(name: "unsigned int",
; CHECK-DAG: [[SUBPROG]] = distinct !DISubprogram(name: "test", {{.*}}retainedNodes: [[EMPTY]])
More information about the llvm-commits
mailing list