diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2021-02-26 11:03:10 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-26 11:03:10 -0800 |
commit | cafe85d6d8d5a7497ebf40b8474052be0885e58f (patch) | |
tree | c38932e394bff7b2ad87660a55e985a76c4ace0b /src/shell-interface.h | |
parent | b3f67918fe34e7de76d1f5565bd3f07f4f7eb12f (diff) | |
download | binaryen-cafe85d6d8d5a7497ebf40b8474052be0885e58f.tar.gz binaryen-cafe85d6d8d5a7497ebf40b8474052be0885e58f.tar.bz2 binaryen-cafe85d6d8d5a7497ebf40b8474052be0885e58f.zip |
Use Tarjan's SCC alg. to find self-referential types (#3621)
Previously we computed the fixed point of the parent-child relation to identify
self-referential HeapTypes in the TypeBuilder canonicalizer. That algorithm was
O(|V|^3) in the worst case and took over five seconds to find the
self-referential HeapTypes in an example program with just 1134 HeapTypes,
probably due to high allocation traffic from the std::unordered_map and
std::unordered_sets used to implement the parent-child graph's adjacency list.
This PR replaces that algorithm with Tarjan's strongly connected component
algorithm, which runs in O(|V|+|E|) and finds the self-referential HeapTypes in
the mentioned example program in under 30 ms. All strongly connected components
of more than one element in the HeapType parent-child graph correspond to sets
of mutually recursive HeapTypes that are therefore self-referential. The only
other self-referential HeapTypes are those that are not mutually recursive with
any other HeapTypes, but these are trivial to find because they must be their
own direct children.
Diffstat (limited to 'src/shell-interface.h')
0 files changed, 0 insertions, 0 deletions