16 #include "mlir/IR/PatternMatch.h"
17 #include "mlir/Pass/Pass.h"
18 #include "llvm/Support/Debug.h"
20 #define DEBUG_TYPE "firrtl-layer-merge"
24 #define GEN_PASS_DEF_LAYERMERGE
25 #include "circt/Dialect/FIRRTL/Passes.h.inc"
29 using namespace circt;
30 using namespace firrtl;
34 struct LayerMerge :
public circt::firrtl::impl::LayerMergeBase<LayerMerge> {
35 void runOnOperation()
override;
39 void LayerMerge::runOnOperation() {
41 llvm::dbgs() <<
"==----- Running LayerMerge "
42 "--------------------------------------------------===\n"
43 <<
"Module: '" << getOperation().
getName() <<
"'\n";);
49 llvm::DenseMap<SymbolRefAttr, LayerBlockOp> priorLayerBlocks;
60 auto moduleOp = getOperation();
61 mlir::IRRewriter rewriter(moduleOp.getContext());
62 moduleOp.walk([&](LayerBlockOp layerBlock) {
63 auto layerName = layerBlock.getLayerName();
66 auto priorLayerBlockIt = priorLayerBlocks.find(layerName);
67 if (priorLayerBlockIt == priorLayerBlocks.end()) {
68 priorLayerBlocks[layerName] = layerBlock;
69 return WalkResult::advance();
72 auto &priorLayerBlock = priorLayerBlockIt->getSecond();
73 rewriter.inlineBlockBefore(priorLayerBlock.getBody(), layerBlock.getBody(),
74 layerBlock.getBody()->begin());
75 priorLayerBlock->erase();
76 priorLayerBlocks[layerName] = layerBlock;
78 return WalkResult::advance();
83 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.