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
This commit is contained in:
Mehdi Amini 2022-01-19 19:57:59 +00:00
parent 5bd38a2826
commit e7ab36f191
4 changed files with 7 additions and 7 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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>} : () -> ()

View File

@ -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,