[Mlir-commits] [mlir] [mlir][SCF] Add scf.index_switch support for populateSCFStructuralTypeConversionsAndLegality (PR #160344)

Ivan Butygin llvmlistbot at llvm.org
Tue Sep 23 10:18:57 PDT 2025


================
@@ -185,6 +185,31 @@ class ConvertWhileOpTypes
 };
 } // namespace
 
+namespace {
+class ConvertIndexSwitchOpTypes
+    : public Structural1ToNConversionPattern<IndexSwitchOp,
+                                             ConvertIndexSwitchOpTypes> {
+public:
+  using Structural1ToNConversionPattern::Structural1ToNConversionPattern;
+
+  std::optional<IndexSwitchOp>
+  convertSourceOp(IndexSwitchOp op, OneToNOpAdaptor adaptor,
+                  ConversionPatternRewriter &rewriter,
+                  TypeRange dstTypes) const {
+    auto newOp = rewriter.create<IndexSwitchOp>(
+        op.getLoc(), dstTypes, op.getArg(), op.getCases(), op.getNumCases());
+
+    for (unsigned i = 0u; i < op.getNumRegions(); i++) {
+      if (failed(rewriter.convertRegionTypes(&op.getRegion(i), *typeConverter)))
----------------
Hardcode84 wrote:

`convertRegionTypes` is supposed to update block args types but I don't see any block with arguments in `scf.index_switch`. Do we need this? If we do we will need a test where this path is exercised.

https://github.com/llvm/llvm-project/pull/160344


More information about the Mlir-commits mailing list