CIRCT 24.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 an OptionType.
65MLIR_CAPI_EXPORTED bool omTypeIsAOptionType(MlirType type);
66
67/// Get the TypeID for an OptionType.
68MLIR_CAPI_EXPORTED MlirTypeID omOptionTypeGetTypeID(void);
69
70/// Get the element type of an OptionType.
71MLIR_CAPI_EXPORTED MlirType omOptionTypeGetElementType(MlirType type);
72
73/// Get an OptionType.
74MLIR_CAPI_EXPORTED MlirType omOptionTypeGet(MlirType elementType);
75
76/// Is the Type a StringType.
77MLIR_CAPI_EXPORTED bool omTypeIsAStringType(MlirType type);
78
79/// Get the TypeID for a StringType.
80MLIR_CAPI_EXPORTED MlirTypeID omStringTypeGetTypeID(void);
81
82/// Get a StringType.
83MLIR_CAPI_EXPORTED MlirType omStringTypeGet(MlirContext ctx);
84
85//===----------------------------------------------------------------------===//
86// Evaluator data structures.
87//===----------------------------------------------------------------------===//
88
89/// A value type for use in C APIs that just wraps a pointer to an Evaluator.
90/// This is in line with the usual MLIR DEFINE_C_API_STRUCT.
92 void *ptr;
93};
94
95// clang-tidy doesn't respect extern "C".
96// see https://github.com/llvm/llvm-project/issues/35272.
97// NOLINTNEXTLINE(modernize-use-using)
98typedef struct OMEvaluator OMEvaluator;
99
100/// A value type for use in C APIs that just wraps a pointer to an Object.
101/// This is in line with the usual MLIR DEFINE_C_API_STRUCT.
103 void *ptr;
104};
105
106// clang-tidy doesn't respect extern "C".
107// see https://github.com/llvm/llvm-project/issues/35272.
108// NOLINTNEXTLINE(modernize-use-using)
110
111//===----------------------------------------------------------------------===//
112// Evaluator API.
113//===----------------------------------------------------------------------===//
114
115/// Construct an Evaluator with an IR module.
116MLIR_CAPI_EXPORTED OMEvaluator omEvaluatorNew(MlirModule mod);
117
118/// Use the Evaluator to Instantiate an Object from its class name and actual
119/// parameters.
120MLIR_CAPI_EXPORTED OMEvaluatorValue
121omEvaluatorInstantiate(OMEvaluator evaluator, MlirAttribute className,
122 intptr_t nActualParams, OMEvaluatorValue *actualParams);
123
124/// Get the Module the Evaluator is built from.
125MLIR_CAPI_EXPORTED MlirModule omEvaluatorGetModule(OMEvaluator evaluator);
126
127//===----------------------------------------------------------------------===//
128// Object API.
129//===----------------------------------------------------------------------===//
130
131/// Query if the Object is null.
132MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsNull(OMEvaluatorValue object);
133
134/// Get the Type from an Object, which will be a ClassType.
135MLIR_CAPI_EXPORTED MlirType omEvaluatorObjectGetType(OMEvaluatorValue object);
136
137/// Get a field from an Object, which must contain a field of that name.
138MLIR_CAPI_EXPORTED OMEvaluatorValue
139omEvaluatorObjectGetField(OMEvaluatorValue object, MlirAttribute name);
140
141/// Get the object hash.
142MLIR_CAPI_EXPORTED unsigned omEvaluatorObjectGetHash(OMEvaluatorValue object);
143
144/// Check equality of two objects.
145MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsEq(OMEvaluatorValue object,
146 OMEvaluatorValue other);
147
148/// Get all the field names from an Object, can be empty if object has no
149/// fields.
150MLIR_CAPI_EXPORTED MlirAttribute
152
153//===----------------------------------------------------------------------===//
154// EvaluatorValue API.
155//===----------------------------------------------------------------------===//
156
157// Get a context from an EvaluatorValue.
158MLIR_CAPI_EXPORTED MlirContext
160
161// Get Location from an EvaluatorValue.
162MLIR_CAPI_EXPORTED MlirLocation
164
165// Query if the EvaluatorValue is null.
166MLIR_CAPI_EXPORTED bool omEvaluatorValueIsNull(OMEvaluatorValue evaluatorValue);
167
168/// Query if the EvaluatorValue is an Object.
169MLIR_CAPI_EXPORTED bool
171
172/// Query if the EvaluatorValue is a Primitive.
173MLIR_CAPI_EXPORTED bool
175
176/// Get the Primitive from an EvaluatorValue, which must contain a Primitive.
177MLIR_CAPI_EXPORTED MlirAttribute
179
180/// Get the EvaluatorValue from a Primitive value.
181MLIR_CAPI_EXPORTED OMEvaluatorValue
182omEvaluatorValueFromPrimitive(MlirAttribute primitive);
183
184/// Query if the EvaluatorValue is an Object.
185MLIR_CAPI_EXPORTED bool
187
188/// Get the length of the list.
189MLIR_CAPI_EXPORTED intptr_t
191
192/// Get an element of the list.
193MLIR_CAPI_EXPORTED OMEvaluatorValue
194omEvaluatorListGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos);
195
196/// Query if the EvaluatorValue is an Option.
197MLIR_CAPI_EXPORTED bool
199
200/// Create an empty Option. The type must be an OptionType.
201MLIR_CAPI_EXPORTED OMEvaluatorValue
202omEvaluatorOptionGetEmpty(MlirType optionType);
203
204/// Create a present Option. The type must be an OptionType and the payload must
205/// be non-null and valid for its element type and context. Use
206/// omEvaluatorOptionGetEmpty to create an empty Option.
207MLIR_CAPI_EXPORTED OMEvaluatorValue
208omEvaluatorOptionGet(MlirType optionType, OMEvaluatorValue payload);
209
210/// Query whether a fully evaluated, non-unknown Option is present.
211MLIR_CAPI_EXPORTED bool
213
214/// Get the payload of a fully evaluated, non-unknown, present Option.
215MLIR_CAPI_EXPORTED OMEvaluatorValue
217
218/// Query if the EvaluatorValue is a BasePath.
219MLIR_CAPI_EXPORTED bool
221
222/// Create an empty BasePath.
223MLIR_CAPI_EXPORTED OMEvaluatorValue
225
226/// Query if the EvaluatorValue is a Path.
227MLIR_CAPI_EXPORTED bool
229
230/// Get a string representation of a Path.
231MLIR_CAPI_EXPORTED MlirAttribute
233
234/// Query if the EvaluatorValue is Unknown.
235MLIR_CAPI_EXPORTED bool
237
238/// Create an Unknown EvaluatorValue with the given type.
239MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorUnknownGet(MlirContext context,
240 MlirType type);
241
242/// Get the type of an EvaluatorValue.
243MLIR_CAPI_EXPORTED MlirType
245
246//===----------------------------------------------------------------------===//
247// ReferenceAttr API
248//===----------------------------------------------------------------------===//
249
250MLIR_CAPI_EXPORTED bool omAttrIsAReferenceAttr(MlirAttribute attr);
251
252MLIR_CAPI_EXPORTED MlirAttribute omReferenceAttrGetInnerRef(MlirAttribute attr);
253
254//===----------------------------------------------------------------------===//
255// IntegerAttr API
256//===----------------------------------------------------------------------===//
257
258MLIR_CAPI_EXPORTED bool omAttrIsAIntegerAttr(MlirAttribute attr);
259
260/// Given an om::IntegerAttr, return the mlir::IntegerAttr.
261MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGetInt(MlirAttribute attr);
262
263/// Get an om::IntegerAttr from mlir::IntegerAttr.
264MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGet(MlirAttribute attr);
265
266/// Get a string representation of an om::IntegerAttr.
267MLIR_CAPI_EXPORTED MlirStringRef omIntegerAttrToString(MlirAttribute attr);
268
269//===----------------------------------------------------------------------===//
270// ListAttr API
271//===----------------------------------------------------------------------===//
272
273MLIR_CAPI_EXPORTED bool omAttrIsAListAttr(MlirAttribute attr);
274
275MLIR_CAPI_EXPORTED intptr_t omListAttrGetNumElements(MlirAttribute attr);
276
277MLIR_CAPI_EXPORTED MlirAttribute omListAttrGetElement(MlirAttribute attr,
278 intptr_t pos);
279
280MLIR_CAPI_EXPORTED MlirAttribute omListAttrGet(MlirType elementType,
281 intptr_t numElements,
282 const MlirAttribute *elements);
283
284#ifdef __cplusplus
285}
286#endif
287
288#endif // CIRCT_C_DIALECT_OM_H
MlirType uint64_t numElements
Definition CHIRRTL.cpp:30
MlirType elementType
Definition CHIRRTL.cpp:29
static std::unique_ptr< Context > context
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorOptionGetValue(OMEvaluatorValue evaluatorValue)
Get the payload of a fully evaluated, non-unknown, present Option.
Definition OM.cpp:321
MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsEq(OMEvaluatorValue object, OMEvaluatorValue other)
Check equality of two objects.
Definition OM.cpp:199
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsUnknown(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is Unknown.
Definition OM.cpp:344
MLIR_CAPI_EXPORTED intptr_t omListAttrGetNumElements(MlirAttribute attr)
Definition OM.cpp:412
MLIR_CAPI_EXPORTED unsigned omEvaluatorObjectGetHash(OMEvaluatorValue object)
Get the object hash.
Definition OM.cpp:194
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:422
MLIR_CAPI_EXPORTED bool omAttrIsAListAttr(MlirAttribute attr)
Definition OM.cpp:408
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:326
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsNull(OMEvaluatorValue evaluatorValue)
Definition OM.cpp:241
MLIR_CAPI_EXPORTED OMEvaluator omEvaluatorNew(MlirModule mod)
Construct an Evaluator with an IR module.
Definition OM.cpp:138
MLIR_CAPI_EXPORTED MlirLocation omEvaluatorValueGetLoc(OMEvaluatorValue evaluatorValue)
Definition OM.cpp:236
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorValueGetPrimitive(OMEvaluatorValue evaluatorValue)
Get the Primitive from an EvaluatorValue, which must contain a Primitive.
Definition OM.cpp:259
MLIR_CAPI_EXPORTED bool omTypeIsAOptionType(MlirType type)
Is the Type an OptionType.
Definition OM.cpp:81
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorBasePathGetEmpty(MlirContext context)
Create an empty BasePath.
Definition OM.cpp:330
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAPath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Path.
Definition OM.cpp:334
MLIR_CAPI_EXPORTED bool omTypeIsAAnyType(MlirType type)
Is the Type an AnyType.
Definition OM.cpp:33
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:173
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:145
MLIR_CAPI_EXPORTED MlirTypeID omClassTypeGetTypeID(void)
Get the TypeID for a ClassType.
Definition OM.cpp:42
MLIR_CAPI_EXPORTED intptr_t omEvaluatorListGetNumElements(OMEvaluatorValue evaluatorValue)
Get the length of the list.
Definition OM.cpp:287
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:367
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAList(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
Definition OM.cpp:274
MLIR_CAPI_EXPORTED MlirType omListTypeGetElementType(MlirType type)
Definition OM.cpp:76
MLIR_CAPI_EXPORTED MlirType omOptionTypeGetElementType(MlirType type)
Get the element type of an OptionType.
Definition OM.cpp:89
MLIR_CAPI_EXPORTED MlirTypeID omOptionTypeGetTypeID(void)
Get the TypeID for an OptionType.
Definition OM.cpp:86
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:189
MLIR_CAPI_EXPORTED bool omAttrIsAIntegerAttr(MlirAttribute attr)
Definition OM.cpp:380
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(OM, om)
MLIR_CAPI_EXPORTED bool omTypeIsAStringType(MlirType type)
Is the Type a StringType.
Definition OM.cpp:99
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorListGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the list.
Definition OM.cpp:294
MLIR_CAPI_EXPORTED bool omTypeIsAClassType(MlirType type)
Is the Type a ClassType.
Definition OM.cpp:39
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorUnknownGet(MlirContext context, MlirType type)
Create an Unknown EvaluatorValue with the given type.
Definition OM.cpp:349
MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsNull(OMEvaluatorValue object)
Query if the Object is null.
Definition OM.cpp:183
MLIR_CAPI_EXPORTED MlirType omOptionTypeGet(MlirType elementType)
Get an OptionType.
Definition OM.cpp:94
MLIR_CAPI_EXPORTED bool omEvaluatorOptionHasValue(OMEvaluatorValue evaluatorValue)
Query whether a fully evaluated, non-unknown Option is present.
Definition OM.cpp:317
MLIR_CAPI_EXPORTED MlirStringRef omIntegerAttrToString(MlirAttribute attr)
Get a string representation of an om::IntegerAttr.
Definition OM.cpp:395
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorOptionGet(MlirType optionType, OMEvaluatorValue payload)
Create a present Option.
Definition OM.cpp:310
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorValueFromPrimitive(MlirAttribute primitive)
Get the EvaluatorValue from a Primitive value.
Definition OM.cpp:268
MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGet(MlirAttribute attr)
Get an om::IntegerAttr from mlir::IntegerAttr.
Definition OM.cpp:388
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAObject(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
Definition OM.cpp:247
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorOptionGetEmpty(MlirType optionType)
Create an empty Option. The type must be an OptionType.
Definition OM.cpp:304
MLIR_CAPI_EXPORTED MlirAttribute omListAttrGetElement(MlirAttribute attr, intptr_t pos)
Definition OM.cpp:417
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAPrimitive(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Primitive.
Definition OM.cpp:253
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:210
MLIR_CAPI_EXPORTED MlirType omEvaluatorValueGetType(OMEvaluatorValue evaluatorValue)
Get the type of an EvaluatorValue.
Definition OM.cpp:359
MLIR_CAPI_EXPORTED MlirTypeID omStringTypeGetTypeID(void)
Get the TypeID for a StringType.
Definition OM.cpp:109
MLIR_CAPI_EXPORTED MlirContext omEvaluatorValueGetContext(OMEvaluatorValue evaluatorValue)
Definition OM.cpp:231
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:205
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAOption(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Option.
Definition OM.cpp:300
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:338
MLIR_CAPI_EXPORTED MlirType omStringTypeGet(MlirContext ctx)
Get a StringType.
Definition OM.cpp:104
MLIR_CAPI_EXPORTED MlirAttribute omReferenceAttrGetInnerRef(MlirAttribute attr)
Definition OM.cpp:371
MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGetInt(MlirAttribute attr)
Given an om::IntegerAttr, return the mlir::IntegerAttr.
Definition OM.cpp:384
Definition om.py:1
A value type for use in C APIs that just wraps a pointer to an Object.
Definition OM.h:102
void * ptr
Definition OM.h:103
A value type for use in C APIs that just wraps a pointer to an Evaluator.
Definition OM.h:91
void * ptr
Definition OM.h:92