1 //===-- mlir-c/IntegerSet.h - C API for MLIR Affine maps ----------*- C -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef MLIR_C_INTEGERSET_H
11 #define MLIR_C_INTEGERSET_H
13 #include "mlir-c/AffineExpr.h"
19 //===----------------------------------------------------------------------===//
20 // Opaque type declarations.
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.
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 //===----------------------------------------------------------------------===//
32 #define DEFINE_C_API_STRUCT(name, storage) \
36 typedef struct name name
38 DEFINE_C_API_STRUCT(MlirIntegerSet
, const void);
40 #undef DEFINE_C_API_STRUCT
42 /// Gets the context in which the given integer set lives.
43 MLIR_CAPI_EXPORTED MlirContext
mlirIntegerSetGetContext(MlirIntegerSet set
);
45 /// Checks whether an integer set is a null object.
46 static inline bool mlirIntegerSetIsNull(MlirIntegerSet set
) { return !set
.ptr
; }
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.
54 MLIR_CAPI_EXPORTED
bool mlirIntegerSetEqual(MlirIntegerSet s1
,
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.
60 MLIR_CAPI_EXPORTED
void mlirIntegerSetPrint(MlirIntegerSet set
,
61 MlirStringCallback callback
,
64 /// Prints an integer set to the standard error stream.
65 MLIR_CAPI_EXPORTED
void mlirIntegerSetDump(MlirIntegerSet set
);
67 /// Gets or creates a new canonically empty integer set with the give number of
68 /// dimensions and symbols in the given context.
69 MLIR_CAPI_EXPORTED MlirIntegerSet
mlirIntegerSetEmptyGet(MlirContext context
,
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.
78 MLIR_CAPI_EXPORTED MlirIntegerSet
79 mlirIntegerSetGet(MlirContext context
, intptr_t numDims
, intptr_t numSymbols
,
80 intptr_t numConstraints
, const MlirAffineExpr
*constraints
,
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.
89 MLIR_CAPI_EXPORTED MlirIntegerSet
mlirIntegerSetReplaceGet(
90 MlirIntegerSet set
, const MlirAffineExpr
*dimReplacements
,
91 const MlirAffineExpr
*symbolReplacements
, intptr_t numResultDims
,
92 intptr_t numResultSymbols
);
94 /// Checks whether the given set is a canonical empty set, e.g., the set
95 /// returned by mlirIntegerSetEmptyGet.
96 MLIR_CAPI_EXPORTED
bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set
);
98 /// Returns the number of dimensions in the given set.
99 MLIR_CAPI_EXPORTED
intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set
);
101 /// Returns the number of symbols in the given set.
102 MLIR_CAPI_EXPORTED
intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set
);
104 /// Returns the number of inputs (dimensions + symbols) in the given set.
105 MLIR_CAPI_EXPORTED
intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set
);
107 /// Returns the number of constraints (equalities + inequalities) in the given
109 MLIR_CAPI_EXPORTED
intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set
);
111 /// Returns the number of equalities in the given set.
112 MLIR_CAPI_EXPORTED
intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set
);
114 /// Returns the number of inequalities in the given set.
115 MLIR_CAPI_EXPORTED
intptr_t
116 mlirIntegerSetGetNumInequalities(MlirIntegerSet set
);
118 /// Returns `pos`-th constraint of the set.
119 MLIR_CAPI_EXPORTED MlirAffineExpr
120 mlirIntegerSetGetConstraint(MlirIntegerSet set
, intptr_t pos
);
122 /// Returns `true` of the `pos`-th constraint of the set is an equality
123 /// constraint, `false` otherwise.
124 MLIR_CAPI_EXPORTED
bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set
,
131 #endif // MLIR_C_INTEGERSET_H