Skip to content

[mlir][sparse] rename DimLevelType to LevelType #73561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2023
Merged

Conversation

aartbik
Copy link
Contributor

@aartbik aartbik commented Nov 27, 2023

The "Dim" prefix is a legacy left-over that no longer makes sense, since we have a very strict "Dimension" vs. "Level" definition for sparse tensor types and their storage.

The "Dim" prefix is a legacy left-over that no longer makes
sense, since we have a very strict "Dimension" vs. "Level"
definition for sparse tensor types and their storage.
@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2023

@llvm/pr-subscribers-mlir-execution-engine

@llvm/pr-subscribers-mlir

Author: Aart Bik (aartbik)

Changes

The "Dim" prefix is a legacy left-over that no longer makes sense, since we have a very strict "Dimension" vs. "Level" definition for sparse tensor types and their storage.


Patch is 105.82 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/73561.diff

38 Files Affected:

  • (modified) mlir/include/mlir-c/Dialect/SparseTensor.h (+18-18)
  • (modified) mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h (+195-198)
  • (modified) mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td (+5-5)
  • (modified) mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorStorageLayout.h (+3-3)
  • (modified) mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorType.h (+2-2)
  • (modified) mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h (+9-9)
  • (modified) mlir/include/mlir/ExecutionEngine/SparseTensor/File.h (+1-1)
  • (modified) mlir/include/mlir/ExecutionEngine/SparseTensor/Storage.h (+18-18)
  • (modified) mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h (+1-1)
  • (modified) mlir/lib/Bindings/Python/DialectSparseTensor.cpp (+17-17)
  • (modified) mlir/lib/CAPI/Dialect/SparseTensor.cpp (+24-25)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h (+4-4)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/Detail/LvlTypeParser.cpp (+2-2)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/Detail/LvlTypeParser.h (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp (+38-41)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.h (+2-2)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h (+2-2)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/LoopEmitter.cpp (+4-4)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/LoopEmitter.h (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp (+8-8)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorDescriptor.cpp (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp (+2-3)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp (+85-85)
  • (modified) mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp (+1-2)
  • (modified) mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp (+1-1)
  • (modified) mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp (+2-2)
  • (modified) mlir/test/CAPI/sparse_tensor.c (+2-2)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_conversion_element.mlir (+1-1)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_conversion_sparse2sparse.mlir (+2-2)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_SDDMM.py (+5-5)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_SpMM.py (+5-5)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_output.py (+8-8)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_stress.py (+1-1)
  • (modified) mlir/test/python/dialects/sparse_tensor/dialect.py (+2-2)
  • (modified) mlir/unittests/Dialect/SparseTensor/MergerTest.cpp (+17-17)
diff --git a/mlir/include/mlir-c/Dialect/SparseTensor.h b/mlir/include/mlir-c/Dialect/SparseTensor.h
index 859a4f0dd9f52c8..41d024db04964ef 100644
--- a/mlir/include/mlir-c/Dialect/SparseTensor.h
+++ b/mlir/include/mlir-c/Dialect/SparseTensor.h
@@ -22,24 +22,24 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(SparseTensor, sparse_tensor);
 /// Dimension level types (and properties) that define sparse tensors.
 /// See the documentation in SparseTensorAttrDefs.td for their meaning.
 ///
-/// These correspond to SparseTensorEncodingAttr::DimLevelType in the C++ API.
+/// These correspond to SparseTensorEncodingAttr::LevelType in the C++ API.
 /// If updating, keep them in sync and update the static_assert in the impl
 /// file.
-enum MlirSparseTensorDimLevelType {
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_DENSE = 4,                   // 0b00001_00
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED = 8,              // 0b00010_00
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NU = 9,           // 0b00010_01
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NO = 10,          // 0b00010_10
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NU_NO = 11,       // 0b00010_11
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON = 16,              // 0b00100_00
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NU = 17,           // 0b00100_01
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NO = 18,           // 0b00100_10
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NU_NO = 19,        // 0b00100_11
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED = 32,       // 0b01000_00
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED_NU = 33,    // 0b01000_01
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED_NO = 34,    // 0b01000_10
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED_NU_NO = 35, // 0b01000_11
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_TWO_OUT_OF_FOUR = 64,        // 0b10000_00
+enum MlirSparseTensorLevelType {
+  MLIR_SPARSE_TENSOR_LEVEL_DENSE = 4,                   // 0b00001_00
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED = 8,              // 0b00010_00
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU = 9,           // 0b00010_01
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NO = 10,          // 0b00010_10
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU_NO = 11,       // 0b00010_11
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON = 16,              // 0b00100_00
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU = 17,           // 0b00100_01
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NO = 18,           // 0b00100_10
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU_NO = 19,        // 0b00100_11
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED = 32,       // 0b01000_00
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU = 33,    // 0b01000_01
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NO = 34,    // 0b01000_10
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU_NO = 35, // 0b01000_11
+  MLIR_SPARSE_TENSOR_LEVEL_TWO_OUT_OF_FOUR = 64,        // 0b10000_00
 };
 
 //===----------------------------------------------------------------------===//
@@ -53,7 +53,7 @@ mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr);
 /// Creates a `sparse_tensor.encoding` attribute with the given parameters.
 MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet(
     MlirContext ctx, intptr_t lvlRank,
-    enum MlirSparseTensorDimLevelType const *lvlTypes, MlirAffineMap dimToLvl,
+    enum MlirSparseTensorLevelType const *lvlTypes, MlirAffineMap dimToLvl,
     MlirAffineMap lvlTodim, int posWidth, int crdWidth);
 
 /// Returns the level-rank of the `sparse_tensor.encoding` attribute.
@@ -61,7 +61,7 @@ MLIR_CAPI_EXPORTED intptr_t
 mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr);
 
 /// Returns a specified level-type of the `sparse_tensor.encoding` attribute.
-MLIR_CAPI_EXPORTED enum MlirSparseTensorDimLevelType
+MLIR_CAPI_EXPORTED enum MlirSparseTensorLevelType
 mlirSparseTensorEncodingAttrGetLvlType(MlirAttribute attr, intptr_t lvl);
 
 /// Returns the dimension-to-level mapping of the `sparse_tensor.encoding`
diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
index 5f9c271b398dedb..9af42f00f91ed4e 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
@@ -10,7 +10,7 @@
 // IR, and the lightweight runtime support library for sparse tensor
 // manipulations.  That is, all the enums are used to define the API
 // of the runtime library and hence are also needed when generating
-// calls into the runtime library.  Moveover, the `DimLevelType` enum
+// calls into the runtime library.  Moveover, the `LevelType` enum
 // is also used as the internal IR encoding of dimension level types,
 // to avoid code duplication (e.g., for the predicates).
 //
@@ -162,10 +162,10 @@ enum class Action : uint32_t {
 /// about the particular binary encoding.
 ///
 /// The `Undef` "format" is a special value used internally for cases
-/// where we need to store an undefined or indeterminate `DimLevelType`.
+/// where we need to store an undefined or indeterminate `LevelType`.
 /// It should not be used externally, since it does not indicate an
 /// actual/representable format.
-enum class DimLevelType : uint8_t {
+enum class LevelType : uint8_t {
   Undef = 0,                // 0b00000_00
   Dense = 4,                // 0b00001_00
   Compressed = 8,           // 0b00010_00
@@ -199,44 +199,44 @@ enum class LevelPropertyNondefault : uint8_t {
 };
 
 /// Returns string representation of the given dimension level type.
-constexpr const char *toMLIRString(DimLevelType lt) {
+constexpr const char *toMLIRString(LevelType lt) {
   switch (lt) {
-  case DimLevelType::Undef:
+  case LevelType::Undef:
     return "undef";
-  case DimLevelType::Dense:
+  case LevelType::Dense:
     return "dense";
-  case DimLevelType::Compressed:
+  case LevelType::Compressed:
     return "compressed";
-  case DimLevelType::CompressedNu:
+  case LevelType::CompressedNu:
     return "compressed(nonunique)";
-  case DimLevelType::CompressedNo:
+  case LevelType::CompressedNo:
     return "compressed(nonordered)";
-  case DimLevelType::CompressedNuNo:
+  case LevelType::CompressedNuNo:
     return "compressed(nonunique, nonordered)";
-  case DimLevelType::Singleton:
+  case LevelType::Singleton:
     return "singleton";
-  case DimLevelType::SingletonNu:
+  case LevelType::SingletonNu:
     return "singleton(nonunique)";
-  case DimLevelType::SingletonNo:
+  case LevelType::SingletonNo:
     return "singleton(nonordered)";
-  case DimLevelType::SingletonNuNo:
+  case LevelType::SingletonNuNo:
     return "singleton(nonunique, nonordered)";
-  case DimLevelType::LooseCompressed:
+  case LevelType::LooseCompressed:
     return "loose_compressed";
-  case DimLevelType::LooseCompressedNu:
+  case LevelType::LooseCompressedNu:
     return "loose_compressed(nonunique)";
-  case DimLevelType::LooseCompressedNo:
+  case LevelType::LooseCompressedNo:
     return "loose_compressed(nonordered)";
-  case DimLevelType::LooseCompressedNuNo:
+  case LevelType::LooseCompressedNuNo:
     return "loose_compressed(nonunique, nonordered)";
-  case DimLevelType::TwoOutOfFour:
+  case LevelType::TwoOutOfFour:
     return "block2_4";
   }
   return "";
 }
 
-/// Check that the `DimLevelType` contains a valid (possibly undefined) value.
-constexpr bool isValidLT(DimLevelType lt) {
+/// Check that the `LevelType` contains a valid (possibly undefined) value.
+constexpr bool isValidLT(LevelType lt) {
   const uint8_t formatBits = static_cast<uint8_t>(lt) >> 2;
   const uint8_t propertyBits = static_cast<uint8_t>(lt) & 3;
   // If undefined or dense, then must be unique and ordered.
@@ -246,75 +246,75 @@ constexpr bool isValidLT(DimLevelType lt) {
              : (formatBits == 2 || formatBits == 4 || formatBits == 8);
 }
 
-/// Check if the `DimLevelType` is the special undefined value.
-constexpr bool isUndefLT(DimLevelType lt) { return lt == DimLevelType::Undef; }
+/// Check if the `LevelType` is the special undefined value.
+constexpr bool isUndefLT(LevelType lt) { return lt == LevelType::Undef; }
 
-/// Check if the `DimLevelType` is dense (regardless of properties).
-constexpr bool isDenseLT(DimLevelType lt) {
+/// Check if the `LevelType` is dense (regardless of properties).
+constexpr bool isDenseLT(LevelType lt) {
   return (static_cast<uint8_t>(lt) & ~3) ==
-         static_cast<uint8_t>(DimLevelType::Dense);
+         static_cast<uint8_t>(LevelType::Dense);
 }
 
-/// Check if the `DimLevelType` is compressed (regardless of properties).
-constexpr bool isCompressedLT(DimLevelType lt) {
+/// Check if the `LevelType` is compressed (regardless of properties).
+constexpr bool isCompressedLT(LevelType lt) {
   return (static_cast<uint8_t>(lt) & ~3) ==
-         static_cast<uint8_t>(DimLevelType::Compressed);
+         static_cast<uint8_t>(LevelType::Compressed);
 }
 
-/// Check if the `DimLevelType` is singleton (regardless of properties).
-constexpr bool isSingletonLT(DimLevelType lt) {
+/// Check if the `LevelType` is singleton (regardless of properties).
+constexpr bool isSingletonLT(LevelType lt) {
   return (static_cast<uint8_t>(lt) & ~3) ==
-         static_cast<uint8_t>(DimLevelType::Singleton);
+         static_cast<uint8_t>(LevelType::Singleton);
 }
 
-/// Check if the `DimLevelType` is loose compressed (regardless of properties).
-constexpr bool isLooseCompressedLT(DimLevelType lt) {
+/// Check if the `LevelType` is loose compressed (regardless of properties).
+constexpr bool isLooseCompressedLT(LevelType lt) {
   return (static_cast<uint8_t>(lt) & ~3) ==
-         static_cast<uint8_t>(DimLevelType::LooseCompressed);
+         static_cast<uint8_t>(LevelType::LooseCompressed);
 }
 
-/// Check if the `DimLevelType` is 2OutOf4 (regardless of properties).
-constexpr bool is2OutOf4LT(DimLevelType lt) {
+/// Check if the `LevelType` is 2OutOf4 (regardless of properties).
+constexpr bool is2OutOf4LT(LevelType lt) {
   return (static_cast<uint8_t>(lt) & ~3) ==
-         static_cast<uint8_t>(DimLevelType::TwoOutOfFour);
+         static_cast<uint8_t>(LevelType::TwoOutOfFour);
 }
 
-/// Check if the `DimLevelType` needs positions array.
-constexpr bool isWithPosLT(DimLevelType lt) {
+/// Check if the `LevelType` needs positions array.
+constexpr bool isWithPosLT(LevelType lt) {
   return isCompressedLT(lt) || isLooseCompressedLT(lt);
 }
 
-/// Check if the `DimLevelType` needs coordinates array.
-constexpr bool isWithCrdLT(DimLevelType lt) {
+/// Check if the `LevelType` needs coordinates array.
+constexpr bool isWithCrdLT(LevelType lt) {
   return isCompressedLT(lt) || isSingletonLT(lt) || isLooseCompressedLT(lt) ||
          is2OutOf4LT(lt);
 }
 
-/// Check if the `DimLevelType` is ordered (regardless of storage format).
-constexpr bool isOrderedLT(DimLevelType lt) {
+/// Check if the `LevelType` is ordered (regardless of storage format).
+constexpr bool isOrderedLT(LevelType lt) {
   return !(static_cast<uint8_t>(lt) & 2);
 }
 
-/// Check if the `DimLevelType` is unique (regardless of storage format).
-constexpr bool isUniqueLT(DimLevelType lt) {
+/// Check if the `LevelType` is unique (regardless of storage format).
+constexpr bool isUniqueLT(LevelType lt) {
   return !(static_cast<uint8_t>(lt) & 1);
 }
 
-/// Convert a DimLevelType to its corresponding LevelFormat.
+/// Convert a LevelType to its corresponding LevelFormat.
 /// Returns std::nullopt when input lt is Undef.
-constexpr std::optional<LevelFormat> getLevelFormat(DimLevelType lt) {
-  if (lt == DimLevelType::Undef)
+constexpr std::optional<LevelFormat> getLevelFormat(LevelType lt) {
+  if (lt == LevelType::Undef)
     return std::nullopt;
   return static_cast<LevelFormat>(static_cast<uint8_t>(lt) & ~3);
 }
 
-/// Convert a LevelFormat to its corresponding DimLevelType with the given
+/// Convert a LevelFormat to its corresponding LevelType with the given
 /// properties. Returns std::nullopt when the properties are not applicable
 /// for the input level format.
-constexpr std::optional<DimLevelType>
-buildLevelType(LevelFormat lf, bool ordered, bool unique) {
-  auto lt = static_cast<DimLevelType>(static_cast<uint8_t>(lf) |
-                                      (ordered ? 0 : 2) | (unique ? 0 : 1));
+constexpr std::optional<LevelType> buildLevelType(LevelFormat lf, bool ordered,
+                                                  bool unique) {
+  auto lt = static_cast<LevelType>(static_cast<uint8_t>(lf) |
+                                   (ordered ? 0 : 2) | (unique ? 0 : 1));
   return isValidLT(lt) ? std::optional(lt) : std::nullopt;
 }
 
@@ -323,190 +323,187 @@ buildLevelType(LevelFormat lf, bool ordered, bool unique) {
 //
 
 static_assert(
-    (getLevelFormat(DimLevelType::Undef) == std::nullopt &&
-     *getLevelFormat(DimLevelType::Dense) == LevelFormat::Dense &&
-     *getLevelFormat(DimLevelType::Compressed) == LevelFormat::Compressed &&
-     *getLevelFormat(DimLevelType::CompressedNu) == LevelFormat::Compressed &&
-     *getLevelFormat(DimLevelType::CompressedNo) == LevelFormat::Compressed &&
-     *getLevelFormat(DimLevelType::CompressedNuNo) == LevelFormat::Compressed &&
-     *getLevelFormat(DimLevelType::Singleton) == LevelFormat::Singleton &&
-     *getLevelFormat(DimLevelType::SingletonNu) == LevelFormat::Singleton &&
-     *getLevelFormat(DimLevelType::SingletonNo) == LevelFormat::Singleton &&
-     *getLevelFormat(DimLevelType::SingletonNuNo) == LevelFormat::Singleton &&
-     *getLevelFormat(DimLevelType::LooseCompressed) ==
+    (getLevelFormat(LevelType::Undef) == std::nullopt &&
+     *getLevelFormat(LevelType::Dense) == LevelFormat::Dense &&
+     *getLevelFormat(LevelType::Compressed) == LevelFormat::Compressed &&
+     *getLevelFormat(LevelType::CompressedNu) == LevelFormat::Compressed &&
+     *getLevelFormat(LevelType::CompressedNo) == LevelFormat::Compressed &&
+     *getLevelFormat(LevelType::CompressedNuNo) == LevelFormat::Compressed &&
+     *getLevelFormat(LevelType::Singleton) == LevelFormat::Singleton &&
+     *getLevelFormat(LevelType::SingletonNu) == LevelFormat::Singleton &&
+     *getLevelFormat(LevelType::SingletonNo) == LevelFormat::Singleton &&
+     *getLevelFormat(LevelType::SingletonNuNo) == LevelFormat::Singleton &&
+     *getLevelFormat(LevelType::LooseCompressed) ==
          LevelFormat::LooseCompressed &&
-     *getLevelFormat(DimLevelType::LooseCompressedNu) ==
+     *getLevelFormat(LevelType::LooseCompressedNu) ==
          LevelFormat::LooseCompressed &&
-     *getLevelFormat(DimLevelType::LooseCompressedNo) ==
+     *getLevelFormat(LevelType::LooseCompressedNo) ==
          LevelFormat::LooseCompressed &&
-     *getLevelFormat(DimLevelType::LooseCompressedNuNo) ==
+     *getLevelFormat(LevelType::LooseCompressedNuNo) ==
          LevelFormat::LooseCompressed &&
-     *getLevelFormat(DimLevelType::TwoOutOfFour) == LevelFormat::TwoOutOfFour),
+     *getLevelFormat(LevelType::TwoOutOfFour) == LevelFormat::TwoOutOfFour),
     "getLevelFormat conversion is broken");
 
 static_assert(
     (buildLevelType(LevelFormat::Dense, false, true) == std::nullopt &&
      buildLevelType(LevelFormat::Dense, true, false) == std::nullopt &&
      buildLevelType(LevelFormat::Dense, false, false) == std::nullopt &&
-     *buildLevelType(LevelFormat::Dense, true, true) == DimLevelType::Dense &&
+     *buildLevelType(LevelFormat::Dense, true, true) == LevelType::Dense &&
      *buildLevelType(LevelFormat::Compressed, true, true) ==
-         DimLevelType::Compressed &&
+         LevelType::Compressed &&
      *buildLevelType(LevelFormat::Compressed, true, false) ==
-         DimLevelType::CompressedNu &&
+         LevelType::CompressedNu &&
      *buildLevelType(LevelFormat::Compressed, false, true) ==
-         DimLevelType::CompressedNo &&
+         LevelType::CompressedNo &&
      *buildLevelType(LevelFormat::Compressed, false, false) ==
-         DimLevelType::CompressedNuNo &&
+         LevelType::CompressedNuNo &&
      *buildLevelType(LevelFormat::Singleton, true, true) ==
-         DimLevelType::Singleton &&
+         LevelType::Singleton &&
      *buildLevelType(LevelFormat::Singleton, true, false) ==
-         DimLevelType::SingletonNu &&
+         LevelType::SingletonNu &&
      *buildLevelType(LevelFormat::Singleton, false, true) ==
-         DimLevelType::SingletonNo &&
+         LevelType::SingletonNo &&
      *buildLevelType(LevelFormat::Singleton, false, false) ==
-         DimLevelType::SingletonNuNo &&
+         LevelType::SingletonNuNo &&
      *buildLevelType(LevelFormat::LooseCompressed, true, true) ==
-         DimLevelType::LooseCompressed &&
+         LevelType::LooseCompressed &&
      *buildLevelType(LevelFormat::LooseCompressed, true, false) ==
-         DimLevelType::LooseCompressedNu &&
+         LevelType::LooseCompressedNu &&
      *buildLevelType(LevelFormat::LooseCompressed, false, true) ==
-         DimLevelType::LooseCompressedNo &&
+         LevelType::LooseCompressedNo &&
      *buildLevelType(LevelFormat::LooseCompressed, false, false) ==
-         DimLevelType::LooseCompressedNuNo &&
+         LevelType::LooseCompressedNuNo &&
      buildLevelType(LevelFormat::TwoOutOfFour, false, true) == std::nullopt &&
      buildLevelType(LevelFormat::TwoOutOfFour, true, false) == std::nullopt &&
      buildLevelType(LevelFormat::TwoOutOfFour, false, false) == std::nullopt &&
      *buildLevelType(LevelFormat::TwoOutOfFour, true, true) ==
-         DimLevelType::TwoOutOfFour),
+         LevelType::TwoOutOfFour),
     "buildLevelType conversion is broken");
 
-static_assert((isValidLT(DimLevelType::Undef) &&
-               isValidLT(DimLevelType::Dense) &&
-               isValidLT(DimLevelType::Compressed) &&
-               isValidLT(DimLevelType::CompressedNu) &&
-               isValidLT(DimLevelType::CompressedNo) &&
-               isValidLT(DimLevelType::CompressedNuNo) &&
-               isValidLT(DimLevelType::Singleton) &&
-               isValidLT(DimLevelType::SingletonNu) &&
-               isValidLT(DimLevelType::SingletonNo) &&
-               isValidLT(DimLevelType::SingletonNuNo) &&
-               isValidLT(DimLevelType::LooseCompressed) &&
-               isValidLT(DimLevelType::LooseCompressedNu) &&
-               isValidLT(DimLevelType::LooseCompressedNo) &&
-               isValidLT(DimLevelType::LooseCompressedNuNo) &&
-               isValidLT(DimLevelType::TwoOutOfFour)),
-              "isValidLT definition is broken");
-
-static_assert((isDenseLT(DimLevelType::Dense) &&
-               !isDenseLT(DimLevelType::Compressed) &&
-               !isDenseLT(DimLevelType::CompressedNu) &&
-               !isDenseLT(DimLevelType::CompressedNo) &&
-               !isDenseLT(DimLevelType::CompressedNuNo) &&
-               !isDenseLT(DimLevelType::Singleton) &&
-               !isDenseLT(DimLevelType::SingletonNu) &&
-               !isDenseLT(DimLevelType::SingletonNo) &&
-               !isDenseLT(DimLevelType::SingletonNuNo) &&
-               !isDenseLT(DimLevelType::LooseCompressed) &&
-               !isDenseLT(DimLevelType::LooseCompressedNu) &&
-               !isDenseLT(DimLevelType::LooseCompressedNo) &&
-               !isDenseLT(DimLevelType::LooseCompressedNuNo) &&
-               !isDenseLT(DimLevelType::TwoOutOfFour)),
+static_assert(
+    (isValidLT(LevelType::Undef) && isValidLT(LevelType::Dense) &&
+     isValidLT(LevelType::Compressed) && isValidLT(LevelType::CompressedNu) &&
+     isValidLT(LevelType::CompressedNo) &&
+     isValidLT(LevelType::CompressedNuNo) && isValidLT(LevelType::Singleton) &&
+     isValidLT(LevelType::SingletonNu) && isValidLT(LevelType::SingletonNo) &&
+     isValidLT(LevelType::SingletonNuNo) &&
+     isValidLT(LevelType::LooseCompressed) &&
+     isValidLT(LevelType::LooseCompressedNu) &&
+     isValidLT(LevelType::LooseCompressedNo) &&
+     isValidLT(LevelType::LooseCompressedNuNo) &&
+     isValidLT(LevelType::TwoOutOfFour)),
+    "isValidLT definition is broken");
+
+static_assert((isDenseLT(LevelType::Dense) &&
+               !isDenseLT(LevelType::Compressed) &&
+               !isDenseLT(LevelType::CompressedNu) &&
+               !isDenseLT(LevelType::CompressedNo) &&
+               !isDenseLT(LevelType::CompressedNuNo) &&
+               !isDenseLT(LevelType::Singleton) &&
+               !isDenseLT(LevelType::SingletonNu) &&
+               !isDenseLT(LevelType::SingletonNo) &&
+               !isDenseLT(LevelType::SingletonNuNo) &&
+               !isDenseLT(LevelType::LooseCompressed) &&
...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2023

@llvm/pr-subscribers-mlir-sparse

Author: Aart Bik (aartbik)

Changes

The "Dim" prefix is a legacy left-over that no longer makes sense, since we have a very strict "Dimension" vs. "Level" definition for sparse tensor types and their storage.


Patch is 105.82 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/73561.diff

38 Files Affected:

  • (modified) mlir/include/mlir-c/Dialect/SparseTensor.h (+18-18)
  • (modified) mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h (+195-198)
  • (modified) mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td (+5-5)
  • (modified) mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorStorageLayout.h (+3-3)
  • (modified) mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorType.h (+2-2)
  • (modified) mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h (+9-9)
  • (modified) mlir/include/mlir/ExecutionEngine/SparseTensor/File.h (+1-1)
  • (modified) mlir/include/mlir/ExecutionEngine/SparseTensor/Storage.h (+18-18)
  • (modified) mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h (+1-1)
  • (modified) mlir/lib/Bindings/Python/DialectSparseTensor.cpp (+17-17)
  • (modified) mlir/lib/CAPI/Dialect/SparseTensor.cpp (+24-25)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.h (+4-4)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMapParser.cpp (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/Detail/LvlTypeParser.cpp (+2-2)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/Detail/LvlTypeParser.h (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp (+38-41)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.h (+2-2)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h (+2-2)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/LoopEmitter.cpp (+4-4)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/LoopEmitter.h (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp (+8-8)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorDescriptor.cpp (+1-1)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp (+2-3)
  • (modified) mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp (+85-85)
  • (modified) mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp (+1-2)
  • (modified) mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp (+1-1)
  • (modified) mlir/lib/ExecutionEngine/SparseTensorRuntime.cpp (+2-2)
  • (modified) mlir/test/CAPI/sparse_tensor.c (+2-2)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_conversion_element.mlir (+1-1)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_conversion_sparse2sparse.mlir (+2-2)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_SDDMM.py (+5-5)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_SpMM.py (+5-5)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_output.py (+8-8)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_stress.py (+1-1)
  • (modified) mlir/test/python/dialects/sparse_tensor/dialect.py (+2-2)
  • (modified) mlir/unittests/Dialect/SparseTensor/MergerTest.cpp (+17-17)
diff --git a/mlir/include/mlir-c/Dialect/SparseTensor.h b/mlir/include/mlir-c/Dialect/SparseTensor.h
index 859a4f0dd9f52c8..41d024db04964ef 100644
--- a/mlir/include/mlir-c/Dialect/SparseTensor.h
+++ b/mlir/include/mlir-c/Dialect/SparseTensor.h
@@ -22,24 +22,24 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(SparseTensor, sparse_tensor);
 /// Dimension level types (and properties) that define sparse tensors.
 /// See the documentation in SparseTensorAttrDefs.td for their meaning.
 ///
-/// These correspond to SparseTensorEncodingAttr::DimLevelType in the C++ API.
+/// These correspond to SparseTensorEncodingAttr::LevelType in the C++ API.
 /// If updating, keep them in sync and update the static_assert in the impl
 /// file.
-enum MlirSparseTensorDimLevelType {
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_DENSE = 4,                   // 0b00001_00
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED = 8,              // 0b00010_00
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NU = 9,           // 0b00010_01
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NO = 10,          // 0b00010_10
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NU_NO = 11,       // 0b00010_11
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON = 16,              // 0b00100_00
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NU = 17,           // 0b00100_01
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NO = 18,           // 0b00100_10
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NU_NO = 19,        // 0b00100_11
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED = 32,       // 0b01000_00
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED_NU = 33,    // 0b01000_01
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED_NO = 34,    // 0b01000_10
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED_NU_NO = 35, // 0b01000_11
-  MLIR_SPARSE_TENSOR_DIM_LEVEL_TWO_OUT_OF_FOUR = 64,        // 0b10000_00
+enum MlirSparseTensorLevelType {
+  MLIR_SPARSE_TENSOR_LEVEL_DENSE = 4,                   // 0b00001_00
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED = 8,              // 0b00010_00
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU = 9,           // 0b00010_01
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NO = 10,          // 0b00010_10
+  MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU_NO = 11,       // 0b00010_11
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON = 16,              // 0b00100_00
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU = 17,           // 0b00100_01
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NO = 18,           // 0b00100_10
+  MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU_NO = 19,        // 0b00100_11
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED = 32,       // 0b01000_00
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU = 33,    // 0b01000_01
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NO = 34,    // 0b01000_10
+  MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU_NO = 35, // 0b01000_11
+  MLIR_SPARSE_TENSOR_LEVEL_TWO_OUT_OF_FOUR = 64,        // 0b10000_00
 };
 
 //===----------------------------------------------------------------------===//
@@ -53,7 +53,7 @@ mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr);
 /// Creates a `sparse_tensor.encoding` attribute with the given parameters.
 MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet(
     MlirContext ctx, intptr_t lvlRank,
-    enum MlirSparseTensorDimLevelType const *lvlTypes, MlirAffineMap dimToLvl,
+    enum MlirSparseTensorLevelType const *lvlTypes, MlirAffineMap dimToLvl,
     MlirAffineMap lvlTodim, int posWidth, int crdWidth);
 
 /// Returns the level-rank of the `sparse_tensor.encoding` attribute.
@@ -61,7 +61,7 @@ MLIR_CAPI_EXPORTED intptr_t
 mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr);
 
 /// Returns a specified level-type of the `sparse_tensor.encoding` attribute.
-MLIR_CAPI_EXPORTED enum MlirSparseTensorDimLevelType
+MLIR_CAPI_EXPORTED enum MlirSparseTensorLevelType
 mlirSparseTensorEncodingAttrGetLvlType(MlirAttribute attr, intptr_t lvl);
 
 /// Returns the dimension-to-level mapping of the `sparse_tensor.encoding`
diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
index 5f9c271b398dedb..9af42f00f91ed4e 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
@@ -10,7 +10,7 @@
 // IR, and the lightweight runtime support library for sparse tensor
 // manipulations.  That is, all the enums are used to define the API
 // of the runtime library and hence are also needed when generating
-// calls into the runtime library.  Moveover, the `DimLevelType` enum
+// calls into the runtime library.  Moveover, the `LevelType` enum
 // is also used as the internal IR encoding of dimension level types,
 // to avoid code duplication (e.g., for the predicates).
 //
@@ -162,10 +162,10 @@ enum class Action : uint32_t {
 /// about the particular binary encoding.
 ///
 /// The `Undef` "format" is a special value used internally for cases
-/// where we need to store an undefined or indeterminate `DimLevelType`.
+/// where we need to store an undefined or indeterminate `LevelType`.
 /// It should not be used externally, since it does not indicate an
 /// actual/representable format.
-enum class DimLevelType : uint8_t {
+enum class LevelType : uint8_t {
   Undef = 0,                // 0b00000_00
   Dense = 4,                // 0b00001_00
   Compressed = 8,           // 0b00010_00
@@ -199,44 +199,44 @@ enum class LevelPropertyNondefault : uint8_t {
 };
 
 /// Returns string representation of the given dimension level type.
-constexpr const char *toMLIRString(DimLevelType lt) {
+constexpr const char *toMLIRString(LevelType lt) {
   switch (lt) {
-  case DimLevelType::Undef:
+  case LevelType::Undef:
     return "undef";
-  case DimLevelType::Dense:
+  case LevelType::Dense:
     return "dense";
-  case DimLevelType::Compressed:
+  case LevelType::Compressed:
     return "compressed";
-  case DimLevelType::CompressedNu:
+  case LevelType::CompressedNu:
     return "compressed(nonunique)";
-  case DimLevelType::CompressedNo:
+  case LevelType::CompressedNo:
     return "compressed(nonordered)";
-  case DimLevelType::CompressedNuNo:
+  case LevelType::CompressedNuNo:
     return "compressed(nonunique, nonordered)";
-  case DimLevelType::Singleton:
+  case LevelType::Singleton:
     return "singleton";
-  case DimLevelType::SingletonNu:
+  case LevelType::SingletonNu:
     return "singleton(nonunique)";
-  case DimLevelType::SingletonNo:
+  case LevelType::SingletonNo:
     return "singleton(nonordered)";
-  case DimLevelType::SingletonNuNo:
+  case LevelType::SingletonNuNo:
     return "singleton(nonunique, nonordered)";
-  case DimLevelType::LooseCompressed:
+  case LevelType::LooseCompressed:
     return "loose_compressed";
-  case DimLevelType::LooseCompressedNu:
+  case LevelType::LooseCompressedNu:
     return "loose_compressed(nonunique)";
-  case DimLevelType::LooseCompressedNo:
+  case LevelType::LooseCompressedNo:
     return "loose_compressed(nonordered)";
-  case DimLevelType::LooseCompressedNuNo:
+  case LevelType::LooseCompressedNuNo:
     return "loose_compressed(nonunique, nonordered)";
-  case DimLevelType::TwoOutOfFour:
+  case LevelType::TwoOutOfFour:
     return "block2_4";
   }
   return "";
 }
 
-/// Check that the `DimLevelType` contains a valid (possibly undefined) value.
-constexpr bool isValidLT(DimLevelType lt) {
+/// Check that the `LevelType` contains a valid (possibly undefined) value.
+constexpr bool isValidLT(LevelType lt) {
   const uint8_t formatBits = static_cast<uint8_t>(lt) >> 2;
   const uint8_t propertyBits = static_cast<uint8_t>(lt) & 3;
   // If undefined or dense, then must be unique and ordered.
@@ -246,75 +246,75 @@ constexpr bool isValidLT(DimLevelType lt) {
              : (formatBits == 2 || formatBits == 4 || formatBits == 8);
 }
 
-/// Check if the `DimLevelType` is the special undefined value.
-constexpr bool isUndefLT(DimLevelType lt) { return lt == DimLevelType::Undef; }
+/// Check if the `LevelType` is the special undefined value.
+constexpr bool isUndefLT(LevelType lt) { return lt == LevelType::Undef; }
 
-/// Check if the `DimLevelType` is dense (regardless of properties).
-constexpr bool isDenseLT(DimLevelType lt) {
+/// Check if the `LevelType` is dense (regardless of properties).
+constexpr bool isDenseLT(LevelType lt) {
   return (static_cast<uint8_t>(lt) & ~3) ==
-         static_cast<uint8_t>(DimLevelType::Dense);
+         static_cast<uint8_t>(LevelType::Dense);
 }
 
-/// Check if the `DimLevelType` is compressed (regardless of properties).
-constexpr bool isCompressedLT(DimLevelType lt) {
+/// Check if the `LevelType` is compressed (regardless of properties).
+constexpr bool isCompressedLT(LevelType lt) {
   return (static_cast<uint8_t>(lt) & ~3) ==
-         static_cast<uint8_t>(DimLevelType::Compressed);
+         static_cast<uint8_t>(LevelType::Compressed);
 }
 
-/// Check if the `DimLevelType` is singleton (regardless of properties).
-constexpr bool isSingletonLT(DimLevelType lt) {
+/// Check if the `LevelType` is singleton (regardless of properties).
+constexpr bool isSingletonLT(LevelType lt) {
   return (static_cast<uint8_t>(lt) & ~3) ==
-         static_cast<uint8_t>(DimLevelType::Singleton);
+         static_cast<uint8_t>(LevelType::Singleton);
 }
 
-/// Check if the `DimLevelType` is loose compressed (regardless of properties).
-constexpr bool isLooseCompressedLT(DimLevelType lt) {
+/// Check if the `LevelType` is loose compressed (regardless of properties).
+constexpr bool isLooseCompressedLT(LevelType lt) {
   return (static_cast<uint8_t>(lt) & ~3) ==
-         static_cast<uint8_t>(DimLevelType::LooseCompressed);
+         static_cast<uint8_t>(LevelType::LooseCompressed);
 }
 
-/// Check if the `DimLevelType` is 2OutOf4 (regardless of properties).
-constexpr bool is2OutOf4LT(DimLevelType lt) {
+/// Check if the `LevelType` is 2OutOf4 (regardless of properties).
+constexpr bool is2OutOf4LT(LevelType lt) {
   return (static_cast<uint8_t>(lt) & ~3) ==
-         static_cast<uint8_t>(DimLevelType::TwoOutOfFour);
+         static_cast<uint8_t>(LevelType::TwoOutOfFour);
 }
 
-/// Check if the `DimLevelType` needs positions array.
-constexpr bool isWithPosLT(DimLevelType lt) {
+/// Check if the `LevelType` needs positions array.
+constexpr bool isWithPosLT(LevelType lt) {
   return isCompressedLT(lt) || isLooseCompressedLT(lt);
 }
 
-/// Check if the `DimLevelType` needs coordinates array.
-constexpr bool isWithCrdLT(DimLevelType lt) {
+/// Check if the `LevelType` needs coordinates array.
+constexpr bool isWithCrdLT(LevelType lt) {
   return isCompressedLT(lt) || isSingletonLT(lt) || isLooseCompressedLT(lt) ||
          is2OutOf4LT(lt);
 }
 
-/// Check if the `DimLevelType` is ordered (regardless of storage format).
-constexpr bool isOrderedLT(DimLevelType lt) {
+/// Check if the `LevelType` is ordered (regardless of storage format).
+constexpr bool isOrderedLT(LevelType lt) {
   return !(static_cast<uint8_t>(lt) & 2);
 }
 
-/// Check if the `DimLevelType` is unique (regardless of storage format).
-constexpr bool isUniqueLT(DimLevelType lt) {
+/// Check if the `LevelType` is unique (regardless of storage format).
+constexpr bool isUniqueLT(LevelType lt) {
   return !(static_cast<uint8_t>(lt) & 1);
 }
 
-/// Convert a DimLevelType to its corresponding LevelFormat.
+/// Convert a LevelType to its corresponding LevelFormat.
 /// Returns std::nullopt when input lt is Undef.
-constexpr std::optional<LevelFormat> getLevelFormat(DimLevelType lt) {
-  if (lt == DimLevelType::Undef)
+constexpr std::optional<LevelFormat> getLevelFormat(LevelType lt) {
+  if (lt == LevelType::Undef)
     return std::nullopt;
   return static_cast<LevelFormat>(static_cast<uint8_t>(lt) & ~3);
 }
 
-/// Convert a LevelFormat to its corresponding DimLevelType with the given
+/// Convert a LevelFormat to its corresponding LevelType with the given
 /// properties. Returns std::nullopt when the properties are not applicable
 /// for the input level format.
-constexpr std::optional<DimLevelType>
-buildLevelType(LevelFormat lf, bool ordered, bool unique) {
-  auto lt = static_cast<DimLevelType>(static_cast<uint8_t>(lf) |
-                                      (ordered ? 0 : 2) | (unique ? 0 : 1));
+constexpr std::optional<LevelType> buildLevelType(LevelFormat lf, bool ordered,
+                                                  bool unique) {
+  auto lt = static_cast<LevelType>(static_cast<uint8_t>(lf) |
+                                   (ordered ? 0 : 2) | (unique ? 0 : 1));
   return isValidLT(lt) ? std::optional(lt) : std::nullopt;
 }
 
@@ -323,190 +323,187 @@ buildLevelType(LevelFormat lf, bool ordered, bool unique) {
 //
 
 static_assert(
-    (getLevelFormat(DimLevelType::Undef) == std::nullopt &&
-     *getLevelFormat(DimLevelType::Dense) == LevelFormat::Dense &&
-     *getLevelFormat(DimLevelType::Compressed) == LevelFormat::Compressed &&
-     *getLevelFormat(DimLevelType::CompressedNu) == LevelFormat::Compressed &&
-     *getLevelFormat(DimLevelType::CompressedNo) == LevelFormat::Compressed &&
-     *getLevelFormat(DimLevelType::CompressedNuNo) == LevelFormat::Compressed &&
-     *getLevelFormat(DimLevelType::Singleton) == LevelFormat::Singleton &&
-     *getLevelFormat(DimLevelType::SingletonNu) == LevelFormat::Singleton &&
-     *getLevelFormat(DimLevelType::SingletonNo) == LevelFormat::Singleton &&
-     *getLevelFormat(DimLevelType::SingletonNuNo) == LevelFormat::Singleton &&
-     *getLevelFormat(DimLevelType::LooseCompressed) ==
+    (getLevelFormat(LevelType::Undef) == std::nullopt &&
+     *getLevelFormat(LevelType::Dense) == LevelFormat::Dense &&
+     *getLevelFormat(LevelType::Compressed) == LevelFormat::Compressed &&
+     *getLevelFormat(LevelType::CompressedNu) == LevelFormat::Compressed &&
+     *getLevelFormat(LevelType::CompressedNo) == LevelFormat::Compressed &&
+     *getLevelFormat(LevelType::CompressedNuNo) == LevelFormat::Compressed &&
+     *getLevelFormat(LevelType::Singleton) == LevelFormat::Singleton &&
+     *getLevelFormat(LevelType::SingletonNu) == LevelFormat::Singleton &&
+     *getLevelFormat(LevelType::SingletonNo) == LevelFormat::Singleton &&
+     *getLevelFormat(LevelType::SingletonNuNo) == LevelFormat::Singleton &&
+     *getLevelFormat(LevelType::LooseCompressed) ==
          LevelFormat::LooseCompressed &&
-     *getLevelFormat(DimLevelType::LooseCompressedNu) ==
+     *getLevelFormat(LevelType::LooseCompressedNu) ==
          LevelFormat::LooseCompressed &&
-     *getLevelFormat(DimLevelType::LooseCompressedNo) ==
+     *getLevelFormat(LevelType::LooseCompressedNo) ==
          LevelFormat::LooseCompressed &&
-     *getLevelFormat(DimLevelType::LooseCompressedNuNo) ==
+     *getLevelFormat(LevelType::LooseCompressedNuNo) ==
          LevelFormat::LooseCompressed &&
-     *getLevelFormat(DimLevelType::TwoOutOfFour) == LevelFormat::TwoOutOfFour),
+     *getLevelFormat(LevelType::TwoOutOfFour) == LevelFormat::TwoOutOfFour),
     "getLevelFormat conversion is broken");
 
 static_assert(
     (buildLevelType(LevelFormat::Dense, false, true) == std::nullopt &&
      buildLevelType(LevelFormat::Dense, true, false) == std::nullopt &&
      buildLevelType(LevelFormat::Dense, false, false) == std::nullopt &&
-     *buildLevelType(LevelFormat::Dense, true, true) == DimLevelType::Dense &&
+     *buildLevelType(LevelFormat::Dense, true, true) == LevelType::Dense &&
      *buildLevelType(LevelFormat::Compressed, true, true) ==
-         DimLevelType::Compressed &&
+         LevelType::Compressed &&
      *buildLevelType(LevelFormat::Compressed, true, false) ==
-         DimLevelType::CompressedNu &&
+         LevelType::CompressedNu &&
      *buildLevelType(LevelFormat::Compressed, false, true) ==
-         DimLevelType::CompressedNo &&
+         LevelType::CompressedNo &&
      *buildLevelType(LevelFormat::Compressed, false, false) ==
-         DimLevelType::CompressedNuNo &&
+         LevelType::CompressedNuNo &&
      *buildLevelType(LevelFormat::Singleton, true, true) ==
-         DimLevelType::Singleton &&
+         LevelType::Singleton &&
      *buildLevelType(LevelFormat::Singleton, true, false) ==
-         DimLevelType::SingletonNu &&
+         LevelType::SingletonNu &&
      *buildLevelType(LevelFormat::Singleton, false, true) ==
-         DimLevelType::SingletonNo &&
+         LevelType::SingletonNo &&
      *buildLevelType(LevelFormat::Singleton, false, false) ==
-         DimLevelType::SingletonNuNo &&
+         LevelType::SingletonNuNo &&
      *buildLevelType(LevelFormat::LooseCompressed, true, true) ==
-         DimLevelType::LooseCompressed &&
+         LevelType::LooseCompressed &&
      *buildLevelType(LevelFormat::LooseCompressed, true, false) ==
-         DimLevelType::LooseCompressedNu &&
+         LevelType::LooseCompressedNu &&
      *buildLevelType(LevelFormat::LooseCompressed, false, true) ==
-         DimLevelType::LooseCompressedNo &&
+         LevelType::LooseCompressedNo &&
      *buildLevelType(LevelFormat::LooseCompressed, false, false) ==
-         DimLevelType::LooseCompressedNuNo &&
+         LevelType::LooseCompressedNuNo &&
      buildLevelType(LevelFormat::TwoOutOfFour, false, true) == std::nullopt &&
      buildLevelType(LevelFormat::TwoOutOfFour, true, false) == std::nullopt &&
      buildLevelType(LevelFormat::TwoOutOfFour, false, false) == std::nullopt &&
      *buildLevelType(LevelFormat::TwoOutOfFour, true, true) ==
-         DimLevelType::TwoOutOfFour),
+         LevelType::TwoOutOfFour),
     "buildLevelType conversion is broken");
 
-static_assert((isValidLT(DimLevelType::Undef) &&
-               isValidLT(DimLevelType::Dense) &&
-               isValidLT(DimLevelType::Compressed) &&
-               isValidLT(DimLevelType::CompressedNu) &&
-               isValidLT(DimLevelType::CompressedNo) &&
-               isValidLT(DimLevelType::CompressedNuNo) &&
-               isValidLT(DimLevelType::Singleton) &&
-               isValidLT(DimLevelType::SingletonNu) &&
-               isValidLT(DimLevelType::SingletonNo) &&
-               isValidLT(DimLevelType::SingletonNuNo) &&
-               isValidLT(DimLevelType::LooseCompressed) &&
-               isValidLT(DimLevelType::LooseCompressedNu) &&
-               isValidLT(DimLevelType::LooseCompressedNo) &&
-               isValidLT(DimLevelType::LooseCompressedNuNo) &&
-               isValidLT(DimLevelType::TwoOutOfFour)),
-              "isValidLT definition is broken");
-
-static_assert((isDenseLT(DimLevelType::Dense) &&
-               !isDenseLT(DimLevelType::Compressed) &&
-               !isDenseLT(DimLevelType::CompressedNu) &&
-               !isDenseLT(DimLevelType::CompressedNo) &&
-               !isDenseLT(DimLevelType::CompressedNuNo) &&
-               !isDenseLT(DimLevelType::Singleton) &&
-               !isDenseLT(DimLevelType::SingletonNu) &&
-               !isDenseLT(DimLevelType::SingletonNo) &&
-               !isDenseLT(DimLevelType::SingletonNuNo) &&
-               !isDenseLT(DimLevelType::LooseCompressed) &&
-               !isDenseLT(DimLevelType::LooseCompressedNu) &&
-               !isDenseLT(DimLevelType::LooseCompressedNo) &&
-               !isDenseLT(DimLevelType::LooseCompressedNuNo) &&
-               !isDenseLT(DimLevelType::TwoOutOfFour)),
+static_assert(
+    (isValidLT(LevelType::Undef) && isValidLT(LevelType::Dense) &&
+     isValidLT(LevelType::Compressed) && isValidLT(LevelType::CompressedNu) &&
+     isValidLT(LevelType::CompressedNo) &&
+     isValidLT(LevelType::CompressedNuNo) && isValidLT(LevelType::Singleton) &&
+     isValidLT(LevelType::SingletonNu) && isValidLT(LevelType::SingletonNo) &&
+     isValidLT(LevelType::SingletonNuNo) &&
+     isValidLT(LevelType::LooseCompressed) &&
+     isValidLT(LevelType::LooseCompressedNu) &&
+     isValidLT(LevelType::LooseCompressedNo) &&
+     isValidLT(LevelType::LooseCompressedNuNo) &&
+     isValidLT(LevelType::TwoOutOfFour)),
+    "isValidLT definition is broken");
+
+static_assert((isDenseLT(LevelType::Dense) &&
+               !isDenseLT(LevelType::Compressed) &&
+               !isDenseLT(LevelType::CompressedNu) &&
+               !isDenseLT(LevelType::CompressedNo) &&
+               !isDenseLT(LevelType::CompressedNuNo) &&
+               !isDenseLT(LevelType::Singleton) &&
+               !isDenseLT(LevelType::SingletonNu) &&
+               !isDenseLT(LevelType::SingletonNo) &&
+               !isDenseLT(LevelType::SingletonNuNo) &&
+               !isDenseLT(LevelType::LooseCompressed) &&
...
[truncated]

Copy link

github-actions bot commented Nov 27, 2023

✅ With the latest revision this PR passed the Python code formatter.

@aartbik aartbik merged commit 1944c4f into llvm:main Nov 27, 2023
@aartbik aartbik deleted the bik branch November 27, 2023 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants