18 #include "mlir/IR/Builders.h"
19 #include "mlir/IR/Threading.h"
20 #include "mlir/Pass/Pass.h"
21 #include "llvm/Support/Debug.h"
23 #define DEBUG_TYPE "lower-seq-firmem"
25 using namespace circt;
27 using llvm::MapVector;
34 #define GEN_PASS_DEF_LOWERFIRMEM
35 #include "circt/Conversion/Passes.h.inc"
37 struct LowerFirMemPass :
public impl::LowerFirMemBase<LowerFirMemPass> {
38 void runOnOperation()
override;
42 void LowerFirMemPass::runOnOperation() {
43 auto circuit = getOperation();
45 auto modules = llvm::to_vector(circuit.getOps<
HWModuleOp>());
46 LLVM_DEBUG(llvm::dbgs() <<
"Lowering memories in " << modules.size()
52 auto uniqueMems = lowering.collectMemories(modules);
53 LLVM_DEBUG(llvm::dbgs() <<
"Found " << uniqueMems.size()
54 <<
" unique memory congiurations\n");
55 if (uniqueMems.empty()) {
56 markAllAnalysesPreserved();
62 MapVector<HWModuleOp, SmallVector<FirMemLowering::MemoryConfig>> memsByModule;
63 for (
auto &[config, memOps] : uniqueMems) {
65 auto genOp = lowering.createMemoryModule(config, memOps);
68 for (
auto memOp : memOps) {
69 auto parent = memOp->getParentOfType<
HWModuleOp>();
70 memsByModule[parent].emplace_back(&config, genOp, memOp);
75 mlir::parallelForEach(&getContext(), memsByModule, [&](
auto pair) {
76 lowering.lowerMemoriesInModule(pair.first, pair.second);
85 return std::make_unique<LowerFirMemPass>();
FIR memory lowering helper.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
std::unique_ptr< mlir::Pass > createLowerFirMemPass()