Skip to content

Commit 64d493f

Browse files
committed
[EquivalenceClasses] Return ECValue directly from insert (NFC).
Removes a redundant lookup in the mapping.:
1 parent c5afcfe commit 64d493f

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

clang/lib/Analysis/FlowSensitive/SimplifyConstraints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void simplifyConstraints(llvm::SetVector<const Formula *> &Constraints,
155155
It != End; ++It) {
156156
if (!It->isLeader())
157157
continue;
158-
Atom At = *EquivalentAtoms.findLeader(It);
158+
Atom At = *EquivalentAtoms.findLeader(*It);
159159
if (TrueAtoms.contains(At) || FalseAtoms.contains(At))
160160
continue;
161161
llvm::SmallVector<Atom> Atoms =

llvm/include/llvm/ADT/EquivalenceClasses.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ class EquivalenceClasses {
175175
// Only leaders provide anything to iterate over.
176176
return member_iterator(I->isLeader() ? &*I : nullptr);
177177
}
178+
member_iterator member_begin(const ECValue &ECV) const {
179+
// Only leaders provide anything to iterate over.
180+
return member_iterator(ECV.getLeader());
181+
}
182+
178183
member_iterator member_end() const {
179184
return member_iterator(nullptr);
180185
}
@@ -216,26 +221,28 @@ class EquivalenceClasses {
216221

217222
/// insert - Insert a new value into the union/find set, ignoring the request
218223
/// if the value already exists.
219-
iterator insert(const ElemTy &Data) {
220-
return TheMapping.insert(ECValue(Data)).first;
224+
const ECValue &insert(const ElemTy &Data) {
225+
return *TheMapping.insert(ECValue(Data)).first;
221226
}
222227

223228
/// findLeader - Given a value in the set, return a member iterator for the
224229
/// equivalence class it is in. This does the path-compression part that
225230
/// makes union-find "union findy". This returns an end iterator if the value
226231
/// is not in the equivalence class.
227-
member_iterator findLeader(iterator I) const {
228-
if (I == TheMapping.end()) return member_end();
229-
return member_iterator(I->getLeader());
230-
}
231232
member_iterator findLeader(const ElemTy &V) const {
232-
return findLeader(TheMapping.find(V));
233+
auto I = TheMapping.find(V);
234+
if (I == TheMapping.end())
235+
return member_iterator(nullptr);
236+
return findLeader(*I);
237+
}
238+
member_iterator findLeader(const ECValue &ECV) const {
239+
return member_iterator(ECV.getLeader());
233240
}
234241

235242
/// union - Merge the two equivalence sets for the specified values, inserting
236243
/// them if they do not already exist in the equivalence set.
237244
member_iterator unionSets(const ElemTy &V1, const ElemTy &V2) {
238-
iterator V1I = insert(V1), V2I = insert(V2);
245+
const ECValue &V1I = insert(V1), &V2I = insert(V2);
239246
return unionSets(findLeader(V1I), findLeader(V2I));
240247
}
241248
member_iterator unionSets(member_iterator L1, member_iterator L2) {

llvm/lib/Transforms/IPO/LowerTypeTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,7 @@ bool LowerTypeTestsModule::lower() {
22392239
auto Ins = TypeIdUsers.insert({TypeId, {}});
22402240
if (Ins.second) {
22412241
// Add the type identifier to the equivalence class.
2242-
GlobalClassesTy::iterator GCI = GlobalClasses.insert(TypeId);
2242+
auto &GCI = GlobalClasses.insert(TypeId);
22432243
GlobalClassesTy::member_iterator CurSet = GlobalClasses.findLeader(GCI);
22442244

22452245
// Add the referenced globals to the type identifier's equivalence class.

llvm/lib/Transforms/Utils/SplitModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap,
203203
<< "\n");
204204

205205
for (ClusterMapType::member_iterator MI =
206-
GVtoClusterMap.findLeader(I.second);
206+
GVtoClusterMap.findLeader(*I.second);
207207
MI != GVtoClusterMap.member_end(); ++MI) {
208208
if (!Visited.insert(*MI).second)
209209
continue;

0 commit comments

Comments
 (0)