This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tablegen] Generate default attr values in Python bindings
ClosedPublic

Authored by springerm on Jun 14 2022, 8:13 AM.

Details

Summary

When specifying an op attribute with a default value (via DefaultValuedAttr), the default value is a string of C++ code. In the general case, the default value of such an attribute cannot be translated to Python when generating the bindings. However, we can hard-code default Python values for frequently-used C++ default values.

This change adds a Python default value for empty ArrayAttrs.

Diff Detail

Event Timeline

springerm created this revision.Jun 14 2022, 8:13 AM
springerm requested review of this revision.Jun 14 2022, 8:13 AM
ftynse accepted this revision.Jun 15 2022, 7:22 AM

Thanks!

mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
552

Nit: {1} is not None is more pythonic

669

Nit: why is the llvm:: prefix necessary here?

This revision is now accepted and ready to land.Jun 15 2022, 7:22 AM
springerm marked 2 inline comments as done.Jun 15 2022, 7:39 AM
This revision was landed with ongoing or failed builds.Jun 15 2022, 7:43 AM
This revision was automatically updated to reflect the committed changes.

As discussed in the other thread, the better approach is to move the default attributes from being lazily instantiated when queried, to being eagerly created in C++ build method, that way None here is sufficient Python side and all default valued attributes are supported out of box.