diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp index 8e351cb22eb94..47a85c2a486fd 100644 --- a/mlir/lib/Bindings/Python/IRCore.cpp +++ b/mlir/lib/Bindings/Python/IRCore.cpp @@ -1296,8 +1296,10 @@ void PyOperationBase::print(std::optional largeElementsLimit, fileObject = nb::module_::import_("sys").attr("stdout"); MlirOpPrintingFlags flags = mlirOpPrintingFlagsCreate(); - if (largeElementsLimit) + if (largeElementsLimit) { mlirOpPrintingFlagsElideLargeElementsAttrs(flags, *largeElementsLimit); + mlirOpPrintingFlagsElideLargeResourceString(flags, *largeElementsLimit); + } if (enableDebugInfo) mlirOpPrintingFlagsEnableDebugInfo(flags, /*enable=*/true, /*prettyForm=*/prettyDebugInfo); diff --git a/mlir/test/python/ir/operation.py b/mlir/test/python/ir/operation.py index d5d72c98b66ad..c2d3aed8808b4 100644 --- a/mlir/test/python/ir/operation.py +++ b/mlir/test/python/ir/operation.py @@ -583,14 +583,24 @@ def testOperationPrint(): r""" func.func @f1(%arg0: i32) -> i32 { %0 = arith.constant dense<[1, 2, 3, 4]> : tensor<4xi32> loc("nom") + %1 = arith.constant dense_resource : tensor<3xi64> return %arg0 : i32 } + + {-# + dialect_resources: { + builtin: { + resource1: "0x08000000010000000000000002000000000000000300000000000000" + } + } + #-} """, ctx, ) # Test print to stdout. # CHECK: return %arg0 : i32 + # CHECK: resource1: "0x08 module.operation.print() # Test print to text file. @@ -607,7 +617,8 @@ def testOperationPrint(): module.operation.write_bytecode(bytecode_stream, desired_version=1) bytecode = bytecode_stream.getvalue() assert bytecode.startswith(b"ML\xefR"), "Expected bytecode to start with MLïR" - module_roundtrip = Module.parse(bytecode, ctx) + ctx2 = Context() + module_roundtrip = Module.parse(bytecode, ctx2) f = io.StringIO() module_roundtrip.operation.print(file=f) roundtrip_value = f.getvalue() @@ -633,7 +644,8 @@ def testOperationPrint(): # Test print with options. # CHECK: value = dense_resource<__elided__> : tensor<4xi32> - # CHECK: "func.return"(%arg0) : (i32) -> () -:4:7 + # CHECK: "func.return"(%arg0) : (i32) -> () -:5:7 + # CHECK-NOT: resource1: "0x08 module.operation.print( large_elements_limit=2, enable_debug_info=True,