9 #ifndef MLIR_DIALECT_SPARSETENSOR_IR_SPARSETENSOR_H_
10 #define MLIR_DIALECT_SPARSETENSOR_IR_SPARSETENSOR_H_
25 #include "llvm/ADT/bit.h"
36 namespace sparse_tensor {
81 operator uint64_t()
const {
return storage; }
85 storage |=
static_cast<uint64_t
>(0x01u) << i;
90 storage |=
static_cast<uint64_t
>(lhs);
95 storage = storage << offset;
108 if (prev >=
max() - 1)
111 uint64_t b = storage >> (prev +
static_cast<int64_t
>(1));
114 return llvm::countr_zero(b) + prev +
static_cast<int64_t
>(1);
119 return (storage & (
static_cast<int64_t
>(1) << i)) != 0;
122 unsigned m = llvm::countr_zero(storage);
123 return m == 64 ? -1 : m;
125 unsigned max()
const {
return 64 - llvm::countl_zero(storage); }
126 unsigned count()
const {
return llvm::popcount(storage); }
127 bool empty()
const {
return storage == 0; }
137 #define GET_ATTRDEF_CLASSES
138 #include "mlir/Dialect/SparseTensor/IR/SparseTensorAttrEnums.h.inc"
140 #define GET_ATTRDEF_CLASSES
141 #include "mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.h.inc"
143 #define GET_TYPEDEF_CLASSES
144 #include "mlir/Dialect/SparseTensor/IR/SparseTensorTypes.h.inc"
146 #define GET_OP_CLASSES
147 #include "mlir/Dialect/SparseTensor/IR/SparseTensorOps.h.inc"
149 #include "mlir/Dialect/SparseTensor/IR/SparseTensorOpsDialect.h.inc"
156 namespace sparse_tensor {
159 template <
typename T>
161 assert(
static_cast<bool>(std::forward<T>(t)) &&
162 "getRankedTensorType got null argument");
163 return dyn_cast<RankedTensorType>(std::forward<T>(t).
getType());
167 template <
typename T>
169 assert(
static_cast<bool>(std::forward<T>(t)) &&
170 "getMemRefType got null argument");
171 return cast<MemRefType>(std::forward<T>(t).
getType());
180 return llvm::any_of(types, [](
Type type) {
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.
type_range getTypes() const
Operation is the basic unit of execution within MLIR.
operand_range getOperands()
Returns an iterator on the underlying Value's.
result_range getResults()
type_range getTypes() const
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
A simple wrapper to encode a bitset of (at most 64) levels, currently used by sparse_tensor....
iterator_range< const_set_bits_iterator > bits() const
I64BitSet & lshift(unsigned offset)
bool isSubSetOf(const I64BitSet p) const
const_set_bits_iterator begin() const
int find_next(unsigned prev) const
I64BitSet & set(unsigned i)
bool operator[](unsigned i) const
const_set_bits_iterator end() const
I64BitSet & operator|=(I64BitSet lhs)
llvm::const_set_bits_iterator_impl< I64BitSet > const_set_bits_iterator
bool hasAnySparseOperandOrResult(Operation *op)
Returns true iff MLIR operand has any sparse operand or result.
Dimension toDim(SparseTensorEncodingAttr enc, Level l)
Convenience method to translate the given level to the corresponding dimension.
uint64_t Dimension
The type of dimension identifiers and dimension-ranks.
uint64_t Level
The type of level identifiers and level-ranks.
int64_t Size
The type for individual components of a compile-time shape, including the value ShapedType::kDynamic ...
RankedTensorType getRankedTensorType(T &&t)
Convenience method to abbreviate casting getType().
AffineMap inferLvlToDim(AffineMap dimToLvl, MLIRContext *context)
Given the dimToLvl map, infers the lvlToDim map, or returns empty Affine map when inference fails.
SparseTensorEncodingAttr getSparseTensorEncoding(Type type)
Convenience method to get a sparse encoding attribute from a type.
MemRefType getMemRefType(T &&t)
Convenience method to abbreviate casting getType().
bool hasAnySparseType(TypeRange types)
Returns true iff the type range has any sparse tensor type.
Level toLvl(SparseTensorEncodingAttr enc, Dimension d)
Convenience method to translate the given dimension to the corresponding level.
bool isBlockSparsity(AffineMap dimToLvl)
Given the dimToLvl map, returns if it's block sparsity.
bool hasAnyNonIdentityOperandsOrResults(Operation *op)
Returns true iff MLIR operation has any sparse tensor with non-identity dim2lvl maps.
bool hasAnySparseResult(Operation *op)
Returns true iff MLIR operand has any sparse result.
bool hasAnySparseOperand(Operation *op)
Returns true iff MLIR operand has any sparse operand.
SmallVector< unsigned > getBlockSize(AffineMap dimToLvl)
Given the dimToLvl map, returns the block sizes in a vector.
AffineMap inverseBlockSparsity(AffineMap dimToLvl, MLIRContext *context)
Returns the lvlToDim map for the given dimToLvl map specific to the block sparse cases.
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
A simple structure that encodes a range of levels in the sparse tensors that forms a COO segment.
bool inSegment(Level l) const
bool isSegmentStart(Level l) const
std::pair< Level, Level > lvlRange