diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td --- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td +++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td @@ -630,8 +630,8 @@ } ``` - `scf.if` may also return results that are defined in its regions. The - values defined are determined by which execution path is taken. + `scf.if` may also produce results. Which values are returned depends on + which execution path is taken. Example: @@ -647,11 +647,13 @@ } ``` - `scf.if` regions are always terminated with "scf.yield". If "scf.if" - defines no values, the "scf.yield" can be left out, and will be inserted - implicitly. Otherwise, it must be explicit. - Also, if "scf.if" defines one or more values, the 'else' block cannot be - omitted. + The "then" region has exactly 1 block. The "else" region may have 0 or 1 + block. In case the `scf.if` produces results, the "else" region must also + have exactly 1 block. + + The blocks are always terminated with `scf.yield`. If `scf.if` defines no + values, the `scf.yield` can be left out, and will be inserted implicitly. + Otherwise, it must be explicit. Example: @@ -660,10 +662,14 @@ ... } ``` + + The types of the yielded values must match the result types of the + `scf.if`. }]; let arguments = (ins I1:$condition); let results = (outs Variadic:$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 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -1762,6 +1762,11 @@ 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;