diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp index 37ca3b953067a..98566ddea2f3f 100644 --- a/mlir/lib/Bindings/Python/IRCore.cpp +++ b/mlir/lib/Bindings/Python/IRCore.cpp @@ -1002,6 +1002,8 @@ void PyOperationBase::print(py::object fileObject, bool binary, mlirOpPrintingFlagsEnableDebugInfo(flags, /*prettyForm=*/prettyDebugInfo); if (printGenericOpForm) mlirOpPrintingFlagsPrintGenericOpForm(flags); + if (useLocalScope) + mlirOpPrintingFlagsUseLocalScope(flags); PyFileAccumulator accum(fileObject, binary); mlirOperationPrintWithFlags(operation, flags, accum.getCallback(), diff --git a/mlir/test/python/ir/operation.py b/mlir/test/python/ir/operation.py index 489723a6d13d4..b7b47f8bf07c8 100644 --- a/mlir/test/python/ir/operation.py +++ b/mlir/test/python/ir/operation.py @@ -535,7 +535,7 @@ def testOperationPrint(): module = Module.parse( r""" func.func @f1(%arg0: i32) -> i32 { - %0 = arith.constant dense<[1, 2, 3, 4]> : tensor<4xi32> + %0 = arith.constant dense<[1, 2, 3, 4]> : tensor<4xi32> loc("nom") return %arg0 : i32 } """, ctx) @@ -562,6 +562,10 @@ def testOperationPrint(): print(bytes_value.__class__) print(bytes_value) + # Test get_asm local_scope. + # CHECK: constant dense<[1, 2, 3, 4]> : tensor<4xi32> loc("nom") + module.operation.print(enable_debug_info=True, use_local_scope=True) + # Test get_asm with options. # CHECK: value = opaque<"elided_large_const", "0xDEADBEEF"> : tensor<4xi32> # CHECK: "func.return"(%arg0) : (i32) -> () -:4:7