//===- CFGToSCF.h - Control Flow Graph to Structured Control Flow *- C++ -*===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This header file defines a generic `transformCFGToSCF` function that can be // used to lift any dialect operations implementing control flow graph // operations to any dialect implementing structured control flow operations. // //===----------------------------------------------------------------------===// #ifndef MLIR_TRANSFORMS_CFGTOSCF_H #define MLIR_TRANSFORMS_CFGTOSCF_H #include "mlir/IR/Builders.h" #include "mlir/IR/Dominance.h" #include "mlir/IR/Operation.h" namespace mlir { /// Interface that should be implemented by any caller of `transformCFGToSCF`. /// The transformation requires the caller to 1) create switch-like control /// flow operations for intermediate transformations and 2) to create /// the desired structured control flow ops. class CFGToSCFInterface { … }; /// Transformation lifting any dialect implementing control flow graph /// operations to a dialect implementing structured control flow operations. /// `region` is the region that should be transformed. /// The implementation of `interface` is responsible for the conversion of the /// control flow operations to the structured control flow operations. /// /// If the region contains only a single kind of return-like operation, all /// control flow graph operations will be converted successfully. /// Otherwise a single control flow graph operation branching to one block /// per return-like operation kind remains. /// /// The transformation currently requires that all control flow graph operations /// have no side effects, implement the BranchOpInterface and does not have any /// operation produced successor operands. /// Returns failure if any of the preconditions are violated or if any of the /// methods of `interface` failed. The IR is left in an unspecified state. /// /// Otherwise, returns true or false if any changes to the IR have been made. FailureOr<bool> transformCFGToSCF(Region ®ion, CFGToSCFInterface &interface, DominanceInfo &dominanceInfo); } // namespace mlir #endif // MLIR_TRANSFORMS_CFGTOSCF_H