Skip to content

Commit

Permalink
[FIRRTL][LowerLayers] Update rwprobe operations if possible.
Browse files Browse the repository at this point in the history
Fixes first example in llvm#7365 .
  • Loading branch information
dtzSiFive committed Jul 22, 2024
1 parent 2418f80 commit 818793f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/Dialect/FIRRTL/Transforms/LowerLayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ void LowerLayersPass::runOnModuleBody(FModuleOp moduleOp,
};

SmallVector<hw::InnerSymAttr> innerSyms;
SmallVector<RWProbeOp> rwprobes;
for (auto &op : llvm::make_early_inc_range(*body)) {
// Record any operations inside the layer block which have inner symbols.
// Theses may have symbol users which need to be updated.
Expand Down Expand Up @@ -475,6 +476,11 @@ void LowerLayersPass::runOnModuleBody(FModuleOp moduleOp,
continue;
}

if (auto rwprobe = dyn_cast<RWProbeOp>(op)) {
rwprobes.push_back(rwprobe);
continue;
}

if (auto connect = dyn_cast<FConnectLike>(op)) {
auto src = connect.getSrc();
auto dst = connect.getDest();
Expand Down Expand Up @@ -589,6 +595,25 @@ void LowerLayersPass::runOnModuleBody(FModuleOp moduleOp,
<< splice.second << "\n";);
}

// Update RWProbe operations.
if (!rwprobes.empty()) {
for (auto rwprobe : rwprobes) {
auto target = rwprobe.getTarget();
auto mapped = innerRefMap.find(target);
// This should be diagnosed, need to add error reporting path for that,
// though.
if (mapped == innerRefMap.end())
llvm::report_fatal_error(
"rwprobe target not moved (not part of this block?)");

if (mapped->second.second != newModule.getModuleNameAttr())
llvm::report_fatal_error("inner ref mapped to different module");

rwprobe.setTargetAttr(
hw::InnerRefAttr::get(mapped->second.second, target.getName()));
}
}

// Connect instance ports to values.
assert(ports.size() == connectValues.size() &&
"the number of instance ports and values to connect to them must be "
Expand Down

0 comments on commit 818793f

Please sign in to comment.