Skip to content

Commit 71e74a0

Browse files
authored
feat: use a densemap implementation (#9025)
Addressing feedback from Fabian Signed-off-by: Tianrui Wei <[email protected]>
1 parent 2c40259 commit 71e74a0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/Dialect/FIRRTL/FIRRTLReductions.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "mlir/IR/ImplicitLocOpBuilder.h"
2626
#include "mlir/IR/Matchers.h"
2727
#include "llvm/ADT/APSInt.h"
28+
#include "llvm/ADT/DenseMap.h"
2829
#include "llvm/ADT/SmallSet.h"
2930
#include "llvm/Support/Debug.h"
3031

@@ -1134,12 +1135,14 @@ struct EagerInliner : public OpReduction<InstanceOp> {
11341135
void beforeReduction(mlir::ModuleOp op) override {
11351136
symbols.clear();
11361137
nlaRemover.clear();
1137-
nlaTable = std::make_unique<NLATable>(op);
1138+
nlaTables.clear();
1139+
for (auto circuitOp : op.getOps<CircuitOp>())
1140+
nlaTables.insert({circuitOp, std::make_unique<NLATable>(circuitOp)});
11381141
innerSymTables = std::make_unique<hw::InnerSymbolTableCollection>();
11391142
}
11401143
void afterReduction(mlir::ModuleOp op) override {
11411144
nlaRemover.remove(op);
1142-
nlaTable.reset();
1145+
nlaTables.clear();
11431146
innerSymTables.reset();
11441147
}
11451148

@@ -1153,8 +1156,14 @@ struct EagerInliner : public OpReduction<InstanceOp> {
11531156
return 0;
11541157

11551158
// Skip instances that participate in any NLAs
1159+
auto circuitOp = instOp->getParentOfType<CircuitOp>();
1160+
if (!circuitOp)
1161+
return 0;
1162+
auto it = nlaTables.find(circuitOp);
1163+
if (it == nlaTables.end() || !it->second)
1164+
return 0;
11561165
DenseSet<hw::HierPathOp> nlas;
1157-
nlaTable->getInstanceNLAs(instOp, nlas);
1166+
it->second->getInstanceNLAs(instOp, nlas);
11581167
if (!nlas.empty())
11591168
return 0;
11601169

@@ -1209,7 +1218,7 @@ struct EagerInliner : public OpReduction<InstanceOp> {
12091218

12101219
::detail::SymbolCache symbols;
12111220
NLARemover nlaRemover;
1212-
std::unique_ptr<NLATable> nlaTable;
1221+
DenseMap<CircuitOp, std::unique_ptr<NLATable>> nlaTables;
12131222
std::unique_ptr<hw::InnerSymbolTableCollection> innerSymTables;
12141223
};
12151224

0 commit comments

Comments
 (0)