Revert "[lldb][test] Remove compiler version check and use regex" (#124101)
[llvm-project.git] / mlir / include / mlir-c / AffineMap.h
blobc24c1ced3cbb65d74aec47eea7ccc2593b317320
1 //===-- mlir-c/AffineMap.h - C API for MLIR Affine maps -----------*- 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_AFFINEMAP_H
11 #define MLIR_C_AFFINEMAP_H
13 #include "mlir-c/AffineExpr.h"
14 #include "mlir-c/IR.h"
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
20 //===----------------------------------------------------------------------===//
21 // Opaque type declarations.
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.
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 //===----------------------------------------------------------------------===//
33 #define DEFINE_C_API_STRUCT(name, storage) \
34 struct name { \
35 storage *ptr; \
36 }; \
37 typedef struct name name
39 DEFINE_C_API_STRUCT(MlirAffineMap, const void);
41 #undef DEFINE_C_API_STRUCT
43 /// Gets the context that the given affine map was created with
44 MLIR_CAPI_EXPORTED MlirContext mlirAffineMapGetContext(MlirAffineMap affineMap);
46 /// Checks whether an affine map is null.
47 static inline bool mlirAffineMapIsNull(MlirAffineMap affineMap) {
48 return !affineMap.ptr;
51 /// Checks if two affine maps are equal.
52 MLIR_CAPI_EXPORTED bool mlirAffineMapEqual(MlirAffineMap a1, MlirAffineMap a2);
54 /// Prints an affine map by sending chunks of the string representation and
55 /// forwarding `userData to `callback`. Note that the callback may be called
56 /// several times with consecutive chunks of the string.
57 MLIR_CAPI_EXPORTED void mlirAffineMapPrint(MlirAffineMap affineMap,
58 MlirStringCallback callback,
59 void *userData);
61 /// Prints the affine map to the standard error stream.
62 MLIR_CAPI_EXPORTED void mlirAffineMapDump(MlirAffineMap affineMap);
64 /// Creates a zero result affine map with no dimensions or symbols in the
65 /// context. The affine map is owned by the context.
66 MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapEmptyGet(MlirContext ctx);
68 /// Creates a zero result affine map of the given dimensions and symbols in the
69 /// context. The affine map is owned by the context.
70 MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapZeroResultGet(
71 MlirContext ctx, intptr_t dimCount, intptr_t symbolCount);
73 /// Creates an affine map with results defined by the given list of affine
74 /// expressions. The map resulting map also has the requested number of input
75 /// dimensions and symbols, regardless of them being used in the results.
77 MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapGet(MlirContext ctx,
78 intptr_t dimCount,
79 intptr_t symbolCount,
80 intptr_t nAffineExprs,
81 MlirAffineExpr *affineExprs);
83 /// Creates a single constant result affine map in the context. The affine map
84 /// is owned by the context.
85 MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapConstantGet(MlirContext ctx,
86 int64_t val);
88 /// Creates an affine map with 'numDims' identity in the context. The affine map
89 /// is owned by the context.
90 MLIR_CAPI_EXPORTED MlirAffineMap
91 mlirAffineMapMultiDimIdentityGet(MlirContext ctx, intptr_t numDims);
93 /// Creates an identity affine map on the most minor dimensions in the context.
94 /// The affine map is owned by the context. The function asserts that the number
95 /// of dimensions is greater or equal to the number of results.
96 MLIR_CAPI_EXPORTED MlirAffineMap
97 mlirAffineMapMinorIdentityGet(MlirContext ctx, intptr_t dims, intptr_t results);
99 /// Creates an affine map with a permutation expression and its size in the
100 /// context. The permutation expression is a non-empty vector of integers.
101 /// The elements of the permutation vector must be continuous from 0 and cannot
102 /// be repeated (i.e. `[1,2,0]` is a valid permutation. `[2,0]` or `[1,1,2]` is
103 /// an invalid permutation.) The affine map is owned by the context.
104 MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapPermutationGet(
105 MlirContext ctx, intptr_t size, unsigned *permutation);
107 /// Checks whether the given affine map is an identity affine map. The function
108 /// asserts that the number of dimensions is greater or equal to the number of
109 /// results.
110 MLIR_CAPI_EXPORTED bool mlirAffineMapIsIdentity(MlirAffineMap affineMap);
112 /// Checks whether the given affine map is a minor identity affine map.
113 MLIR_CAPI_EXPORTED bool mlirAffineMapIsMinorIdentity(MlirAffineMap affineMap);
115 /// Checks whether the given affine map is an empty affine map.
116 MLIR_CAPI_EXPORTED bool mlirAffineMapIsEmpty(MlirAffineMap affineMap);
118 /// Checks whether the given affine map is a single result constant affine
119 /// map.
120 MLIR_CAPI_EXPORTED bool mlirAffineMapIsSingleConstant(MlirAffineMap affineMap);
122 /// Returns the constant result of the given affine map. The function asserts
123 /// that the map has a single constant result.
124 MLIR_CAPI_EXPORTED int64_t
125 mlirAffineMapGetSingleConstantResult(MlirAffineMap affineMap);
127 /// Returns the number of dimensions of the given affine map.
128 MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumDims(MlirAffineMap affineMap);
130 /// Returns the number of symbols of the given affine map.
131 MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumSymbols(MlirAffineMap affineMap);
133 /// Returns the number of results of the given affine map.
134 MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumResults(MlirAffineMap affineMap);
136 /// Returns the result at the given position.
137 MLIR_CAPI_EXPORTED MlirAffineExpr
138 mlirAffineMapGetResult(MlirAffineMap affineMap, intptr_t pos);
140 /// Returns the number of inputs (dimensions + symbols) of the given affine
141 /// map.
142 MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumInputs(MlirAffineMap affineMap);
144 /// Checks whether the given affine map represents a subset of a symbol-less
145 /// permutation map.
146 MLIR_CAPI_EXPORTED bool
147 mlirAffineMapIsProjectedPermutation(MlirAffineMap affineMap);
149 /// Checks whether the given affine map represents a symbol-less permutation
150 /// map.
151 MLIR_CAPI_EXPORTED bool mlirAffineMapIsPermutation(MlirAffineMap affineMap);
153 /// Returns the affine map consisting of the `resultPos` subset.
154 MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapGetSubMap(MlirAffineMap affineMap,
155 intptr_t size,
156 intptr_t *resultPos);
158 /// Returns the affine map consisting of the most major `numResults` results.
159 /// Returns the null AffineMap if the `numResults` is equal to zero.
160 /// Returns the `affineMap` if `numResults` is greater or equals to number of
161 /// results of the given affine map.
162 MLIR_CAPI_EXPORTED MlirAffineMap
163 mlirAffineMapGetMajorSubMap(MlirAffineMap affineMap, intptr_t numResults);
165 /// Returns the affine map consisting of the most minor `numResults` results.
166 /// Returns the null AffineMap if the `numResults` is equal to zero.
167 /// Returns the `affineMap` if `numResults` is greater or equals to number of
168 /// results of the given affine map.
169 MLIR_CAPI_EXPORTED MlirAffineMap
170 mlirAffineMapGetMinorSubMap(MlirAffineMap affineMap, intptr_t numResults);
172 /// Apply AffineExpr::replace(`map`) to each of the results and return a new
173 /// new AffineMap with the new results and the specified number of dims and
174 /// symbols.
175 MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapReplace(
176 MlirAffineMap affineMap, MlirAffineExpr expression,
177 MlirAffineExpr replacement, intptr_t numResultDims, intptr_t numResultSyms);
179 /// Returns the simplified affine map resulting from dropping the symbols that
180 /// do not appear in any of the individual maps in `affineMaps`.
181 /// Asserts that all maps in `affineMaps` are normalized to the same number of
182 /// dims and symbols.
183 /// Takes a callback `populateResult` to fill the `res` container with value
184 /// `m` at entry `idx`. This allows returning without worrying about ownership
185 /// considerations.
186 MLIR_CAPI_EXPORTED void mlirAffineMapCompressUnusedSymbols(
187 MlirAffineMap *affineMaps, intptr_t size, void *result,
188 void (*populateResult)(void *res, intptr_t idx, MlirAffineMap m));
190 #ifdef __cplusplus
192 #endif
194 #endif // MLIR_C_AFFINEMAP_H