forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAffineExpr.h
216 lines (164 loc) · 9.49 KB
/
AffineExpr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//===-- mlir-c/AffineExpr.h - C API for MLIR Affine Expressions ---*- C -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
// Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_C_AFFINEEXPR_H
#define MLIR_C_AFFINEEXPR_H
#include "mlir-c/IR.h"
#ifdef __cplusplus
extern "C" {
#endif
//===----------------------------------------------------------------------===//
// Opaque type declarations.
//
// Types are exposed to C bindings as structs containing opaque pointers. They
// are not supposed to be inspected from C. This allows the underlying
// representation to change without affecting the API users. The use of structs
// instead of typedefs enables some type safety as structs are not implicitly
// convertible to each other.
//
// Instances of these types may or may not own the underlying object. The
// ownership semantics is defined by how an instance of the type was obtained.
//===----------------------------------------------------------------------===//
#define DEFINE_C_API_STRUCT(name, storage) \
struct name { \
storage *ptr; \
}; \
typedef struct name name
DEFINE_C_API_STRUCT(MlirAffineExpr, const void);
#undef DEFINE_C_API_STRUCT
struct MlirAffineMap;
/// Gets the context that owns the affine expression.
MLIR_CAPI_EXPORTED MlirContext
mlirAffineExprGetContext(MlirAffineExpr affineExpr);
/// Returns `true` if the two affine expressions are equal.
MLIR_CAPI_EXPORTED bool mlirAffineExprEqual(MlirAffineExpr lhs,
MlirAffineExpr rhs);
/// Returns `true` if the given affine expression is a null expression. Note
/// constant zero is not a null expression.
inline static bool mlirAffineExprIsNull(MlirAffineExpr affineExpr) {
return affineExpr.ptr == NULL;
}
/// Prints an affine expression by sending chunks of the string representation
/// and forwarding `userData to `callback`. Note that the callback may be called
/// several times with consecutive chunks of the string.
MLIR_CAPI_EXPORTED void mlirAffineExprPrint(MlirAffineExpr affineExpr,
MlirStringCallback callback,
void *userData);
/// Prints the affine expression to the standard error stream.
MLIR_CAPI_EXPORTED void mlirAffineExprDump(MlirAffineExpr affineExpr);
/// Checks whether the given affine expression is made out of only symbols and
/// constants.
MLIR_CAPI_EXPORTED bool
mlirAffineExprIsSymbolicOrConstant(MlirAffineExpr affineExpr);
/// Checks whether the given affine expression is a pure affine expression, i.e.
/// mul, floordiv, ceildic, and mod is only allowed w.r.t constants.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsPureAffine(MlirAffineExpr affineExpr);
/// Returns the greatest known integral divisor of this affine expression. The
/// result is always positive.
MLIR_CAPI_EXPORTED int64_t
mlirAffineExprGetLargestKnownDivisor(MlirAffineExpr affineExpr);
/// Checks whether the given affine expression is a multiple of 'factor'.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsMultipleOf(MlirAffineExpr affineExpr,
int64_t factor);
/// Checks whether the given affine expression involves AffineDimExpr
/// 'position'.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsFunctionOfDim(MlirAffineExpr affineExpr,
intptr_t position);
/// Composes the given map with the given expression.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineExprCompose(
MlirAffineExpr affineExpr, struct MlirAffineMap affineMap);
//===----------------------------------------------------------------------===//
// Affine Dimension Expression.
//===----------------------------------------------------------------------===//
/// Checks whether the given affine expression is a dimension expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsADim(MlirAffineExpr affineExpr);
/// Creates an affine dimension expression with 'position' in the context.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineDimExprGet(MlirContext ctx,
intptr_t position);
/// Returns the position of the given affine dimension expression.
MLIR_CAPI_EXPORTED intptr_t
mlirAffineDimExprGetPosition(MlirAffineExpr affineExpr);
//===----------------------------------------------------------------------===//
// Affine Symbol Expression.
//===----------------------------------------------------------------------===//
/// Checks whether the given affine expression is a symbol expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsASymbol(MlirAffineExpr affineExpr);
/// Creates an affine symbol expression with 'position' in the context.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineSymbolExprGet(MlirContext ctx,
intptr_t position);
/// Returns the position of the given affine symbol expression.
MLIR_CAPI_EXPORTED intptr_t
mlirAffineSymbolExprGetPosition(MlirAffineExpr affineExpr);
//===----------------------------------------------------------------------===//
// Affine Constant Expression.
//===----------------------------------------------------------------------===//
/// Checks whether the given affine expression is a constant expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAConstant(MlirAffineExpr affineExpr);
/// Creates an affine constant expression with 'constant' in the context.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineConstantExprGet(MlirContext ctx,
int64_t constant);
/// Returns the value of the given affine constant expression.
MLIR_CAPI_EXPORTED int64_t
mlirAffineConstantExprGetValue(MlirAffineExpr affineExpr);
//===----------------------------------------------------------------------===//
// Affine Add Expression.
//===----------------------------------------------------------------------===//
/// Checks whether the given affine expression is an add expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAAdd(MlirAffineExpr affineExpr);
/// Creates an affine add expression with 'lhs' and 'rhs'.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineAddExprGet(MlirAffineExpr lhs,
MlirAffineExpr rhs);
//===----------------------------------------------------------------------===//
// Affine Mul Expression.
//===----------------------------------------------------------------------===//
/// Checks whether the given affine expression is an mul expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMul(MlirAffineExpr affineExpr);
/// Creates an affine mul expression with 'lhs' and 'rhs'.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineMulExprGet(MlirAffineExpr lhs,
MlirAffineExpr rhs);
//===----------------------------------------------------------------------===//
// Affine Mod Expression.
//===----------------------------------------------------------------------===//
/// Checks whether the given affine expression is an mod expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMod(MlirAffineExpr affineExpr);
/// Creates an affine mod expression with 'lhs' and 'rhs'.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineModExprGet(MlirAffineExpr lhs,
MlirAffineExpr rhs);
//===----------------------------------------------------------------------===//
// Affine FloorDiv Expression.
//===----------------------------------------------------------------------===//
/// Checks whether the given affine expression is an floordiv expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAFloorDiv(MlirAffineExpr affineExpr);
/// Creates an affine floordiv expression with 'lhs' and 'rhs'.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineFloorDivExprGet(MlirAffineExpr lhs,
MlirAffineExpr rhs);
//===----------------------------------------------------------------------===//
// Affine CeilDiv Expression.
//===----------------------------------------------------------------------===//
/// Checks whether the given affine expression is an ceildiv expression.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsACeilDiv(MlirAffineExpr affineExpr);
/// Creates an affine ceildiv expression with 'lhs' and 'rhs'.
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineCeilDivExprGet(MlirAffineExpr lhs,
MlirAffineExpr rhs);
//===----------------------------------------------------------------------===//
// Affine Binary Operation Expression.
//===----------------------------------------------------------------------===//
/// Checks whether the given affine expression is binary.
MLIR_CAPI_EXPORTED bool mlirAffineExprIsABinary(MlirAffineExpr affineExpr);
/// Returns the left hand side affine expression of the given affine binary
/// operation expression.
MLIR_CAPI_EXPORTED MlirAffineExpr
mlirAffineBinaryOpExprGetLHS(MlirAffineExpr affineExpr);
/// Returns the right hand side affine expression of the given affine binary
/// operation expression.
MLIR_CAPI_EXPORTED MlirAffineExpr
mlirAffineBinaryOpExprGetRHS(MlirAffineExpr affineExpr);
#ifdef __cplusplus
}
#endif
#endif // MLIR_C_AFFINEEXPR_H