9#ifndef MLIR_DIALECT_SPARSETENSOR_IR_DETAIL_DIMLVLMAP_H
10#define MLIR_DIALECT_SPARSETENSOR_IR_DETAIL_DIMLVLMAP_H
15#include "llvm/ADT/STLForwardCompat.h"
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;
71 return expr.getKind();
74 return expr ? expr.getContext() :
nullptr;
84 std::tuple<DimLvlExpr, AffineExprKind, DimLvlExpr>
unpackBinop()
const;
103 return expr->getExprKind() ==
Kind;
110 return var ? std::make_optional(var->cast<
LvlVar>()) : std::nullopt;
122 return expr->getExprKind() ==
Kind;
129 return var ? std::make_optional(var->cast<
DimVar>()) : std::nullopt;
136 if constexpr (std::is_same_v<U, DimExpr>)
138 if constexpr (std::is_same_v<U, LvlExpr>)
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; }
201 bool elideVar =
false;
257 [[nodiscard]]
bool isWF()
const;
263 assert(expr &&
getRanks().isValid(expr));
264 dimSpecs[dim].setExpr(expr);
271 bool mustPrintLvlVars;
Base type for affine expression.
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
std::optional< LvlVar > dyn_castLvlVar() const
static constexpr bool classof(DimLvlExpr const *expr)
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
MLIRContext * tryGetContext() 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
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
const LvlSpec & getLvl(Level lvl) const
AffineMap getLvlToDimMap(MLIRContext *context) const
ArrayRef< DimSpec > getDims() const
const DimSpec & getDim(Dimension dim) const
unsigned getRank(VarKind vk) const
ArrayRef< LvlSpec > getLvls() const
unsigned getLvlRank() const
LevelType getLvlType(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.
MLIRContext * tryGetContext() const
void setExpr(DimExpr newExpr)
constexpr bool canElideExpr() 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)
std::optional< DimVar > dyn_castDimVar() const
static constexpr ExprKind Kind
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.
constexpr bool isWF(VarKind vk)
VarKind
The three kinds of variables that Var can be.
constexpr VarKind getVarKindAllowedInExpr(ExprKind ek)
static constexpr bool IsZeroCostAbstraction
Include the generated interface declarations.
This enum defines all the sparse representations supportable by the SparseTensor dialect.