1//===-- mlir-c/IntegerSet.h - C API for MLIR Affine maps ----------*- C -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4// Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef MLIR_C_INTEGERSET_H
11#define MLIR_C_INTEGERSET_H
12
13#include "mlir-c/AffineExpr.h"
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19//===----------------------------------------------------------------------===//
20// Opaque type declarations.
21//
22// Types are exposed to C bindings as structs containing opaque pointers. They
23// are not supposed to be inspected from C. This allows the underlying
24// representation to change without affecting the API users. The use of structs
25// instead of typedefs enables some type safety as structs are not implicitly
26// convertible to each other.
27//
28// Instances of these types may or may not own the underlying object. The
29// ownership semantics is defined by how an instance of the type was obtained.
30//===----------------------------------------------------------------------===//
31
32#define DEFINE_C_API_STRUCT(name, storage) \
33 struct name { \
34 storage *ptr; \
35 }; \
36 typedef struct name name
37
38DEFINE_C_API_STRUCT(MlirIntegerSet, const void);
39
40#undef DEFINE_C_API_STRUCT
41
42/// Gets the context in which the given integer set lives.
43MLIR_CAPI_EXPORTED MlirContext mlirIntegerSetGetContext(MlirIntegerSet set);
44
45/// Checks whether an integer set is a null object.
46static inline bool mlirIntegerSetIsNull(MlirIntegerSet set) { return !set.ptr; }
47
48/// Checks if two integer set objects are equal. This is a "shallow" comparison
49/// of two objects. Only the sets with some small number of constraints are
50/// uniqued and compare equal here. Set objects that represent the same integer
51/// set with different constraints may be considered non-equal by this check.
52/// Set difference followed by an (expensive) emptiness check should be used to
53/// check equivalence of the underlying integer sets.
54MLIR_CAPI_EXPORTED bool mlirIntegerSetEqual(MlirIntegerSet s1,
55 MlirIntegerSet s2);
56
57/// Prints an integer set by sending chunks of the string representation and
58/// forwarding `userData to `callback`. Note that the callback may be called
59/// several times with consecutive chunks of the string.
60MLIR_CAPI_EXPORTED void mlirIntegerSetPrint(MlirIntegerSet set,
61 MlirStringCallback callback,
62 void *userData);
63
64/// Prints an integer set to the standard error stream.
65MLIR_CAPI_EXPORTED void mlirIntegerSetDump(MlirIntegerSet set);
66
67/// Gets or creates a new canonically empty integer set with the give number of
68/// dimensions and symbols in the given context.
69MLIR_CAPI_EXPORTED MlirIntegerSet mlirIntegerSetEmptyGet(MlirContext context,
70 intptr_t numDims,
71 intptr_t numSymbols);
72
73/// Gets or creates a new integer set in the given context. The set is defined
74/// by a list of affine constraints, with the given number of input dimensions
75/// and symbols, which are treated as either equalities (eqFlags is 1) or
76/// inequalities (eqFlags is 0). Both `constraints` and `eqFlags` are expected
77/// to point to at least `numConstraint` consecutive values.
78MLIR_CAPI_EXPORTED MlirIntegerSet
79mlirIntegerSetGet(MlirContext context, intptr_t numDims, intptr_t numSymbols,
80 intptr_t numConstraints, const MlirAffineExpr *constraints,
81 const bool *eqFlags);
82
83/// Gets or creates a new integer set in which the values and dimensions of the
84/// given set are replaced with the given affine expressions. `dimReplacements`
85/// and `symbolReplacements` are expected to point to at least as many
86/// consecutive expressions as the given set has dimensions and symbols,
87/// respectively. The new set will have `numResultDims` and `numResultSymbols`
88/// dimensions and symbols, respectively.
89MLIR_CAPI_EXPORTED MlirIntegerSet mlirIntegerSetReplaceGet(
90 MlirIntegerSet set, const MlirAffineExpr *dimReplacements,
91 const MlirAffineExpr *symbolReplacements, intptr_t numResultDims,
92 intptr_t numResultSymbols);
93
94/// Checks whether the given set is a canonical empty set, e.g., the set
95/// returned by mlirIntegerSetEmptyGet.
96MLIR_CAPI_EXPORTED bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set);
97
98/// Returns the number of dimensions in the given set.
99MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set);
100
101/// Returns the number of symbols in the given set.
102MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set);
103
104/// Returns the number of inputs (dimensions + symbols) in the given set.
105MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set);
106
107/// Returns the number of constraints (equalities + inequalities) in the given
108/// set.
109MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set);
110
111/// Returns the number of equalities in the given set.
112MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set);
113
114/// Returns the number of inequalities in the given set.
115MLIR_CAPI_EXPORTED intptr_t
116mlirIntegerSetGetNumInequalities(MlirIntegerSet set);
117
118/// Returns `pos`-th constraint of the set.
119MLIR_CAPI_EXPORTED MlirAffineExpr
120mlirIntegerSetGetConstraint(MlirIntegerSet set, intptr_t pos);
121
122/// Returns `true` of the `pos`-th constraint of the set is an equality
123/// constraint, `false` otherwise.
124MLIR_CAPI_EXPORTED bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set,
125 intptr_t pos);
126
127#ifdef __cplusplus
128}
129#endif
130
131#endif // MLIR_C_INTEGERSET_H
132

source code of mlir/include/mlir-c/IntegerSet.h