From e7ab36f191108cb42e85702b9a90d92cefdff6ec Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Wed, 19 Jan 2022 19:57:59 +0000 Subject: [PATCH] Change elided large constant syntax to make it more explicit When the printer is requested to elide large constant, we emit an opaque attribute instead. This patch fills the dialect name with "elided_large_const" instead of "_" to remove some user confusion when they later try to consume it. Differential Revision: https://reviews.llvm.org/D117711 --- mlir/lib/IR/AsmPrinter.cpp | 2 +- mlir/test/CAPI/ir.c | 2 +- mlir/test/IR/pretty-attributes.mlir | 8 ++++---- mlir/test/python/ir/operation.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 6c9977df101f..97eca237cdb6 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -1607,7 +1607,7 @@ static void printSymbolReference(StringRef symbolRef, raw_ostream &os) { // accept the string "elided". The first string must be a registered dialect // name and the latter must be a hex constant. static void printElidedElementsAttr(raw_ostream &os) { - os << R"(opaque<"_", "0xDEADBEEF">)"; + os << R"(opaque<"elided_large_const", "0xDEADBEEF">)"; } LogicalResult AsmPrinter::Impl::printAlias(Attribute attr) { diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c index 51e0c2b4bcd2..418d5a0aa3fe 100644 --- a/mlir/test/CAPI/ir.c +++ b/mlir/test/CAPI/ir.c @@ -463,7 +463,7 @@ static void printFirstOfEach(MlirContext ctx, MlirOperation operation) { mlirOperationPrintWithFlags(operation, flags, printToStderr, NULL); fprintf(stderr, "\n"); // clang-format off - // CHECK: Op print with all flags: %{{.*}} = "arith.constant"() {elts = opaque<"_", "0xDEADBEEF"> : tensor<4xi32>, value = 0 : index} : () -> index loc(unknown) + // CHECK: Op print with all flags: %{{.*}} = "arith.constant"() {elts = opaque<"elided_large_const", "0xDEADBEEF"> : tensor<4xi32>, value = 0 : index} : () -> index loc(unknown) // clang-format on mlirOpPrintingFlagsDestroy(flags); diff --git a/mlir/test/IR/pretty-attributes.mlir b/mlir/test/IR/pretty-attributes.mlir index d1d43a17b862..8146608d4310 100644 --- a/mlir/test/IR/pretty-attributes.mlir +++ b/mlir/test/IR/pretty-attributes.mlir @@ -5,17 +5,17 @@ // tensor which passes don't look at directly, this isn't an issue. // RUN: mlir-opt %s -mlir-elide-elementsattrs-if-larger=2 | mlir-opt -// CHECK: opaque<"_", "0xDEADBEEF"> : tensor<3xi32> +// CHECK: opaque<"elided_large_const", "0xDEADBEEF"> : tensor<3xi32> "test.dense_attr"() {foo.dense_attr = dense<[1, 2, 3]> : tensor<3xi32>} : () -> () // CHECK: dense<[1, 2]> : tensor<2xi32> "test.non_elided_dense_attr"() {foo.dense_attr = dense<[1, 2]> : tensor<2xi32>} : () -> () -// CHECK: opaque<"_", "0xDEADBEEF"> : vector<1x1x10xf16> +// CHECK: opaque<"elided_large_const", "0xDEADBEEF"> : vector<1x1x10xf16> "test.sparse_attr"() {foo.sparse_attr = sparse<[[0, 0, 5]], -2.0> : vector<1x1x10xf16>} : () -> () -// CHECK: opaque<"_", "0xDEADBEEF"> : tensor<100xf32> -"test.opaque_attr"() {foo.opaque_attr = opaque<"_", "0xEBFE"> : tensor<100xf32> } : () -> () +// CHECK: opaque<"elided_large_const", "0xDEADBEEF"> : tensor<100xf32> +"test.opaque_attr"() {foo.opaque_attr = opaque<"elided_large_const", "0xEBFE"> : tensor<100xf32> } : () -> () // CHECK: dense<1> : tensor<3xi32> "test.dense_splat"() {foo.dense_attr = dense<1> : tensor<3xi32>} : () -> () diff --git a/mlir/test/python/ir/operation.py b/mlir/test/python/ir/operation.py index 12f08e9c2fda..f7484920c65f 100644 --- a/mlir/test/python/ir/operation.py +++ b/mlir/test/python/ir/operation.py @@ -555,7 +555,7 @@ def testOperationPrint(): print(bytes_value) # Test get_asm with options. - # CHECK: value = opaque<"_", "0xDEADBEEF"> : tensor<4xi32> + # CHECK: value = opaque<"elided_large_const", "0xDEADBEEF"> : tensor<4xi32> # CHECK: "std.return"(%arg0) : (i32) -> () -:4:7 module.operation.print( large_elements_limit=2,