[PATCH] D76144: [mlir] Automatically add DerivedAttribute op interface
Jacques Pienaar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 13 14:35:13 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2bb8b6cd640: [mlir] Automatically add DerivedAttribute op interface (authored by jpienaar).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76144/new/
https://reviews.llvm.org/D76144
Files:
mlir/test/mlir-tblgen/op-attribute.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Index: mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
===================================================================
--- mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -401,16 +401,19 @@
// Generate helper method to query whether a named attribute is a derived
// attribute. This enables, for example, avoiding adding an attribute that
// overlaps with a derived attribute.
- auto &method =
- opClass.newMethod("bool", "isDerivedAttribute", "StringRef name");
- auto &body = method.body();
auto derivedAttr = make_filter_range(op.getAttributes(),
[](const NamedAttribute &namedAttr) {
return namedAttr.attr.isDerivedAttr();
});
- for (auto namedAttr : derivedAttr)
- body << " if (name == \"" << namedAttr.name << "\") return true;\n";
- body << " return false;";
+ if (!derivedAttr.empty()) {
+ opClass.addTrait("DerivedAttributeOpInterface::Trait");
+ auto &method = opClass.newMethod("bool", "isDerivedAttribute",
+ "StringRef name", OpMethod::MP_Static);
+ auto &body = method.body();
+ for (auto namedAttr : derivedAttr)
+ body << " if (name == \"" << namedAttr.name << "\") return true;\n";
+ body << " return false;";
+ }
}
void OpEmitter::genAttrSetters() {
Index: mlir/test/mlir-tblgen/op-attribute.td
===================================================================
--- mlir/test/mlir-tblgen/op-attribute.td
+++ mlir/test/mlir-tblgen/op-attribute.td
@@ -208,7 +208,9 @@
DerivedTypeAttr element_dtype = DerivedTypeAttr<"return output().getType();">;
}
-// DECL: bool isDerivedAttribute
+// DECL: class DerivedTypeAttrOp : public Op
+// DECL-SAME: DerivedAttributeOpInterface::Trait
+// DECL: static bool isDerivedAttribute
// DEF: bool DerivedTypeAttrOp::isDerivedAttribute(StringRef name) {
// DEF: if (name == "element_dtype") return true;
// DEF: return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76144.250306.patch
Type: text/x-patch
Size: 2053 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200313/c03bd632/attachment.bin>
More information about the llvm-commits
mailing list