[Mlir-commits] [mlir] [MLIR][IRDL] Relax the restrictions on IRDL-defined names (PR #187911)

Théo Degioanni llvmlistbot at llvm.org
Sun Mar 22 23:57:03 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));
----------------
Moxinilian wrote:

One of the goals of IRDL (and IRDL to C++) is to have self contained error reports: if C++ is generated, then this C++ must compile. This lack of guarantee from TableGen is one of the reasons the user experience is subpar, and it's really crucial that IRDL does not reproduce this.

The reason we added the snake case limitation in the first place is because of this. We tried to come up with a reasonable mapping. If you can find one that makes sense I would agree this constraint can be lifted, but I'm afraid so far we have not been able to.

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


More information about the Mlir-commits mailing list