CIRCT  19.0.0git
OM.h
Go to the documentation of this file.
1 //===- OM.h - C interface for the OM dialect ----------------------*- C -*-===//
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 
9 #ifndef CIRCT_C_DIALECT_OM_H
10 #define CIRCT_C_DIALECT_OM_H
11 
12 #include "mlir-c/IR.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 //===----------------------------------------------------------------------===//
19 // Dialect API.
20 //===----------------------------------------------------------------------===//
21 
23 
24 //===----------------------------------------------------------------------===//
25 // Type API.
26 //===----------------------------------------------------------------------===//
27 
28 /// Is the Type a ClassType.
29 MLIR_CAPI_EXPORTED bool omTypeIsAClassType(MlirType type);
30 
31 /// Get the TypeID for a ClassType.
32 MLIR_CAPI_EXPORTED MlirTypeID omClassTypeGetTypeID(void);
33 
34 /// Get the name for a ClassType.
35 MLIR_CAPI_EXPORTED MlirIdentifier omClassTypeGetName(MlirType type);
36 
37 /// Is the Type a FrozenBasePathType.
38 MLIR_CAPI_EXPORTED bool omTypeIsAFrozenBasePathType(MlirType type);
39 
40 /// Get the TypeID for a FrozenBasePathType.
41 MLIR_CAPI_EXPORTED MlirTypeID omFrozenBasePathTypeGetTypeID(void);
42 
43 /// Is the Type a FrozenPathType.
44 MLIR_CAPI_EXPORTED bool omTypeIsAFrozenPathType(MlirType type);
45 
46 /// Get the TypeID for a FrozenPathType.
47 MLIR_CAPI_EXPORTED MlirTypeID omFrozenPathTypeGetTypeID(void);
48 
49 /// Is the Type a MapType.
50 MLIR_CAPI_EXPORTED bool omTypeIsAMapType(MlirType type);
51 
52 // Return a key type of a MapType.
53 MLIR_CAPI_EXPORTED MlirType omMapTypeGetKeyType(MlirType type);
54 
55 /// Is the Type a StringType.
56 MLIR_CAPI_EXPORTED bool omTypeIsAStringType(MlirType type);
57 
58 //===----------------------------------------------------------------------===//
59 // Evaluator data structures.
60 //===----------------------------------------------------------------------===//
61 
62 /// A value type for use in C APIs that just wraps a pointer to an Evaluator.
63 /// This is in line with the usual MLIR DEFINE_C_API_STRUCT.
64 struct OMEvaluator {
65  void *ptr;
66 };
67 
68 // clang-tidy doesn't respect extern "C".
69 // see https://github.com/llvm/llvm-project/issues/35272.
70 // NOLINTNEXTLINE(modernize-use-using)
71 typedef struct OMEvaluator OMEvaluator;
72 
73 /// A value type for use in C APIs that just wraps a pointer to an Object.
74 /// This is in line with the usual MLIR DEFINE_C_API_STRUCT.
76  void *ptr;
77 };
78 
79 // clang-tidy doesn't respect extern "C".
80 // see https://github.com/llvm/llvm-project/issues/35272.
81 // NOLINTNEXTLINE(modernize-use-using)
82 typedef struct OMEvaluatorValue OMEvaluatorValue;
83 
84 //===----------------------------------------------------------------------===//
85 // Evaluator API.
86 //===----------------------------------------------------------------------===//
87 
88 /// Construct an Evaluator with an IR module.
89 MLIR_CAPI_EXPORTED OMEvaluator omEvaluatorNew(MlirModule mod);
90 
91 /// Use the Evaluator to Instantiate an Object from its class name and actual
92 /// parameters.
93 MLIR_CAPI_EXPORTED OMEvaluatorValue
94 omEvaluatorInstantiate(OMEvaluator evaluator, MlirAttribute className,
95  intptr_t nActualParams, OMEvaluatorValue *actualParams);
96 
97 /// Get the Module the Evaluator is built from.
98 MLIR_CAPI_EXPORTED MlirModule omEvaluatorGetModule(OMEvaluator evaluator);
99 
100 //===----------------------------------------------------------------------===//
101 // Object API.
102 //===----------------------------------------------------------------------===//
103 
104 /// Query if the Object is null.
105 MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsNull(OMEvaluatorValue object);
106 
107 /// Get the Type from an Object, which will be a ClassType.
108 MLIR_CAPI_EXPORTED MlirType omEvaluatorObjectGetType(OMEvaluatorValue object);
109 
110 /// Get a field from an Object, which must contain a field of that name.
111 MLIR_CAPI_EXPORTED OMEvaluatorValue
112 omEvaluatorObjectGetField(OMEvaluatorValue object, MlirAttribute name);
113 
114 /// Get the object hash.
115 MLIR_CAPI_EXPORTED unsigned omEvaluatorObjectGetHash(OMEvaluatorValue object);
116 
117 /// Check equality of two objects.
118 MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsEq(OMEvaluatorValue object,
119  OMEvaluatorValue other);
120 
121 /// Get all the field names from an Object, can be empty if object has no
122 /// fields.
123 MLIR_CAPI_EXPORTED MlirAttribute
125 
126 //===----------------------------------------------------------------------===//
127 // EvaluatorValue API.
128 //===----------------------------------------------------------------------===//
129 
130 // Get a context from an EvaluatorValue.
131 MLIR_CAPI_EXPORTED MlirContext
133 
134 // Get Location from an EvaluatorValue.
135 MLIR_CAPI_EXPORTED MlirLocation
137 
138 // Query if the EvaluatorValue is null.
139 MLIR_CAPI_EXPORTED bool omEvaluatorValueIsNull(OMEvaluatorValue evaluatorValue);
140 
141 /// Query if the EvaluatorValue is an Object.
142 MLIR_CAPI_EXPORTED bool
144 
145 /// Query if the EvaluatorValue is a Primitive.
146 MLIR_CAPI_EXPORTED bool
148 
149 /// Get the Primitive from an EvaluatorValue, which must contain a Primitive.
150 MLIR_CAPI_EXPORTED MlirAttribute
152 
153 /// Get the EvaluatorValue from a Primitive value.
154 MLIR_CAPI_EXPORTED OMEvaluatorValue
155 omEvaluatorValueFromPrimitive(MlirAttribute primitive);
156 
157 /// Query if the EvaluatorValue is an Object.
158 MLIR_CAPI_EXPORTED bool
160 
161 /// Get the length of the list.
162 MLIR_CAPI_EXPORTED intptr_t
164 
165 /// Get an element of the list.
166 MLIR_CAPI_EXPORTED OMEvaluatorValue
167 omEvaluatorListGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos);
168 
169 /// Query if the EvaluatorValue is a Tuple.
170 MLIR_CAPI_EXPORTED bool
172 
173 /// Get the size of the tuple.
174 MLIR_CAPI_EXPORTED intptr_t
176 
177 /// Get an element of the tuple.
178 MLIR_CAPI_EXPORTED OMEvaluatorValue
179 omEvaluatorTupleGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos);
180 
181 /// Get an element of the map.
182 MLIR_CAPI_EXPORTED OMEvaluatorValue
183 omEvaluatorMapGetElement(OMEvaluatorValue evaluatorValue, MlirAttribute attr);
184 
185 MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorMapGetKeys(OMEvaluatorValue object);
186 
187 /// Query if the EvaluatorValue is a Map.
188 MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAMap(OMEvaluatorValue evaluatorValue);
189 
190 /// Get the Type from a Map, which will be a MapType.
191 MLIR_CAPI_EXPORTED MlirType
193 
194 /// Query if the EvaluatorValue is a BasePath.
195 MLIR_CAPI_EXPORTED bool
197 
198 /// Create an empty BasePath.
199 MLIR_CAPI_EXPORTED OMEvaluatorValue
200 omEvaluatorBasePathGetEmpty(MlirContext context);
201 
202 /// Query if the EvaluatorValue is a Path.
203 MLIR_CAPI_EXPORTED bool
205 
206 /// Get a string representation of a Path.
207 MLIR_CAPI_EXPORTED MlirAttribute
209 
210 /// Query if the EvaluatorValue is a Reference.
211 MLIR_CAPI_EXPORTED bool
213 
214 /// Dereference a Reference EvaluatorValue. Emits an error and returns null if
215 /// the Reference cannot be dereferenced.
216 MLIR_CAPI_EXPORTED OMEvaluatorValue
218 
219 //===----------------------------------------------------------------------===//
220 // ReferenceAttr API
221 //===----------------------------------------------------------------------===//
222 
223 MLIR_CAPI_EXPORTED bool omAttrIsAReferenceAttr(MlirAttribute attr);
224 
225 MLIR_CAPI_EXPORTED MlirAttribute omReferenceAttrGetInnerRef(MlirAttribute attr);
226 
227 //===----------------------------------------------------------------------===//
228 // IntegerAttr API
229 //===----------------------------------------------------------------------===//
230 
231 MLIR_CAPI_EXPORTED bool omAttrIsAIntegerAttr(MlirAttribute attr);
232 
233 /// Given an om::IntegerAttr, return the mlir::IntegerAttr.
234 MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGetInt(MlirAttribute attr);
235 
236 /// Get an om::IntegerAttr from mlir::IntegerAttr.
237 MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGet(MlirAttribute attr);
238 
239 /// Get a string representation of an om::IntegerAttr.
240 MLIR_CAPI_EXPORTED MlirStringRef omIntegerAttrToString(MlirAttribute attr);
241 
242 //===----------------------------------------------------------------------===//
243 // ListAttr API
244 //===----------------------------------------------------------------------===//
245 
246 MLIR_CAPI_EXPORTED bool omAttrIsAListAttr(MlirAttribute attr);
247 
248 MLIR_CAPI_EXPORTED intptr_t omListAttrGetNumElements(MlirAttribute attr);
249 
250 MLIR_CAPI_EXPORTED MlirAttribute omListAttrGetElement(MlirAttribute attr,
251  intptr_t pos);
252 
253 //===----------------------------------------------------------------------===//
254 // MapAttr API
255 //===----------------------------------------------------------------------===//
256 
257 MLIR_CAPI_EXPORTED bool omAttrIsAMapAttr(MlirAttribute attr);
258 
259 MLIR_CAPI_EXPORTED intptr_t omMapAttrGetNumElements(MlirAttribute attr);
260 
261 MLIR_CAPI_EXPORTED MlirIdentifier omMapAttrGetElementKey(MlirAttribute attr,
262  intptr_t pos);
263 
264 MLIR_CAPI_EXPORTED MlirAttribute omMapAttrGetElementValue(MlirAttribute attr,
265  intptr_t pos);
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 
271 #endif // CIRCT_C_DIALECT_OM_H
MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsEq(OMEvaluatorValue object, OMEvaluatorValue other)
Check equality of two objects.
Definition: OM.cpp:166
MLIR_CAPI_EXPORTED intptr_t omListAttrGetNumElements(MlirAttribute attr)
Definition: OM.cpp:402
MLIR_CAPI_EXPORTED unsigned omEvaluatorObjectGetHash(OMEvaluatorValue object)
Get the object hash.
Definition: OM.cpp:161
MLIR_CAPI_EXPORTED bool omTypeIsAFrozenBasePathType(MlirType type)
Is the Type a FrozenBasePathType.
Definition: OM.cpp:44
MLIR_CAPI_EXPORTED bool omAttrIsAListAttr(MlirAttribute attr)
Definition: OM.cpp:398
MLIR_CAPI_EXPORTED MlirTypeID omFrozenPathTypeGetTypeID(void)
Get the TypeID for a FrozenPathType.
Definition: OM.cpp:59
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsABasePath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a BasePath.
Definition: OM.cpp:311
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsNull(OMEvaluatorValue evaluatorValue)
Definition: OM.cpp:217
MLIR_CAPI_EXPORTED MlirAttribute omMapAttrGetElementValue(MlirAttribute attr, intptr_t pos)
Definition: OM.cpp:428
MLIR_CAPI_EXPORTED intptr_t omEvaluatorTupleGetNumElements(OMEvaluatorValue evaluatorValue)
Get the size of the tuple.
Definition: OM.cpp:282
MLIR_CAPI_EXPORTED OMEvaluator omEvaluatorNew(MlirModule mod)
Construct an Evaluator with an IR module.
Definition: OM.cpp:105
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorValueGetReferenceValue(OMEvaluatorValue evaluatorValue)
Dereference a Reference EvaluatorValue.
Definition: OM.cpp:336
MLIR_CAPI_EXPORTED MlirLocation omEvaluatorValueGetLoc(OMEvaluatorValue evaluatorValue)
Definition: OM.cpp:212
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorValueGetPrimitive(OMEvaluatorValue evaluatorValue)
Get the Primitive from an EvaluatorValue, which must contain a Primitive.
Definition: OM.cpp:235
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorBasePathGetEmpty(MlirContext context)
Create an empty BasePath.
Definition: OM.cpp:315
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAPath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Path.
Definition: OM.cpp:319
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAMap(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Map.
Definition: OM.cpp:307
MLIR_CAPI_EXPORTED MlirTypeID omFrozenBasePathTypeGetTypeID(void)
Get the TypeID for a FrozenBasePathType.
Definition: OM.cpp:49
MLIR_CAPI_EXPORTED MlirModule omEvaluatorGetModule(OMEvaluator evaluator)
Get the Module the Evaluator is built from.
Definition: OM.cpp:140
MLIR_CAPI_EXPORTED MlirType omMapTypeGetKeyType(MlirType type)
Return a key type of a map.
Definition: OM.cpp:74
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorInstantiate(OMEvaluator evaluator, MlirAttribute className, intptr_t nActualParams, OMEvaluatorValue *actualParams)
Use the Evaluator to Instantiate an Object from its class name and actual parameters.
Definition: OM.cpp:112
MLIR_CAPI_EXPORTED MlirTypeID omClassTypeGetTypeID(void)
Get the TypeID for a ClassType.
Definition: OM.cpp:36
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorMapGetElement(OMEvaluatorValue evaluatorValue, MlirAttribute attr)
Get an element of the map.
Definition: OM.cpp:296
MLIR_CAPI_EXPORTED bool omTypeIsAMapType(MlirType type)
Is the Type a MapType.
MLIR_CAPI_EXPORTED intptr_t omEvaluatorListGetNumElements(OMEvaluatorValue evaluatorValue)
Get the length of the list.
Definition: OM.cpp:263
MLIR_CAPI_EXPORTED MlirIdentifier omClassTypeGetName(MlirType type)
Get the name for a ClassType.
Definition: OM.cpp:39
MLIR_CAPI_EXPORTED bool omAttrIsAReferenceAttr(MlirAttribute attr)
Definition: OM.cpp:357
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorTupleGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the tuple.
Definition: OM.cpp:289
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAList(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
Definition: OM.cpp:250
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsATuple(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Tuple.
Definition: OM.cpp:277
MLIR_CAPI_EXPORTED MlirType omEvaluatorMapGetType(OMEvaluatorValue evaluatorValue)
Get the Type from a Map, which will be a MapType.
Definition: OM.cpp:176
MLIR_CAPI_EXPORTED bool omTypeIsAFrozenPathType(MlirType type)
Is the Type a FrozenPathType.
Definition: OM.cpp:54
MLIR_CAPI_EXPORTED MlirType omEvaluatorObjectGetType(OMEvaluatorValue object)
Get the Type from an Object, which will be a ClassType.
Definition: OM.cpp:156
MLIR_CAPI_EXPORTED bool omAttrIsAIntegerAttr(MlirAttribute attr)
Definition: OM.cpp:370
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(OM, om)
MLIR_CAPI_EXPORTED bool omTypeIsAStringType(MlirType type)
Is the Type a StringType.
Definition: OM.cpp:64
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorListGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the list.
Definition: OM.cpp:270
MLIR_CAPI_EXPORTED bool omTypeIsAClassType(MlirType type)
Is the Type a ClassType.
Definition: OM.cpp:33
MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsNull(OMEvaluatorValue object)
Query if the Object is null.
Definition: OM.cpp:150
MLIR_CAPI_EXPORTED intptr_t omMapAttrGetNumElements(MlirAttribute attr)
Definition: OM.cpp:418
MLIR_CAPI_EXPORTED MlirStringRef omIntegerAttrToString(MlirAttribute attr)
Get a string representation of an om::IntegerAttr.
Definition: OM.cpp:385
MLIR_CAPI_EXPORTED MlirIdentifier omMapAttrGetElementKey(MlirAttribute attr, intptr_t pos)
Definition: OM.cpp:423
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorValueFromPrimitive(MlirAttribute primitive)
Get the EvaluatorValue from a Primitive value.
Definition: OM.cpp:244
MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGet(MlirAttribute attr)
Get an om::IntegerAttr from mlir::IntegerAttr.
Definition: OM.cpp:378
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAObject(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
Definition: OM.cpp:223
MLIR_CAPI_EXPORTED MlirAttribute omListAttrGetElement(MlirAttribute attr, intptr_t pos)
Definition: OM.cpp:407
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAPrimitive(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Primitive.
Definition: OM.cpp:229
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorObjectGetField(OMEvaluatorValue object, MlirAttribute name)
Get a field from an Object, which must contain a field of that name.
Definition: OM.cpp:186
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorMapGetKeys(OMEvaluatorValue object)
Get an ArrayAttr with the keys in a Map.
Definition: OM.cpp:181
MLIR_CAPI_EXPORTED MlirContext omEvaluatorValueGetContext(OMEvaluatorValue evaluatorValue)
Definition: OM.cpp:207
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorObjectGetFieldNames(OMEvaluatorValue object)
Get all the field names from an Object, can be empty if object has no fields.
Definition: OM.cpp:172
MLIR_CAPI_EXPORTED bool omAttrIsAMapAttr(MlirAttribute attr)
Definition: OM.cpp:416
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAReference(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Reference.
Definition: OM.cpp:329
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorPathGetAsString(OMEvaluatorValue evaluatorValue)
Get a string representation of a Path.
Definition: OM.cpp:323
MLIR_CAPI_EXPORTED MlirAttribute omReferenceAttrGetInnerRef(MlirAttribute attr)
Definition: OM.cpp:361
MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGetInt(MlirAttribute attr)
Given an om::IntegerAttr, return the mlir::IntegerAttr.
Definition: OM.cpp:374
Definition: om.py:1
A value type for use in C APIs that just wraps a pointer to an Object.
Definition: OM.h:75
void * ptr
Definition: OM.h:76
A value type for use in C APIs that just wraps a pointer to an Evaluator.
Definition: OM.h:64
void * ptr
Definition: OM.h:65