[PATCH] D137863: llvm-reduce: Use DenseSet

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 11 13:02:00 PST 2022


arsenm created this revision.
arsenm added a reviewer: aeubanks.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

https://reviews.llvm.org/D137863

Files:
  llvm/tools/llvm-reduce/deltas/Delta.cpp
  llvm/tools/llvm-reduce/deltas/Delta.h


Index: llvm/tools/llvm-reduce/deltas/Delta.h
===================================================================
--- llvm/tools/llvm-reduce/deltas/Delta.h
+++ llvm/tools/llvm-reduce/deltas/Delta.h
@@ -42,12 +42,39 @@
     return C1.Begin != C2.Begin || C1.End != C2.End;
   }
 
+  friend bool operator==(const Chunk &C1, const Chunk &C2) {
+    return C1.Begin == C2.Begin && C1.End == C2.End;
+  }
+
   /// Operator used for sets
   friend bool operator<(const Chunk &C1, const Chunk &C2) {
     return std::tie(C1.Begin, C1.End) < std::tie(C2.Begin, C2.End);
   }
 };
 
+template<>
+struct DenseMapInfo<Chunk> {
+  static inline Chunk getEmptyKey() {
+    return {DenseMapInfo<int>::getEmptyKey(),
+            DenseMapInfo<int>::getEmptyKey()};
+  }
+
+  static inline Chunk getTombstoneKey() {
+    return {DenseMapInfo<int>::getTombstoneKey(),
+            DenseMapInfo<int>::getTombstoneKey()};
+  }
+
+  static unsigned getHashValue(const Chunk Val) {
+    std::pair<int, int> PairVal = std::make_pair(Val.Begin, Val.End);
+    return DenseMapInfo<std::pair<int, int>>::getHashValue(PairVal);
+  }
+
+  static bool isEqual(const Chunk LHS, const Chunk RHS) {
+    return LHS == RHS;
+  }
+};
+
+
 /// Provides opaque interface for querying into ChunksToKeep without having to
 /// actually understand what is going on.
 class Oracle {
Index: llvm/tools/llvm-reduce/deltas/Delta.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -136,7 +136,7 @@
 CheckChunk(Chunk &ChunkToCheckForUninterestingness,
            std::unique_ptr<ReducerWorkItem> Clone, TestRunner &Test,
            ReductionFunc ExtractChunksFromModule,
-           std::set<Chunk> &UninterestingChunks,
+           DenseSet<Chunk> &UninterestingChunks,
            std::vector<Chunk> &ChunksStillConsideredInteresting) {
   // Take all of ChunksStillConsideredInteresting chunks, except those we've
   // already deemed uninteresting (UninterestingChunks) but didn't remove
@@ -188,7 +188,7 @@
 
 static SmallString<0> ProcessChunkFromSerializedBitcode(
     Chunk &ChunkToCheckForUninterestingness, TestRunner &Test,
-    ReductionFunc ExtractChunksFromModule, std::set<Chunk> &UninterestingChunks,
+    ReductionFunc ExtractChunksFromModule, DenseSet<Chunk> &UninterestingChunks,
     std::vector<Chunk> &ChunksStillConsideredInteresting,
     SmallString<0> &OriginalBC, std::atomic<bool> &AnyReduced) {
   LLVMContext Ctx;
@@ -270,7 +270,7 @@
   do {
     FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = false;
 
-    std::set<Chunk> UninterestingChunks;
+    DenseSet<Chunk> UninterestingChunks;
 
     // When running with more than one thread, serialize the original bitcode
     // to OriginalBC.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137863.474841.patch
Type: text/x-patch
Size: 2804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221111/42b501f1/attachment.bin>


More information about the llvm-commits mailing list