This is an archive of the discontinued LLVM Phabricator instance.

Add mlir python APIs for creating operations, regions and blocks.
ClosedPublic

Authored by stellaraccident on Sep 20 2020, 9:29 PM.

Details

Summary
  • The API is a bit more verbose than I feel like it needs to be. In a follow-up I'd like to abbreviate some things and look in to creating aliases for common accessors.
  • There is a lingering lifetime hazard between the module and newly added operations. We have the facilities now to solve for this but I will do that in a follow-up.
  • We may need to craft a more limited API for safely referencing successors when creating operations. We need more facilities to really prove that out and should defer for now.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptSep 20 2020, 9:29 PM
stellaraccident requested review of this revision.Sep 20 2020, 9:29 PM
ftynse accepted this revision.Sep 23 2020, 6:10 AM
ftynse added inline comments.
mlir/lib/Bindings/Python/IRModules.cpp
407
1306

Nit: should this rather be a member of PyMlirContext? Compact .def lists are easier to scan as "documentation".

1357

We can have a RAII cleaner if needed

1367

Nit: reserve space

This revision is now accepted and ready to land.Sep 23 2020, 6:10 AM
stellaraccident marked 4 inline comments as done.

Address comments.

This revision was landed with ongoing or failed builds.Sep 23 2020, 7:59 AM
This revision was automatically updated to reflect the committed changes.
mlir/lib/Bindings/Python/IRModules.cpp
1306

I switched it and maybe it is marginally better. This is kind of the worst-case scenario: lots of args that need to line up, complicated implementation. It's a burden either way.

1357

I started down that path and then just opted for simplicity since this is the one and only place we are doing this kind of juggling (mental overhead of a cleaner and releasing properly to avoid double free can be bug prone too).