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) {
37 new (self) SynthLongestPathAnalysis(synthLongestPathAnalysisCreate(
38 module, collectDebugInfo, keepOnlyMaxDelayPaths,
39 lazyComputation));
40 },
41 nb::arg("module"), nb::arg("collect_debug_info") = false,
42 nb::arg("keep_only_max_delay_paths") = false,
43 nb::arg("lazy_computation") = false)
44 .def("__del__",
45 [](SynthLongestPathAnalysis &self) {
47 })
48 .def("get_paths",
49 [](SynthLongestPathAnalysis *self, MlirValue value, int64_t bitPos,
50 bool elaboratePaths) -> SynthLongestPathCollection {
51 auto collection =
52 SynthLongestPathCollection(synthLongestPathAnalysisGetPaths(
53 *self, value, bitPos, elaboratePaths));
54
56 throw nb::value_error(
57 "Failed to get all paths, see previous error(s).");
58
59 return collection;
60 })
61 .def("get_all_paths",
62 [](SynthLongestPathAnalysis *self, const std::string &moduleName,
63 bool elaboratePaths) -> SynthLongestPathCollection {
64 MlirStringRef moduleNameRef =
65 mlirStringRefCreateFromCString(moduleName.c_str());
66
67 auto collection =
68 SynthLongestPathCollection(synthLongestPathAnalysisGetAllPaths(
69 *self, moduleNameRef, elaboratePaths));
70
72 throw nb::value_error(
73 "Failed to get all paths, see previous error(s).");
74
75 return collection;
76 });
77
78 nb::class_<SynthLongestPathCollection>(m, "_LongestPathCollection")
79 .def("__del__",
80 [](SynthLongestPathCollection &self) {
82 })
83 .def("get_size",
84 [](SynthLongestPathCollection &self) {
86 })
87 .def("get_path",
88 [](SynthLongestPathCollection &self,
89 int pathIndex) -> SynthLongestPathDataflowPath {
90 return synthLongestPathCollectionGetDataflowPath(self, pathIndex);
91 })
92 .def("merge", [](SynthLongestPathCollection &self,
93 SynthLongestPathCollection &src) {
95 });
96
97 nb::class_<SynthLongestPathDataflowPath>(m, "_LongestPathDataflowPath")
98 .def_prop_ro("delay",
99 [](SynthLongestPathDataflowPath &self) {
101 })
102 .def_prop_ro("start_point",
103 [](SynthLongestPathDataflowPath &self) {
105 })
106 .def_prop_ro("end_point",
107 [](SynthLongestPathDataflowPath &self) {
109 })
110 .def_prop_ro("history",
111 [](SynthLongestPathDataflowPath &self) {
113 })
114 .def_prop_ro("root", [](SynthLongestPathDataflowPath &self) {
116 });
117
118 nb::class_<SynthLongestPathHistory>(m, "_LongestPathHistory")
119 .def_prop_ro("empty",
120 [](SynthLongestPathHistory &self) {
122 })
123 .def_prop_ro("head",
124 [](SynthLongestPathHistory &self) {
125 SynthLongestPathObject object;
126 int64_t delay;
127 MlirStringRef comment;
128 synthLongestPathHistoryGetHead(self, &object, &delay,
129 &comment);
130 return std::make_tuple(object, delay, comment);
131 })
132 .def_prop_ro("tail", [](SynthLongestPathHistory &self) {
134 });
135
136 nb::class_<SynthLongestPathObject>(m, "_LongestPathObject")
137 .def_prop_ro("instance_path",
138 [](SynthLongestPathObject &self) {
140 if (!path.ptr)
141 return std::vector<MlirOperation>();
142 size_t size = igraphInstancePathSize(path);
143 std::vector<MlirOperation> result;
144 for (size_t i = 0; i < size; ++i)
145 result.push_back(igraphInstancePathGet(path, i));
146 return result;
147 })
148 .def_prop_ro("name",
149 [](SynthLongestPathObject &self) {
150 return synthLongestPathObjectName(self);
151 })
152 .def_prop_ro("bit_pos", [](SynthLongestPathObject &self) {
153 return synthLongestPathObjectBitPos(self);
154 });
155}
MLIR_CAPI_EXPORTED MlirOperation synthLongestPathDataflowPathGetRoot(SynthLongestPathDataflowPath dataflowPath)
Definition Synth.cpp:203
MLIR_CAPI_EXPORTED bool synthLongestPathHistoryIsEmpty(SynthLongestPathHistory history)
Definition Synth.cpp:212
MLIR_CAPI_EXPORTED SynthLongestPathHistory synthLongestPathHistoryGetTail(SynthLongestPathHistory history)
Definition Synth.cpp:230
MLIR_CAPI_EXPORTED void synthLongestPathCollectionDestroy(SynthLongestPathCollection collection)
Definition Synth.cpp:142
MLIR_CAPI_EXPORTED void synthLongestPathHistoryGetHead(SynthLongestPathHistory history, SynthLongestPathObject *object, int64_t *delay, MlirStringRef *comment)
Definition Synth.cpp:217
MLIR_CAPI_EXPORTED size_t synthLongestPathCollectionGetSize(SynthLongestPathCollection collection)
Definition Synth.cpp:147
MLIR_CAPI_EXPORTED size_t synthLongestPathObjectBitPos(SynthLongestPathObject object)
Definition Synth.cpp:267
MLIR_CAPI_EXPORTED SynthLongestPathObject synthLongestPathDataflowPathGetStartPoint(SynthLongestPathDataflowPath dataflowPath)
Definition Synth.cpp:179
MLIR_CAPI_EXPORTED IgraphInstancePath synthLongestPathObjectGetInstancePath(SynthLongestPathObject object)
Definition Synth.cpp:242
MLIR_CAPI_EXPORTED SynthLongestPathAnalysis synthLongestPathAnalysisCreate(MlirOperation module, bool collectDebugInfo, bool keepOnlyMaxDelayPaths, bool lazyComputation)
Definition Synth.cpp:82
MLIR_CAPI_EXPORTED SynthLongestPathObject synthLongestPathDataflowPathGetEndPoint(SynthLongestPathDataflowPath dataflowPath)
Definition Synth.cpp:186
MLIR_CAPI_EXPORTED SynthLongestPathCollection synthLongestPathAnalysisGetPaths(SynthLongestPathAnalysis analysis, MlirValue value, int64_t bitPos, bool elaboratePaths)
Definition Synth.cpp:102
MLIR_CAPI_EXPORTED SynthLongestPathHistory synthLongestPathDataflowPathGetHistory(SynthLongestPathDataflowPath dataflowPath)
Definition Synth.cpp:196
MLIR_CAPI_EXPORTED bool synthLongestPathCollectionIsNull(SynthLongestPathCollection collection)
Definition Synth.cpp:138
MLIR_CAPI_EXPORTED SynthLongestPathDataflowPath synthLongestPathCollectionGetDataflowPath(SynthLongestPathCollection collection, size_t pathIndex)
Definition Synth.cpp:154
MLIR_CAPI_EXPORTED SynthLongestPathCollection synthLongestPathAnalysisGetAllPaths(SynthLongestPathAnalysis analysis, MlirStringRef moduleName, bool elaboratePaths)
Definition Synth.cpp:117
MLIR_CAPI_EXPORTED void synthLongestPathCollectionMerge(SynthLongestPathCollection dest, SynthLongestPathCollection src)
Definition Synth.cpp:161
MLIR_CAPI_EXPORTED void synthLongestPathAnalysisDestroy(SynthLongestPathAnalysis analysis)
Definition Synth.cpp:97
MLIR_CAPI_EXPORTED MlirStringRef synthLongestPathObjectName(SynthLongestPathObject object)
Definition Synth.cpp:256
MLIR_CAPI_EXPORTED int64_t synthLongestPathDataflowPathGetDelay(SynthLongestPathDataflowPath dataflowPath)
Definition Synth.cpp:173
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.