This is an archive of the discontinued LLVM Phabricator instance.

Add InsertionPoint and context managers to the Python API.
ClosedPublic

Authored by stellaraccident on Oct 28 2020, 11:20 PM.

Details

Summary
  • Removes index based insertion. All insertion now happens through the insertion point.
  • Introduces thread local context managers for implicit creation relative to an insertion point.
  • Introduces (but does not yet use) binding the Context to the thread local context stack. Intent is to refactor all methods to take context optionally and have them use the default if available.
  • Adds C APIs for mlirOperationGetParentOperation(), mlirOperationGetBlock() and mlirBlockGetTerminator().
  • Removes an assert in PyOperation creation that was incorrectly constraining. There is already a TODO to rework the keepAlive field that it was guarding and without the assert, it is no worse than the current state.

Diff Detail

Event Timeline

stellaraccident requested review of this revision.Oct 28 2020, 11:20 PM

Very nice!

mlir/lib/Bindings/Python/IRModules.cpp
647

Nit: remove trivial brace.

685

This API does not have a user in this patch right now.

905

(trivial braces twice here)

967

(trivial brace)

996

(trivial brace)

1023

(trivial brace, and above)

mlir/lib/Bindings/Python/IRModules.h
100

Why the difference between the two APIs? (one is returning nullptr the other throwing an exception)?

110

Why a std::list instead of a vector?

stellaraccident marked 7 inline comments as done.

Address comments.

Thanks. PTAL.

mlir/lib/Bindings/Python/IRModules.cpp
685

I'm going to leave it (it is leaking from the next patch and has an implementation in line with the one for default insertion points).

mlir/lib/Bindings/Python/IRModules.h
100

Just added them as needed (here and leaking from the followup). I've normalized them with a required flag. I would like the accessors for the default context and insertion point centralized because the next patch wires them in various ways for converting args when not explicitly provided, and the exception raising should be in one place.

110

I suppose because "that's what I always do for these context manager holders" isn't a great answer, considering that we all know that list is inferior if not used for specific things :)

I've switch to vector, and in my defense, I think I was reaching for it because of previous designs that needed to store non-movable types.

mehdi_amini accepted this revision.Oct 29 2020, 4:50 PM
This revision is now accepted and ready to land.Oct 29 2020, 4:50 PM
This revision was landed with ongoing or failed builds.Oct 29 2020, 5:53 PM
This revision was automatically updated to reflect the committed changes.