16 #include "mlir/IR/Iterators.h"
17 #include "mlir/IR/PatternMatch.h"
18 #include "mlir/Pass/Pass.h"
19 #include "llvm/Support/Debug.h"
21 #define DEBUG_TYPE "firrtl-layer-merge"
25 #define GEN_PASS_DEF_LAYERMERGE
26 #include "circt/Dialect/FIRRTL/Passes.h.inc"
30 using namespace circt;
31 using namespace firrtl;
35 struct LayerMerge :
public circt::firrtl::impl::LayerMergeBase<LayerMerge> {
36 void runOnOperation()
override;
40 void LayerMerge::runOnOperation() {
42 llvm::dbgs() <<
"==----- Running LayerMerge "
43 "--------------------------------------------------===\n"
44 <<
"Module: '" << getOperation().
getName() <<
"'\n";);
47 llvm::DenseMap<SymbolRefAttr, LayerBlockOp> lastBlockMap;
53 auto moduleOp = getOperation();
54 mlir::IRRewriter rewriter(moduleOp.getContext());
55 moduleOp.walk<mlir::WalkOrder::PostOrder, mlir::ReverseIterator>(
56 [&](LayerBlockOp thisBlock) {
57 auto layer = thisBlock.getLayerName();
59 auto [item, inserted] = lastBlockMap.try_emplace(layer, thisBlock);
61 return WalkResult::advance();
63 auto &lastBlock = item->getSecond();
64 rewriter.inlineBlockBefore(thisBlock.getBody(), lastBlock.getBody(),
65 lastBlock.getBody()->begin());
68 return WalkResult::advance();
73 return std::make_unique<LayerMerge>();
std::unique_ptr< mlir::Pass > createLayerMergePass()
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.