Skip to content

Commit

Permalink
[FIRRTL] Cleanup variable names in LayerMerge, NFC
Browse files Browse the repository at this point in the history
Superficial cleanup of LayerMerge to make the variable names make more
sense.

Signed-off-by: Schuyler Eldridge <[email protected]>
  • Loading branch information
seldridge committed Aug 24, 2024
1 parent d5bf8f8 commit 66122eb
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/Dialect/FIRRTL/Transforms/LayerMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void LayerMerge::runOnOperation() {
<< "Module: '" << getOperation().getName() << "'\n";);

// Track the last layer block in a module associated with a specific layer.
llvm::DenseMap<SymbolRefAttr, LayerBlockOp> lastBlock;
llvm::DenseMap<SymbolRefAttr, LayerBlockOp> lastBlockMap;

// Recursively visit LayerBlockOps in reverse order. Merge all earlier layer
// blocks into the last layer blocks of the same layer definition.
Expand All @@ -53,18 +53,17 @@ void LayerMerge::runOnOperation() {
auto moduleOp = getOperation();
mlir::IRRewriter rewriter(moduleOp.getContext());
moduleOp.walk<mlir::WalkOrder::PostOrder, mlir::ReverseIterator>(
[&](LayerBlockOp layerBlock) {
auto layerName = layerBlock.getLayerName();
// If we haven't seen this block before, then mark it as the last.
auto [last, inserted] = lastBlock.try_emplace(layerName, layerBlock);
[&](LayerBlockOp thisBlock) {
auto layer = thisBlock.getLayerName();
// If we haven't seen this block before, then it is the last block.
auto [item, inserted] = lastBlockMap.try_emplace(layer, thisBlock);
if (inserted)
return WalkResult::advance();

auto &priorLayerBlock = last->getSecond();
rewriter.inlineBlockBefore(layerBlock.getBody(),
priorLayerBlock.getBody(),
priorLayerBlock.getBody()->begin());
layerBlock->erase();
auto &lastBlock = item->getSecond();
rewriter.inlineBlockBefore(thisBlock.getBody(), lastBlock.getBody(),
lastBlock.getBody()->begin());
thisBlock->erase();
numMerged++;
return WalkResult::advance();
});
Expand Down

0 comments on commit 66122eb

Please sign in to comment.