[Mlir-commits] [mlir] 98e142c - [mlir][sparse] Using x-macros in the function-suffix functions
wren romano
llvmlistbot at llvm.org
Tue May 31 17:36:54 PDT 2022
Author: wren romano
Date: 2022-05-31T17:36:43-07:00
New Revision: 98e142cd4fa4bc2371ea483ba2c82f88f99a5cf3
URL: https://github.com/llvm/llvm-project/commit/98e142cd4fa4bc2371ea483ba2c82f88f99a5cf3
DIFF: https://github.com/llvm/llvm-project/commit/98e142cd4fa4bc2371ea483ba2c82f88f99a5cf3.diff
LOG: [mlir][sparse] Using x-macros in the function-suffix functions
By defining the `{primary,overhead}TypeFunctionSuffix` functions via the same x-macros used to generate the runtime library's functions themselves, this helps avoid bugs from typos or things getting out of sync.
Reviewed By: bixia
Differential Revision: https://reviews.llvm.org/D126720
Added:
Modified:
mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp
index cf574fdabb7a..8bd2aceadaa9 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp
@@ -78,18 +78,19 @@ Type mlir::sparse_tensor::getIndexOverheadType(
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 @@ PrimaryType mlir::sparse_tensor::primaryTypeEncoding(Type elemTp) {
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");
}
More information about the Mlir-commits
mailing list