[Mlir-commits] [mlir] [mlir][spirv] Simplify unreachable default cases in type switch. NFC. (PR #162010)
Jakub Kuderski
llvmlistbot at llvm.org
Sun Oct 5 04:54:53 PDT 2025
https://github.com/kuhar created https://github.com/llvm/llvm-project/pull/162010
Use `DefaultUnreachable` from https://github.com/llvm/llvm-project/pull/161970.
>From 7768233637c63e7304420d09dcff57349d9b8427 Mon Sep 17 00:00:00 2001
From: Jakub Kuderski <jakub at nod-labs.com>
Date: Sun, 5 Oct 2025 07:53:12 -0400
Subject: [PATCH] [mlir][spirv] Simplify unreachable default cases in type
switch. NFC.
Using `DefaultUnreachable` from
https://github.com/llvm/llvm-project/pull/161970.
---
mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp | 5 +----
mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp | 2 +-
mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp | 11 ++++-------
mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp | 8 ++------
4 files changed, 8 insertions(+), 18 deletions(-)
diff --git a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
index 9b6154057b806..50fca564b5b64 100644
--- a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
+++ b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
@@ -1118,10 +1118,7 @@ StringRef getTypeMangling(Type type, bool isSigned) {
llvm_unreachable("Unsupported integer width");
}
})
- .Default([](auto) {
- llvm_unreachable("No mangling defined");
- return "";
- });
+ .DefaultUnreachable("No mangling defined");
}
template <typename ReduceOp>
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
index c8efdf0094223..24c33f9ae1b90 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
@@ -987,7 +987,7 @@ void SPIRVDialect::printType(Type type, DialectAsmPrinter &os) const {
.Case<ArrayType, CooperativeMatrixType, PointerType, RuntimeArrayType,
ImageType, SampledImageType, StructType, MatrixType, TensorArmType>(
[&](auto type) { print(type, os); })
- .Default([](Type) { llvm_unreachable("unhandled SPIR-V type"); });
+ .DefaultUnreachable("Unhandled SPIR-V type");
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
index 7e9a80e7d73a1..f895807ea1d18 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
@@ -57,7 +57,7 @@ class TypeExtensionVisitor {
for (Type elementType : concreteType.getElementTypes())
add(elementType);
})
- .Default([](SPIRVType) { llvm_unreachable("Unhandled type"); });
+ .DefaultUnreachable("Unhandled type");
}
void add(Type type) { add(cast<SPIRVType>(type)); }
@@ -107,7 +107,7 @@ class TypeCapabilityVisitor {
for (Type elementType : concreteType.getElementTypes())
add(elementType);
})
- .Default([](SPIRVType) { llvm_unreachable("Unhandled type"); });
+ .DefaultUnreachable("Unhandled type");
}
void add(Type type) { add(cast<SPIRVType>(type)); }
@@ -198,8 +198,7 @@ Type CompositeType::getElementType(unsigned index) const {
.Case<MatrixType>([](MatrixType type) { return type.getColumnType(); })
.Case<StructType>(
[index](StructType type) { return type.getElementType(index); })
- .Default(
- [](Type) -> Type { llvm_unreachable("invalid composite type"); });
+ .DefaultUnreachable("Invalid composite type");
}
unsigned CompositeType::getNumElements() const {
@@ -207,9 +206,7 @@ unsigned CompositeType::getNumElements() const {
.Case<ArrayType, StructType, TensorArmType, VectorType>(
[](auto type) { return type.getNumElements(); })
.Case<MatrixType>([](MatrixType type) { return type.getNumColumns(); })
- .Default([](SPIRVType) -> unsigned {
- llvm_unreachable("Invalid type for number of elements query");
- });
+ .DefaultUnreachable("Invalid type for number of elements query");
}
bool CompositeType::hasCompileTimeKnownNumElements() const {
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
index 122f61e0a66ae..88e1ab6ab1e4d 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
@@ -622,7 +622,7 @@ static spirv::Dim convertRank(int64_t rank) {
}
static spirv::ImageFormat getImageFormat(Type elementType) {
- return llvm::TypeSwitch<Type, spirv::ImageFormat>(elementType)
+ return TypeSwitch<Type, spirv::ImageFormat>(elementType)
.Case<Float16Type>([](Float16Type) { return spirv::ImageFormat::R16f; })
.Case<Float32Type>([](Float32Type) { return spirv::ImageFormat::R32f; })
.Case<IntegerType>([](IntegerType intType) {
@@ -639,11 +639,7 @@ static spirv::ImageFormat getImageFormat(Type elementType) {
llvm_unreachable("Unhandled integer type!");
}
})
- .Default([](Type) {
- llvm_unreachable("Unhandled element type!");
- // We need to return something here to satisfy the type switch.
- return spirv::ImageFormat::R32f;
- });
+ .DefaultUnreachable("Unhandled element type!");
#undef BIT_WIDTH_CASE
}
More information about the Mlir-commits
mailing list