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//===----------------------------------------------------------------------===//
148// Attribute API.
149//===----------------------------------------------------------------------===//
150
151// DefaultContext
152//===----------------------------------------------------------------------===//
153
154bool rtgAttrIsADefaultContextAttr(MlirAttribute attr) {
155 return isa<DefaultContextAttr>(unwrap(attr));
156}
157
158MlirAttribute rtgDefaultContextAttrGet(MlirContext ctxt, MlirType type) {
159 return wrap(DefaultContextAttr::get(unwrap(ctxt), unwrap(type)));
160}
161
162// Label Visibility
163//===----------------------------------------------------------------------===//
164
165bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr) {
166 return isa<LabelVisibilityAttr>(unwrap(attr));
167}
168
170 auto convert = [](LabelVisibility visibility) {
171 switch (visibility) {
172 case LabelVisibility::local:
174 case LabelVisibility::global:
176 case LabelVisibility::external:
178 }
179 };
180 return convert(cast<LabelVisibilityAttr>(unwrap(attr)).getValue());
181}
182
183MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt,
184 RTGLabelVisibility visibility) {
185 auto convert = [](RTGLabelVisibility visibility) {
186 switch (visibility) {
188 return LabelVisibility::local;
190 return LabelVisibility::global;
192 return LabelVisibility::external;
193 }
194 };
195 return wrap(LabelVisibilityAttr::get(unwrap(ctxt), convert(visibility)));
196}
197
198// ImmediateAttr
199//===----------------------------------------------------------------------===//
200
201bool rtgAttrIsAImmediate(MlirAttribute attr) {
202 return isa<ImmediateAttr>(unwrap(attr));
203}
204
205MlirAttribute rtgImmediateAttrGet(MlirContext ctx, uint32_t width,
206 uint64_t value) {
207 return wrap(rtg::ImmediateAttr::get(unwrap(ctx), APInt(width, value)));
208}
209
210uint32_t rtgImmediateAttrGetWidth(MlirAttribute attr) {
211 return cast<ImmediateAttr>(unwrap(attr)).getValue().getBitWidth();
212}
213
214uint64_t rtgImmediateAttrGetValue(MlirAttribute attr) {
215 return cast<ImmediateAttr>(unwrap(attr)).getValue().getZExtValue();
216}
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
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:169
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:183
bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr)
If the attribute is an RTG label visibility.
Definition RTG.cpp:165
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:201
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:210
bool rtgTypeIsAArray(MlirType type)
If the type is an RTG array.
Definition RTG.cpp:126
bool rtgTypeIsASet(MlirType type)
If the type is an RTG set.
Definition RTG.cpp:75
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
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:205
uint64_t rtgImmediateAttrGetValue(MlirAttribute attr)
Returns the value of the RTG immediate attribute.
Definition RTG.cpp:214
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
MlirAttribute rtgDefaultContextAttrGet(MlirContext ctxt, MlirType type)
Creates an RTG default context attribute in the context.
Definition RTG.cpp:158
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:154
RTGLabelVisibility
Definition RTG.h:105
@ RTG_LABEL_VISIBILITY_EXTERNAL
Definition RTG.h:108
@ RTG_LABEL_VISIBILITY_GLOBAL
Definition RTG.h:107
@ RTG_LABEL_VISIBILITY_LOCAL
Definition RTG.h:106
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