[llvm] [SandboxVec][Scheduler][NFC] ReadyListContainer::contains() is now constant time (PR #215418)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 22:39:13 PDT 2026
================
@@ -69,40 +71,51 @@ class ReadyListContainer {
assert(!contains(N) && "Node already exists in ready list!");
#endif
List.push(N);
+ Set.insert(N);
+ assert(List.size() == Set.size() && "List and Set out-of-sync!");
}
DGNode *pop() {
auto *Back = List.top();
List.pop();
+ Set.erase(Back);
+ assert(List.size() == Set.size() && "List and Set out-of-sync!");
return Back;
}
- bool empty() const { return List.empty(); }
- void clear() { List = {}; }
+ bool empty() const {
+ assert(List.empty() == Set.empty() && "List and Set out-of-sync!");
+ return List.empty();
+ }
+ void clear() {
+ List.clear();
+ Set.clear();
+ }
bool contains(DGNode *N) const {
- // TODO: We should update the data structure to make this O(1).
- auto ListCopy = List;
- while (!ListCopy.empty()) {
- DGNode *Top = ListCopy.top();
- if (Top == N)
- return true;
- ListCopy.pop();
- }
- return false;
+#ifndef NDEBUG
+ // TODO: We should eventually remove this check.
+ auto ListContains = [this](DGNode *N) {
+ auto ListCopy = List;
+ while (!ListCopy.empty()) {
+ DGNode *Top = ListCopy.top();
+ if (Top == N)
+ return true;
+ ListCopy.pop();
+ }
+ return false;
+ };
+ assert(ListContains(N) == Set.contains(N) && "List and Set out-of-sync!");
+#endif
+ return Set.contains(N);
}
- /// \Removes \p N if found in the ready list.
+ /// \Removes \p N if found in the ready list. Note: this is linear time!
----------------
vporpo wrote:
The linear time component is the removal from the PriorityQueue with erase_one() (line 116).
https://github.com/llvm/llvm-project/pull/215418
More information about the llvm-commits
mailing list