CIRCT 21.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
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//===----------------------------------------------------------------------===//
119// Attribute API.
120//===----------------------------------------------------------------------===//
121
122bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr) {
123 return isa<LabelVisibilityAttr>(unwrap(attr));
124}
125
127 auto convert = [](LabelVisibility visibility) {
128 switch (visibility) {
129 case LabelVisibility::local:
131 case LabelVisibility::global:
133 case LabelVisibility::external:
135 }
136 };
137 return convert(cast<LabelVisibilityAttr>(unwrap(attr)).getValue());
138}
139
140MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt,
141 RTGLabelVisibility visibility) {
142 auto convert = [](RTGLabelVisibility visibility) {
143 switch (visibility) {
145 return LabelVisibility::local;
147 return LabelVisibility::global;
149 return LabelVisibility::external;
150 }
151 };
152 return wrap(LabelVisibilityAttr::get(unwrap(ctxt), convert(visibility)));
153}
154
155bool rtgAttrIsADefaultContextAttr(MlirAttribute attr) {
156 return isa<DefaultContextAttr>(unwrap(attr));
157}
158
159MlirAttribute rtgDefaultContextAttrGet(MlirContext ctxt, MlirType type) {
160 return wrap(DefaultContextAttr::get(unwrap(ctxt), unwrap(type)));
161}
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:113
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
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:126
MlirType rtgSetTypeGet(MlirType elementType)
Creates an RTG set type in the context.
Definition RTG.cpp:77
MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt, RTGLabelVisibility visibility)
Creates an RTG label visibility attribute in the context.
Definition RTG.cpp:140
bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr)
If the attribute is an RTG label visibility.
Definition RTG.cpp:122
MlirType rtgSequenceTypeGet(MlirContext ctxt, intptr_t numElements, MlirType const *elementTypes)
Creates an RTG sequence type in the context.
Definition RTG.cpp:36
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
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
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
MlirAttribute rtgDefaultContextAttrGet(MlirContext ctxt, MlirType type)
Creates an RTG default context attribute in the context.
Definition RTG.cpp:159
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:155
RTGLabelVisibility
Definition RTG.h:86
@ RTG_LABEL_VISIBILITY_EXTERNAL
Definition RTG.h:89
@ RTG_LABEL_VISIBILITY_GLOBAL
Definition RTG.h:88
@ RTG_LABEL_VISIBILITY_LOCAL
Definition RTG.h:87
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