Skip to content

Commit 8bab6c4

Browse files
authored
[mlir] Simplify unreachable type switch cases. NFC. (#162032)
Use `DefaultUnreachable` from #161970.
1 parent 5296d01 commit 8bab6c4

File tree

22 files changed

+35
-78
lines changed

22 files changed

+35
-78
lines changed

mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static void getTreePredicates(std::vector<PositionalPredicate> &predList,
243243
.Case<OperandPosition, OperandGroupPosition>([&](auto *pos) {
244244
getOperandTreePredicates(predList, val, builder, inputs, pos);
245245
})
246-
.Default([](auto *) { llvm_unreachable("unexpected position kind"); });
246+
.DefaultUnreachable("unexpected position kind");
247247
}
248248

249249
static void getAttributePredicates(pdl::AttributeOp op,

mlir/lib/Conversion/XeVMToLLVM/XeVMToLLVM.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ std::string getTypeMangling(Type ty, bool isUnsigned = false) {
6868
llvm_unreachable("unhandled integer type");
6969
}
7070
})
71-
.Default([](Type) -> std::string {
72-
llvm_unreachable("unhandled type for mangling");
73-
});
71+
.DefaultUnreachable("unhandled type for mangling");
7472
}
7573

7674
std::string mangle(StringRef baseName, ArrayRef<Type> types,

mlir/lib/Dialect/ArmSME/Transforms/OuterProductFusion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class OuterProductFusion2Way
170170
op2, op.getResultType(), lhs, rhs, lhsMask, rhsMask,
171171
op1.getAcc());
172172
})
173-
.Default([&](auto) { llvm_unreachable("unexpected extend op!"); });
173+
.DefaultUnreachable("unexpected extend op!");
174174
} else if (kind == arm_sme::CombiningKind::Sub) {
175175
TypeSwitch<Operation *>(extOp)
176176
.Case<arith::ExtFOp>([&](auto) {
@@ -188,7 +188,7 @@ class OuterProductFusion2Way
188188
op2, op.getResultType(), lhs, rhs, lhsMask, rhsMask,
189189
op1.getAcc());
190190
})
191-
.Default([&](auto) { llvm_unreachable("unexpected extend op!"); });
191+
.DefaultUnreachable("unexpected extend op!");
192192
} else {
193193
llvm_unreachable("unexpected arm_sme::CombiningKind!");
194194
}

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ void GPUDialect::printType(Type type, DialectAsmPrinter &os) const {
375375
os << shape.back() << 'x' << fragTy.getElementType();
376376
os << ", \"" << fragTy.getOperand() << "\"" << '>';
377377
})
378-
.Default([](Type) { llvm_unreachable("unexpected 'gpu' type kind"); });
378+
.DefaultUnreachable("unexpected 'gpu' type kind");
379379
}
380380

381381
static LogicalResult verifyKnownLaunchSizeAttr(Operation *op,

mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,7 @@ getThreadIdBuilder(std::optional<TransformOpInterface> transformOp,
847847
return GpuLaneIdBuilder(ctx, warpSize, useLinearMapping,
848848
*maybeMaskingAttr);
849849
})
850-
.Default([&](DeviceMappingAttrInterface) -> GpuIdBuilder {
851-
llvm_unreachable("unknown mapping attribute");
852-
});
850+
.DefaultUnreachable("unknown mapping attribute");
853851
return DiagnosedSilenceableFailure::success();
854852
}
855853

mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,10 +1096,8 @@ static Value memsetGetStored(MemsetIntr op, const MemorySlot &slot,
10961096
Value intVal = buildMemsetValue(type.getWidth());
10971097
return LLVM::BitcastOp::create(builder, op.getLoc(), type, intVal);
10981098
})
1099-
.Default([](Type) -> Value {
1100-
llvm_unreachable(
1101-
"getStored should not be called on memset to unsupported type");
1102-
});
1099+
.DefaultUnreachable(
1100+
"getStored should not be called on memset to unsupported type");
11031101
}
11041102

11051103
template <class MemsetIntr>

mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ static StringRef getTypeKeyword(Type type) {
4545
.Case<LLVMStructType>([&](Type) { return "struct"; })
4646
.Case<LLVMTargetExtType>([&](Type) { return "target"; })
4747
.Case<LLVMX86AMXType>([&](Type) { return "x86_amx"; })
48-
.Default([](Type) -> StringRef {
49-
llvm_unreachable("unexpected 'llvm' type kind");
50-
});
48+
.DefaultUnreachable("unexpected 'llvm' type kind");
5149
}
5250

5351
/// Prints a structure type. Keeps track of known struct names to handle self-

mlir/lib/Dialect/Linalg/Transforms/Loops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static void replaceIndexOpsByInductionVariables(RewriterBase &rewriter,
192192
.Case([&](affine::AffineForOp affineForOp) {
193193
allIvs.push_back(affineForOp.getInductionVar());
194194
})
195-
.Default([&](Operation *op) { assert(false && "unexpected op"); });
195+
.DefaultUnreachable("unexpected op");
196196
}
197197
assert(linalgOp.getNumLoops() == allIvs.size() &&
198198
"expected the number of loops and induction variables to match");

mlir/lib/Dialect/Linalg/Transforms/NamedToElementwise.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ ElementwiseKind getKind(Operation *op) {
4848
.Case([](SquareOp) { return ElementwiseKind::square; })
4949
.Case([](TanhOp) { return ElementwiseKind::tanh; })
5050
.Case([](ErfOp) { return ElementwiseKind::erf; })
51-
.Default([&](Operation *op) {
52-
llvm_unreachable("unhandled case in named to elementwise");
53-
return ElementwiseKind::sub;
54-
});
51+
.DefaultUnreachable("unhandled case in named to elementwise");
5552
}
5653

5754
template <typename NamedOpTy>

mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,10 +1427,7 @@ FailureOr<Conv1DOp> DownscaleSizeOneWindowed2DConvolution<Conv2DOp, Conv1DOp>::
14271427
.Case([&](linalg::PoolingNchwMaxOp op) {
14281428
return std::make_tuple(0, 1, 2, 3);
14291429
})
1430-
.Default([&](Operation *op) {
1431-
llvm_unreachable("unexpected conv2d/pool2d operation.");
1432-
return std::make_tuple(0, 0, 0, 0);
1433-
});
1430+
.DefaultUnreachable("unexpected conv2d/pool2d operation.");
14341431

14351432
// Only handle the case where at least one of the window dimensions is
14361433
// of size 1. Other cases can rely on tiling to reduce to such cases.

0 commit comments

Comments
 (0)