Skip to content

Commit 2c62332

Browse files
committed
Update the code based on comments
1 parent acf94ab commit 2c62332

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

llvm/include/llvm/ADT/EquivalenceClasses.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "llvm/ADT/DenseMap.h"
1919
#include "llvm/ADT/SmallVector.h"
20+
#include "llvm/ADT/STLExtras.h"
2021
#include "llvm/ADT/iterator_range.h"
2122
#include "llvm/Support/Allocator.h"
2223
#include <cassert>
@@ -220,13 +221,18 @@ template <class ElemTy> class EquivalenceClasses {
220221
return *ECV;
221222
}
222223

223-
/// erase - Erase a value from the union/find set, return if erase succeed.
224+
/// erase - Erase a value from the union/find set, return "true" if erase
225+
/// succeeded.
224226
bool erase(const ElemTy &V) {
225227
if (!TheMapping.contains(V))
226228
return false;
227229
const ECValue *Cur = TheMapping[V];
228230
const ECValue *Next = Cur->getNext();
229231
if (Cur->isLeader()) {
232+
// If the current element is the leader and has a successor element,
233+
// update the successor element's 'Leader' field to be the last element,
234+
// set the successor element's stolen bit, and set the 'Leader' field of
235+
// all other elements in same class to be the successor element.
230236
if (Next) {
231237
Next->Leader = Cur->Leader;
232238
Next->Next = (const ECValue *)((intptr_t)Next->Next | (intptr_t)1);
@@ -242,21 +248,26 @@ template <class ElemTy> class EquivalenceClasses {
242248
Pre = Pre->getNext();
243249
}
244250
if (!Next) {
251+
// If the current element is the last element(not leader), set the
252+
// successor of the current element's predecessor to null, and set
253+
// the 'Leader' field of the class leader to the predecessor element.
245254
Pre->Next = nullptr;
246255
Leader->Leader = Pre;
247256
} else {
257+
// If the current element is in the middle of class, then simply
258+
// connect the predecessor element and the successor element.
248259
Pre->Next =
249260
(const ECValue *)((intptr_t)Next | (intptr_t)Pre->isLeader());
250261
Next->Leader = Pre;
251262
}
252263
}
264+
265+
// Update 'TheMapping' and 'Members'.
266+
assert(TheMapping.contains(V) && "Can't find input in TheMapping!");
253267
TheMapping.erase(V);
254-
for (auto I = Members.begin(); I != Members.end(); I++) {
255-
if (*I == Cur) {
256-
Members.erase(I);
257-
break;
258-
}
259-
}
268+
auto I = llvm::find(Members, Cur);
269+
assert(I != Members.end() && "Can't find input in members!");
270+
Members.erase(I);
260271
return true;
261272
}
262273

0 commit comments

Comments
 (0)