MLIR 24.0.0git
IntegerSet.cpp
Go to the documentation of this file.
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"
12#include "mlir/CAPI/IR.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(unwrap(set).getContext());
21}
22
23bool mlirIntegerSetEqual(MlirIntegerSet s1, MlirIntegerSet s2) {
24 return unwrap(s1) == unwrap(s2);
25}
26
27void mlirIntegerSetPrint(MlirIntegerSet set, MlirStringCallback callback,
28 void *userData) {
29 mlir::detail::CallbackOstream stream(callback, userData);
30 unwrap(set).print(stream);
31}
32
33void mlirIntegerSetDump(MlirIntegerSet set) {
34 unwrap(set).print(llvm::errs());
35 llvm::errs() << "\n";
36}
37
38MlirIntegerSet mlirIntegerSetEmptyGet(MlirContext context, intptr_t numDims,
39 intptr_t numSymbols) {
40 return wrap(IntegerSet::getEmptySet(static_cast<unsigned>(numDims),
41 static_cast<unsigned>(numSymbols),
42 unwrap(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(static_cast<size_t>(numConstraints), constraints,
51 mlirConstraints);
52 return wrap(IntegerSet::get(
53 static_cast<unsigned>(numDims), static_cast<unsigned>(numSymbols),
54 mlirConstraints,
55 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(unwrap(set).getNumDims(), dimReplacements, mlirDims);
65 (void)unwrapList(unwrap(set).getNumSymbols(), symbolReplacements,
66 mlirSymbols);
67 return wrap(unwrap(set).replaceDimsAndSymbols(
68 mlirDims, mlirSymbols, static_cast<unsigned>(numResultDims),
69 static_cast<unsigned>(numResultSymbols)));
70}
71
72bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set) {
73 return unwrap(set).isEmptyIntegerSet();
74}
75
77 return static_cast<intptr_t>(unwrap(set).getNumDims());
78}
79
81 return static_cast<intptr_t>(unwrap(set).getNumSymbols());
82}
83
85 return static_cast<intptr_t>(unwrap(set).getNumInputs());
86}
87
89 return static_cast<intptr_t>(unwrap(set).getNumConstraints());
90}
91
93 return static_cast<intptr_t>(unwrap(set).getNumEqualities());
94}
95
97 return static_cast<intptr_t>(unwrap(set).getNumInequalities());
98}
99
100MlirAffineExpr mlirIntegerSetGetConstraint(MlirIntegerSet set, intptr_t pos) {
101 return wrap(unwrap(set).getConstraint(static_cast<unsigned>(pos)));
102}
103
104bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set, intptr_t pos) {
105 return unwrap(set).isEq(pos);
106}
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)
bool mlirIntegerSetEqual(MlirIntegerSet s1, MlirIntegerSet s2)
Checks if two integer set objects are equal.
void mlirIntegerSetPrint(MlirIntegerSet set, MlirStringCallback callback, void *userData)
MlirContext mlirIntegerSetGetContext(MlirIntegerSet set)
Gets the context in which the given integer set lives.
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)
bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set, intptr_t pos)
Prints an integer set by sending chunks of the string representation and forwarding userData to callb...
b getContext())
llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Definition Wrap.h:40
void print(raw_ostream &os, std::optional< int64_t > messagePartIndex=std::nullopt) const
Outputs this diagnostic to a stream.
static IntegerSet get(unsigned dimCount, unsigned symbolCount, ArrayRef< AffineExpr > constraints, ArrayRef< bool > eqFlags)
static IntegerSet getEmptySet(unsigned numDims, unsigned numSymbols, MLIRContext *context)
Definition IntegerSet.h:56
A simple raw ostream subclass that forwards write_impl calls to the user-supplied callback together w...
Definition Utils.h:30
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition Diagnostics.h:24
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition Diagnostics.h:19
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition Support.h:110
Include the generated interface declarations.