Skip to content

[NFC][equivalenceClass] Refactor coding style in EquivalenceClasses.h. #135467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2025

Conversation

cxy-1993
Copy link
Contributor

No description provided.

@cxy-1993 cxy-1993 requested review from fhahn and kuhar April 12, 2025 02:34
@llvmbot
Copy link
Member

llvmbot commented Apr 12, 2025

@llvm/pr-subscribers-llvm-adt

Author: donald chen (cxy-1993)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/135467.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/EquivalenceClasses.h (+21-15)
diff --git a/llvm/include/llvm/ADT/EquivalenceClasses.h b/llvm/include/llvm/ADT/EquivalenceClasses.h
index 0d44d2c79dd2e..fed012ce56005 100644
--- a/llvm/include/llvm/ADT/EquivalenceClasses.h
+++ b/llvm/include/llvm/ADT/EquivalenceClasses.h
@@ -79,11 +79,15 @@ template <class ElemTy> class EquivalenceClasses {
     // ECValue ctor - Start out with EndOfList pointing to this node, Next is
     // Null, isLeader = true.
     ECValue(const ElemTy &Elt)
-      : Leader(this), Next((ECValue*)(intptr_t)1), Data(Elt) {}
+        : Leader(this),
+          Next(reinterpret_cast<ECValue *>(static_cast<intptr_t>(1))),
+          Data(Elt) {}
 
     const ECValue *getLeader() const {
-      if (isLeader()) return this;
-      if (Leader->isLeader()) return Leader;
+      if (isLeader())
+        return this;
+      if (Leader->isLeader())
+        return Leader;
       // Path compression.
       return Leader = Leader->getLeader();
     }
@@ -95,12 +99,16 @@ template <class ElemTy> class EquivalenceClasses {
 
     void setNext(const ECValue *NewNext) const {
       assert(getNext() == nullptr && "Already has a next pointer!");
-      Next = (const ECValue*)((intptr_t)NewNext | (intptr_t)isLeader());
+      Next = reinterpret_cast<const ECValue *>(
+          reinterpret_cast<intptr_t>(NewNext) |
+          static_cast<intptr_t>(isLeader()));
     }
 
   public:
-    ECValue(const ECValue &RHS) : Leader(this), Next((ECValue*)(intptr_t)1),
-                                  Data(RHS.Data) {
+    ECValue(const ECValue &RHS)
+        : Leader(this),
+          Next(reinterpret_cast<ECValue *>(static_cast<intptr_t>(1))),
+          Data(RHS.Data) {
       // Only support copying of singleton nodes.
       assert(RHS.isLeader() && RHS.getNext() == nullptr && "Not a singleton!");
     }
@@ -109,7 +117,8 @@ template <class ElemTy> class EquivalenceClasses {
     const ElemTy &getData() const { return Data; }
 
     const ECValue *getNext() const {
-      return (ECValue*)((intptr_t)Next & ~(intptr_t)1);
+      return reinterpret_cast<ECValue *>(reinterpret_cast<intptr_t>(Next) &
+                                         ~static_cast<intptr_t>(1));
     }
   };
 
@@ -124,9 +133,7 @@ template <class ElemTy> class EquivalenceClasses {
 
 public:
   EquivalenceClasses() = default;
-  EquivalenceClasses(const EquivalenceClasses &RHS) {
-    operator=(RHS);
-  }
+  EquivalenceClasses(const EquivalenceClasses &RHS) { operator=(RHS); }
 
   EquivalenceClasses &operator=(const EquivalenceClasses &RHS) {
     TheMapping.clear();
@@ -160,9 +167,7 @@ template <class ElemTy> class EquivalenceClasses {
     return member_iterator(ECV.isLeader() ? &ECV : nullptr);
   }
 
-  member_iterator member_end() const {
-    return member_iterator(nullptr);
-  }
+  member_iterator member_end() const { return member_iterator(nullptr); }
 
   iterator_range<member_iterator> members(const ECValue &ECV) const {
     return make_range(member_begin(ECV), member_end());
@@ -294,7 +299,8 @@ template <class ElemTy> class EquivalenceClasses {
   }
   member_iterator unionSets(member_iterator L1, member_iterator L2) {
     assert(L1 != member_end() && L2 != member_end() && "Illegal inputs!");
-    if (L1 == L2) return L1;   // Unifying the same two sets, noop.
+    if (L1 == L2)
+      return L1; // Unifying the same two sets, noop.
 
     // Otherwise, this is a real union operation.  Set the end of the L1 list to
     // point to the L2 leader node.
@@ -350,7 +356,7 @@ template <class ElemTy> class EquivalenceClasses {
       return *this;
     }
 
-    member_iterator operator++(int) {    // postincrement operators.
+    member_iterator operator++(int) { // postincrement operators.
       member_iterator tmp = *this;
       ++*this;
       return tmp;

@cxy-1993
Copy link
Contributor Author

This PR used clang-format to format the code style and also replaced C-style casts with C++ style casts.

@cxy-1993 cxy-1993 merged commit 7a6a795 into llvm:main Apr 12, 2025
13 checks passed
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants