//===- ControlFlowSinkUtils.cpp - Code to perform control-flow sinking ----===// // // 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 file implements utilities for control-flow sinking. Control-flow // sinking moves operations whose only uses are in conditionally-executed blocks // into those blocks so that they aren't executed on paths where their results // are not needed. // // Control-flow sinking is not implemented on BranchOpInterface because // sinking ops into the successors of branch operations may move ops into loops. // It is idiomatic MLIR to perform optimizations at IR levels that readily // provide the necessary information. // //===----------------------------------------------------------------------===// #include "mlir/Transforms/ControlFlowSinkUtils.h" #include "mlir/IR/Dominance.h" #include "mlir/IR/Matchers.h" #include "mlir/Interfaces/ControlFlowInterfaces.h" #include <vector> #define DEBUG_TYPE … usingnamespacemlir; namespace { /// A helper struct for control-flow sinking. class Sinker { … }; } // end anonymous namespace bool Sinker::allUsersDominatedBy(Operation *op, Region *region) { … } void Sinker::tryToSinkPredecessors(Operation *user, Region *region, std::vector<Operation *> &stack) { … } void Sinker::sinkRegion(Region *region) { … } size_t Sinker::sinkRegions(RegionRange regions) { … } size_t mlir::controlFlowSink( RegionRange regions, DominanceInfo &domInfo, function_ref<bool(Operation *, Region *)> shouldMoveIntoRegion, function_ref<void(Operation *, Region *)> moveIntoRegion) { … } void mlir::getSinglyExecutedRegionsToSink(RegionBranchOpInterface branch, SmallVectorImpl<Region *> ®ions) { … }