[Mlir-commits] [mlir] [mlir] NamedAttribute utility generator (PR #75118)

Mehdi Amini llvmlistbot at llvm.org
Tue Dec 12 13:32:44 PST 2023


================
@@ -283,6 +283,78 @@ class AttrDef<Dialect dialect, string name, list<Trait> traits = [],
                                  "::" # cppClassName # ">($_self)">;
 }
 
+// Define a StringAttr wrapper for the NamedAttribute `name`
+// - `name` is dialect-scoped when not-inherent.
+// - Utilities to is/has/get/set/lookup/create typed Attr on an Operation
+//   including typed `value` attribute
+class NamedAttrDef<Dialect dialect, string name, string userName,
+    string valueAttrType = "::mlir::Attribute">
+    : AttrDef<dialect, name, [], "::mlir::StringAttr"> {
+  let mnemonic = userName;
+
+  string scopedName = dialect.name # "." # mnemonic;
+  code typedefValueAttr = "typedef " # valueAttrType # " ValueAttrType;\n";
+  code getNameFunc = "static constexpr llvm::StringLiteral getScopedName() { return \""
+      # scopedName # "\"; }\n";
+
+  code namedAttrFuncs = !strconcat(typedefValueAttr, getNameFunc, [{
+    // Get name based on inherentness
+    static llvm::StringLiteral getName(Operation *op = nullptr) {
----------------
joker-eph wrote:

I don't understand the intended semantics of all this right now.

https://github.com/llvm/llvm-project/pull/75118


More information about the Mlir-commits mailing list