CIRCT 23.0.0git
Loading...
Searching...
No Matches
OMModule.cpp
Go to the documentation of this file.
1//===- OMModule.cpp - OM API nanobind module ------------------------------===//
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#include "CIRCTModules.h"
10#include "circt-c/Dialect/HW.h"
11#include "circt-c/Dialect/OM.h"
12#include "mlir-c/BuiltinAttributes.h"
13#include "mlir-c/BuiltinTypes.h"
14#include "mlir-c/IR.h"
15#include "mlir/Bindings/Python/NanobindAdaptors.h"
16#include "mlir/Bindings/Python/NanobindUtils.h"
17#include <nanobind/nanobind.h>
18#include <nanobind/stl/variant.h>
19#include <nanobind/stl/vector.h>
20namespace nb = nanobind;
21
22using namespace mlir;
23using namespace mlir::python;
24using namespace mlir::python::nanobind_adaptors;
25
26namespace {
27
28struct List;
29struct Object;
30struct BasePath;
31struct Path;
32
33/// Represents a value that is not known because it is an unsupplied input, or
34/// derived from unsupplied inputs.
35struct Unknown {
36 Unknown(MlirType type) : type(type) {}
37 MlirType getType() const { return type; }
38
39private:
40 MlirType type;
41};
42
43/// These are the Python types that are represented by the different primitive
44/// OMEvaluatorValues as Attributes.
45using PythonPrimitive = std::variant<nb::int_, nb::float_, nb::str, nb::bool_,
46 nb::tuple, nb::list, nb::dict>;
47
48/// None is used to by nanobind when default initializing a PythonValue. The
49/// order of types in the variant matters here, and we want nanobind to try
50/// casting to the Python classes defined in this file first, before
51/// MlirAttribute and the upstream MLIR type casters. If the MlirAttribute
52/// is tried first, then we can hit an assert inside the MLIR codebase.
53struct None {};
54using PythonValue =
55 std::variant<None, Object, List, BasePath, Path, Unknown, PythonPrimitive>;
56
57/// Map an opaque OMEvaluatorValue into a python value.
58PythonValue omEvaluatorValueToPythonValue(OMEvaluatorValue result);
59OMEvaluatorValue pythonValueToOMEvaluatorValue(PythonValue result,
60 MlirContext ctx);
61static PythonPrimitive omPrimitiveToPythonValue(MlirAttribute attr);
62static MlirAttribute omPythonValueToPrimitive(PythonPrimitive value,
63 MlirContext ctx);
64
65/// Provides a List class by simply wrapping the OMObject CAPI.
66struct List {
67 // Instantiate a List with a reference to the underlying OMEvaluatorValue.
68 List(OMEvaluatorValue value) : value(value) {}
69
70 /// Return the number of elements.
71 intptr_t getNumElements() { return omEvaluatorListGetNumElements(value); }
72
73 PythonValue getElement(intptr_t i);
74 OMEvaluatorValue getValue() const { return value; }
75
76private:
77 // The underlying CAPI value.
78 OMEvaluatorValue value;
79};
80
81/// Provides a BasePath class by simply wrapping the OMObject CAPI.
82struct BasePath {
83 /// Instantiate a BasePath with a reference to the underlying
84 /// OMEvaluatorValue.
85 BasePath(OMEvaluatorValue value) : value(value) {}
86
87 static BasePath getEmpty(MlirContext context) {
88 return BasePath(omEvaluatorBasePathGetEmpty(context));
89 }
90
91 /// Return a context from an underlying value.
92 MlirContext getContext() const { return omEvaluatorValueGetContext(value); }
93
94 OMEvaluatorValue getValue() const { return value; }
95
96private:
97 // The underlying CAPI value.
98 OMEvaluatorValue value;
99};
100
101/// Provides a Path class by simply wrapping the OMObject CAPI.
102struct Path {
103 /// Instantiate a Path with a reference to the underlying OMEvaluatorValue.
104 Path(OMEvaluatorValue value) : value(value) {}
105
106 /// Return a context from an underlying value.
107 MlirContext getContext() const { return omEvaluatorValueGetContext(value); }
108
109 OMEvaluatorValue getValue() const { return value; }
110
111 std::string dunderStr() {
112 auto ref = mlirStringAttrGetValue(omEvaluatorPathGetAsString(getValue()));
113 return std::string(ref.data, ref.length);
114 }
115
116private:
117 // The underlying CAPI value.
118 OMEvaluatorValue value;
119};
120
121/// Provides an Object class by simply wrapping the OMObject CAPI.
122struct Object {
123 // Instantiate an Object with a reference to the underlying OMObject.
124 Object(OMEvaluatorValue value) : value(value) {}
125
126 /// Get the Type from an Object, which will be a ClassType.
127 MlirType getType() { return omEvaluatorObjectGetType(value); }
128
129 /// Get the Location from an Object, which will be an MlirLocation.
130 MlirLocation getLocation() { return omEvaluatorValueGetLoc(value); }
131
132 // Get the field location info.
133 MlirLocation getFieldLoc(const std::string &name) {
134 // Wrap the requested field name in an attribute.
135 MlirContext context = mlirTypeGetContext(omEvaluatorObjectGetType(value));
136 MlirStringRef cName = mlirStringRefCreateFromCString(name.c_str());
137 MlirAttribute nameAttr = mlirStringAttrGet(context, cName);
138
139 // Get the field's ObjectValue via the CAPI.
140 OMEvaluatorValue result = omEvaluatorObjectGetField(value, nameAttr);
141
142 return omEvaluatorValueGetLoc(result);
143 }
144
145 // Get a field from the Object, using nanobind's support for variant to return
146 // a Python object that is either an Object or Attribute.
147 PythonValue getField(const std::string &name) {
148 // Wrap the requested field name in an attribute.
149 MlirContext context = mlirTypeGetContext(omEvaluatorObjectGetType(value));
150 MlirStringRef cName = mlirStringRefCreateFromCString(name.c_str());
151 MlirAttribute nameAttr = mlirStringAttrGet(context, cName);
152
153 // Get the field's ObjectValue via the CAPI.
154 OMEvaluatorValue result = omEvaluatorObjectGetField(value, nameAttr);
155
156 return omEvaluatorValueToPythonValue(result);
157 }
158
159 // Get a list with the names of all the fields in the Object.
160 std::vector<std::string> getFieldNames() {
161 MlirAttribute fieldNames = omEvaluatorObjectGetFieldNames(value);
162 intptr_t numFieldNames = mlirArrayAttrGetNumElements(fieldNames);
163
164 std::vector<std::string> pyFieldNames;
165 for (intptr_t i = 0; i < numFieldNames; ++i) {
166 MlirAttribute fieldName = mlirArrayAttrGetElement(fieldNames, i);
167 MlirStringRef fieldNameStr = mlirStringAttrGetValue(fieldName);
168 pyFieldNames.emplace_back(fieldNameStr.data, fieldNameStr.length);
169 }
170
171 return pyFieldNames;
172 }
173
174 // Get the hash of the object
175 unsigned getHash() { return omEvaluatorObjectGetHash(value); }
176
177 // Check the equality of the underlying values.
178 bool eq(Object &other) { return omEvaluatorObjectIsEq(value, other.value); }
179
180 OMEvaluatorValue getValue() const { return value; }
181
182private:
183 // The underlying CAPI OMObject.
184 OMEvaluatorValue value;
185};
186
187/// Provides an Evaluator class by simply wrapping the OMEvaluator CAPI.
188struct Evaluator {
189 // Instantiate an Evaluator with a reference to the underlying OMEvaluator.
190 Evaluator(MlirModule mod) : evaluator(omEvaluatorNew(mod)) {}
191
192 // Instantiate an Object.
193 Object instantiate(MlirAttribute className,
194 std::vector<PythonValue> actualParams) {
195 std::vector<OMEvaluatorValue> values;
196 for (auto &param : actualParams)
197 values.push_back(pythonValueToOMEvaluatorValue(
198 param, mlirModuleGetContext(getModule())));
199
200 // Instantiate the Object via the CAPI.
202 evaluator, className, values.size(), values.data());
203
204 // If the Object is null, something failed. Diagnostic handling is
205 // implemented in pure Python, so nothing to do here besides throwing an
206 // error to halt execution.
207 if (omEvaluatorObjectIsNull(result))
208 throw nb::value_error(
209 "unable to instantiate object, see previous error(s)");
210
211 // Return a new Object.
212 return Object(result);
213 }
214
215 // Get the Module the Evaluator is built from.
216 MlirModule getModule() { return omEvaluatorGetModule(evaluator); }
217
218private:
219 // The underlying CAPI OMEvaluator.
220 OMEvaluator evaluator;
221};
222
223class PyListAttrIterator {
224public:
225 PyListAttrIterator(MlirAttribute attr) : attr(std::move(attr)) {}
226
227 PyListAttrIterator &dunderIter() { return *this; }
228
229 MlirAttribute dunderNext() {
230 if (nextIndex >= omListAttrGetNumElements(attr))
231 throw nb::stop_iteration();
232 return omListAttrGetElement(attr, nextIndex++);
233 }
234
235 static void bind(nb::module_ &m) {
236 nb::class_<PyListAttrIterator>(m, "ListAttributeIterator")
237 .def("__iter__", &PyListAttrIterator::dunderIter)
238 .def("__next__", &PyListAttrIterator::dunderNext);
239 }
240
241private:
242 MlirAttribute attr;
243 intptr_t nextIndex = 0;
244};
245
246PythonValue List::getElement(intptr_t i) {
247 return omEvaluatorValueToPythonValue(omEvaluatorListGetElement(value, i));
248}
249// Convert a generic MLIR Attribute to a PythonValue. This is basically a C++
250// fast path of the parts of attribute_to_var that we use in the OM dialect.
251static PythonPrimitive omPrimitiveToPythonValue(MlirAttribute attr) {
252 if (omAttrIsAIntegerAttr(attr)) {
253 auto strRef = omIntegerAttrToString(attr);
254 return nb::int_(nb::str(strRef.data, strRef.length));
255 }
256
257 if (mlirAttributeIsAFloat(attr)) {
258 return nb::float_(mlirFloatAttrGetValueDouble(attr));
259 }
260
261 if (mlirAttributeIsAString(attr)) {
262 auto strRef = mlirStringAttrGetValue(attr);
263 return nb::str(strRef.data, strRef.length);
264 }
265
266 // BoolAttr's are IntegerAttr's, check this first.
267 if (mlirAttributeIsABool(attr)) {
268 return nb::bool_(mlirBoolAttrGetValue(attr));
269 }
270
271 if (mlirAttributeIsAInteger(attr)) {
272 MlirType type = mlirAttributeGetType(attr);
273 if (mlirTypeIsAIndex(type) || mlirIntegerTypeIsSignless(type))
274 return nb::int_(mlirIntegerAttrGetValueInt(attr));
275 if (mlirIntegerTypeIsSigned(type))
276 return nb::int_(mlirIntegerAttrGetValueSInt(attr));
277 return nb::int_(mlirIntegerAttrGetValueUInt(attr));
278 }
279
280 if (omAttrIsAReferenceAttr(attr)) {
281 auto innerRef = omReferenceAttrGetInnerRef(attr);
282 auto moduleStrRef =
283 mlirStringAttrGetValue(hwInnerRefAttrGetModule(innerRef));
284 auto nameStrRef = mlirStringAttrGetValue(hwInnerRefAttrGetName(innerRef));
285 auto moduleStr = nb::str(moduleStrRef.data, moduleStrRef.length);
286 auto nameStr = nb::str(nameStrRef.data, nameStrRef.length);
287 return nb::make_tuple(moduleStr, nameStr);
288 }
289
290 if (omAttrIsAListAttr(attr)) {
291 nb::list results;
292 for (intptr_t i = 0, e = omListAttrGetNumElements(attr); i < e; ++i)
293 results.append(omPrimitiveToPythonValue(omListAttrGetElement(attr, i)));
294 return results;
295 }
296
297 mlirAttributeDump(attr);
298 throw nb::type_error("Unexpected OM primitive attribute");
299}
300
301// Convert a primitive PythonValue to a generic MLIR Attribute. This is
302// basically a C++ fast path of the parts of var_to_attribute that we use in the
303// OM dialect.
304static MlirAttribute omPythonValueToPrimitive(PythonPrimitive value,
305 MlirContext ctx) {
306 if (auto *intValue = std::get_if<nb::int_>(&value)) {
307 auto intType = mlirIntegerTypeSignedGet(ctx, 64);
308 auto intAttr = mlirIntegerAttrGet(intType, nb::cast<int64_t>(*intValue));
309 return omIntegerAttrGet(intAttr);
310 }
311
312 if (auto *attr = std::get_if<nb::float_>(&value)) {
313 auto floatType = mlirF64TypeGet(ctx);
314 return mlirFloatAttrDoubleGet(ctx, floatType, nb::cast<double>(*attr));
315 }
316
317 if (auto *attr = std::get_if<nb::str>(&value)) {
318 auto str = nb::cast<std::string>(*attr);
319 auto strRef = mlirStringRefCreate(str.data(), str.length());
320 auto omStringType = omStringTypeGet(ctx);
321 return mlirStringAttrTypedGet(omStringType, strRef);
322 }
323
324 if (auto *attr = std::get_if<nb::bool_>(&value)) {
325 return mlirBoolAttrGet(ctx, nb::cast<bool>(*attr));
326 }
327
328 // For a python list try constructing OM list attribute. The element
329 // type must be uniform.
330 if (auto *attr = std::get_if<nb::list>(&value)) {
331 if (attr->size() == 0)
332 throw nb::type_error("Empty list is prohibited now");
333
334 std::vector<MlirAttribute> attrs;
335 attrs.reserve(attr->size());
336 std::optional<MlirType> elemenType;
337 for (auto v : *attr) {
338 attrs.push_back(
339 omPythonValueToPrimitive(nb::cast<PythonPrimitive>(v), ctx));
340 if (!elemenType)
341 elemenType = mlirAttributeGetType(attrs.back());
342 else if (!mlirTypeEqual(*elemenType,
343 mlirAttributeGetType(attrs.back()))) {
344 throw nb::type_error("List elements must be of the same type");
345 }
346 }
347 return omListAttrGet(*elemenType, attrs.size(), attrs.data());
348 }
349
350 throw nb::type_error("Unexpected OM primitive value");
351}
352
353PythonValue omEvaluatorValueToPythonValue(OMEvaluatorValue result) {
354 // If the result is null, something failed. Diagnostic handling is
355 // implemented in pure Python, so nothing to do here besides throwing an
356 // error to halt execution.
357 if (omEvaluatorValueIsNull(result))
358 throw nb::value_error("unable to get field, see previous error(s)");
359
360 // If the field was an Object, return a new Object.
361 if (omEvaluatorValueIsAObject(result))
362 return Object(result);
363
364 // If the field was a list, return a new List.
365 if (omEvaluatorValueIsAList(result))
366 return List(result);
367
368 // If the field was a base path, return a new BasePath.
369 if (omEvaluatorValueIsABasePath(result))
370 return BasePath(result);
371
372 // If the field was a path, return a new Path.
373 if (omEvaluatorValueIsAPath(result))
374 return Path(result);
375
376 if (omEvaluatorValueIsUnknown(result))
377 return Unknown(omEvaluatorValueGetType(result));
378
380 return omEvaluatorValueToPythonValue(
382
383 // If the field was a primitive, return the Attribute.
385 return omPrimitiveToPythonValue(omEvaluatorValueGetPrimitive(result));
386}
387
388OMEvaluatorValue pythonValueToOMEvaluatorValue(PythonValue result,
389 MlirContext ctx) {
390 if (auto *list = std::get_if<List>(&result))
391 return list->getValue();
392
393 if (auto *basePath = std::get_if<BasePath>(&result))
394 return basePath->getValue();
395
396 if (auto *path = std::get_if<Path>(&result))
397 return path->getValue();
398
399 if (auto *object = std::get_if<Object>(&result))
400 return object->getValue();
401
402 if (auto *unknown = std::get_if<Unknown>(&result))
403 return omEvaluatorUnknownGet(ctx, unknown->getType());
404
405 auto primitive = std::get<PythonPrimitive>(result);
407 omPythonValueToPrimitive(primitive, ctx));
408}
409
410} // namespace
411
412/// Populate the OM Python module.
414 m.doc() = "OM dialect Python native extension";
415
416 // Add the Evaluator class definition.
417 nb::class_<Evaluator>(m, "Evaluator")
418 .def(nb::init<MlirModule>(), nb::arg("module"))
419 .def("instantiate", &Evaluator::instantiate, "Instantiate an Object",
420 nb::arg("class_name"), nb::arg("actual_params"))
421 .def_prop_ro("module", &Evaluator::getModule,
422 "The Module the Evaluator is built from");
423
424 // Add the List class definition.
425 nb::class_<List>(m, "List")
426 .def(nb::init<List>(), nb::arg("list"))
427 .def("__getitem__", &List::getElement)
428 .def("__len__", &List::getNumElements);
429
430 // Add the BasePath class definition.
431 nb::class_<BasePath>(m, "BasePath")
432 .def(nb::init<BasePath>(), nb::arg("basepath"))
433 .def_static("get_empty", &BasePath::getEmpty,
434 nb::arg("context") = nb::none());
435
436 // Add the Path class definition.
437 nb::class_<Path>(m, "Path")
438 .def(nb::init<Path>(), nb::arg("path"))
439 .def("__str__", &Path::dunderStr);
440
441 // Add the Unknown sentinel class definition.
442 nb::class_<Unknown>(m, "Unknown")
443 .def(nb::init<MlirType>(), nb::arg("type"))
444 .def_prop_ro("type", &Unknown::getType)
445 .def("__repr__", [](const Unknown &u) {
446 PyPrintAccumulator printAccum;
447 printAccum.parts.append("Unknown(");
448 mlirTypePrint(u.getType(), printAccum.getCallback(),
449 printAccum.getUserData());
450 printAccum.parts.append(")");
451 return printAccum.join();
452 });
453
454 // Add the Object class definition.
455 nb::class_<Object>(m, "Object")
456 .def(nb::init<Object>(), nb::arg("object"))
457 .def("__getattr__", &Object::getField, "Get a field from an Object",
458 nb::arg("name"))
459 .def("get_field_loc", &Object::getFieldLoc,
460 "Get the location of a field from an Object", nb::arg("name"))
461 .def_prop_ro("field_names", &Object::getFieldNames,
462 "Get field names from an Object")
463 .def_prop_ro("type", &Object::getType, "The Type of the Object")
464 .def_prop_ro("loc", &Object::getLocation, "The Location of the Object")
465 .def("__hash__", &Object::getHash, "Get object hash")
466 .def("__eq__", &Object::eq, "Check if two objects are same");
467
468 // Add the ReferenceAttr definition
469 mlir_attribute_subclass(m, "ReferenceAttr", omAttrIsAReferenceAttr)
470 .def_property_readonly("inner_ref", [](MlirAttribute self) {
471 return omReferenceAttrGetInnerRef(self);
472 });
473
474 // Add the IntegerAttr definition
475 mlir_attribute_subclass(m, "OMIntegerAttr", omAttrIsAIntegerAttr)
476 .def_classmethod("get",
477 [](nb::object cls, MlirAttribute intVal) {
478 return cls(omIntegerAttrGet(intVal));
479 })
480 .def_property_readonly(
481 "integer",
482 [](MlirAttribute self) { return omIntegerAttrGetInt(self); })
483 .def("__str__", [](MlirAttribute self) {
484 MlirStringRef str = omIntegerAttrToString(self);
485 return std::string(str.data, str.length);
486 });
487
488 // Add the OMListAttr definition
489 mlir_attribute_subclass(m, "ListAttr", omAttrIsAListAttr)
490 .def("__getitem__", &omListAttrGetElement)
491 .def("__len__", &omListAttrGetNumElements)
492 .def("__iter__",
493 [](MlirAttribute arr) { return PyListAttrIterator(arr); });
494 PyListAttrIterator::bind(m);
495
496 // Add the AnyType class definition.
497 mlir_type_subclass(m, "AnyType", omTypeIsAAnyType, omAnyTypeGetTypeID);
498
499 // Add the ClassType class definition.
500 mlir_type_subclass(m, "ClassType", omTypeIsAClassType, omClassTypeGetTypeID)
501 .def_property_readonly("name", [](MlirType type) {
502 MlirStringRef name = mlirIdentifierStr(omClassTypeGetName(type));
503 return std::string(name.data, name.length);
504 });
505
506 // Add the BasePathType class definition.
507 mlir_type_subclass(m, "BasePathType", omTypeIsAFrozenBasePathType,
509
510 // Add the ListType class definition.
511 mlir_type_subclass(m, "ListType", omTypeIsAListType, omListTypeGetTypeID)
512 .def_property_readonly("element_type", omListTypeGetElementType);
513
514 // Add the PathType class definition.
515 mlir_type_subclass(m, "PathType", omTypeIsAFrozenPathType,
517}
assert(baseType &&"element must be base type")
static std::unique_ptr< Context > context
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute)
Definition HW.cpp:308
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute)
Definition HW.cpp:304
MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsEq(OMEvaluatorValue object, OMEvaluatorValue other)
Check equality of two objects.
Definition OM.cpp:181
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsUnknown(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is Unknown.
Definition OM.cpp:325
MLIR_CAPI_EXPORTED intptr_t omListAttrGetNumElements(MlirAttribute attr)
Definition OM.cpp:393
MLIR_CAPI_EXPORTED unsigned omEvaluatorObjectGetHash(OMEvaluatorValue object)
Get the object hash.
Definition OM.cpp:176
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:403
MLIR_CAPI_EXPORTED bool omAttrIsAListAttr(MlirAttribute attr)
Definition OM.cpp:389
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:282
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsNull(OMEvaluatorValue evaluatorValue)
Definition OM.cpp:223
MLIR_CAPI_EXPORTED OMEvaluator omEvaluatorNew(MlirModule mod)
Construct an Evaluator with an IR module.
Definition OM.cpp:120
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorValueGetReferenceValue(OMEvaluatorValue evaluatorValue)
Dereference a Reference EvaluatorValue.
Definition OM.cpp:307
MLIR_CAPI_EXPORTED MlirLocation omEvaluatorValueGetLoc(OMEvaluatorValue evaluatorValue)
Definition OM.cpp:218
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorValueGetPrimitive(OMEvaluatorValue evaluatorValue)
Get the Primitive from an EvaluatorValue, which must contain a Primitive.
Definition OM.cpp:241
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorBasePathGetEmpty(MlirContext context)
Create an empty BasePath.
Definition OM.cpp:286
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAPath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Path.
Definition OM.cpp:290
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:155
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:127
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:269
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:348
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAList(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
Definition OM.cpp:256
MLIR_CAPI_EXPORTED MlirType omListTypeGetElementType(MlirType type)
Definition OM.cpp:76
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:171
MLIR_CAPI_EXPORTED bool omAttrIsAIntegerAttr(MlirAttribute attr)
Definition OM.cpp:361
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorListGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the list.
Definition OM.cpp:276
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:330
MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsNull(OMEvaluatorValue object)
Query if the Object is null.
Definition OM.cpp:165
MLIR_CAPI_EXPORTED MlirStringRef omIntegerAttrToString(MlirAttribute attr)
Get a string representation of an om::IntegerAttr.
Definition OM.cpp:376
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorValueFromPrimitive(MlirAttribute primitive)
Get the EvaluatorValue from a Primitive value.
Definition OM.cpp:250
MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGet(MlirAttribute attr)
Get an om::IntegerAttr from mlir::IntegerAttr.
Definition OM.cpp:369
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAObject(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
Definition OM.cpp:229
MLIR_CAPI_EXPORTED MlirAttribute omListAttrGetElement(MlirAttribute attr, intptr_t pos)
Definition OM.cpp:398
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAPrimitive(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Primitive.
Definition OM.cpp:235
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:192
MLIR_CAPI_EXPORTED MlirType omEvaluatorValueGetType(OMEvaluatorValue evaluatorValue)
Get the type of an EvaluatorValue.
Definition OM.cpp:340
MLIR_CAPI_EXPORTED MlirContext omEvaluatorValueGetContext(OMEvaluatorValue evaluatorValue)
Definition OM.cpp:213
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:187
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAReference(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Reference.
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:294
MLIR_CAPI_EXPORTED MlirType omStringTypeGet(MlirContext ctx)
Get a StringType.
Definition OM.cpp:86
MLIR_CAPI_EXPORTED MlirAttribute omReferenceAttrGetInnerRef(MlirAttribute attr)
Definition OM.cpp:352
MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGetInt(MlirAttribute attr)
Given an om::IntegerAttr, return the mlir::IntegerAttr.
Definition OM.cpp:365
evaluator::ObjectValue Object
Definition Evaluator.h:366
void populateDialectOMSubmodule(nanobind::module_ &m)
A value type for use in C APIs that just wraps a pointer to an Object.
Definition OM.h:90
A value type for use in C APIs that just wraps a pointer to an Evaluator.
Definition OM.h:79