CIRCT 23.0.0git
Loading...
Searching...
No Matches
SeqModule.cpp
Go to the documentation of this file.
1//===- SeqModule.cpp - Seq API nanobind module ----------------------------===//
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
11#include "circt-c/Dialect/Seq.h"
12#include "mlir/Bindings/Python/NanobindAdaptors.h"
13
14#include "NanobindUtils.h"
15#include "mlir-c/Support.h"
16#include <nanobind/nanobind.h>
17
18namespace nb = nanobind;
19
20using namespace circt;
21using namespace mlir::python::nanobind_adaptors;
22
23/// Populate the seq python module.
25 m.doc() = "Seq dialect Python native extension";
26
27 mlir_type_subclass(m, "ClockType", seqTypeIsAClock)
28 .def_classmethod(
29 "get",
30 [](nb::object cls, MlirContext ctx) {
31 return cls(seqClockTypeGet(ctx));
32 },
33 nb::arg("cls"), nb::arg("context") = nb::none());
34
35 mlir_type_subclass(m, "ImmutableType", seqTypeIsAImmutable)
36 .def_classmethod("get",
37 [](nb::object cls, MlirType innerType) {
38 return cls(seqImmutableTypeGet(innerType));
39 })
40 .def_property_readonly("inner_type", [](MlirType self) {
42 });
43
44 mlir_type_subclass(m, "HLMemType", seqTypeIsAHLMem)
45 .def_classmethod(
46 "get",
47 [](nb::object cls, std::vector<int64_t> shape, MlirType elementType,
48 MlirContext ctx) {
49 return cls(
50 seqHLMemTypeGet(ctx, shape.size(), shape.data(), elementType));
51 },
52 nb::arg("cls"), nb::arg("shape"), nb::arg("element_type"),
53 nb::arg("context") = nb::none())
54 .def_property_readonly(
55 "element_type",
56 [](MlirType self) { return seqHLMemTypeGetElementType(self); })
57 .def_property_readonly(
58 "rank", [](MlirType self) { return seqHLMemTypeGetRank(self); })
59 .def_property_readonly("shape", [](MlirType self) {
60 intptr_t rank = seqHLMemTypeGetRank(self);
61 const int64_t *shapePtr = seqHLMemTypeGetShape(self);
62 nb::list result;
63 for (intptr_t i = 0; i < rank; ++i)
64 result.append(shapePtr[i]);
65 return result;
66 });
67
68 mlir_type_subclass(m, "FirMemType", seqTypeIsAFirMem)
69 .def_classmethod(
70 "get",
71 [](nb::object cls, uint64_t depth, uint32_t width,
72 std::optional<uint32_t> maskWidth, MlirContext ctx) {
73 const uint32_t *maskPtr = nullptr;
74 uint32_t maskVal = 0;
75 if (maskWidth.has_value()) {
76 maskVal = maskWidth.value();
77 maskPtr = &maskVal;
78 }
79 return cls(seqFirMemTypeGet(ctx, depth, width, maskPtr));
80 },
81 nb::arg("cls"), nb::arg("depth"), nb::arg("width"),
82 nb::arg("mask_width") = nb::none(), nb::arg("context") = nb::none())
83 .def_property_readonly(
84 "depth", [](MlirType self) { return seqFirMemTypeGetDepth(self); })
85 .def_property_readonly(
86 "width", [](MlirType self) { return seqFirMemTypeGetWidth(self); })
87 .def_property_readonly("mask_width", [](MlirType self) -> nb::object {
88 if (seqFirMemTypeHasMask(self))
89 return nb::cast(seqFirMemTypeGetMaskWidth(self));
90 return nb::none();
91 });
92}
MlirType elementType
Definition CHIRRTL.cpp:29
MLIR_CAPI_EXPORTED bool seqTypeIsAClock(MlirType type)
If the type is an clock type.
Definition Seq.cpp:24
MLIR_CAPI_EXPORTED MlirType seqImmutableTypeGetInnerType(MlirType type)
Creates a seq immutable type.
Definition Seq.cpp:40
MLIR_CAPI_EXPORTED bool seqTypeIsAFirMem(MlirType type)
If the type is a FirMem type.
Definition Seq.cpp:66
MLIR_CAPI_EXPORTED uint64_t seqFirMemTypeGetDepth(MlirType type)
Gets the depth of a FirMem type.
Definition Seq.cpp:78
MLIR_CAPI_EXPORTED MlirType seqImmutableTypeGet(MlirType type)
Creates a seq immutable type.
Definition Seq.cpp:36
MLIR_CAPI_EXPORTED uint32_t seqFirMemTypeGetWidth(MlirType type)
Gets the width of a FirMem type.
Definition Seq.cpp:82
MLIR_CAPI_EXPORTED MlirType seqFirMemTypeGet(MlirContext ctx, uint64_t depth, uint32_t width, const uint32_t *maskWidth)
Creates a seq FirMem type.
Definition Seq.cpp:70
MLIR_CAPI_EXPORTED MlirType seqHLMemTypeGetElementType(MlirType type)
Gets the element type of an HLMem type.
Definition Seq.cpp:54
MLIR_CAPI_EXPORTED bool seqTypeIsAImmutable(MlirType type)
If the type is an immutable type.
Definition Seq.cpp:32
MLIR_CAPI_EXPORTED intptr_t seqHLMemTypeGetRank(MlirType type)
Gets the rank of an HLMem type.
Definition Seq.cpp:58
MLIR_CAPI_EXPORTED bool seqTypeIsAHLMem(MlirType type)
If the type is a HLMemType.
Definition Seq.cpp:44
MLIR_CAPI_EXPORTED bool seqFirMemTypeHasMask(MlirType type)
Returns true if the FirMem type has a mask width defined.
Definition Seq.cpp:86
MLIR_CAPI_EXPORTED MlirType seqHLMemTypeGet(MlirContext ctx, intptr_t rank, const int64_t *shape, MlirType elementType)
Creates a seq HLMem type.
Definition Seq.cpp:48
MLIR_CAPI_EXPORTED MlirType seqClockTypeGet(MlirContext ctx)
Creates an seq clock type.
Definition Seq.cpp:28
MLIR_CAPI_EXPORTED const int64_t * seqHLMemTypeGetShape(MlirType type)
Gets a pointer to the shape array of an HLMem type The array length is equal to the rank.
Definition Seq.cpp:62
MLIR_CAPI_EXPORTED uint32_t seqFirMemTypeGetMaskWidth(MlirType type)
Gets the mask width of a FirMem type Behavior is undefined if seqFirMemTypeHasMask returns false.
Definition Seq.cpp:90
void populateDialectSeqSubmodule(nanobind::module_ &m)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.