[llvm] Refactor the LeaderTable structure in GVN into a properly encapsulated data structure. (PR #88347)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 20:01:59 PDT 2024


================
@@ -232,13 +232,67 @@ class GVNPass : public PassInfoMixin<GVNPass> {
 
   /// A mapping from value numbers to lists of Value*'s that
   /// have that value number.  Use findLeader to query it.
-  struct LeaderTableEntry {
-    Value *Val;
-    const BasicBlock *BB;
-    LeaderTableEntry *Next;
+  class LeaderMap {
+  public:
+    struct LeaderTableEntry {
+      Value *Val;
+      const BasicBlock *BB;
+    };
+
+  private:
+    struct LeaderListNode {
+      LeaderTableEntry Entry;
+      LeaderListNode *Next;
+    };
+    DenseMap<uint32_t, LeaderListNode> NumToLeaders;
+    BumpPtrAllocator TableAllocator;
+
+  public:
+    class leader_iterator {
+      const LeaderListNode *current;
----------------
nikic wrote:

```suggestion
      const LeaderListNode *Current;
```
etc

https://github.com/llvm/llvm-project/pull/88347


More information about the llvm-commits mailing list