[Mlir-commits] [mlir] [mlir][spirv] Simplify unreachable default cases in type switch. NFC. (PR #162010)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Oct 5 04:55:20 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Jakub Kuderski (kuhar)
<details>
<summary>Changes</summary>
Use `DefaultUnreachable` from https://github.com/llvm/llvm-project/pull/161970.
---
Full diff: https://github.com/llvm/llvm-project/pull/162010.diff
4 Files Affected:
- (modified) mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp (+1-4)
- (modified) mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp (+1-1)
- (modified) mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp (+4-7)
- (modified) mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp (+2-6)
``````````diff
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
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/162010
More information about the Mlir-commits
mailing list