Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dad6624
Add a dominator-tree WTO utility for reducible CFGs
tlively Oct 2, 2026
eb5b060
Use WTOWorklist in ConstraintAnalysis and RedundantSetElimination
tlively Oct 2, 2026
d1eb897
Use BasicBlock::contents.index in DomTree
tlively Oct 2, 2026
50f7064
Work around clang++-18 crash on defaulted WTOCycle::operator==
tlively Oct 6, 2026
60f33d0
Merge branch 'domtree-wto2' into wto-passes
tlively Oct 6, 2026
4850b4c
Merge branch 'wto-passes' into domtree-block-indices
tlively Oct 6, 2026
08750e7
tighten up definition
tlively Oct 6, 2026
4aea7cd
Moar comments (I wrote them myself!)
tlively Oct 6, 2026
a469c96
mini CFG comment
tlively Oct 6, 2026
f4d0e76
recursion comments
tlively Oct 7, 2026
f1a4061
Work around GCC 11 ICE on local static constexpr in WTO
tlively Oct 7, 2026
bece156
Merge branch 'domtree-wto2' into wto-passes
tlively Oct 7, 2026
865e017
Merge branch 'wto-passes' into domtree-block-indices
tlively Oct 7, 2026
9fb7800
Merge branch 'main' into wto-passes
tlively Oct 7, 2026
2f54272
Merge branch 'wto-passes' into domtree-block-indices
tlively Oct 7, 2026
8964e96
"for domtree"
tlively Oct 7, 2026
91d6872
setBlockIndices
tlively Oct 7, 2026
5001f17
Merge branch 'main' into wto-passes
tlively Oct 7, 2026
4b1947a
Merge branch 'wto-passes' into domtree-block-indices
tlively Oct 7, 2026
db7d4fe
Merge branch 'main' into domtree-block-indices
tlively Oct 9, 2026
7b7eeb7
Have DomTree set block indices itself
tlively Oct 9, 2026
1ff7152
Collapse inner loops with union-find during WTO construction (#9218)
tlively Oct 9, 2026
cb502e1
Revert "Collapse inner loops with union-find during WTO construction …
tlively Oct 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/cfg/domtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace wasm {
// etc.
//
// The BasicBlock type is assumed to have a ".in" property which declares a
// vector of pointers to the incoming blocks, that is, the predecessors.
// vector of pointers to the incoming blocks, that is, the predecessors, and a
// ".contents.index" property to hold each block's index in `blocks`.
template<typename BasicBlock> struct DomTree {
std::vector<Index> iDoms;

Expand Down Expand Up @@ -83,9 +84,8 @@ DomTree<BasicBlock>::DomTree(std::vector<std::unique_ptr<BasicBlock>>& blocks) {
}

// Map basic blocks to their indices.
std::unordered_map<BasicBlock*, Index> blockIndices;
for (Index i = 0; i < numBlocks; i++) {
blockIndices[blocks[i].get()] = i;
blocks[i]->contents.index = i;
}

// Initialize the iDoms array. The entry starts with its own index, which is
Expand All @@ -107,14 +107,14 @@ DomTree<BasicBlock>::DomTree(std::vector<std::unique_ptr<BasicBlock>>& blocks) {
auto& preds = blocks[index]->in;
Index newParent = nonsense;
for (auto* pred : preds) {
auto predIndex = blockIndices[pred];
Index predIndex = pred->contents.index;

// In a reducible graph, we only need to care about the predecessors
// that appear before us in the reverse postorder numbering. The only
// predecessor that can appear *after* us is a loop backedge, but that
// that appear before us in the reverse postorder numbering. Any
// predecessor that appears at or after us is a loop backedge, which
// will never dominate the loop - the loop is dominated by its single
// entry (since it is reducible, it has just one entry).
if (predIndex > index) {
if (predIndex >= index) {
Comment thread
kripken marked this conversation as resolved.
continue;
}

Expand Down
17 changes: 4 additions & 13 deletions src/cfg/wto.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ WeakTopologicalOrdering<BasicBlock>::WeakTopologicalOrdering(
return;
}

for (Index i = 0; i < numBlocks; ++i) {
blocks[i]->contents.index = i;
}

// TODO: Avoid building an unordered_map of block indices in DomTree when
// BasicBlock already stores its RPO index on `contents`.
DomTree<BasicBlock> domTree(blocks);

auto isReachable = [&](Index i) {
Expand Down Expand Up @@ -253,8 +247,8 @@ WeakTopologicalOrdering<BasicBlock>::WeakTopologicalOrdering(
// fixed-point analysis over its basic blocks using a Weak Topological Ordering.
//
// Usage:
// 1. Construct `WTOWorklist work(cfg);` (which initializes `inQueue` and
// `index` on each block's `contents`).
// 1. Construct `WTOWorklist work(cfg);` (which initializes `inQueue` on each
// block's `contents`).
// 2. Seed the initial block(s) to evaluate via `work.push(cfg.entry);`.
// 3. Call `work.run([&](BasicBlock* block) { ... });`. Inside the visitor
// callback, evaluate the transfer function for `block` and call
Expand All @@ -272,11 +266,8 @@ template<typename CFG> struct WTOWorklist {
CFG& cfg;

WTOWorklist(CFG& cfg) : cfg(cfg) {
auto& basicBlocks = cfg.basicBlocks;
for (Index i = 0; i < basicBlocks.size(); ++i) {
auto& contents = basicBlocks[i]->contents;
contents.inQueue = false;
contents.index = i;
for (auto& block : cfg.basicBlocks) {
block->contents.inQueue = false;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/passes/OnceReduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ struct Scanner : public WalkerPass<PostWalker<Scanner>> {

// Information in a basic block.
struct BlockInfo {
// For DomTree.
Index index;

// We track relevant expressions, which are call to "once" functions, and
// writes to "once" globals.
std::vector<Expression*> exprs;
Expand Down
3 changes: 3 additions & 0 deletions test/example/domtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using namespace wasm;

struct BasicBlock {
struct {
Index index;
} contents;
std::vector<BasicBlock*> in;

void addPred(BasicBlock* pred) { in.push_back(pred); }
Expand Down
Loading