1 //===- DialectLinalg.cpp - Pybind module for Linalg dialect API support --===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "IRModule.h" 10 #include "mlir-c/Dialect/Linalg.h" 11 #include "mlir-c/IR.h" 12 13 #include <pybind11/pybind11.h> 14 15 namespace py = pybind11; 16 using namespace mlir; 17 using namespace mlir::python; 18 19 namespace mlir { 20 namespace python { 21 22 void populateDialectLinalgSubmodule(py::module &m) { 23 m.def( 24 "fill_builtin_region", 25 [](PyDialectDescriptor &dialect, PyOperation &op, py::list captures) { 26 llvm::SmallVector<MlirValue, 4> mlirOperands; 27 mlirOperands.reserve(captures.size()); 28 for (auto v : captures) 29 mlirOperands.push_back(py::cast<PyValue *>(v)->get()); 30 mlirLinalgFillBuiltinNamedOpRegion( 31 dialect.get(), op.get(), mlirOperands.size(), mlirOperands.data()); 32 }, 33 py::arg("dialect"), py::arg("op"), py::arg("captures") = py::list(), 34 "Fill the region for `op`, which is assumed to be a builtin named Linalg " 35 "op."); 36 } 37 38 } // namespace python 39 } // namespace mlir 40