[llvm] 9e5bfbf - [EquivalenceClasses] Update member_begin to take ECValue (NFC).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 1 01:29:09 PDT 2025


Author: Florian Hahn
Date: 2025-04-01T09:28:46+01:00
New Revision: 9e5bfbf77db0945f59c0d18012a8e6d43c711b3a

URL: https://github.com/llvm/llvm-project/commit/9e5bfbf77db0945f59c0d18012a8e6d43c711b3a
DIFF: https://github.com/llvm/llvm-project/commit/9e5bfbf77db0945f59c0d18012a8e6d43c711b3a.diff

LOG: [EquivalenceClasses] Update member_begin to take ECValue (NFC).

Remove a level of indirection and update code to use range-based for
loops.

Added: 
    

Modified: 
    clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
    llvm/include/llvm/ADT/EquivalenceClasses.h
    llvm/lib/Analysis/VectorUtils.cpp
    llvm/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp
    llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
    llvm/lib/Transforms/IPO/LowerTypeTests.cpp
    llvm/lib/Transforms/Scalar/Float2Int.cpp
    llvm/lib/Transforms/Scalar/LoopDistribute.cpp
    llvm/lib/Transforms/Utils/SplitModule.cpp
    llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp b/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
index bbd73ef9b2f03..69a90334c9df5 100644
--- a/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
+++ b/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
@@ -151,11 +151,10 @@ void simplifyConstraints(llvm::SetVector<const Formula *> &Constraints,
   }
 
   if (Info) {
-    for (auto It = EquivalentAtoms.begin(), End = EquivalentAtoms.end();
-         It != End; ++It) {
-      if (!It->isLeader())
+    for (const auto &E : EquivalentAtoms) {
+      if (!E.isLeader())
         continue;
-      Atom At = *EquivalentAtoms.findLeader(*It);
+      Atom At = *EquivalentAtoms.findLeader(E);
       if (TrueAtoms.contains(At) || FalseAtoms.contains(At))
         continue;
       llvm::SmallVector<Atom> Atoms =

diff  --git a/llvm/include/llvm/ADT/EquivalenceClasses.h b/llvm/include/llvm/ADT/EquivalenceClasses.h
index be46a4445c3f2..4f692052847aa 100644
--- a/llvm/include/llvm/ADT/EquivalenceClasses.h
+++ b/llvm/include/llvm/ADT/EquivalenceClasses.h
@@ -148,7 +148,7 @@ class EquivalenceClasses {
     TheMapping.clear();
     for (iterator I = RHS.begin(), E = RHS.end(); I != E; ++I)
       if (I->isLeader()) {
-        member_iterator MI = RHS.member_begin(I);
+        member_iterator MI = RHS.member_begin(*I);
         member_iterator LeaderIt = member_begin(insert(*MI));
         for (++MI; MI != member_end(); ++MI)
           unionSets(LeaderIt, member_begin(insert(*MI)));
@@ -171,13 +171,9 @@ class EquivalenceClasses {
 
   /// member_* Iterate over the members of an equivalence class.
   class member_iterator;
-  member_iterator member_begin(iterator I) const {
-    // Only leaders provide anything to iterate over.
-    return member_iterator(I->isLeader() ? &*I : nullptr);
-  }
   member_iterator member_begin(const ECValue &ECV) const {
     // Only leaders provide anything to iterate over.
-    return member_iterator(ECV.getLeader());
+    return member_iterator(ECV.isLeader() ? ECV.getLeader() : nullptr);
   }
 
   member_iterator member_end() const {

diff  --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp
index 91ba68fe03324..f57186589a325 100644
--- a/llvm/lib/Analysis/VectorUtils.cpp
+++ b/llvm/lib/Analysis/VectorUtils.cpp
@@ -843,9 +843,11 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
       if (U->getType()->isIntegerTy() && DBits.count(U) == 0)
         DBits[ECs.getOrInsertLeaderValue(I.first)] |= ~0ULL;
 
-  for (auto I = ECs.begin(), E = ECs.end(); I != E; ++I) {
+  for (const auto &E : ECs) {
+    if (!E.isLeader())
+      continue;
     uint64_t LeaderDemandedBits = 0;
-    for (Value *M : llvm::make_range(ECs.member_begin(I), ECs.member_end()))
+    for (Value *M : make_range(ECs.member_begin(E), ECs.member_end()))
       LeaderDemandedBits |= DBits[M];
 
     uint64_t MinBW = llvm::bit_width(LeaderDemandedBits);
@@ -857,7 +859,7 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
     // indvars.
     // If we are required to shrink a PHI, abandon this entire equivalence class.
     bool Abort = false;
-    for (Value *M : llvm::make_range(ECs.member_begin(I), ECs.member_end()))
+    for (Value *M : make_range(ECs.member_begin(E), ECs.member_end()))
       if (isa<PHINode>(M) && MinBW < M->getType()->getScalarSizeInBits()) {
         Abort = true;
         break;
@@ -865,7 +867,7 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
     if (Abort)
       continue;
 
-    for (Value *M : llvm::make_range(ECs.member_begin(I), ECs.member_end())) {
+    for (Value *M : make_range(ECs.member_begin(E), ECs.member_end())) {
       auto *MI = dyn_cast<Instruction>(M);
       if (!MI)
         continue;

diff  --git a/llvm/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp b/llvm/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp
index c27ec8e6dc6b3..c6d40cb00b252 100644
--- a/llvm/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp
+++ b/llvm/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp
@@ -367,8 +367,10 @@ bool AArch64A57FPLoadBalancing::runOnBasicBlock(MachineBasicBlock &MBB) {
 
   // Convert the EquivalenceClasses to a simpler set of sets.
   std::vector<std::vector<Chain*> > V;
-  for (auto I = EC.begin(), E = EC.end(); I != E; ++I) {
-    std::vector<Chain*> Cs(EC.member_begin(I), EC.member_end());
+  for (const auto &E : EC) {
+    if (!E.isLeader())
+      continue;
+    std::vector<Chain *> Cs(EC.member_begin(E), EC.member_end());
     if (Cs.empty()) continue;
     V.push_back(std::move(Cs));
   }

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
index 212b16cb3da6e..4a700bd213ed5 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
@@ -1016,12 +1016,12 @@ void RecursiveSearchSplitting::setupWorkList() {
     });
   }
 
-  for (auto I = NodeEC.begin(), E = NodeEC.end(); I != E; ++I) {
-    if (!I->isLeader())
+  for (const auto &Node : NodeEC) {
+    if (!Node.isLeader())
       continue;
 
     BitVector Cluster = SG.createNodesBitVector();
-    for (auto MI = NodeEC.member_begin(I); MI != NodeEC.member_end(); ++MI) {
+    for (auto MI = NodeEC.member_begin(Node); MI != NodeEC.member_end(); ++MI) {
       const SplitGraph::Node &N = SG.getNode(*MI);
       if (N.isGraphEntryPoint())
         N.getDependencies(Cluster);

diff  --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 299b3a9162389..11f9f0271395b 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -2350,7 +2350,7 @@ bool LowerTypeTestsModule::lower() {
     ++NumTypeIdDisjointSets;
 
     unsigned MaxUniqueId = 0;
-    for (GlobalClassesTy::member_iterator MI = GlobalClasses.member_begin(I);
+    for (GlobalClassesTy::member_iterator MI = GlobalClasses.member_begin(*I);
          MI != GlobalClasses.member_end(); ++MI) {
       if (auto *MD = dyn_cast_if_present<Metadata *>(*MI))
         MaxUniqueId = std::max(MaxUniqueId, TypeIdInfo[MD].UniqueId);
@@ -2368,7 +2368,7 @@ bool LowerTypeTestsModule::lower() {
     std::vector<GlobalTypeMember *> Globals;
     std::vector<ICallBranchFunnel *> ICallBranchFunnels;
     for (GlobalClassesTy::member_iterator MI =
-             GlobalClasses.member_begin(S.first);
+             GlobalClasses.member_begin(*S.first);
          MI != GlobalClasses.member_end(); ++MI) {
       if (isa<Metadata *>(*MI))
         TypeIds.push_back(cast<Metadata *>(*MI));

diff  --git a/llvm/lib/Transforms/Scalar/Float2Int.cpp b/llvm/lib/Transforms/Scalar/Float2Int.cpp
index 9d23c89943009..85c376c564d35 100644
--- a/llvm/lib/Transforms/Scalar/Float2Int.cpp
+++ b/llvm/lib/Transforms/Scalar/Float2Int.cpp
@@ -311,14 +311,15 @@ bool Float2IntPass::validateAndTransform(const DataLayout &DL) {
   bool MadeChange = false;
 
   // Iterate over every disjoint partition of the def-use graph.
-  for (auto It = ECs.begin(), E = ECs.end(); It != E; ++It) {
+  for (const auto &E : ECs) {
+    if (!E.isLeader())
+      continue;
     ConstantRange R(MaxIntegerBW + 1, false);
     bool Fail = false;
     Type *ConvertedToTy = nullptr;
 
     // For every member of the partition, union all the ranges together.
-    for (auto MI = ECs.member_begin(It), ME = ECs.member_end();
-         MI != ME; ++MI) {
+    for (auto MI = ECs.member_begin(E), ME = ECs.member_end(); MI != ME; ++MI) {
       Instruction *I = *MI;
       auto SeenI = SeenInsts.find(I);
       if (SeenI == SeenInsts.end())
@@ -348,8 +349,8 @@ bool Float2IntPass::validateAndTransform(const DataLayout &DL) {
 
     // If the set was empty, or we failed, or the range is poisonous,
     // bail out.
-    if (ECs.member_begin(It) == ECs.member_end() || Fail ||
-        R.isFullSet() || R.isSignWrappedSet())
+    if (ECs.member_begin(E) == ECs.member_end() || Fail || R.isFullSet() ||
+        R.isSignWrappedSet())
       continue;
     assert(ConvertedToTy && "Must have set the convertedtoty by this point!");
 
@@ -388,8 +389,7 @@ bool Float2IntPass::validateAndTransform(const DataLayout &DL) {
       }
     }
 
-    for (auto MI = ECs.member_begin(It), ME = ECs.member_end();
-         MI != ME; ++MI)
+    for (auto MI = ECs.member_begin(E), ME = ECs.member_end(); MI != ME; ++MI)
       convert(*MI, Ty);
     MadeChange = true;
   }

diff  --git a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
index efbd1b89aca8f..5f03d854b51e6 100644
--- a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
@@ -385,14 +385,13 @@ class InstPartitionContainer {
 
     // Merge the member of an equivalence class into its class leader.  This
     // makes the members empty.
-    for (ToBeMergedT::iterator I = ToBeMerged.begin(), E = ToBeMerged.end();
-         I != E; ++I) {
-      if (!I->isLeader())
+    for (const auto &C : ToBeMerged) {
+      if (!C.isLeader())
         continue;
 
-      auto PartI = I->getData();
-      for (auto *PartJ : make_range(std::next(ToBeMerged.member_begin(I)),
-                                   ToBeMerged.member_end())) {
+      auto PartI = C.getData();
+      for (auto *PartJ : make_range(std::next(ToBeMerged.member_begin(C)),
+                                    ToBeMerged.member_end())) {
         PartJ->moveTo(*PartI);
       }
     }

diff  --git a/llvm/lib/Transforms/Utils/SplitModule.cpp b/llvm/lib/Transforms/Utils/SplitModule.cpp
index 07956f3a191c4..507e3c7a42737 100644
--- a/llvm/lib/Transforms/Utils/SplitModule.cpp
+++ b/llvm/lib/Transforms/Utils/SplitModule.cpp
@@ -182,7 +182,7 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap,
        I != E; ++I)
     if (I->isLeader())
       Sets.push_back(
-          std::make_pair(std::distance(GVtoClusterMap.member_begin(I),
+          std::make_pair(std::distance(GVtoClusterMap.member_begin(*I),
                                        GVtoClusterMap.member_end()),
                          I));
 

diff  --git a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
index 770494405810d..feaa3602f88cb 100644
--- a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
@@ -581,10 +581,9 @@ CombineRuleOperandTypeChecker::getRuleEqClasses() const {
 
   if (DebugTypeInfer) {
     errs() << "Final Type Equivalence Classes: ";
-    for (auto ClassIt = TECs.begin(); ClassIt != TECs.end(); ++ClassIt) {
+    for (const auto &Class : TECs) {
       // only print non-empty classes.
-      if (auto MembIt = TECs.member_begin(ClassIt);
-          MembIt != TECs.member_end()) {
+      if (auto MembIt = TECs.member_begin(Class); MembIt != TECs.member_end()) {
         errs() << '[';
         StringRef Sep = "";
         for (; MembIt != TECs.member_end(); ++MembIt) {


        


More information about the llvm-commits mailing list