15 #include "mlir/IR/PatternMatch.h"
16 #include "llvm/Support/Debug.h"
18 #define DEBUG_TYPE "firrtl-layer-merge"
20 using namespace circt;
21 using namespace firrtl;
25 struct LayerMerge :
public LayerMergeBase<LayerMerge> {
26 void runOnOperation()
override;
30 void LayerMerge::runOnOperation() {
32 llvm::dbgs() <<
"==----- Running LayerMerge "
33 "--------------------------------------------------===\n"
34 <<
"Module: '" << getOperation().
getName() <<
"'\n";);
40 llvm::DenseMap<SymbolRefAttr, LayerBlockOp> priorLayerBlocks;
51 auto moduleOp = getOperation();
52 mlir::IRRewriter rewriter(moduleOp.getContext());
53 moduleOp.walk([&](LayerBlockOp layerBlock) {
54 auto layerName = layerBlock.getLayerName();
57 auto priorLayerBlockIt = priorLayerBlocks.find(layerName);
58 if (priorLayerBlockIt == priorLayerBlocks.end()) {
59 priorLayerBlocks[layerName] = layerBlock;
60 return WalkResult::advance();
63 auto &priorLayerBlock = priorLayerBlockIt->getSecond();
64 rewriter.inlineBlockBefore(priorLayerBlock.getBody(), layerBlock.getBody(),
65 layerBlock.getBody()->begin());
66 priorLayerBlock->erase();
67 priorLayerBlocks[layerName] = layerBlock;
69 return WalkResult::advance();
74 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.