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