diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 5b5ec841917e..c7194aca7ff1 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -3463,6 +3463,10 @@ void OperationPrinter::printResourceFileMetadata( std::optional charLimit = printerFlags.getLargeResourceStringLimit(); if (charLimit.has_value()) { + // Don't compute resourceStr when charLimit is 0. + if (charLimit.value() == 0) + return; + llvm::raw_string_ostream ss(resourceStr); valueFn(ss); diff --git a/mlir/test/IR/pretty-resources-print.mlir b/mlir/test/IR/pretty-resources-print.mlir index 297c83bbb138..980af80343d4 100644 --- a/mlir/test/IR/pretty-resources-print.mlir +++ b/mlir/test/IR/pretty-resources-print.mlir @@ -2,11 +2,16 @@ // RUN: mlir-opt %s --mlir-elide-resource-strings-if-larger=20| FileCheck %s +// RUN: mlir-opt %s --mlir-elide-resource-strings-if-larger=0| FileCheck %s --check-prefix=ZERO + + // To ensure we print the resource keys, have reference to them // CHECK: attr = dense_resource : tensor<3xi64> +// ZERO: attr = dense_resource : tensor<3xi64> "test.blob1op"() {attr = dense_resource : tensor<3xi64> } : () -> () // CHECK-NEXT: attr = dense_resource : tensor<3xi64> +// ZERO-NEXT: attr = dense_resource : tensor<3xi64> "test.blob2op"() {attr = dense_resource : tensor<3xi64> } : () -> () // CHECK: {-# @@ -21,6 +26,11 @@ // CHECK-NEXT: } // CHECK-NEXT: #-} +// Make sure no external_resources are printed when --mlir-elide-resource-strings-if-larger=0 +// ZERO: {-# +// ZERO-EMPTY: +// ZERO-NEXT: #-} + {-# dialect_resources: { builtin: {