[PATCH] D73645: Add IntegerAttr::verifyConstructionInvariants.
Sean Silva via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 12:26:29 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9accbd58fb3f: Add IntegerAttr::verifyConstructionInvariants. (authored by silvas).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73645/new/
https://reviews.llvm.org/D73645
Files:
mlir/include/mlir/IR/Attributes.h
mlir/lib/IR/Attributes.cpp
Index: mlir/lib/IR/Attributes.cpp
===================================================================
--- mlir/lib/IR/Attributes.cpp
+++ mlir/lib/IR/Attributes.cpp
@@ -281,6 +281,33 @@
int64_t IntegerAttr::getInt() const { return getValue().getSExtValue(); }
+static LogicalResult verifyIntegerTypeInvariants(Optional<Location> loc,
+ Type type) {
+ if (type.isa<IntegerType>() || type.isa<IndexType>())
+ return success();
+ return emitOptionalError(loc, "expected integer or index type");
+}
+
+LogicalResult verifyConstructionInvariants(Optional<Location> loc,
+ MLIRContext *ctx, Type type,
+ int64_t value) {
+ return verifyIntegerTypeInvariants(loc, type);
+}
+
+LogicalResult IntegerAttr::verifyConstructionInvariants(Optional<Location> loc,
+ MLIRContext *ctx,
+ Type type,
+ const APInt &value) {
+ if (failed(verifyIntegerTypeInvariants(loc, type)))
+ return failure();
+ if (auto integerType = type.dyn_cast<IntegerType>())
+ if (integerType.getWidth() != value.getBitWidth())
+ return emitOptionalError(
+ loc, "integer type bit width (", integerType.getWidth(),
+ ") doesn't match value bit width (", value.getBitWidth(), ")");
+ return success();
+}
+
//===----------------------------------------------------------------------===//
// IntegerSetAttr
//===----------------------------------------------------------------------===//
Index: mlir/include/mlir/IR/Attributes.h
===================================================================
--- mlir/include/mlir/IR/Attributes.h
+++ mlir/include/mlir/IR/Attributes.h
@@ -359,6 +359,13 @@
static bool kindof(unsigned kind) {
return kind == StandardAttributes::Integer;
}
+
+ static LogicalResult verifyConstructionInvariants(Optional<Location> loc,
+ MLIRContext *ctx, Type type,
+ int64_t value);
+ static LogicalResult verifyConstructionInvariants(Optional<Location> loc,
+ MLIRContext *ctx, Type type,
+ const APInt &value);
};
//===----------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73645.241253.patch
Type: text/x-patch
Size: 2539 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200129/b80e6d29/attachment.bin>
More information about the llvm-commits
mailing list