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