Skip to content

Commit

Permalink
[LowerToHW][nfc] Use function to record mapping
Browse files Browse the repository at this point in the history
Add a member function for recording a mapping of old FIRRTL module to new
HW module.  Use this to avoid some tedious repeated code that manipulates
two mappings (old to new and new to old) directly.

Signed-off-by: Schuyler Eldridge <[email protected]>
  • Loading branch information
seldridge committed Mar 3, 2024
1 parent b213b74 commit 49b5331
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/Conversion/FIRRTLToHW/LowerToHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ struct CircuitLoweringState {
return it != newToOldModuleMap.end() ? it->second : nullptr;
}

void recordModuleMapping(Operation *oldFMod, Operation *newHWMod) {
oldToNewModuleMap[oldFMod] = newHWMod;
newToOldModuleMap[newHWMod] = oldFMod;
}

// Process remaining annotations and emit warnings on unprocessed annotations
// still remaining in the annoSet.
void processRemainingAnnotations(Operation *op, const AnnotationSet &annoSet);
Expand Down Expand Up @@ -610,8 +615,7 @@ void FIRRTLModuleLowering::runOnOperation() {
if (!loweredMod)
return failure();

state.oldToNewModuleMap[&op] = loweredMod;
state.newToOldModuleMap[loweredMod] = &op;
state.recordModuleMapping(&op, loweredMod);
modulesToProcess.push_back(loweredMod);
// Lower all the alias types.
module.walk([&](Operation *op) {
Expand All @@ -628,17 +632,15 @@ void FIRRTLModuleLowering::runOnOperation() {
lowerExtModule(extModule, topLevelModule, state);
if (!loweredMod)
return failure();
state.oldToNewModuleMap[&op] = loweredMod;
state.newToOldModuleMap[loweredMod] = &op;
state.recordModuleMapping(&op, loweredMod);
return success();
})
.Case<FMemModuleOp>([&](auto memModule) {
auto loweredMod =
lowerMemModule(memModule, topLevelModule, state);
if (!loweredMod)
return failure();
state.oldToNewModuleMap[&op] = loweredMod;
state.newToOldModuleMap[loweredMod] = &op;
state.recordModuleMapping(&op, loweredMod);
return success();
})
.Default([&](Operation *op) {
Expand Down

0 comments on commit 49b5331

Please sign in to comment.