13 #ifndef MLIR_IR_AFFINEEXPRVISITOR_H
14 #define MLIR_IR_AFFINEEXPRVISITOR_H
18 #include "llvm/ADT/ArrayRef.h"
71 template <
typename SubClass,
typename RetTy>
76 static_assert(std::is_base_of<AffineExprVisitorBase, SubClass>::value,
77 "Must instantiate with a derived type of AffineExprVisitor");
78 auto self =
static_cast<SubClass *
>(
this);
81 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
82 return self->visitAddExpr(binOpExpr);
85 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
86 return self->visitMulExpr(binOpExpr);
89 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
90 return self->visitModExpr(binOpExpr);
93 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
94 return self->visitFloorDivExpr(binOpExpr);
97 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
98 return self->visitCeilDivExpr(binOpExpr);
101 return self->visitConstantExpr(cast<AffineConstantExpr>(expr));
103 return self->visitDimExpr(cast<AffineDimExpr>(expr));
105 return self->visitSymbolExpr(cast<AffineSymbolExpr>(expr));
107 llvm_unreachable(
"Unknown AffineExpr");
143 template <
typename SubClass,
typename RetTy =
void>
151 static_assert(std::is_base_of<AffineExprVisitor, SubClass>::value,
152 "Must instantiate with a derived type of AffineExprVisitor");
153 auto self =
static_cast<SubClass *
>(
this);
156 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
157 if constexpr (std::is_same<RetTy, WalkResult>::value) {
158 if (walkOperandsPostOrder(binOpExpr).wasInterrupted())
161 walkOperandsPostOrder(binOpExpr);
163 return self->visitAddExpr(binOpExpr);
166 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
167 if constexpr (std::is_same<RetTy, WalkResult>::value) {
168 if (walkOperandsPostOrder(binOpExpr).wasInterrupted())
171 walkOperandsPostOrder(binOpExpr);
173 return self->visitMulExpr(binOpExpr);
176 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
177 if constexpr (std::is_same<RetTy, WalkResult>::value) {
178 if (walkOperandsPostOrder(binOpExpr).wasInterrupted())
181 walkOperandsPostOrder(binOpExpr);
183 return self->visitModExpr(binOpExpr);
186 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
187 if constexpr (std::is_same<RetTy, WalkResult>::value) {
188 if (walkOperandsPostOrder(binOpExpr).wasInterrupted())
191 walkOperandsPostOrder(binOpExpr);
193 return self->visitFloorDivExpr(binOpExpr);
196 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
197 if constexpr (std::is_same<RetTy, WalkResult>::value) {
198 if (walkOperandsPostOrder(binOpExpr).wasInterrupted())
201 walkOperandsPostOrder(binOpExpr);
203 return self->visitCeilDivExpr(binOpExpr);
206 return self->visitConstantExpr(cast<AffineConstantExpr>(expr));
208 return self->visitDimExpr(cast<AffineDimExpr>(expr));
210 return self->visitSymbolExpr(cast<AffineSymbolExpr>(expr));
212 llvm_unreachable(
"Unknown AffineExpr");
218 if constexpr (std::is_same<RetTy, WalkResult>::value) {
224 if constexpr (std::is_same<RetTy, WalkResult>::value) {
234 template <
typename SubClass>
243 static_assert(std::is_base_of<AffineExprVisitor, SubClass>::value,
244 "Must instantiate with a derived type of AffineExprVisitor");
245 auto self =
static_cast<SubClass *
>(
this);
248 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
249 if (failed(walkOperandsPostOrder(binOpExpr)))
251 return self->visitAddExpr(binOpExpr);
254 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
255 if (failed(walkOperandsPostOrder(binOpExpr)))
257 return self->visitMulExpr(binOpExpr);
260 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
261 if (failed(walkOperandsPostOrder(binOpExpr)))
263 return self->visitModExpr(binOpExpr);
266 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
267 if (failed(walkOperandsPostOrder(binOpExpr)))
269 return self->visitFloorDivExpr(binOpExpr);
272 auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
273 if (failed(walkOperandsPostOrder(binOpExpr)))
275 return self->visitCeilDivExpr(binOpExpr);
278 return self->visitConstantExpr(cast<AffineConstantExpr>(expr));
280 return self->visitDimExpr(cast<AffineDimExpr>(expr));
282 return self->visitSymbolExpr(cast<AffineSymbolExpr>(expr));
284 llvm_unreachable(
"Unknown AffineExpr");
431 unsigned long resultSize);
445 inline unsigned getNumCols()
const {
448 inline unsigned getConstantIndex()
const {
return getNumCols() - 1; }
450 inline unsigned getSymbolStartIndex()
const {
return numDims; }
451 inline unsigned getDimStartIndex()
const {
return 0; }
Affine binary operation expression.
AffineExpr getLHS() const
AffineExpr getRHS() const
An integer constant appearing in affine expression.
A dimensional identifier appearing in an affine expression.
Base class for AffineExpr visitors/walkers.
RetTy visitAddExpr(AffineBinaryOpExpr expr)
RetTy visitDimExpr(AffineDimExpr expr)
RetTy visitFloorDivExpr(AffineBinaryOpExpr expr)
RetTy visit(AffineExpr expr)
RetTy visitSymbolExpr(AffineSymbolExpr expr)
RetTy visitAffineBinaryOpExpr(AffineBinaryOpExpr expr)
RetTy visitModExpr(AffineBinaryOpExpr expr)
RetTy visitConstantExpr(AffineConstantExpr expr)
RetTy visitMulExpr(AffineBinaryOpExpr expr)
RetTy visitCeilDivExpr(AffineBinaryOpExpr expr)
LogicalResult walkPostOrder(AffineExpr expr)
See documentation for AffineExprVisitorBase.
RetTy walkPostOrder(AffineExpr expr)
Base type for affine expression.
AffineExprKind getKind() const
Return the classification for this type.
A symbolic identifier appearing in an affine expression.
virtual void addLocalFloorDivId(ArrayRef< int64_t > dividend, int64_t divisor, AffineExpr localExpr)
LogicalResult visitSymbolExpr(AffineSymbolExpr expr)
std::vector< SmallVector< int64_t, 8 > > operandExprStack
LogicalResult visitDimExpr(AffineDimExpr expr)
LogicalResult visitFloorDivExpr(AffineBinaryOpExpr expr)
LogicalResult visitConstantExpr(AffineConstantExpr expr)
virtual LogicalResult addLocalIdSemiAffine(ArrayRef< int64_t > lhs, ArrayRef< int64_t > rhs, AffineExpr localExpr)
Add a local identifier (needed to flatten a mod, floordiv, ceildiv, mul expr) when the rhs is a symbo...
LogicalResult visitModExpr(AffineBinaryOpExpr expr)
LogicalResult visitAddExpr(AffineBinaryOpExpr expr)
virtual ~SimpleAffineExprFlattener()=default
LogicalResult visitCeilDivExpr(AffineBinaryOpExpr expr)
LogicalResult visitMulExpr(AffineBinaryOpExpr expr)
SmallVector< AffineExpr, 4 > localExprs
SimpleAffineExprFlattener(unsigned numDims, unsigned numSymbols)
static WalkResult advance()
static WalkResult interrupt()
Include the generated interface declarations.
@ CeilDiv
RHS of ceildiv is always a constant or a symbolic expression.
@ Mul
RHS of mul is always a constant or a symbolic expression.
@ Mod
RHS of mod is always a constant or a symbolic expression with a positive value.
@ DimId
Dimensional identifier.
@ FloorDiv
RHS of floordiv is always a constant or a symbolic expression.
@ Constant
Constant integer.
@ SymbolId
Symbolic identifier.