24 #include "llvm/ADT/Hashing.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/ADT/Twine.h"
34 using llvm::StringRef;
38 R
"(Dumps a debug representation of the object to stderr.)";
44 template <
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());
66 template <
typename PermutationTy>
69 for (
auto val : permutation) {
70 if (val < permutation.size()) {
86 template <
typename DerivedTy,
typename BaseTy = PyAffineExpr>
87 class PyConcreteAffineExpr :
public BaseTy {
93 using ClassTy = nb::class_<DerivedTy, BaseTy>;
94 using IsAFunctionTy = bool (*)(MlirAffineExpr);
96 PyConcreteAffineExpr() =
default;
98 : BaseTy(std::move(contextRef), affineExpr) {}
100 : PyConcreteAffineExpr(orig.
getContext(), castFrom(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"));
120 return DerivedTy::isaFunction(otherAffineExpr);
123 DerivedTy::bindDerived(cls);
127 static void bindDerived(ClassTy &m) {}
130 class PyAffineConstantExpr :
public PyConcreteAffineExpr<PyAffineConstantExpr> {
133 static constexpr
const char *pyClassName =
"AffineConstantExpr";
134 using PyConcreteAffineExpr::PyConcreteAffineExpr;
136 static PyAffineConstantExpr
get(intptr_t value,
138 MlirAffineExpr affineExpr =
140 return PyAffineConstantExpr(context->getRef(), affineExpr);
143 static void bindDerived(ClassTy &c) {
145 nb::arg(
"context").none() = nb::none());
146 c.def_prop_ro(
"value", [](PyAffineConstantExpr &
self) {
152 class PyAffineDimExpr :
public PyConcreteAffineExpr<PyAffineDimExpr> {
155 static constexpr
const char *pyClassName =
"AffineDimExpr";
156 using PyConcreteAffineExpr::PyConcreteAffineExpr;
160 return PyAffineDimExpr(context->getRef(), affineExpr);
163 static void bindDerived(ClassTy &c) {
165 nb::arg(
"context").none() = nb::none());
166 c.def_prop_ro(
"position", [](PyAffineDimExpr &
self) {
172 class PyAffineSymbolExpr :
public PyConcreteAffineExpr<PyAffineSymbolExpr> {
175 static constexpr
const char *pyClassName =
"AffineSymbolExpr";
176 using PyConcreteAffineExpr::PyConcreteAffineExpr;
180 return PyAffineSymbolExpr(context->getRef(), affineExpr);
183 static void bindDerived(ClassTy &c) {
185 nb::arg(
"context").none() = nb::none());
186 c.def_prop_ro(
"position", [](PyAffineSymbolExpr &
self) {
192 class 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);
214 class PyAffineAddExpr
215 :
public PyConcreteAffineExpr<PyAffineAddExpr, PyAffineBinaryExpr> {
218 static constexpr
const char *pyClassName =
"AffineAddExpr";
219 using PyConcreteAffineExpr::PyConcreteAffineExpr;
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) {
243 class PyAffineMulExpr
244 :
public PyConcreteAffineExpr<PyAffineMulExpr, PyAffineBinaryExpr> {
247 static constexpr
const char *pyClassName =
"AffineMulExpr";
248 using PyConcreteAffineExpr::PyConcreteAffineExpr;
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) {
272 class PyAffineModExpr
273 :
public PyConcreteAffineExpr<PyAffineModExpr, PyAffineBinaryExpr> {
276 static constexpr
const char *pyClassName =
"AffineModExpr";
277 using PyConcreteAffineExpr::PyConcreteAffineExpr;
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) {
301 class PyAffineFloorDivExpr
302 :
public PyConcreteAffineExpr<PyAffineFloorDivExpr, PyAffineBinaryExpr> {
305 static constexpr
const char *pyClassName =
"AffineFloorDivExpr";
306 using PyConcreteAffineExpr::PyConcreteAffineExpr;
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) {
330 class PyAffineCeilDivExpr
331 :
public PyConcreteAffineExpr<PyAffineCeilDivExpr, PyAffineBinaryExpr> {
334 static constexpr
const char *pyClassName =
"AffineCeilDivExpr";
335 using PyConcreteAffineExpr::PyConcreteAffineExpr;
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) {
372 throw nb::python_error();
387 class 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);
430 throw nb::python_error();
441 class 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);
464 class 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)
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")
520 .def(
"__add__", &PyAffineAddExpr::getRHSConstant)
521 .def(
"__radd__", &PyAffineAddExpr::getRHSConstant)
523 .def(
"__mul__", &PyAffineMulExpr::getRHSConstant)
524 .def(
"__rmul__", &PyAffineMulExpr::getRHSConstant)
526 .def(
"__mod__", &PyAffineModExpr::getRHSConstant)
548 return PyAffineAddExpr::getLHSConstant(
549 other, PyAffineMulExpr::getLHSConstant(-1,
self));
554 [](
PyAffineExpr &
self, nb::object &other) {
return false; })
560 return printAccum.
join();
565 printAccum.
parts.append(
"AffineExpr(");
568 printAccum.
parts.append(
")");
569 return printAccum.
join();
577 [](
PyAffineExpr &
self) {
return self.getContext().getObject(); })
585 [](
PyAffineExpr &
self, uint32_t numDims, uint32_t shift,
591 nb::arg(
"num_dims"), nb::arg(
"shift"), nb::arg(
"offset").none() = 0)
594 [](
PyAffineExpr &
self, uint32_t numSymbols, uint32_t shift,
600 nb::arg(
"num_symbols"), nb::arg(
"shift"),
601 nb::arg(
"offset").none() = 0)
603 "simplify_affine_expr",
604 [](
PyAffineExpr &
self, uint32_t numDims, uint32_t numSymbols) {
609 nb::arg(
"expr"), nb::arg(
"num_dims"), nb::arg(
"num_symbols"),
610 "Simplify an affine expression by flattening and some amount of "
614 "Gets an affine expression containing a sum of two expressions.")
615 .def_static(
"get_add", &PyAffineAddExpr::getLHSConstant,
616 "Gets an affine expression containing a sum of a constant "
617 "and another expression.")
618 .def_static(
"get_add", &PyAffineAddExpr::getRHSConstant,
619 "Gets an affine expression containing a sum of an expression "
623 "Gets an affine expression containing a product of two expressions.")
624 .def_static(
"get_mul", &PyAffineMulExpr::getLHSConstant,
625 "Gets an affine expression containing a product of a "
626 "constant and another expression.")
627 .def_static(
"get_mul", &PyAffineMulExpr::getRHSConstant,
628 "Gets an affine expression containing a product of an "
629 "expression and a constant.")
631 "Gets an affine expression containing the modulo of dividing "
632 "one expression by another.")
633 .def_static(
"get_mod", &PyAffineModExpr::getLHSConstant,
634 "Gets a semi-affine expression containing the modulo of "
635 "dividing a constant by an expression.")
636 .def_static(
"get_mod", &PyAffineModExpr::getRHSConstant,
637 "Gets an affine expression containing the module of dividing"
638 "an expression by a constant.")
640 "Gets an affine expression containing the rounded-down "
641 "result of dividing one expression by another.")
642 .def_static(
"get_floor_div", &PyAffineFloorDivExpr::getLHSConstant,
643 "Gets a semi-affine expression containing the rounded-down "
644 "result of dividing a constant by an expression.")
645 .def_static(
"get_floor_div", &PyAffineFloorDivExpr::getRHSConstant,
646 "Gets an affine expression containing the rounded-down "
647 "result of dividing an expression by a constant.")
649 "Gets an affine expression containing the rounded-up result "
650 "of dividing one expression by another.")
651 .def_static(
"get_ceil_div", &PyAffineCeilDivExpr::getLHSConstant,
652 "Gets a semi-affine expression containing the rounded-up "
653 "result of dividing a constant by an expression.")
654 .def_static(
"get_ceil_div", &PyAffineCeilDivExpr::getRHSConstant,
655 "Gets an affine expression containing the rounded-up result "
656 "of dividing an expression by a constant.")
658 nb::arg(
"context").none() = nb::none(),
659 "Gets a constant affine expression with the given value.")
662 nb::arg(
"context").none() = nb::none(),
663 "Gets an affine expression of a dimension at the given position.")
666 nb::arg(
"context").none() = nb::none(),
667 "Gets an affine expression of a symbol at the given position.")
671 PyAffineConstantExpr::bind(m);
672 PyAffineDimExpr::bind(m);
673 PyAffineSymbolExpr::bind(m);
674 PyAffineBinaryExpr::bind(m);
675 PyAffineAddExpr::bind(m);
676 PyAffineMulExpr::bind(m);
677 PyAffineModExpr::bind(m);
678 PyAffineFloorDivExpr::bind(m);
679 PyAffineCeilDivExpr::bind(m);
684 nb::class_<PyAffineMap>(m,
"AffineMap")
689 .def(
"__eq__", [](
PyAffineMap &
self, nb::object &other) {
return false; })
695 return printAccum.
join();
700 printAccum.
parts.append(
"AffineMap(");
703 printAccum.
parts.append(
")");
704 return printAccum.
join();
710 .def_static(
"compress_unused_symbols",
713 pyListToVector<PyAffineMap, MlirAffineMap>(
714 affineMaps, maps,
"attempting to create an AffineMap");
715 std::vector<MlirAffineMap> compressed(affineMaps.size());
716 auto populate = [](
void *result, intptr_t idx,
718 static_cast<MlirAffineMap *
>(result)[idx] = (m);
721 maps.data(), maps.size(), compressed.data(), populate);
722 std::vector<PyAffineMap> res;
723 res.reserve(compressed.size());
724 for (
auto m : compressed)
725 res.emplace_back(context->getRef(), m);
730 [](
PyAffineMap &
self) {
return self.getContext().getObject(); },
731 "Context that owns the Affine Map")
737 [](intptr_t dimCount, intptr_t symbolCount, nb::list exprs,
740 pyListToVector<PyAffineExpr, MlirAffineExpr>(
741 exprs, affineExprs,
"attempting to create an AffineMap");
744 affineExprs.size(), affineExprs.data());
747 nb::arg(
"dim_count"), nb::arg(
"symbol_count"), nb::arg(
"exprs"),
748 nb::arg(
"context").none() = nb::none(),
749 "Gets a map with the given expressions as results.")
753 MlirAffineMap affineMap =
757 nb::arg(
"value"), nb::arg(
"context").none() = nb::none(),
758 "Gets an affine map with a single constant result")
765 nb::arg(
"context").none() = nb::none(),
"Gets an empty affine map.")
769 MlirAffineMap affineMap =
773 nb::arg(
"n_dims"), nb::arg(
"context").none() = nb::none(),
774 "Gets an identity map with the given number of dimensions.")
776 "get_minor_identity",
777 [](intptr_t nDims, intptr_t nResults,
779 MlirAffineMap affineMap =
783 nb::arg(
"n_dims"), nb::arg(
"n_results"),
784 nb::arg(
"context").none() = nb::none(),
785 "Gets a minor identity map with the given number of dimensions and "
789 [](std::vector<unsigned> permutation,
792 throw std::runtime_error(
"Invalid permutation when attempting to "
793 "create an AffineMap");
795 context->
get(), permutation.size(), permutation.data());
798 nb::arg(
"permutation"), nb::arg(
"context").none() = nb::none(),
799 "Gets an affine map that permutes its inputs.")
802 [](
PyAffineMap &
self, std::vector<intptr_t> &resultPos) {
804 for (intptr_t pos : resultPos) {
805 if (pos < 0 || pos >= numResults)
806 throw nb::value_error(
"result position out of bounds");
809 self, resultPos.size(), resultPos.data());
812 nb::arg(
"result_positions"))
817 throw nb::value_error(
"number of results out of bounds");
818 MlirAffineMap affineMap =
822 nb::arg(
"n_results"))
827 throw nb::value_error(
"number of results out of bounds");
828 MlirAffineMap affineMap =
832 nb::arg(
"n_results"))
837 intptr_t numResultSyms) {
839 self, expression, replacement, numResultDims, numResultSyms);
842 nb::arg(
"expr"), nb::arg(
"replacement"), nb::arg(
"n_result_dims"),
843 nb::arg(
"n_result_syms"))
847 .def_prop_ro(
"is_projected_permutation",
860 .def_prop_ro(
"results",
861 [](
PyAffineMap &
self) {
return PyAffineMapExprList(
self); });
862 PyAffineMapExprList::bind(m);
867 nb::class_<PyIntegerSet>(m,
"IntegerSet")
872 .def(
"__eq__", [](
PyIntegerSet &
self, nb::object other) {
return false; })
878 return printAccum.
join();
883 printAccum.
parts.append(
"IntegerSet(");
886 printAccum.
parts.append(
")");
887 return printAccum.
join();
895 [](
PyIntegerSet &
self) {
return self.getContext().getObject(); })
901 [](intptr_t numDims, intptr_t numSymbols, nb::list exprs,
903 if (exprs.size() != eqFlags.size())
904 throw nb::value_error(
905 "Expected the number of constraints to match "
906 "that of equality flags");
907 if (exprs.size() == 0)
908 throw nb::value_error(
"Expected non-empty list of constraints");
916 pyListToVector<PyAffineExpr>(exprs, affineExprs,
917 "attempting to create an IntegerSet");
919 context->
get(), numDims, numSymbols, exprs.size(),
920 affineExprs.data(), flags.data());
923 nb::arg(
"num_dims"), nb::arg(
"num_symbols"), nb::arg(
"exprs"),
924 nb::arg(
"eq_flags"), nb::arg(
"context").none() = nb::none())
927 [](intptr_t numDims, intptr_t numSymbols,
933 nb::arg(
"num_dims"), nb::arg(
"num_symbols"),
934 nb::arg(
"context").none() = nb::none())
937 [](
PyIntegerSet &
self, nb::list dimExprs, nb::list symbolExprs,
938 intptr_t numResultDims, intptr_t numResultSymbols) {
939 if (
static_cast<intptr_t
>(dimExprs.size()) !=
941 throw nb::value_error(
942 "Expected the number of dimension replacement expressions "
943 "to match that of dimensions");
944 if (
static_cast<intptr_t
>(symbolExprs.size()) !=
946 throw nb::value_error(
947 "Expected the number of symbol replacement expressions "
948 "to match that of symbols");
951 pyListToVector<PyAffineExpr>(
952 dimExprs, dimAffineExprs,
953 "attempting to create an IntegerSet by replacing dimensions");
954 pyListToVector<PyAffineExpr>(
955 symbolExprs, symbolAffineExprs,
956 "attempting to create an IntegerSet by replacing symbols");
958 self, dimAffineExprs.data(), symbolAffineExprs.data(),
959 numResultDims, numResultSymbols);
962 nb::arg(
"dim_exprs"), nb::arg(
"symbol_exprs"),
963 nb::arg(
"num_result_dims"), nb::arg(
"num_result_symbols"))
964 .def_prop_ro(
"is_canonical_empty",
977 .def_prop_ro(
"n_equalities",
981 .def_prop_ro(
"n_inequalities",
986 return PyIntegerSetConstraintList(
self);
988 PyIntegerSetConstraint::bind(m);
989 PyIntegerSetConstraintList::bind(m);
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 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.
nanobind::object getCapsule()
Gets a capsule wrapping the void* within the MlirAffineExpr.
PyAffineExpr(PyMlirContextRef contextRef, MlirAffineExpr affineExpr)
static PyAffineExpr createFromCapsule(nanobind::object capsule)
Creates a PyAffineExpr from the MlirAffineExpr wrapped by a capsule.
bool operator==(const PyAffineExpr &other) const
PyAffineMap(PyMlirContextRef contextRef, MlirAffineMap affineMap)
bool operator==(const PyAffineMap &other) const
nanobind::object getCapsule()
Gets a capsule wrapping the void* within the MlirAffineMap.
static PyAffineMap createFromCapsule(nanobind::object capsule)
Creates a PyAffineMap from the MlirAffineMap wrapped by a capsule.
bool operator==(const PyIntegerSet &other) const
static PyIntegerSet createFromCapsule(nanobind::object capsule)
Creates a PyIntegerSet from the MlirAffineMap wrapped by a capsule.
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.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineExprShiftDims(MlirAffineExpr affineExpr, uint32_t numDims, uint32_t shift, uint32_t offset)
Replace dims[offset ...
MLIR_CAPI_EXPORTED MlirAffineExpr mlirSimplifyAffineExpr(MlirAffineExpr expr, uint32_t numDims, uint32_t numSymbols)
Simplify an affine expression by flattening and some amount of simple analysis.
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 MlirAffineExpr mlirAffineExprShiftSymbols(MlirAffineExpr affineExpr, uint32_t numSymbols, uint32_t shift, uint32_t offset)
Replace symbols[offset ...
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(nanobind::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()