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