MLIR 23.0.0git
VerificationUtils.cpp
Go to the documentation of this file.
1//===- VerificationUtils.cpp - Common verification utilities --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11using namespace mlir;
12
13LogicalResult mlir::verifyDynamicDimensionCount(Operation *op, ShapedType type,
14 ValueRange dynamicSizes) {
15 int64_t expectedCount = type.getNumDynamicDims();
16 int64_t actualCount = dynamicSizes.size();
17 if (expectedCount != actualCount) {
18 return op->emitOpError("incorrect number of dynamic sizes, has ")
19 << actualCount << ", expected " << expectedCount;
20 }
21 return success();
22}
23
24LogicalResult mlir::verifyRanksMatch(Operation *op, ShapedType lhs,
25 ShapedType rhs, StringRef lhsName,
26 StringRef rhsName) {
27 if (!lhs.hasRank() || !rhs.hasRank())
28 return success(); // Unranked types are considered compatible
29
30 int64_t rank1 = lhs.getRank();
31 int64_t rank2 = rhs.getRank();
32 if (rank1 != rank2) {
33 return op->emitOpError()
34 << lhsName << " rank (" << rank1 << ") does not match " << rhsName
35 << " rank (" << rank2 << ")";
36 }
37 return success();
38}
39
40LogicalResult mlir::verifyElementTypesMatch(Operation *op, ShapedType lhs,
41 ShapedType rhs, StringRef lhsName,
42 StringRef rhsName) {
43 Type lhsElementType = lhs.getElementType();
44 Type rhsElementType = rhs.getElementType();
45 if (lhsElementType != rhsElementType) {
46 return op->emitOpError() << lhsName << " element type (" << lhsElementType
47 << ") does not match " << rhsName
48 << " element type (" << rhsElementType << ")";
49 }
50 return success();
51}
return success()
lhs
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:387
Include the generated interface declarations.
LogicalResult verifyDynamicDimensionCount(Operation *op, ShapedType type, ValueRange dynamicSizes)
Verify that the number of dynamic size operands matches the number of dynamic dimensions in the shape...
LogicalResult verifyRanksMatch(Operation *op, ShapedType lhs, ShapedType rhs, StringRef lhsName, StringRef rhsName)
Verify that two shaped types have matching ranks.
LogicalResult verifyElementTypesMatch(Operation *op, ShapedType lhs, ShapedType rhs, StringRef lhsName, StringRef rhsName)
Verify that two shaped types have matching element types.