1 //===- IntegerSet.cpp - C API for MLIR Integer Sets -----------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "mlir-c/IntegerSet.h"
10 #include "mlir-c/AffineExpr.h"
11 #include "mlir/CAPI/AffineExpr.h"
12 #include "mlir/CAPI/IR.h"
13 #include "mlir/CAPI/IntegerSet.h"
14 #include "mlir/CAPI/Utils.h"
15 #include "mlir/IR/IntegerSet.h"
19 MlirContext
mlirIntegerSetGetContext(MlirIntegerSet set
) {
20 return wrap(unwrap(set
).getContext());
23 bool mlirIntegerSetEqual(MlirIntegerSet s1
, MlirIntegerSet s2
) {
24 return unwrap(s1
) == unwrap(s2
);
27 void mlirIntegerSetPrint(MlirIntegerSet set
, MlirStringCallback callback
,
29 mlir::detail::CallbackOstream
stream(callback
, userData
);
30 unwrap(set
).print(stream
);
33 void mlirIntegerSetDump(MlirIntegerSet set
) { unwrap(set
).dump(); }
35 MlirIntegerSet
mlirIntegerSetEmptyGet(MlirContext context
, intptr_t numDims
,
36 intptr_t numSymbols
) {
37 return wrap(IntegerSet::getEmptySet(static_cast<unsigned>(numDims
),
38 static_cast<unsigned>(numSymbols
),
42 MlirIntegerSet
mlirIntegerSetGet(MlirContext context
, intptr_t numDims
,
43 intptr_t numSymbols
, intptr_t numConstraints
,
44 const MlirAffineExpr
*constraints
,
45 const bool *eqFlags
) {
46 SmallVector
<AffineExpr
> mlirConstraints
;
47 (void)unwrapList(static_cast<size_t>(numConstraints
), constraints
,
49 return wrap(IntegerSet::get(
50 static_cast<unsigned>(numDims
), static_cast<unsigned>(numSymbols
),
52 llvm::ArrayRef(eqFlags
, static_cast<size_t>(numConstraints
))));
56 mlirIntegerSetReplaceGet(MlirIntegerSet set
,
57 const MlirAffineExpr
*dimReplacements
,
58 const MlirAffineExpr
*symbolReplacements
,
59 intptr_t numResultDims
, intptr_t numResultSymbols
) {
60 SmallVector
<AffineExpr
> mlirDims
, mlirSymbols
;
61 (void)unwrapList(unwrap(set
).getNumDims(), dimReplacements
, mlirDims
);
62 (void)unwrapList(unwrap(set
).getNumSymbols(), symbolReplacements
,
64 return wrap(unwrap(set
).replaceDimsAndSymbols(
65 mlirDims
, mlirSymbols
, static_cast<unsigned>(numResultDims
),
66 static_cast<unsigned>(numResultSymbols
)));
69 bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set
) {
70 return unwrap(set
).isEmptyIntegerSet();
73 intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set
) {
74 return static_cast<intptr_t>(unwrap(set
).getNumDims());
77 intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set
) {
78 return static_cast<intptr_t>(unwrap(set
).getNumSymbols());
81 intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set
) {
82 return static_cast<intptr_t>(unwrap(set
).getNumInputs());
85 intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set
) {
86 return static_cast<intptr_t>(unwrap(set
).getNumConstraints());
89 intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set
) {
90 return static_cast<intptr_t>(unwrap(set
).getNumEqualities());
93 intptr_t mlirIntegerSetGetNumInequalities(MlirIntegerSet set
) {
94 return static_cast<intptr_t>(unwrap(set
).getNumInequalities());
97 MlirAffineExpr
mlirIntegerSetGetConstraint(MlirIntegerSet set
, intptr_t pos
) {
98 return wrap(unwrap(set
).getConstraint(static_cast<unsigned>(pos
)));
101 bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set
, intptr_t pos
) {
102 return unwrap(set
).isEq(pos
);