llvm-project/mlir/lib/Bindings/Python/DialectLinalg.cpp
Nicolas Vasilache b5f3a128bf [mlir][Python][Linalg] Add support for captures in body builder.
When Linalg named ops support was added, captures were omitted
from the body builder. This revision adds support for captures
which allows us to write FillOp in a more idiomatic fashion using
the _linalg_ops_ext mixin support.

This raises an issue in the generation of `_linalg_ops_gen.py` where
```
  @property
  def result(self):
    return self.operation.results[0] if len(self.operation.results) > 1 else None
```.
The condition should be `== 1`.

This will be fixed in a separate commit.

Differential Revision: https://reviews.llvm.org/D100363
2021-04-16 08:47:26 +00:00

40 lines
1.3 KiB
C++

//===- DialectLinalg.cpp - Pybind module for Linalg dialect API support --===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "IRModule.h"
#include "mlir-c/Dialect/Linalg.h"
#include "mlir-c/IR.h"
#include <pybind11/pybind11.h>
namespace py = pybind11;
using namespace mlir;
using namespace mlir::python;
namespace mlir {
namespace python {
void populateDialectLinalgSubmodule(py::module &m) {
m.def(
"fill_builtin_region",
[](PyDialectDescriptor &dialect, PyOperation &op, py::list captures) {
llvm::SmallVector<MlirValue, 4> mlirOperands;
mlirOperands.reserve(captures.size());
for (auto v : captures)
mlirOperands.push_back(py::cast<PyValue *>(v)->get());
mlirLinalgFillBuiltinNamedOpRegion(
dialect.get(), op.get(), mlirOperands.size(), mlirOperands.data());
},
py::arg("dialect"), py::arg("op"), py::arg("captures") = py::list(),
"Fill the region for `op`, which is assumed to be a builtin named Linalg "
"op.");
}
} // namespace python
} // namespace mlir