20 return SymVar(llvm::cast<AffineSymbolExpr>(expr));
24 if (
const auto s = dyn_cast_or_null<AffineSymbolExpr>(expr))
34 if (
const auto x = dyn_cast_or_null<AffineDimExpr>(expr))
39 std::tuple<DimLvlExpr, AffineExprKind, DimLvlExpr>
42 const auto binop = llvm::dyn_cast<AffineBinaryOpExpr>(expr);
43 const DimLvlExpr lhs(kind, binop ? binop.getLHS() :
nullptr);
44 const DimLvlExpr rhs(kind, binop ? binop.getRHS() :
nullptr);
45 return {lhs, ak, rhs};
53 : var(var), expr(expr), slice(slice) {}
66 : var(var), expr(expr), type(type) {
82 : symRank(symRank), dimSpecs(dimSpecs), lvlSpecs(lvlSpecs),
83 mustPrintLvlVars(false) {
90 for (
const auto &dimSpec : dimSpecs)
91 if (!dimSpec.canElideExpr())
92 usedVars.
add(dimSpec.getExpr());
93 for (
auto &lvlSpec : this->lvlSpecs) {
95 const bool isUsed = usedVars.
contains(lvlSpec.getBoundVar());
97 lvlSpec.setElideVar(!isUsed);
99 mustPrintLvlVars = mustPrintLvlVars || isUsed;
103 bool DimLvlMap::isWF()
const {
106 for (
const auto &dimSpec : dimSpecs)
107 if (dimSpec.getBoundVar().getNum() != dimNum++ || !dimSpec.isValid(ranks))
109 assert(dimNum == ranks.getDimRank());
111 for (
const auto &lvlSpec : lvlSpecs)
112 if (lvlSpec.getBoundVar().getNum() != lvlNum++ || !lvlSpec.isValid(ranks))
114 assert(lvlNum == ranks.getLvlRank());
121 for (
const auto &lvlSpec : lvlSpecs)
122 lvlAffines.push_back(lvlSpec.getExpr().getAffineExpr());
130 for (
const auto &dimSpec : dimSpecs) {
131 auto expr = dimSpec.getExpr().getAffineExpr();
133 dimAffines.push_back(expr);
139 if (dimAffines.empty())
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
static AffineMap get(MLIRContext *context)
Returns a zero result affine map with no dimensions or symbols: () -> ().
MLIRContext is the top-level object for a collection of MLIR operations.
SymVar castSymVar() const
std::optional< SymVar > dyn_castSymVar() const
AffineExprKind getAffineKind() const
Var castDimLvlVar() const
std::tuple< DimLvlExpr, AffineExprKind, DimLvlExpr > unpackBinop() const
constexpr VarKind getAllowedVarKind() const
std::optional< Var > dyn_castDimLvlVar() const
DimLvlMap(unsigned symRank, ArrayRef< DimSpec > dimSpecs, ArrayRef< LvlSpec > lvlSpecs)
AffineMap getDimToLvlMap(MLIRContext *context) const
unsigned getSymRank() const
unsigned getDimRank() const
AffineMap getLvlToDimMap(MLIRContext *context) const
unsigned getLvlRank() const
bool isValid(Ranks const &ranks) const
Checks whether the variables bound/used by this spec are valid with respect to the given ranks.
DimSpec(DimVar var, DimExpr expr, SparseTensorDimSliceAttr slice)
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 bool isValid(Var var) const
Efficient representation of a set of Var.
bool contains(Var var) const
For the contains method: if variables occurring in the method parameter are OOB for the VarSet,...
void add(Var var)
For the add methods: OOB parameters cause undefined behavior.
A concrete variable, to be used in our variant of AffineExpr.
bool isUndefLT(LevelType lt)
bool isValidLT(LevelType lt)
Include the generated interface declarations.
This enum defines all the sparse representations supportable by the SparseTensor dialect.