diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -1160,6 +1160,9 @@ /// Return if the printer should print users of values. bool shouldPrintValueUsers() const; + /// Return if the printer should print the value of resources. + bool shouldPrintResourceValues() const; + private: /// Elide large elements attributes if the number of elements is larger than /// the upper limit. @@ -1183,6 +1186,9 @@ /// Print users of values. bool printValueUsersFlag : 1; + + /// Whether to print the value of resources. + bool disablePrintResourceValuesFlag : 1; }; //===----------------------------------------------------------------------===// diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -168,6 +168,11 @@ "mlir-print-value-users", llvm::cl::init(false), llvm::cl::desc( "Print users of operation results and block arguments as a comment")}; + + llvm::cl::opt disablePrintingResourceValues{ + "mlir-disable-printing-resource-values", llvm::cl::init(false), + llvm::cl::desc( + "Whether to elide the printing of the value of resources")}; }; } // namespace @@ -197,6 +202,7 @@ assumeVerifiedFlag = clOptions->assumeVerifiedOpt; printLocalScope = clOptions->printLocalScopeOpt; printValueUsersFlag = clOptions->printValueUsers; + disablePrintResourceValuesFlag = clOptions->disablePrintingResourceValues; } /// Enable the elision of large elements attributes, by printing a '...' @@ -293,6 +299,11 @@ return printValueUsersFlag; } +/// Return if the printer should print the value of resources. +bool OpPrintingFlags::shouldPrintResourceValues() const { + return !disablePrintResourceValuesFlag; +} + /// Returns true if an ElementsAttr with the given number of elements should be /// printed with hex. static bool shouldPrintElementsAttrWithHex(int64_t numElements) { @@ -3192,7 +3203,11 @@ } os << " " << key << ": "; - valueFn(os); + + if (printerFlags.shouldPrintResourceValues()) + valueFn(os); + else + os << "\"__elided__\""; }; ResourceBuilder entryBuilder(*this, printFn); provider.buildResources(op, providerArgs..., entryBuilder); diff --git a/mlir/test/IR/pretty-resources-print.mlir b/mlir/test/IR/pretty-resources-print.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/IR/pretty-resources-print.mlir @@ -0,0 +1,48 @@ +// Check printing with --mlir-disable-printing-resource-values elides printing resources + +// RUN: mlir-opt %s --mlir-disable-printing-resource-values| FileCheck %s + +// To ensure we print the resource keys, have reference to them +// CHECK: attr = dense_resource : tensor<3xi64> +"test.blob1op"() {attr = dense_resource : tensor<3xi64> } : () -> () + +// CHECK-NEXT: attr = dense_resource : tensor<3xi64> +"test.blob2op"() {attr = dense_resource : tensor<3xi64> } : () -> () + +// CHECK: {-# +// CHECK-NEXT: dialect_resources: { +// CHECK-NEXT: builtin: { +// CHECK-NEXT: blob1: "__elided__", +// CHECK-NEXT: blob2: "__elided__" +// CHECK-NEXT: } +// CHECK-NEXT: }, +// CHECK-NEXT: external_resources: { +// CHECK-NEXT: external: { +// CHECK-NEXT: blob: "__elided__", +// CHECK-NEXT: bool: "__elided__", +// CHECK-NEXT: string: "__elided__" +// CHECK-NEXT: }, +// CHECK-NEXT: other_stuff: { +// CHECK-NEXT: bool: "__elided__" +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: #-} + +{-# + dialect_resources: { + builtin: { + blob1: "0x08000000010000000000000002000000000000000300000000000000", + blob2: "0x08000000040000000000000005000000000000000600000000000000" + } + }, + external_resources: { + external: { + blob: "0x08000000010000000000000002000000000000000300000000000000", + bool: true, + string: "string" + }, + other_stuff: { + bool: true + } + } +#-}