mirror-llvm-project/mlir/tools
Maksim Levental c3f381ccfe
[mlir-python] Fix duplicate EnumAttr builder registration across dialects. (#187191)
When multiple dialects share td `#includes` (e.g. `affine` includes
`arith`), each dialect's `*_enum_gen.py` file registers attribute
builders under the same keys, causing "already registered" errors on the
second import; the first commit checks in such a case which currently
fails on main:

```
# | RuntimeError: Attribute builder for 'Arith_CmpFPredicateAttr' is already registered with func: <function _arith_cmpfpredicateattr at 0x78d13cbe9a80>
```

This PR implements a two-pronged fix:

1. Add `allow_existing=True` to `register_attribute_builder` (and the
underlying C++ `registerAttributeBuilder`). When set, silently skips
registration if the key already exists (first-wins semantics). This
handles `EnumInfo`-based builders which have no dialect prefix (e.g.
`AtomicRMWKindAttr`, `Arith_CmpFPredicateAttr`), which may be emitted by
every dialect whose td file includes the defining file;
2. Filter `EnumAttr` builders by `-bind-dialect` in
`EnumPythonBindingGen.cpp` and register them under dialect qualified
keys (`"dialect.AttrName"`). Update `OpPythonBindingGen.cpp` to look up
the same qualified keys for EnumAttr typed op attributes (detected via
`isSubClassOf("EnumAttr")`). Pass `-bind-dialect` from
`AddMLIRPython.cmake`.

This approach incurs no changes to `ir.py` registrations (no "builtin."
prefix), and no manual builder additions to individual dialect Python
files (unlike the previous attempt
https://github.com/llvm/llvm-project/pull/117918).

Note, this PR was "clauded" not "coded".
2026-03-19 21:02:23 -07:00
..
mlir-irdl-to-cpp [MLIR] Apply clang-tidy fixes for readability-container-size-empty in mlir-irdl-to-cpp.cpp (NFC) 2025-12-09 05:54:06 -08:00
mlir-linalg-ods-gen [NFC] Exactly one kind typo fixes, change defintions to definitions. (#174333) 2026-01-14 08:12:26 +00:00
mlir-lsp-server [LLVM][MLIR] Move LSP server support library from MLIR into LLVM (#157885) 2025-09-11 17:17:52 +00:00
mlir-opt [mlir][linalg] Data layout propagation test schedule (#184151) 2026-03-04 08:36:29 +01:00
mlir-parser-fuzzer
mlir-pdll [support] Use VFS in SourceMgr for loading includes (#162903) 2025-10-15 09:24:36 -07:00
mlir-pdll-lsp-server
mlir-query [mlir] Reland Move InitAll*** implementation into static library (#151150) 2025-07-29 18:15:33 +03:00
mlir-reduce [mlir] Reland Move InitAll*** implementation into static library (#151150) 2025-07-29 18:15:33 +03:00
mlir-rewrite [MLIR] Apply clang-tidy fixes for misc-use-internal-linkage in mlir-rewrite.cpp (NFC) 2025-10-03 03:16:39 -07:00
mlir-runner [MLIR] Apply clang-tidy fixes for readability-identifier-naming in mlir-runner.cpp (NFC) 2025-08-29 00:21:45 -07:00
mlir-shlib
mlir-src-sharder [mlir] Avoid ASan ODR violation in mlir-src-sharder with LLVM dylib (#181045) 2026-03-05 11:42:47 +01:00
mlir-tblgen [mlir-python] Fix duplicate EnumAttr builder registration across dialects. (#187191) 2026-03-19 21:02:23 -07:00
mlir-translate
tblgen-lsp-server
tblgen-to-irdl [mlir] fix the Disambiguate NoneType in OpDefinitionsGen (#172923) 2025-12-22 11:36:40 +01:00
CMakeLists.txt