[mlir][Python] Context managers for Context, InsertionPoint, Location.
authorStella Laurenzo <stellaraccident@gmail.com>
Sun, 1 Nov 2020 06:40:25 +0000 (23:40 -0700)
committerStella Laurenzo <stellaraccident@gmail.com>
Mon, 2 Nov 2020 03:00:39 +0000 (19:00 -0800)
commitaf66cd173fe00b86d1c399b585738eaa01a65042
tree5149bc9ef93e8374e3848ea83870897f7b1e615c
parent8954fd436c729796615bac11b3553c4341f01a82
[mlir][Python] Context managers for Context, InsertionPoint, Location.

* Finishes support for Context, InsertionPoint and Location to be carried by the thread using context managers.
* Introduces type casters and utilities so that DefaultPyMlirContext and DefaultPyLocation in method signatures does the right thing (allows explicit or gets from the thread context).
* Extend the rules for the thread context stack to handle nesting, appropriately inheriting and clearing depending on whether the context is the same.
* Refactors all method signatures to follow the new convention on trailing parameters for defaulting parameters (loc, ip, context). When the objects are carried in the thread context, this allows most explicit uses of these values to be elided.
* Removes the style guide section on putting accessors to construct global objects on the PyMlirContext: this style fails to make good use of the new facility since it is often the only thing remaining needing an MlirContext.
* Moves Module parse/creation from mlir.ir.Context to static methods on mlir.ir.Module.
* Moves Context.create_operation to a static Operation.create method.
* Moves Type parsing from mlir.ir.Context to static methods on mlir.ir.Type.
* Moves Attribute parsing from mlir.ir.Context to static methods on mlir.ir.Attribute.
* Move Location factory methods from mlir.ir.Context to static methods on mlir.ir.Location.
* Refactors the std dialect fake "ODS" generated code to take advantage of the new scheme.

Differential Revision: https://reviews.llvm.org/D90547
14 files changed:
mlir/docs/Bindings/Python.md
mlir/lib/Bindings/Python/IRModules.cpp
mlir/lib/Bindings/Python/IRModules.h
mlir/lib/Bindings/Python/PybindUtils.h
mlir/lib/Bindings/Python/mlir/dialects/std.py
mlir/test/Bindings/Python/context_managers.py [new file with mode: 0644]
mlir/test/Bindings/Python/dialects.py
mlir/test/Bindings/Python/insertion_point.py
mlir/test/Bindings/Python/ir_array_attributes.py
mlir/test/Bindings/Python/ir_attributes.py
mlir/test/Bindings/Python/ir_location.py
mlir/test/Bindings/Python/ir_module.py
mlir/test/Bindings/Python/ir_operation.py
mlir/test/Bindings/Python/ir_types.py