[llvm] [ORC] Avoid self-dependence in SuperNode dependence graph. (PR #169286)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 23 23:15:27 PST 2025
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/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).
>From 05ed3f2535ef737e944f3d3ca0c50ca188d8156f Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Mon, 24 Nov 2025 17:25:06 +1100
Subject: [PATCH] [ORC] Avoid self-dependence in SuperNode dependence graph.
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).
---
llvm/include/llvm/ExecutionEngine/Orc/WaitingOnGraph.h | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/WaitingOnGraph.h b/llvm/include/llvm/ExecutionEngine/Orc/WaitingOnGraph.h
index f9995917363f9..9f14c8b2efd5f 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/WaitingOnGraph.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/WaitingOnGraph.h
@@ -500,7 +500,7 @@ template <typename ContainerIdT, typename ElementIdT> class WaitingOnGraph {
if (I == SN->Deps.end())
continue;
for (auto &[DefElem, DefSN] : DefElems)
- if (I->second.erase(DefElem))
+ if (I->second.erase(DefElem) && DefSN != SN.get())
SNDeps.insert(DefSN);
if (I->second.empty())
SN->Deps.erase(I);
@@ -511,11 +511,13 @@ template <typename ContainerIdT, typename ElementIdT> class WaitingOnGraph {
// Compute transitive closure of deps for each node.
static void propagateSuperNodeDeps(SuperNodeDepsMap &SuperNodeDeps) {
for (auto &[SN, Deps] : SuperNodeDeps) {
- DenseSet<SuperNode *> Reachable({SN});
+ DenseSet<SuperNode *> Reachable;
SmallVector<SuperNode *> Worklist(Deps.begin(), Deps.end());
while (!Worklist.empty()) {
auto *DepSN = Worklist.pop_back_val();
+ if (DepSN == SN)
+ continue;
if (!Reachable.insert(DepSN).second)
continue;
auto I = SuperNodeDeps.find(DepSN);
@@ -537,9 +539,11 @@ template <typename ContainerIdT, typename ElementIdT> class WaitingOnGraph {
if (I == SuperNodeDeps.end())
continue;
- for (auto *DepSN : I->second)
+ for (auto *DepSN : I->second) {
+ assert(DepSN != SN.get() && "Unexpected self-dependence for SN");
for (auto &[Container, Elems] : DepSN->Deps)
SN->Deps[Container].insert(Elems.begin(), Elems.end());
+ }
}
}
More information about the llvm-commits
mailing list