2018-07-06 10:46:19 -07:00
|
|
|
//===- Verifier.cpp - MLIR Verifier Implementation ------------------------===//
|
|
|
|
//
|
|
|
|
// Copyright 2019 The MLIR Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
// =============================================================================
|
|
|
|
//
|
|
|
|
// This file implements the verify() methods on the various IR types, performing
|
|
|
|
// (potentially expensive) checks on the holistic structure of the code. This
|
|
|
|
// can be used for detecting bugs in compiler transformations and hand written
|
|
|
|
// .mlir files.
|
|
|
|
//
|
|
|
|
// The checks in this file are only for things that can occur as part of IR
|
|
|
|
// transformations: e.g. violation of dominance information, malformed operation
|
|
|
|
// attributes, etc. MLIR supports transformations moving IR through locally
|
2019-03-27 08:55:17 -07:00
|
|
|
// invalid states (e.g. unlinking an operation from a block before re-inserting
|
|
|
|
// it in a new place), but each transformation must complete with the IR in a
|
|
|
|
// valid form.
|
2018-07-06 10:46:19 -07:00
|
|
|
//
|
|
|
|
// This should not check for things that are always wrong by construction (e.g.
|
|
|
|
// affine maps or other immutable structures that are incorrect), because those
|
|
|
|
// are not mutable and can be checked at time of construction.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-09-21 14:40:36 -07:00
|
|
|
#include "mlir/Analysis/Dominance.h"
|
2018-08-21 08:42:19 -07:00
|
|
|
#include "mlir/IR/Attributes.h"
|
2019-03-02 22:34:18 -08:00
|
|
|
#include "mlir/IR/Dialect.h"
|
2018-12-27 11:07:34 -08:00
|
|
|
#include "mlir/IR/Function.h"
|
2018-07-06 10:46:19 -07:00
|
|
|
#include "mlir/IR/Module.h"
|
2019-03-26 14:45:38 -07:00
|
|
|
#include "mlir/IR/Operation.h"
|
2019-02-28 09:30:52 -08:00
|
|
|
#include "llvm/Support/FormatVariadic.h"
|
2018-08-05 21:12:29 -07:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2019-02-26 16:43:12 -08:00
|
|
|
#include "llvm/Support/Regex.h"
|
2018-07-06 10:46:19 -07:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace mlir;
|
|
|
|
|
2018-07-21 14:32:09 -07:00
|
|
|
namespace {
|
2018-12-29 09:11:58 -08:00
|
|
|
/// This class encapsulates all the state used to verify a function body. It is
|
|
|
|
/// a pervasive truth that this file treats "true" as an error that needs to be
|
|
|
|
/// recovered from, and "false" as success.
|
2018-07-21 14:32:09 -07:00
|
|
|
///
|
2018-12-29 09:11:58 -08:00
|
|
|
class FuncVerifier {
|
2018-07-21 14:32:09 -07:00
|
|
|
public:
|
2019-04-02 10:24:11 -07:00
|
|
|
LogicalResult failure() { return mlir::failure(); }
|
|
|
|
|
|
|
|
LogicalResult failure(const Twine &message, Operation &value) {
|
|
|
|
return value.emitError(message), failure();
|
2018-07-21 14:32:09 -07:00
|
|
|
}
|
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
LogicalResult failure(const Twine &message, Function &fn) {
|
|
|
|
return fn.emitError(message), failure();
|
2018-08-01 10:18:59 -07:00
|
|
|
}
|
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
LogicalResult failure(const Twine &message, Block &bb) {
|
2019-03-27 08:55:17 -07:00
|
|
|
// Take the location information for the first operation in the block.
|
2018-09-07 09:08:13 -07:00
|
|
|
if (!bb.empty())
|
2019-02-03 10:03:46 -08:00
|
|
|
return failure(message, bb.front());
|
2018-09-07 09:08:13 -07:00
|
|
|
|
|
|
|
// Worst case, fall back to using the function's location.
|
|
|
|
return failure(message, fn);
|
2018-09-06 20:56:12 -07:00
|
|
|
}
|
|
|
|
|
2019-03-02 22:34:18 -08:00
|
|
|
/// Returns the registered dialect for a dialect-specific attribute.
|
2019-03-31 23:30:22 -07:00
|
|
|
Dialect *getDialectForAttribute(const NamedAttribute &attr) {
|
2019-03-02 22:34:18 -08:00
|
|
|
assert(attr.first.strref().contains('.') && "expected dialect attribute");
|
|
|
|
auto dialectNamePair = attr.first.strref().split('.');
|
|
|
|
return fn.getContext()->getRegisteredDialect(dialectNamePair.first);
|
|
|
|
}
|
|
|
|
|
2019-02-26 16:43:12 -08:00
|
|
|
template <typename ErrorContext>
|
2019-04-02 10:24:11 -07:00
|
|
|
LogicalResult verifyAttribute(Attribute attr, ErrorContext &ctx) {
|
2019-02-26 16:43:12 -08:00
|
|
|
if (!attr.isOrContainsFunction())
|
2019-04-02 10:24:11 -07:00
|
|
|
return success();
|
2019-02-26 16:43:12 -08:00
|
|
|
|
|
|
|
// If we have a function attribute, check that it is non-null and in the
|
|
|
|
// same module as the operation that refers to it.
|
|
|
|
if (auto fnAttr = attr.dyn_cast<FunctionAttr>()) {
|
|
|
|
if (!fnAttr.getValue())
|
|
|
|
return failure("attribute refers to deallocated function!", ctx);
|
|
|
|
|
|
|
|
if (fnAttr.getValue()->getModule() != fn.getModule())
|
|
|
|
return failure("attribute refers to function '" +
|
|
|
|
Twine(fnAttr.getValue()->getName()) +
|
|
|
|
"' defined in another module!",
|
|
|
|
ctx);
|
2019-04-02 10:24:11 -07:00
|
|
|
return success();
|
2019-02-26 16:43:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we must have an array attribute, remap the elements.
|
2019-04-02 10:24:11 -07:00
|
|
|
for (auto elt : attr.cast<ArrayAttr>().getValue())
|
|
|
|
if (failed(verifyAttribute(elt, ctx)))
|
|
|
|
return failure();
|
2019-02-26 16:43:12 -08:00
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
return success();
|
2019-02-26 16:43:12 -08:00
|
|
|
}
|
2018-08-21 08:42:19 -07:00
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
LogicalResult verify();
|
|
|
|
LogicalResult verifyBlock(Block &block, bool isTopLevel);
|
|
|
|
LogicalResult verifyOperation(Operation &op);
|
|
|
|
LogicalResult verifyDominance(Block &block);
|
|
|
|
LogicalResult verifyOpDominance(Operation &op);
|
2018-12-29 09:11:58 -08:00
|
|
|
|
2019-03-21 11:39:22 -07:00
|
|
|
explicit FuncVerifier(Function &fn)
|
2019-03-02 22:34:18 -08:00
|
|
|
: fn(fn), identifierRegex("^[a-zA-Z_][a-zA-Z_0-9\\.\\$]*$") {}
|
2018-07-21 14:32:09 -07:00
|
|
|
|
|
|
|
private:
|
2018-08-21 08:42:19 -07:00
|
|
|
/// The function being checked.
|
2019-03-21 11:39:22 -07:00
|
|
|
Function &fn;
|
2018-12-29 09:11:58 -08:00
|
|
|
|
|
|
|
/// Dominance information for this function, when checking dominance.
|
|
|
|
DominanceInfo *domInfo = nullptr;
|
2019-02-26 16:43:12 -08:00
|
|
|
|
|
|
|
/// Regex checker for attribute names.
|
2019-03-02 22:34:18 -08:00
|
|
|
llvm::Regex identifierRegex;
|
2019-03-31 23:30:22 -07:00
|
|
|
|
|
|
|
/// Mapping between dialect namespace and if that dialect supports
|
|
|
|
/// unregistered operations.
|
|
|
|
llvm::StringMap<bool> dialectAllowsUnknownOps;
|
2018-07-21 14:32:09 -07:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
2018-07-06 10:46:19 -07:00
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
LogicalResult FuncVerifier::verify() {
|
2018-12-29 09:11:58 -08:00
|
|
|
llvm::PrettyStackTraceFormat fmt("MLIR Verifier: func @%s",
|
|
|
|
fn.getName().c_str());
|
|
|
|
|
2019-02-26 16:43:12 -08:00
|
|
|
// Check that the function name is valid.
|
2019-03-02 22:34:18 -08:00
|
|
|
if (!identifierRegex.match(fn.getName().strref()))
|
2019-02-26 16:43:12 -08:00
|
|
|
return failure("invalid function name '" + fn.getName().strref() + "'", fn);
|
|
|
|
|
|
|
|
/// Verify that all of the attributes are okay.
|
|
|
|
for (auto attr : fn.getAttrs()) {
|
2019-03-02 22:34:18 -08:00
|
|
|
if (!identifierRegex.match(attr.first))
|
2019-02-26 16:43:12 -08:00
|
|
|
return failure("invalid attribute name '" + attr.first.strref() + "'",
|
|
|
|
fn);
|
2019-04-02 10:24:11 -07:00
|
|
|
if (failed(verifyAttribute(attr.second, fn)))
|
|
|
|
return failure();
|
2019-03-02 22:34:18 -08:00
|
|
|
|
|
|
|
/// Check that the attribute is a dialect attribute, i.e. contains a '.' for
|
|
|
|
/// the namespace.
|
2019-03-05 14:42:55 -08:00
|
|
|
if (!attr.first.strref().contains('.'))
|
|
|
|
return failure("functions may only have dialect attributes", fn);
|
2019-03-02 22:34:18 -08:00
|
|
|
|
|
|
|
// Verify this attribute with the defining dialect.
|
2019-03-31 23:30:22 -07:00
|
|
|
if (auto *dialect = getDialectForAttribute(attr))
|
2019-03-05 10:05:53 -08:00
|
|
|
if (dialect->verifyFunctionAttribute(&fn, attr))
|
2019-04-02 10:24:11 -07:00
|
|
|
return failure();
|
2019-02-26 16:43:12 -08:00
|
|
|
}
|
|
|
|
|
2019-02-28 09:30:52 -08:00
|
|
|
/// Verify that all of the argument attributes are okay.
|
|
|
|
for (unsigned i = 0, e = fn.getNumArguments(); i != e; ++i) {
|
|
|
|
for (auto attr : fn.getArgAttrs(i)) {
|
2019-03-02 22:34:18 -08:00
|
|
|
if (!identifierRegex.match(attr.first))
|
2019-02-28 09:30:52 -08:00
|
|
|
return failure(
|
|
|
|
llvm::formatv("invalid attribute name '{0}' on argument {1}",
|
|
|
|
attr.first.strref(), i),
|
|
|
|
fn);
|
2019-04-02 10:24:11 -07:00
|
|
|
if (failed(verifyAttribute(attr.second, fn)))
|
|
|
|
return failure();
|
2019-03-02 22:34:18 -08:00
|
|
|
|
|
|
|
/// Check that the attribute is a dialect attribute, i.e. contains a '.'
|
|
|
|
/// for the namespace.
|
|
|
|
if (!attr.first.strref().contains('.'))
|
|
|
|
return failure("function arguments may only have dialect attributes",
|
|
|
|
fn);
|
|
|
|
|
|
|
|
// Verify this attribute with the defining dialect.
|
2019-03-31 23:30:22 -07:00
|
|
|
if (auto *dialect = getDialectForAttribute(attr))
|
2019-03-05 10:05:53 -08:00
|
|
|
if (dialect->verifyFunctionArgAttribute(&fn, i, attr))
|
2019-04-02 10:24:11 -07:00
|
|
|
return failure();
|
2019-02-28 09:30:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// External functions have nothing more to check.
|
|
|
|
if (fn.isExternal())
|
2019-04-02 10:24:11 -07:00
|
|
|
return success();
|
2019-02-28 09:30:52 -08:00
|
|
|
|
|
|
|
// Verify the first block has no predecessors.
|
|
|
|
auto *firstBB = &fn.front();
|
|
|
|
if (!firstBB->hasNoPredecessors())
|
|
|
|
return failure("entry block of function may not have predecessors", fn);
|
|
|
|
|
2018-12-29 09:11:58 -08:00
|
|
|
// Verify that the argument list of the function and the arg list of the first
|
|
|
|
// block line up.
|
|
|
|
auto fnInputTypes = fn.getType().getInputs();
|
|
|
|
if (fnInputTypes.size() != firstBB->getNumArguments())
|
|
|
|
return failure("first block of function must have " +
|
|
|
|
Twine(fnInputTypes.size()) +
|
|
|
|
" arguments to match function signature",
|
|
|
|
fn);
|
|
|
|
for (unsigned i = 0, e = firstBB->getNumArguments(); i != e; ++i)
|
|
|
|
if (fnInputTypes[i] != firstBB->getArgument(i)->getType())
|
|
|
|
return failure(
|
|
|
|
"type of argument #" + Twine(i) +
|
|
|
|
" must match corresponding argument in function signature",
|
|
|
|
fn);
|
|
|
|
|
2019-03-08 14:26:23 -08:00
|
|
|
for (auto &block : fn)
|
2019-04-02 10:24:11 -07:00
|
|
|
if (failed(verifyBlock(block, /*isTopLevel=*/true)))
|
|
|
|
return failure();
|
2018-12-29 09:11:58 -08:00
|
|
|
|
|
|
|
// Since everything looks structurally ok to this point, we do a dominance
|
|
|
|
// check. 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.
|
2019-03-24 23:26:39 -07:00
|
|
|
DominanceInfo theDomInfo(&fn);
|
2018-12-29 09:11:58 -08:00
|
|
|
domInfo = &theDomInfo;
|
2019-03-08 14:26:23 -08:00
|
|
|
for (auto &block : fn)
|
2019-04-02 10:24:11 -07:00
|
|
|
if (failed(verifyDominance(block)))
|
|
|
|
return failure();
|
2018-12-29 09:11:58 -08:00
|
|
|
|
|
|
|
domInfo = nullptr;
|
2019-04-02 10:24:11 -07:00
|
|
|
return success();
|
2018-12-29 09:11:58 -08:00
|
|
|
}
|
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
LogicalResult FuncVerifier::verifyBlock(Block &block, bool isTopLevel) {
|
2018-12-29 09:11:58 -08:00
|
|
|
for (auto *arg : block.getArguments()) {
|
|
|
|
if (arg->getOwner() != &block)
|
|
|
|
return failure("block argument not owned by block", block);
|
|
|
|
}
|
|
|
|
|
2019-02-08 09:52:26 -08:00
|
|
|
// Verify that this block has a terminator.
|
|
|
|
if (block.empty()) {
|
|
|
|
return failure("block with no terminator", block);
|
|
|
|
}
|
|
|
|
|
2019-03-27 08:55:17 -07:00
|
|
|
// Verify the non-terminator operations separately so that we can verify
|
2019-02-08 09:52:26 -08:00
|
|
|
// they has no successors.
|
2019-03-27 08:55:17 -07:00
|
|
|
for (auto &op : llvm::make_range(block.begin(), std::prev(block.end()))) {
|
|
|
|
if (op.getNumSuccessors() != 0)
|
2019-02-08 09:52:26 -08:00
|
|
|
return failure(
|
2019-03-27 08:55:17 -07:00
|
|
|
"operation with block successors must terminate its parent block",
|
|
|
|
op);
|
2019-02-08 09:52:26 -08:00
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
if (failed(verifyOperation(op)))
|
|
|
|
return failure();
|
2019-01-25 12:48:25 -08:00
|
|
|
}
|
|
|
|
|
2019-02-08 09:52:26 -08:00
|
|
|
// Verify the terminator.
|
2019-04-02 10:24:11 -07:00
|
|
|
if (failed(verifyOperation(block.back())))
|
|
|
|
return failure();
|
2019-03-27 05:11:58 -07:00
|
|
|
if (block.back().isKnownNonTerminator())
|
2019-02-08 09:52:26 -08:00
|
|
|
return failure("block with no terminator", block);
|
|
|
|
|
|
|
|
// Verify that this block is not branching to a block of a different
|
|
|
|
// region.
|
2019-03-21 17:53:00 -07:00
|
|
|
for (Block *successor : block.getSuccessors())
|
2019-02-08 09:52:26 -08:00
|
|
|
if (successor->getParent() != block.getParent())
|
|
|
|
return failure("branching to block of a different region", block.back());
|
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
return success();
|
2018-12-29 09:11:58 -08:00
|
|
|
}
|
|
|
|
|
2018-12-27 21:21:41 -08:00
|
|
|
/// Check the invariants of the specified operation.
|
2019-04-02 10:24:11 -07:00
|
|
|
LogicalResult FuncVerifier::verifyOperation(Operation &op) {
|
2018-12-27 21:21:41 -08:00
|
|
|
if (op.getFunction() != &fn)
|
2018-09-06 20:56:12 -07:00
|
|
|
return failure("operation in the wrong function", op);
|
2018-08-21 08:42:19 -07:00
|
|
|
|
2018-09-05 17:45:19 -07:00
|
|
|
// Check that operands are non-nil and structurally ok.
|
2019-03-23 15:09:06 -07:00
|
|
|
for (auto *operand : op.getOperands()) {
|
2018-09-05 17:45:19 -07:00
|
|
|
if (!operand)
|
2018-09-06 20:56:12 -07:00
|
|
|
return failure("null operand found", op);
|
2018-09-05 17:45:19 -07:00
|
|
|
|
|
|
|
if (operand->getFunction() != &fn)
|
2018-09-06 20:56:12 -07:00
|
|
|
return failure("reference to operand defined in another function", op);
|
2018-09-05 17:45:19 -07:00
|
|
|
}
|
2018-08-21 08:42:19 -07:00
|
|
|
|
2019-02-26 16:43:12 -08:00
|
|
|
/// Verify that all of the attributes are okay.
|
2018-08-21 08:42:19 -07:00
|
|
|
for (auto attr : op.getAttrs()) {
|
2019-03-02 22:34:18 -08:00
|
|
|
if (!identifierRegex.match(attr.first))
|
2019-02-26 16:43:12 -08:00
|
|
|
return failure("invalid attribute name '" + attr.first.strref() + "'",
|
|
|
|
op);
|
2019-04-02 10:24:11 -07:00
|
|
|
if (failed(verifyAttribute(attr.second, op)))
|
|
|
|
return failure();
|
2019-03-02 22:34:18 -08:00
|
|
|
|
|
|
|
// Check for any optional dialect specific attributes.
|
|
|
|
if (!attr.first.strref().contains('.'))
|
|
|
|
continue;
|
2019-03-31 23:30:22 -07:00
|
|
|
if (auto *dialect = getDialectForAttribute(attr))
|
2019-03-26 17:05:09 -07:00
|
|
|
if (dialect->verifyOperationAttribute(&op, attr))
|
2019-04-02 10:24:11 -07:00
|
|
|
return failure();
|
2018-08-21 08:42:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we can get operation info for this, check the custom hook.
|
2019-03-31 23:30:22 -07:00
|
|
|
auto *opInfo = op.getAbstractOperation();
|
|
|
|
if (opInfo && opInfo->verifyInvariants(&op))
|
2019-04-02 10:24:11 -07:00
|
|
|
return failure();
|
2018-08-21 08:42:19 -07:00
|
|
|
|
2019-01-25 12:48:25 -08:00
|
|
|
// Verify that all child blocks are ok.
|
2019-03-14 10:38:44 -07:00
|
|
|
for (auto ®ion : op.getRegions())
|
|
|
|
for (auto &b : region)
|
2019-04-02 10:24:11 -07:00
|
|
|
if (failed(verifyBlock(b, /*isTopLevel=*/false)))
|
|
|
|
return failure();
|
2019-01-25 12:48:25 -08:00
|
|
|
|
2019-03-31 23:30:22 -07:00
|
|
|
// If this is a registered operation, there is nothing left to do.
|
|
|
|
if (opInfo)
|
2019-04-02 10:24:11 -07:00
|
|
|
return success();
|
2019-03-31 23:30:22 -07:00
|
|
|
|
|
|
|
// Otherwise, verify that the parent dialect allows un-registered operations.
|
|
|
|
auto opName = op.getName().getStringRef();
|
|
|
|
auto dialectPrefix = opName.split('.').first;
|
|
|
|
|
|
|
|
// Check for an existing answer for the operation dialect.
|
|
|
|
auto it = dialectAllowsUnknownOps.find(dialectPrefix);
|
|
|
|
if (it == dialectAllowsUnknownOps.end()) {
|
|
|
|
// If the operation dialect is registered, query it directly.
|
|
|
|
if (auto *dialect = fn.getContext()->getRegisteredDialect(dialectPrefix))
|
|
|
|
it = dialectAllowsUnknownOps
|
|
|
|
.try_emplace(dialectPrefix, dialect->allowsUnknownOperations())
|
|
|
|
.first;
|
|
|
|
// Otherwise, conservatively allow unknown operations.
|
|
|
|
else
|
|
|
|
it = dialectAllowsUnknownOps.try_emplace(dialectPrefix, true).first;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!it->second) {
|
|
|
|
return failure("unregistered operation '" + opName +
|
|
|
|
"' found in dialect ('" + dialectPrefix +
|
|
|
|
"') that does not allow unknown operations",
|
|
|
|
op);
|
|
|
|
}
|
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
return success();
|
2018-08-21 08:42:19 -07:00
|
|
|
}
|
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
LogicalResult FuncVerifier::verifyDominance(Block &block) {
|
2019-03-27 08:55:17 -07:00
|
|
|
// Verify the dominance of each of the held operations.
|
|
|
|
for (auto &op : block)
|
2019-04-02 10:24:11 -07:00
|
|
|
if (failed(verifyOpDominance(op)))
|
|
|
|
return failure();
|
|
|
|
return success();
|
2018-07-06 10:46:19 -07:00
|
|
|
}
|
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
LogicalResult FuncVerifier::verifyOpDominance(Operation &op) {
|
2018-09-21 14:40:36 -07:00
|
|
|
// Check that operands properly dominate this use.
|
2019-03-27 08:55:17 -07:00
|
|
|
for (unsigned operandNo = 0, e = op.getNumOperands(); operandNo != e;
|
2018-09-21 14:40:36 -07:00
|
|
|
++operandNo) {
|
2019-03-27 08:55:17 -07:00
|
|
|
auto *operand = op.getOperand(operandNo);
|
|
|
|
if (domInfo->properlyDominates(operand, &op))
|
2018-09-21 14:40:36 -07:00
|
|
|
continue;
|
|
|
|
|
2019-03-27 08:55:17 -07:00
|
|
|
op.emitError("operand #" + Twine(operandNo) +
|
|
|
|
" does not dominate this use");
|
|
|
|
if (auto *useOp = operand->getDefiningOp())
|
|
|
|
useOp->emitNote("operand defined here");
|
2019-04-02 10:24:11 -07:00
|
|
|
return failure();
|
2018-09-21 14:40:36 -07:00
|
|
|
}
|
|
|
|
|
2019-03-27 08:55:17 -07:00
|
|
|
// Verify the dominance of each of the nested blocks within this operation.
|
|
|
|
for (auto ®ion : op.getRegions())
|
2019-03-14 10:38:44 -07:00
|
|
|
for (auto &block : region)
|
2019-04-02 10:24:11 -07:00
|
|
|
if (failed(verifyDominance(block)))
|
|
|
|
return failure();
|
2019-03-08 14:26:23 -08:00
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
return success();
|
2018-09-21 14:40:36 -07:00
|
|
|
}
|
|
|
|
|
2018-07-06 10:46:19 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Entrypoints
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Perform (potentially expensive) checks of invariants, used to detect
|
2018-09-07 09:08:13 -07:00
|
|
|
/// compiler bugs. On error, this reports the error through the MLIRContext and
|
2019-04-02 10:24:11 -07:00
|
|
|
/// returns failure.
|
|
|
|
LogicalResult Function::verify() { return FuncVerifier(*this).verify(); }
|
2018-07-06 10:46:19 -07:00
|
|
|
|
|
|
|
/// Perform (potentially expensive) checks of invariants, used to detect
|
2018-09-07 09:08:13 -07:00
|
|
|
/// compiler bugs. On error, this reports the error through the MLIRContext and
|
2019-04-02 10:24:11 -07:00
|
|
|
/// returns failure.
|
|
|
|
LogicalResult Module::verify() {
|
2018-07-06 10:46:19 -07:00
|
|
|
/// Check that each function is correct.
|
2019-04-02 10:24:11 -07:00
|
|
|
for (auto &fn : *this)
|
|
|
|
if (failed(fn.verify()))
|
|
|
|
return failure();
|
2018-07-21 14:32:09 -07:00
|
|
|
|
2019-04-02 10:24:11 -07:00
|
|
|
return success();
|
2018-07-06 10:46:19 -07:00
|
|
|
}
|