[NFC][SeqToSV] Fix constant caching in FIR mem loweringi

This commit is contained in:
Nandor Licker 2023-11-14 23:14:55 -08:00
parent 02f0bff91b
commit 74683f60cb
1 changed files with 5 additions and 4 deletions

View File

@ -307,14 +307,15 @@ void FirMemLowering::lowerMemoriesInModule(
LLVM_DEBUG(llvm::dbgs() << "Lowering " << mems.size() << " memories in "
<< module.getName() << "\n");
hw::ConstantOp constOneOp;
DenseMap<unsigned, Value> constOneOps;
auto constOne = [&](unsigned width = 1) {
if (!constOneOp) {
auto it = constOneOps.try_emplace(width, Value{});
if (it.second) {
auto builder = OpBuilder::atBlockBegin(module.getBodyBlock());
constOneOp = builder.create<hw::ConstantOp>(
it.first->second = builder.create<hw::ConstantOp>(
module.getLoc(), builder.getIntegerType(width), 1);
}
return constOneOp;
return it.first->second;
};
auto valueOrOne = [&](Value value, unsigned width = 1) {
return value ? value : constOne(width);