@@ -30,7 +30,12 @@ using namespace mlir;
3030namespace {
3131// / A control-flow sink pass.
3232struct ControlFlowSink : public impl ::ControlFlowSinkBase<ControlFlowSink> {
33+ ControlFlowSink (
34+ function_ref<bool (Operation *, Region *)> shouldMoveIntoRegion)
35+ : shouldMoveIntoRegion(shouldMoveIntoRegion) {}
3336 void runOnOperation () override ;
37+
38+ function_ref<bool (Operation *, Region *)> shouldMoveIntoRegion;
3439};
3540} // end anonymous namespace
3641
@@ -40,19 +45,25 @@ void ControlFlowSink::runOnOperation() {
4045 SmallVector<Region *> regionsToSink;
4146 // Get the regions are that known to be executed at most once.
4247 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+ });
5357 });
5458}
5559
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);
5869}
0 commit comments