MLIR  21.0.0git
AffineExpr.h
Go to the documentation of this file.
1 //===-- mlir-c/AffineExpr.h - C API for MLIR Affine Expressions ---*- 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_AFFINEEXPR_H
11 #define MLIR_C_AFFINEEXPR_H
12 
13 #include "mlir-c/IR.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(MlirAffineExpr, const void);
39 
40 #undef DEFINE_C_API_STRUCT
41 
42 struct MlirAffineMap;
43 
44 /// Gets the context that owns the affine expression.
45 MLIR_CAPI_EXPORTED MlirContext
46 mlirAffineExprGetContext(MlirAffineExpr affineExpr);
47 
48 /// Returns `true` if the two affine expressions are equal.
49 MLIR_CAPI_EXPORTED bool mlirAffineExprEqual(MlirAffineExpr lhs,
50  MlirAffineExpr rhs);
51 
52 /// Returns `true` if the given affine expression is a null expression. Note
53 /// constant zero is not a null expression.
54 inline static bool mlirAffineExprIsNull(MlirAffineExpr affineExpr) {
55  return affineExpr.ptr == NULL;
56 }
57 
58 /// Prints an affine expression by sending chunks of the string representation
59 /// and forwarding `userData to `callback`. Note that the callback may be called
60 /// several times with consecutive chunks of the string.
61 MLIR_CAPI_EXPORTED void mlirAffineExprPrint(MlirAffineExpr affineExpr,
62  MlirStringCallback callback,
63  void *userData);
64 
65 /// Prints the affine expression to the standard error stream.
66 MLIR_CAPI_EXPORTED void mlirAffineExprDump(MlirAffineExpr affineExpr);
67 
68 /// Checks whether the given affine expression is made out of only symbols and
69 /// constants.
71 mlirAffineExprIsSymbolicOrConstant(MlirAffineExpr affineExpr);
72 
73 /// Checks whether the given affine expression is a pure affine expression, i.e.
74 /// mul, floordiv, ceildic, and mod is only allowed w.r.t constants.
75 MLIR_CAPI_EXPORTED bool mlirAffineExprIsPureAffine(MlirAffineExpr affineExpr);
76 
77 /// Returns the greatest known integral divisor of this affine expression. The
78 /// result is always positive.
79 MLIR_CAPI_EXPORTED int64_t
80 mlirAffineExprGetLargestKnownDivisor(MlirAffineExpr affineExpr);
81 
82 /// Checks whether the given affine expression is a multiple of 'factor'.
83 MLIR_CAPI_EXPORTED bool mlirAffineExprIsMultipleOf(MlirAffineExpr affineExpr,
84  int64_t factor);
85 
86 /// Checks whether the given affine expression involves AffineDimExpr
87 /// 'position'.
88 MLIR_CAPI_EXPORTED bool mlirAffineExprIsFunctionOfDim(MlirAffineExpr affineExpr,
89  intptr_t position);
90 
91 /// Composes the given map with the given expression.
93  MlirAffineExpr affineExpr, struct MlirAffineMap affineMap);
94 
95 /// Replace dims[offset ... numDims)
96 /// by dims[offset + shift ... shift + numDims).
97 MLIR_CAPI_EXPORTED MlirAffineExpr
98 mlirAffineExprShiftDims(MlirAffineExpr affineExpr, uint32_t numDims,
99  uint32_t shift, uint32_t offset);
100 
101 /// Replace symbols[offset ... numSymbols)
102 /// by symbols[offset + shift ... shift + numSymbols).
103 MLIR_CAPI_EXPORTED MlirAffineExpr
104 mlirAffineExprShiftSymbols(MlirAffineExpr affineExpr, uint32_t numSymbols,
105  uint32_t shift, uint32_t offset);
106 
107 /// Simplify an affine expression by flattening and some amount of simple
108 /// analysis. This has complexity linear in the number of nodes in 'expr'.
109 /// Returns the simplified expression, which is the same as the input expression
110 /// if it can't be simplified. When `expr` is semi-affine, a simplified
111 /// semi-affine expression is constructed in the sorted order of dimension and
112 /// symbol positions.
113 MLIR_CAPI_EXPORTED MlirAffineExpr mlirSimplifyAffineExpr(MlirAffineExpr expr,
114  uint32_t numDims,
115  uint32_t numSymbols);
116 
117 //===----------------------------------------------------------------------===//
118 // Affine Dimension Expression.
119 //===----------------------------------------------------------------------===//
120 
121 /// Checks whether the given affine expression is a dimension expression.
122 MLIR_CAPI_EXPORTED bool mlirAffineExprIsADim(MlirAffineExpr affineExpr);
123 
124 /// Creates an affine dimension expression with 'position' in the context.
125 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineDimExprGet(MlirContext ctx,
126  intptr_t position);
127 
128 /// Returns the position of the given affine dimension expression.
129 MLIR_CAPI_EXPORTED intptr_t
130 mlirAffineDimExprGetPosition(MlirAffineExpr affineExpr);
131 
132 //===----------------------------------------------------------------------===//
133 // Affine Symbol Expression.
134 //===----------------------------------------------------------------------===//
135 
136 /// Checks whether the given affine expression is a symbol expression.
137 MLIR_CAPI_EXPORTED bool mlirAffineExprIsASymbol(MlirAffineExpr affineExpr);
138 
139 /// Creates an affine symbol expression with 'position' in the context.
140 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineSymbolExprGet(MlirContext ctx,
141  intptr_t position);
142 
143 /// Returns the position of the given affine symbol expression.
144 MLIR_CAPI_EXPORTED intptr_t
145 mlirAffineSymbolExprGetPosition(MlirAffineExpr affineExpr);
146 
147 //===----------------------------------------------------------------------===//
148 // Affine Constant Expression.
149 //===----------------------------------------------------------------------===//
150 
151 /// Checks whether the given affine expression is a constant expression.
152 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAConstant(MlirAffineExpr affineExpr);
153 
154 /// Creates an affine constant expression with 'constant' in the context.
155 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineConstantExprGet(MlirContext ctx,
156  int64_t constant);
157 
158 /// Returns the value of the given affine constant expression.
159 MLIR_CAPI_EXPORTED int64_t
160 mlirAffineConstantExprGetValue(MlirAffineExpr affineExpr);
161 
162 //===----------------------------------------------------------------------===//
163 // Affine Add Expression.
164 //===----------------------------------------------------------------------===//
165 
166 /// Checks whether the given affine expression is an add expression.
167 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAAdd(MlirAffineExpr affineExpr);
168 
169 /// Creates an affine add expression with 'lhs' and 'rhs'.
170 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineAddExprGet(MlirAffineExpr lhs,
171  MlirAffineExpr rhs);
172 
173 //===----------------------------------------------------------------------===//
174 // Affine Mul Expression.
175 //===----------------------------------------------------------------------===//
176 
177 /// Checks whether the given affine expression is an mul expression.
178 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMul(MlirAffineExpr affineExpr);
179 
180 /// Creates an affine mul expression with 'lhs' and 'rhs'.
181 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineMulExprGet(MlirAffineExpr lhs,
182  MlirAffineExpr rhs);
183 
184 //===----------------------------------------------------------------------===//
185 // Affine Mod Expression.
186 //===----------------------------------------------------------------------===//
187 
188 /// Checks whether the given affine expression is an mod expression.
189 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMod(MlirAffineExpr affineExpr);
190 
191 /// Creates an affine mod expression with 'lhs' and 'rhs'.
192 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineModExprGet(MlirAffineExpr lhs,
193  MlirAffineExpr rhs);
194 
195 //===----------------------------------------------------------------------===//
196 // Affine FloorDiv Expression.
197 //===----------------------------------------------------------------------===//
198 
199 /// Checks whether the given affine expression is an floordiv expression.
200 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAFloorDiv(MlirAffineExpr affineExpr);
201 
202 /// Creates an affine floordiv expression with 'lhs' and 'rhs'.
203 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineFloorDivExprGet(MlirAffineExpr lhs,
204  MlirAffineExpr rhs);
205 
206 //===----------------------------------------------------------------------===//
207 // Affine CeilDiv Expression.
208 //===----------------------------------------------------------------------===//
209 
210 /// Checks whether the given affine expression is an ceildiv expression.
211 MLIR_CAPI_EXPORTED bool mlirAffineExprIsACeilDiv(MlirAffineExpr affineExpr);
212 
213 /// Creates an affine ceildiv expression with 'lhs' and 'rhs'.
214 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineCeilDivExprGet(MlirAffineExpr lhs,
215  MlirAffineExpr rhs);
216 
217 //===----------------------------------------------------------------------===//
218 // Affine Binary Operation Expression.
219 //===----------------------------------------------------------------------===//
220 
221 /// Checks whether the given affine expression is binary.
222 MLIR_CAPI_EXPORTED bool mlirAffineExprIsABinary(MlirAffineExpr affineExpr);
223 
224 /// Returns the left hand side affine expression of the given affine binary
225 /// operation expression.
226 MLIR_CAPI_EXPORTED MlirAffineExpr
227 mlirAffineBinaryOpExprGetLHS(MlirAffineExpr affineExpr);
228 
229 /// Returns the right hand side affine expression of the given affine binary
230 /// operation expression.
231 MLIR_CAPI_EXPORTED MlirAffineExpr
232 mlirAffineBinaryOpExprGetRHS(MlirAffineExpr affineExpr);
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 
238 #endif // MLIR_C_AFFINEEXPR_H
MLIR_CAPI_EXPORTED bool mlirAffineExprIsMultipleOf(MlirAffineExpr affineExpr, int64_t factor)
Checks whether the given affine expression is a multiple of 'factor'.
Definition: AffineExpr.cpp:50
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineExprShiftDims(MlirAffineExpr affineExpr, uint32_t numDims, uint32_t shift, uint32_t offset)
Replace dims[offset ...
Definition: AffineExpr.cpp:64
MLIR_CAPI_EXPORTED bool mlirAffineExprIsPureAffine(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a pure affine expression, i.e.
Definition: AffineExpr.cpp:42
MLIR_CAPI_EXPORTED bool mlirAffineExprIsSymbolicOrConstant(MlirAffineExpr affineExpr)
Checks whether the given affine expression is made out of only symbols and constants.
Definition: AffineExpr.cpp:38
MLIR_CAPI_EXPORTED MlirAffineExpr mlirSimplifyAffineExpr(MlirAffineExpr expr, uint32_t numDims, uint32_t numSymbols)
Simplify an affine expression by flattening and some amount of simple analysis.
Definition: AffineExpr.cpp:76
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAConstant(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a constant expression.
Definition: AffineExpr.cpp:117
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineBinaryOpExprGetLHS(MlirAffineExpr affineExpr)
Returns the left hand side affine expression of the given affine binary operation expression.
Definition: AffineExpr.cpp:204
MLIR_CAPI_EXPORTED bool mlirAffineExprIsFunctionOfDim(MlirAffineExpr affineExpr, intptr_t position)
Checks whether the given affine expression involves AffineDimExpr 'position'.
Definition: AffineExpr.cpp:54
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineMulExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine mul expression with 'lhs' and 'rhs'.
Definition: AffineExpr.cpp:150
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineConstantExprGet(MlirContext ctx, int64_t constant)
Creates an affine constant expression with 'constant' in the context.
Definition: AffineExpr.cpp:121
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineBinaryOpExprGetRHS(MlirAffineExpr affineExpr)
Returns the right hand side affine expression of the given affine binary operation expression.
Definition: AffineExpr.cpp:208
MLIR_CAPI_EXPORTED void mlirAffineExprPrint(MlirAffineExpr affineExpr, MlirStringCallback callback, void *userData)
Prints an affine expression by sending chunks of the string representation and forwarding userData to...
Definition: AffineExpr.cpp:28
#define DEFINE_C_API_STRUCT(name, storage)
Definition: AffineExpr.h:32
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineAddExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine add expression with 'lhs' and 'rhs'.
Definition: AffineExpr.cpp:137
MLIR_CAPI_EXPORTED intptr_t mlirAffineDimExprGetPosition(MlirAffineExpr affineExpr)
Returns the position of the given affine dimension expression.
Definition: AffineExpr.cpp:93
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAAdd(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an add expression.
Definition: AffineExpr.cpp:133
MLIR_CAPI_EXPORTED bool mlirAffineExprIsABinary(MlirAffineExpr affineExpr)
Checks whether the given affine expression is binary.
Definition: AffineExpr.cpp:200
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMul(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an mul expression.
Definition: AffineExpr.cpp:146
MLIR_CAPI_EXPORTED int64_t mlirAffineConstantExprGetValue(MlirAffineExpr affineExpr)
Returns the value of the given affine constant expression.
Definition: AffineExpr.cpp:125
MLIR_CAPI_EXPORTED MlirContext mlirAffineExprGetContext(MlirAffineExpr affineExpr)
Gets the context that owns the affine expression.
Definition: AffineExpr.cpp:20
MLIR_CAPI_EXPORTED bool mlirAffineExprIsASymbol(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a symbol expression.
Definition: AffineExpr.cpp:101
MLIR_CAPI_EXPORTED bool mlirAffineExprIsACeilDiv(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an ceildiv expression.
Definition: AffineExpr.cpp:186
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineFloorDivExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine floordiv expression with 'lhs' and 'rhs'.
Definition: AffineExpr.cpp:176
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAFloorDiv(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an floordiv expression.
Definition: AffineExpr.cpp:172
MLIR_CAPI_EXPORTED bool mlirAffineExprEqual(MlirAffineExpr lhs, MlirAffineExpr rhs)
Returns true if the two affine expressions are equal.
Definition: AffineExpr.cpp:24
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineDimExprGet(MlirContext ctx, intptr_t position)
Creates an affine dimension expression with 'position' in the context.
Definition: AffineExpr.cpp:89
MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMod(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an mod expression.
Definition: AffineExpr.cpp:159
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineModExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine mod expression with 'lhs' and 'rhs'.
Definition: AffineExpr.cpp:163
MLIR_CAPI_EXPORTED void mlirAffineExprDump(MlirAffineExpr affineExpr)
Prints the affine expression to the standard error stream.
Definition: AffineExpr.cpp:34
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineExprCompose(MlirAffineExpr affineExpr, struct MlirAffineMap affineMap)
Composes the given map with the given expression.
Definition: AffineExpr.cpp:59
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineSymbolExprGet(MlirContext ctx, intptr_t position)
Creates an affine symbol expression with 'position' in the context.
Definition: AffineExpr.cpp:105
static bool mlirAffineExprIsNull(MlirAffineExpr affineExpr)
Returns true if the given affine expression is a null expression.
Definition: AffineExpr.h:54
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineCeilDivExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine ceildiv expression with 'lhs' and 'rhs'.
Definition: AffineExpr.cpp:190
MLIR_CAPI_EXPORTED intptr_t mlirAffineSymbolExprGetPosition(MlirAffineExpr affineExpr)
Returns the position of the given affine symbol expression.
Definition: AffineExpr.cpp:109
MLIR_CAPI_EXPORTED int64_t mlirAffineExprGetLargestKnownDivisor(MlirAffineExpr affineExpr)
Returns the greatest known integral divisor of this affine expression.
Definition: AffineExpr.cpp:46
MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineExprShiftSymbols(MlirAffineExpr affineExpr, uint32_t numSymbols, uint32_t shift, uint32_t offset)
Replace symbols[offset ...
Definition: AffineExpr.cpp:70
MLIR_CAPI_EXPORTED bool mlirAffineExprIsADim(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a dimension expression.
Definition: AffineExpr.cpp:85
#define MLIR_CAPI_EXPORTED
Definition: Support.h:46
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition: Support.h:105