Skip to content

Commit efedaec

Browse files
lhamesPriyanshu3820
authored andcommitted
[ORC] Avoid self-dependence in SuperNode dependence graph. (llvm#169286)
Avoid adding any given SuperNode SN to its own SuperNode-deps set. This saves us from trying to redundantly merge its dependencies back into itself (a no-op, but a potentially expensive one).
1 parent 93ea99e commit efedaec

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

llvm/include/llvm/ExecutionEngine/Orc/WaitingOnGraph.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ template <typename ContainerIdT, typename ElementIdT> class WaitingOnGraph {
500500
if (I == SN->Deps.end())
501501
continue;
502502
for (auto &[DefElem, DefSN] : DefElems)
503-
if (I->second.erase(DefElem))
503+
if (I->second.erase(DefElem) && DefSN != SN.get())
504504
SNDeps.insert(DefSN);
505505
if (I->second.empty())
506506
SN->Deps.erase(I);
@@ -511,11 +511,13 @@ template <typename ContainerIdT, typename ElementIdT> class WaitingOnGraph {
511511
// Compute transitive closure of deps for each node.
512512
static void propagateSuperNodeDeps(SuperNodeDepsMap &SuperNodeDeps) {
513513
for (auto &[SN, Deps] : SuperNodeDeps) {
514-
DenseSet<SuperNode *> Reachable({SN});
514+
DenseSet<SuperNode *> Reachable;
515515
SmallVector<SuperNode *> Worklist(Deps.begin(), Deps.end());
516516

517517
while (!Worklist.empty()) {
518518
auto *DepSN = Worklist.pop_back_val();
519+
if (DepSN == SN)
520+
continue;
519521
if (!Reachable.insert(DepSN).second)
520522
continue;
521523
auto I = SuperNodeDeps.find(DepSN);
@@ -537,9 +539,11 @@ template <typename ContainerIdT, typename ElementIdT> class WaitingOnGraph {
537539
if (I == SuperNodeDeps.end())
538540
continue;
539541

540-
for (auto *DepSN : I->second)
542+
for (auto *DepSN : I->second) {
543+
assert(DepSN != SN.get() && "Unexpected self-dependence for SN");
541544
for (auto &[Container, Elems] : DepSN->Deps)
542545
SN->Deps[Container].insert(Elems.begin(), Elems.end());
546+
}
543547
}
544548
}
545549

0 commit comments

Comments
 (0)