mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 19:07:53 +08:00
Initial MLIR python bindings based on the C API.
* Basic support for context creation, module parsing and dumping. Differential Revision: https://reviews.llvm.org/D85481
This commit is contained in:
committed by
Stella Laurenzo
parent
e10e7829bf
commit
fcd2969da9
36
mlir/lib/Bindings/Python/IRModules.cpp
Normal file
36
mlir/lib/Bindings/Python/IRModules.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
//===- IRModules.cpp - IR Submodules of pybind module ---------------------===//
|
||||
//
|
||||
// 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 "IRModules.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Context Wrapper Class.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
PyMlirModule PyMlirContext::parse(const std::string &module) {
|
||||
auto moduleRef = mlirModuleCreateParse(context, module.c_str());
|
||||
return PyMlirModule(moduleRef);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Module Wrapper Class.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void PyMlirModule::dump() { mlirOperationDump(mlirModuleGetOperation(module)); }
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Populates the pybind11 IR submodule.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void populateIRSubmodule(py::module &m) {
|
||||
py::class_<PyMlirContext>(m, "MlirContext")
|
||||
.def(py::init<>())
|
||||
.def("parse", &PyMlirContext::parse, py::keep_alive<0, 1>());
|
||||
|
||||
py::class_<PyMlirModule>(m, "MlirModule").def("dump", &PyMlirModule::dump);
|
||||
}
|
||||
Reference in New Issue
Block a user