Skip to content

[mlir][IR] DominanceInfo: Fix inconsistency in proper block/op dominance #115413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions mlir/include/mlir/IR/Dominance.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class DominanceInfo : public detail::DominanceInfoBase</*IsPostDom=*/false> {
/// are in the same block and A properly dominates B within the block, or if
/// the block that contains A properly dominates the block that contains B. In
/// an SSACFG region, Operation A dominates Operation B in the same block if A
/// preceeds B. In a Graph region, all operations in a block dominate all
/// other operations in the same block.
/// preceeds B. In a Graph region, all operations in a block properly dominate
/// all operations in the same block.
///
/// The `enclosingOpOk` flag says whether we should return true if the B op
/// is enclosed by a region on A.
Expand Down Expand Up @@ -176,9 +176,14 @@ class DominanceInfo : public detail::DominanceInfoBase</*IsPostDom=*/false> {
/// Return true if the specified block A properly dominates block B, i.e.: if
/// block A contains block B, or if the region which contains block A also
/// contains block B or some parent of block B and block A dominates that
/// block in that kind of region. In an SSACFG region, block A dominates
/// block B if all control flow paths from the entry block to block B flow
/// through block A. In a Graph region, all blocks dominate all other blocks.
/// block in that kind of region.
///
/// In an SSACFG region, block A dominates block B if all control flow paths
/// from the entry block to block B flow through block A.
///
/// Graph regions have only a single block. To be consistent with "proper
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This could also go the other way. We could say that an operation does not dominate itself in a graph region. But I find the current definition a bit more intuitive. (Considering that "dominance" does not exist in a graph region, so it does not matter at all which ops we are "comparing" in the same region.)

/// dominance" of ops, the single block is considered to properly dominate
/// itself in a graph region.
bool properlyDominates(Block *a, Block *b) const {
return super::properlyDominates(a, b);
}
Expand Down
10 changes: 6 additions & 4 deletions mlir/lib/IR/Dominance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ DominanceInfoBase<IsPostDom>::~DominanceInfoBase() {
delete entry.second.getPointer();
}

template <bool IsPostDom> void DominanceInfoBase<IsPostDom>::invalidate() {
template <bool IsPostDom>
void DominanceInfoBase<IsPostDom>::invalidate() {
for (auto entry : dominanceInfos)
delete entry.second.getPointer();
dominanceInfos.clear();
Expand Down Expand Up @@ -217,9 +218,10 @@ template <bool IsPostDom>
bool DominanceInfoBase<IsPostDom>::properlyDominates(Block *a, Block *b) const {
assert(a && b && "null blocks not allowed");

// A block dominates itself but does not properly dominate itself.
// A block dominates, but does not properly dominate, itself unless this
// is a graph region.
if (a == b)
return false;
return !hasSSADominance(a);

// If both blocks are not in the same region, `a` properly dominates `b` if
// `b` is defined in an operation region that (recursively) ends up being
Expand Down Expand Up @@ -269,7 +271,7 @@ bool DominanceInfo::properlyDominatesImpl(Operation *a, Operation *b,
Block *aBlock = a->getBlock(), *bBlock = b->getBlock();
assert(aBlock && bBlock && "operations must be in a block");

// An instruction dominates, but does not properlyDominate, itself unless this
// An operation dominates, but does not properly dominate, itself unless this
// is a graph region.
if (a == b)
return !hasSSADominance(aBlock);
Expand Down
Loading
Loading