Skip to content

[llvm] Clean backport of upstream PR183272 - #23284

Draft
hahnjo wants to merge 2 commits into
root-project:masterfrom
hahnjo:backport-llvm-PR183272
Draft

[llvm] Clean backport of upstream PR183272#23284
hahnjo wants to merge 2 commits into
root-project:masterfrom
hahnjo:backport-llvm-PR183272

Conversation

@hahnjo

@hahnjo hahnjo commented Sep 7, 2026

Copy link
Copy Markdown
Member

Backport llvm/llvm-project@55ce4b7 as a dependency of llvm/llvm-project@db5ffb0 (llvm/llvm-project#183272)

(Clean) alternative to #23249

This reapplies 85354c6d8bc, which was reverted in d7347c0b81a due to bot
failures.

In this commit further changes are made to address the bot failure, and
general readability.

WaitingOnGraph::Coalescer::remove is renamed WaitingOnGraph::Coalescer::erase,
since its behavior is now similar to common container erase operations.

WaitingOnGraph::Coalescer::clear is provided to enable a fast reset of
Coalescer state.

SuperNodeBuilder::takeSuperNodes is updated to clear the Coalescer state before
returning the SuperNodes, ensuring that future calls to SuperNodeBuilder::add
do not trip the assert that caused the builder failures.
This commit replaces the core dependence propagation algorithm in
WaitingOnGraph to avoid worst-case behavior in the common case where
dependence graphs are sparse. This algorithm showed up as the underlying
cause of the bug in llvm/llvm-project#179611.

For each call to MaterializationResponsibility::notifyEmitted,
WaitingOnGraph would build the transitive closure of all SuperNodes
whose "waiting on" relationships were affected by the newly emitted
symbols, then propagate any remaining unemitted dependencies through
this transitive closure graph. This approach is simple, but pushes the
algorithm towards n^2 complexity even for sparse dependence graphs.

The new propagation algorithm:
1. Inverts the edge direction in the SymbolDependenceMap data structure:
SymbolDepMap[SN] now contains the set of SuperNodes that depend on SN,
rather than the set that SN depends upon.

2. Pushes dependencies through the SymbolDepMap iteratively until it
reaches a fixed point.

This updated algorithm converges much more quickly than the original for
the testcase reported in the issue, and for other cases tested so far.

No testcase yet, as this only affects performance. I've filed a
follow-up issue, llvm/llvm-project#183251, to
track construction of performance testing infrastructure for
WaitingOnGraph.

Should fix llvm/llvm-project#179611
@hahnjo hahnjo self-assigned this Sep 7, 2026
@hahnjo hahnjo added the in:Cling label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants