[Mlir-commits] [mlir] Fix tblgen properties printing (PR #79243)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jan 23 18:58:49 PST 2024
https://github.com/arthurqiu updated https://github.com/llvm/llvm-project/pull/79243
>From 8baa547742e3766042a596e06f2bcea5b5ec5af4 Mon Sep 17 00:00:00 2001
From: Arthurq Qiu <arthurq at nvidia.com>
Date: Wed, 24 Jan 2024 10:22:21 +0800
Subject: [PATCH] Fix tblgen for printing prop-dict attr-dict
---
mlir/test/IR/properties.mlir | 10 +++++-----
mlir/tools/mlir-tblgen/OpFormatGen.cpp | 17 ++++++++++++++---
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/mlir/test/IR/properties.mlir b/mlir/test/IR/properties.mlir
index 2aef2abc81f790..3c4bd57859ef91 100644
--- a/mlir/test/IR/properties.mlir
+++ b/mlir/test/IR/properties.mlir
@@ -2,31 +2,31 @@
// # RUN: mlir-opt %s -mlir-print-op-generic -split-input-file | mlir-opt -mlir-print-op-generic | FileCheck %s --check-prefix=GENERIC
// CHECK: test.with_properties
-// CHECK-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}>
+// CHECK-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}>{{$}}
// GENERIC: "test.with_properties"()
// GENERIC-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}> : () -> ()
test.with_properties <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}>
// CHECK: test.with_nice_properties
-// CHECK-SAME: "foo bar" is -3
+// CHECK-SAME: "foo bar" is -3{{$}}
// GENERIC: "test.with_nice_properties"()
// GENERIC-SAME: <{prop = {label = "foo bar", value = -3 : i32}}> : () -> ()
test.with_nice_properties "foo bar" is -3
// CHECK: test.with_wrapped_properties
-// CHECK-SAME: "content for properties"
+// CHECK-SAME: <{prop = "content for properties"}>{{$}}
// GENERIC: "test.with_wrapped_properties"()
// GENERIC-SAME: <{prop = "content for properties"}> : () -> ()
test.with_wrapped_properties <{prop = "content for properties"}>
// CHECK: test.using_property_in_custom
-// CHECK-SAME: [1, 4, 20]
+// CHECK-SAME: [1, 4, 20]{{$}}
// GENERIC: "test.using_property_in_custom"()
// GENERIC-SAME: prop = array<i64: 1, 4, 20>
test.using_property_in_custom [1, 4, 20]
// CHECK: test.using_property_ref_in_custom
-// CHECK-SAME: 1 + 4 = 5
+// CHECK-SAME: 1 + 4 = 5{{$}}
// GENERIC: "test.using_property_ref_in_custom"()
// GENERIC-SAME: <{
// GENERIC-SAME: first = 1
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index b6405baef28e84..31ceb05ad1dbfd 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -366,6 +366,9 @@ struct OperationFormat {
/// Indicate whether attribute are stored in properties.
bool useProperties;
+ /// Indicate whether prop-dict is used in the format
+ bool hasPropDict;
+
/// The Operation class name
StringRef opCppClassName;
@@ -1810,9 +1813,14 @@ static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
body << " }\n";
}
}
- body << " _odsPrinter.printOptionalAttrDict"
- << (withKeyword ? "WithKeyword" : "")
- << "((*this)->getAttrs(), elidedAttrs);\n";
+ if (fmt.hasPropDict)
+ body << " _odsPrinter.printOptionalAttrDict"
+ << (withKeyword ? "WithKeyword" : "")
+ << "(llvm::to_vector((*this)->getDiscardableAttrs()), elidedAttrs);\n";
+ else
+ body << " _odsPrinter.printOptionalAttrDict"
+ << (withKeyword ? "WithKeyword" : "")
+ << "((*this)->getAttrs(), elidedAttrs);\n";
}
/// Generate the printer for a literal value. `shouldEmitSpace` is true if a
@@ -2560,6 +2568,9 @@ LogicalResult OpFormatParser::verify(SMLoc loc,
// Collect the set of used attributes in the format.
fmt.usedAttributes = seenAttrs.takeVector();
+
+ // Set whether prop-dict is used in the format
+ fmt.hasPropDict = hasPropDict;
return success();
}
More information about the Mlir-commits
mailing list