Loading [MathJax]/extensions/tex2jax.js
CIRCT 22.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RTG.cpp
Go to the documentation of this file.
1//===- RTG.cpp - C interface for the RTG dialect --------------------------===//
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
15
16#include "mlir/CAPI/Registration.h"
17
18using namespace circt;
19using namespace circt::rtg;
20
21//===----------------------------------------------------------------------===//
22// Dialect API.
23//===----------------------------------------------------------------------===//
24
26
28 circt::rtg::registerPasses();
30}
31
32//===----------------------------------------------------------------------===//
33// Type API.
34//===----------------------------------------------------------------------===//
35
36// SequenceType
37//===----------------------------------------------------------------------===//
38
39bool rtgTypeIsASequence(MlirType type) {
40 return isa<SequenceType>(unwrap(type));
41}
42
43MlirType rtgSequenceTypeGet(MlirContext ctxt, intptr_t numElements,
44 MlirType const *elementTypes) {
45 SmallVector<Type> types;
46 for (unsigned i = 0; i < numElements; ++i)
47 types.emplace_back(unwrap(elementTypes[i]));
48 return wrap(SequenceType::get(unwrap(ctxt), types));
49}
50
51unsigned rtgSequenceTypeGetNumElements(MlirType type) {
52 return cast<SequenceType>(unwrap(type)).getElementTypes().size();
53}
54
55MlirType rtgSequenceTypeGetElement(MlirType type, unsigned i) {
56 return wrap(cast<SequenceType>(unwrap(type)).getElementTypes()[i]);
57}
58
59// RandomizedSequenceType
60//===----------------------------------------------------------------------===//
61
62bool rtgTypeIsARandomizedSequence(MlirType type) {
63 return isa<RandomizedSequenceType>(unwrap(type));
64}
65
66MlirType rtgRandomizedSequenceTypeGet(MlirContext ctxt) {
67 return wrap(RandomizedSequenceType::get(unwrap(ctxt)));
68}
69
70// LabelType
71//===----------------------------------------------------------------------===//
72
73bool rtgTypeIsALabel(MlirType type) { return isa<LabelType>(unwrap(type)); }
74
75MlirType rtgLabelTypeGet(MlirContext ctxt) {
76 return wrap(LabelType::get(unwrap(ctxt)));
77}
78
79// SetType
80//===----------------------------------------------------------------------===//
81
82bool rtgTypeIsASet(MlirType type) { return isa<SetType>(unwrap(type)); }
83
84MlirType rtgSetTypeGet(MlirType elementType) {
85 auto ty = unwrap(elementType);
86 return wrap(SetType::get(ty.getContext(), ty));
87}
88
89MlirType rtgSetTypeGetElementType(MlirType type) {
90 return wrap(cast<SetType>(unwrap(type)).getElementType());
91}
92
93// BagType
94//===----------------------------------------------------------------------===//
95
96bool rtgTypeIsABag(MlirType type) { return isa<BagType>(unwrap(type)); }
97
98MlirType rtgBagTypeGet(MlirType elementType) {
99 auto ty = unwrap(elementType);
100 return wrap(BagType::get(ty.getContext(), ty));
101}
102
103MlirType rtgBagTypeGetElementType(MlirType type) {
104 return wrap(cast<BagType>(unwrap(type)).getElementType());
105}
106
107// DictType
108//===----------------------------------------------------------------------===//
109
110bool rtgTypeIsADict(MlirType type) { return isa<DictType>(unwrap(type)); }
111
112MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries,
113 MlirAttribute const *entryNames,
114 MlirType const *entryTypes) {
115 SmallVector<DictEntry> entries;
116 for (unsigned i = 0; i < numEntries; ++i) {
117 DictEntry entry;
118 entry.name = cast<StringAttr>(unwrap(entryNames[i]));
119 entry.type = unwrap(entryTypes[i]);
120 entries.emplace_back(entry);
121 }
122 return wrap(DictType::get(unwrap(ctxt), entries));
123}
124
125// ArrayType
126//===----------------------------------------------------------------------===//
127
128MlirType rtgArrayTypeGet(MlirType elementType) {
129 return wrap(
130 ArrayType::get(unwrap(elementType).getContext(), unwrap(elementType)));
131}
132
133bool rtgTypeIsAArray(MlirType type) { return isa<ArrayType>(unwrap(type)); }
134
135MlirType rtgArrayTypeGetElementType(MlirType type) {
136 return wrap(cast<ArrayType>(unwrap(type)).getElementType());
137}
138
139// TupleType
140//===----------------------------------------------------------------------===//
141
142MlirType rtgTupleTypeGet(MlirContext ctxt, intptr_t numFields,
143 MlirType const *fieldTypes) {
144 SmallVector<Type> types;
145 for (unsigned i = 0; i < numFields; ++i)
146 types.emplace_back(unwrap(fieldTypes[i]));
147 return wrap(rtg::TupleType::get(unwrap(ctxt), types));
148}
149
150bool rtgTypeIsATuple(MlirType type) {
151 return isa<rtg::TupleType>(unwrap(type));
152}
153
154intptr_t rtgTypeGetNumFields(MlirType type) {
155 return cast<rtg::TupleType>(unwrap(type)).getFieldTypes().size();
156}
157
158MlirType rtgTupleTypeGetFieldType(MlirType type, intptr_t idx) {
159 return wrap(cast<rtg::TupleType>(unwrap(type)).getFieldTypes()[idx]);
160}
161
162// ImmediateType
163//===----------------------------------------------------------------------===//
164
165bool rtgTypeIsAImmediate(MlirType type) {
166 return isa<ImmediateType>(unwrap(type));
167}
168
169MlirType rtgImmediateTypeGet(MlirContext ctx, uint32_t width) {
170 return wrap(ImmediateType::get(unwrap(ctx), width));
171}
172
173uint32_t rtgImmediateTypeGetWidth(MlirType type) {
174 return cast<ImmediateType>(unwrap(type)).getWidth();
175}
176
177// MemoryType
178//===----------------------------------------------------------------------===//
179
180bool rtgTypeIsAMemory(MlirType type) { return isa<MemoryType>(unwrap(type)); }
181
182MlirType rtgMemoryTypeGet(MlirContext ctxt, uint32_t addressWidth) {
183 return wrap(MemoryType::get(unwrap(ctxt), addressWidth));
184}
185
186uint32_t rtgMemoryTypeGetAddressWidth(MlirType type) {
187 return cast<MemoryType>(unwrap(type)).getAddressWidth();
188}
189
190// MemoryBlockType
191//===----------------------------------------------------------------------===//
192
193bool rtgTypeIsAMemoryBlock(MlirType type) {
194 return isa<MemoryBlockType>(unwrap(type));
195}
196
197MlirType rtgMemoryBlockTypeGet(MlirContext ctxt, uint32_t addressWidth) {
198 return wrap(MemoryBlockType::get(unwrap(ctxt), addressWidth));
199}
200
201uint32_t rtgMemoryBlockTypeGetAddressWidth(MlirType type) {
202 return cast<MemoryBlockType>(unwrap(type)).getAddressWidth();
203}
204
205//===----------------------------------------------------------------------===//
206// Attribute API.
207//===----------------------------------------------------------------------===//
208
209// DefaultContext
210//===----------------------------------------------------------------------===//
211
212bool rtgAttrIsADefaultContextAttr(MlirAttribute attr) {
213 return isa<DefaultContextAttr>(unwrap(attr));
214}
215
216MlirAttribute rtgDefaultContextAttrGet(MlirContext ctxt, MlirType type) {
217 return wrap(DefaultContextAttr::get(unwrap(ctxt), unwrap(type)));
218}
219
220// Label Visibility
221//===----------------------------------------------------------------------===//
222
223bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr) {
224 return isa<LabelVisibilityAttr>(unwrap(attr));
225}
226
228 auto convert = [](LabelVisibility visibility) {
229 switch (visibility) {
230 case LabelVisibility::local:
232 case LabelVisibility::global:
234 case LabelVisibility::external:
236 }
237 };
238 return convert(cast<LabelVisibilityAttr>(unwrap(attr)).getValue());
239}
240
241MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt,
242 RTGLabelVisibility visibility) {
243 auto convert = [](RTGLabelVisibility visibility) {
244 switch (visibility) {
246 return LabelVisibility::local;
248 return LabelVisibility::global;
250 return LabelVisibility::external;
251 }
252 };
253 return wrap(LabelVisibilityAttr::get(unwrap(ctxt), convert(visibility)));
254}
255
256// ImmediateAttr
257//===----------------------------------------------------------------------===//
258
259bool rtgAttrIsAImmediate(MlirAttribute attr) {
260 return isa<ImmediateAttr>(unwrap(attr));
261}
262
263MlirAttribute rtgImmediateAttrGet(MlirContext ctx, uint32_t width,
264 uint64_t value) {
265 return wrap(rtg::ImmediateAttr::get(unwrap(ctx), APInt(width, value)));
266}
267
268uint32_t rtgImmediateAttrGetWidth(MlirAttribute attr) {
269 return cast<ImmediateAttr>(unwrap(attr)).getValue().getBitWidth();
270}
271
272uint64_t rtgImmediateAttrGetValue(MlirAttribute attr) {
273 return cast<ImmediateAttr>(unwrap(attr)).getValue().getZExtValue();
274}
275
276// AnyContexts
277//===----------------------------------------------------------------------===//
278
279bool rtgAttrIsAAnyContextAttr(MlirAttribute attr) {
280 return isa<AnyContextAttr>(unwrap(attr));
281}
282
283MlirAttribute rtgAnyContextAttrGet(MlirContext ctxt, MlirType type) {
284 return wrap(AnyContextAttr::get(unwrap(ctxt), unwrap(type)));
285}
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
MlirType uint64_t numElements
Definition CHIRRTL.cpp:30
MlirType elementType
Definition CHIRRTL.cpp:29
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CHIRRTL, chirrtl, circt::chirrtl::CHIRRTLDialect) MlirType chirrtlTypeGetCMemory(MlirContext ctx
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition OM.cpp:111
bool rtgTypeIsABag(MlirType type)
If the type is an RTG bag.
Definition RTG.cpp:96
void registerRTGPasses()
Definition RTG.cpp:27
MlirAttribute rtgAnyContextAttrGet(MlirContext ctxt, MlirType type)
Creates an RTG any context attribute in the context.
Definition RTG.cpp:283
bool rtgAttrIsAAnyContextAttr(MlirAttribute attr)
If the attribute is an RTG any context attribute.
Definition RTG.cpp:279
MlirType rtgSequenceTypeGetElement(MlirType type, unsigned i)
The type of of the substitution element at the given index.
Definition RTG.cpp:55
MlirType rtgArrayTypeGet(MlirType elementType)
Creates an RTG array type in the context.
Definition RTG.cpp:128
intptr_t rtgTypeGetNumFields(MlirType type)
Returns the number of fields in the RTG tuple.
Definition RTG.cpp:154
bool rtgTypeIsARandomizedSequence(MlirType type)
If the type is an RTG randomized sequence.
Definition RTG.cpp:62
RTGLabelVisibility rtgLabelVisibilityAttrGetValue(MlirAttribute attr)
Get the RTG label visibility from the attribute.
Definition RTG.cpp:227
MlirType rtgSetTypeGet(MlirType elementType)
Creates an RTG set type in the context.
Definition RTG.cpp:84
MlirType rtgArrayTypeGetElementType(MlirType type)
Returns the element type of the RTG array.
Definition RTG.cpp:135
MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt, RTGLabelVisibility visibility)
Creates an RTG label visibility attribute in the context.
Definition RTG.cpp:241
bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr)
If the attribute is an RTG label visibility.
Definition RTG.cpp:223
uint32_t rtgMemoryBlockTypeGetAddressWidth(MlirType type)
Returns the address with of an RTG memory block type.
Definition RTG.cpp:201
MlirType rtgImmediateTypeGet(MlirContext ctx, uint32_t width)
Creates an RTG immediate type in the context.
Definition RTG.cpp:169
bool rtgAttrIsAImmediate(MlirAttribute attr)
Checks if the attribute is an RTG immediate attribute.
Definition RTG.cpp:259
MlirType rtgSequenceTypeGet(MlirContext ctxt, intptr_t numElements, MlirType const *elementTypes)
Creates an RTG sequence type in the context.
Definition RTG.cpp:43
uint32_t rtgImmediateAttrGetWidth(MlirAttribute attr)
Returns the width of the RTG immediate attribute.
Definition RTG.cpp:268
bool rtgTypeIsAArray(MlirType type)
If the type is an RTG array.
Definition RTG.cpp:133
MlirType rtgMemoryTypeGet(MlirContext ctxt, uint32_t addressWidth)
Creates an RTG memory type in the context.
Definition RTG.cpp:182
bool rtgTypeIsASet(MlirType type)
If the type is an RTG set.
Definition RTG.cpp:82
bool rtgTypeIsAMemory(MlirType type)
If the type is an RTG memory.
Definition RTG.cpp:180
bool rtgTypeIsADict(MlirType type)
If the type is an RTG dict.
Definition RTG.cpp:110
unsigned rtgSequenceTypeGetNumElements(MlirType type)
The number of substitution elements of the RTG sequence.
Definition RTG.cpp:51
MlirType rtgRandomizedSequenceTypeGet(MlirContext ctxt)
Creates an RTG randomized sequence type in the context.
Definition RTG.cpp:66
bool rtgTypeIsALabel(MlirType type)
If the type is an RTG label.
Definition RTG.cpp:73
MlirType rtgSetTypeGetElementType(MlirType type)
Return the element type of the RTG set.
Definition RTG.cpp:89
bool rtgTypeIsAMemoryBlock(MlirType type)
If the type is an RTG memory block.
Definition RTG.cpp:193
MlirAttribute rtgImmediateAttrGet(MlirContext ctx, uint32_t width, uint64_t value)
Creates an RTG immediate attribute in the context with the given width and value.
Definition RTG.cpp:263
uint64_t rtgImmediateAttrGetValue(MlirAttribute attr)
Returns the value of the RTG immediate attribute.
Definition RTG.cpp:272
MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries, MlirAttribute const *entryNames, MlirType const *entryTypes)
Creates an RTG dict type in the context.
Definition RTG.cpp:112
uint32_t rtgImmediateTypeGetWidth(MlirType type)
Returns the width of the RTG immediate type.
Definition RTG.cpp:173
bool rtgTypeIsASequence(MlirType type)
If the type is an RTG sequence.
Definition RTG.cpp:39
MlirType rtgTupleTypeGetFieldType(MlirType type, intptr_t idx)
Returns a field type of the RTG tuple.
Definition RTG.cpp:158
MlirType rtgBagTypeGet(MlirType elementType)
Creates an RTG bag type in the context.
Definition RTG.cpp:98
MlirType rtgLabelTypeGet(MlirContext ctxt)
Creates an RTG mode type in the context.
Definition RTG.cpp:75
MlirType rtgTupleTypeGet(MlirContext ctxt, intptr_t numFields, MlirType const *fieldTypes)
Creates an RTG tuple type in the context.
Definition RTG.cpp:142
bool rtgTypeIsAImmediate(MlirType type)
If the type is an RTG immediate.
Definition RTG.cpp:165
uint32_t rtgMemoryTypeGetAddressWidth(MlirType type)
Returns the address with of an RTG memory type.
Definition RTG.cpp:186
MlirType rtgMemoryBlockTypeGet(MlirContext ctxt, uint32_t addressWidth)
Creates an RTG memory block type in the context.
Definition RTG.cpp:197
MlirAttribute rtgDefaultContextAttrGet(MlirContext ctxt, MlirType type)
Creates an RTG default context attribute in the context.
Definition RTG.cpp:216
bool rtgTypeIsATuple(MlirType type)
If the type is an RTG tuple.
Definition RTG.cpp:150
MlirType rtgBagTypeGetElementType(MlirType type)
Return the element type of the RTG bag.
Definition RTG.cpp:103
bool rtgAttrIsADefaultContextAttr(MlirAttribute attr)
If the attribute is an RTG default context.
Definition RTG.cpp:212
RTGLabelVisibility
Definition RTG.h:141
@ RTG_LABEL_VISIBILITY_EXTERNAL
Definition RTG.h:144
@ RTG_LABEL_VISIBILITY_GLOBAL
Definition RTG.h:143
@ RTG_LABEL_VISIBILITY_LOCAL
Definition RTG.h:142
void registerPipelines()
Registers all pipelines for the rtg dialect.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition rtg.py:1
Defines an entry in an !rtg.dict.
Definition RTGTypes.h:20
mlir::StringAttr name
Definition RTGTypes.h:21