[all-commits] [llvm/llvm-project] 37107e: [mlir][python] Add generic operation parse APIs

rk via All-commits all-commits at lists.llvm.org
Wed Mar 1 15:17:28 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 37107e177e4a0a9ceab397f2667fe4dab98fb729
      https://github.com/llvm/llvm-project/commit/37107e177e4a0a9ceab397f2667fe4dab98fb729
  Author: rkayaith <rkayaith at gmail.com>
  Date:   2023-03-01 (Wed, 01 Mar 2023)

  Changed paths:
    M mlir/include/mlir-c/IR.h
    M mlir/include/mlir/Parser/Parser.h
    M mlir/lib/Bindings/Python/IRCore.cpp
    M mlir/lib/Bindings/Python/IRModule.h
    M mlir/lib/CAPI/IR/IR.cpp
    M mlir/lib/Parser/Parser.cpp
    M mlir/test/python/ir/operation.py

  Log Message:
  -----------
  [mlir][python] Add generic operation parse APIs

Currently the bindings only allow for parsing IR with a top-level
`builtin.module` op, since the parse APIs insert an implicit module op.
This change adds `Operation.parse`, which returns whatever top-level op
is actually in the source.

To simplify parsing of specific operations, `OpView.parse` is also
added, which handles the error checking for `OpView` subclasses.

Reviewed By: ftynse, stellaraccident

Differential Revision: https://reviews.llvm.org/D143352


  Commit: 6f5590ca347a5a2467b8aaea4b24bc9b70ef138f
      https://github.com/llvm/llvm-project/commit/6f5590ca347a5a2467b8aaea4b24bc9b70ef138f
  Author: rkayaith <rkayaith at gmail.com>
  Date:   2023-03-01 (Wed, 01 Mar 2023)

  Changed paths:
    M mlir/include/mlir-c/Pass.h
    M mlir/lib/Bindings/Python/Pass.cpp
    M mlir/lib/CAPI/IR/Pass.cpp
    M mlir/test/CAPI/execution_engine.c
    M mlir/test/CAPI/pass.c

  Log Message:
  -----------
  [mlir][CAPI] Allow running pass manager on any operation

`mlirPassManagerRun` is currently restricted to running on
`builtin.module` ops, but this restriction doesn't exist on the C++
side. This renames it to `mlirPassManagerRunOnOp` and updates it to take
`MlirOperation` instead of `MlirModule`.

Depends on D143352

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D143354


  Commit: c00f81cc46bd88b001110e9c6564c4848f82900c
      https://github.com/llvm/llvm-project/commit/c00f81cc46bd88b001110e9c6564c4848f82900c
  Author: rkayaith <rkayaith at gmail.com>
  Date:   2023-03-01 (Wed, 01 Mar 2023)

  Changed paths:
    M mlir/lib/Bindings/Python/Pass.cpp
    M mlir/test/Integration/Dialect/SparseTensor/python/tools/sparse_compiler.py
    M mlir/test/Integration/Dialect/SparseTensor/taco/tools/mlir_sparse_compiler.py
    M mlir/test/python/execution_engine.py
    M mlir/test/python/integration/dialects/linalg/opsrun.py
    M mlir/test/python/pass_manager.py

  Log Message:
  -----------
  [mlir][python] Allow running pass manager on any operation

`PassManager.run` is currently restricted to running on `builtin.module`
ops, but this restriction doesn't exist on the C++ side. This updates it
to take `ir.Operation/OpView` instead of `ir.Module`.

Depends on D143354

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D143356


  Commit: a7f8b7cd8e49bb8680c34c1cc290a121ae37b4ac
      https://github.com/llvm/llvm-project/commit/a7f8b7cd8e49bb8680c34c1cc290a121ae37b4ac
  Author: Rahul Kayaith <rkayaith at gmail.com>
  Date:   2023-03-01 (Wed, 01 Mar 2023)

  Changed paths:
    M mlir/lib/Bindings/Python/Globals.h
    M mlir/lib/Bindings/Python/IRCore.cpp
    M mlir/lib/Bindings/Python/IRModule.cpp
    M mlir/lib/Bindings/Python/IRModule.h
    M mlir/lib/Bindings/Python/MainModule.cpp
    M mlir/python/mlir/_mlir_libs/_mlir/__init__.pyi
    M mlir/test/python/ir/operation.py

  Log Message:
  -----------
  [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


Compare: https://github.com/llvm/llvm-project/compare/f5f8a46bb0ce...a7f8b7cd8e49


More information about the All-commits mailing list