15 #include "mlir/Pass/Pass.h"
18 #include "mlir/IR/Dominance.h"
19 #include "mlir/Interfaces/ControlFlowInterfaces.h"
20 #include "mlir/Interfaces/SideEffectInterfaces.h"
21 #include "mlir/Transforms/ControlFlowSinkUtils.h"
23 #define DEBUG_TYPE "firrtl-layer-sink"
27 #define GEN_PASS_DEF_LAYERSINK
28 #include "circt/Dialect/FIRRTL/Passes.h.inc"
32 using namespace circt;
33 using namespace firrtl;
37 struct LayerSink :
public circt::firrtl::impl::LayerSinkBase<LayerSink> {
38 void runOnOperation()
override;
42 void LayerSink::runOnOperation() {
45 <<
"Module: '" << getOperation().
getName() <<
"'\n";);
46 auto &domInfo = getAnalysis<mlir::DominanceInfo>();
47 getOperation()->walk([&](LayerBlockOp layerBlock) {
48 SmallVector<Region *> regionsToSink({&layerBlock.getRegion()});
49 numSunk = controlFlowSink(
50 regionsToSink, domInfo,
51 [](Operation *op, Region *) {
return !
hasDontTouch(op); },
52 [](Operation *op, Region *region) {
56 op->moveBefore(®ion->front(), region->front().begin());
62 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.