/// Verify the body of the given function.
LogicalResult verify(Function &fn);
+ /// Verify the given operation.
+ LogicalResult verify(Operation &op);
+
/// Returns the registered dialect for a dialect-specific attribute.
Dialect *getDialectForAttribute(const NamedAttribute &attr) {
assert(attr.first.strref().contains('.') && "expected dialect attribute");
private:
/// Verify the given potentially nested region or block.
- LogicalResult verifyRegion(Region ®ion, bool isTopLevel);
- LogicalResult verifyBlock(Block &block, bool isTopLevel);
+ LogicalResult verifyRegion(Region ®ion);
+ LogicalResult verifyBlock(Block &block);
LogicalResult verifyOperation(Operation &op);
/// Verify the dominance within the given IR unit.
LogicalResult verifyDominance(Region ®ion);
- LogicalResult verifyDominance(Block &block);
LogicalResult verifyDominance(Operation &op);
/// Emit an error for the given block.
/// Verify the body of the given function.
LogicalResult OperationVerifier::verify(Function &fn) {
// Verify the body first.
- if (failed(verifyRegion(fn.getBody(), /*isTopLevel=*/true)))
+ if (failed(verifyRegion(fn.getBody())))
return failure();
// Since everything looks structurally ok to this point, we do a dominance
// resilient to malformed code.
DominanceInfo theDomInfo(&fn);
domInfo = &theDomInfo;
- for (auto &block : fn)
- if (failed(verifyDominance(block)))
+ if (failed(verifyDominance(fn.getBody())))
+ return failure();
+
+ domInfo = nullptr;
+ return success();
+}
+
+/// Verify the given operation.
+LogicalResult OperationVerifier::verify(Operation &op) {
+ // Verify the operation first.
+ if (failed(verifyOperation(op)))
+ return failure();
+
+ // Since everything looks structurally ok to this point, we do a dominance
+ // check for any nested regions. We do this as a second pass since malformed
+ // CFG's can cause dominator analysis constructure to crash and we want the
+ // verifier to be resilient to malformed code.
+ DominanceInfo theDomInfo(&op);
+ domInfo = &theDomInfo;
+ for (auto ®ion : op.getRegions())
+ if (failed(verifyDominance(region)))
return failure();
domInfo = nullptr;
return success();
}
-LogicalResult OperationVerifier::verifyRegion(Region ®ion, bool isTopLevel) {
+LogicalResult OperationVerifier::verifyRegion(Region ®ion) {
if (region.empty())
return success();
// Verify each of the blocks within the region.
for (auto &block : region)
- if (failed(verifyBlock(block, isTopLevel)))
+ if (failed(verifyBlock(block)))
return failure();
return success();
}
-LogicalResult OperationVerifier::verifyBlock(Block &block, bool isTopLevel) {
+LogicalResult OperationVerifier::verifyBlock(Block &block) {
for (auto *arg : block.getArguments())
if (arg->getOwner() != &block)
return emitError(block, "block argument not owned by block");
// Verify that all child regions are ok.
for (auto ®ion : op.getRegions())
- if (failed(verifyRegion(region, /*isTopLevel=*/false)))
+ if (failed(verifyRegion(region)))
return failure();
// If this is a registered operation, there is nothing left to do.
return success();
}
-LogicalResult OperationVerifier::verifyDominance(Block &block) {
+LogicalResult OperationVerifier::verifyDominance(Region ®ion) {
// Verify the dominance of each of the held operations.
- for (auto &op : block)
- if (failed(verifyDominance(op)))
- return failure();
+ for (auto &block : region)
+ for (auto &op : block)
+ if (failed(verifyDominance(op)))
+ return failure();
return success();
}
// Verify the dominance of each of the nested blocks within this operation.
for (auto ®ion : op.getRegions())
- for (auto &block : region)
- if (failed(verifyDominance(block)))
- return failure();
+ if (failed(verifyDominance(region)))
+ return failure();
return success();
}
/// Perform (potentially expensive) checks of invariants, used to detect
/// compiler bugs. On error, this reports the error through the MLIRContext and
/// returns failure.
+LogicalResult Operation::verify() {
+ return OperationVerifier(getContext()).verify(*this);
+}
+
+/// Perform (potentially expensive) checks of invariants, used to detect
+/// compiler bugs. On error, this reports the error through the MLIRContext and
+/// returns failure.
LogicalResult Module::verify() {
/// Check that each function is correct.
for (auto &fn : *this)