CIRCT 20.0.0git
Loading...
Searching...
No Matches
RTGModule.cpp
Go to the documentation of this file.
1//===- RTGModule.cpp - RTG 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/RTG.h"
12
13#include "mlir/Bindings/Python/NanobindAdaptors.h"
14
15#include <nanobind/nanobind.h>
16
17namespace nb = nanobind;
18
19using namespace circt;
20using namespace mlir::python::nanobind_adaptors;
21
22/// Populate the rtg python module.
24 m.doc() = "RTG dialect Python native extension";
25
26 mlir_type_subclass(m, "SequenceType", rtgTypeIsASequence)
27 .def_classmethod(
28 "get",
29 [](nb::object cls, std::vector<MlirType> &elementTypes,
30 MlirContext ctxt) {
31 return cls(rtgSequenceTypeGet(ctxt, elementTypes.size(),
32 elementTypes.data()));
33 },
34 nb::arg("self"), nb::arg("elementTypes") = std::vector<MlirType>(),
35 nb::arg("ctxt") = nullptr)
36 .def_property_readonly(
37 "num_elements",
38 [](MlirType self) { return rtgSequenceTypeGetNumElements(self); })
39 .def("get_element", [](MlirType self, unsigned i) {
40 return rtgSequenceTypeGetElement(self, i);
41 });
42
43 mlir_type_subclass(m, "RandomizedSequenceType", rtgTypeIsARandomizedSequence)
44 .def_classmethod(
45 "get",
46 [](nb::object cls, MlirContext ctxt) {
47 return cls(rtgRandomizedSequenceTypeGet(ctxt));
48 },
49 nb::arg("self"), nb::arg("ctxt") = nullptr);
50
51 mlir_type_subclass(m, "LabelType", rtgTypeIsALabel)
52 .def_classmethod(
53 "get",
54 [](nb::object cls, MlirContext ctxt) {
55 return cls(rtgLabelTypeGet(ctxt));
56 },
57 nb::arg("self"), nb::arg("ctxt") = nullptr);
58
59 mlir_type_subclass(m, "SetType", rtgTypeIsASet)
60 .def_classmethod(
61 "get",
62 [](nb::object cls, MlirType elementType) {
63 return cls(rtgSetTypeGet(elementType));
64 },
65 nb::arg("self"), nb::arg("element_type"));
66
67 mlir_type_subclass(m, "BagType", rtgTypeIsABag)
68 .def_classmethod(
69 "get",
70 [](nb::object cls, MlirType elementType) {
71 return cls(rtgBagTypeGet(elementType));
72 },
73 nb::arg("self"), nb::arg("element_type"));
74
75 mlir_type_subclass(m, "DictType", rtgTypeIsADict)
76 .def_classmethod(
77 "get",
78 [](nb::object cls, MlirContext ctxt,
79 const std::vector<std::pair<MlirAttribute, MlirType>> &entries) {
80 std::vector<MlirAttribute> names;
81 std::vector<MlirType> types;
82 for (auto entry : entries) {
83 names.push_back(entry.first);
84 types.push_back(entry.second);
85 }
86 return cls(
87 rtgDictTypeGet(ctxt, types.size(), names.data(), types.data()));
88 },
89 nb::arg("self"), nb::arg("ctxt") = nullptr,
90 nb::arg("entries") =
91 std::vector<std::pair<MlirAttribute, MlirType>>());
92
93 nb::enum_<RTGLabelVisibility>(m, "LabelVisibility")
94 .value("LOCAL", RTG_LABEL_VISIBILITY_LOCAL)
95 .value("GLOBAL", RTG_LABEL_VISIBILITY_GLOBAL)
96 .value("EXTERNAL", RTG_LABEL_VISIBILITY_EXTERNAL)
97 .export_values();
98
99 mlir_attribute_subclass(m, "LabelVisibilityAttr",
101 .def_classmethod(
102 "get",
103 [](nb::object cls, RTGLabelVisibility visibility, MlirContext ctxt) {
104 return cls(rtgLabelVisibilityAttrGet(ctxt, visibility));
105 },
106 nb::arg("self"), nb::arg("visibility"), nb::arg("ctxt") = nullptr)
107 .def_property_readonly("value", [](MlirAttribute self) {
109 });
110}
MlirType elementType
Definition CHIRRTL.cpp:29
MLIR_CAPI_EXPORTED MlirType rtgLabelTypeGet(MlirContext ctxt)
Creates an RTG mode type in the context.
Definition RTG.cpp:67
MLIR_CAPI_EXPORTED RTGLabelVisibility rtgLabelVisibilityAttrGetValue(MlirAttribute attr)
Get the RTG label visibility from the attribute.
Definition RTG.cpp:117
RTGLabelVisibility
Definition RTG.h:80
@ RTG_LABEL_VISIBILITY_EXTERNAL
Definition RTG.h:83
@ RTG_LABEL_VISIBILITY_GLOBAL
Definition RTG.h:82
@ RTG_LABEL_VISIBILITY_LOCAL
Definition RTG.h:81
MLIR_CAPI_EXPORTED MlirType rtgSequenceTypeGetElement(MlirType type, unsigned i)
The type of of the substitution element at the given index.
Definition RTG.cpp:47
MLIR_CAPI_EXPORTED bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr)
If the attribute is an RTG label visibility.
Definition RTG.cpp:113
MLIR_CAPI_EXPORTED MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt, RTGLabelVisibility visibility)
Creates an RTG label visibility attribute in the context.
Definition RTG.cpp:131
MLIR_CAPI_EXPORTED bool rtgTypeIsABag(MlirType type)
If the type is an RTG bag.
Definition RTG.cpp:84
MLIR_CAPI_EXPORTED MlirType rtgSequenceTypeGet(MlirContext ctxt, intptr_t numElements, MlirType const *elementTypes)
Creates an RTG sequence type in the context.
Definition RTG.cpp:35
MLIR_CAPI_EXPORTED unsigned rtgSequenceTypeGetNumElements(MlirType type)
The number of substitution elements of the RTG sequence.
Definition RTG.cpp:43
MLIR_CAPI_EXPORTED MlirType rtgSetTypeGet(MlirType elementType)
Creates an RTG set type in the context.
Definition RTG.cpp:76
MLIR_CAPI_EXPORTED bool rtgTypeIsASet(MlirType type)
If the type is an RTG set.
Definition RTG.cpp:74
MLIR_CAPI_EXPORTED MlirType rtgRandomizedSequenceTypeGet(MlirContext ctxt)
Creates an RTG randomized sequence type in the context.
Definition RTG.cpp:58
MLIR_CAPI_EXPORTED bool rtgTypeIsARandomizedSequence(MlirType type)
If the type is an RTG randomized sequence.
Definition RTG.cpp:54
MLIR_CAPI_EXPORTED bool rtgTypeIsADict(MlirType type)
If the type is an RTG dict.
Definition RTG.cpp:94
MLIR_CAPI_EXPORTED MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries, MlirAttribute const *entryNames, MlirType const *entryTypes)
Creates an RTG dict type in the context.
Definition RTG.cpp:96
MLIR_CAPI_EXPORTED MlirType rtgBagTypeGet(MlirType elementType)
Creates an RTG bag type in the context.
Definition RTG.cpp:86
MLIR_CAPI_EXPORTED bool rtgTypeIsASequence(MlirType type)
If the type is an RTG sequence.
Definition RTG.cpp:31
MLIR_CAPI_EXPORTED bool rtgTypeIsALabel(MlirType type)
If the type is an RTG label.
Definition RTG.cpp:65
void populateDialectRTGSubmodule(nanobind::module_ &m)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.