Skip to content

Commit

Permalink
[FIRRTL] Use InstanceInfo in MemToRegOfVec
Browse files Browse the repository at this point in the history
Change the MemToRegOfVec pass to use the InstanceInfo analysis.  This does
subtly change the semantic of what is considered "in the design" to now
treat layers and Grand Central Companions as "outside" the design.  This
should be safe.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
  • Loading branch information
seldridge committed Jan 7, 2025
1 parent c92de74 commit acc5075
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions lib/Dialect/FIRRTL/Transforms/MemToRegOfVec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
//
//===----------------------------------------------------------------------===//

#include "circt/Analysis/FIRRTLInstanceInfo.h"
#include "circt/Dialect/FIRRTL/AnnotationDetails.h"
#include "circt/Dialect/FIRRTL/FIRRTLAnnotations.h"
#include "circt/Dialect/FIRRTL/FIRRTLInstanceGraph.h"
#include "circt/Dialect/FIRRTL/FIRRTLOps.h"
#include "circt/Dialect/FIRRTL/FIRRTLTypes.h"
#include "circt/Dialect/FIRRTL/Passes.h"
#include "mlir/IR/Threading.h"
#include "mlir/Pass/Pass.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/Support/Debug.h"

#define DEBUG_TYPE "mem-to-reg-of-vec"
Expand All @@ -41,27 +40,16 @@ struct MemToRegOfVecPass

void runOnOperation() override {
auto circtOp = getOperation();
DenseSet<Operation *> dutModuleSet;
auto &instanceInfo = getAnalysis<InstanceInfo>();

if (!AnnotationSet::removeAnnotations(circtOp,
convertMemToRegOfVecAnnoClass))
return markAllAnalysesPreserved();
auto *body = circtOp.getBodyBlock();

// Find the device under test and create a set of all modules underneath it.
auto it = llvm::find_if(*body, [&](Operation &op) -> bool {
return AnnotationSet::hasAnnotation(&op, dutAnnoClass);
});
if (it != body->end()) {
auto &instanceGraph = getAnalysis<InstanceGraph>();
auto *node = instanceGraph.lookup(cast<igraph::ModuleOpInterface>(*it));
llvm::for_each(llvm::depth_first(node),
[&](igraph::InstanceGraphNode *node) {
dutModuleSet.insert(node->getModule());
});
} else {
auto mods = circtOp.getOps<FModuleOp>();
dutModuleSet.insert(mods.begin(), mods.end());
}
DenseSet<Operation *> dutModuleSet;
for (auto moduleOp : circtOp.getOps<FModuleOp>())
if (instanceInfo.anyInstanceInEffectiveDesign(moduleOp))
dutModuleSet.insert(moduleOp);

mlir::parallelForEach(circtOp.getContext(), dutModuleSet,
[&](Operation *op) {
Expand Down

0 comments on commit acc5075

Please sign in to comment.