Skip to content

Commit 8f20da7

Browse files
committed
Add computeDominanceFrontier().
A trivial utility that returns the leaf blocks in a dominance subtree.
1 parent 522dc9d commit 8f20da7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

include/swift/SIL/Dominance.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ class DominanceInfo : public DominatorTreeBase {
8888
}
8989
};
9090

91+
/// Compute a single block's dominance frontier.
92+
///
93+
/// Precondition: no critical edges (OSSA)
94+
///
95+
/// Postcondition: each block in \p frontier is dominated by \p root and either
96+
/// exits the function or has a single successor that is not dominated by \p
97+
/// root.
98+
///
99+
/// With no critical edges, the dominance frontier is identified simply by leaf
100+
/// blocks in the dominance subtree.
101+
void computeDominanceFrontier(SILBasicBlock *root, DominanceInfo *domTree,
102+
SmallVectorImpl<SILBasicBlock *> &frontier);
103+
91104
/// Helper class for visiting basic blocks in dominance order, based on a
92105
/// worklist algorithm. Example usage:
93106
/// \code

lib/SIL/Utils/Dominance.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,22 @@ void PostDominanceInfo::verify() const {
141141
abort();
142142
}
143143
}
144+
145+
void
146+
swift::computeDominanceFrontier(SILBasicBlock *root,
147+
DominanceInfo *domTree,
148+
SmallVectorImpl<SILBasicBlock *> &frontier) {
149+
auto *function = root->getParent();
150+
assert(function->hasOwnership());
151+
assert(frontier.empty());
152+
153+
DominanceOrder domOrder(root, domTree);
154+
while (SILBasicBlock *block = domOrder.getNext()) {
155+
DominanceInfoNode *domNode = domTree->getNode(block);
156+
if (domNode->isLeaf()) {
157+
frontier.push_back(block);
158+
continue;
159+
}
160+
domOrder.pushChildren(block);
161+
}
162+
}

0 commit comments

Comments
 (0)