[Mlir-commits] [mlir] b074b35 - [mlir] Add a test for default valued dictionary attributes
Eugene Zhulenev
llvmlistbot at llvm.org
Fri Dec 30 12:16:01 PST 2022
Author: Eugene Zhulenev
Date: 2022-12-30T12:15:54-08:00
New Revision: b074b356c982a9139cf9dfd1167dd957ea5cc8a1
URL: https://github.com/llvm/llvm-project/commit/b074b356c982a9139cf9dfd1167dd957ea5cc8a1
DIFF: https://github.com/llvm/llvm-project/commit/b074b356c982a9139cf9dfd1167dd957ea5cc8a1.diff
LOG: [mlir] Add a test for default valued dictionary attributes
+ Replace special placeholders ($_builder, etc...) in default attribute string
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D140765
Added:
Modified:
mlir/test/mlir-tblgen/op-attribute.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Removed:
################################################################################
diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td
index 5351db36dea9..012d03c3dae6 100644
--- a/mlir/test/mlir-tblgen/op-attribute.td
+++ b/mlir/test/mlir-tblgen/op-attribute.td
@@ -392,6 +392,27 @@ def DOp : NS_Op<"d_op", []> {
// DEF: odsState.addAttribute(getStrAttrAttrName(odsState.name), odsBuilder.getStringAttr(str_attr));
// DEF: odsState.addAttribute(getDvStrAttrAttrName(odsState.name), odsBuilder.getStringAttr(dv_str_attr));
+
+// Test default dictionary attribute.
+// ---
+
+def DefaultDictAttrOp : NS_Op<"default_dict_attr_op", []> {
+ let arguments = (ins
+ DefaultValuedAttr<DictionaryAttr, "{}">:$empty,
+ DefaultValuedAttr<DictionaryAttr, "getDefaultDictAttrs($_builder)">:$non_empty
+ );
+}
+
+// DEF-LABEL: DefaultDictAttrOp definitions
+// DEF: if (!attributes.get(attrNames[0]))
+// DEF: attributes.append(attrNames[0], odsBuilder.getDictionaryAttr({}));
+// DEF: if (!attributes.get(attrNames[1]))
+// DEF: attributes.append(attrNames[1], odsBuilder.getDictionaryAttr(getDefaultDictAttrs(odsBuilder)));
+
+// DECL-LABEL: DefaultDictAttrOp declarations
+// DECL: build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::DictionaryAttr empty, ::mlir::DictionaryAttr non_empty)
+
+
// Test derived type attr.
// ---
def DerivedTypeAttrOp : NS_Op<"derived_type_attr_op", []> {
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 2f88583d7fac..204d1d730ba5 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -1725,8 +1725,10 @@ void OpEmitter::genPopulateDefaultAttributes() {
body << "if (!attributes.get(attrNames[" << index << "])) {\n";
FmtContext fctx;
fctx.withBuilder(odsBuilder);
- std::string defaultValue = std::string(
- tgfmt(attr.getConstBuilderTemplate(), &fctx, attr.getDefaultValue()));
+
+ std::string defaultValue =
+ std::string(tgfmt(attr.getConstBuilderTemplate(), &fctx,
+ tgfmt(attr.getDefaultValue(), &fctx)));
body.indent() << formatv("attributes.append(attrNames[{0}], {1});\n", index,
defaultValue);
body.unindent() << "}\n";
More information about the Mlir-commits
mailing list