13#include "mlir/Bindings/Python/NanobindAdaptors.h"
15#include <nanobind/nanobind.h>
20using namespace mlir::python::nanobind_adaptors;
24 m.doc() =
"RTG dialect Python native extension";
36 [](nb::object cls, std::vector<MlirType> &elementTypes,
39 elementTypes.data()));
41 nb::arg(
"self"), nb::arg(
"elementTypes") = std::vector<MlirType>(),
42 nb::arg(
"ctxt") =
nullptr)
43 .def_property_readonly(
46 .def(
"get_element", [](MlirType self,
unsigned i) {
53 [](nb::object cls, MlirContext ctxt) {
56 nb::arg(
"self"), nb::arg(
"ctxt") =
nullptr);
67 nb::arg(
"self"), nb::arg(
"element_type"))
68 .def_property_readonly(
"element_type", [](MlirType self) {
78 nb::arg(
"self"), nb::arg(
"element_type"))
79 .def_property_readonly(
"element_type", [](MlirType self) {
87 const std::vector<std::pair<MlirAttribute, MlirType>> &entries,
89 std::vector<MlirAttribute> names;
90 std::vector<MlirType> types;
91 for (
auto entry : entries) {
92 names.push_back(entry.first);
93 types.push_back(entry.second);
100 std::vector<std::pair<MlirAttribute, MlirType>>(),
101 nb::arg(
"ctxt") =
nullptr);
106 [](nb::object cls, MlirType
elementType, MlirContext ctxt) {
109 nb::arg(
"self"), nb::arg(
"element_type"), nb::arg(
"ctxt") =
nullptr)
110 .def_property_readonly(
"element_type", [](MlirType self) {
117 [](nb::object cls, MlirType keyType, MlirType valueType) {
120 nb::arg(
"self"), nb::arg(
"key_type"), nb::arg(
"value_type"))
121 .def_property_readonly(
123 .def_property_readonly(
"value_type", [](MlirType self) {
130 [](nb::object cls,
const std::vector<MlirType> &fieldTypes,
135 nb::arg(
"self"), nb::arg(
"field_types") = std::vector<MlirType>(),
136 nb::arg(
"ctxt") =
nullptr)
137 .def_property_readonly(
"fields", [](MlirType self) {
138 std::vector<MlirType> fields;
147 [](nb::object cls, MlirContext ctxt) {
150 nb::arg(
"self"), nb::arg(
"ctxt") =
nullptr);
158 [](nb::object cls, MlirContext ctxt) {
161 nb::arg(
"self"), nb::arg(
"ctxt") =
nullptr);
166 [](nb::object cls, uint32_t width, MlirContext ctx) {
169 nb::arg(
"self"), nb::arg(
"width"), nb::arg(
"ctx") =
nullptr)
170 .def_property_readonly(
"width", [](MlirType self) {
177 [](nb::object cls, uint32_t addressWidth, MlirContext ctxt) {
180 nb::arg(
"self"), nb::arg(
"address_width"), nb::arg(
"ctxt") =
nullptr)
181 .def_property_readonly(
"address_width", [](MlirType self) {
188 [](nb::object cls, uint32_t addressWidth, MlirContext ctxt) {
191 nb::arg(
"self"), nb::arg(
"address_width"), nb::arg(
"ctxt") =
nullptr)
192 .def_property_readonly(
"address_width", [](MlirType self) {
203 [](nb::object cls, MlirType type, MlirContext ctxt) {
206 nb::arg(
"self"), nb::arg(
"type"), nb::arg(
"ctxt") =
nullptr);
211 [](nb::object cls, MlirType type, MlirContext ctxt) {
214 nb::arg(
"self"), nb::arg(
"type"), nb::arg(
"ctxt") =
nullptr);
219 [](nb::object cls, MlirType mapType,
220 const std::vector<std::pair<MlirAttribute, MlirAttribute>>
223 std::vector<MlirAttribute> keys;
224 std::vector<MlirAttribute> values;
225 for (
auto entry : entries) {
226 keys.push_back(entry.first);
227 values.push_back(entry.second);
229 return cls(
rtgMapAttrGet(ctxt, mapType, keys.size(), keys.data(),
232 nb::arg(
"self"), nb::arg(
"map_type"),
234 std::vector<std::pair<MlirAttribute, MlirAttribute>>(),
235 nb::arg(
"ctxt") =
nullptr)
238 [](MlirAttribute self, MlirAttribute key) {
240 if (mlirAttributeIsNull(val))
242 return nb::cast(val);
245 "Look up the value associated with the given key. Returns None if "
246 "the key is not found.");
251 nb::enum_<RTGLabelVisibility>(m,
"LabelVisibility")
257 mlir_attribute_subclass(m,
"LabelVisibilityAttr",
264 nb::arg(
"self"), nb::arg(
"visibility"), nb::arg(
"ctxt") =
nullptr)
265 .def_property_readonly(
"value", [](MlirAttribute self) {
272 [](nb::object cls, uint32_t width, uint64_t value, MlirContext ctx) {
275 nb::arg(
"self"), nb::arg(
"width"), nb::arg(
"value"),
276 nb::arg(
"ctx") =
nullptr)
277 .def_property_readonly(
280 .def_property_readonly(
"value", [](MlirAttribute self) {
284 mlir_attribute_subclass(m,
"VirtualRegisterConfigAttr",
288 [](nb::object cls,
const std::vector<MlirAttribute> &allowedRegs,
291 allowedRegs.data()));
293 nb::arg(
"self"), nb::arg(
"allowed_regs"), nb::arg(
"ctxt") =
nullptr)
294 .def_property_readonly(
"regs", [](MlirAttribute self) {
295 std::vector<MlirAttribute> regs;
307 [](nb::object cls,
const std::string &name, MlirContext ctxt) {
308 MlirStringRef nameRef =
309 mlirStringRefCreate(name.data(), name.size());
312 nb::arg(
"self"), nb::arg(
"name"), nb::arg(
"ctxt") =
nullptr)
313 .def_property_readonly(
"name", [](MlirAttribute self) {
315 return nb::str(name.data, name.length);
MLIR_CAPI_EXPORTED MlirAttribute rtgAnyContextAttrGet(MlirContext ctxt, MlirType type)
Creates an RTG any context attribute in the context.
MLIR_CAPI_EXPORTED bool rtgTypeIsAMemory(MlirType type)
If the type is an RTG memory.
MLIR_CAPI_EXPORTED bool rtgAttrIsAAnyContextAttr(MlirAttribute attr)
If the attribute is an RTG any context attribute.
MLIR_CAPI_EXPORTED MlirType rtgLabelTypeGet(MlirContext ctxt)
Creates an RTG mode type in the context.
MLIR_CAPI_EXPORTED RTGLabelVisibility rtgLabelVisibilityAttrGetValue(MlirAttribute attr)
Get the RTG label visibility from the attribute.
MLIR_CAPI_EXPORTED MlirAttribute rtgVirtualRegisterConfigAttrGet(MlirContext ctxt, intptr_t numRegs, MlirAttribute const *allowedRegs)
Creates an RTG virtual register config attribute in the context.
MLIR_CAPI_EXPORTED uint32_t rtgImmediateAttrGetWidth(MlirAttribute attr)
Returns the width of the RTG immediate attribute.
@ RTG_LABEL_VISIBILITY_EXTERNAL
@ RTG_LABEL_VISIBILITY_GLOBAL
@ RTG_LABEL_VISIBILITY_LOCAL
MLIR_CAPI_EXPORTED MlirAttribute rtgVirtualRegisterConfigAttrGetRegister(MlirAttribute attr, intptr_t index)
Returns the allowed register at the given index in the RTG virtual register config attribute.
MLIR_CAPI_EXPORTED MlirType rtgSequenceTypeGetElement(MlirType type, unsigned i)
The type of of the substitution element at the given index.
MLIR_CAPI_EXPORTED MlirAttribute rtgDefaultContextAttrGet(MlirContext ctxt, MlirType type)
Creates an RTG default context attribute in the context.
MLIR_CAPI_EXPORTED MlirAttribute rtgMapAttrGet(MlirContext ctx, MlirType mapType, intptr_t numEntries, MlirAttribute const *keys, MlirAttribute const *values)
Creates an RTG map attribute in the context with the given entries.
MLIR_CAPI_EXPORTED MlirType rtgImmediateTypeGet(MlirContext ctx, uint32_t width)
Creates an RTG immediate type in the context.
MLIR_CAPI_EXPORTED uint32_t rtgMemoryTypeGetAddressWidth(MlirType type)
Returns the address with of an RTG memory type.
MLIR_CAPI_EXPORTED bool rtgTypeIsAArray(MlirType type)
If the type is an RTG array.
MLIR_CAPI_EXPORTED bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr)
If the attribute is an RTG label visibility.
MLIR_CAPI_EXPORTED bool rtgAttrIsALabel(MlirAttribute attr)
Checks if the attribute is an RTG label attribute.
MLIR_CAPI_EXPORTED intptr_t rtgTypeGetNumFields(MlirType type)
Returns the number of fields in the RTG tuple.
MLIR_CAPI_EXPORTED MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt, RTGLabelVisibility visibility)
Creates an RTG label visibility attribute in the context.
MLIR_CAPI_EXPORTED MlirAttribute rtgMapAttrLookup(MlirAttribute attr, MlirAttribute key)
Looks up the value associated with the given key in the RTG map attribute.
MLIR_CAPI_EXPORTED MlirType rtgMapTypeGet(MlirType keyType, MlirType valueType)
Creates an RTG map type in the context.
MLIR_CAPI_EXPORTED MlirType rtgArrayTypeGetElementType(MlirType type)
Returns the element type of the RTG array.
MLIR_CAPI_EXPORTED bool rtgTypeIsATuple(MlirType type)
If the type is an RTG tuple.
MLIR_CAPI_EXPORTED bool rtgTypeIsABag(MlirType type)
If the type is an RTG bag.
MLIR_CAPI_EXPORTED MlirType rtgSequenceTypeGet(MlirContext ctxt, intptr_t numElements, MlirType const *elementTypes)
Creates an RTG sequence type in the context.
MLIR_CAPI_EXPORTED MlirType rtgStringTypeGet(MlirContext ctxt)
Creates an RTG string type in the context.
MLIR_CAPI_EXPORTED MlirAttribute rtgImmediateAttrGet(MlirContext ctx, uint32_t width, uint64_t value)
Creates an RTG immediate attribute in the context with the given width and value.
MLIR_CAPI_EXPORTED unsigned rtgSequenceTypeGetNumElements(MlirType type)
The number of substitution elements of the RTG sequence.
MLIR_CAPI_EXPORTED MlirType rtgSetTypeGet(MlirType elementType)
Creates an RTG set type in the context.
MLIR_CAPI_EXPORTED bool rtgTypeIsASet(MlirType type)
If the type is an RTG set.
MLIR_CAPI_EXPORTED MlirType rtgTupleTypeGet(MlirContext ctxt, intptr_t numFields, MlirType const *fieldTypes)
Creates an RTG tuple type in the context.
MLIR_CAPI_EXPORTED MlirType rtgMemoryTypeGet(MlirContext ctx, uint32_t addressWidth)
Creates an RTG memory type in the context.
MLIR_CAPI_EXPORTED MlirType rtgRandomizedSequenceTypeGet(MlirContext ctxt)
Creates an RTG randomized sequence type in the context.
MLIR_CAPI_EXPORTED uint64_t rtgImmediateAttrGetValue(MlirAttribute attr)
Returns the value of the RTG immediate attribute.
MLIR_CAPI_EXPORTED bool rtgTypeIsAMemoryBlock(MlirType type)
If the type is an RTG memory block.
MLIR_CAPI_EXPORTED bool rtgAttrIsAImmediate(MlirAttribute attr)
Checks if the attribute is an RTG immediate attribute.
MLIR_CAPI_EXPORTED bool rtgTypeIsARandomizedSequence(MlirType type)
If the type is an RTG randomized sequence.
MLIR_CAPI_EXPORTED bool rtgTypeIsAMap(MlirType type)
If the type is an RTG map.
MLIR_CAPI_EXPORTED bool rtgTypeIsADict(MlirType type)
If the type is an RTG dict.
MLIR_CAPI_EXPORTED MlirType rtgTupleTypeGetFieldType(MlirType type, intptr_t idx)
Returns a field type of the RTG tuple.
MLIR_CAPI_EXPORTED MlirStringRef rtgLabelAttrGetName(MlirAttribute attr)
Returns the name of the RTG label attribute.
MLIR_CAPI_EXPORTED bool rtgAttrIsAVirtualRegisterConfig(MlirAttribute attr)
Checks if the attribute is an RTG virtual register config attribute.
MLIR_CAPI_EXPORTED bool rtgTypeIsAImmediate(MlirType type)
If the type is an RTG immediate.
MLIR_CAPI_EXPORTED MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries, MlirAttribute const *entryNames, MlirType const *entryTypes)
Creates an RTG dict type in the context.
MLIR_CAPI_EXPORTED bool rtgAttrIsAMap(MlirAttribute attr)
Checks if the attribute is an RTG map attribute.
MLIR_CAPI_EXPORTED intptr_t rtgVirtualRegisterConfigAttrGetNumRegisters(MlirAttribute attr)
Returns the number of allowed registers in the RTG virtual register config attribute.
MLIR_CAPI_EXPORTED MlirType rtgBagTypeGet(MlirType elementType)
Creates an RTG bag type in the context.
MLIR_CAPI_EXPORTED uint32_t rtgMemoryBlockTypeGetAddressWidth(MlirType type)
Returns the address with of an RTG memory block type.
MLIR_CAPI_EXPORTED MlirType rtgArrayTypeGet(MlirType elementType)
Creates an RTG array type in the context.
MLIR_CAPI_EXPORTED MlirType rtgBagTypeGetElementType(MlirType type)
Return the element type of the RTG bag.
MLIR_CAPI_EXPORTED bool rtgTypeIsAString(MlirType type)
If the type is an RTG string.
MLIR_CAPI_EXPORTED bool rtgTypeIsASequence(MlirType type)
If the type is an RTG sequence.
MLIR_CAPI_EXPORTED MlirAttribute rtgLabelAttrGet(MlirContext ctx, MlirStringRef name)
Creates an RTG label attribute in the context with the given name.
MLIR_CAPI_EXPORTED bool rtgTypeIsALabel(MlirType type)
If the type is an RTG label.
MLIR_CAPI_EXPORTED uint32_t rtgImmediateTypeGetWidth(MlirType type)
Returns the width of the RTG immediate type.
MLIR_CAPI_EXPORTED MlirType rtgMemoryBlockTypeGet(MlirContext ctx, uint32_t addressWidth)
Creates an RTG memory block type in the context.
MLIR_CAPI_EXPORTED MlirType rtgMapTypeGetKeyType(MlirType type)
Return the key type of the RTG map.
MLIR_CAPI_EXPORTED MlirType rtgSetTypeGetElementType(MlirType type)
Return the element type of the RTG set.
MLIR_CAPI_EXPORTED bool rtgAttrIsADefaultContextAttr(MlirAttribute attr)
If the attribute is an RTG default context.
MLIR_CAPI_EXPORTED MlirType rtgMapTypeGetValueType(MlirType type)
Return the value type of the RTG map.
void populateDialectRTGSubmodule(nanobind::module_ &m)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.