CIRCT 21.0.0git
Loading...
Searching...
No Matches
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
15extern "C" {
16#endif
17
18//===----------------------------------------------------------------------===//
19// Dialect API.
20//===----------------------------------------------------------------------===//
21
23
24//===----------------------------------------------------------------------===//
25// Type API.
26//===----------------------------------------------------------------------===//
27
28/// Is the Type an AnyType.
29MLIR_CAPI_EXPORTED bool omTypeIsAAnyType(MlirType type);
30
31/// Get the TypeID for an AnyType.
32MLIR_CAPI_EXPORTED MlirTypeID omAnyTypeGetTypeID(void);
33
34/// Is the Type a ClassType.
35MLIR_CAPI_EXPORTED bool omTypeIsAClassType(MlirType type);
36
37/// Get the TypeID for a ClassType.
38MLIR_CAPI_EXPORTED MlirTypeID omClassTypeGetTypeID(void);
39
40/// Get the name for a ClassType.
41MLIR_CAPI_EXPORTED MlirIdentifier omClassTypeGetName(MlirType type);
42
43/// Is the Type a FrozenBasePathType.
44MLIR_CAPI_EXPORTED bool omTypeIsAFrozenBasePathType(MlirType type);
45
46/// Get the TypeID for a FrozenBasePathType.
47MLIR_CAPI_EXPORTED MlirTypeID omFrozenBasePathTypeGetTypeID(void);
48
49/// Is the Type a FrozenPathType.
50MLIR_CAPI_EXPORTED bool omTypeIsAFrozenPathType(MlirType type);
51
52/// Get the TypeID for a FrozenPathType.
53MLIR_CAPI_EXPORTED MlirTypeID omFrozenPathTypeGetTypeID(void);
54
55/// Is the Type a ListType.
56MLIR_CAPI_EXPORTED bool omTypeIsAListType(MlirType type);
57
58/// Get the TypeID for a ListType.
59MLIR_CAPI_EXPORTED MlirTypeID omListTypeGetTypeID(void);
60
61// Return a element type of a ListType.
62MLIR_CAPI_EXPORTED MlirType omListTypeGetElementType(MlirType type);
63
64/// Is the Type a MapType.
65MLIR_CAPI_EXPORTED bool omTypeIsAMapType(MlirType type);
66
67// Return a key type of a MapType.
68MLIR_CAPI_EXPORTED MlirType omMapTypeGetKeyType(MlirType type);
69
70/// Is the Type a StringType.
71MLIR_CAPI_EXPORTED bool omTypeIsAStringType(MlirType type);
72
73/// Get the TypeID for a StringType.
74MLIR_CAPI_EXPORTED MlirTypeID omStringTypeGetTypeID(void);
75
76/// Get a StringType.
77MLIR_CAPI_EXPORTED MlirType omStringTypeGet(MlirContext ctx);
78
79//===----------------------------------------------------------------------===//
80// Evaluator data structures.
81//===----------------------------------------------------------------------===//
82
83/// A value type for use in C APIs that just wraps a pointer to an Evaluator.
84/// This is in line with the usual MLIR DEFINE_C_API_STRUCT.
86 void *ptr;
87};
88
89// clang-tidy doesn't respect extern "C".
90// see https://github.com/llvm/llvm-project/issues/35272.
91// NOLINTNEXTLINE(modernize-use-using)
92typedef struct OMEvaluator OMEvaluator;
93
94/// A value type for use in C APIs that just wraps a pointer to an Object.
95/// This is in line with the usual MLIR DEFINE_C_API_STRUCT.
97 void *ptr;
98};
99
100// clang-tidy doesn't respect extern "C".
101// see https://github.com/llvm/llvm-project/issues/35272.
102// NOLINTNEXTLINE(modernize-use-using)
104
105//===----------------------------------------------------------------------===//
106// Evaluator API.
107//===----------------------------------------------------------------------===//
108
109/// Construct an Evaluator with an IR module.
110MLIR_CAPI_EXPORTED OMEvaluator omEvaluatorNew(MlirModule mod);
111
112/// Use the Evaluator to Instantiate an Object from its class name and actual
113/// parameters.
114MLIR_CAPI_EXPORTED OMEvaluatorValue
115omEvaluatorInstantiate(OMEvaluator evaluator, MlirAttribute className,
116 intptr_t nActualParams, OMEvaluatorValue *actualParams);
117
118/// Get the Module the Evaluator is built from.
119MLIR_CAPI_EXPORTED MlirModule omEvaluatorGetModule(OMEvaluator evaluator);
120
121//===----------------------------------------------------------------------===//
122// Object API.
123//===----------------------------------------------------------------------===//
124
125/// Query if the Object is null.
126MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsNull(OMEvaluatorValue object);
127
128/// Get the Type from an Object, which will be a ClassType.
129MLIR_CAPI_EXPORTED MlirType omEvaluatorObjectGetType(OMEvaluatorValue object);
130
131/// Get a field from an Object, which must contain a field of that name.
132MLIR_CAPI_EXPORTED OMEvaluatorValue
133omEvaluatorObjectGetField(OMEvaluatorValue object, MlirAttribute name);
134
135/// Get the object hash.
136MLIR_CAPI_EXPORTED unsigned omEvaluatorObjectGetHash(OMEvaluatorValue object);
137
138/// Check equality of two objects.
139MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsEq(OMEvaluatorValue object,
140 OMEvaluatorValue other);
141
142/// Get all the field names from an Object, can be empty if object has no
143/// fields.
144MLIR_CAPI_EXPORTED MlirAttribute
146
147//===----------------------------------------------------------------------===//
148// EvaluatorValue API.
149//===----------------------------------------------------------------------===//
150
151// Get a context from an EvaluatorValue.
152MLIR_CAPI_EXPORTED MlirContext
154
155// Get Location from an EvaluatorValue.
156MLIR_CAPI_EXPORTED MlirLocation
158
159// Query if the EvaluatorValue is null.
160MLIR_CAPI_EXPORTED bool omEvaluatorValueIsNull(OMEvaluatorValue evaluatorValue);
161
162/// Query if the EvaluatorValue is an Object.
163MLIR_CAPI_EXPORTED bool
165
166/// Query if the EvaluatorValue is a Primitive.
167MLIR_CAPI_EXPORTED bool
169
170/// Get the Primitive from an EvaluatorValue, which must contain a Primitive.
171MLIR_CAPI_EXPORTED MlirAttribute
173
174/// Get the EvaluatorValue from a Primitive value.
175MLIR_CAPI_EXPORTED OMEvaluatorValue
176omEvaluatorValueFromPrimitive(MlirAttribute primitive);
177
178/// Query if the EvaluatorValue is an Object.
179MLIR_CAPI_EXPORTED bool
181
182/// Get the length of the list.
183MLIR_CAPI_EXPORTED intptr_t
185
186/// Get an element of the list.
187MLIR_CAPI_EXPORTED OMEvaluatorValue
188omEvaluatorListGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos);
189
190/// Query if the EvaluatorValue is a Tuple.
191MLIR_CAPI_EXPORTED bool
193
194/// Get the size of the tuple.
195MLIR_CAPI_EXPORTED intptr_t
197
198/// Get an element of the tuple.
199MLIR_CAPI_EXPORTED OMEvaluatorValue
200omEvaluatorTupleGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos);
201
202/// Get an element of the map.
203MLIR_CAPI_EXPORTED OMEvaluatorValue
204omEvaluatorMapGetElement(OMEvaluatorValue evaluatorValue, MlirAttribute attr);
205
206MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorMapGetKeys(OMEvaluatorValue object);
207
208/// Query if the EvaluatorValue is a Map.
209MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAMap(OMEvaluatorValue evaluatorValue);
210
211/// Get the Type from a Map, which will be a MapType.
212MLIR_CAPI_EXPORTED MlirType
214
215/// Query if the EvaluatorValue is a BasePath.
216MLIR_CAPI_EXPORTED bool
218
219/// Create an empty BasePath.
220MLIR_CAPI_EXPORTED OMEvaluatorValue
221omEvaluatorBasePathGetEmpty(MlirContext context);
222
223/// Query if the EvaluatorValue is a Path.
224MLIR_CAPI_EXPORTED bool
226
227/// Get a string representation of a Path.
228MLIR_CAPI_EXPORTED MlirAttribute
230
231/// Query if the EvaluatorValue is a Reference.
232MLIR_CAPI_EXPORTED bool
234
235/// Dereference a Reference EvaluatorValue. Emits an error and returns null if
236/// the Reference cannot be dereferenced.
237MLIR_CAPI_EXPORTED OMEvaluatorValue
239
240//===----------------------------------------------------------------------===//
241// ReferenceAttr API
242//===----------------------------------------------------------------------===//
243
244MLIR_CAPI_EXPORTED bool omAttrIsAReferenceAttr(MlirAttribute attr);
245
246MLIR_CAPI_EXPORTED MlirAttribute omReferenceAttrGetInnerRef(MlirAttribute attr);
247
248//===----------------------------------------------------------------------===//
249// IntegerAttr API
250//===----------------------------------------------------------------------===//
251
252MLIR_CAPI_EXPORTED bool omAttrIsAIntegerAttr(MlirAttribute attr);
253
254/// Given an om::IntegerAttr, return the mlir::IntegerAttr.
255MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGetInt(MlirAttribute attr);
256
257/// Get an om::IntegerAttr from mlir::IntegerAttr.
258MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGet(MlirAttribute attr);
259
260/// Get a string representation of an om::IntegerAttr.
261MLIR_CAPI_EXPORTED MlirStringRef omIntegerAttrToString(MlirAttribute attr);
262
263//===----------------------------------------------------------------------===//
264// ListAttr API
265//===----------------------------------------------------------------------===//
266
267MLIR_CAPI_EXPORTED bool omAttrIsAListAttr(MlirAttribute attr);
268
269MLIR_CAPI_EXPORTED intptr_t omListAttrGetNumElements(MlirAttribute attr);
270
271MLIR_CAPI_EXPORTED MlirAttribute omListAttrGetElement(MlirAttribute attr,
272 intptr_t pos);
273
274MLIR_CAPI_EXPORTED MlirAttribute omListAttrGet(MlirType elementType,
275 intptr_t numElements,
276 const MlirAttribute *elements);
277
278//===----------------------------------------------------------------------===//
279// MapAttr API
280//===----------------------------------------------------------------------===//
281
282MLIR_CAPI_EXPORTED bool omAttrIsAMapAttr(MlirAttribute attr);
283
284MLIR_CAPI_EXPORTED intptr_t omMapAttrGetNumElements(MlirAttribute attr);
285
286MLIR_CAPI_EXPORTED MlirIdentifier omMapAttrGetElementKey(MlirAttribute attr,
287 intptr_t pos);
288
289MLIR_CAPI_EXPORTED MlirAttribute omMapAttrGetElementValue(MlirAttribute attr,
290 intptr_t pos);
291
292#ifdef __cplusplus
293}
294#endif
295
296#endif // CIRCT_C_DIALECT_OM_H
MlirType uint64_t numElements
Definition CHIRRTL.cpp:30
MlirType elementType
Definition CHIRRTL.cpp:29
MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsEq(OMEvaluatorValue object, OMEvaluatorValue other)
Check equality of two objects.
Definition OM.cpp:189
MLIR_CAPI_EXPORTED intptr_t omListAttrGetNumElements(MlirAttribute attr)
Definition OM.cpp:425
MLIR_CAPI_EXPORTED unsigned omEvaluatorObjectGetHash(OMEvaluatorValue object)
Get the object hash.
Definition OM.cpp:184
MLIR_CAPI_EXPORTED bool omTypeIsAFrozenBasePathType(MlirType type)
Is the Type a FrozenBasePathType.
Definition OM.cpp:50
MLIR_CAPI_EXPORTED MlirTypeID omListTypeGetTypeID(void)
Get the TypeID for a ListType.
Definition OM.cpp:73
MLIR_CAPI_EXPORTED MlirAttribute omListAttrGet(MlirType elementType, intptr_t numElements, const MlirAttribute *elements)
Definition OM.cpp:435
MLIR_CAPI_EXPORTED bool omAttrIsAListAttr(MlirAttribute attr)
Definition OM.cpp:421
MLIR_CAPI_EXPORTED bool omTypeIsAListType(MlirType type)
Is the Type a ListType.
Definition OM.cpp:70
MLIR_CAPI_EXPORTED MlirTypeID omFrozenPathTypeGetTypeID(void)
Get the TypeID for a FrozenPathType.
Definition OM.cpp:65
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsABasePath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a BasePath.
Definition OM.cpp:334
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsNull(OMEvaluatorValue evaluatorValue)
Definition OM.cpp:240
MLIR_CAPI_EXPORTED MlirAttribute omMapAttrGetElementValue(MlirAttribute attr, intptr_t pos)
Definition OM.cpp:460
MLIR_CAPI_EXPORTED intptr_t omEvaluatorTupleGetNumElements(OMEvaluatorValue evaluatorValue)
Get the size of the tuple.
Definition OM.cpp:305
MLIR_CAPI_EXPORTED OMEvaluator omEvaluatorNew(MlirModule mod)
Construct an Evaluator with an IR module.
Definition OM.cpp:128
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorValueGetReferenceValue(OMEvaluatorValue evaluatorValue)
Dereference a Reference EvaluatorValue.
Definition OM.cpp:359
MLIR_CAPI_EXPORTED MlirLocation omEvaluatorValueGetLoc(OMEvaluatorValue evaluatorValue)
Definition OM.cpp:235
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorValueGetPrimitive(OMEvaluatorValue evaluatorValue)
Get the Primitive from an EvaluatorValue, which must contain a Primitive.
Definition OM.cpp:258
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorBasePathGetEmpty(MlirContext context)
Create an empty BasePath.
Definition OM.cpp:338
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAPath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Path.
Definition OM.cpp:342
MLIR_CAPI_EXPORTED bool omTypeIsAAnyType(MlirType type)
Is the Type an AnyType.
Definition OM.cpp:33
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAMap(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Map.
Definition OM.cpp:330
MLIR_CAPI_EXPORTED MlirTypeID omFrozenBasePathTypeGetTypeID(void)
Get the TypeID for a FrozenBasePathType.
Definition OM.cpp:55
MLIR_CAPI_EXPORTED MlirModule omEvaluatorGetModule(OMEvaluator evaluator)
Get the Module the Evaluator is built from.
Definition OM.cpp:163
MLIR_CAPI_EXPORTED MlirType omMapTypeGetKeyType(MlirType type)
Return a key type of a map.
Definition OM.cpp:97
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:135
MLIR_CAPI_EXPORTED MlirTypeID omClassTypeGetTypeID(void)
Get the TypeID for a ClassType.
Definition OM.cpp:42
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorMapGetElement(OMEvaluatorValue evaluatorValue, MlirAttribute attr)
Get an element of the map.
Definition OM.cpp:319
MLIR_CAPI_EXPORTED bool omTypeIsAMapType(MlirType type)
Is the Type a MapType.
Definition OM.cpp:94
MLIR_CAPI_EXPORTED intptr_t omEvaluatorListGetNumElements(OMEvaluatorValue evaluatorValue)
Get the length of the list.
Definition OM.cpp:286
MLIR_CAPI_EXPORTED MlirIdentifier omClassTypeGetName(MlirType type)
Get the name for a ClassType.
Definition OM.cpp:45
MLIR_CAPI_EXPORTED bool omAttrIsAReferenceAttr(MlirAttribute attr)
Definition OM.cpp:380
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorTupleGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the tuple.
Definition OM.cpp:312
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAList(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
Definition OM.cpp:273
MLIR_CAPI_EXPORTED MlirType omListTypeGetElementType(MlirType type)
Definition OM.cpp:76
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsATuple(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Tuple.
Definition OM.cpp:300
MLIR_CAPI_EXPORTED MlirType omEvaluatorMapGetType(OMEvaluatorValue evaluatorValue)
Get the Type from a Map, which will be a MapType.
Definition OM.cpp:199
MLIR_CAPI_EXPORTED bool omTypeIsAFrozenPathType(MlirType type)
Is the Type a FrozenPathType.
Definition OM.cpp:60
MLIR_CAPI_EXPORTED MlirType omEvaluatorObjectGetType(OMEvaluatorValue object)
Get the Type from an Object, which will be a ClassType.
Definition OM.cpp:179
MLIR_CAPI_EXPORTED bool omAttrIsAIntegerAttr(MlirAttribute attr)
Definition OM.cpp:393
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(OM, om)
MLIR_CAPI_EXPORTED bool omTypeIsAStringType(MlirType type)
Is the Type a StringType.
Definition OM.cpp:81
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorListGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the list.
Definition OM.cpp:293
MLIR_CAPI_EXPORTED bool omTypeIsAClassType(MlirType type)
Is the Type a ClassType.
Definition OM.cpp:39
MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsNull(OMEvaluatorValue object)
Query if the Object is null.
Definition OM.cpp:173
MLIR_CAPI_EXPORTED intptr_t omMapAttrGetNumElements(MlirAttribute attr)
Definition OM.cpp:450
MLIR_CAPI_EXPORTED MlirStringRef omIntegerAttrToString(MlirAttribute attr)
Get a string representation of an om::IntegerAttr.
Definition OM.cpp:408
MLIR_CAPI_EXPORTED MlirIdentifier omMapAttrGetElementKey(MlirAttribute attr, intptr_t pos)
Definition OM.cpp:455
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorValueFromPrimitive(MlirAttribute primitive)
Get the EvaluatorValue from a Primitive value.
Definition OM.cpp:267
MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGet(MlirAttribute attr)
Get an om::IntegerAttr from mlir::IntegerAttr.
Definition OM.cpp:401
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAObject(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
Definition OM.cpp:246
MLIR_CAPI_EXPORTED MlirAttribute omListAttrGetElement(MlirAttribute attr, intptr_t pos)
Definition OM.cpp:430
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAPrimitive(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Primitive.
Definition OM.cpp:252
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:209
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorMapGetKeys(OMEvaluatorValue object)
Get an ArrayAttr with the keys in a Map.
Definition OM.cpp:204
MLIR_CAPI_EXPORTED MlirTypeID omStringTypeGetTypeID(void)
Get the TypeID for a StringType.
Definition OM.cpp:91
MLIR_CAPI_EXPORTED MlirContext omEvaluatorValueGetContext(OMEvaluatorValue evaluatorValue)
Definition OM.cpp:230
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:195
MLIR_CAPI_EXPORTED bool omAttrIsAMapAttr(MlirAttribute attr)
Definition OM.cpp:448
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAReference(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Reference.
Definition OM.cpp:352
MLIR_CAPI_EXPORTED MlirTypeID omAnyTypeGetTypeID(void)
Get the TypeID for an AnyType.
Definition OM.cpp:36
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorPathGetAsString(OMEvaluatorValue evaluatorValue)
Get a string representation of a Path.
Definition OM.cpp:346
MLIR_CAPI_EXPORTED MlirType omStringTypeGet(MlirContext ctx)
Get a StringType.
Definition OM.cpp:86
MLIR_CAPI_EXPORTED MlirAttribute omReferenceAttrGetInnerRef(MlirAttribute attr)
Definition OM.cpp:384
MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGetInt(MlirAttribute attr)
Given an om::IntegerAttr, return the mlir::IntegerAttr.
Definition OM.cpp:397
Definition om.py:1
A value type for use in C APIs that just wraps a pointer to an Object.
Definition OM.h:96
void * ptr
Definition OM.h:97
A value type for use in C APIs that just wraps a pointer to an Evaluator.
Definition OM.h:85
void * ptr
Definition OM.h:86