This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Make attributes mutable in Python bindings
ClosedPublic

Authored by ftynse on Nov 17 2020, 11:23 AM.

Details

Summary

Attributes represent additional data about an operation and are intended to be
modifiable during the lifetime of the operation. In the dialect-specific Python
bindings, attributes are exposed as properties on the operation class. Allow
for assigning values to these properties. Also support creating new and
deleting existing attributes through the generic "attributes" property of an
operation. Any validity checking must be performed by the op verifier after the
mutation, similarly to C++. Operations are not invalidated in the process: no
dangling pointers can be created as all attributes are owned by the context and
will remain live even if they are not used in any operation.

Introduce a Python Test dialect by analogy with the Test dialect and to avoid
polluting the latter with Python-specific constructs. Use this dialect to
implement a test for the attribute access and mutation API.

Diff Detail

Event Timeline

ftynse created this revision.Nov 17 2020, 11:23 AM
ftynse requested review of this revision.Nov 17 2020, 11:23 AM
mehdi_amini added inline comments.Nov 19 2020, 9:03 PM
mlir/test/Bindings/Python/python_test_ops.td
14

The relative include is a bit unexpected here, what's the plan for dialects if they need to include this file?

stellaraccident accepted this revision.Nov 20 2020, 7:49 AM

Nice!

mlir/test/Bindings/Python/python_test_ops.td
14

I've been assuming that once this is usable for more than testing, we would need an include/Bindings/Python/Attributes.td path. This and a couple of other things would move there. Alex, concur?

This revision is now accepted and ready to land.Nov 20 2020, 7:49 AM
ftynse added inline comments.Nov 23 2020, 5:05 AM
mlir/test/Bindings/Python/python_test_ops.td
14

I hesitated to add include/mlir/Bindings/Python/ because it's not there yet. If we all agree, I'll just do that as a separate commit (there are other users of Attributes.td that need to be changed).

ftynse added inline comments.Nov 23 2020, 5:22 AM
mlir/test/Bindings/Python/python_test_ops.td
14
mehdi_amini accepted this revision.Nov 23 2020, 10:40 AM
This revision was landed with ongoing or failed builds.Nov 24 2020, 12:16 AM
This revision was automatically updated to reflect the committed changes.