CIRCT 23.0.0git
Loading...
Searching...
No Matches
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/Pass.h"
17#include "mlir/CAPI/Registration.h"
18
19using namespace circt;
20using namespace circt::rtg;
21
22//===----------------------------------------------------------------------===//
23// Dialect API.
24//===----------------------------------------------------------------------===//
25
27
29
30//===----------------------------------------------------------------------===//
31// Type API.
32//===----------------------------------------------------------------------===//
33
34// SequenceType
35//===----------------------------------------------------------------------===//
36
37bool rtgTypeIsASequence(MlirType type) {
38 return isa<SequenceType>(unwrap(type));
39}
40
41MlirType rtgSequenceTypeGet(MlirContext ctxt, intptr_t numElements,
42 MlirType const *elementTypes) {
43 SmallVector<Type> types;
44 for (unsigned i = 0; i < numElements; ++i)
45 types.emplace_back(unwrap(elementTypes[i]));
46 return wrap(SequenceType::get(unwrap(ctxt), types));
47}
48
49unsigned rtgSequenceTypeGetNumElements(MlirType type) {
50 return cast<SequenceType>(unwrap(type)).getElementTypes().size();
51}
52
53MlirType rtgSequenceTypeGetElement(MlirType type, unsigned i) {
54 return wrap(cast<SequenceType>(unwrap(type)).getElementTypes()[i]);
55}
56
57// RandomizedSequenceType
58//===----------------------------------------------------------------------===//
59
60bool rtgTypeIsARandomizedSequence(MlirType type) {
61 return isa<RandomizedSequenceType>(unwrap(type));
62}
63
64MlirType rtgRandomizedSequenceTypeGet(MlirContext ctxt) {
65 return wrap(RandomizedSequenceType::get(unwrap(ctxt)));
66}
67
68// LabelType
69//===----------------------------------------------------------------------===//
70
71bool rtgTypeIsALabel(MlirType type) { return isa<LabelType>(unwrap(type)); }
72
73MlirType rtgLabelTypeGet(MlirContext ctxt) {
74 return wrap(LabelType::get(unwrap(ctxt)));
75}
76
77// SetType
78//===----------------------------------------------------------------------===//
79
80bool rtgTypeIsASet(MlirType type) { return isa<SetType>(unwrap(type)); }
81
82MlirType rtgSetTypeGet(MlirType elementType) {
83 auto ty = unwrap(elementType);
84 return wrap(SetType::get(ty.getContext(), ty));
85}
86
87MlirType rtgSetTypeGetElementType(MlirType type) {
88 return wrap(cast<SetType>(unwrap(type)).getElementType());
89}
90
91// BagType
92//===----------------------------------------------------------------------===//
93
94bool rtgTypeIsABag(MlirType type) { return isa<BagType>(unwrap(type)); }
95
96MlirType rtgBagTypeGet(MlirType elementType) {
97 auto ty = unwrap(elementType);
98 return wrap(BagType::get(ty.getContext(), ty));
99}
100
101MlirType rtgBagTypeGetElementType(MlirType type) {
102 return wrap(cast<BagType>(unwrap(type)).getElementType());
103}
104
105// DictType
106//===----------------------------------------------------------------------===//
107
108bool rtgTypeIsADict(MlirType type) { return isa<DictType>(unwrap(type)); }
109
110MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries,
111 MlirAttribute const *entryNames,
112 MlirType const *entryTypes) {
113 SmallVector<DictEntry> entries;
114 for (unsigned i = 0; i < numEntries; ++i) {
115 DictEntry entry;
116 entry.name = cast<StringAttr>(unwrap(entryNames[i]));
117 entry.type = unwrap(entryTypes[i]);
118 entries.emplace_back(entry);
119 }
120 return wrap(DictType::get(unwrap(ctxt), entries));
121}
122
123// ArrayType
124//===----------------------------------------------------------------------===//
125
126MlirType rtgArrayTypeGet(MlirType elementType) {
127 return wrap(
128 ArrayType::get(unwrap(elementType).getContext(), unwrap(elementType)));
129}
130
131bool rtgTypeIsAArray(MlirType type) { return isa<ArrayType>(unwrap(type)); }
132
133MlirType rtgArrayTypeGetElementType(MlirType type) {
134 return wrap(cast<ArrayType>(unwrap(type)).getElementType());
135}
136
137// TupleType
138//===----------------------------------------------------------------------===//
139
140MlirType rtgTupleTypeGet(MlirContext ctxt, intptr_t numFields,
141 MlirType const *fieldTypes) {
142 SmallVector<Type> types;
143 for (unsigned i = 0; i < numFields; ++i)
144 types.emplace_back(unwrap(fieldTypes[i]));
145 return wrap(rtg::TupleType::get(unwrap(ctxt), types));
146}
147
148bool rtgTypeIsATuple(MlirType type) {
149 return isa<rtg::TupleType>(unwrap(type));
150}
151
152intptr_t rtgTypeGetNumFields(MlirType type) {
153 return cast<rtg::TupleType>(unwrap(type)).getFieldTypes().size();
154}
155
156MlirType rtgTupleTypeGetFieldType(MlirType type, intptr_t idx) {
157 return wrap(cast<rtg::TupleType>(unwrap(type)).getFieldTypes()[idx]);
158}
159
160// ImmediateType
161//===----------------------------------------------------------------------===//
162
163bool rtgTypeIsAImmediate(MlirType type) {
164 return isa<ImmediateType>(unwrap(type));
165}
166
167MlirType rtgImmediateTypeGet(MlirContext ctx, uint32_t width) {
168 return wrap(ImmediateType::get(unwrap(ctx), width));
169}
170
171uint32_t rtgImmediateTypeGetWidth(MlirType type) {
172 return cast<ImmediateType>(unwrap(type)).getWidth();
173}
174
175// MemoryType
176//===----------------------------------------------------------------------===//
177
178bool rtgTypeIsAMemory(MlirType type) { return isa<MemoryType>(unwrap(type)); }
179
180MlirType rtgMemoryTypeGet(MlirContext ctxt, uint32_t addressWidth) {
181 return wrap(MemoryType::get(unwrap(ctxt), addressWidth));
182}
183
184uint32_t rtgMemoryTypeGetAddressWidth(MlirType type) {
185 return cast<MemoryType>(unwrap(type)).getAddressWidth();
186}
187
188// MemoryBlockType
189//===----------------------------------------------------------------------===//
190
191bool rtgTypeIsAMemoryBlock(MlirType type) {
192 return isa<MemoryBlockType>(unwrap(type));
193}
194
195MlirType rtgMemoryBlockTypeGet(MlirContext ctxt, uint32_t addressWidth) {
196 return wrap(MemoryBlockType::get(unwrap(ctxt), addressWidth));
197}
198
199uint32_t rtgMemoryBlockTypeGetAddressWidth(MlirType type) {
200 return cast<MemoryBlockType>(unwrap(type)).getAddressWidth();
201}
202
203// StringType
204//===----------------------------------------------------------------------===//
205
206bool rtgTypeIsAString(MlirType type) { return isa<StringType>(unwrap(type)); }
207
208MlirType rtgStringTypeGet(MlirContext ctxt) {
209 return wrap(StringType::get(unwrap(ctxt)));
210}
211
212//===----------------------------------------------------------------------===//
213// Attribute API.
214//===----------------------------------------------------------------------===//
215
216// DefaultContext
217//===----------------------------------------------------------------------===//
218
219bool rtgAttrIsADefaultContextAttr(MlirAttribute attr) {
220 return isa<DefaultContextAttr>(unwrap(attr));
221}
222
223MlirAttribute rtgDefaultContextAttrGet(MlirContext ctxt, MlirType type) {
224 return wrap(DefaultContextAttr::get(unwrap(ctxt), unwrap(type)));
225}
226
227// Label Visibility
228//===----------------------------------------------------------------------===//
229
230bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr) {
231 return isa<LabelVisibilityAttr>(unwrap(attr));
232}
233
235 auto convert = [](LabelVisibility visibility) {
236 switch (visibility) {
237 case LabelVisibility::local:
239 case LabelVisibility::global:
241 case LabelVisibility::external:
243 }
244 };
245 return convert(cast<LabelVisibilityAttr>(unwrap(attr)).getValue());
246}
247
248MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt,
249 RTGLabelVisibility visibility) {
250 auto convert = [](RTGLabelVisibility visibility) {
251 switch (visibility) {
253 return LabelVisibility::local;
255 return LabelVisibility::global;
257 return LabelVisibility::external;
258 }
259 };
260 return wrap(LabelVisibilityAttr::get(unwrap(ctxt), convert(visibility)));
261}
262
263// ImmediateAttr
264//===----------------------------------------------------------------------===//
265
266bool rtgAttrIsAImmediate(MlirAttribute attr) {
267 return isa<ImmediateAttr>(unwrap(attr));
268}
269
270MlirAttribute rtgImmediateAttrGet(MlirContext ctx, uint32_t width,
271 uint64_t value) {
272 return wrap(rtg::ImmediateAttr::get(unwrap(ctx), APInt(width, value)));
273}
274
275uint32_t rtgImmediateAttrGetWidth(MlirAttribute attr) {
276 return cast<ImmediateAttr>(unwrap(attr)).getValue().getBitWidth();
277}
278
279uint64_t rtgImmediateAttrGetValue(MlirAttribute attr) {
280 return cast<ImmediateAttr>(unwrap(attr)).getValue().getZExtValue();
281}
282
283// AnyContexts
284//===----------------------------------------------------------------------===//
285
286bool rtgAttrIsAAnyContextAttr(MlirAttribute attr) {
287 return isa<AnyContextAttr>(unwrap(attr));
288}
289
290MlirAttribute rtgAnyContextAttrGet(MlirContext ctxt, MlirType type) {
291 return wrap(AnyContextAttr::get(unwrap(ctxt), unwrap(type)));
292}
293
294// VirtualRegConfigAttr
295//===----------------------------------------------------------------------===//
296
297bool rtgAttrIsAVirtualRegisterConfig(MlirAttribute attr) {
298 return isa<VirtualRegisterConfigAttr>(unwrap(attr));
299}
300
301MlirAttribute
302rtgVirtualRegisterConfigAttrGet(MlirContext ctxt, intptr_t numRegs,
303 MlirAttribute const *allowedRegs) {
304 SmallVector<rtg::RegisterAttrInterface> regs;
305 for (intptr_t i = 0; i < numRegs; ++i)
306 regs.push_back(cast<rtg::RegisterAttrInterface>(unwrap(allowedRegs[i])));
307 return wrap(VirtualRegisterConfigAttr::get(unwrap(ctxt), regs));
308}
309
311 return cast<VirtualRegisterConfigAttr>(unwrap(attr)).getAllowedRegs().size();
312}
313
314MlirAttribute rtgVirtualRegisterConfigAttrGetRegister(MlirAttribute attr,
315 intptr_t index) {
316 auto allowedRegs =
317 cast<VirtualRegisterConfigAttr>(unwrap(attr)).getAllowedRegs();
318 return wrap(allowedRegs[index]);
319}
320
321// LabelAttr
322//===----------------------------------------------------------------------===//
323
324bool rtgAttrIsALabel(MlirAttribute attr) {
325 return isa<LabelAttr>(unwrap(attr));
326}
327
328MlirAttribute rtgLabelAttrGet(MlirContext ctx, MlirStringRef name) {
329 return wrap(LabelAttr::get(unwrap(ctx), unwrap(name)));
330}
331
332MlirStringRef rtgLabelAttrGetName(MlirAttribute attr) {
333 return wrap(cast<LabelAttr>(unwrap(attr)).getName());
334}
335
336//===----------------------------------------------------------------------===//
337// Passes
338//===----------------------------------------------------------------------===//
339
340#include "circt/Dialect/RTG/Transforms/RTGPasses.capi.cpp.inc"
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 LogicalResult convert(arc::ExecuteOp op, arc::ExecuteOp::Adaptor adaptor, ConversionPatternRewriter &rewriter, const TypeConverter &converter)
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition OM.cpp:111
bool rtgTypeIsABag(MlirType type)
If the type is an RTG bag.
Definition RTG.cpp:94
MlirAttribute rtgAnyContextAttrGet(MlirContext ctxt, MlirType type)
Creates an RTG any context attribute in the context.
Definition RTG.cpp:290
bool rtgAttrIsAAnyContextAttr(MlirAttribute attr)
If the attribute is an RTG any context attribute.
Definition RTG.cpp:286
MlirType rtgSequenceTypeGetElement(MlirType type, unsigned i)
The type of of the substitution element at the given index.
Definition RTG.cpp:53
MlirType rtgArrayTypeGet(MlirType elementType)
Creates an RTG array type in the context.
Definition RTG.cpp:126
intptr_t rtgTypeGetNumFields(MlirType type)
Returns the number of fields in the RTG tuple.
Definition RTG.cpp:152
bool rtgTypeIsARandomizedSequence(MlirType type)
If the type is an RTG randomized sequence.
Definition RTG.cpp:60
RTGLabelVisibility rtgLabelVisibilityAttrGetValue(MlirAttribute attr)
Get the RTG label visibility from the attribute.
Definition RTG.cpp:234
MlirType rtgSetTypeGet(MlirType elementType)
Creates an RTG set type in the context.
Definition RTG.cpp:82
MlirType rtgArrayTypeGetElementType(MlirType type)
Returns the element type of the RTG array.
Definition RTG.cpp:133
MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt, RTGLabelVisibility visibility)
Creates an RTG label visibility attribute in the context.
Definition RTG.cpp:248
bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr)
If the attribute is an RTG label visibility.
Definition RTG.cpp:230
uint32_t rtgMemoryBlockTypeGetAddressWidth(MlirType type)
Returns the address with of an RTG memory block type.
Definition RTG.cpp:199
MlirType rtgImmediateTypeGet(MlirContext ctx, uint32_t width)
Creates an RTG immediate type in the context.
Definition RTG.cpp:167
bool rtgAttrIsAImmediate(MlirAttribute attr)
Checks if the attribute is an RTG immediate attribute.
Definition RTG.cpp:266
MlirType rtgSequenceTypeGet(MlirContext ctxt, intptr_t numElements, MlirType const *elementTypes)
Creates an RTG sequence type in the context.
Definition RTG.cpp:41
uint32_t rtgImmediateAttrGetWidth(MlirAttribute attr)
Returns the width of the RTG immediate attribute.
Definition RTG.cpp:275
bool rtgTypeIsAArray(MlirType type)
If the type is an RTG array.
Definition RTG.cpp:131
MlirType rtgMemoryTypeGet(MlirContext ctxt, uint32_t addressWidth)
Creates an RTG memory type in the context.
Definition RTG.cpp:180
bool rtgTypeIsASet(MlirType type)
If the type is an RTG set.
Definition RTG.cpp:80
bool rtgTypeIsAMemory(MlirType type)
If the type is an RTG memory.
Definition RTG.cpp:178
MlirAttribute rtgVirtualRegisterConfigAttrGet(MlirContext ctxt, intptr_t numRegs, MlirAttribute const *allowedRegs)
Creates an RTG virtual register config attribute in the context.
Definition RTG.cpp:302
bool rtgAttrIsAVirtualRegisterConfig(MlirAttribute attr)
Checks if the attribute is an RTG virtual register config attribute.
Definition RTG.cpp:297
bool rtgTypeIsADict(MlirType type)
If the type is an RTG dict.
Definition RTG.cpp:108
unsigned rtgSequenceTypeGetNumElements(MlirType type)
The number of substitution elements of the RTG sequence.
Definition RTG.cpp:49
MlirType rtgRandomizedSequenceTypeGet(MlirContext ctxt)
Creates an RTG randomized sequence type in the context.
Definition RTG.cpp:64
MlirType rtgStringTypeGet(MlirContext ctxt)
Creates an RTG string type in the context.
Definition RTG.cpp:208
bool rtgTypeIsALabel(MlirType type)
If the type is an RTG label.
Definition RTG.cpp:71
void registerRTGPipelines()
Definition RTG.cpp:28
MlirType rtgSetTypeGetElementType(MlirType type)
Return the element type of the RTG set.
Definition RTG.cpp:87
bool rtgTypeIsAMemoryBlock(MlirType type)
If the type is an RTG memory block.
Definition RTG.cpp:191
bool rtgTypeIsAString(MlirType type)
If the type is an RTG string.
Definition RTG.cpp:206
bool rtgAttrIsALabel(MlirAttribute attr)
Checks if the attribute is an RTG label attribute.
Definition RTG.cpp:324
MlirStringRef rtgLabelAttrGetName(MlirAttribute attr)
Returns the name of the RTG label attribute.
Definition RTG.cpp:332
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:270
uint64_t rtgImmediateAttrGetValue(MlirAttribute attr)
Returns the value of the RTG immediate attribute.
Definition RTG.cpp:279
MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries, MlirAttribute const *entryNames, MlirType const *entryTypes)
Creates an RTG dict type in the context.
Definition RTG.cpp:110
uint32_t rtgImmediateTypeGetWidth(MlirType type)
Returns the width of the RTG immediate type.
Definition RTG.cpp:171
bool rtgTypeIsASequence(MlirType type)
If the type is an RTG sequence.
Definition RTG.cpp:37
MlirType rtgTupleTypeGetFieldType(MlirType type, intptr_t idx)
Returns a field type of the RTG tuple.
Definition RTG.cpp:156
MlirType rtgBagTypeGet(MlirType elementType)
Creates an RTG bag type in the context.
Definition RTG.cpp:96
MlirAttribute rtgVirtualRegisterConfigAttrGetRegister(MlirAttribute attr, intptr_t index)
Returns the allowed register at the given index in the RTG virtual register config attribute.
Definition RTG.cpp:314
MlirType rtgLabelTypeGet(MlirContext ctxt)
Creates an RTG mode type in the context.
Definition RTG.cpp:73
MlirType rtgTupleTypeGet(MlirContext ctxt, intptr_t numFields, MlirType const *fieldTypes)
Creates an RTG tuple type in the context.
Definition RTG.cpp:140
bool rtgTypeIsAImmediate(MlirType type)
If the type is an RTG immediate.
Definition RTG.cpp:163
uint32_t rtgMemoryTypeGetAddressWidth(MlirType type)
Returns the address with of an RTG memory type.
Definition RTG.cpp:184
MlirType rtgMemoryBlockTypeGet(MlirContext ctxt, uint32_t addressWidth)
Creates an RTG memory block type in the context.
Definition RTG.cpp:195
MlirAttribute rtgDefaultContextAttrGet(MlirContext ctxt, MlirType type)
Creates an RTG default context attribute in the context.
Definition RTG.cpp:223
bool rtgTypeIsATuple(MlirType type)
If the type is an RTG tuple.
Definition RTG.cpp:148
MlirType rtgBagTypeGetElementType(MlirType type)
Return the element type of the RTG bag.
Definition RTG.cpp:101
intptr_t rtgVirtualRegisterConfigAttrGetNumRegisters(MlirAttribute attr)
Returns the number of allowed registers in the RTG virtual register config attribute.
Definition RTG.cpp:310
bool rtgAttrIsADefaultContextAttr(MlirAttribute attr)
If the attribute is an RTG default context.
Definition RTG.cpp:219
MlirAttribute rtgLabelAttrGet(MlirContext ctx, MlirStringRef name)
Creates an RTG label attribute in the context with the given name.
Definition RTG.cpp:328
RTGLabelVisibility
Definition RTG.h:147
@ RTG_LABEL_VISIBILITY_EXTERNAL
Definition RTG.h:150
@ RTG_LABEL_VISIBILITY_GLOBAL
Definition RTG.h:149
@ RTG_LABEL_VISIBILITY_LOCAL
Definition RTG.h:148
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