Skip to content

Commit

Permalink
[Verifier] Inline a method to simplify the code in preparation for bi…
Browse files Browse the repository at this point in the history
…gger changes, NFC.

Differential Revision: https://reviews.llvm.org/D103365
  • Loading branch information
lattner committed May 29, 2021
1 parent ffb48d4 commit d11abdf
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions mlir/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class OperationVerifier {
LogicalResult verifyBlock(Block &block);
LogicalResult verifyOperation(Operation &op);

/// Verify the dominance property of operations within the given Region.
LogicalResult verifyDominance(Region &region);

/// Verify the dominance property of regions contained within the given
/// Operation.
LogicalResult verifyDominanceOfContainedRegions(Operation &op);
Expand Down Expand Up @@ -302,41 +299,36 @@ static void diagnoseInvalidOperandDominance(Operation &op, unsigned operandNo) {
note << " neither in a parent nor in a child region)";
}

LogicalResult OperationVerifier::verifyDominance(Region &region) {
// 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 (unsigned operandNo = 0, e = op.getNumOperands(); operandNo != e;
++operandNo) {
if (domInfo->properlyDominates(op.getOperand(operandNo), &op))
continue;

diagnoseInvalidOperandDominance(op, operandNo);
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 (failed(verifyDominanceOfContainedRegions(op)))
return failure();
}
}
return success();
}

/// Verify the dominance of each of the nested blocks within the given operation
LogicalResult
OperationVerifier::verifyDominanceOfContainedRegions(Operation &op) {
for (Region &region : op.getRegions()) {
if (failed(verifyDominance(region)))
return failure();
// 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 (unsigned operandNo = 0, e = op.getNumOperands(); operandNo != e;
++operandNo) {
if (domInfo->properlyDominates(op.getOperand(operandNo), &op))
continue;

diagnoseInvalidOperandDominance(op, operandNo);
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 (op.getNumRegions() != 0)
if (failed(verifyDominanceOfContainedRegions(op)))
return failure();
}
}
}
return success();
}
Expand Down

0 comments on commit d11abdf

Please sign in to comment.