CIRCT 22.0.0git
Loading...
Searching...
No Matches
SynthModule.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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 "CIRCTModules.h"
10
12
13#include "mlir-c/Support.h"
14#include "mlir/Bindings/Python/NanobindAdaptors.h"
15#include "mlir/CAPI/Wrap.h"
16
17#include "NanobindUtils.h"
18#include <nanobind/nanobind.h>
19#include <string_view>
20
21namespace nb = nanobind;
22
23using namespace circt;
24using namespace mlir::python::nanobind_adaptors;
25
26/// Populate the synth python module.
28 m.doc() = "Synth dialect Python native extension";
29
30 // LongestPathAnalysis class
31 nb::class_<SynthLongestPathAnalysis>(m, "_LongestPathAnalysis")
32 .def(
33 "__init__",
34 [](SynthLongestPathAnalysis *self, MlirOperation module,
35 bool collectDebugInfo, bool keepOnlyMaxDelayPaths,
36 bool lazyComputation, const std::string &topModuleName) {
37 new (self) SynthLongestPathAnalysis(synthLongestPathAnalysisCreate(
38 module, collectDebugInfo, keepOnlyMaxDelayPaths,
39 lazyComputation,
40 mlirStringRefCreateFromCString(topModuleName.c_str())));
41 },
42 nb::arg("module"), nb::arg("collect_debug_info") = false,
43 nb::arg("keep_only_max_delay_paths") = false,
44 nb::arg("lazy_computation") = false, nb::arg("top_module_name") = "")
45 .def("__del__",
46 [](SynthLongestPathAnalysis &self) {
48 })
49 .def("get_paths",
50 [](SynthLongestPathAnalysis *self, MlirValue value, int64_t bitPos,
51 bool elaboratePaths) -> SynthLongestPathCollection {
52 auto collection =
53 SynthLongestPathCollection(synthLongestPathAnalysisGetPaths(
54 *self, value, bitPos, elaboratePaths));
55
57 throw nb::value_error(
58 "Failed to get all paths, see previous error(s).");
59
60 return collection;
61 })
62 .def("get_internal_paths",
63 [](SynthLongestPathAnalysis *self, const std::string &moduleName,
64 bool elaboratePaths) -> SynthLongestPathCollection {
65 MlirStringRef moduleNameRef =
66 mlirStringRefCreateFromCString(moduleName.c_str());
67
68 auto collection = SynthLongestPathCollection(
70 elaboratePaths));
71
73 throw nb::value_error(
74 "Failed to get all paths, see previous error(s).");
75
76 return collection;
77 })
78 // Get external paths from module input ports to internal sequential
79 // elements.
80 .def("get_paths_from_input_ports_to_internal",
81 [](SynthLongestPathAnalysis *self,
82 const std::string &moduleName) -> SynthLongestPathCollection {
83 MlirStringRef moduleNameRef =
84 mlirStringRefCreateFromCString(moduleName.c_str());
85
86 auto collection = SynthLongestPathCollection(
88 *self, moduleNameRef));
89
91 throw nb::value_error(
92 "Failed to get paths from input ports to internal, see "
93 "previous error(s).");
94
95 return collection;
96 })
97 // Get external paths from internal sequential elements to module output
98 // ports.
99 .def("get_paths_from_internal_to_output_ports",
100 [](SynthLongestPathAnalysis *self,
101 const std::string &moduleName) -> SynthLongestPathCollection {
102 MlirStringRef moduleNameRef =
103 mlirStringRefCreateFromCString(moduleName.c_str());
104
105 auto collection = SynthLongestPathCollection(
107 *self, moduleNameRef));
108
109 if (synthLongestPathCollectionIsNull(collection))
110 throw nb::value_error(
111 "Failed to get paths from internal to output ports, see "
112 "previous error(s).");
113
114 return collection;
115 });
116
117 nb::class_<SynthLongestPathCollection>(m, "_LongestPathCollection")
118 .def("__del__",
119 [](SynthLongestPathCollection &self) {
121 })
122 .def("get_size",
123 [](SynthLongestPathCollection &self) {
125 })
126 .def("get_path",
127 [](SynthLongestPathCollection &self,
128 int pathIndex) -> SynthLongestPathDataflowPath {
129 return synthLongestPathCollectionGetDataflowPath(self, pathIndex);
130 })
131 .def("merge", [](SynthLongestPathCollection &self,
132 SynthLongestPathCollection &src) {
134 });
135
136 nb::class_<SynthLongestPathDataflowPath>(m, "_LongestPathDataflowPath")
137 .def_prop_ro("delay",
138 [](SynthLongestPathDataflowPath &self) {
140 })
141 .def_prop_ro("start_point",
142 [](SynthLongestPathDataflowPath &self) {
144 })
145 .def_prop_ro("end_point",
146 [](SynthLongestPathDataflowPath &self) {
148 })
149 .def_prop_ro("history",
150 [](SynthLongestPathDataflowPath &self) {
152 })
153 .def_prop_ro("root", [](SynthLongestPathDataflowPath &self) {
155 });
156
157 nb::class_<SynthLongestPathHistory>(m, "_LongestPathHistory")
158 .def_prop_ro("empty",
159 [](SynthLongestPathHistory &self) {
161 })
162 .def_prop_ro("head",
163 [](SynthLongestPathHistory &self) {
164 SynthLongestPathObject object;
165 int64_t delay;
166 MlirStringRef comment;
167 synthLongestPathHistoryGetHead(self, &object, &delay,
168 &comment);
169 return std::make_tuple(object, delay, comment);
170 })
171 .def_prop_ro("tail", [](SynthLongestPathHistory &self) {
173 });
174
175 nb::class_<SynthLongestPathObject>(m, "_LongestPathObject")
176 .def_prop_ro("instance_path",
177 [](SynthLongestPathObject &self) {
179 if (!path.ptr)
180 return std::vector<MlirOperation>();
181 size_t size = igraphInstancePathSize(path);
182 std::vector<MlirOperation> result;
183 for (size_t i = 0; i < size; ++i)
184 result.push_back(igraphInstancePathGet(path, i));
185 return result;
186 })
187 .def_prop_ro("name",
188 [](SynthLongestPathObject &self) {
189 return synthLongestPathObjectName(self);
190 })
191 .def_prop_ro("bit_pos", [](SynthLongestPathObject &self) {
192 return synthLongestPathObjectBitPos(self);
193 });
194}
MLIR_CAPI_EXPORTED MlirOperation synthLongestPathDataflowPathGetRoot(SynthLongestPathDataflowPath dataflowPath)
Definition Synth.cpp:241
MLIR_CAPI_EXPORTED bool synthLongestPathHistoryIsEmpty(SynthLongestPathHistory history)
Definition Synth.cpp:250
MLIR_CAPI_EXPORTED SynthLongestPathHistory synthLongestPathHistoryGetTail(SynthLongestPathHistory history)
Definition Synth.cpp:268
MLIR_CAPI_EXPORTED void synthLongestPathCollectionDestroy(SynthLongestPathCollection collection)
Definition Synth.cpp:180
MLIR_CAPI_EXPORTED void synthLongestPathHistoryGetHead(SynthLongestPathHistory history, SynthLongestPathObject *object, int64_t *delay, MlirStringRef *comment)
Definition Synth.cpp:255
MLIR_CAPI_EXPORTED size_t synthLongestPathCollectionGetSize(SynthLongestPathCollection collection)
Definition Synth.cpp:185
MLIR_CAPI_EXPORTED size_t synthLongestPathObjectBitPos(SynthLongestPathObject object)
Definition Synth.cpp:305
MLIR_CAPI_EXPORTED SynthLongestPathObject synthLongestPathDataflowPathGetStartPoint(SynthLongestPathDataflowPath dataflowPath)
Definition Synth.cpp:217
MLIR_CAPI_EXPORTED IgraphInstancePath synthLongestPathObjectGetInstancePath(SynthLongestPathObject object)
Definition Synth.cpp:280
MLIR_CAPI_EXPORTED SynthLongestPathObject synthLongestPathDataflowPathGetEndPoint(SynthLongestPathDataflowPath dataflowPath)
Definition Synth.cpp:224
MLIR_CAPI_EXPORTED SynthLongestPathCollection synthLongestPathAnalysisGetInternalPaths(SynthLongestPathAnalysis analysis, MlirStringRef moduleName, bool elaboratePaths)
Definition Synth.cpp:119
MLIR_CAPI_EXPORTED SynthLongestPathCollection synthLongestPathAnalysisGetPaths(SynthLongestPathAnalysis analysis, MlirValue value, int64_t bitPos, bool elaboratePaths)
Definition Synth.cpp:104
MLIR_CAPI_EXPORTED SynthLongestPathCollection synthLongestPathAnalysisGetPathsFromInternalToOutputPorts(SynthLongestPathAnalysis analysis, MlirStringRef moduleName)
Definition Synth.cpp:156
MLIR_CAPI_EXPORTED SynthLongestPathHistory synthLongestPathDataflowPathGetHistory(SynthLongestPathDataflowPath dataflowPath)
Definition Synth.cpp:234
MLIR_CAPI_EXPORTED bool synthLongestPathCollectionIsNull(SynthLongestPathCollection collection)
Definition Synth.cpp:176
MLIR_CAPI_EXPORTED SynthLongestPathDataflowPath synthLongestPathCollectionGetDataflowPath(SynthLongestPathCollection collection, size_t pathIndex)
Definition Synth.cpp:192
MLIR_CAPI_EXPORTED SynthLongestPathAnalysis synthLongestPathAnalysisCreate(MlirOperation module, bool collectDebugInfo, bool keepOnlyMaxDelayPaths, bool lazyComputation, MlirStringRef topModuleName)
Definition Synth.cpp:82
MLIR_CAPI_EXPORTED SynthLongestPathCollection synthLongestPathAnalysisGetPathsFromInputPortsToInternal(SynthLongestPathAnalysis analysis, MlirStringRef moduleName)
Definition Synth.cpp:138
MLIR_CAPI_EXPORTED void synthLongestPathCollectionMerge(SynthLongestPathCollection dest, SynthLongestPathCollection src)
Definition Synth.cpp:199
MLIR_CAPI_EXPORTED void synthLongestPathAnalysisDestroy(SynthLongestPathAnalysis analysis)
Definition Synth.cpp:99
MLIR_CAPI_EXPORTED MlirStringRef synthLongestPathObjectName(SynthLongestPathObject object)
Definition Synth.cpp:294
MLIR_CAPI_EXPORTED int64_t synthLongestPathDataflowPathGetDelay(SynthLongestPathDataflowPath dataflowPath)
Definition Synth.cpp:211
MLIR_CAPI_EXPORTED size_t igraphInstancePathSize(IgraphInstancePath path)
MLIR_CAPI_EXPORTED MlirOperation igraphInstancePathGet(IgraphInstancePath path, size_t index)
void populateDialectSynthSubmodule(nanobind::module_ &m)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.