Skip to content

[mlir][IR] Make verifyDominanceOfContainedRegions iterative #74428

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
Dec 5, 2023
Merged
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
56 changes: 28 additions & 28 deletions mlir/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,39 +378,39 @@ static void diagnoseInvalidOperandDominance(Operation &op, unsigned operandNo) {
LogicalResult
OperationVerifier::verifyDominanceOfContainedRegions(Operation &op,
DominanceInfo &domInfo) {
for (Region &region : op.getRegions()) {
// Verify the dominance of each of the held operations.
for (Block &block : region) {
// Dominance is only meaningful inside reachable blocks.
bool isReachable = domInfo.isReachableFromEntry(&block);

for (Operation &op : block) {
if (isReachable) {
// Check that operands properly dominate this use.
for (const auto &operand : llvm::enumerate(op.getOperands())) {
if (domInfo.properlyDominates(operand.value(), &op))
continue;

diagnoseInvalidOperandDominance(op, operand.index());
return failure();
llvm::SmallVector<Operation *, 8> worklist{&op};
while (!worklist.empty()) {
auto *op = worklist.pop_back_val();
for (auto &region : op->getRegions())
for (auto &block : region.getBlocks()) {
// Dominance is only meaningful inside reachable blocks.
bool isReachable = domInfo.isReachableFromEntry(&block);
for (auto &op : block) {
if (isReachable) {
// Check that operands properly dominate this use.
for (const auto &operand : llvm::enumerate(op.getOperands())) {
if (domInfo.properlyDominates(operand.value(), &op))
continue;

diagnoseInvalidOperandDominance(op, operand.index());
return failure();
}
}
}

// Recursively verify dominance within each operation in the block, even
// if the block itself is not reachable, or we are in a region which
// doesn't respect dominance.
if (verifyRecursively && op.getNumRegions() != 0) {
// If this operation is IsolatedFromAbove, then we'll handle it in the
// outer verification loop.
if (op.hasTrait<OpTrait::IsIsolatedFromAbove>())
continue;

if (failed(verifyDominanceOfContainedRegions(op, domInfo)))
return failure();
// Recursively verify dominance within each operation in the block,
// even if the block itself is not reachable, or we are in a region
// which doesn't respect dominance.
if (verifyRecursively && op.getNumRegions() != 0) {
// If this operation is IsolatedFromAbove, then we'll handle it in
// the outer verification loop.
if (op.hasTrait<OpTrait::IsIsolatedFromAbove>())
continue;
worklist.push_back(&op);
}
}
}
}
}

return success();
}

Expand Down