[Mlir-commits] [mlir] f5665a2 - [mlir][python] Add Operation.verify().
Stella Laurenzo
llvmlistbot at llvm.org
Tue Dec 29 14:12:30 PST 2020
Author: Stella Laurenzo
Date: 2020-12-29T14:10:31-08:00
New Revision: f5665a24862163e8783ccf3fd2d2cab62d539e93
URL: https://github.com/llvm/llvm-project/commit/f5665a24862163e8783ccf3fd2d2cab62d539e93
DIFF: https://github.com/llvm/llvm-project/commit/f5665a24862163e8783ccf3fd2d2cab62d539e93.diff
LOG: [mlir][python] Add Operation.verify().
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D93913
Added:
Modified:
mlir/lib/Bindings/Python/IRModules.cpp
mlir/test/Bindings/Python/ir_operation.py
Removed:
################################################################################
diff --git a/mlir/lib/Bindings/Python/IRModules.cpp b/mlir/lib/Bindings/Python/IRModules.cpp
index 86d6f8206155..cd58f291d2ec 100644
--- a/mlir/lib/Bindings/Python/IRModules.cpp
+++ b/mlir/lib/Bindings/Python/IRModules.cpp
@@ -3025,7 +3025,14 @@ void mlir::python::populateIRSubmodule(py::module &m) {
py::arg("enable_debug_info") = false,
py::arg("pretty_debug_info") = false,
py::arg("print_generic_op_form") = false,
- py::arg("use_local_scope") = false, kOperationGetAsmDocstring);
+ py::arg("use_local_scope") = false, kOperationGetAsmDocstring)
+ .def(
+ "verify",
+ [](PyOperationBase &self) {
+ return mlirOperationVerify(self.getOperation());
+ },
+ "Verify the operation and return true if it passes, false if it "
+ "fails.");
py::class_<PyOperation, PyOperationBase>(m, "Operation")
.def_static("create", &PyOperation::create, py::arg("name"),
diff --git a/mlir/test/Bindings/Python/ir_operation.py b/mlir/test/Bindings/Python/ir_operation.py
index 1f6df8626a0a..1aa365a1f35d 100644
--- a/mlir/test/Bindings/Python/ir_operation.py
+++ b/mlir/test/Bindings/Python/ir_operation.py
@@ -31,6 +31,10 @@ def testTraverseOpRegionBlockIterators():
# CHECK: MODULE REGIONS=1 BLOCKS=1
print(f"MODULE REGIONS={len(regions)} BLOCKS={len(blocks)}")
+ # Should verify.
+ # CHECK: .verify = True
+ print(f".verify = {module.operation.verify()}")
+
# Get the regions and blocks from the default collections.
default_regions = list(op)
default_blocks = list(default_regions[0])
@@ -546,10 +550,12 @@ def testPrintInvalidOperation():
# This block does not have a terminator, it may crash the custom printer.
# Verify that we fallback to the generic printer for safety.
block = module.regions[0].blocks.append()
- print(module)
# CHECK: // Verification failed, printing generic form
# CHECK: "module"() ( {
# CHECK: }) : () -> ()
+ print(module)
+ # CHECK: .verify = False
+ print(f".verify = {module.operation.verify()}")
run(testPrintInvalidOperation)
More information about the Mlir-commits
mailing list