16 #include "mlir/IR/Dominance.h"
17 #include "mlir/Pass/Pass.h"
18 #include "mlir/Transforms/ControlFlowSinkUtils.h"
20 #define DEBUG_TYPE "firrtl-layer-sink"
24 #define GEN_PASS_DEF_LAYERSINK
25 #include "circt/Dialect/FIRRTL/Passes.h.inc"
29 using namespace circt;
30 using namespace firrtl;
34 struct LayerSink :
public circt::firrtl::impl::LayerSinkBase<LayerSink> {
35 void runOnOperation()
override;
39 void LayerSink::runOnOperation() {
42 <<
"Module: '" << getOperation().
getName() <<
"'\n";);
43 auto &domInfo = getAnalysis<mlir::DominanceInfo>();
44 getOperation()->walk([&](LayerBlockOp layerBlock) {
45 SmallVector<Region *> regionsToSink({&layerBlock.getRegion()});
46 numSunk = controlFlowSink(
47 regionsToSink, domInfo,
48 [](Operation *op, Region *) {
return !
hasDontTouch(op); },
49 [](Operation *op, Region *region) {
53 op->moveBefore(®ion->front(), region->front().begin());
59 return std::make_unique<LayerSink>();
bool hasDontTouch(Value value)
Check whether a block argument ("port") or the operation defining a value has a DontTouch annotation,...
std::unique_ptr< mlir::Pass > createLayerSinkPass()
StringAttr getName(ArrayAttr names, size_t idx)
Return the name at the specified index of the ArrayAttr or null if it cannot be determined.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
llvm::raw_ostream & debugPassHeader(const mlir::Pass *pass, int width=80)
Write a boilerplate header for a pass to the debug stream.