1//===- IntegerSet.cpp - C API for MLIR Integer Sets -----------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
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"
16
17using namespace mlir;
18
19MlirContext mlirIntegerSetGetContext(MlirIntegerSet set) {
20 return wrap(cpp: unwrap(c: set).getContext());
21}
22
23bool mlirIntegerSetEqual(MlirIntegerSet s1, MlirIntegerSet s2) {
24 return unwrap(c: s1) == unwrap(c: s2);
25}
26
27void mlirIntegerSetPrint(MlirIntegerSet set, MlirStringCallback callback,
28 void *userData) {
29 mlir::detail::CallbackOstream stream(callback, userData);
30 unwrap(c: set).print(os&: stream);
31}
32
33void mlirIntegerSetDump(MlirIntegerSet set) {
34 unwrap(c: set).print(os&: llvm::errs());
35 llvm::errs() << "\n";
36}
37
38MlirIntegerSet mlirIntegerSetEmptyGet(MlirContext context, intptr_t numDims,
39 intptr_t numSymbols) {
40 return wrap(cpp: IntegerSet::getEmptySet(numDims: static_cast<unsigned>(numDims),
41 numSymbols: static_cast<unsigned>(numSymbols),
42 context: unwrap(c: context)));
43}
44
45MlirIntegerSet mlirIntegerSetGet(MlirContext context, intptr_t numDims,
46 intptr_t numSymbols, intptr_t numConstraints,
47 const MlirAffineExpr *constraints,
48 const bool *eqFlags) {
49 SmallVector<AffineExpr> mlirConstraints;
50 (void)unwrapList(size: static_cast<size_t>(numConstraints), first: constraints,
51 storage&: mlirConstraints);
52 return wrap(cpp: IntegerSet::get(
53 dimCount: static_cast<unsigned>(numDims), symbolCount: static_cast<unsigned>(numSymbols),
54 constraints: mlirConstraints,
55 eqFlags: llvm::ArrayRef(eqFlags, static_cast<size_t>(numConstraints))));
56}
57
58MlirIntegerSet
59mlirIntegerSetReplaceGet(MlirIntegerSet set,
60 const MlirAffineExpr *dimReplacements,
61 const MlirAffineExpr *symbolReplacements,
62 intptr_t numResultDims, intptr_t numResultSymbols) {
63 SmallVector<AffineExpr> mlirDims, mlirSymbols;
64 (void)unwrapList(size: unwrap(c: set).getNumDims(), first: dimReplacements, storage&: mlirDims);
65 (void)unwrapList(size: unwrap(c: set).getNumSymbols(), first: symbolReplacements,
66 storage&: mlirSymbols);
67 return wrap(cpp: unwrap(c: set).replaceDimsAndSymbols(
68 dimReplacements: mlirDims, symReplacements: mlirSymbols, numResultDims: static_cast<unsigned>(numResultDims),
69 numResultSyms: static_cast<unsigned>(numResultSymbols)));
70}
71
72bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set) {
73 return unwrap(c: set).isEmptyIntegerSet();
74}
75
76intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set) {
77 return static_cast<intptr_t>(unwrap(c: set).getNumDims());
78}
79
80intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set) {
81 return static_cast<intptr_t>(unwrap(c: set).getNumSymbols());
82}
83
84intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set) {
85 return static_cast<intptr_t>(unwrap(c: set).getNumInputs());
86}
87
88intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set) {
89 return static_cast<intptr_t>(unwrap(c: set).getNumConstraints());
90}
91
92intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set) {
93 return static_cast<intptr_t>(unwrap(c: set).getNumEqualities());
94}
95
96intptr_t mlirIntegerSetGetNumInequalities(MlirIntegerSet set) {
97 return static_cast<intptr_t>(unwrap(c: set).getNumInequalities());
98}
99
100MlirAffineExpr mlirIntegerSetGetConstraint(MlirIntegerSet set, intptr_t pos) {
101 return wrap(cpp: unwrap(c: set).getConstraint(idx: static_cast<unsigned>(pos)));
102}
103
104bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set, intptr_t pos) {
105 return unwrap(c: set).isEq(idx: pos);
106}
107