MLIR  16.0.0git
AffineExpr.cpp
Go to the documentation of this file.
1 //===- AffineExpr.cpp - C API for MLIR Affine Expressions -----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "mlir-c/AffineExpr.h"
10 #include "mlir-c/AffineMap.h"
11 #include "mlir-c/IR.h"
12 #include "mlir/CAPI/AffineExpr.h"
13 #include "mlir/CAPI/AffineMap.h"
14 #include "mlir/CAPI/IR.h"
15 #include "mlir/CAPI/Utils.h"
16 #include "mlir/IR/AffineExpr.h"
17 
18 using namespace mlir;
19 
20 MlirContext mlirAffineExprGetContext(MlirAffineExpr affineExpr) {
21  return wrap(unwrap(affineExpr).getContext());
22 }
23 
24 bool mlirAffineExprEqual(MlirAffineExpr lhs, MlirAffineExpr rhs) {
25  return unwrap(lhs) == unwrap(rhs);
26 }
27 
28 void mlirAffineExprPrint(MlirAffineExpr affineExpr, MlirStringCallback callback,
29  void *userData) {
30  mlir::detail::CallbackOstream stream(callback, userData);
31  unwrap(affineExpr).print(stream);
32 }
33 
34 void mlirAffineExprDump(MlirAffineExpr affineExpr) {
35  unwrap(affineExpr).dump();
36 }
37 
38 bool mlirAffineExprIsSymbolicOrConstant(MlirAffineExpr affineExpr) {
39  return unwrap(affineExpr).isSymbolicOrConstant();
40 }
41 
42 bool mlirAffineExprIsPureAffine(MlirAffineExpr affineExpr) {
43  return unwrap(affineExpr).isPureAffine();
44 }
45 
46 int64_t mlirAffineExprGetLargestKnownDivisor(MlirAffineExpr affineExpr) {
47  return unwrap(affineExpr).getLargestKnownDivisor();
48 }
49 
50 bool mlirAffineExprIsMultipleOf(MlirAffineExpr affineExpr, int64_t factor) {
51  return unwrap(affineExpr).isMultipleOf(factor);
52 }
53 
54 bool mlirAffineExprIsFunctionOfDim(MlirAffineExpr affineExpr,
55  intptr_t position) {
56  return unwrap(affineExpr).isFunctionOfDim(position);
57 }
58 
59 MlirAffineExpr mlirAffineExprCompose(MlirAffineExpr affineExpr,
60  MlirAffineMap affineMap) {
61  return wrap(unwrap(affineExpr).compose(unwrap(affineMap)));
62 }
63 
64 //===----------------------------------------------------------------------===//
65 // Affine Dimension Expression.
66 //===----------------------------------------------------------------------===//
67 
68 bool mlirAffineExprIsADim(MlirAffineExpr affineExpr) {
69  return unwrap(affineExpr).isa<AffineDimExpr>();
70 }
71 
72 MlirAffineExpr mlirAffineDimExprGet(MlirContext ctx, intptr_t position) {
73  return wrap(getAffineDimExpr(position, unwrap(ctx)));
74 }
75 
76 intptr_t mlirAffineDimExprGetPosition(MlirAffineExpr affineExpr) {
77  return unwrap(affineExpr).cast<AffineDimExpr>().getPosition();
78 }
79 
80 //===----------------------------------------------------------------------===//
81 // Affine Symbol Expression.
82 //===----------------------------------------------------------------------===//
83 
84 bool mlirAffineExprIsASymbol(MlirAffineExpr affineExpr) {
85  return unwrap(affineExpr).isa<AffineSymbolExpr>();
86 }
87 
88 MlirAffineExpr mlirAffineSymbolExprGet(MlirContext ctx, intptr_t position) {
89  return wrap(getAffineSymbolExpr(position, unwrap(ctx)));
90 }
91 
92 intptr_t mlirAffineSymbolExprGetPosition(MlirAffineExpr affineExpr) {
93  return unwrap(affineExpr).cast<AffineSymbolExpr>().getPosition();
94 }
95 
96 //===----------------------------------------------------------------------===//
97 // Affine Constant Expression.
98 //===----------------------------------------------------------------------===//
99 
100 bool mlirAffineExprIsAConstant(MlirAffineExpr affineExpr) {
101  return unwrap(affineExpr).isa<AffineConstantExpr>();
102 }
103 
104 MlirAffineExpr mlirAffineConstantExprGet(MlirContext ctx, int64_t constant) {
105  return wrap(getAffineConstantExpr(constant, unwrap(ctx)));
106 }
107 
108 int64_t mlirAffineConstantExprGetValue(MlirAffineExpr affineExpr) {
109  return unwrap(affineExpr).cast<AffineConstantExpr>().getValue();
110 }
111 
112 //===----------------------------------------------------------------------===//
113 // Affine Add Expression.
114 //===----------------------------------------------------------------------===//
115 
116 bool mlirAffineExprIsAAdd(MlirAffineExpr affineExpr) {
117  return unwrap(affineExpr).getKind() == mlir::AffineExprKind::Add;
118 }
119 
120 MlirAffineExpr mlirAffineAddExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs) {
122  unwrap(rhs)));
123 }
124 
125 //===----------------------------------------------------------------------===//
126 // Affine Mul Expression.
127 //===----------------------------------------------------------------------===//
128 
129 bool mlirAffineExprIsAMul(MlirAffineExpr affineExpr) {
130  return unwrap(affineExpr).getKind() == mlir::AffineExprKind::Mul;
131 }
132 
133 MlirAffineExpr mlirAffineMulExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs) {
135  unwrap(rhs)));
136 }
137 
138 //===----------------------------------------------------------------------===//
139 // Affine Mod Expression.
140 //===----------------------------------------------------------------------===//
141 
142 bool mlirAffineExprIsAMod(MlirAffineExpr affineExpr) {
143  return unwrap(affineExpr).getKind() == mlir::AffineExprKind::Mod;
144 }
145 
146 MlirAffineExpr mlirAffineModExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs) {
148  unwrap(rhs)));
149 }
150 
151 //===----------------------------------------------------------------------===//
152 // Affine FloorDiv Expression.
153 //===----------------------------------------------------------------------===//
154 
155 bool mlirAffineExprIsAFloorDiv(MlirAffineExpr affineExpr) {
156  return unwrap(affineExpr).getKind() == mlir::AffineExprKind::FloorDiv;
157 }
158 
159 MlirAffineExpr mlirAffineFloorDivExprGet(MlirAffineExpr lhs,
160  MlirAffineExpr rhs) {
162  unwrap(rhs)));
163 }
164 
165 //===----------------------------------------------------------------------===//
166 // Affine CeilDiv Expression.
167 //===----------------------------------------------------------------------===//
168 
169 bool mlirAffineExprIsACeilDiv(MlirAffineExpr affineExpr) {
170  return unwrap(affineExpr).getKind() == mlir::AffineExprKind::CeilDiv;
171 }
172 
173 MlirAffineExpr mlirAffineCeilDivExprGet(MlirAffineExpr lhs,
174  MlirAffineExpr rhs) {
176  unwrap(rhs)));
177 }
178 
179 //===----------------------------------------------------------------------===//
180 // Affine Binary Operation Expression.
181 //===----------------------------------------------------------------------===//
182 
183 bool mlirAffineExprIsABinary(MlirAffineExpr affineExpr) {
184  return unwrap(affineExpr).isa<AffineBinaryOpExpr>();
185 }
186 
187 MlirAffineExpr mlirAffineBinaryOpExprGetLHS(MlirAffineExpr affineExpr) {
188  return wrap(unwrap(affineExpr).cast<AffineBinaryOpExpr>().getLHS());
189 }
190 
191 MlirAffineExpr mlirAffineBinaryOpExprGetRHS(MlirAffineExpr affineExpr) {
192  return wrap(unwrap(affineExpr).cast<AffineBinaryOpExpr>().getRHS());
193 }
Affine binary operation expression.
Definition: AffineExpr.h:207
Include the generated interface declarations.
MlirAffineExpr mlirAffineModExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine mod expression with &#39;lhs&#39; and &#39;rhs&#39;.
Definition: AffineExpr.cpp:146
MlirAffineExpr mlirAffineConstantExprGet(MlirContext ctx, int64_t constant)
Creates an affine constant expression with &#39;constant&#39; in the context.
Definition: AffineExpr.cpp:104
RHS of mod is always a constant or a symbolic expression with a positive value.
bool mlirAffineExprIsAConstant(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a constant expression.
Definition: AffineExpr.cpp:100
AffineExpr getAffineConstantExpr(int64_t constant, MLIRContext *context)
Definition: AffineExpr.cpp:513
bool mlirAffineExprIsAMod(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an mod expression.
Definition: AffineExpr.cpp:142
bool mlirAffineExprIsAFloorDiv(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an floordiv expression.
Definition: AffineExpr.cpp:155
MlirAffineExpr mlirAffineBinaryOpExprGetLHS(MlirAffineExpr affineExpr)
Returns the left hand side affine expression of the given affine binary operation expression...
Definition: AffineExpr.cpp:187
bool mlirAffineExprIsPureAffine(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a pure affine expression, i.e.
Definition: AffineExpr.cpp:42
MlirAffineExpr mlirAffineAddExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine add expression with &#39;lhs&#39; and &#39;rhs&#39;.
Definition: AffineExpr.cpp:120
bool mlirAffineExprIsASymbol(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a symbol expression.
Definition: AffineExpr.cpp:84
A simple raw ostream subclass that forwards write_impl calls to the user-supplied callback together w...
Definition: Utils.h:30
An integer constant appearing in affine expression.
Definition: AffineExpr.h:232
bool mlirAffineExprIsACeilDiv(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an ceildiv expression.
Definition: AffineExpr.cpp:169
MlirAffineExpr mlirAffineDimExprGet(MlirContext ctx, intptr_t position)
Creates an affine dimension expression with &#39;position&#39; in the context.
Definition: AffineExpr.cpp:72
bool mlirAffineExprIsADim(MlirAffineExpr affineExpr)
Checks whether the given affine expression is a dimension expression.
Definition: AffineExpr.cpp:68
void print(raw_ostream &os) const
Outputs this diagnostic to a stream.
AffineExpr getAffineSymbolExpr(unsigned position, MLIRContext *context)
Definition: AffineExpr.cpp:498
bool mlirAffineExprIsSymbolicOrConstant(MlirAffineExpr affineExpr)
Checks whether the given affine expression is made out of only symbols and constants.
Definition: AffineExpr.cpp:38
RHS of mul is always a constant or a symbolic expression.
int64_t mlirAffineConstantExprGetValue(MlirAffineExpr affineExpr)
Returns the value of the given affine constant expression.
Definition: AffineExpr.cpp:108
intptr_t mlirAffineDimExprGetPosition(MlirAffineExpr affineExpr)
Returns the position of the given affine dimension expression.
Definition: AffineExpr.cpp:76
bool mlirAffineExprEqual(MlirAffineExpr lhs, MlirAffineExpr rhs)
Returns true if the two affine expressions are equal.
Definition: AffineExpr.cpp:24
void mlirAffineExprDump(MlirAffineExpr affineExpr)
Prints the affine expression to the standard error stream.
Definition: AffineExpr.cpp:34
MlirAffineExpr mlirAffineMulExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine mul expression with &#39;lhs&#39; and &#39;rhs&#39;.
Definition: AffineExpr.cpp:133
MlirAffineExpr mlirAffineBinaryOpExprGetRHS(MlirAffineExpr affineExpr)
Returns the right hand side affine expression of the given affine binary operation expression...
Definition: AffineExpr.cpp:191
RHS of floordiv is always a constant or a symbolic expression.
AffineExpr getAffineDimExpr(unsigned position, MLIRContext *context)
These free functions allow clients of the API to not use classes in detail.
Definition: AffineExpr.cpp:488
AffineExpr getAffineBinaryOpExpr(AffineExprKind kind, AffineExpr lhs, AffineExpr rhs)
Definition: AffineExpr.cpp:46
MlirContext mlirAffineExprGetContext(MlirAffineExpr affineExpr)
Gets the context that owns the affine expression.
Definition: AffineExpr.cpp:20
RHS of ceildiv is always a constant or a symbolic expression.
void mlirAffineExprPrint(MlirAffineExpr affineExpr, MlirStringCallback callback, void *userData)
Prints an affine expression by sending chunks of the string representation and forwarding userData to...
Definition: AffineExpr.cpp:28
bool mlirAffineExprIsAMul(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an mul expression.
Definition: AffineExpr.cpp:129
MlirAffineExpr mlirAffineFloorDivExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine floordiv expression with &#39;lhs&#39; and &#39;rhs&#39;.
Definition: AffineExpr.cpp:159
bool mlirAffineExprIsMultipleOf(MlirAffineExpr affineExpr, int64_t factor)
Checks whether the given affine expression is a multiple of &#39;factor&#39;.
Definition: AffineExpr.cpp:50
bool mlirAffineExprIsABinary(MlirAffineExpr affineExpr)
Checks whether the given affine expression is binary.
Definition: AffineExpr.cpp:183
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition: Diagnostics.h:24
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition: Support.h:103
A dimensional identifier appearing in an affine expression.
Definition: AffineExpr.h:216
intptr_t mlirAffineSymbolExprGetPosition(MlirAffineExpr affineExpr)
Returns the position of the given affine symbol expression.
Definition: AffineExpr.cpp:92
bool mlirAffineExprIsFunctionOfDim(MlirAffineExpr affineExpr, intptr_t position)
Checks whether the given affine expression involves AffineDimExpr &#39;position&#39;.
Definition: AffineExpr.cpp:54
MlirAffineExpr mlirAffineSymbolExprGet(MlirContext ctx, intptr_t position)
Creates an affine symbol expression with &#39;position&#39; in the context.
Definition: AffineExpr.cpp:88
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
bool mlirAffineExprIsAAdd(MlirAffineExpr affineExpr)
Checks whether the given affine expression is an add expression.
Definition: AffineExpr.cpp:116
MlirAffineExpr mlirAffineCeilDivExprGet(MlirAffineExpr lhs, MlirAffineExpr rhs)
Creates an affine ceildiv expression with &#39;lhs&#39; and &#39;rhs&#39;.
Definition: AffineExpr.cpp:173
MlirAffineExpr mlirAffineExprCompose(MlirAffineExpr affineExpr, MlirAffineMap affineMap)
Composes the given map with the given expression.
Definition: AffineExpr.cpp:59
int64_t mlirAffineExprGetLargestKnownDivisor(MlirAffineExpr affineExpr)
Returns the greatest known integral divisor of this affine expression.
Definition: AffineExpr.cpp:46
A symbolic identifier appearing in an affine expression.
Definition: AffineExpr.h:224