File: AffineMap.h

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (194 lines) | stat: -rw-r--r-- 9,016 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//===-- mlir-c/AffineMap.h - C API for MLIR Affine maps -----------*- C -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
// Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_C_AFFINEMAP_H
#define MLIR_C_AFFINEMAP_H

#include "mlir-c/AffineExpr.h"
#include "mlir-c/IR.h"

#ifdef __cplusplus
extern "C" {
#endif

//===----------------------------------------------------------------------===//
// Opaque type declarations.
//
// Types are exposed to C bindings as structs containing opaque pointers. They
// are not supposed to be inspected from C. This allows the underlying
// representation to change without affecting the API users. The use of structs
// instead of typedefs enables some type safety as structs are not implicitly
// convertible to each other.
//
// Instances of these types may or may not own the underlying object. The
// ownership semantics is defined by how an instance of the type was obtained.
//===----------------------------------------------------------------------===//

#define DEFINE_C_API_STRUCT(name, storage)                                     \
  struct name {                                                                \
    storage *ptr;                                                              \
  };                                                                           \
  typedef struct name name

DEFINE_C_API_STRUCT(MlirAffineMap, const void);

#undef DEFINE_C_API_STRUCT

/// Gets the context that the given affine map was created with
MLIR_CAPI_EXPORTED MlirContext mlirAffineMapGetContext(MlirAffineMap affineMap);

/// Checks whether an affine map is null.
static inline bool mlirAffineMapIsNull(MlirAffineMap affineMap) {
  return !affineMap.ptr;
}

/// Checks if two affine maps are equal.
MLIR_CAPI_EXPORTED bool mlirAffineMapEqual(MlirAffineMap a1, MlirAffineMap a2);

/// Prints an affine map by sending chunks of the string representation and
/// forwarding `userData to `callback`. Note that the callback may be called
/// several times with consecutive chunks of the string.
MLIR_CAPI_EXPORTED void mlirAffineMapPrint(MlirAffineMap affineMap,
                                           MlirStringCallback callback,
                                           void *userData);

/// Prints the affine map to the standard error stream.
MLIR_CAPI_EXPORTED void mlirAffineMapDump(MlirAffineMap affineMap);

/// Creates a zero result affine map with no dimensions or symbols in the
/// context. The affine map is owned by the context.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapEmptyGet(MlirContext ctx);

/// Creates a zero result affine map of the given dimensions and symbols in the
/// context. The affine map is owned by the context.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapZeroResultGet(
    MlirContext ctx, intptr_t dimCount, intptr_t symbolCount);

/// Creates an affine map with results defined by the given list of affine
/// expressions. The map resulting map also has the requested number of input
/// dimensions and symbols, regardless of them being used in the results.

MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapGet(MlirContext ctx,
                                                  intptr_t dimCount,
                                                  intptr_t symbolCount,
                                                  intptr_t nAffineExprs,
                                                  MlirAffineExpr *affineExprs);

/// Creates a single constant result affine map in the context. The affine map
/// is owned by the context.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapConstantGet(MlirContext ctx,
                                                          int64_t val);

/// Creates an affine map with 'numDims' identity in the context. The affine map
/// is owned by the context.
MLIR_CAPI_EXPORTED MlirAffineMap
mlirAffineMapMultiDimIdentityGet(MlirContext ctx, intptr_t numDims);

/// Creates an identity affine map on the most minor dimensions in the context.
/// The affine map is owned by the context. The function asserts that the number
/// of dimensions is greater or equal to the number of results.
MLIR_CAPI_EXPORTED MlirAffineMap
mlirAffineMapMinorIdentityGet(MlirContext ctx, intptr_t dims, intptr_t results);

/// Creates an affine map with a permutation expression and its size in the
/// context. The permutation expression is a non-empty vector of integers.
/// The elements of the permutation vector must be continuous from 0 and cannot
/// be repeated (i.e. `[1,2,0]` is a valid permutation. `[2,0]` or `[1,1,2]` is
/// an invalid invalid permutation.) The affine map is owned by the context.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapPermutationGet(
    MlirContext ctx, intptr_t size, unsigned *permutation);

