@@ -1635,20 +1635,27 @@ struct AIEObjectFifoStatefulTransformPass
16351635 /// shimDMAAllocationOp containing the channelDir, channelIndex and
16361636 /// shimTile col assigned by the objectFifo lowering.
16371637 void createObjectFifoAllocationInfo (OpBuilder &builder , MLIRContext *ctx ,
1638- FlatSymbolRefAttr obj_fifo , int colIndex ,
1639- DMAChannelDir channelDir ,
1638+ ObjectFifoCreateOp & objFifoOp ,
1639+ int colIndex , DMAChannelDir channelDir ,
16401640 int channelIndex , bool plio ,
16411641 std ::optional <PacketInfoAttr > packet ) {
16421642 PacketInfoAttr packetInfo = nullptr;
16431643 if (packet)
16441644 packetInfo = *packet;
1645- builder.create<ShimDMAAllocationOp >(builder.getUnknownLoc(), obj_fifo ,
1645+ std::string alloc_name = getShimAllocationName(objFifoOp.getName());
1646+ // SymbolRefAttr::get(ctx, objFifoOp.getName())
1647+ builder.create<ShimDMAAllocationOp >(builder.getUnknownLoc(),
1648+ StringAttr::get(ctx , alloc_name),
16461649 DMAChannelDirAttr::get(ctx , channelDir),
16471650 builder.getI64 IntegerAttr(channelIndex),
16481651 builder.getI64 IntegerAttr(colIndex),
16491652 builder.getBoolAttr(plio), packetInfo);
16501653 }
16511654
1655+ static std ::string getShimAllocationName (llvm ::StringRef objFifoName ) {
1656+ return (objFifoName + " _shim_alloc" ).str();
1657+ }
1658+
16521659 /// Function used to verify that an objectfifo is present in at most one
16531660 /// ObjectFifoLinkOp.
16541661 void verifyObjectFifoLinks (DeviceOp &device ) {
@@ -1908,9 +1915,9 @@ struct AIEObjectFifoStatefulTransformPass
19081915
19091916 if (producer.getProducerTileOp().isShimTile())
19101917 createObjectFifoAllocationInfo(
1911- builder , ctx , SymbolRefAttr::get( ctx , producer.getName() ),
1912- producer.getProducerTileOp().colIndex() , producerChan.direction ,
1913- producerChan.channel , producer.getPlio(), bdPacket);
1918+ builder , ctx , producer , producer.getProducerTileOp().colIndex( ),
1919+ producerChan.direction , producerChan.channel , producer.getPlio() ,
1920+ bdPacket);
19141921
19151922 PacketFlowOp packetflow;
19161923 if (clPacketSwObjectFifos) {
@@ -1963,9 +1970,9 @@ struct AIEObjectFifoStatefulTransformPass
19631970
19641971 if (consumer.getProducerTileOp().isShimTile())
19651972 createObjectFifoAllocationInfo(
1966- builder , ctx , SymbolRefAttr::get( ctx , producer.getName() ),
1967- consumer.getProducerTileOp().colIndex() , consumerChan.direction ,
1968- consumerChan.channel , producer.getPlio(), {});
1973+ builder , ctx , producer , consumer.getProducerTileOp().colIndex( ),
1974+ consumerChan.direction , consumerChan.channel , producer.getPlio() ,
1975+ {});
19691976
19701977 if (!clPacketSwObjectFifos ) {
19711978 // create flow
@@ -2233,34 +2240,41 @@ struct AIEObjectFifoStatefulTransformPass
22332240 if (res.wasInterrupted ())
22342241 return signalPassFailure ();
22352242 }
2236- // make global symbols to replace the to be erased ObjectFifoCreateOps
2237- for (auto createOp : device.getOps <ObjectFifoCreateOp >()) {
2238- builder.setInsertionPointToStart(device.getBody());
2239- auto sym_name = createOp.getName();
2240- createOp->setAttr(SymbolTable::getSymbolAttrName(),
2241- builder.getStringAttr(" __erase_" + sym_name));
2242- auto memrefType = llvm::cast<AIEObjectFifoType >(createOp.getElemType())
2243- .getElementType();
2244- builder.create<memref ::GlobalOp >(builder.getUnknownLoc(), sym_name ,
2245- builder.getStringAttr(" public" ),
2246- memrefType , nullptr , false , nullptr);
2247- }
22482243
22492244 //===------------------------------------------------------------------===//
22502245 // Remove old ops
22512246 //===------------------------------------------------------------------===//
22522247 SetVector <Operation *> opsToErase ;
22532248 device.walk ([&](Operation *op ) {
2254- if (isa<ObjectFifoCreateOp , ObjectFifoLinkOp ,
2255- ObjectFifoRegisterExternalBuffersOp , ObjectFifoAcquireOp ,
2256- ObjectFifoSubviewAccessOp , ObjectFifoReleaseOp ,
2257- ObjectFifoAllocateOp >(op))
2249+ if (isa<ObjectFifoLinkOp , ObjectFifoRegisterExternalBuffersOp ,
2250+ ObjectFifoAcquireOp , ObjectFifoSubviewAccessOp ,
2251+ ObjectFifoReleaseOp , ObjectFifoAllocateOp >(op))
22582252 opsToErase.insert(op);
22592253 });
22602254 SmallVector <Operation *> sorted {opsToErase.begin(), opsToErase.end()};
22612255 computeTopologicalSorting (sorted );
22622256 for (auto *op : llvm ::reverse (sorted ))
22632257 op ->erase();
2258+
2259+ //===------------------------------------------------------------------===//
2260+ // Replace any remaining uses of object fifo symbol with symbol of its shim
2261+ // dma allocation.
2262+ //===------------------------------------------------------------------===//
2263+ opsToErase.clear();
2264+ for (auto createOp : device.getOps<ObjectFifoCreateOp >()) {
2265+ std::string shimAllocName = getShimAllocationName(createOp.getName());
2266+ if (failed(SymbolTable::replaceAllSymbolUses(
2267+ createOp.getNameAttr(), builder.getStringAttr(shimAllocName),
2268+ device))) {
2269+ createOp.emitError(
2270+ " failed to replace symbol uses with shim allocation" );
2271+ return signalPassFailure();
2272+ }
2273+ opsToErase.insert(createOp);
2274+ }
2275+ for (auto *op : opsToErase) {
2276+ op->erase();
2277+ }
22642278 }
22652279};
22662280
0 commit comments