forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAffineExpr.cpp
188 lines (146 loc) · 6.77 KB
/
AffineExpr.cpp
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
//===- AffineExpr.cpp - C API for MLIR Affine Expressions -----------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "mlir-c/AffineExpr.h"
#include "mlir-c/AffineMap.h"
#include "mlir-c/IR.h"
#include "mlir/CAPI/AffineExpr.h"
#include "mlir/CAPI/AffineMap.h"
#include "mlir/CAPI/IR.h"
#include "mlir/CAPI/Utils.h"
#include "mlir/IR/AffineExpr.h"
using namespace mlir;
MlirContext mlirAffineExprGetContext(MlirAffineExpr affineExpr) {
return wrap(unwrap(affineExpr).getContext());
}
bool mlirAffineExprEqual(MlirAffineExpr lhs, MlirAffineExpr rhs) {
return unwrap(lhs) == unwrap(rhs);
}
void mlirAffineExprPrint(MlirAffineExpr affineExpr, MlirStringCallback callback,
void *userData) {
mlir::detail::CallbackOstream stream(callback, userData);
unwrap(affineExpr).print(stream);
}
void mlirAffineExprDump(MlirAffineExpr affineExpr) {
unwrap(affineExpr).dump();
}
bool mlirAffineExprIsSymbolicOrConstant(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).isSymbolicOrConstant();
}
bool mlirAffineExprIsPureAffine(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).isPureAffine();
}
int64_t mlirAffineExprGetLargestKnownDivisor(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).getLargestKnownDivisor();
}
bool mlirAffineExprIsMultipleOf(MlirAffineExpr affineExpr, int64_t factor) {
return unwrap(affineExpr).isMultipleOf(factor);
}
bool mlirAffineExprIsFunctionOfDim(MlirAffineExpr affineExpr,
intptr_t position) {
return unwrap(affineExpr).isFunctionOfDim(position);
}
//===----------------------------------------------------------------------===//
// Affine Dimension Expression.
//===----------------------------------------------------------------------===//
bool mlirAffineExprIsADim(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).isa<AffineDimExpr>();
}
MlirAffineExpr mlirAffineDimExprGet(MlirContext ctx, intptr_t position) {
return wrap(getAffineDimExpr(position, unwrap(ctx)));
}
intptr_t mlirAffineDimExprGetPosition(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).cast<AffineDimExpr>().getPosition();
}
//===----------------------------------------------------------------------===//
// Affine Symbol Expression.
//===----------------------------------------------------------------------===//
bool mlirAffineExprIsASymbol(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).isa<AffineSymbolExpr>();
}
MlirAffineExpr mlirAffineSymbolExprGet(MlirContext ctx, intptr_t position) {
return wrap(getAffineSymbolExpr(position, unwrap(ctx)));
}
intptr_t mlirAffineSymbolExprGetPosition(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).cast<AffineSymbolExpr>().getPosition();
}
//===----------------------------------------------------------------------===//
// Affine Constant Expression.
//===----------------------------------------------------------------------===//
bool mlirAffineExprIsAConstant(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).isa<AffineConstantExpr>();
}
MlirAffineExpr mlirAffineConstantExprGet(MlirContext ctx, int64_t constant) {
return wrap(getAffineConstantExpr(constant, unwrap(ctx)));
}
int64_t mlirAffineConstantExprGetValue(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).cast<AffineConstantExpr>().getValue();
}
//===----------------------------------------------------------------------===//
// Affine Add Expression.
//===----------------------------------------------------------------------===//
bool mlirAffineExprIsAAdd(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).getKind() == mlir::AffineExprKind::Add;
}
MlirAffineExpr mlirAffineAddExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs) {
return wrap(getAffineBinaryOpExpr(mlir::AffineExprKind::Add, unwrap(lhs),
unwrap(rhs)));
}
//===----------------------------------------------------------------------===//
// Affine Mul Expression.
//===----------------------------------------------------------------------===//
bool mlirAffineExprIsAMul(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).getKind() == mlir::AffineExprKind::Mul;
}
MlirAffineExpr mlirAffineMulExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs) {
return wrap(getAffineBinaryOpExpr(mlir::AffineExprKind::Mul, unwrap(lhs),
unwrap(rhs)));
}
//===----------------------------------------------------------------------===//
// Affine Mod Expression.
//===----------------------------------------------------------------------===//
bool mlirAffineExprIsAMod(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).getKind() == mlir::AffineExprKind::Mod;
}
MlirAffineExpr mlirAffineModExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs) {
return wrap(getAffineBinaryOpExpr(mlir::AffineExprKind::Mod, unwrap(lhs),
unwrap(rhs)));
}
//===----------------------------------------------------------------------===//
// Affine FloorDiv Expression.
//===----------------------------------------------------------------------===//
bool mlirAffineExprIsAFloorDiv(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).getKind() == mlir::AffineExprKind::FloorDiv;
}
MlirAffineExpr mlirAffineFloorDivExprGet(MlirAffineExpr lhs,
MlirAffineExpr rhs) {
return wrap(getAffineBinaryOpExpr(mlir::AffineExprKind::FloorDiv, unwrap(lhs),
unwrap(rhs)));
}
//===----------------------------------------------------------------------===//
// Affine CeilDiv Expression.
//===----------------------------------------------------------------------===//
bool mlirAffineExprIsACeilDiv(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).getKind() == mlir::AffineExprKind::CeilDiv;
}
MlirAffineExpr mlirAffineCeilDivExprGet(MlirAffineExpr lhs,
MlirAffineExpr rhs) {
return wrap(getAffineBinaryOpExpr(mlir::AffineExprKind::CeilDiv, unwrap(lhs),
unwrap(rhs)));
}
//===----------------------------------------------------------------------===//
// Affine Binary Operation Expression.
//===----------------------------------------------------------------------===//
bool mlirAffineExprIsABinary(MlirAffineExpr affineExpr) {
return unwrap(affineExpr).isa<AffineBinaryOpExpr>();
}
MlirAffineExpr mlirAffineBinaryOpExprGetLHS(MlirAffineExpr affineExpr) {
return wrap(unwrap(affineExpr).cast<AffineBinaryOpExpr>().getLHS());
}
MlirAffineExpr mlirAffineBinaryOpExprGetRHS(MlirAffineExpr affineExpr) {
return wrap(unwrap(affineExpr).cast<AffineBinaryOpExpr>().getRHS());
}