[Mlir-commits] [mlir] [MLIR][IRDL] Relax the restrictions on IRDL-defined names (PR #187911)
Rolf Morel
llvmlistbot at llvm.org
Tue Mar 24 05:27:22 PDT 2026
================
@@ -65,16 +65,46 @@ static std::string joinNameList(llvm::ArrayRef<std::string> names) {
return nameArray;
}
+// Convert a dialect/operation/type/attribute name to a valid identifier in C++.
+// The conversion is done by removing dots, underscores and dollar signs and
+// capitalizing the following character. For example, `name.with.dots` will be
+// converted to `nameWithDots` with `capitalizeFirst = false`.
+static std::string toCppName(StringRef input, bool capitalizeFirst = false) {
+ if (input.empty())
+ return "";
+
+ std::string output;
+ output.reserve(input.size());
+
+ // Push the first character, capatilizing if necessary.
+ if (capitalizeFirst && std::islower(input.front()))
+ output.push_back(llvm::toUpper(input.front()));
+ else
+ output.push_back(input.front());
+
+ // Walk the input converting any `*[._$]+[a-z]` snake case into `*[A-Z]`
+ // camelCase.
+ bool isSpecial = false;
+ for (char c : input.drop_front()) {
+ if (c == '_' || c == '.' || c == '$')
+ isSpecial = true;
+ else if (isSpecial) {
+ output.push_back(llvm::toUpper(c));
----------------
rolfmorel wrote:
There are indeed places in the C++/tablegen codebase where these "sub"dialects are put in a dedicated namespace. I think that's a good solution for the `.` characters, i.e. they map to `::`. If we have the no-uppercase restriction, we can map any `_` followed by a lowercase char to the corresponding single uppercase char -- that's bijective. Any `_`s that are followed by an underscore can be mapped to just a `_`.
Then what remains is the `$` case. Unless someone has a good suggestion now, I vote for punting that to a later PR and just disallowing it for now. I don't think I have seen any actual usage of it.
https://github.com/llvm/llvm-project/pull/187911
More information about the Mlir-commits
mailing list