From 51184e5be51d4668aa9d40babec0340877d18e9f Mon Sep 17 00:00:00 2001 From: erwei-xilinx Date: Thu, 19 Sep 2024 13:36:19 -0700 Subject: [PATCH] Faster (static) method to get unique id for creating global op (#1781) --- lib/Dialect/AIEX/Transforms/AIEDmaToNpu.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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();