Skip to content

Commit aa065c0

Browse files
committed
Revert "[llvm-reduce] Remove debug metadata elements"
This reverts commit 69549de. 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
1 parent 69c661a commit aa065c0

File tree

6 files changed

+20
-135
lines changed

6 files changed

+20
-135
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import sys
2+
3+
input = open(sys.argv[1], "r")
4+
for line in input:
5+
if "!interesting" in line:
6+
sys.exit(0)
7+
8+
sys.exit(1)

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
; CHECK-INTERESTINGNESS-DAG: [[CU]] = distinct !DICompileUnit(language: DW_LANG_C99,{{.*}}, retainedTypes: [[TYPES:![0-9]+]]
1313
; CHECK-INTERESTINGNESS-DAG: [[TYPES]] = !{[[T0:![0-9]+]]
1414
; CHECK-INTERESTINGNESS-DAG: [[T0]] = !DIBasicType(name: "unsigned int",
15-
; CHECK-INTERESTINGNESS-DAG: !DIGlobalVariable(
16-
; CHECK-INTERESTINGNESS-DAG: !DILocalVariable(name: "A"
17-
; CHECK-INTERESTINGNESS-DAG: !DILocalVariable(name: "B"
18-
; CHECK-INTERESTINGNESS-DAG: !DILocalVariable(name: "C"
1915

2016

2117

llvm/test/tools/llvm-reduce/remove-metadata-elements.ll

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
; Test that llvm-reduce can remove uninteresting metadata from an IR file.
22
; The Metadata pass erases named & unnamed metadata nodes.
33
;
4-
; RUN: llvm-reduce %s -o %t --delta-passes=metadata --test FileCheck --test-arg %s --test-arg --input-file
5-
; RUN: FileCheck %s < %t
4+
; RUN: llvm-reduce --test %python --test-arg %p/Inputs/remove-metadata.py %s -o %t
5+
; RUN: cat %t | FileCheck -implicit-check-not=! %s
66

77
@global = global i32 0, !dbg !0
88

@@ -11,9 +11,9 @@ define void @main() !dbg !0 {
1111
}
1212

1313
!uninteresting = !{!0}
14-
; CHECK: !interesting = !{![[I:[0-9]+]]}
14+
; CHECK: !interesting = !{!0}
1515
!interesting = !{!1}
1616

1717
!0 = !{!"uninteresting"}
18-
; CHECK: ![[I]] = !{!"interesting"}
18+
; CHECK: !0 = !{!"interesting"}
1919
!1 = !{!"interesting"}

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -23,107 +23,46 @@ using namespace llvm;
2323
/// Removes all the Named and Unnamed Metadata Nodes, as well as any debug
2424
/// functions that aren't inside the desired Chunks.
2525
static void extractMetadataFromModule(Oracle &O, Module &Program) {
26-
SmallSetVector<MDNode *, 8> NodesToVisit;
27-
2826
// Get out-of-chunk Named metadata nodes
2927
SmallVector<NamedMDNode *> NamedNodesToDelete;
30-
for (NamedMDNode &MD : Program.named_metadata()) {
31-
if (O.shouldKeep()) {
32-
for (auto *Op : MD.operands())
33-
NodesToVisit.insert(Op);
34-
} else {
28+
for (NamedMDNode &MD : Program.named_metadata())
29+
if (!O.shouldKeep())
3530
NamedNodesToDelete.push_back(&MD);
36-
}
37-
}
3831

3932
for (NamedMDNode *NN : NamedNodesToDelete) {
4033
for (auto I : seq<unsigned>(0, NN->getNumOperands()))
4134
NN->setOperand(I, nullptr);
4235
NN->eraseFromParent();
4336
}
4437

45-
// Delete elements from named metadata lists
46-
for (auto &NamedList : Program.named_metadata()) {
47-
SmallVector<MDNode *> NewOperands;
48-
for (auto *Op : NamedList.operands())
49-
if (O.shouldKeep())
50-
NewOperands.push_back(Op);
51-
if (NewOperands.size() == NamedList.getNumOperands())
52-
continue;
53-
NamedList.clearOperands();
54-
for (auto *Op : NewOperands)
55-
NamedList.addOperand(Op);
56-
}
57-
5838
// Delete out-of-chunk metadata attached to globals.
5939
for (GlobalVariable &GV : Program.globals()) {
6040
SmallVector<std::pair<unsigned, MDNode *>> MDs;
6141
GV.getAllMetadata(MDs);
62-
for (std::pair<unsigned, MDNode *> &MD : MDs) {
63-
if (O.shouldKeep()) {
64-
NodesToVisit.insert(MD.second);
65-
} else {
42+
for (std::pair<unsigned, MDNode *> &MD : MDs)
43+
if (!O.shouldKeep())
6644
GV.setMetadata(MD.first, nullptr);
67-
}
68-
}
6945
}
7046

7147
for (Function &F : Program) {
7248
{
7349
SmallVector<std::pair<unsigned, MDNode *>> MDs;
7450
// Delete out-of-chunk metadata attached to functions.
7551
F.getAllMetadata(MDs);
76-
for (std::pair<unsigned, MDNode *> &MD : MDs) {
77-
if (O.shouldKeep()) {
78-
NodesToVisit.insert(MD.second);
79-
} else {
52+
for (std::pair<unsigned, MDNode *> &MD : MDs)
53+
if (!O.shouldKeep())
8054
F.setMetadata(MD.first, nullptr);
81-
}
82-
}
8355
}
8456

8557
// Delete out-of-chunk metadata attached to instructions.
8658
for (Instruction &I : instructions(F)) {
8759
SmallVector<std::pair<unsigned, MDNode *>> MDs;
8860
I.getAllMetadata(MDs);
89-
for (std::pair<unsigned, MDNode *> &MD : MDs) {
90-
if (O.shouldKeep()) {
91-
NodesToVisit.insert(MD.second);
92-
} else {
61+
for (std::pair<unsigned, MDNode *> &MD : MDs)
62+
if (!O.shouldKeep())
9363
I.setMetadata(MD.first, nullptr);
94-
}
95-
}
9664
}
9765
}
98-
99-
// Gather all metadata tuples and their parents
100-
SmallVector<std::pair<MDNode *, unsigned>> OperandsOfTuples;
101-
SmallSet<Metadata *, 8> VisitedNodes;
102-
while (!NodesToVisit.empty()) {
103-
auto *Node = NodesToVisit.pop_back_val();
104-
if (!VisitedNodes.insert(Node).second)
105-
continue;
106-
for (auto I : seq<unsigned>(0, Node->getNumOperands())) {
107-
auto *Op = Node->getOperand(I).get();
108-
if (auto *MD = dyn_cast_or_null<MDNode>(Op))
109-
NodesToVisit.insert(MD);
110-
if (isa_and_nonnull<MDTuple>(Op))
111-
OperandsOfTuples.push_back(std::make_pair(Node, I));
112-
}
113-
}
114-
115-
// Delete elements from metadata tuples
116-
for (auto [Node, NodeOpID] : OperandsOfTuples) {
117-
auto *Tuple = dyn_cast<MDTuple>(Node->getOperand(NodeOpID));
118-
SmallVector<Metadata *> NewOperands;
119-
for (auto &Op : Tuple->operands())
120-
if (O.shouldKeep())
121-
NewOperands.push_back(Op.get());
122-
if (NewOperands.size() == Tuple->getNumOperands())
123-
continue;
124-
Node->replaceOperandWith(
125-
NodeOpID, MDTuple::get(Tuple->getContext(), makeArrayRef(NewOperands)));
126-
}
12766
}
12867

12968
void llvm::reduceMetadataDeltaPass(TestRunner &Test) {

0 commit comments

Comments
 (0)