MLIR  20.0.0git
IntegerSet.h
Go to the documentation of this file.
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
16 extern "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 
38 DEFINE_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.
43 MLIR_CAPI_EXPORTED MlirContext mlirIntegerSetGetContext(MlirIntegerSet set);
44 
45 /// Checks whether an integer set is a null object.
46 static 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.
54 MLIR_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.
60 MLIR_CAPI_EXPORTED void mlirIntegerSetPrint(MlirIntegerSet set,
61  MlirStringCallback callback,
62  void *userData);
63 
64 /// Prints an integer set to the standard error stream.
65 MLIR_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.
69 MLIR_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.
78 MLIR_CAPI_EXPORTED MlirIntegerSet
79 mlirIntegerSetGet(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.
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.
96 MLIR_CAPI_EXPORTED bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set);
97 
98 /// Returns the number of dimensions in the given set.
99 MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set);
100 
101 /// Returns the number of symbols in the given set.
102 MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set);
103 
104 /// Returns the number of inputs (dimensions + symbols) in the given set.
105 MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set);
106 
107 /// Returns the number of constraints (equalities + inequalities) in the given
108 /// set.
109 MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set);
110 
111 /// Returns the number of equalities in the given set.
112 MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set);
113 
114 /// Returns the number of inequalities in the given set.
115 MLIR_CAPI_EXPORTED intptr_t
116 mlirIntegerSetGetNumInequalities(MlirIntegerSet set);
117 
118 /// Returns `pos`-th constraint of the set.
119 MLIR_CAPI_EXPORTED MlirAffineExpr
120 mlirIntegerSetGetConstraint(MlirIntegerSet set, intptr_t pos);
121 
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,
125  intptr_t pos);
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif // MLIR_C_INTEGERSET_H
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumConstraints(MlirIntegerSet set)
Returns the number of constraints (equalities + inequalities) in the given set.
Definition: IntegerSet.cpp:85
MLIR_CAPI_EXPORTED MlirAffineExpr mlirIntegerSetGetConstraint(MlirIntegerSet set, intptr_t pos)
Returns pos-th constraint of the set.
Definition: IntegerSet.cpp:97
MLIR_CAPI_EXPORTED bool mlirIntegerSetIsCanonicalEmpty(MlirIntegerSet set)
Checks whether the given set is a canonical empty set, e.g., the set returned by mlirIntegerSetEmptyG...
Definition: IntegerSet.cpp:69
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumInputs(MlirIntegerSet set)
Returns the number of inputs (dimensions + symbols) in the given set.
Definition: IntegerSet.cpp:81
MLIR_CAPI_EXPORTED MlirIntegerSet mlirIntegerSetEmptyGet(MlirContext context, intptr_t numDims, intptr_t numSymbols)
Gets or creates a new canonically empty integer set with the give number of dimensions and symbols in...
Definition: IntegerSet.cpp:35
MLIR_CAPI_EXPORTED MlirIntegerSet mlirIntegerSetGet(MlirContext context, intptr_t numDims, intptr_t numSymbols, intptr_t numConstraints, const MlirAffineExpr *constraints, const bool *eqFlags)
Gets or creates a new integer set in the given context.
Definition: IntegerSet.cpp:42
#define DEFINE_C_API_STRUCT(name, storage)
Definition: IntegerSet.h:32
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumEqualities(MlirIntegerSet set)
Returns the number of equalities in the given set.
Definition: IntegerSet.cpp:89
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumDims(MlirIntegerSet set)
Returns the number of dimensions in the given set.
Definition: IntegerSet.cpp:73
MLIR_CAPI_EXPORTED MlirIntegerSet mlirIntegerSetReplaceGet(MlirIntegerSet set, const MlirAffineExpr *dimReplacements, const MlirAffineExpr *symbolReplacements, intptr_t numResultDims, intptr_t numResultSymbols)
Gets or creates a new integer set in which the values and dimensions of the given set are replaced wi...
Definition: IntegerSet.cpp:56
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumSymbols(MlirIntegerSet set)
Returns the number of symbols in the given set.
Definition: IntegerSet.cpp:77
static bool mlirIntegerSetIsNull(MlirIntegerSet set)
Checks whether an integer set is a null object.
Definition: IntegerSet.h:46
MLIR_CAPI_EXPORTED MlirContext mlirIntegerSetGetContext(MlirIntegerSet set)
Gets the context in which the given integer set lives.
Definition: IntegerSet.cpp:19
MLIR_CAPI_EXPORTED void mlirIntegerSetPrint(MlirIntegerSet set, MlirStringCallback callback, void *userData)
Prints an integer set by sending chunks of the string representation and forwarding userData tocallba...
Definition: IntegerSet.cpp:27
MLIR_CAPI_EXPORTED bool mlirIntegerSetEqual(MlirIntegerSet s1, MlirIntegerSet s2)
Checks if two integer set objects are equal.
Definition: IntegerSet.cpp:23
MLIR_CAPI_EXPORTED bool mlirIntegerSetIsConstraintEq(MlirIntegerSet set, intptr_t pos)
Returns true of the pos-th constraint of the set is an equality constraint, false otherwise.
Definition: IntegerSet.cpp:101
MLIR_CAPI_EXPORTED void mlirIntegerSetDump(MlirIntegerSet set)
Prints an integer set to the standard error stream.
Definition: IntegerSet.cpp:33
MLIR_CAPI_EXPORTED intptr_t mlirIntegerSetGetNumInequalities(MlirIntegerSet set)
Returns the number of inequalities in the given set.
Definition: IntegerSet.cpp:93
#define MLIR_CAPI_EXPORTED
Definition: Support.h:46
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition: Support.h:105