[Mlir-commits] [mlir] [mlir][python] fix value-builder generation for snake_case ops (PR #135302)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Apr 10 19:50:35 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
@llvm/pr-subscribers-mlir
Author: Maksim Levental (makslevental)
<details>
<summary>Changes</summary>
Ops that are already snake case (like [`ROCDL_wmma_*` ops](https://github.com/makslevental/llvm-project/blob/66b0b0466bbd995146aadaf2cd18de5476c19941/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td#L411)) produce python "value-builders" that collide with the class names;
```python
class wmma_bf16_16x16x16_bf16(_ods_ir.OpView):
OPERATION_NAME = "rocdl.wmma.bf16.16x16x16.bf16"
...
def wmma_bf16_16x16x16_bf16(res, args, *, loc=None, ip=None) -> _ods_ir.Value:
return wmma_bf16_16x16x16_bf16(res=res, args=args, loc=loc, ip=ip).result
```
and thus cannot be emited (because recursive self-calls).
This PR fixes that by affixing `_` to the value builders. I would've preferred to just rename the ops but that would be a breaking change :shrug:.
---
Full diff: https://github.com/llvm/llvm-project/pull/135302.diff
2 Files Affected:
- (modified) mlir/test/mlir-tblgen/op-python-bindings.td (+3)
- (modified) mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp (+5-2)
``````````diff
diff --git a/mlir/test/mlir-tblgen/op-python-bindings.td b/mlir/test/mlir-tblgen/op-python-bindings.td
index 72963cac64d54..280c745262428 100644
--- a/mlir/test/mlir-tblgen/op-python-bindings.td
+++ b/mlir/test/mlir-tblgen/op-python-bindings.td
@@ -654,3 +654,6 @@ def WithSuccessorsOp : TestOp<"with_successors"> {
// CHECK: def with_successors(successor, successors, *, loc=None, ip=None)
// CHECK: return WithSuccessorsOp(successor=successor, successors=successors, loc=loc, ip=ip)
+
+def already_snake_case : TestOp<"already_snake_case"> {}
+// CHECK: def already_snake_case_(*, loc=None, ip=None)
diff --git a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
index 604d2376052a8..14d50cd71047b 100644
--- a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
@@ -998,8 +998,11 @@ static void emitValueBuilder(const Operator &op,
auto lhs = *llvm::split(arg, "=").begin();
return (lhs + "=" + llvm::convertToSnakeFromCamelCase(lhs)).str();
});
- std::string nameWithoutDialect = sanitizeName(
- op.getOperationName().substr(op.getOperationName().find('.') + 1));
+ StringRef opClassName =
+ op.getOperationName().substr(op.getOperationName().find('.') + 1);
+ std::string nameWithoutDialect = sanitizeName(opClassName);
+ if (nameWithoutDialect == opClassName)
+ nameWithoutDialect += "_";
std::string params = llvm::join(valueBuilderParams, ", ");
std::string args = llvm::join(opBuilderArgs, ", ");
const char *type =
``````````
</details>
https://github.com/llvm/llvm-project/pull/135302
More information about the Mlir-commits
mailing list