[Mlir-commits] [mlir] [mlir][python] Make the Context/Operation capsule creation methods work as documented. (PR #76010)

Maksim Levental llvmlistbot at llvm.org
Thu Dec 21 01:35:35 PST 2023


makslevental wrote:

> @makslevental could you give an example of the wrong things downstreams were doing and how to make it right? This will help downstreams to fix themselves after they bump LLVM version past this commit.

Well I'm doing super-gnarly stuff like shipping arbitrary `mlir::Operation`s [across the boundary](https://github.com/Xilinx/mlir-aie/blob/a63eb5dac38c89257c94174d0cb214332083d597/python/PybindTypes.cpp#L37):

```cpp
 return static_cast<PySwitchboxOp &>(
      PyOperation::forOperation(DefaultingPyMlirContext::resolve().getRef(),
                                wrap(switchboxOp.getOperation()))
          ->getOperation());
```

I highly doubt anyone else is doing this (I don't think anyone else knows how to...). `return_value_policy` I've had to reach for when returning arbitrary [C++ functions across the boundary](https://github.com/Xilinx/mlir-aie/blob/a63eb5dac38c89257c94174d0cb214332083d597/python/PybindTypes.cpp#L143) (another thing I doubt anyone else is doing). 

I was actually curious what exactly @stellaraccident was experiencing that prompted this PR (there's a linked PR in iree but it doesn't say much).

> This will help downstreams to fix themselves after they bump LLVM version past this commit.

My plan is to change `forOperation` -> `stealExternalOperation` and see what happens. Not very scientific unfortunately.

https://github.com/llvm/llvm-project/pull/76010


More information about the Mlir-commits mailing list