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