27 #define DEBUG_TYPE "cf-sink"
39 : shouldMoveIntoRegion(shouldMoveIntoRegion),
40 moveIntoRegion(moveIntoRegion), domInfo(domInfo) {}
58 std::vector<Operation *> &stack);
62 void sinkRegion(
Region *region);
77 "expected op to be defined outside the region");
81 return domInfo.dominates(®ion->front(), user->getBlock());
86 std::vector<Operation *> &stack) {
87 LLVM_DEBUG(user->
print(llvm::dbgs() <<
"\nContained op:\n"));
93 LLVM_DEBUG(op->
print(llvm::dbgs() <<
"\nTry to sink:\n"));
96 if (allUsersDominatedBy(op, region) && shouldMoveIntoRegion(op, region)) {
97 moveIntoRegion(op, region);
105 void Sinker::sinkRegion(
Region *region) {
107 std::vector<Operation *> stack;
109 stack.push_back(&op);
113 while (!stack.empty()) {
116 tryToSinkPredecessors(op, region, stack);
121 for (
Region *region : regions)
122 if (!region->
empty())
131 return Sinker(shouldMoveIntoRegion, moveIntoRegion, domInfo)
132 .sinkRegions(regions);
144 branch.getRegionInvocationBounds(operands, bounds);
148 for (
auto it : llvm::zip(branch->getRegions(), bounds)) {
151 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.
Operation is the basic unit of execution within MLIR.
void print(raw_ostream &os, const OpPrintingFlags &flags=std::nullopt)
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.