28 #ifndef MLIR_DIALECT_SPARSETENSOR_IR_ENUMS_H
29 #define MLIR_DIALECT_SPARSETENSOR_IR_ENUMS_H
40 namespace sparse_tensor {
62 #define MLIR_SPARSETENSOR_FOREVERY_FIXED_O(DO) \
70 #define MLIR_SPARSETENSOR_FOREVERY_O(DO) \
71 MLIR_SPARSETENSOR_FOREVERY_FIXED_O(DO) \
95 #define MLIR_SPARSETENSOR_FOREVERY_V(DO) \
108 #define MLIR_SPARSETENSOR_FOREVERY_V_VAR(DO, ...) \
109 DO(F64, double, __VA_ARGS__) \
110 DO(F32, float, __VA_ARGS__) \
111 DO(F16, f16, __VA_ARGS__) \
112 DO(BF16, bf16, __VA_ARGS__) \
113 DO(I64, int64_t, __VA_ARGS__) \
114 DO(I32, int32_t, __VA_ARGS__) \
115 DO(I16, int16_t, __VA_ARGS__) \
116 DO(I8, int8_t, __VA_ARGS__) \
117 DO(C64, complex64, __VA_ARGS__) \
118 DO(C32, complex32, __VA_ARGS__)
121 #define MLIR_SPARSETENSOR_FOREVERY_V_O(DO) \
122 MLIR_SPARSETENSOR_FOREVERY_V_VAR(DO, 64, uint64_t) \
123 MLIR_SPARSETENSOR_FOREVERY_V_VAR(DO, 32, uint32_t) \
124 MLIR_SPARSETENSOR_FOREVERY_V_VAR(DO, 16, uint16_t) \
125 MLIR_SPARSETENSOR_FOREVERY_V_VAR(DO, 8, uint8_t) \
126 MLIR_SPARSETENSOR_FOREVERY_V_VAR(DO, 0, index_type)
211 return "compressed(nonunique)";
213 return "compressed(nonordered)";
215 return "compressed(nonunique, nonordered)";
219 return "singleton(nonunique)";
221 return "singleton(nonordered)";
223 return "singleton(nonunique, nonordered)";
225 return "loose_compressed";
227 return "loose_compressed(nonunique)";
229 return "loose_compressed(nonordered)";
231 return "loose_compressed(nonunique, nonordered)";
240 const uint8_t formatBits =
static_cast<uint8_t
>(lt) >> 2;
241 const uint8_t propertyBits =
static_cast<uint8_t
>(lt) & 3;
244 return (formatBits <= 1 || formatBits == 16)
245 ? (propertyBits == 0)
246 : (formatBits == 2 || formatBits == 4 || formatBits == 8);
254 return (
static_cast<uint8_t
>(lt) & ~3) ==
260 return (
static_cast<uint8_t
>(lt) & ~3) ==
266 return (
static_cast<uint8_t
>(lt) & ~3) ==
272 return (
static_cast<uint8_t
>(lt) & ~3) ==
278 return (
static_cast<uint8_t
>(lt) & ~3) ==
295 return !(
static_cast<uint8_t
>(lt) & 2);
300 return !(
static_cast<uint8_t
>(lt) & 1);
308 return static_cast<LevelFormat>(
static_cast<uint8_t
>(lt) & ~3);
316 auto lt =
static_cast<LevelType>(
static_cast<uint8_t
>(lf) |
317 (ordered ? 0 : 2) | (unique ? 0 : 1));
318 return isValidLT(lt) ? std::optional(lt) : std::nullopt;
345 "getLevelFormat conversion is broken");
381 "buildLevelType conversion is broken");
395 "isValidLT definition is broken");
411 "isDenseLT definition is broken");
427 "isCompressedLT definition is broken");
443 "isSingletonLT definition is broken");
459 "isLooseCompressedLT definition is broken");
475 "is2OutOf4LT definition is broken");
491 "isOrderedLT definition is broken");
507 "isUniqueLT definition is broken");
531 constexpr uint64_t
encodeDim(uint64_t i, uint64_t cf, uint64_t cm) {
533 assert(cf <= 0xfffff && cm == 0 && i <= 0xfffff);
534 return (0x01ULL << 60) | (cf << 20) | i;
537 assert(cm <= 0xfffff && i <= 0xfffff);
538 return (0x02ULL << 60) | (cm << 20) | i;
540 assert(i <= 0x0fffffffffffffffu);
543 constexpr uint64_t
encodeLvl(uint64_t i, uint64_t c, uint64_t ii) {
545 assert(c <= 0xfffff && ii <= 0xfffff && i <= 0xfffff);
546 return (0x03ULL << 60) | (c << 20) | (ii << 40) | i;
548 assert(i <= 0x0fffffffffffffffu);
554 constexpr uint64_t
decodeIndex(uint64_t v) {
return v & 0xfffffu; }
555 constexpr uint64_t
decodeConst(uint64_t v) {
return (v >> 20) & 0xfffffu; }
556 constexpr uint64_t
decodeMulc(uint64_t v) {
return (v >> 20) & 0xfffffu; }
557 constexpr uint64_t
decodeMuli(uint64_t v) {
return (v >> 40) & 0xfffffu; }
std::complex< double > complex64
constexpr const char * toMLIRString(LevelType lt)
Returns string representation of the given dimension level type.
LevelPropertyNondefault
This enum defines all the nondefault properties for storage formats.
LevelFormat
This enum defines all supported storage format without the level properties.
constexpr uint64_t decodeMuli(uint64_t v)
constexpr bool isWithPosLT(LevelType lt)
Check if the LevelType needs positions array.
OverheadType
Encoding of overhead types (both position overhead and coordinate overhead), for "overloading" @newSp...
constexpr bool isLooseCompressedLT(LevelType lt)
Check if the LevelType is loose compressed (regardless of properties).
Action
The actions performed by @newSparseTensor.
constexpr bool isEncodedMul(uint64_t v)
constexpr bool isUniqueLT(LevelType lt)
Check if the LevelType is unique (regardless of storage format).
constexpr bool isIntegralPrimaryType(PrimaryType valTy)
constexpr bool isEncodedMod(uint64_t v)
constexpr uint64_t decodeConst(uint64_t v)
constexpr bool isUndefLT(LevelType lt)
Check if the LevelType is the special undefined value.
PrimaryType
Encoding of the elemental type, for "overloading" @newSparseTensor.
std::complex< float > complex32
constexpr bool isWithCrdLT(LevelType lt)
Check if the LevelType needs coordinates array.
constexpr uint64_t decodeIndex(uint64_t v)
constexpr bool is2OutOf4LT(LevelType lt)
Check if the LevelType is 2OutOf4 (regardless of properties).
constexpr bool isDenseLT(LevelType lt)
Check if the LevelType is dense (regardless of properties).
constexpr std::optional< LevelFormat > getLevelFormat(LevelType lt)
Convert a LevelType to its corresponding LevelFormat.
constexpr bool isSingletonLT(LevelType lt)
Check if the LevelType is singleton (regardless of properties).
constexpr bool isRealPrimaryType(PrimaryType valTy)
constexpr bool isOrderedLT(LevelType lt)
Check if the LevelType is ordered (regardless of storage format).
LevelType
This enum defines all the sparse representations supportable by the SparseTensor dialect.
uint64_t index_type
This type is used in the public API at all places where MLIR expects values with the built-in type "i...
constexpr bool isCompressedLT(LevelType lt)
Check if the LevelType is compressed (regardless of properties).
constexpr bool isComplexPrimaryType(PrimaryType valTy)
constexpr uint64_t encodeLvl(uint64_t i, uint64_t c, uint64_t ii)
constexpr uint64_t decodeMulc(uint64_t v)
constexpr bool isValidLT(LevelType lt)
Check that the LevelType contains a valid (possibly undefined) value.
constexpr uint64_t encodeDim(uint64_t i, uint64_t cf, uint64_t cm)
Bit manipulations for affine encoding.
constexpr std::optional< LevelType > buildLevelType(LevelFormat lf, bool ordered, bool unique)
Convert a LevelFormat to its corresponding LevelType with the given properties.
constexpr bool isFloatingPrimaryType(PrimaryType valTy)
constexpr bool isEncodedFloor(uint64_t v)
Include the generated interface declarations.