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"
80 explicit operator bool()
const {
return expr; }
116 template <
typename FnT,
typename RetT = detail::walkResultType<FnT>>
117 RetT
walk(FnT &&callback)
const {
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>
248 return ::llvm::hash_value(arg.
expr);
254 return expr * (-1) + val;
272 unsigned numDims,
unsigned numSymbols,
285 unsigned numSymbols);
291template <
int N,
typename AffineExprTy,
typename... AffineExprTy2>
294 bindDims<N + 1, AffineExprTy2 &...>(ctx, exprs...);
300template <
int N,
typename AffineExprTy,
typename... AffineExprTy2>
303 bindSymbols<N + 1, AffineExprTy2 &...>(ctx, exprs...);
310template <
typename... AffineExprTy>
315template <
typename AffineExprTy>
318 for (AffineExprTy &e : exprs)
324template <
typename... AffineExprTy>
329template <
typename AffineExprTy>
332 for (AffineExprTy &e : exprs)
344std::optional<int64_t>
346 ArrayRef<std::optional<int64_t>> constLowerBounds,
347 ArrayRef<std::optional<int64_t>> constUpperBounds,
375template <
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>)
391 if constexpr (std::is_same_v<To, ::mlir::AffineDimExpr>)
393 if constexpr (std::is_same_v<To, ::mlir::AffineSymbolExpr>)
395 if constexpr (std::is_same_v<To, ::mlir::AffineConstantExpr>)
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be the output argument nBegin is set to its * replacement(set to `begin` if no invalidation happens). Since outgoing *copies could have been inserted at `end`
AffineExpr getLHS() const
AffineBinaryOpExpr(AffineExpr::ImplType *ptr)
detail::AffineBinaryOpExprStorage ImplType
AffineExpr getRHS() const
AffineConstantExpr(AffineExpr::ImplType *ptr=nullptr)
detail::AffineConstantExprStorage ImplType
AffineDimExpr(AffineExpr::ImplType *ptr)
detail::AffineDimExprStorage ImplType
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.
const void * getAsOpaquePointer() const
Methods supporting C API.
AffineExpr shiftDims(unsigned numDims, unsigned shift, unsigned offset=0) const
Replace dims[offset ... numDims) by dims[offset + shift ... shift + numDims).
bool operator==(int64_t v) const
ImplType * getImpl() const
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
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 ... numSymbols) by symbols[offset + shift ... shift + numSymbols).
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
friend::llvm::hash_code hash_value(AffineExpr arg)
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.
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.
detail::AffineExprStorage ImplType
AffineExpr operator+(AffineExpr other) const
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.
unsigned getPosition() const
detail::AffineDimExprStorage ImplType
AffineSymbolExpr(AffineExpr::ImplType *ptr)
An integer set representing a conjunction of one or more affine equalities and inequalities.
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.
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
void bindDimsList(MLIRContext *ctx, MutableArrayRef< AffineExprTy > exprs)
void bindDims(MLIRContext *ctx, AffineExprTy &...exprs)
Bind a list of AffineExpr references to DimExpr at positions: [0 .
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...
@ 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)
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
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.
llvm::function_ref< Fn > function_ref
AffineExpr getAffineSymbolExpr(unsigned position, MLIRContext *context)
void bindSymbolsList(MLIRContext *ctx, MutableArrayRef< AffineExprTy > exprs)
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.