-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
[mlir][IR] DominanceInfo
: Fix inconsistency in proper block/op dominance
#115413
Conversation
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: Matthias Springer (matthias-springer) ChangesAn operation is considered to properly dominate itself in a graph region. That's because there is no concept of "dominance" in a graph region. ( Previously, a block was not considered to dominate itself in a graph region. This commit fixes thise asymmetry between ops and blocks: both are now properly dominating themselves in a graph region. Full diff: https://github.com/llvm/llvm-project/pull/115413.diff 2 Files Affected:
diff --git a/mlir/include/mlir/IR/Dominance.h b/mlir/include/mlir/IR/Dominance.h
index 2536ce585b3fdd..66fdf1c4c6851b 100644
--- a/mlir/include/mlir/IR/Dominance.h
+++ b/mlir/include/mlir/IR/Dominance.h
@@ -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.
@@ -178,7 +178,8 @@ class DominanceInfo : public detail::DominanceInfoBase</*IsPostDom=*/false> {
/// 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.
+ /// through block A. In a Graph region, all blocks properly dominate all
+ /// blocks.
bool properlyDominates(Block *a, Block *b) const {
return super::properlyDominates(a, b);
}
diff --git a/mlir/lib/IR/Dominance.cpp b/mlir/lib/IR/Dominance.cpp
index 2b138ae223546e..31f7e7dbc925ce 100644
--- a/mlir/lib/IR/Dominance.cpp
+++ b/mlir/lib/IR/Dominance.cpp
@@ -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();
@@ -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
@@ -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);
|
9d46f80
to
502ea36
Compare
/// 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 |
There was a problem hiding this comment.
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.)
502ea36
to
e8c5e29
Compare
DominanceInfo
: Fix inconsistency in proper block/op dominance
Any way to exercise his in a test? |
e8c5e29
to
68c43c6
Compare
I updated the |
An operation is considered to properly dominate itself in a graph region. That's because there is no concept of "dominance" in a graph region. (`dominates` returns "true" for all pairs of ops in the same block.) Previously, a block was *not* considered to dominate itself in a graph region. This commit fixes thise asymmetry between ops and blocks: both are now properly dominating themselves in a graph region.
68c43c6
to
2052c65
Compare
…nance (llvm#115413) An operation is considered to properly dominate itself in a graph region. That's because there is no concept of "dominance" in a graph region. (`dominates` returns "true" for all pairs of ops in the same block. It makes sense to do the same for `properlyDominates`.) Previously, a block was *not* considered to dominate itself in a graph region. This commit fixes this asymmetry between ops and blocks: both are now properly dominating themselves in a graph region.
An operation is considered to properly dominate itself in a graph region. That's because there is no concept of "dominance" in a graph region. (
dominates
returns "true" for all pairs of ops in the same block. It makes sense to do the same forproperlyDominates
.)Previously, a block was not considered to dominate itself in a graph region. This commit fixes this asymmetry between ops and blocks: both are now properly dominating themselves in a graph region.