[llvm] aa065c0 - Revert "[llvm-reduce] Remove debug metadata elements"

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 6 13:40:12 PDT 2022


Author: Ellis Hoag
Date: 2022-10-06T13:40:03-07:00
New Revision: aa065c016bd91412275054c450e09b0205a3eeee

URL: https://github.com/llvm/llvm-project/commit/aa065c016bd91412275054c450e09b0205a3eeee
DIFF: https://github.com/llvm/llvm-project/commit/aa065c016bd91412275054c450e09b0205a3eeee.diff

LOG: Revert "[llvm-reduce] Remove debug metadata elements"

This reverts commit 69549de865550e54983ed8d00009920184de47ff.

The change in D135237 can lead to verification failures like `scope must have two or three operands`.
The ongoing work in D132077 does something similar without these failures, so lets wait for that to land and revert this patch.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D135395

Added: 
    llvm/test/tools/llvm-reduce/Inputs/remove-metadata.py

Modified: 
    llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll
    llvm/test/tools/llvm-reduce/remove-metadata.ll
    llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp

Removed: 
    llvm/test/tools/llvm-reduce/remove-metadata-elements.ll
    llvm/test/tools/llvm-reduce/remove-named-metadata-elements.ll


################################################################################
diff  --git a/llvm/test/tools/llvm-reduce/Inputs/remove-metadata.py b/llvm/test/tools/llvm-reduce/Inputs/remove-metadata.py
new file mode 100755
index 0000000000000..37af33314853c
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/Inputs/remove-metadata.py
@@ -0,0 +1,8 @@
+import sys
+
+input = open(sys.argv[1], "r")
+for line in input:
+  if "!interesting" in line:
+    sys.exit(0)
+
+sys.exit(1)

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 ab1380508f1e3..1863d35d9c750 100644
--- a/llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll
+++ b/llvm/test/tools/llvm-reduce/remove-debug-info-nodes.ll
@@ -12,10 +12,6 @@
 ; CHECK-INTERESTINGNESS-DAG: [[CU]] = distinct !DICompileUnit(language: DW_LANG_C99,{{.*}}, retainedTypes: [[TYPES:![0-9]+]]
 ; CHECK-INTERESTINGNESS-DAG: [[TYPES]] = !{[[T0:![0-9]+]]
 ; CHECK-INTERESTINGNESS-DAG: [[T0]] = !DIBasicType(name: "unsigned int",
-; CHECK-INTERESTINGNESS-DAG: !DIGlobalVariable(
-; CHECK-INTERESTINGNESS-DAG: !DILocalVariable(name: "A"
-; CHECK-INTERESTINGNESS-DAG: !DILocalVariable(name: "B"
-; CHECK-INTERESTINGNESS-DAG: !DILocalVariable(name: "C"
 
 
 

diff  --git a/llvm/test/tools/llvm-reduce/remove-metadata-elements.ll b/llvm/test/tools/llvm-reduce/remove-metadata-elements.ll
deleted file mode 100644
index 07c21115a487a..0000000000000
--- a/llvm/test/tools/llvm-reduce/remove-metadata-elements.ll
+++ /dev/null
@@ -1,35 +0,0 @@
-; RUN: llvm-reduce %s -o %t --delta-passes=metadata --test FileCheck --test-arg %s --test-arg --input-file
-; RUN: FileCheck %s < %t --implicit-check-not="boring"
-
-; Test that debug metadata lists can be reduced by making sure debug info for
-; "boring" globals are removed.
-
-; $ cat a.c
-; int boringA, interesting, boringB;
-; $ clang a.c -g -S -emit-llvm -o -
-
- at A = dso_local global i32 0, align 4, !dbg !0
- at B = dso_local global i32 0, align 4, !dbg !5
- at C = dso_local global i32 0, align 4, !dbg !8
-
-!llvm.dbg.cu = !{!2}
-!llvm.module.flags = !{!10, !11, !12, !13, !14, !15, !16}
-
-!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
-!1 = distinct !DIGlobalVariable(name: "boringA", scope: !2, file: !3, line: 1, type: !7, isLocal: false, isDefinition: true)
-!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
-!3 = !DIFile(filename: "a.c", directory: "")
-!4 = !{!0, !5, !8}
-!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
-; CHECK: !DIGlobalVariable(name: "interesting"
-!6 = distinct !DIGlobalVariable(name: "interesting", scope: !2, file: !3, line: 1, type: !7, isLocal: false, isDefinition: true)
-!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
-!9 = distinct !DIGlobalVariable(name: "boringB", scope: !2, file: !3, line: 1, type: !7, isLocal: false, isDefinition: true)
-!10 = !{i32 7, !"Dwarf Version", i32 5}
-!11 = !{i32 2, !"Debug Info Version", i32 3}
-!12 = !{i32 1, !"wchar_size", i32 4}
-!13 = !{i32 8, !"PIC Level", i32 2}
-!14 = !{i32 7, !"PIE Level", i32 2}
-!15 = !{i32 7, !"uwtable", i32 2}
-!16 = !{i32 7, !"frame-pointer", i32 2}

diff  --git a/llvm/test/tools/llvm-reduce/remove-metadata.ll b/llvm/test/tools/llvm-reduce/remove-metadata.ll
index 2ffcdd1ac7554..51a50ca20a985 100644
--- a/llvm/test/tools/llvm-reduce/remove-metadata.ll
+++ b/llvm/test/tools/llvm-reduce/remove-metadata.ll
@@ -1,8 +1,8 @@
 ; Test that llvm-reduce can remove uninteresting metadata from an IR file.
 ; The Metadata pass erases named & unnamed metadata nodes.
 ;
-; RUN: llvm-reduce %s -o %t --delta-passes=metadata --test FileCheck --test-arg %s --test-arg --input-file
-; RUN: FileCheck %s < %t
+; RUN: llvm-reduce --test %python --test-arg %p/Inputs/remove-metadata.py %s -o %t
+; RUN: cat %t | FileCheck -implicit-check-not=! %s
 
 @global = global i32 0, !dbg !0
 
@@ -11,9 +11,9 @@ define void @main() !dbg !0 {
 }
 
 !uninteresting = !{!0}
-; CHECK: !interesting = !{![[I:[0-9]+]]}
+; CHECK: !interesting = !{!0}
 !interesting = !{!1}
 
 !0 = !{!"uninteresting"}
-; CHECK: ![[I]] = !{!"interesting"}
+; CHECK: !0 = !{!"interesting"}
 !1 = !{!"interesting"}

diff  --git a/llvm/test/tools/llvm-reduce/remove-named-metadata-elements.ll b/llvm/test/tools/llvm-reduce/remove-named-metadata-elements.ll
deleted file mode 100644
index 9ac735ba7d014..0000000000000
--- a/llvm/test/tools/llvm-reduce/remove-named-metadata-elements.ll
+++ /dev/null
@@ -1,23 +0,0 @@
-; RUN: llvm-reduce %s -o %t --delta-passes=metadata --test FileCheck --test-arg %s --test-arg --input-file
-; RUN: FileCheck %s < %t --implicit-check-not="boring" --check-prefixes=CHECK,REDUCED
-
-; Test that we can remove elements from named metadata.
-
-!llvm.dbg.cu = !{!0, !1}
-; CHECK: !llvm.module.flags =
-; REDUCED-SAME: !{}
-!llvm.module.flags = !{!10, !11, !12, !13, !14, !15, !16}
-
-!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
-!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
-; CHECK: !DIFile(filename: "interesting.c"
-!2 = !DIFile(filename: "interesting.c", directory: "")
-!3 = !DIFile(filename: "boring.c", directory: "")
-
-!10 = !{i32 7, !"Dwarf Version", i32 5}
-!11 = !{i32 2, !"Debug Info Version", i32 3}
-!12 = !{i32 1, !"wchar_size", i32 4}
-!13 = !{i32 8, !"PIC Level", i32 2}
-!14 = !{i32 7, !"PIE Level", i32 2}
-!15 = !{i32 7, !"uwtable", i32 2}
-!16 = !{i32 7, !"frame-pointer", i32 2}

diff  --git a/llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp b/llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp
index 7409a4a19a0a9..078230e809549 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceMetadata.cpp
@@ -23,18 +23,11 @@ using namespace llvm;
 /// Removes all the Named and Unnamed Metadata Nodes, as well as any debug
 /// functions that aren't inside the desired Chunks.
 static void extractMetadataFromModule(Oracle &O, Module &Program) {
-  SmallSetVector<MDNode *, 8> NodesToVisit;
-
   // Get out-of-chunk Named metadata nodes
   SmallVector<NamedMDNode *> NamedNodesToDelete;
-  for (NamedMDNode &MD : Program.named_metadata()) {
-    if (O.shouldKeep()) {
-      for (auto *Op : MD.operands())
-        NodesToVisit.insert(Op);
-    } else {
+  for (NamedMDNode &MD : Program.named_metadata())
+    if (!O.shouldKeep())
       NamedNodesToDelete.push_back(&MD);
-    }
-  }
 
   for (NamedMDNode *NN : NamedNodesToDelete) {
     for (auto I : seq<unsigned>(0, NN->getNumOperands()))
@@ -42,30 +35,13 @@ static void extractMetadataFromModule(Oracle &O, Module &Program) {
     NN->eraseFromParent();
   }
 
-  // Delete elements from named metadata lists
-  for (auto &NamedList : Program.named_metadata()) {
-    SmallVector<MDNode *> NewOperands;
-    for (auto *Op : NamedList.operands())
-      if (O.shouldKeep())
-        NewOperands.push_back(Op);
-    if (NewOperands.size() == NamedList.getNumOperands())
-      continue;
-    NamedList.clearOperands();
-    for (auto *Op : NewOperands)
-      NamedList.addOperand(Op);
-  }
-
   // Delete out-of-chunk metadata attached to globals.
   for (GlobalVariable &GV : Program.globals()) {
     SmallVector<std::pair<unsigned, MDNode *>> MDs;
     GV.getAllMetadata(MDs);
-    for (std::pair<unsigned, MDNode *> &MD : MDs) {
-      if (O.shouldKeep()) {
-        NodesToVisit.insert(MD.second);
-      } else {
+    for (std::pair<unsigned, MDNode *> &MD : MDs)
+      if (!O.shouldKeep())
         GV.setMetadata(MD.first, nullptr);
-      }
-    }
   }
 
   for (Function &F : Program) {
@@ -73,57 +49,20 @@ static void extractMetadataFromModule(Oracle &O, Module &Program) {
       SmallVector<std::pair<unsigned, MDNode *>> MDs;
       // Delete out-of-chunk metadata attached to functions.
       F.getAllMetadata(MDs);
-      for (std::pair<unsigned, MDNode *> &MD : MDs) {
-        if (O.shouldKeep()) {
-          NodesToVisit.insert(MD.second);
-        } else {
+      for (std::pair<unsigned, MDNode *> &MD : MDs)
+        if (!O.shouldKeep())
           F.setMetadata(MD.first, nullptr);
-        }
-      }
     }
 
     // Delete out-of-chunk metadata attached to instructions.
     for (Instruction &I : instructions(F)) {
       SmallVector<std::pair<unsigned, MDNode *>> MDs;
       I.getAllMetadata(MDs);
-      for (std::pair<unsigned, MDNode *> &MD : MDs) {
-        if (O.shouldKeep()) {
-          NodesToVisit.insert(MD.second);
-        } else {
+      for (std::pair<unsigned, MDNode *> &MD : MDs)
+        if (!O.shouldKeep())
           I.setMetadata(MD.first, nullptr);
-        }
-      }
     }
   }
-
-  // Gather all metadata tuples and their parents
-  SmallVector<std::pair<MDNode *, unsigned>> OperandsOfTuples;
-  SmallSet<Metadata *, 8> VisitedNodes;
-  while (!NodesToVisit.empty()) {
-    auto *Node = NodesToVisit.pop_back_val();
-    if (!VisitedNodes.insert(Node).second)
-      continue;
-    for (auto I : seq<unsigned>(0, Node->getNumOperands())) {
-      auto *Op = Node->getOperand(I).get();
-      if (auto *MD = dyn_cast_or_null<MDNode>(Op))
-        NodesToVisit.insert(MD);
-      if (isa_and_nonnull<MDTuple>(Op))
-        OperandsOfTuples.push_back(std::make_pair(Node, I));
-    }
-  }
-
-  // Delete elements from metadata tuples
-  for (auto [Node, NodeOpID] : OperandsOfTuples) {
-    auto *Tuple = dyn_cast<MDTuple>(Node->getOperand(NodeOpID));
-    SmallVector<Metadata *> NewOperands;
-    for (auto &Op : Tuple->operands())
-      if (O.shouldKeep())
-        NewOperands.push_back(Op.get());
-    if (NewOperands.size() == Tuple->getNumOperands())
-      continue;
-    Node->replaceOperandWith(
-        NodeOpID, MDTuple::get(Tuple->getContext(), makeArrayRef(NewOperands)));
-  }
 }
 
 void llvm::reduceMetadataDeltaPass(TestRunner &Test) {


        


More information about the llvm-commits mailing list