Skip to content

Commit 75596ac

Browse files
python3kgaeIanWood1
authored andcommitted
[NFC][mlir][AsmPrinter] Don't compute resourceStr when --mlir-elide-resource-strings-if-larger=0 (llvm#138275)
When skipping the printing of large DenseResourceElementsAttr with --mlir-elide-resource-strings-if-larger, we need to compute resourceStr to check if the string is small enough to print. With --mlir-elide-resource-strings-if-larger set to 0, nothing should be printed, but we still compute the size. This change will allow an early return when --mlir-elide-resource-strings-if-larger=0, making the print process faster.
1 parent 6607b2f commit 75596ac

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

mlir/lib/IR/AsmPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,6 +3463,10 @@ void OperationPrinter::printResourceFileMetadata(
34633463
std::optional<uint64_t> charLimit =
34643464
printerFlags.getLargeResourceStringLimit();
34653465
if (charLimit.has_value()) {
3466+
// Don't compute resourceStr when charLimit is 0.
3467+
if (charLimit.value() == 0)
3468+
return;
3469+
34663470
llvm::raw_string_ostream ss(resourceStr);
34673471
valueFn(ss);
34683472

mlir/test/IR/pretty-resources-print.mlir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
// RUN: mlir-opt %s --mlir-elide-resource-strings-if-larger=20| FileCheck %s
44

5+
// RUN: mlir-opt %s --mlir-elide-resource-strings-if-larger=0| FileCheck %s --check-prefix=ZERO
6+
7+
58
// To ensure we print the resource keys, have reference to them
69
// CHECK: attr = dense_resource<blob1> : tensor<3xi64>
10+
// ZERO: attr = dense_resource<blob1> : tensor<3xi64>
711
"test.blob1op"() {attr = dense_resource<blob1> : tensor<3xi64> } : () -> ()
812

913
// CHECK-NEXT: attr = dense_resource<blob2> : tensor<3xi64>
14+
// ZERO-NEXT: attr = dense_resource<blob2> : tensor<3xi64>
1015
"test.blob2op"() {attr = dense_resource<blob2> : tensor<3xi64> } : () -> ()
1116

1217
// CHECK: {-#
@@ -21,6 +26,11 @@
2126
// CHECK-NEXT: }
2227
// CHECK-NEXT: #-}
2328

29+
// Make sure no external_resources are printed when --mlir-elide-resource-strings-if-larger=0
30+
// ZERO: {-#
31+
// ZERO-EMPTY:
32+
// ZERO-NEXT: #-}
33+
2434
{-#
2535
dialect_resources: {
2636
builtin: {

0 commit comments

Comments
 (0)