xref: /llvm-project/mlir/lib/CAPI/IR/IntegerSet.cpp (revision 984b800a036fc61ccb129a8da7592af9cadc94dd)
1f5c7c031SAlex Zinenko //===- IntegerSet.cpp - C API for MLIR Integer Sets -----------------------===//
2f5c7c031SAlex Zinenko //
3f5c7c031SAlex Zinenko // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4f5c7c031SAlex Zinenko // See https://llvm.org/LICENSE.txt for license information.
5f5c7c031SAlex Zinenko // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f5c7c031SAlex Zinenko //
7f5c7c031SAlex Zinenko //===----------------------------------------------------------------------===//
8f5c7c031SAlex Zinenko 
9f5c7c031SAlex Zinenko #include "mlir-c/IntegerSet.h"
10f5c7c031SAlex Zinenko #include "mlir-c/AffineExpr.h"
11f5c7c031SAlex Zinenko #include "mlir/CAPI/AffineExpr.h"
12f5c7c031SAlex Zinenko #include "mlir/CAPI/IR.h"
13f5c7c031SAlex Zinenko #include "mlir/CAPI/IntegerSet.h"
14f5c7c031SAlex Zinenko #include "mlir/CAPI/Utils.h"
15f5c7c031SAlex Zinenko #include "mlir/IR/IntegerSet.h"
16f5c7c031SAlex Zinenko 
17f5c7c031SAlex Zinenko using namespace mlir;
18f5c7c031SAlex Zinenko 
mlirIntegerSetGetContext(MlirIntegerSet set)19f5c7c031SAlex Zinenko MlirContext mlirIntegerSetGetContext(MlirIntegerSet set) {
20f5c7c031SAlex Zinenko   return wrap(unwrap(set).getContext());
21f5c7c031SAlex Zinenko }
22f5c7c031SAlex Zinenko 
mlirIntegerSetEqual(MlirIntegerSet s1,MlirIntegerSet s2)23f5c7c031SAlex Zinenko bool mlirIntegerSetEqual(MlirIntegerSet s1, MlirIntegerSet s2) {
24f5c7c031SAlex Zinenko   return unwrap(s1) == unwrap(s2);
25f5c7c031SAlex Zinenko }
26f5c7c031SAlex Zinenko 
mlirIntegerSetPrint(MlirIntegerSet set,MlirStringCallback callback,void * userData)27f5c7c031SAlex Zinenko void mlirIntegerSetPrint(MlirIntegerSet set, MlirStringCallback callback,
28f5c7c031SAlex Zinenko                          void *userData) {
29f5c7c031SAlex Zinenko   mlir::detail::CallbackOstream stream(callback, userData);
30f5c7c031SAlex Zinenko   unwrap(set).print(stream);
31f5c7c031SAlex Zinenko }
32f5c7c031SAlex Zinenko 
mlirIntegerSetDump(MlirIntegerSet set)33f5c7c031SAlex Zinenko void mlirIntegerSetDump(MlirIntegerSet set) { unwrap(set).dump(); }
34f5c7c031SAlex Zinenko 
mlirIntegerSetEmptyGet(MlirContext context,intptr_t numDims,intptr_t numSymbols)35f5c7c031SAlex Zinenko MlirIntegerSet mlirIntegerSetEmptyGet(MlirContext context, intptr_t numDims,
36f5c7c031SAlex Zinenko                                       intptr_t numSymbols) {
37f5c7c031SAlex Zinenko   return wrap(IntegerSet::getEmptySet(static_cast<unsigned>(numDims),
38f5c7c031SAlex Zinenko                                       static_cast<unsigned>(numSymbols),
39f5c7c031SAlex Zinenko                                       unwrap(context)));
40f5c7c031SAlex Zinenko }
41f5c7c031SAlex Zinenko 
mlirIntegerSetGet(MlirContext context,intptr_t numDims,intptr_t numSymbols,intptr_t numConstraints,const MlirAffineExpr * constraints,const bool * eqFlags)42f5c7c031SAlex Zinenko MlirIntegerSet mlirIntegerSetGet(MlirContext context, intptr_t numDims,
43f5c7c031SAlex Zinenko                                  intptr_t numSymbols, intptr_t numConstraints,
44f5c7c031SAlex Zinenko                                  const MlirAffineExpr *constraints,
45f5c7c031SAlex Zinenko                                  const bool *eqFlags) {
46f5c7c031SAlex Zinenko   SmallVector<AffineExpr> mlirConstraints;
47f5c7c031SAlex Zinenko   (void)unwrapList(static_cast<size_t>(numConstraints), constraints,
48f5c7c031SAlex Zinenko                    mlirConstraints);
49f5c7c031SAlex Zinenko   return wrap(IntegerSet::get(
50f5c7c031SAlex Zinenko       static_cast<unsigned>(numDims), static_cast<unsigned>(numSymbols),
51f5c7c031SAlex Zinenko       mlirConstraints,
52*984b800aSserge-sans-paille       llvm::ArrayRef(eqFlags, static_cast<size_t>(numConstraints))));
53f5c7c031SAlex Zinenko }
54f5c7c031SAlex Zinenko 
55f5c7c031SAlex Zinenko MlirIntegerSet
mlirIntegerSetReplaceGet(MlirIntegerSet set,const MlirAffineExpr * dimReplacements,const MlirAffineExpr * symbolReplacements,intptr_t numResultDims,intptr_t numResultSymbols)56f5c7c031SAlex Zinenko mlirIntegerSetReplaceGet(MlirIntegerSet set,
57f5c7c031SAlex Zinenko                          const MlirAffineExpr *dimReplacements,
58f5c7c031SAlex Zinenko                          const MlirAffineExpr *symbolReplacements,
59f5c7c031SAlex Zinenko                          intptr_t numResultDims, intptr_t numResultSymbols) {
60f5c7c031SAlex Zinenko   SmallVector<AffineExpr> mlirDims, mlirSymbols;
61f5c7c031SAlex Zinenko   (void)unwrapList(unwrap(set).getNumDims(), dimReplacements, mlirDims);
62f5c7c031SAlex Zinenko   (void)unwrapList(unwrap(set).getNumSymbols(), symbolReplacements,
63f5c7c031SAlex Zinenko                    mlirSymbols);
64f5c7c031SAlex Zinenko   return wrap(unwrap(set).replaceDimsAndSymbols(
65f5c7c031SAlex Zinenko       mlirDims, mlirSymbols, static_cast<unsigned>(numResultDims),
66f5c7c031SAlex Zinenko       static_cast<unsigned>(numResultSymbols)));
67f5c7c031SAlex Zinenko }
68f5c7c031SAlex Zinenko 
mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set)69f5c7c031SAlex Zinenko bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set) {
70f5c7c031SAlex Zinenko   return unwrap(set).isEmptyIntegerSet();
71f5c7c031SAlex Zinenko }
72f5c7c031SAlex Zinenko 
mlirIntegerSetGetNumDims(MlirIntegerSet set)73f5c7c031SAlex Zinenko intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set) {
74f5c7c031SAlex Zinenko   return static_cast<intptr_t>(unwrap(set).getNumDims());
75f5c7c031SAlex Zinenko }
76f5c7c031SAlex Zinenko 
mlirIntegerSetGetNumSymbols(MlirIntegerSet set)77f5c7c031SAlex Zinenko intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set) {
78f5c7c031SAlex Zinenko   return static_cast<intptr_t>(unwrap(set).getNumSymbols());
79f5c7c031SAlex Zinenko }
80f5c7c031SAlex Zinenko 
mlirIntegerSetGetNumInputs(MlirIntegerSet set)81f5c7c031SAlex Zinenko intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set) {
82f5c7c031SAlex Zinenko   return static_cast<intptr_t>(unwrap(set).getNumInputs());
83f5c7c031SAlex Zinenko }
84f5c7c031SAlex Zinenko 
mlirIntegerSetGetNumConstraints(MlirIntegerSet set)85f5c7c031SAlex Zinenko intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set) {
86f5c7c031SAlex Zinenko   return static_cast<intptr_t>(unwrap(set).getNumConstraints());
87f5c7c031SAlex Zinenko }
88f5c7c031SAlex Zinenko 
mlirIntegerSetGetNumEqualities(MlirIntegerSet set)89f5c7c031SAlex Zinenko intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set) {
90f5c7c031SAlex Zinenko   return static_cast<intptr_t>(unwrap(set).getNumEqualities());
91f5c7c031SAlex Zinenko }
92f5c7c031SAlex Zinenko 
mlirIntegerSetGetNumInequalities(MlirIntegerSet set)93f5c7c031SAlex Zinenko intptr_t mlirIntegerSetGetNumInequalities(MlirIntegerSet set) {
94f5c7c031SAlex Zinenko   return static_cast<intptr_t>(unwrap(set).getNumInequalities());
95f5c7c031SAlex Zinenko }
96f5c7c031SAlex Zinenko 
mlirIntegerSetGetConstraint(MlirIntegerSet set,intptr_t pos)97f5c7c031SAlex Zinenko MlirAffineExpr mlirIntegerSetGetConstraint(MlirIntegerSet set, intptr_t pos) {
98f5c7c031SAlex Zinenko   return wrap(unwrap(set).getConstraint(static_cast<unsigned>(pos)));
99f5c7c031SAlex Zinenko }
100f5c7c031SAlex Zinenko 
mlirIntegerSetIsConstraintEq(MlirIntegerSet set,intptr_t pos)101f5c7c031SAlex Zinenko bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set, intptr_t pos) {
102f5c7c031SAlex Zinenko   return unwrap(set).isEq(pos);
103f5c7c031SAlex Zinenko }
104