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/AffineMap.h" 14 #include "mlir-c/IR.h" 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 //===----------------------------------------------------------------------===// 21 /** Opaque type declarations. 22 * 23 * Types are exposed to C bindings as structs containing opaque pointers. They 24 * are not supposed to be inspected from C. This allows the underlying 25 * representation to change without affecting the API users. The use of structs 26 * instead of typedefs enables some type safety as structs are not implicitly 27 * convertible to each other. 28 * 29 * Instances of these types may or may not own the underlying object. The 30 * ownership semantics is defined by how an instance of the type was obtained. 31 */ 32 //===----------------------------------------------------------------------===// 33 34 #define DEFINE_C_API_STRUCT(name, storage) \ 35 struct name { \ 36 storage *ptr; \ 37 }; \ 38 typedef struct name name 39 40 DEFINE_C_API_STRUCT(MlirAffineExpr, const void); 41 42 #undef DEFINE_C_API_STRUCT 43 44 /// Gets the context that owns the affine expression. 45 MLIR_CAPI_EXPORTED MlirContext 46 mlirAffineExprGetContext(MlirAffineExpr affineExpr); 47 48 /** Prints an affine expression by sending chunks of the string representation 49 * and forwarding `userData to `callback`. Note that the callback may be called 50 * several times with consecutive chunks of the string. */ 51 MLIR_CAPI_EXPORTED void mlirAffineExprPrint(MlirAffineExpr affineExpr, 52 MlirStringCallback callback, 53 void *userData); 54 55 /// Prints the affine expression to the standard error stream. 56 MLIR_CAPI_EXPORTED void mlirAffineExprDump(MlirAffineExpr affineExpr); 57 58 /** Checks whether the given affine expression is made out of only symbols and 59 * constants. */ 60 MLIR_CAPI_EXPORTED bool 61 mlirAffineExprIsSymbolicOrConstant(MlirAffineExpr affineExpr); 62 63 /** Checks whether the given affine expression is a pure affine expression, i.e. 64 * mul, floordiv, ceildic, and mod is only allowed w.r.t constants. */ 65 MLIR_CAPI_EXPORTED bool mlirAffineExprIsPureAffine(MlirAffineExpr affineExpr); 66 67 /** Returns the greatest known integral divisor of this affine expression. The 68 * result is always positive. */ 69 MLIR_CAPI_EXPORTED int64_t 70 mlirAffineExprGetLargestKnownDivisor(MlirAffineExpr affineExpr); 71 72 /// Checks whether the given affine expression is a multiple of 'factor'. 73 MLIR_CAPI_EXPORTED bool mlirAffineExprIsMultipleOf(MlirAffineExpr affineExpr, 74 int64_t factor); 75 76 /** Checks whether the given affine expression involves AffineDimExpr 77 * 'position'. */ 78 MLIR_CAPI_EXPORTED bool mlirAffineExprIsFunctionOfDim(MlirAffineExpr affineExpr, 79 intptr_t position); 80 81 //===----------------------------------------------------------------------===// 82 // Affine Dimension Expression. 83 //===----------------------------------------------------------------------===// 84 85 /// Creates an affine dimension expression with 'position' in the context. 86 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineDimExprGet(MlirContext ctx, 87 intptr_t position); 88 89 /// Returns the position of the given affine dimension expression. 90 MLIR_CAPI_EXPORTED intptr_t 91 mlirAffineDimExprGetPosition(MlirAffineExpr affineExpr); 92 93 //===----------------------------------------------------------------------===// 94 // Affine Symbol Expression. 95 //===----------------------------------------------------------------------===// 96 97 /// Creates an affine symbol expression with 'position' in the context. 98 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineSymbolExprGet(MlirContext ctx, 99 intptr_t position); 100 101 /// Returns the position of the given affine symbol expression. 102 MLIR_CAPI_EXPORTED intptr_t 103 mlirAffineSymbolExprGetPosition(MlirAffineExpr affineExpr); 104 105 //===----------------------------------------------------------------------===// 106 // Affine Constant Expression. 107 //===----------------------------------------------------------------------===// 108 109 /// Creates an affine constant expression with 'constant' in the context. 110 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineConstantExprGet(MlirContext ctx, 111 int64_t constant); 112 113 /// Returns the value of the given affine constant expression. 114 MLIR_CAPI_EXPORTED int64_t 115 mlirAffineConstantExprGetValue(MlirAffineExpr affineExpr); 116 117 //===----------------------------------------------------------------------===// 118 // Affine Add Expression. 119 //===----------------------------------------------------------------------===// 120 121 /// Checks whether the given affine expression is an add expression. 122 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAAdd(MlirAffineExpr affineExpr); 123 124 /// Creates an affine add expression with 'lhs' and 'rhs'. 125 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineAddExprGet(MlirAffineExpr lhs, 126 MlirAffineExpr rhs); 127 128 //===----------------------------------------------------------------------===// 129 // Affine Mul Expression. 130 //===----------------------------------------------------------------------===// 131 132 /// Checks whether the given affine expression is an mul expression. 133 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMul(MlirAffineExpr affineExpr); 134 135 /// Creates an affine mul expression with 'lhs' and 'rhs'. 136 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineMulExprGet(MlirAffineExpr lhs, 137 MlirAffineExpr rhs); 138 139 //===----------------------------------------------------------------------===// 140 // Affine Mod Expression. 141 //===----------------------------------------------------------------------===// 142 143 /// Checks whether the given affine expression is an mod expression. 144 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAMod(MlirAffineExpr affineExpr); 145 146 /// Creates an affine mod expression with 'lhs' and 'rhs'. 147 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineModExprGet(MlirAffineExpr lhs, 148 MlirAffineExpr rhs); 149 150 //===----------------------------------------------------------------------===// 151 // Affine FloorDiv Expression. 152 //===----------------------------------------------------------------------===// 153 154 /// Checks whether the given affine expression is an floordiv expression. 155 MLIR_CAPI_EXPORTED bool mlirAffineExprIsAFloorDiv(MlirAffineExpr affineExpr); 156 157 /// Creates an affine floordiv expression with 'lhs' and 'rhs'. 158 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineFloorDivExprGet(MlirAffineExpr lhs, 159 MlirAffineExpr rhs); 160 161 //===----------------------------------------------------------------------===// 162 // Affine CeilDiv Expression. 163 //===----------------------------------------------------------------------===// 164 165 /// Checks whether the given affine expression is an ceildiv expression. 166 MLIR_CAPI_EXPORTED bool mlirAffineExprIsACeilDiv(MlirAffineExpr affineExpr); 167 168 /// Creates an affine ceildiv expression with 'lhs' and 'rhs'. 169 MLIR_CAPI_EXPORTED MlirAffineExpr mlirAffineCeilDivExprGet(MlirAffineExpr lhs, 170 MlirAffineExpr rhs); 171 172 //===----------------------------------------------------------------------===// 173 // Affine Binary Operation Expression. 174 //===----------------------------------------------------------------------===// 175 176 /** Returns the left hand side affine expression of the given affine binary 177 * operation expression. */ 178 MLIR_CAPI_EXPORTED MlirAffineExpr 179 mlirAffineBinaryOpExprGetLHS(MlirAffineExpr affineExpr); 180 181 /** Returns the right hand side affine expression of the given affine binary 182 * operation expression. */ 183 MLIR_CAPI_EXPORTED MlirAffineExpr 184 mlirAffineBinaryOpExprGetRHS(MlirAffineExpr affineExpr); 185 186 #ifdef __cplusplus 187 } 188 #endif 189 190 #endif // MLIR_C_AFFINEEXPR_H 191