-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python module for Support library, including backedge helpers.
- Loading branch information
1 parent
151ef53
commit 1b9fc38
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//===- SupportModule.cpp - Support API 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 "SupportModule.h" | ||
|
||
#include "circt/Support/BackedgeBuilder.h" | ||
#include "circt/Support/LLVM.h" | ||
|
||
#include "mlir-c/IR.h" | ||
#include "mlir/CAPI/IR.h" | ||
#include "mlir/IR/Builders.h" | ||
#include "mlir/IR/Dialect.h" | ||
|
||
#include "PybindUtils.h" | ||
#include "pybind11/pybind11.h" | ||
namespace py = pybind11; | ||
|
||
using namespace circt; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Classes that translate from something Pybind11 understands to MLIR C++. | ||
//===----------------------------------------------------------------------===// | ||
|
||
namespace { | ||
|
||
class PyBackedge { | ||
public: | ||
PyBackedge(Backedge backedge) : backedge(backedge) {} | ||
|
||
MlirValue value() { return wrap(backedge); } | ||
|
||
void setValue(MlirValue newValue) { backedge.setValue(unwrap(newValue)); } | ||
|
||
private: | ||
Backedge backedge; | ||
}; | ||
|
||
class PyBackedgeBuilder { | ||
public: | ||
PyBackedgeBuilder(MlirLocation loc) | ||
: builder(OpBuilder(unwrap(mlirLocationGetContext(loc)))), | ||
backedgeBuilder(BackedgeBuilder(builder, unwrap(loc))) {} | ||
|
||
PyBackedge get(MlirType type) { | ||
return PyBackedge(backedgeBuilder.get(unwrap(type))); | ||
} | ||
|
||
private: | ||
OpBuilder builder; | ||
BackedgeBuilder backedgeBuilder; | ||
}; | ||
|
||
} // namespace | ||
|
||
void circt::python::populateSupportSubmodule(py::module &m) { | ||
py::class_<PyBackedge>(m, "Backedge") | ||
.def(py::init<Backedge>()) | ||
.def("set_value", &PyBackedge::setValue, "Set the backedge value.") | ||
.def_property_readonly("value", &PyBackedge::value, | ||
"Get the value from the backedge."); | ||
py::class_<PyBackedgeBuilder>(m, "BackedgeBuilder") | ||
.def(py::init<MlirLocation>()) | ||
.def("get", &PyBackedgeBuilder::get, "Get a backedge builder."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===- SupportModule.h - Support API submodule ----------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CIRCT_BINDINGS_PYTHON_SUPPORTMODULE_H | ||
#define CIRCT_BINDINGS_PYTHON_SUPPORTMODULE_H | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace circt { | ||
namespace python { | ||
|
||
void populateSupportSubmodule(pybind11::module &m); | ||
|
||
} // namespace python | ||
} // namespace circt | ||
|
||
#endif // CIRCT_BINDINGS_PYTHON_SUPPORTMODULE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 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 | ||
|
||
from _circt._support import * |