CIRCT 20.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
12
13#include "mlir/CAPI/Registration.h"
14
15using namespace circt;
16using namespace circt::rtg;
17
18//===----------------------------------------------------------------------===//
19// Dialect API.
20//===----------------------------------------------------------------------===//
21
23
24//===----------------------------------------------------------------------===//
25// Type API.
26//===----------------------------------------------------------------------===//
27
28// SequenceType
29//===----------------------------------------------------------------------===//
30
31bool rtgTypeIsASequence(MlirType type) {
32 return isa<SequenceType>(unwrap(type));
33}
34
35MlirType rtgSequenceTypeGet(MlirContext ctxt, intptr_t numElements,
36 MlirType const *elementTypes) {
37 SmallVector<Type> types;
38 for (unsigned i = 0; i < numElements; ++i)
39 types.emplace_back(unwrap(elementTypes[i]));
40 return wrap(SequenceType::get(unwrap(ctxt), types));
41}
42
43unsigned rtgSequenceTypeGetNumElements(MlirType type) {
44 return cast<SequenceType>(unwrap(type)).getElementTypes().size();
45}
46
47MlirType rtgSequenceTypeGetElement(MlirType type, unsigned i) {
48 return wrap(cast<SequenceType>(unwrap(type)).getElementTypes()[i]);
49}
50
51// RandomizedSequenceType
52//===----------------------------------------------------------------------===//
53
54bool rtgTypeIsARandomizedSequence(MlirType type) {
55 return isa<RandomizedSequenceType>(unwrap(type));
56}
57
58MlirType rtgRandomizedSequenceTypeGet(MlirContext ctxt) {
59 return wrap(RandomizedSequenceType::get(unwrap(ctxt)));
60}
61
62// LabelType
63//===----------------------------------------------------------------------===//
64
65bool rtgTypeIsALabel(MlirType type) { return isa<LabelType>(unwrap(type)); }
66
67MlirType rtgLabelTypeGet(MlirContext ctxt) {
68 return wrap(LabelType::get(unwrap(ctxt)));
69}
70
71// SetType
72//===----------------------------------------------------------------------===//
73
74bool rtgTypeIsASet(MlirType type) { return isa<SetType>(unwrap(type)); }
75
76MlirType rtgSetTypeGet(MlirType elementType) {
77 auto ty = unwrap(elementType);
78 return wrap(SetType::get(ty.getContext(), ty));
79}
80
81// BagType
82//===----------------------------------------------------------------------===//
83
84bool rtgTypeIsABag(MlirType type) { return isa<BagType>(unwrap(type)); }
85
86MlirType rtgBagTypeGet(MlirType elementType) {
87 auto ty = unwrap(elementType);
88 return wrap(BagType::get(ty.getContext(), ty));
89}
90
91// DictType
92//===----------------------------------------------------------------------===//
93
94bool rtgTypeIsADict(MlirType type) { return isa<DictType>(unwrap(type)); }
95
96MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries,
97 MlirAttribute const *entryNames,
98 MlirType const *entryTypes) {
99 SmallVector<DictEntry> entries;
100 for (unsigned i = 0; i < numEntries; ++i) {
101 DictEntry entry;
102 entry.name = cast<StringAttr>(unwrap(entryNames[i]));
103 entry.type = unwrap(entryTypes[i]);
104 entries.emplace_back(entry);
105 }
106 return wrap(DictType::get(unwrap(ctxt), entries));
107}
108
109//===----------------------------------------------------------------------===//
110// Attribute API.
111//===----------------------------------------------------------------------===//
112
113bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr) {
114 return isa<LabelVisibilityAttr>(unwrap(attr));
115}
116
118 auto convert = [](LabelVisibility visibility) {
119 switch (visibility) {
120 case LabelVisibility::local:
122 case LabelVisibility::global:
124 case LabelVisibility::external:
126 }
127 };
128 return convert(cast<LabelVisibilityAttr>(unwrap(attr)).getValue());
129}
130
131MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt,
132 RTGLabelVisibility visibility) {
133 auto convert = [](RTGLabelVisibility visibility) {
134 switch (visibility) {
136 return LabelVisibility::local;
138 return LabelVisibility::global;
140 return LabelVisibility::external;
141 }
142 };
143 return wrap(LabelVisibilityAttr::get(unwrap(ctxt), convert(visibility)));
144}
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:84
MlirType rtgSequenceTypeGetElement(MlirType type, unsigned i)
The type of of the substitution element at the given index.
Definition RTG.cpp:47
bool rtgTypeIsARandomizedSequence(MlirType type)
If the type is an RTG randomized sequence.
Definition RTG.cpp:54
RTGLabelVisibility rtgLabelVisibilityAttrGetValue(MlirAttribute attr)
Get the RTG label visibility from the attribute.
Definition RTG.cpp:117
MlirType rtgSetTypeGet(MlirType elementType)
Creates an RTG set type in the context.
Definition RTG.cpp:76
MlirAttribute rtgLabelVisibilityAttrGet(MlirContext ctxt, RTGLabelVisibility visibility)
Creates an RTG label visibility attribute in the context.
Definition RTG.cpp:131
bool rtgAttrIsALabelVisibilityAttr(MlirAttribute attr)
If the attribute is an RTG label visibility.
Definition RTG.cpp:113
MlirType rtgSequenceTypeGet(MlirContext ctxt, intptr_t numElements, MlirType const *elementTypes)
Creates an RTG sequence type in the context.
Definition RTG.cpp:35
bool rtgTypeIsASet(MlirType type)
If the type is an RTG set.
Definition RTG.cpp:74
bool rtgTypeIsADict(MlirType type)
If the type is an RTG dict.
Definition RTG.cpp:94
unsigned rtgSequenceTypeGetNumElements(MlirType type)
The number of substitution elements of the RTG sequence.
Definition RTG.cpp:43
MlirType rtgRandomizedSequenceTypeGet(MlirContext ctxt)
Creates an RTG randomized sequence type in the context.
Definition RTG.cpp:58
bool rtgTypeIsALabel(MlirType type)
If the type is an RTG label.
Definition RTG.cpp:65
MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries, MlirAttribute const *entryNames, MlirType const *entryTypes)
Creates an RTG dict type in the context.
Definition RTG.cpp:96
bool rtgTypeIsASequence(MlirType type)
If the type is an RTG sequence.
Definition RTG.cpp:31
MlirType rtgBagTypeGet(MlirType elementType)
Creates an RTG bag type in the context.
Definition RTG.cpp:86
MlirType rtgLabelTypeGet(MlirContext ctxt)
Creates an RTG mode type in the context.
Definition RTG.cpp:67
RTGLabelVisibility
Definition RTG.h:80
@ RTG_LABEL_VISIBILITY_EXTERNAL
Definition RTG.h:83
@ RTG_LABEL_VISIBILITY_GLOBAL
Definition RTG.h:82
@ RTG_LABEL_VISIBILITY_LOCAL
Definition RTG.h:81
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