18 #include "llvm/ADT/Hashing.h"
25 using llvm::StringRef;
29 R
"(Dumps a debug representation of the object to stderr.)";
35 template <
typename PyType,
typename CType>
39 result.reserve(py::len(list));
40 for (py::handle item : list) {
42 result.push_back(item.cast<
PyType>());
43 }
catch (py::cast_error &err) {
44 std::string msg = (llvm::Twine(
"Invalid expression when ") + action +
45 " (" + err.what() +
")")
47 throw py::cast_error(msg);
48 }
catch (py::reference_cast_error &err) {
49 std::string msg = (llvm::Twine(
"Invalid expression (None?) when ") +
50 action +
" (" + err.what() +
")")
52 throw py::cast_error(msg);
57 template <
typename PermutationTy>
60 for (
auto val : permutation) {
61 if (val < permutation.size()) {
77 template <
typename DerivedTy,
typename BaseTy = PyAffineExpr>
78 class PyConcreteAffineExpr :
public BaseTy {
84 using ClassTy = py::class_<DerivedTy, BaseTy>;
85 using IsAFunctionTy = bool (*)(MlirAffineExpr);
87 PyConcreteAffineExpr() =
default;
89 : BaseTy(std::move(contextRef), affineExpr) {}
91 : PyConcreteAffineExpr(orig.getContext(), castFrom(orig)) {}
94 if (!DerivedTy::isaFunction(orig)) {
95 auto origRepr = py::repr(py::cast(orig)).cast<std::string>();
96 throw py::value_error((Twine(
"Cannot cast affine expression to ") +
97 DerivedTy::pyClassName +
" (from " + origRepr +
104 static void bind(py::module &m) {
105 auto cls = ClassTy(m, DerivedTy::pyClassName, py::module_local());
106 cls.def(py::init<PyAffineExpr &>(), py::arg(
"expr"));
110 return DerivedTy::isaFunction(otherAffineExpr);
113 DerivedTy::bindDerived(cls);
117 static void bindDerived(ClassTy &m) {}
120 class PyAffineConstantExpr :
public PyConcreteAffineExpr<PyAffineConstantExpr> {
123 static constexpr
const char *pyClassName =
"AffineConstantExpr";
124 using PyConcreteAffineExpr::PyConcreteAffineExpr;
126 static PyAffineConstantExpr
get(intptr_t value,
128 MlirAffineExpr affineExpr =
130 return PyAffineConstantExpr(context->getRef(), affineExpr);
133 static void bindDerived(ClassTy &c) {
135 py::arg(
"context") = py::none());
136 c.def_property_readonly(
"value", [](PyAffineConstantExpr &
self) {
142 class PyAffineDimExpr :
public PyConcreteAffineExpr<PyAffineDimExpr> {
145 static constexpr
const char *pyClassName =
"AffineDimExpr";
146 using PyConcreteAffineExpr::PyConcreteAffineExpr;
150 return PyAffineDimExpr(context->getRef(), affineExpr);
153 static void bindDerived(ClassTy &c) {
155 py::arg(
"context") = py::none());
156 c.def_property_readonly(
"position", [](PyAffineDimExpr &
self) {
162 class PyAffineSymbolExpr :
public PyConcreteAffineExpr<PyAffineSymbolExpr> {
165 static constexpr
const char *pyClassName =
"AffineSymbolExpr";
166 using PyConcreteAffineExpr::PyConcreteAffineExpr;
170 return PyAffineSymbolExpr(context->getRef(), affineExpr);
173 static void bindDerived(ClassTy &c) {
175 py::arg(
"context") = py::none());
176 c.def_property_readonly(
"position", [](PyAffineSymbolExpr &
self) {
182 class PyAffineBinaryExpr :
public PyConcreteAffineExpr<PyAffineBinaryExpr> {
185 static constexpr
const char *pyClassName =
"AffineBinaryExpr";
186 using PyConcreteAffineExpr::PyConcreteAffineExpr;
198 static void bindDerived(ClassTy &c) {
199 c.def_property_readonly(
"lhs", &PyAffineBinaryExpr::lhs);
200 c.def_property_readonly(
"rhs", &PyAffineBinaryExpr::rhs);
204 class PyAffineAddExpr
205 :
public PyConcreteAffineExpr<PyAffineAddExpr, PyAffineBinaryExpr> {
208 static constexpr
const char *pyClassName =
"AffineAddExpr";
209 using PyConcreteAffineExpr::PyConcreteAffineExpr;
213 return PyAffineAddExpr(lhs.
getContext(), expr);
216 static PyAffineAddExpr getRHSConstant(
PyAffineExpr lhs, intptr_t rhs) {
219 return PyAffineAddExpr(lhs.
getContext(), expr);
222 static PyAffineAddExpr getLHSConstant(intptr_t lhs,
PyAffineExpr rhs) {
225 return PyAffineAddExpr(rhs.
getContext(), expr);
228 static void bindDerived(ClassTy &c) {
233 class PyAffineMulExpr
234 :
public PyConcreteAffineExpr<PyAffineMulExpr, PyAffineBinaryExpr> {
237 static constexpr
const char *pyClassName =
"AffineMulExpr";
238 using PyConcreteAffineExpr::PyConcreteAffineExpr;
242 return PyAffineMulExpr(lhs.
getContext(), expr);
245 static PyAffineMulExpr getRHSConstant(
PyAffineExpr lhs, intptr_t rhs) {
248 return PyAffineMulExpr(lhs.
getContext(), expr);
251 static PyAffineMulExpr getLHSConstant(intptr_t lhs,
PyAffineExpr rhs) {
254 return PyAffineMulExpr(rhs.
getContext(), expr);
257 static void bindDerived(ClassTy &c) {
262 class PyAffineModExpr
263 :
public PyConcreteAffineExpr<PyAffineModExpr, PyAffineBinaryExpr> {
266 static constexpr
const char *pyClassName =
"AffineModExpr";
267 using PyConcreteAffineExpr::PyConcreteAffineExpr;
271 return PyAffineModExpr(lhs.
getContext(), expr);
274 static PyAffineModExpr getRHSConstant(
PyAffineExpr lhs, intptr_t rhs) {
277 return PyAffineModExpr(lhs.
getContext(), expr);
280 static PyAffineModExpr getLHSConstant(intptr_t lhs,
PyAffineExpr rhs) {
283 return PyAffineModExpr(rhs.
getContext(), expr);
286 static void bindDerived(ClassTy &c) {
291 class PyAffineFloorDivExpr
292 :
public PyConcreteAffineExpr<PyAffineFloorDivExpr, PyAffineBinaryExpr> {
295 static constexpr
const char *pyClassName =
"AffineFloorDivExpr";
296 using PyConcreteAffineExpr::PyConcreteAffineExpr;
300 return PyAffineFloorDivExpr(lhs.
getContext(), expr);
303 static PyAffineFloorDivExpr getRHSConstant(
PyAffineExpr lhs, intptr_t rhs) {
306 return PyAffineFloorDivExpr(lhs.
getContext(), expr);
309 static PyAffineFloorDivExpr getLHSConstant(intptr_t lhs,
PyAffineExpr rhs) {
312 return PyAffineFloorDivExpr(rhs.
getContext(), expr);
315 static void bindDerived(ClassTy &c) {
320 class PyAffineCeilDivExpr
321 :
public PyConcreteAffineExpr<PyAffineCeilDivExpr, PyAffineBinaryExpr> {
324 static constexpr
const char *pyClassName =
"AffineCeilDivExpr";
325 using PyConcreteAffineExpr::PyConcreteAffineExpr;
329 return PyAffineCeilDivExpr(lhs.
getContext(), expr);
332 static PyAffineCeilDivExpr getRHSConstant(
PyAffineExpr lhs, intptr_t rhs) {
335 return PyAffineCeilDivExpr(lhs.
getContext(), expr);
338 static PyAffineCeilDivExpr getLHSConstant(intptr_t lhs,
PyAffineExpr rhs) {
341 return PyAffineCeilDivExpr(rhs.
getContext(), expr);
344 static void bindDerived(ClassTy &c) {
356 return py::reinterpret_steal<py::object>(
363 throw py::error_already_set();
378 class PyAffineMapExprList
379 :
public Sliceable<PyAffineMapExprList, PyAffineExpr> {
381 static constexpr
const char *pyClassName =
"AffineExprList";
383 PyAffineMapExprList(
const PyAffineMap &map, intptr_t startIndex = 0,
384 intptr_t length = -1, intptr_t step = 1)
401 PyAffineMapExprList slice(intptr_t startIndex, intptr_t length,
403 return PyAffineMapExprList(affineMap, startIndex, length, step);
421 throw py::error_already_set();
432 class PyIntegerSetConstraint {
435 : set(std::move(set)), pos(pos) {}
444 static void bind(py::module &m) {
445 py::class_<PyIntegerSetConstraint>(m,
"IntegerSetConstraint",
447 .def_property_readonly(
"expr", &PyIntegerSetConstraint::getExpr)
448 .def_property_readonly(
"is_eq", &PyIntegerSetConstraint::isEq);
456 class PyIntegerSetConstraintList
457 :
public Sliceable<PyIntegerSetConstraintList, PyIntegerSetConstraint> {
459 static constexpr
const char *pyClassName =
"IntegerSetConstraintList";
461 PyIntegerSetConstraintList(
const PyIntegerSet &set, intptr_t startIndex = 0,
462 intptr_t length = -1, intptr_t step = 1)
470 friend class Sliceable<PyIntegerSetConstraintList, PyIntegerSetConstraint>;
474 PyIntegerSetConstraint getRawElement(intptr_t pos) {
475 return PyIntegerSetConstraint(set, pos);
478 PyIntegerSetConstraintList slice(intptr_t startIndex, intptr_t length,
480 return PyIntegerSetConstraintList(set, startIndex, length, step);
492 return py::reinterpret_steal<py::object>(
499 throw py::error_already_set();
509 py::class_<PyAffineExpr>(m,
"AffineExpr", py::module_local())
514 .def(
"__add__", &PyAffineAddExpr::getRHSConstant)
515 .def(
"__radd__", &PyAffineAddExpr::getRHSConstant)
517 .def(
"__mul__", &PyAffineMulExpr::getRHSConstant)
518 .def(
"__rmul__", &PyAffineMulExpr::getRHSConstant)
520 .def(
"__mod__", &PyAffineModExpr::getRHSConstant)
542 return PyAffineAddExpr::getLHSConstant(
543 other, PyAffineMulExpr::getLHSConstant(-1,
self));
548 [](
PyAffineExpr &
self, py::object &other) {
return false; })
554 return printAccum.
join();
559 printAccum.
parts.append(
"AffineExpr(");
562 printAccum.
parts.append(
")");
563 return printAccum.
join();
569 .def_property_readonly(
571 [](
PyAffineExpr &
self) {
return self.getContext().getObject(); })
579 "Gets an affine expression containing a sum of two expressions.")
580 .def_static(
"get_add", &PyAffineAddExpr::getLHSConstant,
581 "Gets an affine expression containing a sum of a constant "
582 "and another expression.")
583 .def_static(
"get_add", &PyAffineAddExpr::getRHSConstant,
584 "Gets an affine expression containing a sum of an expression "
588 "Gets an affine expression containing a product of two expressions.")
589 .def_static(
"get_mul", &PyAffineMulExpr::getLHSConstant,
590 "Gets an affine expression containing a product of a "
591 "constant and another expression.")
592 .def_static(
"get_mul", &PyAffineMulExpr::getRHSConstant,
593 "Gets an affine expression containing a product of an "
594 "expression and a constant.")
596 "Gets an affine expression containing the modulo of dividing "
597 "one expression by another.")
598 .def_static(
"get_mod", &PyAffineModExpr::getLHSConstant,
599 "Gets a semi-affine expression containing the modulo of "
600 "dividing a constant by an expression.")
601 .def_static(
"get_mod", &PyAffineModExpr::getRHSConstant,
602 "Gets an affine expression containing the module of dividing"
603 "an expression by a constant.")
605 "Gets an affine expression containing the rounded-down "
606 "result of dividing one expression by another.")
607 .def_static(
"get_floor_div", &PyAffineFloorDivExpr::getLHSConstant,
608 "Gets a semi-affine expression containing the rounded-down "
609 "result of dividing a constant by an expression.")
610 .def_static(
"get_floor_div", &PyAffineFloorDivExpr::getRHSConstant,
611 "Gets an affine expression containing the rounded-down "
612 "result of dividing an expression by a constant.")
614 "Gets an affine expression containing the rounded-up result "
615 "of dividing one expression by another.")
616 .def_static(
"get_ceil_div", &PyAffineCeilDivExpr::getLHSConstant,
617 "Gets a semi-affine expression containing the rounded-up "
618 "result of dividing a constant by an expression.")
619 .def_static(
"get_ceil_div", &PyAffineCeilDivExpr::getRHSConstant,
620 "Gets an affine expression containing the rounded-up result "
621 "of dividing an expression by a constant.")
623 py::arg(
"context") = py::none(),
624 "Gets a constant affine expression with the given value.")
627 py::arg(
"context") = py::none(),
628 "Gets an affine expression of a dimension at the given position.")
631 py::arg(
"context") = py::none(),
632 "Gets an affine expression of a symbol at the given position.")
636 PyAffineConstantExpr::bind(m);
637 PyAffineDimExpr::bind(m);
638 PyAffineSymbolExpr::bind(m);
639 PyAffineBinaryExpr::bind(m);
640 PyAffineAddExpr::bind(m);
641 PyAffineMulExpr::bind(m);
642 PyAffineModExpr::bind(m);
643 PyAffineFloorDivExpr::bind(m);
644 PyAffineCeilDivExpr::bind(m);
649 py::class_<PyAffineMap>(m,
"AffineMap", py::module_local())
655 .def(
"__eq__", [](
PyAffineMap &
self, py::object &other) {
return false; })
661 return printAccum.
join();
666 printAccum.
parts.append(
"AffineMap(");
669 printAccum.
parts.append(
")");
670 return printAccum.
join();
676 .def_static(
"compress_unused_symbols",
679 pyListToVector<PyAffineMap, MlirAffineMap>(
680 affineMaps, maps,
"attempting to create an AffineMap");
681 std::vector<MlirAffineMap> compressed(affineMaps.size());
682 auto populate = [](
void *result, intptr_t idx,
684 static_cast<MlirAffineMap *
>(result)[idx] = (m);
687 maps.data(), maps.size(), compressed.data(), populate);
688 std::vector<PyAffineMap> res;
689 res.reserve(compressed.size());
690 for (
auto m : compressed)
691 res.emplace_back(context->getRef(), m);
694 .def_property_readonly(
696 [](
PyAffineMap &
self) {
return self.getContext().getObject(); },
697 "Context that owns the Affine Map")
703 [](intptr_t dimCount, intptr_t symbolCount, py::list exprs,
706 pyListToVector<PyAffineExpr, MlirAffineExpr>(
707 exprs, affineExprs,
"attempting to create an AffineMap");
710 affineExprs.size(), affineExprs.data());
713 py::arg(
"dim_count"), py::arg(
"symbol_count"), py::arg(
"exprs"),
714 py::arg(
"context") = py::none(),
715 "Gets a map with the given expressions as results.")
719 MlirAffineMap affineMap =
723 py::arg(
"value"), py::arg(
"context") = py::none(),
724 "Gets an affine map with a single constant result")
731 py::arg(
"context") = py::none(),
"Gets an empty affine map.")
735 MlirAffineMap affineMap =
739 py::arg(
"n_dims"), py::arg(
"context") = py::none(),
740 "Gets an identity map with the given number of dimensions.")
742 "get_minor_identity",
743 [](intptr_t nDims, intptr_t nResults,
745 MlirAffineMap affineMap =
749 py::arg(
"n_dims"), py::arg(
"n_results"),
750 py::arg(
"context") = py::none(),
751 "Gets a minor identity map with the given number of dimensions and "
755 [](std::vector<unsigned> permutation,
758 throw py::cast_error(
"Invalid permutation when attempting to "
759 "create an AffineMap");
761 context->
get(), permutation.size(), permutation.data());
764 py::arg(
"permutation"), py::arg(
"context") = py::none(),
765 "Gets an affine map that permutes its inputs.")
768 [](
PyAffineMap &
self, std::vector<intptr_t> &resultPos) {
770 for (intptr_t pos : resultPos) {
771 if (pos < 0 || pos >= numResults)
772 throw py::value_error(
"result position out of bounds");
775 self, resultPos.size(), resultPos.data());
778 py::arg(
"result_positions"))
783 throw py::value_error(
"number of results out of bounds");
784 MlirAffineMap affineMap =
788 py::arg(
"n_results"))
793 throw py::value_error(
"number of results out of bounds");
794 MlirAffineMap affineMap =
798 py::arg(
"n_results"))
803 intptr_t numResultSyms) {
805 self, expression, replacement, numResultDims, numResultSyms);
808 py::arg(
"expr"), py::arg(
"replacement"), py::arg(
"n_result_dims"),
809 py::arg(
"n_result_syms"))
810 .def_property_readonly(
813 .def_property_readonly(
"is_projected_permutation",
817 .def_property_readonly(
820 .def_property_readonly(
823 .def_property_readonly(
826 .def_property_readonly(
"results", [](
PyAffineMap &
self) {
827 return PyAffineMapExprList(
self);
829 PyAffineMapExprList::bind(m);
834 py::class_<PyIntegerSet>(m,
"IntegerSet", py::module_local())
840 .def(
"__eq__", [](
PyIntegerSet &
self, py::object other) {
return false; })
846 return printAccum.
join();
851 printAccum.
parts.append(
"IntegerSet(");
854 printAccum.
parts.append(
")");
855 return printAccum.
join();
861 .def_property_readonly(
863 [](
PyIntegerSet &
self) {
return self.getContext().getObject(); })
869 [](intptr_t numDims, intptr_t numSymbols, py::list exprs,
871 if (exprs.size() != eqFlags.size())
872 throw py::value_error(
873 "Expected the number of constraints to match "
874 "that of equality flags");
876 throw py::value_error(
"Expected non-empty list of constraints");
884 pyListToVector<PyAffineExpr>(exprs, affineExprs,
885 "attempting to create an IntegerSet");
887 context->
get(), numDims, numSymbols, exprs.size(),
888 affineExprs.data(), flags.data());
891 py::arg(
"num_dims"), py::arg(
"num_symbols"), py::arg(
"exprs"),
892 py::arg(
"eq_flags"), py::arg(
"context") = py::none())
895 [](intptr_t numDims, intptr_t numSymbols,
901 py::arg(
"num_dims"), py::arg(
"num_symbols"),
902 py::arg(
"context") = py::none())
905 [](
PyIntegerSet &
self, py::list dimExprs, py::list symbolExprs,
906 intptr_t numResultDims, intptr_t numResultSymbols) {
907 if (
static_cast<intptr_t
>(dimExprs.size()) !=
909 throw py::value_error(
910 "Expected the number of dimension replacement expressions "
911 "to match that of dimensions");
912 if (
static_cast<intptr_t
>(symbolExprs.size()) !=
914 throw py::value_error(
915 "Expected the number of symbol replacement expressions "
916 "to match that of symbols");
919 pyListToVector<PyAffineExpr>(
920 dimExprs, dimAffineExprs,
921 "attempting to create an IntegerSet by replacing dimensions");
922 pyListToVector<PyAffineExpr>(
923 symbolExprs, symbolAffineExprs,
924 "attempting to create an IntegerSet by replacing symbols");
926 self, dimAffineExprs.data(), symbolAffineExprs.data(),
927 numResultDims, numResultSymbols);
930 py::arg(
"dim_exprs"), py::arg(
"symbol_exprs"),
931 py::arg(
"num_result_dims"), py::arg(
"num_result_symbols"))
932 .def_property_readonly(
"is_canonical_empty",
936 .def_property_readonly(
939 .def_property_readonly(
942 .def_property_readonly(
945 .def_property_readonly(
"n_equalities",
949 .def_property_readonly(
"n_inequalities",
953 .def_property_readonly(
"constraints", [](
PyIntegerSet &
self) {
954 return PyIntegerSetConstraintList(
self);
956 PyIntegerSetConstraint::bind(m);
957 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 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.
llvm::hash_code hash_value(const MPInt &x)
Redeclarations of friend declaration above to make it discoverable by lookups.
void populateIRAffine(pybind11::module &m)
This header declares functions that assit transformations in the MemRef dialect.
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()