27 #include "llvm/Support/DebugLog.h"
30 #define DEBUG_TYPE "cf-sink"
42 : shouldMoveIntoRegion(shouldMoveIntoRegion),
43 moveIntoRegion(moveIntoRegion), domInfo(domInfo) {}
61 std::vector<Operation *> &stack);
65 void sinkRegion(
Region *region);
80 "expected op to be defined outside the region");
84 return domInfo.dominates(®ion->front(), user->getBlock());
89 std::vector<Operation *> &stack) {
90 LDBG() <<
"Contained op: "
97 LDBG() <<
"Try to sink:\n"
101 if (allUsersDominatedBy(op, region) && shouldMoveIntoRegion(op, region)) {
102 moveIntoRegion(op, region);
110 void Sinker::sinkRegion(
Region *region) {
112 std::vector<Operation *> stack;
114 stack.push_back(&op);
118 while (!stack.empty()) {
121 tryToSinkPredecessors(op, region, stack);
126 for (
Region *region : regions)
127 if (!region->
empty())
136 return Sinker(shouldMoveIntoRegion, moveIntoRegion, domInfo)
137 .sinkRegions(regions);
149 branch.getRegionInvocationBounds(operands, bounds);
153 for (
auto it : llvm::zip(branch->getRegions(), bounds)) {
156 regions.push_back(&std::get<0>(it));
Attributes are known-constant values of operations.
A class for computing basic dominance information.
This class represents upper and lower bounds on the number of times a region of a RegionBranchOpInter...
std::optional< unsigned > getUpperBound() const
Return the upper bound.
Set of flags used to control the behavior of the various IR print methods (e.g.
A wrapper class that allows for printing an operation with a set of flags, useful to act as a "stream...
Operation is the basic unit of execution within MLIR.
operand_range getOperands()
Returns an iterator on the underlying Value's.
user_range getUsers()
Returns a range of all users.
Region * getParentRegion()
Returns the region to which the instruction belongs.
This class provides an abstraction over the different types of ranges over Regions.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
iterator_range< OpIterator > getOps()
Operation * findAncestorOpInRegion(Operation &op)
Returns 'op' if 'op' lies in this region, or otherwise finds the ancestor of 'op' that lies in this r...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
Include the generated interface declarations.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
void getSinglyExecutedRegionsToSink(RegionBranchOpInterface branch, SmallVectorImpl< Region * > ®ions)
Populates regions with regions of the provided region branch op that are executed at most once at tha...
size_t controlFlowSink(RegionRange regions, DominanceInfo &domInfo, function_ref< bool(Operation *, Region *)> shouldMoveIntoRegion, function_ref< void(Operation *, Region *)> moveIntoRegion)
Given a list of regions, perform control flow sinking on them.
detail::constant_op_matcher m_Constant()
Matches a constant foldable operation.