1+ #ifndef MLIR_C_PRESBURGER_H
2+ #define MLIR_C_PRESBURGER_H
3+ #include "mlir-c/AffineExpr.h"
4+ #include "mlir-c/Support.h"
5+
6+ #ifdef __cplusplus
7+ extern "C" {
8+ #endif
9+
10+ enum MlirPresburgerVariableKind {
11+ Symbol ,
12+ Local ,
13+ Domain ,
14+ Range ,
15+ SetDim = Range
16+ };
17+
18+ #define DEFINE_C_API_STRUCT (name , storage ) \
19+ struct name { \
20+ storage *ptr; \
21+ }; \
22+ typedef struct name name
23+ DEFINE_C_API_STRUCT (MlirPresburgerIntegerRelation , void );
24+ DEFINE_C_API_STRUCT (MlirPresburgerDynamicAPInt , const void );
25+ #undef DEFINE_C_API_STRUCT
26+
27+ //===----------------------------------------------------------------------===//
28+ // IntegerRelation creation/destruction and basic metadata operations
29+ //===----------------------------------------------------------------------===//
30+
31+ /// Constructs a relation reserving memory for the specified number
32+ /// of constraints and variables.
33+ MLIR_CAPI_EXPORTED MlirPresburgerIntegerRelation
34+ mlirPresburgerIntegerRelationCreate (unsigned numReservedInequalities ,
35+ unsigned numReservedEqualities ,
36+ unsigned numReservedCols );
37+
38+ /// Constructs an IntegerRelation from a packed 2D matrix of tableau
39+ /// coefficients in row-major order. The first `numDomainVars` columns are
40+ /// considered domain and the remaining `numRangeVars` columns are domain
41+ /// variables.
42+ MLIR_CAPI_EXPORTED MlirPresburgerIntegerRelation
43+ mlirPresburgerIntegerRelationCreateFromCoefficients (
44+ const int64_t * inequalityCoefficients , unsigned numInequalities ,
45+ const int64_t * equalityCoefficients , unsigned numEqualities ,
46+ unsigned numDomainVars , unsigned numRangeVars ,
47+ unsigned numExtraReservedInequalities = 0 ,
48+ unsigned numExtraReservedEqualities = 0 , unsigned numExtraReservedCols = 0 );
49+
50+ /// Destroys an IntegerRelation.
51+ MLIR_CAPI_EXPORTED void
52+ mlirPresburgerIntegerRelationDestroy (MlirPresburgerIntegerRelation relation );
53+
54+ //===----------------------------------------------------------------------===//
55+ // IntegerRelation binary operations
56+ //===----------------------------------------------------------------------===//
57+
58+ MLIR_CAPI_EXPORTED void
59+ mlirPresburgerIntegerRelationAppend (MlirPresburgerIntegerRelation lhs ,
60+ MlirPresburgerIntegerRelation rhs );
61+
62+ /// Return the intersection of the two relations.
63+ /// If there are locals, they will be merged.
64+ MLIR_CAPI_EXPORTED MlirPresburgerIntegerRelation
65+ mlirPresburgerIntegerRelationIntersect (MlirPresburgerIntegerRelation lhs ,
66+ MlirPresburgerIntegerRelation rhs );
67+
68+ /// Return whether `lhs` and `rhs` are equal. This is integer-exact
69+ /// and somewhat expensive, since it uses the integer emptiness check
70+ /// (see IntegerRelation::findIntegerSample()).
71+ MLIR_CAPI_EXPORTED bool
72+ mlirPresburgerIntegerRelationIsEqual (MlirPresburgerIntegerRelation lhs ,
73+ MlirPresburgerIntegerRelation rhs );
74+
75+ MLIR_CAPI_EXPORTED bool mlirPresburgerIntegerRelationIsObviouslyEqual (
76+ MlirPresburgerIntegerRelation lhs , MlirPresburgerIntegerRelation rhs );
77+
78+ MLIR_CAPI_EXPORTED bool
79+ mlirPresburgerIntegerRelationIsSubsetOf (MlirPresburgerIntegerRelation lhs ,
80+ MlirPresburgerIntegerRelation rhs );
81+
82+ //===----------------------------------------------------------------------===//
83+ // IntegerRelation Tableau Inspection
84+ //===----------------------------------------------------------------------===//
85+
86+ /// Returns the value at the specified equality row and column.
87+ MLIR_CAPI_EXPORTED MlirPresburgerDynamicAPInt
88+ mlirPresburgerIntegerRelationAtEq (unsigned i , unsigned j );
89+
90+ /// The same, but casts to int64_t. This is unsafe and will assert-fail if the
91+ /// value does not fit in an int64_t.
92+ MLIR_CAPI_EXPORTED int64_t mlirPresburgerIntegerRelationAtEq64 (
93+ MlirPresburgerIntegerRelation relation , unsigned row , unsigned col );
94+
95+ /// Returns the value at the specified inequality row and column.
96+ MLIR_CAPI_EXPORTED MlirPresburgerDynamicAPInt
97+ mlirPresburgerIntegerRelationAtIneq (MlirPresburgerIntegerRelation relation ,
98+ unsigned row , unsigned col );
99+
100+ MLIR_CAPI_EXPORTED int64_t mlirPresburgerIntegerRelationAtIneq64 (
101+ MlirPresburgerIntegerRelation relation , unsigned row , unsigned col );
102+
103+ /// Returns the number of inequalities and equalities.
104+ MLIR_CAPI_EXPORTED unsigned mlirPresburgerIntegerRelationNumConstraints (
105+ MlirPresburgerIntegerRelation relation );
106+
107+ /// Returns the number of columns classified as domain variables.
108+ MLIR_CAPI_EXPORTED unsigned mlirPresburgerIntegerRelationNumDomainVars (
109+ MlirPresburgerIntegerRelation relation );
110+
111+ /// Returns the number of columns classified as range variables.
112+ MLIR_CAPI_EXPORTED unsigned mlirPresburgerIntegerRelationNumRangeVars (
113+ MlirPresburgerIntegerRelation relation );
114+
115+ /// Returns the number of columns classified as symbol variables.
116+ MLIR_CAPI_EXPORTED unsigned mlirPresburgerIntegerRelationNumSymbolVars (
117+ MlirPresburgerIntegerRelation relation );
118+
119+ /// Returns the number of columns classified as local variables.
120+ MLIR_CAPI_EXPORTED unsigned mlirPresburgerIntegerRelationNumLocalVars (
121+ MlirPresburgerIntegerRelation relation );
122+
123+ MLIR_CAPI_EXPORTED unsigned
124+ mlirPresburgerIntegerRelationNumDimVars (MlirPresburgerIntegerRelation relation );
125+
126+ MLIR_CAPI_EXPORTED unsigned mlirPresburgerIntegerRelationNumDimAndSymbolVars (
127+ MlirPresburgerIntegerRelation relation );
128+
129+ MLIR_CAPI_EXPORTED unsigned
130+ mlirPresburgerIntegerRelationNumVars (MlirPresburgerIntegerRelation relation );
131+
132+ MLIR_CAPI_EXPORTED unsigned
133+ mlirPresburgerIntegerRelationNumCols (MlirPresburgerIntegerRelation relation );
134+
135+ /// Returns the number of equality constraints.
136+ MLIR_CAPI_EXPORTED unsigned mlirPresburgerIntegerRelationNumEqualities (
137+ MlirPresburgerIntegerRelation relation );
138+
139+ /// Returns the number of inequality constraints.
140+ MLIR_CAPI_EXPORTED unsigned mlirPresburgerIntegerRelationNumInequalities (
141+ MlirPresburgerIntegerRelation relation );
142+
143+ MLIR_CAPI_EXPORTED unsigned mlirPresburgerIntegerRelationNumReservedEqualities (
144+ MlirPresburgerIntegerRelation relation );
145+
146+ MLIR_CAPI_EXPORTED unsigned
147+ mlirPresburgerIntegerRelationNumReservedInequalities (
148+ MlirPresburgerIntegerRelation relation );
149+
150+ /// Return the VarKind of the var at the specified position.
151+ MLIR_CAPI_EXPORTED MlirPresburgerVariableKind
152+ mlirPresburgerIntegerRelationGetVarKindAt (unsigned pos );
153+
154+ //===----------------------------------------------------------------------===//
155+ // IntegerRelation Tableau Manipulation
156+ //===----------------------------------------------------------------------===//
157+ /// Adds an equality with the given coefficients.
158+ MLIR_CAPI_EXPORTED void
159+ mlirPresburgerIntegerRelationAddEquality (const int64_t * coefficients ,
160+ size_t coefficientsSize );
161+
162+ /// Adds an inequality with the given coefficients.
163+ MLIR_CAPI_EXPORTED void
164+ mlirPresburgerIntegerRelationAddInequality (const int64_t * coefficients ,
165+ size_t coefficientsSize );
166+
167+ MLIR_CAPI_EXPORTED void
168+ mlirPresburgerIntegerRelationDump (MlirPresburgerIntegerRelation relation );
169+ #ifdef __cplusplus
170+ }
171+ #endif
172+ #endif // MLIR_C_PRESBURGER_H
0 commit comments