diff --git a/lib/Dialect/AIEX/Transforms/AIEDmaToNpu.cpp b/lib/Dialect/AIEX/Transforms/AIEDmaToNpu.cpp index 5851efb06d..b9390d6e59 100644 --- a/lib/Dialect/AIEX/Transforms/AIEDmaToNpu.cpp +++ b/lib/Dialect/AIEX/Transforms/AIEDmaToNpu.cpp @@ -518,8 +518,13 @@ struct DmaWaitToSyncPattern : OpConversionPattern { struct WriteBdToBlockWritePattern : OpConversionPattern { using OpConversionPattern::OpConversionPattern; - WriteBdToBlockWritePattern(MLIRContext *context, PatternBenefit benefit = 1) - : OpConversionPattern(context, benefit) {} +private: + int &cachedId; + +public: + WriteBdToBlockWritePattern(MLIRContext *context, int &cachedId, + PatternBenefit benefit = 1) + : OpConversionPattern(context, benefit), cachedId(cachedId) {} LogicalResult matchAndRewrite(NpuWriteBdOp op, OpAdaptor adaptor, @@ -634,10 +639,11 @@ struct WriteBdToBlockWritePattern : OpConversionPattern { std::string name = "blockwrite_data_"; rewriter.setInsertionPoint( op->getParentOfType()); - int id = 0; + int id = cachedId; while (dev.lookupSymbol(name + std::to_string(id))) id++; name += std::to_string(id); + cachedId = id; global = rewriter.create( op->getLoc(), name, rewriter.getStringAttr("private"), memrefType, DenseElementsAttr::get(tensorType, words), true, nullptr); @@ -689,7 +695,8 @@ struct AIEDmaToNpuPass : AIEDmaToNpuBase { patterns.insert(&getContext()); patterns.insert(&getContext()); patterns.insert(&getContext()); - patterns.insert(&getContext()); + int cachedId = 0; + patterns.insert(&getContext(), cachedId); if (failed(applyPartialConversion(device, target, std::move(patterns)))) signalPassFailure();