Lang Hames 75eae603ff
[ORC] LinkGraphLinkingLayer::registerDependencies improvements. (#189298)
This commit moves the bulk of
LinkGraphLinkingLayer::registerDependencies into a new static method,
LinkGraphLinkingLayer::calculateDepGroups, where the behavior can be
unit tested.

The new method returns a list of LinkGraphLinkingLayer::SymbolDepGroups:

```
struct SymbolDepGroup {
  SmallVector<jitlink::Symbol*> Defs;
  DenseSet<jitlink::Symbol*> Deps;
};
```

The existing registerDependencies method converts these into
orc::SymbolDependenceGroups for registration with the ExecutionSession.

The calculateDepGroups method uses a new algorithm for calculating
dependencies between symbols in the LinkGraph. As before, the goal is to
compute dependencies of non-locally-scoped symbols defined within the
graph on other non-locally-scoped symbols in the graph (whether defined
by the graph or external). It is sufficient to record the first
non-locally-scoped symbol defined for each block reached (since such
symbols will have their own dependencies reported, and all such symbols
for a given block will have the same dependencies). The new algorithm
uses SCCIterator to visit strongly connected components within the
subgraph formed by edges to "anonymous" blocks (i.e. blocks that do not
define any non-locally-scoped symbols). These are visited in reverse-DFS
order, allowing dependencies to be efficiently propagated.

This change results in a ~2x speedup when JIT-loading clang (as tested
on a 2023 MacBook Pro, 12-core M3 Pro, 18Gb).
2026-03-30 15:18:36 +11:00
..