[Mlir-commits] [mlir] [mlir][ODS] Add `OptionalTypesMatchWith` and remove a custom assemblyFormat (PR #68876)

Cullen Rhodes llvmlistbot at llvm.org
Thu Oct 12 05:06:01 PDT 2023


================
@@ -568,6 +568,21 @@ class TypesMatchWith<string summary, string lhsArg, string rhsArg,
   string transformer = transform;
 }
 
+// Helper which makes the first letter of a string uppercase.
+// e.g. cat -> Cat
+class first_char_to_upper<string str>
+{
+  string ret = !toupper(!substr(str, 0, 1)) # !substr(str, 1);
+}
+
+// The same as TypesMatchWith but if either `lhsArg` or `rhsArg` are optional
+// and not present returns success.
+class OptionalTypesMatchWith<string summary, string lhsArg, string rhsArg,
+                     string transform, string comparator = "std::equal_to<>()">
+  : TypesMatchWith<summary, lhsArg, rhsArg, transform,
+     "!get" # first_char_to_upper<lhsArg>.ret # "()"
+     # " || !get" # first_char_to_upper<rhsArg>.ret # "() || " # comparator>;
----------------
c-rhodes wrote:

I don't think will work for all cases, I think the getters are generated with
```
"get" + convertToCamelFromSnakeCase(name, /*capitalizeFirst=*/true)
```

not sure how easy it'll be to integrate that into tablegen, might be easier to pass the getter as a parameter for now?

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


More information about the Mlir-commits mailing list