Update the dialect attribute verification hooks to return LogicalResult instead...
authorRiver Riddle <riverriddle@google.com>
Tue, 2 Apr 2019 21:02:32 +0000 (14:02 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Tue, 2 Apr 2019 22:15:56 +0000 (15:15 -0700)
--

PiperOrigin-RevId: 241598892

mlir/include/mlir/IR/Dialect.h
mlir/include/mlir/IR/Function.h
mlir/include/mlir/LLVMIR/LLVMDialect.h
mlir/lib/Analysis/Verifier.cpp
mlir/lib/IR/Function.cpp
mlir/lib/LLVMIR/IR/LLVMDialect.cpp

index 386499e..f562bb8 100644 (file)
@@ -105,24 +105,24 @@ public:
   virtual void
   getTypeAliases(SmallVectorImpl<std::pair<StringRef, Type>> &aliases) {}
 
-  /// Verify an attribute from this dialect on the given function. Returns true
-  /// if the verification failed, false otherwise.
-  virtual bool verifyFunctionAttribute(Function *, NamedAttribute) {
-    return false;
+  /// Verify an attribute from this dialect on the given function. Returns
+  /// failure if the verification failed, success otherwise.
+  virtual LogicalResult verifyFunctionAttribute(Function *, NamedAttribute) {
+    return success();
   }
 
   /// Verify an attribute from this dialect on the argument at 'argIndex' for
-  /// the given function. Returns true if the verification failed, false
+  /// the given function. Returns failure if the verification failed, success
   /// otherwise.
-  virtual bool verifyFunctionArgAttribute(Function *, unsigned argIndex,
-                                          NamedAttribute) {
-    return false;
+  virtual LogicalResult
+  verifyFunctionArgAttribute(Function *, unsigned argIndex, NamedAttribute) {
+    return success();
   }
 
   /// Verify an attribute from this dialect on the given operation. Returns
-  /// true if the verification failed, false otherwise.
-  virtual bool verifyOperationAttribute(Operation *, NamedAttribute) {
-    return false;
+  /// failure if the verification failed, success otherwise.
+  virtual LogicalResult verifyOperationAttribute(Operation *, NamedAttribute) {
+    return success();
   }
 
   virtual ~Dialect();
index c680eef..6fbdd2f 100644 (file)
@@ -264,9 +264,9 @@ public:
 
   /// Emit an error about fatal conditions with this operation, reporting up to
   /// any diagnostic handlers that may be listening.  This function always
-  /// returns true.  NOTE: This may terminate the containing application, only
-  /// use when the IR is in an inconsistent state.
-  bool emitError(const Twine &message);
+  /// returns failure.  NOTE: This may terminate the containing application,
+  /// only use when the IR is in an inconsistent state.
+  LogicalResult emitError(const Twine &message);
 
   /// Emit a warning about this operation, reporting up to any diagnostic
   /// handlers that may be listening.
index 61948ec..6c4ac49 100644 (file)
@@ -79,9 +79,9 @@ public:
   void printType(Type type, raw_ostream &os) const override;
 
   /// Verify a function argument attribute registered to this dialect.
-  /// Returns true if the verification failed, false otherwise.
-  bool verifyFunctionArgAttribute(Function *func, unsigned argIdx,
-                                  NamedAttribute argAttr) override;
+  /// Returns failure if the verification failed, success otherwise.
+  LogicalResult verifyFunctionArgAttribute(Function *func, unsigned argIdx,
+                                           NamedAttribute argAttr) override;
 
 private:
   llvm::LLVMContext llvmContext;
index 7439c25..ee4fd73 100644 (file)
@@ -55,11 +55,11 @@ public:
   LogicalResult failure() { return mlir::failure(); }
 
   LogicalResult failure(const Twine &message, Operation &value) {
-    return value.emitError(message), failure();
+    return value.emitError(message);
   }
 
   LogicalResult failure(const Twine &message, Function &fn) {
-    return fn.emitError(message), failure();
+    return fn.emitError(message);
   }
 
   LogicalResult failure(const Twine &message, Block &bb) {
@@ -153,7 +153,7 @@ LogicalResult FuncVerifier::verify() {
 
     // Verify this attribute with the defining dialect.
     if (auto *dialect = getDialectForAttribute(attr))
-      if (dialect->verifyFunctionAttribute(&fn, attr))
+      if (failed(dialect->verifyFunctionAttribute(&fn, attr)))
         return failure();
   }
 
@@ -176,7 +176,7 @@ LogicalResult FuncVerifier::verify() {
 
       // Verify this attribute with the defining dialect.
       if (auto *dialect = getDialectForAttribute(attr))
-        if (dialect->verifyFunctionArgAttribute(&fn, i, attr))
+        if (failed(dialect->verifyFunctionArgAttribute(&fn, i, attr)))
           return failure();
     }
   }
@@ -287,7 +287,7 @@ LogicalResult FuncVerifier::verifyOperation(Operation &op) {
     if (!attr.first.strref().contains('.'))
       continue;
     if (auto *dialect = getDialectForAttribute(attr))
-      if (dialect->verifyOperationAttribute(&op, attr))
+      if (failed(dialect->verifyOperationAttribute(&op, attr)))
         return failure();
   }
 
index d8cc4ed..a723686 100644 (file)
@@ -131,10 +131,10 @@ void Function::emitWarning(const Twine &message) {
 
 /// Emit an error about fatal conditions with this operation, reporting up to
 /// any diagnostic handlers that may be listening.  This function always
-/// returns true.  NOTE: This may terminate the containing application, only use
-/// when the IR is in an inconsistent state.
-bool Function::emitError(const Twine &message) {
-  return getContext()->emitError(getLoc(), message);
+/// returns failure.  NOTE: This may terminate the containing application, only
+/// use when the IR is in an inconsistent state.
+LogicalResult Function::emitError(const Twine &message) {
+  return getContext()->emitError(getLoc(), message), failure();
 }
 
 /// Clone the internal blocks from this function into dest and all attributes
index d9a7be0..8f5209a 100644 (file)
@@ -95,13 +95,14 @@ void LLVMDialect::printType(Type type, raw_ostream &os) const {
 }
 
 /// Verify LLVMIR function argument attributes.
-bool LLVMDialect::verifyFunctionArgAttribute(Function *func, unsigned argIdx,
-                                             NamedAttribute argAttr) {
+LogicalResult LLVMDialect::verifyFunctionArgAttribute(Function *func,
+                                                      unsigned argIdx,
+                                                      NamedAttribute argAttr) {
   // Check that llvm.noalias is a boolean attribute.
   if (argAttr.first == "llvm.noalias" && !argAttr.second.isa<BoolAttr>())
     return func->emitError(
         "llvm.noalias argument attribute of non boolean type");
-  return false;
+  return success();
 }
 
 static DialectRegistration<LLVMDialect> llvmDialect;