[llvm] 64d493f - [EquivalenceClasses] Return ECValue directly from insert (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 1 00:46:15 PDT 2025
Author: Florian Hahn
Date: 2025-04-01T08:45:46+01:00
New Revision: 64d493f987dc24b3d7e45daade9b0e8bfa1cc471
URL: https://github.com/llvm/llvm-project/commit/64d493f987dc24b3d7e45daade9b0e8bfa1cc471
DIFF: https://github.com/llvm/llvm-project/commit/64d493f987dc24b3d7e45daade9b0e8bfa1cc471.diff
LOG: [EquivalenceClasses] Return ECValue directly from insert (NFC).
Removes a redundant lookup in the mapping.:
Added:
Modified:
clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
llvm/include/llvm/ADT/EquivalenceClasses.h
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
llvm/lib/Transforms/Utils/SplitModule.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp b/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
index 02ec0d0213300..bbd73ef9b2f03 100644
--- a/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
+++ b/clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp
@@ -155,7 +155,7 @@ void simplifyConstraints(llvm::SetVector<const Formula *> &Constraints,
It != End; ++It) {
if (!It->isLeader())
continue;
- Atom At = *EquivalentAtoms.findLeader(It);
+ Atom At = *EquivalentAtoms.findLeader(*It);
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 f9c7819f18806..be46a4445c3f2 100644
--- a/llvm/include/llvm/ADT/EquivalenceClasses.h
+++ b/llvm/include/llvm/ADT/EquivalenceClasses.h
@@ -175,6 +175,11 @@ class EquivalenceClasses {
// 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());
+ }
+
member_iterator member_end() const {
return member_iterator(nullptr);
}
@@ -216,26 +221,28 @@ class EquivalenceClasses {
/// insert - Insert a new value into the union/find set, ignoring the request
/// if the value already exists.
- iterator insert(const ElemTy &Data) {
- return TheMapping.insert(ECValue(Data)).first;
+ const ECValue &insert(const ElemTy &Data) {
+ return *TheMapping.insert(ECValue(Data)).first;
}
/// findLeader - Given a value in the set, return a member iterator for the
/// equivalence class it is in. This does the path-compression part that
/// makes union-find "union findy". This returns an end iterator if the value
/// is not in the equivalence class.
- member_iterator findLeader(iterator I) const {
- if (I == TheMapping.end()) return member_end();
- return member_iterator(I->getLeader());
- }
member_iterator findLeader(const ElemTy &V) const {
- return findLeader(TheMapping.find(V));
+ auto I = TheMapping.find(V);
+ if (I == TheMapping.end())
+ return member_iterator(nullptr);
+ return findLeader(*I);
+ }
+ member_iterator findLeader(const ECValue &ECV) const {
+ return member_iterator(ECV.getLeader());
}
/// union - Merge the two equivalence sets for the specified values, inserting
/// them if they do not already exist in the equivalence set.
member_iterator unionSets(const ElemTy &V1, const ElemTy &V2) {
- iterator V1I = insert(V1), V2I = insert(V2);
+ const ECValue &V1I = insert(V1), &V2I = insert(V2);
return unionSets(findLeader(V1I), findLeader(V2I));
}
member_iterator unionSets(member_iterator L1, member_iterator L2) {
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 6cc5d1dc78d99..299b3a9162389 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -2239,7 +2239,7 @@ bool LowerTypeTestsModule::lower() {
auto Ins = TypeIdUsers.insert({TypeId, {}});
if (Ins.second) {
// Add the type identifier to the equivalence class.
- GlobalClassesTy::iterator GCI = GlobalClasses.insert(TypeId);
+ auto &GCI = GlobalClasses.insert(TypeId);
GlobalClassesTy::member_iterator CurSet = GlobalClasses.findLeader(GCI);
// Add the referenced globals to the type identifier's equivalence class.
diff --git a/llvm/lib/Transforms/Utils/SplitModule.cpp b/llvm/lib/Transforms/Utils/SplitModule.cpp
index 4f174fbe48b75..07956f3a191c4 100644
--- a/llvm/lib/Transforms/Utils/SplitModule.cpp
+++ b/llvm/lib/Transforms/Utils/SplitModule.cpp
@@ -203,7 +203,7 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap,
<< "\n");
for (ClusterMapType::member_iterator MI =
- GVtoClusterMap.findLeader(I.second);
+ GVtoClusterMap.findLeader(*I.second);
MI != GVtoClusterMap.member_end(); ++MI) {
if (!Visited.insert(*MI).second)
continue;
More information about the llvm-commits
mailing list