diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp @@ -78,18 +78,19 @@ return getOverheadType(builder, indexOverheadTypeEncoding(enc)); } +// TODO: Adjust the naming convention for the constructors of `OverheadType` +// and the function-suffix for `kIndex` so we can use the `FOREVERY_O` +// x-macro here instead of `FOREVERY_FIXED_O`; to further reduce the +// possibility of typo bugs or things getting out of sync. StringRef mlir::sparse_tensor::overheadTypeFunctionSuffix(OverheadType ot) { switch (ot) { case OverheadType::kIndex: return ""; - case OverheadType::kU64: - return "64"; - case OverheadType::kU32: - return "32"; - case OverheadType::kU16: - return "16"; - case OverheadType::kU8: - return "8"; +#define CASE(ONAME, O) \ + case OverheadType::kU##ONAME: \ + return #ONAME; + FOREVERY_FIXED_O(CASE) +#undef CASE } llvm_unreachable("Unknown OverheadType"); } @@ -123,22 +124,11 @@ StringRef mlir::sparse_tensor::primaryTypeFunctionSuffix(PrimaryType pt) { switch (pt) { - case PrimaryType::kF64: - return "F64"; - case PrimaryType::kF32: - return "F32"; - case PrimaryType::kI64: - return "I64"; - case PrimaryType::kI32: - return "I32"; - case PrimaryType::kI16: - return "I16"; - case PrimaryType::kI8: - return "I8"; - case PrimaryType::kC64: - return "C64"; - case PrimaryType::kC32: - return "C32"; +#define CASE(VNAME, V) \ + case PrimaryType::k##VNAME: \ + return #VNAME; + FOREVERY_V(CASE) +#undef CASE } llvm_unreachable("Unknown PrimaryType"); }