[PATCH] D73645: Add IntegerAttr::verifyConstructionInvariants.

Sean Silva via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 11:03:34 PST 2020


silvas updated this revision to Diff 241225.
silvas added a comment.

Fix review feeback.


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.241225.patch
Type: text/x-patch
Size: 2539 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200129/a24deffc/attachment.bin>


More information about the llvm-commits mailing list