14 #ifndef MLIR_IR_AFFINEEXPR_H
15 #define MLIR_IR_AFFINEEXPR_H
19 #include "llvm/ADT/DenseMapInfo.h"
20 #include "llvm/ADT/Hashing.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/Support/Casting.h"
23 #include <type_traits>
33 struct AffineExprStorage;
34 struct AffineBinaryOpExprStorage;
35 struct AffineDimExprStorage;
36 struct AffineConstantExprStorage;
79 bool operator!=(int64_t v)
const {
return !(*
this == v); }
80 explicit operator bool()
const {
return expr; }
89 void print(raw_ostream &os)
const;
116 template <
typename FnT,
typename RetT = detail::walkResultType<FnT>>
117 RetT
walk(FnT &&callback)
const {
118 return walk<RetT>(*
this, callback);
146 unsigned offset = 0)
const;
151 unsigned offset = 0)
const;
186 return static_cast<const void *
>(
expr);
190 reinterpret_cast<ImplType *
>(
const_cast<void *
>(pointer)));
203 template <
typename WalkRetTy>
254 return expr * (-1) + val;
262 MLIRContext *context);
272 unsigned numDims,
unsigned numSymbols,
273 ArrayRef<AffineExpr> localExprs,
274 MLIRContext *context);
276 raw_ostream &
operator<<(raw_ostream &os, AffineExpr expr);
285 unsigned numSymbols);
291 template <
int N,
typename AffineExprTy,
typename... AffineExprTy2>
294 bindDims<N + 1, AffineExprTy2 &...>(ctx, exprs...);
300 template <
int N,
typename AffineExprTy,
typename... AffineExprTy2>
303 bindSymbols<N + 1, AffineExprTy2 &...>(ctx, exprs...);
310 template <
typename... AffineExprTy>
312 detail::bindDims<0>(ctx, exprs...);
315 template <
typename AffineExprTy>
318 for (AffineExprTy &e : exprs)
324 template <
typename... AffineExprTy>
326 detail::bindSymbols<0>(ctx, exprs...);
329 template <
typename AffineExprTy>
332 for (AffineExprTy &e : exprs)
344 std::optional<int64_t>
346 ArrayRef<std::optional<int64_t>> constLowerBounds,
347 ArrayRef<std::optional<int64_t>> constUpperBounds,
375 template <
typename To,
typename From>
377 std::enable_if_t<std::is_same_v<mlir::AffineExpr,
378 std::remove_const_t<From>> ||
379 std::is_base_of_v<mlir::AffineExpr, From>>>
386 if constexpr (std::is_base_of_v<To, From>) {
389 if constexpr (std::is_same_v<To, ::mlir::AffineBinaryOpExpr>)
390 return expr.
getKind() <= ::mlir::AffineExprKind::LAST_AFFINE_BINARY_OP;
391 if constexpr (std::is_same_v<To, ::mlir::AffineDimExpr>)
392 return expr.
getKind() == ::mlir::AffineExprKind::DimId;
393 if constexpr (std::is_same_v<To, ::mlir::AffineSymbolExpr>)
394 return expr.
getKind() == ::mlir::AffineExprKind::SymbolId;
395 if constexpr (std::is_same_v<To, ::mlir::AffineConstantExpr>)
396 return expr.
getKind() == ::mlir::AffineExprKind::Constant;
union mlir::linalg::@1193::ArityGroupAndKind::Kind kind
Affine binary operation expression.
AffineExpr getLHS() const
AffineBinaryOpExpr(AffineExpr::ImplType *ptr)
AffineExpr getRHS() const
An integer constant appearing in affine expression.
AffineConstantExpr(AffineExpr::ImplType *ptr=nullptr)
A dimensional identifier appearing in an affine expression.
AffineDimExpr(AffineExpr::ImplType *ptr)
unsigned getPosition() const
Base type for affine expression.
static AffineExpr getFromOpaquePointer(const void *pointer)
AffineExpr replaceDimsAndSymbols(ArrayRef< AffineExpr > dimReplacements, ArrayRef< AffineExpr > symReplacements) const
This method substitutes any uses of dimensions and symbols (e.g.
AffineExpr shiftDims(unsigned numDims, unsigned shift, unsigned offset=0) const
Replace dims[offset ...
ImplType * getImpl() const
AffineExpr operator+(int64_t v) const
friend ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
bool isSymbolicOrConstant() const
Returns true if this expression is made out of only symbols and constants, i.e., it does not involve ...
AffineExpr operator*(int64_t v) const
bool operator==(AffineExpr other) const
bool isPureAffine() const
Returns true if this is a pure affine expression, i.e., multiplication, floordiv, ceildiv,...
AffineExpr shiftSymbols(unsigned numSymbols, unsigned shift, unsigned offset=0) const
Replace symbols[offset ...
AffineExpr operator-() const
AffineExpr floorDiv(uint64_t v) const
RetT walk(FnT &&callback) const
Walk all of the AffineExpr's in this expression in postorder.
bool operator!=(int64_t v) const
AffineExprKind getKind() const
Return the classification for this type.
bool isMultipleOf(int64_t factor) const
Return true if the affine expression is a multiple of 'factor'.
int64_t getLargestKnownDivisor() const
Returns the greatest known integral divisor of this affine expression.
AffineExpr compose(AffineMap map) const
Compose with an AffineMap.
bool isFunctionOfDim(unsigned position) const
Return true if the affine expression involves AffineDimExpr position.
const void * getAsOpaquePointer() const
Methods supporting C API.
bool isFunctionOfSymbol(unsigned position) const
Return true if the affine expression involves AffineSymbolExpr position.
AffineExpr replaceDims(ArrayRef< AffineExpr > dimReplacements) const
Dim-only version of replaceDimsAndSymbols.
bool operator!=(AffineExpr other) const
AffineExpr operator%(uint64_t v) const
MLIRContext * getContext() const
AffineExpr replace(AffineExpr expr, AffineExpr replacement) const
Sparse replace method.
AffineExpr replaceSymbols(ArrayRef< AffineExpr > symReplacements) const
Symbol-only version of replaceDimsAndSymbols.
AffineExpr(const ImplType *expr)
AffineExpr ceilDiv(uint64_t v) const
void print(raw_ostream &os) const
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
A symbolic identifier appearing in an affine expression.
AffineSymbolExpr(AffineExpr::ImplType *ptr)
unsigned getPosition() const
MLIRContext is the top-level object for a collection of MLIR operations.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
void bindDims(MLIRContext *ctx)
void bindSymbols(MLIRContext *ctx)
Include the generated interface declarations.
std::optional< int64_t > getBoundForAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols, ArrayRef< std::optional< int64_t >> constLowerBounds, ArrayRef< std::optional< int64_t >> constUpperBounds, bool isUpper)
Get a lower or upper (depending on isUpper) bound for expr while using the constant lower and upper b...
void bindDimsList(MLIRContext *ctx, MutableArrayRef< AffineExprTy > exprs)
void bindDims(MLIRContext *ctx, AffineExprTy &...exprs)
Bind a list of AffineExpr references to DimExpr at positions: [0 .
@ CeilDiv
RHS of ceildiv is always a constant or a symbolic expression.
@ LAST_AFFINE_BINARY_OP
This is a marker for the last affine binary op.
@ 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.
AffineExpr getAffineBinaryOpExpr(AffineExprKind kind, AffineExpr lhs, AffineExpr rhs)
AffineExpr operator-(int64_t val, AffineExpr expr)
AffineExpr getAffineExprFromFlatForm(ArrayRef< int64_t > flatExprs, unsigned numDims, unsigned numSymbols, ArrayRef< AffineExpr > localExprs, MLIRContext *context)
Constructs an affine expression from a flat ArrayRef.
void bindSymbols(MLIRContext *ctx, AffineExprTy &...exprs)
Bind a list of AffineExpr references to SymbolExpr at positions: [0 .
AffineExpr operator+(int64_t val, AffineExpr expr)
AffineExpr operator*(int64_t val, AffineExpr expr)
AffineExpr getAffineConstantExpr(int64_t constant, MLIRContext *context)
AffineExpr simplifyAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols)
Simplify an affine expression by flattening and some amount of simple analysis.
SmallVector< AffineExpr > getAffineConstantExprs(ArrayRef< int64_t > constants, MLIRContext *context)
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
AffineExpr getAffineDimExpr(unsigned position, MLIRContext *context)
These free functions allow clients of the API to not use classes in detail.
AffineExpr getAffineSymbolExpr(unsigned position, MLIRContext *context)
void bindSymbolsList(MLIRContext *ctx, MutableArrayRef< AffineExprTy > exprs)
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
static bool isPossible(mlir::AffineExpr expr)
static To doCast(mlir::AffineExpr expr)
static unsigned getHashValue(mlir::AffineExpr val)
static mlir::AffineExpr getEmptyKey()
static mlir::AffineExpr getTombstoneKey()
static bool isEqual(mlir::AffineExpr LHS, mlir::AffineExpr RHS)
A binary operation appearing in an affine expression.
An integer constant appearing in affine expression.
A dimensional or symbolic identifier appearing in an affine expression.
Base storage class appearing in an affine expression.