[llvm] [LLVM-Reduce] - Distinct Metadata Reduction (PR #96072)
Michal Paszkowski via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 20 03:56:46 PDT 2024
================
@@ -0,0 +1,146 @@
+//===- ReduceDistinctMetadata.cpp - Specialized Delta Pass
+//------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===------------------------------------------------------------------------------===//
+//
+// This file implements two functions used by the Generic Delta Debugging
+// Algorithm, which are used to reduce unnamed distinct metadata nodes.
+//
+//===------------------------------------------------------------------------------===//
+
+#include "ReduceDistinctMetadata.h"
+#include "Delta.h"
+#include "llvm/ADT/Sequence.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/InstIterator.h"
+#include <algorithm>
+#include <queue>
+#include <set>
+
+using namespace llvm;
+
+// Traverse the graph breadth-first and try to remove unnamed metadata nodes
+void BFS_removal(MDNode *root,
+ std::set<std::pair<unsigned int, MDNode *>> &nodesToDelete,
+ MDNode *tmp, Oracle &O, Module &Program) {
+ std::queue<MDNode *> q{};
+ std::set<MDNode *>
+ visited{}; // Keep track of visited nodes not to get into loops
+ q.push(root);
+
+ while (!q.empty()) {
+ MDNode *current = q.front();
+ q.pop();
+
+ // Mark the nodes for removal
+ for (unsigned int i = 0; i < current->getNumOperands(); ++i) {
+ Metadata *operand = current->getOperand(i).get();
+ if (isa_and_nonnull<MDNode>(operand)) {
+ if (std::find(visited.begin(), visited.end(), operand) ==
----------------
michalpaszkowski wrote:
Using std::find on std::set might be inefficient. You could use visited.find(operand) != visited.end().
https://github.com/llvm/llvm-project/pull/96072
More information about the llvm-commits
mailing list