Skip to content

Commit e28a601

Browse files
kuhargithub-actions[bot]
authored andcommitted
Automerge: [mlir][spirv] Simplify unreachable default cases in type switch. NFC. (#162010)
Use `DefaultUnreachable` from llvm/llvm-project#161970.
2 parents c61f31c + 5e07093 commit e28a601

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,10 +1118,7 @@ StringRef getTypeMangling(Type type, bool isSigned) {
11181118
llvm_unreachable("Unsupported integer width");
11191119
}
11201120
})
1121-
.Default([](auto) {
1122-
llvm_unreachable("No mangling defined");
1123-
return "";
1124-
});
1121+
.DefaultUnreachable("No mangling defined");
11251122
}
11261123

11271124
template <typename ReduceOp>

mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ void SPIRVDialect::printType(Type type, DialectAsmPrinter &os) const {
987987
.Case<ArrayType, CooperativeMatrixType, PointerType, RuntimeArrayType,
988988
ImageType, SampledImageType, StructType, MatrixType, TensorArmType>(
989989
[&](auto type) { print(type, os); })
990-
.Default([](Type) { llvm_unreachable("unhandled SPIR-V type"); });
990+
.DefaultUnreachable("Unhandled SPIR-V type");
991991
}
992992

993993
//===----------------------------------------------------------------------===//

mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class TypeExtensionVisitor {
5757
for (Type elementType : concreteType.getElementTypes())
5858
add(elementType);
5959
})
60-
.Default([](SPIRVType) { llvm_unreachable("Unhandled type"); });
60+
.DefaultUnreachable("Unhandled type");
6161
}
6262

6363
void add(Type type) { add(cast<SPIRVType>(type)); }
@@ -107,7 +107,7 @@ class TypeCapabilityVisitor {
107107
for (Type elementType : concreteType.getElementTypes())
108108
add(elementType);
109109
})
110-
.Default([](SPIRVType) { llvm_unreachable("Unhandled type"); });
110+
.DefaultUnreachable("Unhandled type");
111111
}
112112

113113
void add(Type type) { add(cast<SPIRVType>(type)); }
@@ -198,18 +198,15 @@ Type CompositeType::getElementType(unsigned index) const {
198198
.Case<MatrixType>([](MatrixType type) { return type.getColumnType(); })
199199
.Case<StructType>(
200200
[index](StructType type) { return type.getElementType(index); })
201-
.Default(
202-
[](Type) -> Type { llvm_unreachable("invalid composite type"); });
201+
.DefaultUnreachable("Invalid composite type");
203202
}
204203

205204
unsigned CompositeType::getNumElements() const {
206205
return TypeSwitch<SPIRVType, unsigned>(*this)
207206
.Case<ArrayType, StructType, TensorArmType, VectorType>(
208207
[](auto type) { return type.getNumElements(); })
209208
.Case<MatrixType>([](MatrixType type) { return type.getNumColumns(); })
210-
.Default([](SPIRVType) -> unsigned {
211-
llvm_unreachable("Invalid type for number of elements query");
212-
});
209+
.DefaultUnreachable("Invalid type for number of elements query");
213210
}
214211

215212
bool CompositeType::hasCompileTimeKnownNumElements() const {

mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ static spirv::Dim convertRank(int64_t rank) {
622622
}
623623

624624
static spirv::ImageFormat getImageFormat(Type elementType) {
625-
return llvm::TypeSwitch<Type, spirv::ImageFormat>(elementType)
625+
return TypeSwitch<Type, spirv::ImageFormat>(elementType)
626626
.Case<Float16Type>([](Float16Type) { return spirv::ImageFormat::R16f; })
627627
.Case<Float32Type>([](Float32Type) { return spirv::ImageFormat::R32f; })
628628
.Case<IntegerType>([](IntegerType intType) {
@@ -639,11 +639,7 @@ static spirv::ImageFormat getImageFormat(Type elementType) {
639639
llvm_unreachable("Unhandled integer type!");
640640
}
641641
})
642-
.Default([](Type) {
643-
llvm_unreachable("Unhandled element type!");
644-
// We need to return something here to satisfy the type switch.
645-
return spirv::ImageFormat::R32f;
646-
});
642+
.DefaultUnreachable("Unhandled element type!");
647643
#undef BIT_WIDTH_CASE
648644
}
649645

0 commit comments

Comments
 (0)