11 #include <pybind11/cast.h>
12 #include <pybind11/detail/common.h>
13 #include <pybind11/pybind11.h>
14 #include <pybind11/pytypes.h>
28 #include "llvm/ADT/Hashing.h"
29 #include "llvm/ADT/SmallVector.h"
30 #include "llvm/ADT/StringRef.h"
31 #include "llvm/ADT/Twine.h"
38 using llvm::StringRef;
42 R
"(Dumps a debug representation of the object to stderr.)";
48 template <
typename PyType,
typename CType>
52 result.reserve(py::len(list));
53 for (py::handle item : list) {
55 result.push_back(item.cast<
PyType>());
56 }
catch (py::cast_error &err) {
57 std::string msg = (llvm::Twine(
"Invalid expression when ") + action +
58 " (" + err.what() +
")")
60 throw py::cast_error(msg);
61 }
catch (py::reference_cast_error &err) {
62 std::string msg = (llvm::Twine(
"Invalid expression (None?) when ") +
63 action +
" (" + err.what() +
")")
65 throw py::cast_error(msg);
70 template <
typename PermutationTy>
73 for (
auto val : permutation) {
74 if (val < permutation.size()) {
90 template <
typename DerivedTy,
typename BaseTy = PyAffineExpr>
91 class PyConcreteAffineExpr :
public BaseTy {
97 using ClassTy = py::class_<DerivedTy, BaseTy>;
98 using IsAFunctionTy = bool (*)(MlirAffineExpr);
100 PyConcreteAffineExpr() =
default;
101 PyConcreteAffineExpr(
PyMlirContextRef contextRef, MlirAffineExpr affineExpr)
102 : BaseTy(std::move(contextRef), affineExpr) {}
104 : PyConcreteAffineExpr(orig.
getContext(), castFrom(orig)) {}
107 if (!DerivedTy::isaFunction(orig)) {
108 auto origRepr = py::repr(py::cast(orig)).cast<std::string>();
109 throw py::value_error((Twine(
"Cannot cast affine expression to ") +
110 DerivedTy::pyClassName +
" (from " + origRepr +
117 static void bind(py::module &m) {
118 auto cls = ClassTy(m, DerivedTy::pyClassName, py::module_local());
119 cls.def(py::init<PyAffineExpr &>(), py::arg(
"expr"));
123 return DerivedTy::isaFunction(otherAffineExpr);
126 DerivedTy::bindDerived(cls);
130 static void bindDerived(ClassTy &m) {}
133 class PyAffineConstantExpr :
public PyConcreteAffineExpr<PyAffineConstantExpr> {
136 static constexpr
const char *pyClassName =
"AffineConstantExpr";
137 using PyConcreteAffineExpr::PyConcreteAffineExpr;
139 static PyAffineConstantExpr
get(intptr_t value,
141 MlirAffineExpr affineExpr =
143 return PyAffineConstantExpr(context->getRef(), affineExpr);
146 static void bindDerived(ClassTy &c) {
148 py::arg(
"context") = py::none());
149 c.def_property_readonly(
"value", [](PyAffineConstantExpr &
self) {
155 class PyAffineDimExpr :
public PyConcreteAffineExpr<PyAffineDimExpr> {
158 static constexpr
const char *pyClassName =
"AffineDimExpr";
159 using PyConcreteAffineExpr::PyConcreteAffineExpr;
163 return PyAffineDimExpr(context->getRef(), affineExpr);
166 static void bindDerived(ClassTy &c) {
168 py::arg(
"context") = py::none());
169 c.def_property_readonly(
"position", [](PyAffineDimExpr &
self) {
175 class PyAffineSymbolExpr :
public PyConcreteAffineExpr<PyAffineSymbolExpr> {
178 static constexpr
const char *pyClassName =
"AffineSymbolExpr";
179 using PyConcreteAffineExpr::PyConcreteAffineExpr;
183 return PyAffineSymbolExpr(context->getRef(), affineExpr);
186 static void bindDerived(ClassTy &c) {
188 py::arg(
"context") = py::none());
189 c.def_property_readonly(
"position", [](PyAffineSymbolExpr &
self) {
195 class PyAffineBinaryExpr :
public PyConcreteAffineExpr<PyAffineBinaryExpr> {
198 static constexpr
const char *pyClassName =
"AffineBinaryExpr";
199 using PyConcreteAffineExpr::PyConcreteAffineExpr;
211 static void bindDerived(ClassTy &c) {
212 c.def_property_readonly(
"lhs", &PyAffineBinaryExpr::lhs);
213 c.def_property_readonly(
"rhs", &PyAffineBinaryExpr::rhs);
217 class PyAffineAddExpr
218 :
public PyConcreteAffineExpr<PyAffineAddExpr, PyAffineBinaryExpr> {
221 static constexpr
const char *pyClassName =
"AffineAddExpr";
222 using PyConcreteAffineExpr::PyConcreteAffineExpr;
226 return PyAffineAddExpr(lhs.
getContext(), expr);
229 static PyAffineAddExpr getRHSConstant(
PyAffineExpr lhs, intptr_t rhs) {
232 return PyAffineAddExpr(lhs.
getContext(), expr);
235 static PyAffineAddExpr getLHSConstant(intptr_t lhs,
PyAffineExpr rhs) {
238 return PyAffineAddExpr(rhs.
getContext(), expr);
241 static void bindDerived(ClassTy &c) {
246 class PyAffineMulExpr
247 :
public PyConcreteAffineExpr<PyAffineMulExpr, PyAffineBinaryExpr> {
250 static constexpr
const char *pyClassName =
"AffineMulExpr";
251 using PyConcreteAffineExpr::PyConcreteAffineExpr;
255 return PyAffineMulExpr(lhs.
getContext(), expr);
258 static PyAffineMulExpr getRHSConstant(
PyAffineExpr lhs, intptr_t rhs) {
261 return PyAffineMulExpr(lhs.
getContext(), expr);
264 static PyAffineMulExpr getLHSConstant(intptr_t lhs,
PyAffineExpr rhs) {
267 return PyAffineMulExpr(rhs.
getContext(), expr);
270 static void bindDerived(ClassTy &c) {
275 class PyAffineModExpr
276 :
public PyConcreteAffineExpr<PyAffineModExpr, PyAffineBinaryExpr> {
279 static constexpr
const char *pyClassName =
"AffineModExpr";
280 using PyConcreteAffineExpr::PyConcreteAffineExpr;
284 return PyAffineModExpr(lhs.
getContext(), expr);
287 static PyAffineModExpr getRHSConstant(
PyAffineExpr lhs, intptr_t rhs) {
290 return PyAffineModExpr(lhs.
getContext(), expr);
293 static PyAffineModExpr getLHSConstant(intptr_t lhs,
PyAffineExpr rhs) {
296 return PyAffineModExpr(rhs.
getContext(), expr);
299 static void bindDerived(ClassTy &c) {
304 class PyAffineFloorDivExpr
305 :
public PyConcreteAffineExpr<PyAffineFloorDivExpr, PyAffineBinaryExpr> {
308 static constexpr
const char *pyClassName =
"AffineFloorDivExpr";
309 using PyConcreteAffineExpr::PyConcreteAffineExpr;
313 return PyAffineFloorDivExpr(lhs.
getContext(), expr);
316 static PyAffineFloorDivExpr getRHSConstant(
PyAffineExpr lhs, intptr_t rhs) {
319 return PyAffineFloorDivExpr(lhs.
getContext(), expr);
322 static PyAffineFloorDivExpr getLHSConstant(intptr_t lhs,
PyAffineExpr rhs) {
325 return PyAffineFloorDivExpr(rhs.
getContext(), expr);
328 static void bindDerived(ClassTy &c) {
333 class PyAffineCeilDivExpr
334 :
public PyConcreteAffineExpr<PyAffineCeilDivExpr, PyAffineBinaryExpr> {
337 static constexpr
const char *pyClassName =
"AffineCeilDivExpr";
338 using PyConcreteAffineExpr::PyConcreteAffineExpr;
342 return PyAffineCeilDivExpr(lhs.
getContext(), expr);
345 static PyAffineCeilDivExpr getRHSConstant(
PyAffineExpr lhs, intptr_t rhs) {
348 return PyAffineCeilDivExpr(lhs.
getContext(), expr);
351 static PyAffineCeilDivExpr getLHSConstant(intptr_t lhs,
PyAffineExpr rhs) {
354 return PyAffineCeilDivExpr(rhs.
getContext(), expr);
357 static void bindDerived(ClassTy &c) {
369 return py::reinterpret_steal<py::object>(
376 throw py::error_already_set();
391 class PyAffineMapExprList
392 :
public Sliceable<PyAffineMapExprList, PyAffineExpr> {
394 static constexpr
const char *pyClassName =
"AffineExprList";
396 PyAffineMapExprList(
const PyAffineMap &map, intptr_t startIndex = 0,
397 intptr_t length = -1, intptr_t step = 1)
414 PyAffineMapExprList slice(intptr_t startIndex, intptr_t length,
416 return PyAffineMapExprList(affineMap, startIndex, length, step);
434 throw py::error_already_set();
445 class PyIntegerSetConstraint {
448 : set(std::move(set)), pos(pos) {}
457 static void bind(py::module &m) {
458 py::class_<PyIntegerSetConstraint>(m,
"IntegerSetConstraint",
460 .def_property_readonly(
"expr", &PyIntegerSetConstraint::getExpr)
461 .def_property_readonly(
"is_eq", &PyIntegerSetConstraint::isEq);
469 class PyIntegerSetConstraintList
470 :
public Sliceable<PyIntegerSetConstraintList, PyIntegerSetConstraint> {
472 static constexpr
const char *pyClassName =
"IntegerSetConstraintList";
474 PyIntegerSetConstraintList(
const PyIntegerSet &set, intptr_t startIndex = 0,
475 intptr_t length = -1, intptr_t step = 1)
483 friend class Sliceable<PyIntegerSetConstraintList, PyIntegerSetConstraint>;
487 PyIntegerSetConstraint getRawElement(intptr_t pos) {
488 return PyIntegerSetConstraint(set, pos);
491 PyIntegerSetConstraintList slice(intptr_t startIndex, intptr_t length,
493 return PyIntegerSetConstraintList(set, startIndex, length, step);
505 return py::reinterpret_steal<py::object>(
512 throw py::error_already_set();
522 py::class_<PyAffineExpr>(m,
"AffineExpr", py::module_local())
527 .def(
"__add__", &PyAffineAddExpr::getRHSConstant)
528 .def(
"__radd__", &PyAffineAddExpr::getRHSConstant)
530 .def(
"__mul__", &PyAffineMulExpr::getRHSConstant)
531 .def(
"__rmul__", &PyAffineMulExpr::getRHSConstant)
533 .def(
"__mod__", &PyAffineModExpr::getRHSConstant)
555 return PyAffineAddExpr::getLHSConstant(
556 other, PyAffineMulExpr::getLHSConstant(-1,
self));
561 [](
PyAffineExpr &
self, py::object &other) {
return false; })
567 return printAccum.
join();
572 printAccum.
parts.append(
"AffineExpr(");
575 printAccum.
parts.append(
")");
576 return printAccum.
join();
582 .def_property_readonly(
584 [](
PyAffineExpr &
self) {
return self.getContext().getObject(); })
592 "Gets an affine expression containing a sum of two expressions.")
593 .def_static(
"get_add", &PyAffineAddExpr::getLHSConstant,
594 "Gets an affine expression containing a sum of a constant "
595 "and another expression.")
596 .def_static(
"get_add", &PyAffineAddExpr::getRHSConstant,
597 "Gets an affine expression containing a sum of an expression "
601 "Gets an affine expression containing a product of two expressions.")
602 .def_static(
"get_mul", &PyAffineMulExpr::getLHSConstant,
603 "Gets an affine expression containing a product of a "
604 "constant and another expression.")
605 .def_static(
"get_mul", &PyAffineMulExpr::getRHSConstant,
606 "Gets an affine expression containing a product of an "
607 "expression and a constant.")
609 "Gets an affine expression containing the modulo of dividing "
610 "one expression by another.")
611 .def_static(
"get_mod", &PyAffineModExpr::getLHSConstant,
612 "Gets a semi-affine expression containing the modulo of "
613 "dividing a constant by an expression.")
614 .def_static(
"get_mod", &PyAffineModExpr::getRHSConstant,
615 "Gets an affine expression containing the module of dividing"
616 "an expression by a constant.")
618 "Gets an affine expression containing the rounded-down "
619 "result of dividing one expression by another.")
620 .def_static(
"get_floor_div", &PyAffineFloorDivExpr::getLHSConstant,
621 "Gets a semi-affine expression containing the rounded-down "
622 "result of dividing a constant by an expression.")
623 .def_static(
"get_floor_div", &PyAffineFloorDivExpr::getRHSConstant,
624 "Gets an affine expression containing the rounded-down "
625 "result of dividing an expression by a constant.")
627 "Gets an affine expression containing the rounded-up result "
628 "of dividing one expression by another.")
629 .def_static(
"get_ceil_div", &PyAffineCeilDivExpr::getLHSConstant,
630 "Gets a semi-affine expression containing the rounded-up "
631 "result of dividing a constant by an expression.")
632 .def_static(
"get_ceil_div", &PyAffineCeilDivExpr::getRHSConstant,
633 "Gets an affine expression containing the rounded-up result "
634 "of dividing an expression by a constant.")
636 py::arg(
"context") = py::none(),
637 "Gets a constant affine expression with the given value.")
640 py::arg(
"context") = py::none(),
641 "Gets an affine expression of a dimension at the given position.")
644 py::arg(
"context") = py::none(),
645 "Gets an affine expression of a symbol at the given position.")
649 PyAffineConstantExpr::bind(m);
650 PyAffineDimExpr::bind(m);
651 PyAffineSymbolExpr::bind(m);
652 PyAffineBinaryExpr::bind(m);
653 PyAffineAddExpr::bind(m);
654 PyAffineMulExpr::bind(m);
655 PyAffineModExpr::bind(m);
656 PyAffineFloorDivExpr::bind(m);
657 PyAffineCeilDivExpr::bind(m);
662 py::class_<PyAffineMap>(m,
"AffineMap", py::module_local())
668 .def(
"__eq__", [](
PyAffineMap &
self, py::object &other) {
return false; })
674 return printAccum.
join();
679 printAccum.
parts.append(
"AffineMap(");
682 printAccum.
parts.append(
")");
683 return printAccum.
join();
689 .def_static(
"compress_unused_symbols",
692 pyListToVector<PyAffineMap, MlirAffineMap>(
693 affineMaps, maps,
"attempting to create an AffineMap");
694 std::vector<MlirAffineMap> compressed(affineMaps.size());
695 auto populate = [](
void *result, intptr_t idx,
697 static_cast<MlirAffineMap *
>(result)[idx] = (m);
700 maps.data(), maps.size(), compressed.data(), populate);
701 std::vector<PyAffineMap> res;
702 res.reserve(compressed.size());
703 for (
auto m : compressed)
704 res.emplace_back(context->getRef(), m);
707 .def_property_readonly(
709 [](
PyAffineMap &
self) {
return self.getContext().getObject(); },
710 "Context that owns the Affine Map")
716 [](intptr_t dimCount, intptr_t symbolCount, py::list exprs,
719 pyListToVector<PyAffineExpr, MlirAffineExpr>(
720 exprs, affineExprs,
"attempting to create an AffineMap");
723 affineExprs.size(), affineExprs.data());
726 py::arg(
"dim_count"), py::arg(
"symbol_count"), py::arg(
"exprs"),
727 py::arg(
"context") = py::none(),
728 "Gets a map with the given expressions as results.")
732 MlirAffineMap affineMap =
736 py::arg(
"value"), py::arg(
"context") = py::none(),
737 "Gets an affine map with a single constant result")
744 py::arg(
"context") = py::none(),
"Gets an empty affine map.")
748 MlirAffineMap affineMap =
752 py::arg(
"n_dims"), py::arg(
"context") = py::none(),
753 "Gets an identity map with the given number of dimensions.")
755 "get_minor_identity",
756 [](intptr_t nDims, intptr_t nResults,
758 MlirAffineMap affineMap =
762 py::arg(
"n_dims"), py::arg(
"n_results"),
763 py::arg(
"context") = py::none(),
764 "Gets a minor identity map with the given number of dimensions and "
768 [](std::vector<unsigned> permutation,
771 throw py::cast_error(
"Invalid permutation when attempting to "
772 "create an AffineMap");
774 context->
get(), permutation.size(), permutation.data());
777 py::arg(
"permutation"), py::arg(
"context") = py::none(),
778 "Gets an affine map that permutes its inputs.")
781 [](
PyAffineMap &
self, std::vector<intptr_t> &resultPos) {
783 for (intptr_t pos : resultPos) {
784 if (pos < 0 || pos >= numResults)
785 throw py::value_error(
"result position out of bounds");
788 self, resultPos.size(), resultPos.data());
791 py::arg(
"result_positions"))
796 throw py::value_error(
"number of results out of bounds");
797 MlirAffineMap affineMap =
801 py::arg(
"n_results"))
806 throw py::value_error(
"number of results out of bounds");
807 MlirAffineMap affineMap =
811 py::arg(
"n_results"))
816 intptr_t numResultSyms) {
818 self, expression, replacement, numResultDims, numResultSyms);
821 py::arg(
"expr"), py::arg(
"replacement"), py::arg(
"n_result_dims"),
822 py::arg(
"n_result_syms"))
823 .def_property_readonly(
826 .def_property_readonly(
"is_projected_permutation",
830 .def_property_readonly(
833 .def_property_readonly(
836 .def_property_readonly(
839 .def_property_readonly(
"results", [](
PyAffineMap &
self) {
840 return PyAffineMapExprList(
self);
842 PyAffineMapExprList::bind(m);
847 py::class_<PyIntegerSet>(m,
"IntegerSet", py::module_local())
853 .def(
"__eq__", [](
PyIntegerSet &
self, py::object other) {
return false; })
859 return printAccum.
join();
864 printAccum.
parts.append(
"IntegerSet(");
867 printAccum.
parts.append(
")");
868 return printAccum.
join();
874 .def_property_readonly(
876 [](
PyIntegerSet &
self) {
return self.getContext().getObject(); })
882 [](intptr_t numDims, intptr_t numSymbols, py::list exprs,
884 if (exprs.size() != eqFlags.size())
885 throw py::value_error(
886 "Expected the number of constraints to match "
887 "that of equality flags");
889 throw py::value_error(
"Expected non-empty list of constraints");
897 pyListToVector<PyAffineExpr>(exprs, affineExprs,
898 "attempting to create an IntegerSet");
900 context->
get(), numDims, numSymbols, exprs.size(),
901 affineExprs.data(), flags.data());
904 py::arg(
"num_dims"), py::arg(
"num_symbols"), py::arg(
"exprs"),
905 py::arg(
"eq_flags"), py::arg(
"context") = py::none())
908 [](intptr_t numDims, intptr_t numSymbols,
914 py::arg(
"num_dims"), py::arg(
"num_symbols"),
915 py::arg(
"context") = py::none())
918 [](
PyIntegerSet &
self, py::list dimExprs, py::list symbolExprs,
919 intptr_t numResultDims, intptr_t numResultSymbols) {
920 if (
static_cast<intptr_t
>(dimExprs.size()) !=
922 throw py::value_error(
923 "Expected the number of dimension replacement expressions "
924 "to match that of dimensions");
925 if (
static_cast<intptr_t
>(symbolExprs.size()) !=
927 throw py::value_error(
928 "Expected the number of symbol replacement expressions "
929 "to match that of symbols");
932 pyListToVector<PyAffineExpr>(
933 dimExprs, dimAffineExprs,
934 "attempting to create an IntegerSet by replacing dimensions");
935 pyListToVector<PyAffineExpr>(
936 symbolExprs, symbolAffineExprs,
937 "attempting to create an IntegerSet by replacing symbols");
939 self, dimAffineExprs.data(), symbolAffineExprs.data(),
940 numResultDims, numResultSymbols);
943 py::arg(
"dim_exprs"), py::arg(
"symbol_exprs"),
944 py::arg(
"num_result_dims"), py::arg(
"num_result_symbols"))
945 .def_property_readonly(
"is_canonical_empty",
949 .def_property_readonly(
952 .def_property_readonly(
955 .def_property_readonly(
958 .def_property_readonly(
"n_equalities",
962 .def_property_readonly(
"n_inequalities",
966 .def_property_readonly(
"constraints", [](
PyIntegerSet &
self) {
967 return PyIntegerSetConstraintList(
self);
969 PyIntegerSetConstraint::bind(m);
970 PyIntegerSetConstraintList::bind(m);
static void pyListToVector(const py::list &list, llvm::SmallVectorImpl< CType > &result, StringRef action)
Attempts to populate result with the content of list casted to the appropriate type (Python and C typ...
static const char kDumpDocstring[]
static bool isPermutation(std::vector< PermutationTy > permutation)
static MLIRContext * getContext(OpFoldResult val)
static MlirIntegerSet mlirPythonCapsuleToIntegerSet(PyObject *capsule)
Extracts an MlirIntegerSet from a capsule as produced from mlirPythonIntegerSetToCapsule.
#define MLIR_PYTHON_CAPI_PTR_ATTR
Attribute on MLIR Python objects that expose their C-API pointer.
static PyObject * mlirPythonIntegerSetToCapsule(MlirIntegerSet integerSet)
Creates a capsule object encapsulating the raw C-API MlirIntegerSet.
static MlirAffineMap mlirPythonCapsuleToAffineMap(PyObject *capsule)
Extracts an MlirAffineMap from a capsule as produced from mlirPythonAffineMapToCapsule.
#define MLIR_PYTHON_CAPI_FACTORY_ATTR
Attribute on MLIR Python objects that exposes a factory function for constructing the corresponding P...
static PyObject * mlirPythonAffineExprToCapsule(MlirAffineExpr expr)
Creates a capsule object encapsulating the raw C-API MlirAffineExpr.
static PyObject * mlirPythonAffineMapToCapsule(MlirAffineMap affineMap)
Creates a capsule object encapsulating the raw C-API MlirAffineMap.
static MlirAffineExpr mlirPythonCapsuleToAffineExpr(PyObject *capsule)
Extracts an MlirAffineExpr from a capsule as produced from mlirPythonAffineExprToCapsule.
A CRTP base class for pseudo-containers willing to support Python-type slicing access on top of index...
PyMlirContextRef & getContext()
Accesses the context reference.
Used in function arguments when None should resolve to the current context manager set instance.
ReferrentTy * get() const
Wrapper around MlirAffineExpr. Affine expressions are owned by the context.
static PyAffineExpr createFromCapsule(pybind11::object capsule)
Creates a PyAffineExpr from the MlirAffineExpr wrapped by a capsule.
pybind11::object getCapsule()
Gets a capsule wrapping the void* within the MlirAffineExpr.
PyAffineExpr(PyMlirContextRef contextRef, MlirAffineExpr affineExpr)
bool operator==(const PyAffineExpr &other) const
pybind11::object getCapsule()
Gets a capsule wrapping the void* within the MlirAffineMap.
PyAffineMap(PyMlirContextRef contextRef, MlirAffineMap affineMap)
bool operator==(const PyAffineMap &other) const
static PyAffineMap createFromCapsule(pybind11::object capsule)
Creates a PyAffineMap from the MlirAffineMap wrapped by a capsule.
static PyIntegerSet createFromCapsule(pybind11::object capsule)
Creates a PyIntegerSet from the MlirAffineMap wrapped by a capsule.
bool operator==(const PyIntegerSet &other) const
pybind11::object getCapsule()
Gets a capsule wrapping the void* within the MlirIntegerSet.
PyIntegerSet(PyMlirContextRef contextRef, MlirIntegerSet integerSet)
static PyMlirContextRef forContext(MlirContext context)
Returns a context reference for the singleton PyMlirContext wrapper for the given context.
Wrapper around the generic MlirType.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAConstant(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a constant expression.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineBinaryOpExprGetLHS(MlirAffineExpr affineExpr)
Returns the left hand side affine expression of the given affine binary operation expression.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineMulExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine mul expression with 'lhs' and 'rhs'.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineConstantExprGet(MlirContext ctx, int64_t constant)
Creates an affine constant expression with 'constant' in the context.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineBinaryOpExprGetRHS(MlirAffineExpr affineExpr)
Returns the right hand side affine expression of the given affine binary operation expression.
MLIR_CAPI_EXPORTED void mlirAffineExprPrint(MlirAffineExpr affineExpr, MlirStringCallback callback, void *userData)
Prints an affine expression by sending chunks of the string representation and forwarding userData to...
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineAddExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine add expression with 'lhs' and 'rhs'.
MLIR_CAPI_EXPORTED intptr_t mlirAffineDimExprGetPosition(MlirAffineExpr affineExpr)
Returns the position of the given affine dimension expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAAdd(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an add expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsABinary(MlirAffineExpr affineExpr)
Checks whether the given affine expression is binary.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMul(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an mul expression.
MLIR_CAPI_EXPORTED int64_t mlirAffineConstantExprGetValue(MlirAffineExpr affineExpr)
Returns the value of the given affine constant expression.
MLIR_CAPI_EXPORTED MlirContext mlirAffineExprGetContext(MlirAffineExpr affineExpr)
Gets the context that owns the affine expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsASymbol(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a symbol expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsACeilDiv(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an ceildiv expression.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineFloorDivExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine floordiv expression with 'lhs' and 'rhs'.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAFloorDiv(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an floordiv expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprEqual(MlirAffineExpr lhs, MlirAffineExpr rhs)
Returns true if the two affine expressions are equal.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineDimExprGet(MlirContext ctx, intptr_t position)
Creates an affine dimension expression with 'position' in the context.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMod(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an mod expression.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineModExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine mod expression with 'lhs' and 'rhs'.
MLIR_CAPI_EXPORTED void mlirAffineExprDump(MlirAffineExpr affineExpr)
Prints the affine expression to the standard error stream.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineExprCompose(MlirAffineExpr affineExpr, struct MlirAffineMap affineMap)
Composes the given map with the given expression.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineSymbolExprGet(MlirContext ctx, intptr_t position)
Creates an affine symbol expression with 'position' in the context.
static bool mlirAffineExprIsNull(MlirAffineExpr affineExpr)
Returns true if the given affine expression is a null expression.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineCeilDivExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine ceildiv expression with 'lhs' and 'rhs'.
MLIR_CAPI_EXPORTED intptr_t mlirAffineSymbolExprGetPosition(MlirAffineExpr affineExpr)
Returns the position of the given affine symbol expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsADim(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a dimension expression.
MLIR_CAPI_EXPORTED bool mlirAffineMapEqual(MlirAffineMap a1, MlirAffineMap a2)
Checks if two affine maps are equal.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapEmptyGet(MlirContext ctx)
Creates a zero result affine map with no dimensions or symbols in the context.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapGet(MlirContext ctx, intptr_t dimCount, intptr_t symbolCount, intptr_t nAffineExprs, MlirAffineExpr *affineExprs)
Creates an affine map with results defined by the given list of affine expressions.
MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumDims(MlirAffineMap affineMap)
Returns the number of dimensions of the given affine map.
MLIR_CAPI_EXPORTED MlirContext mlirAffineMapGetContext(MlirAffineMap affineMap)
Gets the context that the given affine map was created with.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineMapGetResult(MlirAffineMap affineMap, intptr_t pos)
Returns the result at the given position.
MLIR_CAPI_EXPORTED void mlirAffineMapDump(MlirAffineMap affineMap)
Prints the affine map to the standard error stream.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapConstantGet(MlirContext ctx, int64_t val)
Creates a single constant result affine map in the context.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapMultiDimIdentityGet(MlirContext ctx, intptr_t numDims)
Creates an affine map with 'numDims' identity in the context.
MLIR_CAPI_EXPORTED void mlirAffineMapPrint(MlirAffineMap affineMap, MlirStringCallback callback, void *userData)
Prints an affine map by sending chunks of the string representation and forwarding userData tocallbac...
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapGetMinorSubMap(MlirAffineMap affineMap, intptr_t numResults)
Returns the affine map consisting of the most minor numResults results.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapGetMajorSubMap(MlirAffineMap affineMap, intptr_t numResults)
Returns the affine map consisting of the most major numResults results.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapGetSubMap(MlirAffineMap affineMap, intptr_t size, intptr_t *resultPos)
Returns the affine map consisting of the resultPos subset.
MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumResults(MlirAffineMap affineMap)
Returns the number of results of the given affine map.
MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumSymbols(MlirAffineMap affineMap)
Returns the number of symbols of the given affine map.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapPermutationGet(MlirContext ctx, intptr_t size, unsigned *permutation)
Creates an affine map with a permutation expression and its size in the context.
MLIR_CAPI_EXPORTED void mlirAffineMapCompressUnusedSymbols(MlirAffineMap *affineMaps, intptr_t size, void *result, void(*populateResult)(void *res, intptr_t idx, MlirAffineMap m))
Returns the simplified affine map resulting from dropping the symbols that do not appear in any of th...
MLIR_CAPI_EXPORTED bool mlirAffineMapIsProjectedPermutation(MlirAffineMap affineMap)
Checks whether the given affine map represents a subset of a symbol-less permutation map.
MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumInputs(MlirAffineMap affineMap)
Returns the number of inputs (dimensions + symbols) of the given affine map.
MLIR_CAPI_EXPORTED bool mlirAffineMapIsPermutation(MlirAffineMap affineMap)
Checks whether the given affine map represents a symbol-less permutation map.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapReplace(MlirAffineMap affineMap, MlirAffineExpr expression, MlirAffineExpr replacement, intptr_t numResultDims, intptr_t numResultSyms)
Apply AffineExpr::replace(map) to each of the results and return a new new AffineMap with the new res...
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapMinorIdentityGet(MlirContext ctx, intptr_t dims, intptr_t results)
Creates an identity affine map on the most minor dimensions in the context.
static bool mlirAffineMapIsNull(MlirAffineMap affineMap)
Checks whether an affine map is null.
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set)
Returns the number of constraints (equalities + inequalities) in the given set.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirIntegerSetGetConstraint(MlirIntegerSet set, intptr_t pos)
Returns pos-th constraint of the set.
MLIR_CAPI_EXPORTED bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set)
Checks whether the given set is a canonical empty set, e.g., the set returned by mlirIntegerSetEmptyG...
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set)
Returns the number of inputs (dimensions + symbols) in the given set.
MLIR_CAPI_EXPORTED MlirIntegerSet mlirIntegerSetEmptyGet(MlirContext context, intptr_t numDims, intptr_t numSymbols)
Gets or creates a new canonically empty integer set with the give number of dimensions and symbols in...
MLIR_CAPI_EXPORTED MlirIntegerSet mlirIntegerSetGet(MlirContext context, intptr_t numDims, intptr_t numSymbols, intptr_t numConstraints, const MlirAffineExpr *constraints, const bool *eqFlags)
Gets or creates a new integer set in the given context.
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set)
Returns the number of equalities in the given set.
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set)
Returns the number of dimensions in the given set.
MLIR_CAPI_EXPORTED MlirIntegerSet mlirIntegerSetReplaceGet(MlirIntegerSet set, const MlirAffineExpr *dimReplacements, const MlirAffineExpr *symbolReplacements, intptr_t numResultDims, intptr_t numResultSymbols)
Gets or creates a new integer set in which the values and dimensions of the given set are replaced wi...
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set)
Returns the number of symbols in the given set.
static bool mlirIntegerSetIsNull(MlirIntegerSet set)
Checks whether an integer set is a null object.
MLIR_CAPI_EXPORTED MlirContext mlirIntegerSetGetContext(MlirIntegerSet set)
Gets the context in which the given integer set lives.
MLIR_CAPI_EXPORTED void mlirIntegerSetPrint(MlirIntegerSet set, MlirStringCallback callback, void *userData)
Prints an integer set by sending chunks of the string representation and forwarding userData tocallba...
MLIR_CAPI_EXPORTED bool mlirIntegerSetEqual(MlirIntegerSet s1, MlirIntegerSet s2)
Checks if two integer set objects are equal.
MLIR_CAPI_EXPORTED bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set, intptr_t pos)
Returns true of the pos-th constraint of the set is an equality constraint, false otherwise.
MLIR_CAPI_EXPORTED void mlirIntegerSetDump(MlirIntegerSet set)
Prints an integer set to the standard error stream.
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumInequalities(MlirIntegerSet set)
Returns the number of inequalities in the given set.
inline ::llvm::hash_code hash_value(const PolynomialBase< D, T > &arg)
void populateIRAffine(pybind11::module &m)
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
Accumulates into a python string from a method that accepts an MlirStringCallback.
MlirStringCallback getCallback()