CIRCT 22.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//===----------------------------------------------------------------------===//
204// Attribute API.
205//===----------------------------------------------------------------------===//
206
207// DefaultContext
208//===----------------------------------------------------------------------===//
209
210bool rtgAttrIsADefaultContextAttr(MlirAttribute attr) {
211 return isa<DefaultContextAttr>(unwrap(attr));
212}
213
214MlirAttribute rtgDefaultContextAttrGet(MlirContext ctxt, MlirType type) {
215 return wrap(DefaultContextAttr::get(unwrap(ctxt), unwrap(type)));
216}
217
218// Label Visibility
219//===----------------------------------------------------------------------===//
220
221bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr) {
222 return isa<LabelVisibilityAttr>(unwrap(attr));
223}
224
226 auto convert = [](LabelVisibility visibility) {
227 switch (visibility) {
228 case LabelVisibility::local:
230 case LabelVisibility::global:
232 case LabelVisibility::external:
234 }
235 };
236 return convert(cast<LabelVisibilityAttr>(unwrap(attr)).getValue());
237}
238
239MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt,
240 RTGLabelVisibility visibility) {
241 auto convert = [](RTGLabelVisibility visibility) {
242 switch (visibility) {
244 return LabelVisibility::local;
246 return LabelVisibility::global;
248 return LabelVisibility::external;
249 }
250 };
251 return wrap(LabelVisibilityAttr::get(unwrap(ctxt), convert(visibility)));
252}
253
254// ImmediateAttr
255//===----------------------------------------------------------------------===//
256
257bool rtgAttrIsAImmediate(MlirAttribute attr) {
258 return isa<ImmediateAttr>(unwrap(attr));
259}
260
261MlirAttribute rtgImmediateAttrGet(MlirContext ctx, uint32_t width,
262 uint64_t value) {
263 return wrap(rtg::ImmediateAttr::get(unwrap(ctx), APInt(width, value)));
264}
265
266uint32_t rtgImmediateAttrGetWidth(MlirAttribute attr) {
267 return cast<ImmediateAttr>(unwrap(attr)).getValue().getBitWidth();
268}
269
270uint64_t rtgImmediateAttrGetValue(MlirAttribute attr) {
271 return cast<ImmediateAttr>(unwrap(attr)).getValue().getZExtValue();
272}
273
274// AnyContexts
275//===----------------------------------------------------------------------===//
276
277bool rtgAttrIsAAnyContextAttr(MlirAttribute attr) {
278 return isa<AnyContextAttr>(unwrap(attr));
279}
280
281MlirAttribute rtgAnyContextAttrGet(MlirContext ctxt, MlirType type) {
282 return wrap(AnyContextAttr::get(unwrap(ctxt), unwrap(type)));
283}
284
285//===----------------------------------------------------------------------===//
286// Passes
287//===----------------------------------------------------------------------===//
288
289#include "circt/Dialect/RTG/Transforms/RTGPasses.capi.cpp.inc"
AIGLongestPathObject wrap(llvm::PointerUnion< Object *, DataflowPath::OutputPort * > object)
Definition AIG.cpp:57
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(StopBIOp op, StopBIOp::Adaptor adaptor, ConversionPatternRewriter &rewriter)
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:281
bool rtgAttrIsAAnyContextAttr(MlirAttribute attr)
If the attribute is an RTG any context attribute.
Definition RTG.cpp:277
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:225
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:239
bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr)
If the attribute is an RTG label visibility.
Definition RTG.cpp:221
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:257
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:266
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
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
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
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:261
uint64_t rtgImmediateAttrGetValue(MlirAttribute attr)
Returns the value of the RTG immediate attribute.
Definition RTG.cpp:270
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
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:214
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
bool rtgAttrIsADefaultContextAttr(MlirAttribute attr)
If the attribute is an RTG default context.
Definition RTG.cpp:210
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