/// Checks whether the given affine map is an identity affine map. The function
/// asserts that the number of dimensions is greater or equal to the number of
/// results.
MLIR_CAPI_EXPORTED bool mlirAffineMapIsIdentity(MlirAffineMap affineMap);

/// Checks whether the given affine map is a minor identity affine map.
MLIR_CAPI_EXPORTED bool mlirAffineMapIsMinorIdentity(MlirAffineMap affineMap);

/// Checks whether the given affine map is an empty affine map.
MLIR_CAPI_EXPORTED bool mlirAffineMapIsEmpty(MlirAffineMap affineMap);

/// Checks whether the given affine map is a single result constant affine
/// map.
MLIR_CAPI_EXPORTED bool mlirAffineMapIsSingleConstant(MlirAffineMap affineMap);

/// Returns the constant result of the given affine map. The function asserts
/// that the map has a single constant result.
MLIR_CAPI_EXPORTED int64_t
mlirAffineMapGetSingleConstantResult(MlirAffineMap affineMap);

/// Returns the number of dimensions of the given affine map.
MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumDims(MlirAffineMap affineMap);

/// Returns the number of symbols of the given affine map.
MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumSymbols(MlirAffineMap affineMap);

/// Returns the number of results of the given affine map.
MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumResults(MlirAffineMap affineMap);

/// Returns the result at the given position.
MLIR_CAPI_EXPORTED MlirAffineExpr
mlirAffineMapGetResult(MlirAffineMap affineMap, intptr_t pos);

/// Returns the number of inputs (dimensions + symbols) of the given affine
/// map.
MLIR_CAPI_EXPORTED intptr_t mlirAffineMapGetNumInputs(MlirAffineMap affineMap);

/// Checks whether the given affine map represents a subset of a symbol-less
/// permutation map.
MLIR_CAPI_EXPORTED bool
mlirAffineMapIsProjectedPermutation(MlirAffineMap affineMap);

/// Checks whether the given affine map represents a symbol-less permutation
/// map.
MLIR_CAPI_EXPORTED bool mlirAffineMapIsPermutation(MlirAffineMap affineMap);

/// Returns the affine map consisting of the `resultPos` subset.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapGetSubMap(MlirAffineMap affineMap,
                                                        intptr_t size,
                                                        intptr_t *resultPos);

/// Returns the affine map consisting of the most major `numResults` results.
/// Returns the null AffineMap if the `numResults` is equal to zero.
/// Returns the `affineMap` if `numResults` is greater or equals to number of
/// results of the given affine map.
MLIR_CAPI_EXPORTED MlirAffineMap
mlirAffineMapGetMajorSubMap(MlirAffineMap affineMap, intptr_t numResults);

/// Returns the affine map consisting of the most minor `numResults` results.
/// Returns the null AffineMap if the `numResults` is equal to zero.
/// Returns the `affineMap` if `numResults` is greater or equals to number of
/// results of the given affine map.
MLIR_CAPI_EXPORTED MlirAffineMap
mlirAffineMapGetMinorSubMap(MlirAffineMap affineMap, intptr_t numResults);

/// Apply AffineExpr::replace(`map`) to each of the results and return a new
/// new AffineMap with the new results and the specified number of dims and
/// symbols.
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapReplace(
    MlirAffineMap affineMap, MlirAffineExpr expression,
    MlirAffineExpr replacement, intptr_t numResultDims, intptr_t numResultSyms);

/// Returns the simplified affine map resulting from dropping the symbols that
/// do not appear in any of the individual maps in `affineMaps`.
/// Asserts that all maps in `affineMaps` are normalized to the same number of
/// dims and symbols.
/// Takes a callback `populateResult` to fill the `res` container with value
/// `m` at entry `idx`. This allows returning without worrying about ownership
/// considerations.
MLIR_CAPI_EXPORTED void mlirAffineMapCompressUnusedSymbols(
    MlirAffineMap *affineMaps, intptr_t size, void *result,
    void (*populateResult)(void *res, intptr_t idx, MlirAffineMap m));

#ifdef __cplusplus
}
#endif

#endif // MLIR_C_AFFINEMAP_H