9 #ifndef MLIR_DIALECT_SPARSETENSOR_IR_DETAIL_DIMLVLMAP_H
10 #define MLIR_DIALECT_SPARSETENSOR_IR_DETAIL_DIMLVLMAP_H
15 #include "llvm/ADT/STLForwardCompat.h"
18 namespace sparse_tensor {
25 using VK = std::underlying_type_t<VarKind>;
26 return VarKind{2 *
static_cast<VK
>(!llvm::to_underlying(ek))};
44 return kind == other.kind && expr == other.expr;
47 return !(*
this == other);
49 explicit operator bool()
const {
return static_cast<bool>(expr); }
55 constexpr
bool isa()
const;
57 constexpr U
cast()
const;
84 std::tuple<DimLvlExpr, AffineExprKind, DimLvlExpr>
unpackBinop()
const;
94 static_assert(IsZeroCostAbstraction<DimLvlExpr>);
110 return var ? std::make_optional(var->cast<
LvlVar>()) : std::nullopt;
113 static_assert(IsZeroCostAbstraction<DimExpr>);
129 return var ? std::make_optional(var->cast<
DimVar>()) : std::nullopt;
132 static_assert(IsZeroCostAbstraction<LvlExpr>);
134 template <
typename U>
136 if constexpr (std::is_same_v<U, DimExpr>)
138 if constexpr (std::is_same_v<U, LvlExpr>)
142 template <
typename U>
148 template <
typename U>
150 return isa<U>() ? U(*
this) : U();
165 bool elideExpr =
false;
167 SparseTensorDimSliceAttr slice;
175 bool hasExpr()
const {
return static_cast<bool>(expr); }
183 constexpr SparseTensorDimSliceAttr
getSlice()
const {
return slice; }
192 static_assert(IsZeroCostAbstraction<DimSpec>);
201 bool elideVar =
false;
227 static_assert(IsZeroCostAbstraction<LvlSpec>);
257 [[nodiscard]]
bool isWF()
const;
263 assert(expr &&
getRanks().isValid(expr));
264 dimSpecs[dim].setExpr(expr);
271 bool mustPrintLvlVars;
Base type for affine expression.
AffineExprKind getKind() const
Return the classification for this type.
MLIRContext * getContext() const
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
MLIRContext is the top-level object for a collection of MLIR operations.
LvlVar castLvlVar() const
static constexpr ExprKind Kind
static constexpr bool classof(DimLvlExpr const *expr)
std::optional< LvlVar > dyn_castLvlVar() const
constexpr DimExpr(AffineExpr expr)
SymVar castSymVar() const
constexpr U dyn_cast() const
bool isValid(Ranks const &ranks) const
Checks whether the variables bound/used by this spec are valid with respect to the given ranks.
constexpr bool operator!=(DimLvlExpr other) const
std::optional< SymVar > dyn_castSymVar() const
AffineExprKind getAffineKind() const
Var castDimLvlVar() const
constexpr AffineExpr getAffineExpr() const
constexpr ExprKind getExprKind() const
constexpr bool isa() const
constexpr bool operator==(DimLvlExpr other) const
std::tuple< DimLvlExpr, AffineExprKind, DimLvlExpr > unpackBinop() const
constexpr DimLvlExpr(ExprKind ek, AffineExpr expr)
constexpr VarKind getAllowedVarKind() const
std::optional< Var > dyn_castDimLvlVar() const
MLIRContext * tryGetContext() const
DimLvlMap(unsigned symRank, ArrayRef< DimSpec > dimSpecs, ArrayRef< LvlSpec > lvlSpecs)
SparseTensorDimSliceAttr getDimSlice(Dimension dim) const
AffineMap getDimToLvlMap(MLIRContext *context) const
unsigned getSymRank() const
unsigned getDimRank() const
ArrayRef< LvlSpec > getLvls() const
AffineMap getLvlToDimMap(MLIRContext *context) const
unsigned getRank(VarKind vk) const
const DimSpec & getDim(Dimension dim) const
ArrayRef< DimSpec > getDims() const
unsigned getLvlRank() const
LevelType getLvlType(Level lvl) const
const LvlSpec & getLvl(Level lvl) const
The full dimVar = dimExpr : dimSlice specification for a given dimension.
void setElideExpr(bool b)
constexpr DimExpr getExpr() const
bool isValid(Ranks const &ranks) const
Checks whether the variables bound/used by this spec are valid with respect to the given ranks.
void setExpr(DimExpr newExpr)
constexpr bool canElideExpr() const
MLIRContext * tryGetContext() const
constexpr SparseTensorDimSliceAttr getSlice() const
DimSpec(DimVar var, DimExpr expr, SparseTensorDimSliceAttr slice)
constexpr DimVar getBoundVar() const
constexpr LvlExpr(AffineExpr expr)
static constexpr bool classof(DimLvlExpr const *expr)
static constexpr ExprKind Kind
std::optional< DimVar > dyn_castDimVar() const
DimVar castDimVar() const
The full lvlVar = lvlExpr : lvlType specification for a given level.
bool isValid(Ranks const &ranks) const
Checks whether the variables bound/used by this spec are valid with respect to the given ranks.
LvlSpec(LvlVar var, LvlExpr expr, LevelType type)
constexpr LvlExpr getExpr() const
constexpr bool canElideVar() const
MLIRContext * getContext() const
constexpr LvlVar getBoundVar() const
constexpr LevelType getType() const
constexpr unsigned getRank(VarKind vk) const
A concrete variable, to be used in our variant of AffineExpr.
VarKind
The three kinds of variables that Var can be.
constexpr VarKind getVarKindAllowedInExpr(ExprKind ek)
uint64_t Dimension
The type of dimension identifiers and dimension-ranks.
uint64_t Level
The type of level identifiers and level-ranks.
Include the generated interface declarations.
This enum defines all the sparse representations supportable by the SparseTensor dialect.