Skip to content

Commit 8bf67e1

Browse files
authored
Merge pull request #466 from Xilinx/matthias.cfs_config
[MLIR] control-flow-sink: Allow to configure shouldMoveIntoRegion
2 parents e8be3be + 666ce0f commit 8bf67e1

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

mlir/include/mlir/Transforms/Passes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ createCanonicalizerPass(const GreedyRewriteConfig &config,
6666
ArrayRef<std::string> enabledPatterns = std::nullopt);
6767

6868
/// Creates a pass to perform control-flow sinking.
69-
std::unique_ptr<Pass> createControlFlowSinkPass();
69+
std::unique_ptr<Pass> createControlFlowSinkPass(
70+
function_ref<bool(Operation *, Region *)> shouldMoveIntoRegion = nullptr);
7071

7172
/// Creates a pass to perform common sub expression elimination.
7273
std::unique_ptr<Pass> createCSEPass();

mlir/lib/Transforms/ControlFlowSink.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ using namespace mlir;
3030
namespace {
3131
/// A control-flow sink pass.
3232
struct 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(&region->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(&region->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

Comments
 (0)