24#include "llvm/ADT/Hashing.h"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/StringRef.h"
27#include "llvm/ADT/Twine.h"
38 R
"(Dumps a debug representation of the object to stderr.)";
44template <
typename PyType,
typename CType>
48 result.reserve(nb::len(list));
49 for (nb::handle item : list) {
51 result.push_back(nb::cast<PyType>(item));
52 }
catch (nb::cast_error &err) {
53 std::string msg = (llvm::Twine(
"Invalid expression when ") + action +
54 " (" + err.what() +
")")
56 throw std::runtime_error(msg.c_str());
57 }
catch (std::runtime_error &err) {
58 std::string msg = (llvm::Twine(
"Invalid expression (None?) when ") +
59 action +
" (" + err.what() +
")")
61 throw std::runtime_error(msg.c_str());
66template <
typename PermutationTy>
67static bool isPermutation(
const std::vector<PermutationTy> &permutation) {
69 for (
auto val : permutation) {
70 if (val < permutation.size()) {
86template <
typename DerivedTy,
typename BaseTy = PyAffineExpr>
87class PyConcreteAffineExpr :
public BaseTy {
93 using ClassTy = nb::class_<DerivedTy, BaseTy>;
94 using IsAFunctionTy = bool (*)(MlirAffineExpr);
96 PyConcreteAffineExpr() =
default;
98 : BaseTy(std::move(contextRef), affineExpr) {}
99 PyConcreteAffineExpr(PyAffineExpr &orig)
100 : PyConcreteAffineExpr(orig.
getContext(), castFrom(orig)) {}
102 static MlirAffineExpr castFrom(PyAffineExpr &orig) {
103 if (!DerivedTy::isaFunction(orig)) {
104 auto origRepr = nb::cast<std::string>(nb::repr(nb::cast(orig)));
105 throw nb::value_error((Twine(
"Cannot cast affine expression to ") +
106 DerivedTy::pyClassName +
" (from " + origRepr +
114 static void bind(nb::module_ &m) {
115 auto cls = ClassTy(m, DerivedTy::pyClassName);
116 cls.def(nb::init<PyAffineExpr &>(), nb::arg(
"expr"));
119 [](PyAffineExpr &otherAffineExpr) ->
bool {
120 return DerivedTy::isaFunction(otherAffineExpr);
123 DerivedTy::bindDerived(cls);
127 static void bindDerived(ClassTy &m) {}
130class PyAffineConstantExpr :
public PyConcreteAffineExpr<PyAffineConstantExpr> {
133 static constexpr const char *pyClassName =
"AffineConstantExpr";
134 using PyConcreteAffineExpr::PyConcreteAffineExpr;
136 static PyAffineConstantExpr
get(intptr_t value,
137 DefaultingPyMlirContext context) {
138 MlirAffineExpr affineExpr =
140 return PyAffineConstantExpr(context->getRef(), affineExpr);
143 static void bindDerived(ClassTy &c) {
144 c.def_static(
"get", &PyAffineConstantExpr::get, nb::arg(
"value"),
145 nb::arg(
"context") = nb::none());
146 c.def_prop_ro(
"value", [](PyAffineConstantExpr &self) {
152class PyAffineDimExpr :
public PyConcreteAffineExpr<PyAffineDimExpr> {
155 static constexpr const char *pyClassName =
"AffineDimExpr";
156 using PyConcreteAffineExpr::PyConcreteAffineExpr;
158 static PyAffineDimExpr
get(intptr_t pos, DefaultingPyMlirContext context) {
160 return PyAffineDimExpr(context->getRef(), affineExpr);
163 static void bindDerived(ClassTy &c) {
164 c.def_static(
"get", &PyAffineDimExpr::get, nb::arg(
"position"),
165 nb::arg(
"context") = nb::none());
166 c.def_prop_ro(
"position", [](PyAffineDimExpr &self) {
172class PyAffineSymbolExpr :
public PyConcreteAffineExpr<PyAffineSymbolExpr> {
175 static constexpr const char *pyClassName =
"AffineSymbolExpr";
176 using PyConcreteAffineExpr::PyConcreteAffineExpr;
178 static PyAffineSymbolExpr
get(intptr_t pos, DefaultingPyMlirContext context) {
180 return PyAffineSymbolExpr(context->getRef(), affineExpr);
183 static void bindDerived(ClassTy &c) {
184 c.def_static(
"get", &PyAffineSymbolExpr::get, nb::arg(
"position"),
185 nb::arg(
"context") = nb::none());
186 c.def_prop_ro(
"position", [](PyAffineSymbolExpr &self) {
192class PyAffineBinaryExpr :
public PyConcreteAffineExpr<PyAffineBinaryExpr> {
195 static constexpr const char *pyClassName =
"AffineBinaryExpr";
196 using PyConcreteAffineExpr::PyConcreteAffineExpr;
208 static void bindDerived(ClassTy &c) {
209 c.def_prop_ro(
"lhs", &PyAffineBinaryExpr::lhs);
210 c.def_prop_ro(
"rhs", &PyAffineBinaryExpr::rhs);
215 :
public PyConcreteAffineExpr<PyAffineAddExpr, PyAffineBinaryExpr> {
218 static constexpr const char *pyClassName =
"AffineAddExpr";
219 using PyConcreteAffineExpr::PyConcreteAffineExpr;
221 static PyAffineAddExpr
get(PyAffineExpr
lhs,
const PyAffineExpr &
rhs) {
223 return PyAffineAddExpr(
lhs.getContext(), expr);
226 static PyAffineAddExpr getRHSConstant(PyAffineExpr
lhs, intptr_t
rhs) {
229 return PyAffineAddExpr(
lhs.getContext(), expr);
232 static PyAffineAddExpr getLHSConstant(intptr_t
lhs, PyAffineExpr
rhs) {
235 return PyAffineAddExpr(
rhs.getContext(), expr);
238 static void bindDerived(ClassTy &c) {
239 c.def_static(
"get", &PyAffineAddExpr::get);
244 :
public PyConcreteAffineExpr<PyAffineMulExpr, PyAffineBinaryExpr> {
247 static constexpr const char *pyClassName =
"AffineMulExpr";
248 using PyConcreteAffineExpr::PyConcreteAffineExpr;
250 static PyAffineMulExpr
get(PyAffineExpr
lhs,
const PyAffineExpr &
rhs) {
252 return PyAffineMulExpr(
lhs.getContext(), expr);
255 static PyAffineMulExpr getRHSConstant(PyAffineExpr
lhs, intptr_t
rhs) {
258 return PyAffineMulExpr(
lhs.getContext(), expr);
261 static PyAffineMulExpr getLHSConstant(intptr_t
lhs, PyAffineExpr
rhs) {
264 return PyAffineMulExpr(
rhs.getContext(), expr);
267 static void bindDerived(ClassTy &c) {
268 c.def_static(
"get", &PyAffineMulExpr::get);
273 :
public PyConcreteAffineExpr<PyAffineModExpr, PyAffineBinaryExpr> {
276 static constexpr const char *pyClassName =
"AffineModExpr";
277 using PyConcreteAffineExpr::PyConcreteAffineExpr;
279 static PyAffineModExpr
get(PyAffineExpr
lhs,
const PyAffineExpr &
rhs) {
281 return PyAffineModExpr(
lhs.getContext(), expr);
284 static PyAffineModExpr getRHSConstant(PyAffineExpr
lhs, intptr_t
rhs) {
287 return PyAffineModExpr(
lhs.getContext(), expr);
290 static PyAffineModExpr getLHSConstant(intptr_t
lhs, PyAffineExpr
rhs) {
293 return PyAffineModExpr(
rhs.getContext(), expr);
296 static void bindDerived(ClassTy &c) {
297 c.def_static(
"get", &PyAffineModExpr::get);
301class PyAffineFloorDivExpr
302 :
public PyConcreteAffineExpr<PyAffineFloorDivExpr, PyAffineBinaryExpr> {
305 static constexpr const char *pyClassName =
"AffineFloorDivExpr";
306 using PyConcreteAffineExpr::PyConcreteAffineExpr;
308 static PyAffineFloorDivExpr
get(PyAffineExpr
lhs,
const PyAffineExpr &
rhs) {
310 return PyAffineFloorDivExpr(
lhs.getContext(), expr);
313 static PyAffineFloorDivExpr getRHSConstant(PyAffineExpr
lhs, intptr_t
rhs) {
316 return PyAffineFloorDivExpr(
lhs.getContext(), expr);
319 static PyAffineFloorDivExpr getLHSConstant(intptr_t
lhs, PyAffineExpr
rhs) {
322 return PyAffineFloorDivExpr(
rhs.getContext(), expr);
325 static void bindDerived(ClassTy &c) {
326 c.def_static(
"get", &PyAffineFloorDivExpr::get);
330class PyAffineCeilDivExpr
331 :
public PyConcreteAffineExpr<PyAffineCeilDivExpr, PyAffineBinaryExpr> {
334 static constexpr const char *pyClassName =
"AffineCeilDivExpr";
335 using PyConcreteAffineExpr::PyConcreteAffineExpr;
337 static PyAffineCeilDivExpr
get(PyAffineExpr
lhs,
const PyAffineExpr &
rhs) {
339 return PyAffineCeilDivExpr(
lhs.getContext(), expr);
342 static PyAffineCeilDivExpr getRHSConstant(PyAffineExpr
lhs, intptr_t
rhs) {
345 return PyAffineCeilDivExpr(
lhs.getContext(), expr);
348 static PyAffineCeilDivExpr getLHSConstant(intptr_t
lhs, PyAffineExpr
rhs) {
351 return PyAffineCeilDivExpr(
rhs.getContext(), expr);
354 static void bindDerived(ClassTy &c) {
355 c.def_static(
"get", &PyAffineCeilDivExpr::get);
372 throw nb::python_error();
387class PyAffineMapExprList
388 :
public Sliceable<PyAffineMapExprList, PyAffineExpr> {
390 static constexpr const char *pyClassName =
"AffineExprList";
392 PyAffineMapExprList(
const PyAffineMap &map, intptr_t startIndex = 0,
393 intptr_t length = -1, intptr_t step = 1)
410 PyAffineMapExprList slice(intptr_t startIndex, intptr_t length,
412 return PyAffineMapExprList(affineMap, startIndex, length, step);
415 PyAffineMap affineMap;
430 throw nb::python_error();
441class PyIntegerSetConstraint {
444 : set(std::move(set)), pos(pos) {}
453 static void bind(nb::module_ &m) {
454 nb::class_<PyIntegerSetConstraint>(m,
"IntegerSetConstraint")
455 .def_prop_ro(
"expr", &PyIntegerSetConstraint::getExpr)
456 .def_prop_ro(
"is_eq", &PyIntegerSetConstraint::isEq);
464class PyIntegerSetConstraintList
465 :
public Sliceable<PyIntegerSetConstraintList, PyIntegerSetConstraint> {
467 static constexpr const char *pyClassName =
"IntegerSetConstraintList";
469 PyIntegerSetConstraintList(
const PyIntegerSet &set, intptr_t startIndex = 0,
470 intptr_t length = -1, intptr_t step = 1)
471 : Sliceable(startIndex,
478 friend class Sliceable<PyIntegerSetConstraintList, PyIntegerSetConstraint>;
482 PyIntegerSetConstraint getRawElement(intptr_t pos) {
483 return PyIntegerSetConstraint(set, pos);
486 PyIntegerSetConstraintList slice(intptr_t startIndex, intptr_t length,
488 return PyIntegerSetConstraintList(set, startIndex, length, step);
506 throw nb::python_error();
516 nb::class_<PyAffineExpr>(m,
"AffineExpr")
519 .def(
"__add__", &PyAffineAddExpr::get)
520 .def(
"__add__", &PyAffineAddExpr::getRHSConstant)
521 .def(
"__radd__", &PyAffineAddExpr::getRHSConstant)
522 .def(
"__mul__", &PyAffineMulExpr::get)
523 .def(
"__mul__", &PyAffineMulExpr::getRHSConstant)
524 .def(
"__rmul__", &PyAffineMulExpr::getRHSConstant)
525 .def(
"__mod__", &PyAffineModExpr::get)
526 .def(
"__mod__", &PyAffineModExpr::getRHSConstant)
529 return PyAffineModExpr::get(
537 return PyAffineAddExpr::get(self,
538 PyAffineMulExpr::get(negOne, other));
542 return PyAffineAddExpr::get(
544 PyAffineConstantExpr::get(-other, *self.
getContext().
get()));
548 return PyAffineAddExpr::getLHSConstant(
549 other, PyAffineMulExpr::getLHSConstant(-1, self));
554 [](
PyAffineExpr &self, nb::object &other) {
return false; })
557 PyPrintAccumulator printAccum;
560 return printAccum.
join();
564 PyPrintAccumulator printAccum;
565 printAccum.
parts.append(
"AffineExpr(");
568 printAccum.
parts.append(
")");
569 return printAccum.
join();
573 return static_cast<size_t>(llvm::hash_value(self.
get().ptr));
577 [](
PyAffineExpr &self) -> nb::typed<nb::object, PyMlirContext> {
587 [](
PyAffineExpr &self, uint32_t numDims, uint32_t shift,
593 nb::arg(
"num_dims"), nb::arg(
"shift"), nb::arg(
"offset") = 0)
596 [](
PyAffineExpr &self, uint32_t numSymbols, uint32_t shift,
602 nb::arg(
"num_symbols"), nb::arg(
"shift"), nb::arg(
"offset") = 0)
604 "simplify_affine_expr",
605 [](
PyAffineExpr &self, uint32_t numDims, uint32_t numSymbols) {
610 nb::arg(
"expr"), nb::arg(
"num_dims"), nb::arg(
"num_symbols"),
611 "Simplify an affine expression by flattening and some amount of "
614 "get_add", &PyAffineAddExpr::get,
615 "Gets an affine expression containing a sum of two expressions.")
616 .def_static(
"get_add", &PyAffineAddExpr::getLHSConstant,
617 "Gets an affine expression containing a sum of a constant "
618 "and another expression.")
619 .def_static(
"get_add", &PyAffineAddExpr::getRHSConstant,
620 "Gets an affine expression containing a sum of an expression "
623 "get_mul", &PyAffineMulExpr::get,
624 "Gets an affine expression containing a product of two expressions.")
625 .def_static(
"get_mul", &PyAffineMulExpr::getLHSConstant,
626 "Gets an affine expression containing a product of a "
627 "constant and another expression.")
628 .def_static(
"get_mul", &PyAffineMulExpr::getRHSConstant,
629 "Gets an affine expression containing a product of an "
630 "expression and a constant.")
631 .def_static(
"get_mod", &PyAffineModExpr::get,
632 "Gets an affine expression containing the modulo of dividing "
633 "one expression by another.")
634 .def_static(
"get_mod", &PyAffineModExpr::getLHSConstant,
635 "Gets a semi-affine expression containing the modulo of "
636 "dividing a constant by an expression.")
637 .def_static(
"get_mod", &PyAffineModExpr::getRHSConstant,
638 "Gets an affine expression containing the module of dividing"
639 "an expression by a constant.")
640 .def_static(
"get_floor_div", &PyAffineFloorDivExpr::get,
641 "Gets an affine expression containing the rounded-down "
642 "result of dividing one expression by another.")
643 .def_static(
"get_floor_div", &PyAffineFloorDivExpr::getLHSConstant,
644 "Gets a semi-affine expression containing the rounded-down "
645 "result of dividing a constant by an expression.")
646 .def_static(
"get_floor_div", &PyAffineFloorDivExpr::getRHSConstant,
647 "Gets an affine expression containing the rounded-down "
648 "result of dividing an expression by a constant.")
649 .def_static(
"get_ceil_div", &PyAffineCeilDivExpr::get,
650 "Gets an affine expression containing the rounded-up result "
651 "of dividing one expression by another.")
652 .def_static(
"get_ceil_div", &PyAffineCeilDivExpr::getLHSConstant,
653 "Gets a semi-affine expression containing the rounded-up "
654 "result of dividing a constant by an expression.")
655 .def_static(
"get_ceil_div", &PyAffineCeilDivExpr::getRHSConstant,
656 "Gets an affine expression containing the rounded-up result "
657 "of dividing an expression by a constant.")
658 .def_static(
"get_constant", &PyAffineConstantExpr::get, nb::arg(
"value"),
659 nb::arg(
"context") = nb::none(),
660 "Gets a constant affine expression with the given value.")
662 "get_dim", &PyAffineDimExpr::get, nb::arg(
"position"),
663 nb::arg(
"context") = nb::none(),
664 "Gets an affine expression of a dimension at the given position.")
666 "get_symbol", &PyAffineSymbolExpr::get, nb::arg(
"position"),
667 nb::arg(
"context") = nb::none(),
668 "Gets an affine expression of a symbol at the given position.")
672 PyAffineConstantExpr::bind(m);
673 PyAffineDimExpr::bind(m);
674 PyAffineSymbolExpr::bind(m);
675 PyAffineBinaryExpr::bind(m);
676 PyAffineAddExpr::bind(m);
677 PyAffineMulExpr::bind(m);
678 PyAffineModExpr::bind(m);
679 PyAffineFloorDivExpr::bind(m);
680 PyAffineCeilDivExpr::bind(m);
685 nb::class_<PyAffineMap>(m,
"AffineMap")
690 .def(
"__eq__", [](
PyAffineMap &self, nb::object &other) {
return false; })
693 PyPrintAccumulator printAccum;
696 return printAccum.
join();
700 PyPrintAccumulator printAccum;
701 printAccum.
parts.append(
"AffineMap(");
704 printAccum.
parts.append(
")");
705 return printAccum.
join();
709 return static_cast<size_t>(llvm::hash_value(self.
get().ptr));
712 "compress_unused_symbols",
714 SmallVector<MlirAffineMap> maps;
716 affineMaps, maps,
"attempting to create an AffineMap");
717 std::vector<MlirAffineMap> compressed(affineMaps.size());
718 auto populate = [](
void *
result, intptr_t idx, MlirAffineMap m) {
719 static_cast<MlirAffineMap *
>(
result)[idx] = (m);
722 compressed.data(), populate);
723 std::vector<PyAffineMap> res;
724 res.reserve(compressed.size());
725 for (
auto m : compressed)
726 res.emplace_back(context->getRef(), m);
731 [](
PyAffineMap &self) -> nb::typed<nb::object, PyMlirContext> {
734 "Context that owns the Affine Map")
740 [](intptr_t dimCount, intptr_t symbolCount,
const nb::list &exprs,
742 SmallVector<MlirAffineExpr> affineExprs;
744 exprs, affineExprs,
"attempting to create an AffineMap");
747 affineExprs.size(), affineExprs.data());
750 nb::arg(
"dim_count"), nb::arg(
"symbol_count"), nb::arg(
"exprs"),
751 nb::arg(
"context") = nb::none(),
752 "Gets a map with the given expressions as results.")
756 MlirAffineMap affineMap =
760 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
761 "Gets an affine map with a single constant result")
768 nb::arg(
"context") = nb::none(),
"Gets an empty affine map.")
772 MlirAffineMap affineMap =
776 nb::arg(
"n_dims"), nb::arg(
"context") = nb::none(),
777 "Gets an identity map with the given number of dimensions.")
779 "get_minor_identity",
780 [](intptr_t nDims, intptr_t nResults,
782 MlirAffineMap affineMap =
786 nb::arg(
"n_dims"), nb::arg(
"n_results"),
787 nb::arg(
"context") = nb::none(),
788 "Gets a minor identity map with the given number of dimensions and "
792 [](std::vector<unsigned> permutation,
795 throw std::runtime_error(
"Invalid permutation when attempting to "
796 "create an AffineMap");
798 context->
get(), permutation.size(), permutation.data());
801 nb::arg(
"permutation"), nb::arg(
"context") = nb::none(),
802 "Gets an affine map that permutes its inputs.")
805 [](
PyAffineMap &self, std::vector<intptr_t> &resultPos) {
807 for (intptr_t pos : resultPos) {
808 if (pos < 0 || pos >= numResults)
809 throw nb::value_error(
"result position out of bounds");
812 self, resultPos.size(), resultPos.data());
815 nb::arg(
"result_positions"))
820 throw nb::value_error(
"number of results out of bounds");
821 MlirAffineMap affineMap =
825 nb::arg(
"n_results"))
830 throw nb::value_error(
"number of results out of bounds");
831 MlirAffineMap affineMap =
835 nb::arg(
"n_results"))
840 intptr_t numResultSyms) {
842 self, expression,
replacement, numResultDims, numResultSyms);
845 nb::arg(
"expr"), nb::arg(
"replacement"), nb::arg(
"n_result_dims"),
846 nb::arg(
"n_result_syms"))
850 .def_prop_ro(
"is_projected_permutation",
863 .def_prop_ro(
"results",
864 [](
PyAffineMap &self) {
return PyAffineMapExprList(self); });
865 PyAffineMapExprList::bind(m);
870 nb::class_<PyIntegerSet>(m,
"IntegerSet")
876 [](
PyIntegerSet &self,
const nb::object &other) {
return false; })
879 PyPrintAccumulator printAccum;
882 return printAccum.
join();
886 PyPrintAccumulator printAccum;
887 printAccum.
parts.append(
"IntegerSet(");
890 printAccum.
parts.append(
")");
891 return printAccum.
join();
895 return static_cast<size_t>(llvm::hash_value(self.
get().ptr));
899 [](
PyIntegerSet &self) -> nb::typed<nb::object, PyMlirContext> {
907 [](intptr_t numDims, intptr_t numSymbols,
const nb::list &exprs,
909 if (exprs.size() != eqFlags.size())
910 throw nb::value_error(
911 "Expected the number of constraints to match "
912 "that of equality flags");
913 if (exprs.size() == 0)
914 throw nb::value_error(
"Expected non-empty list of constraints");
919 SmallVector<bool, 8> flags(eqFlags.begin(), eqFlags.end());
921 SmallVector<MlirAffineExpr> affineExprs;
923 "attempting to create an IntegerSet");
925 context->
get(), numDims, numSymbols, exprs.size(),
926 affineExprs.data(), flags.data());
929 nb::arg(
"num_dims"), nb::arg(
"num_symbols"), nb::arg(
"exprs"),
930 nb::arg(
"eq_flags"), nb::arg(
"context") = nb::none())
933 [](intptr_t numDims, intptr_t numSymbols,
939 nb::arg(
"num_dims"), nb::arg(
"num_symbols"),
940 nb::arg(
"context") = nb::none())
944 const nb::list &symbolExprs, intptr_t numResultDims,
945 intptr_t numResultSymbols) {
946 if (
static_cast<intptr_t
>(dimExprs.size()) !=
948 throw nb::value_error(
949 "Expected the number of dimension replacement expressions "
950 "to match that of dimensions");
951 if (
static_cast<intptr_t
>(symbolExprs.size()) !=
953 throw nb::value_error(
954 "Expected the number of symbol replacement expressions "
955 "to match that of symbols");
957 SmallVector<MlirAffineExpr> dimAffineExprs, symbolAffineExprs;
959 dimExprs, dimAffineExprs,
960 "attempting to create an IntegerSet by replacing dimensions");
962 symbolExprs, symbolAffineExprs,
963 "attempting to create an IntegerSet by replacing symbols");
965 self, dimAffineExprs.data(), symbolAffineExprs.data(),
966 numResultDims, numResultSymbols);
969 nb::arg(
"dim_exprs"), nb::arg(
"symbol_exprs"),
970 nb::arg(
"num_result_dims"), nb::arg(
"num_result_symbols"))
971 .def_prop_ro(
"is_canonical_empty",
984 .def_prop_ro(
"n_equalities",
988 .def_prop_ro(
"n_inequalities",
993 return PyIntegerSetConstraintList(self);
995 PyIntegerSetConstraint::bind(m);
996 PyIntegerSetConstraintList::bind(m);
MlirAffineExpr mlirAffineExprCompose(MlirAffineExpr affineExpr, MlirAffineMap affineMap)
void mlirAffineExprDump(MlirAffineExpr affineExpr)
MlirAffineExpr mlirAffineExprShiftDims(MlirAffineExpr affineExpr, uint32_t numDims, uint32_t shift, uint32_t offset)
void mlirAffineExprPrint(MlirAffineExpr affineExpr, MlirStringCallback callback, void *userData)
MlirAffineExpr mlirAffineExprShiftSymbols(MlirAffineExpr affineExpr, uint32_t numSymbols, uint32_t shift, uint32_t offset)
MlirAffineMap mlirAffineMapMultiDimIdentityGet(MlirContext ctx, intptr_t numDims)
MlirAffineMap mlirAffineMapPermutationGet(MlirContext ctx, intptr_t size, unsigned *permutation)
void mlirAffineMapDump(MlirAffineMap affineMap)
bool mlirAffineMapIsProjectedPermutation(MlirAffineMap affineMap)
MlirAffineMap mlirAffineMapConstantGet(MlirContext ctx, int64_t val)
MlirAffineExpr mlirAffineMapGetResult(MlirAffineMap affineMap, intptr_t pos)
intptr_t mlirAffineMapGetNumInputs(MlirAffineMap affineMap)
MlirAffineMap mlirAffineMapGet(MlirContext ctx, intptr_t dimCount, intptr_t symbolCount, intptr_t nAffineExprs, MlirAffineExpr *affineExprs)
MlirAffineMap mlirAffineMapGetSubMap(MlirAffineMap affineMap, intptr_t size, intptr_t *resultPos)
void mlirAffineMapPrint(MlirAffineMap affineMap, MlirStringCallback callback, void *userData)
MlirAffineMap mlirAffineMapEmptyGet(MlirContext ctx)
MlirAffineMap mlirAffineMapGetMajorSubMap(MlirAffineMap affineMap, intptr_t numResults)
MlirAffineMap mlirAffineMapMinorIdentityGet(MlirContext ctx, intptr_t dims, intptr_t results)
bool mlirAffineMapIsPermutation(MlirAffineMap affineMap)
MlirAffineMap mlirAffineMapGetMinorSubMap(MlirAffineMap affineMap, intptr_t numResults)
intptr_t mlirAffineMapGetNumDims(MlirAffineMap affineMap)
intptr_t mlirAffineMapGetNumResults(MlirAffineMap affineMap)
MlirAffineMap mlirAffineMapReplace(MlirAffineMap affineMap, MlirAffineExpr expression, MlirAffineExpr replacement, intptr_t numResultDims, intptr_t numResultSyms)
intptr_t mlirAffineMapGetNumSymbols(MlirAffineMap affineMap)
MlirIntegerSet mlirIntegerSetReplaceGet(MlirIntegerSet set, const MlirAffineExpr *dimReplacements, const MlirAffineExpr *symbolReplacements, intptr_t numResultDims, intptr_t numResultSymbols)
void mlirIntegerSetDump(MlirIntegerSet set)
intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set)
bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set)
intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set)
intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set)
intptr_t mlirIntegerSetGetNumInequalities(MlirIntegerSet set)
intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set)
MlirIntegerSet mlirIntegerSetEmptyGet(MlirContext context, intptr_t numDims, intptr_t numSymbols)
void mlirIntegerSetPrint(MlirIntegerSet set, MlirStringCallback callback, void *userData)
MlirAffineExpr mlirIntegerSetGetConstraint(MlirIntegerSet set, intptr_t pos)
intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set)
MlirIntegerSet mlirIntegerSetGet(MlirContext context, intptr_t numDims, intptr_t numSymbols, intptr_t numConstraints, const MlirAffineExpr *constraints, const bool *eqFlags)
static bool isPermutation(const std::vector< PermutationTy > &permutation)
static void pyListToVector(const nb::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 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 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 * mlirPythonAffineMapToCapsule(MlirAffineMap affineMap)
Creates a capsule object encapsulating the raw C-API MlirAffineMap.
static PyObject * mlirPythonIntegerSetToCapsule(MlirIntegerSet integerSet)
Creates a capsule object encapsulating the raw C-API MlirIntegerSet.
static MlirAffineExpr mlirPythonCapsuleToAffineExpr(PyObject *capsule)
Extracts an MlirAffineExpr from a capsule as produced from mlirPythonAffineExprToCapsule.
static PyObject * mlirPythonAffineExprToCapsule(MlirAffineExpr expr)
Creates a capsule object encapsulating the raw C-API MlirAffineExpr.
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be the output argument nBegin is set to its * replacement(set to `begin` if no invalidation happens). Since outgoing *copies could have been inserted at `end`
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.
nanobind::object getCapsule()
Gets a capsule wrapping the void* within the MlirAffineExpr.
static PyAffineExpr createFromCapsule(const nanobind::object &capsule)
Creates a PyAffineExpr from the MlirAffineExpr wrapped by a capsule.
PyAffineExpr(PyMlirContextRef contextRef, MlirAffineExpr affineExpr)
bool operator==(const PyAffineExpr &other) const
MlirAffineExpr get() const
PyAffineMap(PyMlirContextRef contextRef, MlirAffineMap affineMap)
bool operator==(const PyAffineMap &other) const
nanobind::object getCapsule()
Gets a capsule wrapping the void* within the MlirAffineMap.
MlirAffineMap get() const
static PyAffineMap createFromCapsule(const nanobind::object &capsule)
Creates a PyAffineMap from the MlirAffineMap wrapped by a capsule.
static PyIntegerSet createFromCapsule(const nanobind::object &capsule)
Creates a PyIntegerSet from the MlirAffineMap wrapped by a capsule.
MlirIntegerSet get() const
bool operator==(const PyIntegerSet &other) const
PyIntegerSet(PyMlirContextRef contextRef, MlirIntegerSet integerSet)
nanobind::object getCapsule()
Gets a capsule wrapping the void* within the MlirIntegerSet.
static PyMlirContextRef forContext(MlirContext context)
Returns a context reference for the singleton PyMlirContext wrapper for the given context.
nanobind::object getObject()
MLIR_CAPI_EXPORTED MlirAffineExpr mlirSimplifyAffineExpr(MlirAffineExpr expr, uint32_t numDims, uint32_t numSymbols)
Prints an affine expression by sending chunks of the string representation and forwarding userData to...
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 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 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 MlirContext mlirAffineMapGetContext(MlirAffineMap affineMap)
Gets the context that the given affine map was created with.
MLIR_CAPI_EXPORTED void mlirAffineMapCompressUnusedSymbols(MlirAffineMap *affineMaps, intptr_t size, void *result, void(*populateResult)(void *res, intptr_t idx, MlirAffineMap m))
Prints an affine map by sending chunks of the string representation and forwarding userData to callba...
static bool mlirAffineMapIsNull(MlirAffineMap affineMap)
Checks whether an affine map is null.
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 bool mlirIntegerSetEqual(MlirIntegerSet s1, MlirIntegerSet s2)
Checks if two integer set objects are equal.
MLIR_CAPI_EXPORTED bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set, intptr_t pos)
Prints an integer set by sending chunks of the string representation and forwarding userData to callb...
void populateIRAffine(nanobind::module_ &m)
PyObjectRef< PyMlirContext > PyMlirContextRef
Wrapper around MlirContext.
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...
MlirStringCallback getCallback()