[llvm] [EquivalenceClasses] Introduce erase member function (PR #134660)

donald chen via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 9 20:43:49 PDT 2025


================
@@ -220,6 +221,57 @@ template <class ElemTy> class EquivalenceClasses {
     return *ECV;
   }
 
+  /// erase - Erase a value from the union/find set, return "true" if erase
+  /// succeeded.
+  bool erase(const ElemTy &V) {
+    if (!TheMapping.contains(V))
+      return false;
+    const ECValue *Cur = TheMapping[V];
+    const ECValue *Next = Cur->getNext();
+    // If the current element is the leader and has a successor element,
+    // update the successor element's 'Leader' field to be the last element,
+    // set the successor element's stolen bit, and set the 'Leader' field of
+    // all other elements in same class to be the successor element.
+    if (Cur->isLeader() && Next) {
+      Next->Leader = Cur->Leader;
+      Next->Next = reinterpret_cast<const ECValue *>(
+          reinterpret_cast<intptr_t>(Next->Next) | static_cast<intptr_t>(1));
+
+      const ECValue *newLeader = Next;
----------------
cxy-1993 wrote:

done

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


More information about the llvm-commits mailing list