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