From d0a7bb9b1ad768dfd9b08f66a0e744584b49181f Mon Sep 17 00:00:00 2001 From: Matthias Springer Date: Sat, 4 Feb 2023 15:44:20 +0100 Subject: [PATCH] [mlir][SCF] Disallow multiple blocks in scf.if "else" region The "then" region allows only a single block. The same should be the case for the "else" region. Differential Revision: https://reviews.llvm.org/D143253 --- mlir/include/mlir/Dialect/SCF/IR/SCFOps.td | 22 ++++++++++++++-------- mlir/include/mlir/IR/OpBase.td | 5 +++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td index b3b8825..7e2d337 100644 --- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td +++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td @@ -630,8 +630,8 @@ def IfOp : SCF_Op<"if", [DeclareOpInterfaceMethods:$results); - let regions = (region SizedRegion<1>:$thenRegion, AnyRegion:$elseRegion); + let regions = (region SizedRegion<1>:$thenRegion, + MaxSizedRegion<1>:$elseRegion); let skipDefaultBuilders = 1; let builders = [ diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index d307beb..7ef6268 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -1762,6 +1762,11 @@ class MinSizedRegion : Region< CPred<"::llvm::hasNItemsOrMore($_self, " # numBlocks # ")">, "region with at least " # numBlocks # " blocks">; +// A region with at most the given number of blocks. +class MaxSizedRegion : Region< + CPred<"::llvm::hasNItemsOrLess($_self, " # numBlocks # ")">, + "region with at most " # numBlocks # " blocks">; + // A variadic region constraint. It expands to zero or more of the base region. class VariadicRegion : Region; -- 2.7.4