From 75c1d9155472e343034da88e35e1c29f8142adc7 Mon Sep 17 00:00:00 2001 From: Matthias Springer Date: Wed, 16 Mar 2022 18:18:09 +0900 Subject: [PATCH] [mlir][SCF] Implement RegionBranchOpInterface on ExecuteRegionOp This is needed for the BufferDeallocation pass. Differential Revision: https://reviews.llvm.org/D121526 --- mlir/include/mlir/Dialect/SCF/SCFOps.td | 3 ++- mlir/lib/Dialect/SCF/SCF.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mlir/include/mlir/Dialect/SCF/SCFOps.td b/mlir/include/mlir/Dialect/SCF/SCFOps.td index b9cb09d..929a432 100644 --- a/mlir/include/mlir/Dialect/SCF/SCFOps.td +++ b/mlir/include/mlir/Dialect/SCF/SCFOps.td @@ -56,7 +56,8 @@ def ConditionOp : SCF_Op<"condition", [ // ExecuteRegionOp //===----------------------------------------------------------------------===// -def ExecuteRegionOp : SCF_Op<"execute_region"> { +def ExecuteRegionOp : SCF_Op<"execute_region", [ + DeclareOpInterfaceMethods]> { let summary = "operation that executes its region exactly once"; let description = [{ The `execute_region` operation is used to allow multiple blocks within SCF diff --git a/mlir/lib/Dialect/SCF/SCF.cpp b/mlir/lib/Dialect/SCF/SCF.cpp index 4e7ff08..e025cf6 100644 --- a/mlir/lib/Dialect/SCF/SCF.cpp +++ b/mlir/lib/Dialect/SCF/SCF.cpp @@ -236,6 +236,24 @@ void ExecuteRegionOp::getCanonicalizationPatterns(RewritePatternSet &results, results.add(context); } +/// Given the region at `index`, or the parent operation if `index` is None, +/// return the successor regions. These are the regions that may be selected +/// during the flow of control. `operands` is a set of optional attributes that +/// correspond to a constant value for each operand, or null if that operand is +/// not a constant. +void ExecuteRegionOp::getSuccessorRegions( + Optional index, ArrayRef operands, + SmallVectorImpl ®ions) { + // If the predecessor is the ExecuteRegionOp, branch into the body. + if (!index.hasValue()) { + regions.push_back(RegionSuccessor(&getRegion())); + return; + } + + // Otherwise, the region branches back to the parent operation. + regions.push_back(RegionSuccessor(getResults())); +} + //===----------------------------------------------------------------------===// // ConditionOp //===----------------------------------------------------------------------===// -- 2.7.4