@@ -30,7 +30,12 @@ using namespace mlir;
30
30
namespace {
31
31
// / A control-flow sink pass.
32
32
struct ControlFlowSink : public impl ::ControlFlowSinkBase<ControlFlowSink> {
33
+ ControlFlowSink (
34
+ function_ref<bool (Operation *, Region *)> shouldMoveIntoRegion)
35
+ : shouldMoveIntoRegion(shouldMoveIntoRegion) {}
33
36
void runOnOperation () override ;
37
+
38
+ function_ref<bool (Operation *, Region *)> shouldMoveIntoRegion;
34
39
};
35
40
} // end anonymous namespace
36
41
@@ -40,19 +45,25 @@ void ControlFlowSink::runOnOperation() {
40
45
SmallVector<Region *> regionsToSink;
41
46
// Get the regions are that known to be executed at most once.
42
47
getSinglyExecutedRegionsToSink (branch, regionsToSink);
43
- // Sink side-effect free operations.
44
- numSunk = controlFlowSink (
45
- regionsToSink, domInfo,
46
- [](Operation *op, Region *) { return isMemoryEffectFree (op); },
47
- [](Operation *op, Region *region) {
48
- // Move the operation to the beginning of the region's entry block.
49
- // This guarantees the preservation of SSA dominance of all of the
50
- // operation's uses are in the region.
51
- op->moveBefore (®ion->front (), region->front ().begin ());
52
- });
48
+ numSunk = controlFlowSink (regionsToSink, domInfo, shouldMoveIntoRegion,
49
+ [](Operation *op, Region *region) {
50
+ // Move the operation to the beginning of the
51
+ // region's entry block. This guarantees the
52
+ // preservation of SSA dominance of all of the
53
+ // operation's uses are in the region.
54
+ op->moveBefore (®ion->front (),
55
+ region->front ().begin ());
56
+ });
53
57
});
54
58
}
55
59
56
- std::unique_ptr<Pass> mlir::createControlFlowSinkPass () {
57
- return std::make_unique<ControlFlowSink>();
60
+ std::unique_ptr<Pass> mlir::createControlFlowSinkPass (
61
+ function_ref<bool (Operation *, Region *)> shouldMoveIntoRegion) {
62
+ if (!shouldMoveIntoRegion) {
63
+ // Sink side-effect free operations.
64
+ shouldMoveIntoRegion = [](Operation *op, Region *) {
65
+ return isMemoryEffectFree (op);
66
+ };
67
+ }
68
+ return std::make_unique<ControlFlowSink>(shouldMoveIntoRegion);
58
69
}
0 commit comments