[Mlir-commits] [mlir] be8ad4e - [Verifier] Slightly refactor code to reduce duplication, NFC.
Chris Lattner
llvmlistbot at llvm.org
Sat May 1 11:43:22 PDT 2021
Author: Chris Lattner
Date: 2021-05-01T11:43:15-07:00
New Revision: be8ad4e98e1fd26057471a98d6404bfdb00235cd
URL: https://github.com/llvm/llvm-project/commit/be8ad4e98e1fd26057471a98d6404bfdb00235cd
DIFF: https://github.com/llvm/llvm-project/commit/be8ad4e98e1fd26057471a98d6404bfdb00235cd.diff
LOG: [Verifier] Slightly refactor code to reduce duplication, NFC.
Added:
Modified:
mlir/lib/IR/Verifier.cpp
Removed:
################################################################################
diff --git a/mlir/lib/IR/Verifier.cpp b/mlir/lib/IR/Verifier.cpp
index 65dad3ea35cd1..09daf4261f1ed 100644
--- a/mlir/lib/IR/Verifier.cpp
+++ b/mlir/lib/IR/Verifier.cpp
@@ -137,10 +137,11 @@ LogicalResult OperationVerifier::verifyBlock(Block &block) {
return emitError(block, "empty block: expect at least a terminator");
}
- // Verify the non-terminator operations separately so that we can verify
- // they have no successors.
- for (auto &op : llvm::make_range(block.begin(), std::prev(block.end()))) {
- if (op.getNumSuccessors() != 0)
+ // Check each operation, and make sure there are no branches out of the
+ // middle of this block.
+ for (auto &op : llvm::make_range(block.begin(), block.end())) {
+ // Only the last instructions is allowed to have successors.
+ if (op.getNumSuccessors() != 0 && &op != &block.back())
return op.emitError(
"operation with block successors must terminate its parent block");
@@ -148,11 +149,6 @@ LogicalResult OperationVerifier::verifyBlock(Block &block) {
return failure();
}
- // Verify the terminator.
- Operation &terminator = block.back();
- if (failed(verifyOperation(terminator)))
- return failure();
-
// Verify that this block is not branching to a block of a
diff erent
// region.
for (Block *successor : block.getSuccessors())
@@ -164,6 +160,7 @@ LogicalResult OperationVerifier::verifyBlock(Block &block) {
if (mayBeValidWithoutTerminator(&block))
return success();
+ Operation &terminator = block.back();
if (!terminator.mightHaveTrait<OpTrait::IsTerminator>())
return block.back().emitError("block with no terminator, has ")
<< terminator;
@@ -245,6 +242,10 @@ LogicalResult OperationVerifier::verifyOperation(Operation &op) {
return success();
}
+//===----------------------------------------------------------------------===//
+// Dominance Checking
+//===----------------------------------------------------------------------===//
+
/// Emit an error when the specified operand of the specified operation is an
/// invalid use because of dominance properties.
static void diagnoseInvalidOperandDominance(Operation &op, unsigned operandNo) {
More information about the Mlir-commits
mailing list