MLIR 22.0.0git
AffineMap.h
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
9
10#ifndef MLIR_C_AFFINEMAP_H
11#define MLIR_C_AFFINEMAP_H
12
13#include "mlir-c/AffineExpr.h"
14#include "mlir-c/IR.h"
15
16#ifdef __cplusplus
17extern "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#define DEFINE_C_API_STRUCT(name, storage) \
34 struct name { \
35 storage *ptr; \
36 }; \
37 typedef struct name name
38
39DEFINE_C_API_STRUCT(MlirAffineMap, const void);
40
41#undef DEFINE_C_API_STRUCT
42
43/// Gets the context that the given affine map was created with
44MLIR_CAPI_EXPORTED MlirContext mlirAffineMapGetContext(MlirAffineMap affineMap);
45
46/// Checks whether an affine map is null.
47static inline bool mlirAffineMapIsNull(MlirAffineMap affineMap) {
48 return !affineMap.ptr;
49}
50
51/// Checks if two affine maps are equal.
52MLIR_CAPI_EXPORTED bool mlirAffineMapEqual(MlirAffineMap a1, MlirAffineMap a2);
53
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.
57MLIR_CAPI_EXPORTED void mlirAffineMapPrint(MlirAffineMap affineMap,
58 MlirStringCallback callback,
59 void *userData);
60
61/// Prints the affine map to the standard error stream.
62MLIR_CAPI_EXPORTED void mlirAffineMapDump(MlirAffineMap affineMap);
63
64/// Creates a zero result affine map with no dimensions or symbols in the
65/// context. The affine map is owned by the context.
66MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapEmptyGet(MlirContext ctx);
67
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.
71 MlirContext ctx, intptr_t dimCount, intptr_t symbolCount);
72
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.
76
77MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapGet(MlirContext ctx,
78 intptr_t dimCount,
79 intptr_t symbolCount,
80 intptr_t nAffineExprs,
81 MlirAffineExpr *affineExprs);
82
83/// Creates a single constant result affine map in the context. The affine map
84/// is owned by the context.
85MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapConstantGet(MlirContext ctx,
86 int64_t val);
87
88/// Creates an affine map with 'numDims' identity in the context. The affine map
89/// is owned by the context.
90MLIR_CAPI_EXPORTED MlirAffineMap
91mlirAffineMapMultiDimIdentityGet(MlirContext ctx, intptr_t numDims);
92
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.
96MLIR_CAPI_EXPORTED MlirAffineMap
97mlirAffineMapMinorIdentityGet(MlirContext ctx, intptr_t dims, intptr_t results);
98
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.
105 MlirContext ctx, intptr_t size, unsigned *permutation);
106
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.
110MLIR_CAPI_EXPORTED bool mlirAffineMapIsIdentity(MlirAffineMap affineMap);
111
112/// Checks whether the given affine map is a minor identity affine map.
113MLIR_CAPI_EXPORTED bool mlirAffineMapIsMinorIdentity(MlirAffineMap affineMap);
114
115/// Checks whether the given affine map is an empty affine map.
116MLIR_CAPI_EXPORTED bool mlirAffineMapIsEmpty(MlirAffineMap affineMap);
117
118/// Checks whether the given affine map is a single result constant affine
119/// map.
120MLIR_CAPI_EXPORTED bool mlirAffineMapIsSingleConstant(MlirAffineMap affineMap);
121
122/// Returns the constant result of the given affine map. The function asserts
123/// that the map has a single constant result.
125mlirAffineMapGetSingleConstantResult(MlirAffineMap affineMap);
126
127/// Returns the number of dimensions of the given affine map.
128MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumDims(MlirAffineMap affineMap);
129
130/// Returns the number of symbols of the given affine map.
131MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumSymbols(MlirAffineMap affineMap);
132
133/// Returns the number of results of the given affine map.
134MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumResults(MlirAffineMap affineMap);
135
136/// Returns the result at the given position.
137MLIR_CAPI_EXPORTED MlirAffineExpr
138mlirAffineMapGetResult(MlirAffineMap affineMap, intptr_t pos);
139
140/// Returns the number of inputs (dimensions + symbols) of the given affine
141/// map.
142MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumInputs(MlirAffineMap affineMap);
143
144/// Checks whether the given affine map represents a subset of a symbol-less
145/// permutation map.
147mlirAffineMapIsProjectedPermutation(MlirAffineMap affineMap);
148
149/// Checks whether the given affine map represents a symbol-less permutation
150/// map.
151MLIR_CAPI_EXPORTED bool mlirAffineMapIsPermutation(MlirAffineMap affineMap);
152
153/// Returns the affine map consisting of the `resultPos` subset.
154MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapGetSubMap(MlirAffineMap affineMap,
155 intptr_t size,
156 intptr_t *resultPos);
157
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.
162MLIR_CAPI_EXPORTED MlirAffineMap
163mlirAffineMapGetMajorSubMap(MlirAffineMap affineMap, intptr_t numResults);
164
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.
169MLIR_CAPI_EXPORTED MlirAffineMap
170mlirAffineMapGetMinorSubMap(MlirAffineMap affineMap, intptr_t numResults);
171
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.
176 MlirAffineMap affineMap, MlirAffineExpr expression,
177 MlirAffineExpr replacement, intptr_t numResultDims, intptr_t numResultSyms);
178
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.
187 MlirAffineMap *affineMaps, intptr_t size, void *result,
188 void (*populateResult)(void *res, intptr_t idx, MlirAffineMap m));
189
190#ifdef __cplusplus
191}
192#endif
193
194#endif // MLIR_C_AFFINEMAP_H
MlirAffineMap mlirAffineMapMultiDimIdentityGet(MlirContext ctx, intptr_t numDims)
Definition AffineMap.cpp:58
MlirAffineMap mlirAffineMapPermutationGet(MlirContext ctx, intptr_t size, unsigned *permutation)
Definition AffineMap.cpp:68
void mlirAffineMapDump(MlirAffineMap affineMap)
Definition AffineMap.cpp:35
bool mlirAffineMapIsProjectedPermutation(MlirAffineMap affineMap)
bool mlirAffineMapIsEmpty(MlirAffineMap affineMap)
Definition AffineMap.cpp:82
MlirAffineMap mlirAffineMapConstantGet(MlirContext ctx, int64_t val)
Definition AffineMap.cpp:54
MlirAffineExpr mlirAffineMapGetResult(MlirAffineMap affineMap, intptr_t pos)
intptr_t mlirAffineMapGetNumInputs(MlirAffineMap affineMap)
bool mlirAffineMapIsMinorIdentity(MlirAffineMap affineMap)
Definition AffineMap.cpp:78
MlirAffineMap mlirAffineMapZeroResultGet(MlirContext ctx, intptr_t dimCount, intptr_t symbolCount)
Definition AffineMap.cpp:41
int64_t mlirAffineMapGetSingleConstantResult(MlirAffineMap affineMap)
Definition AffineMap.cpp:90
MlirAffineMap mlirAffineMapGet(MlirContext ctx, intptr_t dimCount, intptr_t symbolCount, intptr_t nAffineExprs, MlirAffineExpr *affineExprs)
Definition AffineMap.cpp:46
MlirAffineMap mlirAffineMapGetSubMap(MlirAffineMap affineMap, intptr_t size, intptr_t *resultPos)
void mlirAffineMapPrint(MlirAffineMap affineMap, MlirStringCallback callback, void *userData)
Definition AffineMap.cpp:29
MlirAffineMap mlirAffineMapEmptyGet(MlirContext ctx)
Definition AffineMap.cpp:37
MlirAffineMap mlirAffineMapGetMajorSubMap(MlirAffineMap affineMap, intptr_t numResults)
bool mlirAffineMapIsSingleConstant(MlirAffineMap affineMap)
Definition AffineMap.cpp:86
MlirAffineMap mlirAffineMapMinorIdentityGet(MlirContext ctx, intptr_t dims, intptr_t results)
Definition AffineMap.cpp:63
bool mlirAffineMapIsPermutation(MlirAffineMap affineMap)
MlirAffineMap mlirAffineMapGetMinorSubMap(MlirAffineMap affineMap, intptr_t numResults)
intptr_t mlirAffineMapGetNumDims(MlirAffineMap affineMap)
Definition AffineMap.cpp:94
intptr_t mlirAffineMapGetNumResults(MlirAffineMap affineMap)
MlirAffineMap mlirAffineMapReplace(MlirAffineMap affineMap, MlirAffineExpr expression, MlirAffineExpr replacement, intptr_t numResultDims, intptr_t numResultSyms)
intptr_t mlirAffineMapGetNumSymbols(MlirAffineMap affineMap)
Definition AffineMap.cpp:98
bool mlirAffineMapIsIdentity(MlirAffineMap affineMap)
Definition AffineMap.cpp:74
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be the output argument nBegin is set to its * replacement(set to `begin` if no invalidation happens). Since outgoing *copies could have been inserted at `end`
MLIR_CAPI_EXPORTED bool mlirAffineMapEqual(MlirAffineMap a1, MlirAffineMap a2)
Checks if two affine maps are equal.
Definition AffineMap.cpp:25
MLIR_CAPI_EXPORTED MlirContext mlirAffineMapGetContext(MlirAffineMap affineMap)
Gets the context that the given affine map was created with.
Definition AffineMap.cpp:21
#define DEFINE_C_API_STRUCT(name, storage)
Definition AffineMap.h:33
MLIR_CAPI_EXPORTED void mlirAffineMapCompressUnusedSymbols(MlirAffineMap *affineMaps, intptr_t size, void *result, void(*populateResult)(void *res, intptr_t idx, MlirAffineMap m))
Prints an affine map by sending chunks of the string representation and forwarding userData to callba...
static bool mlirAffineMapIsNull(MlirAffineMap affineMap)
Checks whether an affine map is null.
Definition AffineMap.h:47
#define MLIR_CAPI_EXPORTED
Definition Support.h:46
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition Support.h:105