diff options
author | Rahul Kayaith <rkayaith@gmail.com> | 2023-01-22 23:31:18 -0500 |
---|---|---|
committer | Rahul Kayaith <rkayaith@gmail.com> | 2023-03-01 18:17:14 -0500 |
commit | a7f8b7cd8e49bb8680c34c1cc290a121ae37b4ac (patch) | |
tree | 78d5ad808fcb94a1e95e89bd18c8421ed3323429 /mlir/lib/Bindings/Python/IRModule.h | |
parent | c00f81cc46bd88b001110e9c6564c4848f82900c (diff) | |
download | llvm-a7f8b7cd8e49bb8680c34c1cc290a121ae37b4ac.zip llvm-a7f8b7cd8e49bb8680c34c1cc290a121ae37b4ac.tar.gz llvm-a7f8b7cd8e49bb8680c34c1cc290a121ae37b4ac.tar.bz2 |
[mlir][python] Remove "Raw" OpView classes
The raw `OpView` classes are used to bypass the constructors of `OpView`
subclasses, but having a separate class can create some confusing
behaviour, e.g.:
```
op = MyOp(...)
# fails, lhs is 'MyOp', rhs is '_MyOp'
assert type(op) == type(op.operation.opview)
```
Instead we can use `__new__` to achieve the same thing without a
separate class:
```
my_op = MyOp.__new__(MyOp)
OpView.__init__(my_op, op)
```
Reviewed By: stellaraccident
Differential Revision: https://reviews.llvm.org/D143830
Diffstat (limited to 'mlir/lib/Bindings/Python/IRModule.h')
-rw-r--r-- | mlir/lib/Bindings/Python/IRModule.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/mlir/lib/Bindings/Python/IRModule.h b/mlir/lib/Bindings/Python/IRModule.h index fa4bc1c..4aced36 100644 --- a/mlir/lib/Bindings/Python/IRModule.h +++ b/mlir/lib/Bindings/Python/IRModule.h @@ -654,8 +654,6 @@ public: PyOpView(const pybind11::object &operationObject); PyOperation &getOperation() override { return operation; } - static pybind11::object createRawSubclass(const pybind11::object &userClass); - pybind11::object getOperationObject() { return operationObject; } static pybind11::object @@ -666,6 +664,16 @@ public: std::optional<int> regions, DefaultingPyLocation location, const pybind11::object &maybeIp); + /// Construct an instance of a class deriving from OpView, bypassing its + /// `__init__` method. The derived class will typically define a constructor + /// that provides a convenient builder, but we need to side-step this when + /// constructing an `OpView` for an already-built operation. + /// + /// The caller is responsible for verifying that `operation` is a valid + /// operation to construct `cls` with. + static pybind11::object constructDerived(const pybind11::object &cls, + const PyOperation &operation); + private: PyOperation &operation; // For efficient, cast-free access from C++ pybind11::object operationObject; // Holds the reference. |