[SampleProfileLoader] Fix integer overflow in generateMDProfMetadata (#90217)
[llvm-project.git] / mlir / include / mlir-c / AffineExpr.h
blob14e951ddee9ad478227de65f6917f3a5b44b075d
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 //===----------------------------------------------------------------------===//
10 #ifndef MLIR_C_AFFINEEXPR_H
11 #define MLIR_C_AFFINEEXPR_H
13 #include "mlir-c/IR.h"
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
19 //===----------------------------------------------------------------------===//
20 // Opaque type declarations.
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.
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 //===----------------------------------------------------------------------===//
32 #define DEFINE_C_API_STRUCT(name, storage) \
33 struct name { \
34 storage *ptr; \
35 }; \
36 typedef struct name name
38 DEFINE_C_API_STRUCT(MlirAffineExpr, const void);
40 #undef DEFINE_C_API_STRUCT
42 struct MlirAffineMap;
44 /// Gets the context that owns the affine expression.
45 MLIR_CAPI_EXPORTED MlirContext
46 mlirAffineExprGetContext(MlirAffineExpr affineExpr);
48 /// Returns `true` if the two affine expressions are equal.
49 MLIR_CAPI_EXPORTED bool mlirAffineExprEqual(MlirAffineExpr lhs,
50 MlirAffineExpr rhs);
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;
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);
65 /// Prints the affine expression to the standard error stream.
66 MLIR_CAPI_EXPORTED void mlirAffineExprDump(MlirAffineExpr affineExpr);
68 /// Checks whether the given affine expression is made out of only symbols and
69 /// constants.
70 MLIR_CAPI_EXPORTED bool
71 mlirAffineExprIsSymbolicOrConstant(MlirAffineExpr affineExpr);
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);
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);
82 /// Checks whether the given affine expression is a multiple of 'factor'.
83 MLIR_CAPI_EXPORTED bool mlirAffineExprIsMultipleOf(MlirAffineExpr affineExpr,
84 int64_t factor);
86 /// Checks whether the given affine expression involves AffineDimExpr
87 /// 'position'.
88 MLIR_CAPI_EXPORTED bool mlirAffineExprIsFunctionOfDim(MlirAffineExpr affineExpr,
89 intptr_t position);
91 /// Composes the given map with the given expression.
92 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineExprCompose(
93 MlirAffineExpr affineExpr, struct MlirAffineMap affineMap);
95 //===----------------------------------------------------------------------===//
96 // Affine Dimension Expression.
97 //===----------------------------------------------------------------------===//
99 /// Checks whether the given affine expression is a dimension expression.
100 MLIR_CAPI_EXPORTED bool mlirAffineExprIsADim(MlirAffineExpr affineExpr);
102 /// Creates an affine dimension expression with 'position' in the context.
103 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineDimExprGet(MlirContext ctx,
104 intptr_t position);
106 /// Returns the position of the given affine dimension expression.
107 MLIR_CAPI_EXPORTED intptr_t
108 mlirAffineDimExprGetPosition(MlirAffineExpr affineExpr);
110 //===----------------------------------------------------------------------===//
111 // Affine Symbol Expression.
112 //===----------------------------------------------------------------------===//
114 /// Checks whether the given affine expression is a symbol expression.
115 MLIR_CAPI_EXPORTED bool mlirAffineExprIsASymbol(MlirAffineExpr affineExpr);
117 /// Creates an affine symbol expression with 'position' in the context.
118 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineSymbolExprGet(MlirContext ctx,
119 intptr_t position);
121 /// Returns the position of the given affine symbol expression.
122 MLIR_CAPI_EXPORTED intptr_t
123 mlirAffineSymbolExprGetPosition(MlirAffineExpr affineExpr);
125 //===----------------------------------------------------------------------===//
126 // Affine Constant Expression.
127 //===----------------------------------------------------------------------===//
129 /// Checks whether the given affine expression is a constant expression.
130 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAConstant(MlirAffineExpr affineExpr);
132 /// Creates an affine constant expression with 'constant' in the context.
133 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineConstantExprGet(MlirContext ctx,
134 int64_t constant);
136 /// Returns the value of the given affine constant expression.
137 MLIR_CAPI_EXPORTED int64_t
138 mlirAffineConstantExprGetValue(MlirAffineExpr affineExpr);
140 //===----------------------------------------------------------------------===//
141 // Affine Add Expression.
142 //===----------------------------------------------------------------------===//
144 /// Checks whether the given affine expression is an add expression.
145 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAAdd(MlirAffineExpr affineExpr);
147 /// Creates an affine add expression with 'lhs' and 'rhs'.
148 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineAddExprGet(MlirAffineExpr lhs,
149 MlirAffineExpr rhs);
151 //===----------------------------------------------------------------------===//
152 // Affine Mul Expression.
153 //===----------------------------------------------------------------------===//
155 /// Checks whether the given affine expression is an mul expression.
156 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMul(MlirAffineExpr affineExpr);
158 /// Creates an affine mul expression with 'lhs' and 'rhs'.
159 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineMulExprGet(MlirAffineExpr lhs,
160 MlirAffineExpr rhs);
162 //===----------------------------------------------------------------------===//
163 // Affine Mod Expression.
164 //===----------------------------------------------------------------------===//
166 /// Checks whether the given affine expression is an mod expression.
167 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMod(MlirAffineExpr affineExpr);
169 /// Creates an affine mod expression with 'lhs' and 'rhs'.
170 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineModExprGet(MlirAffineExpr lhs,
171 MlirAffineExpr rhs);
173 //===----------------------------------------------------------------------===//
174 // Affine FloorDiv Expression.
175 //===----------------------------------------------------------------------===//
177 /// Checks whether the given affine expression is an floordiv expression.
178 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAFloorDiv(MlirAffineExpr affineExpr);
180 /// Creates an affine floordiv expression with 'lhs' and 'rhs'.
181 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineFloorDivExprGet(MlirAffineExpr lhs,
182 MlirAffineExpr rhs);
184 //===----------------------------------------------------------------------===//
185 // Affine CeilDiv Expression.
186 //===----------------------------------------------------------------------===//
188 /// Checks whether the given affine expression is an ceildiv expression.
189 MLIR_CAPI_EXPORTED bool mlirAffineExprIsACeilDiv(MlirAffineExpr affineExpr);
191 /// Creates an affine ceildiv expression with 'lhs' and 'rhs'.
192 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineCeilDivExprGet(MlirAffineExpr lhs,
193 MlirAffineExpr rhs);
195 //===----------------------------------------------------------------------===//
196 // Affine Binary Operation Expression.
197 //===----------------------------------------------------------------------===//
199 /// Checks whether the given affine expression is binary.
200 MLIR_CAPI_EXPORTED bool mlirAffineExprIsABinary(MlirAffineExpr affineExpr);
202 /// Returns the left hand side affine expression of the given affine binary
203 /// operation expression.
204 MLIR_CAPI_EXPORTED MlirAffineExpr
205 mlirAffineBinaryOpExprGetLHS(MlirAffineExpr affineExpr);
207 /// Returns the right hand side affine expression of the given affine binary
208 /// operation expression.
209 MLIR_CAPI_EXPORTED MlirAffineExpr
210 mlirAffineBinaryOpExprGetRHS(MlirAffineExpr affineExpr);
212 #ifdef __cplusplus
214 #endif
216 #endif // MLIR_C_AFFINEEXPR_H