@@ -58,41 +58,6 @@ static constexpr llvm::StringLiteral kBookkeepingSlotAttrName =
5858static constexpr int SEMAPHORE_CORE_PROD_LOCK_IDX = 0 ;
5959static constexpr int SEMAPHORE_CORE_CONS_LOCK_IDX = 1 ;
6060
61- //===----------------------------------------------------------------------===//
62- // Lock Analysis
63- //===----------------------------------------------------------------------===//
64- class LockAnalysis {
65- DenseMap <std ::pair <Value , int >, int > locksPerTile ;
66-
67- public :
68- LockAnalysis (DeviceOp &device ) {
69- // go over the locks created for each tile and update the index in
70- // locksPerTile
71- device.walk ([&](LockOp lockOp ) {
72- // A lock without an ID does not reserve a particular ID yet, so it does
73- // not make one unavailable here. AIEAssignLockIDs runs later and gives
74- // it one of the IDs still free on the tile.
75- if (!lockOp.getLockID ().has_value ())
76- return ;
77- auto tile = lockOp.getTile ();
78- auto lockID = lockOp.getLockIDValue ();
79- locksPerTile [{tile , lockID }] = 1 ;
80- });
81- }
82-
83- /// Given a tile, returns next usable lockID for that tile.
84- int getLockID (TileOp &tileOp ) {
85- const auto &targetModel = getTargetModel (tileOp );
86- for (unsigned i = 0 ;
87- i < targetModel.getNumLocks (tileOp.getCol (), tileOp.getRow ()); i ++)
88- if (int usageCnt = locksPerTile [{tileOp , i }]; usageCnt == 0 ) {
89- locksPerTile[{tileOp , i }] = 1 ;
90- return i;
91- }
92- return -1 ;
93- }
94- };
95-
9661//===----------------------------------------------------------------------===//
9762// DMA Channel Analysis
9863//===----------------------------------------------------------------------===//
@@ -736,10 +701,10 @@ struct AIEObjectFifoStatefulTransformPass
736701 }
737702
738703 /// Function used to create objectFifo locks based on target architecture.
739- /// Called by createObjectFifoElements().
704+ /// Called by createObjectFifoElements(). Locks are created without a lock ID;
705+ /// AIEAssignLockIDs assigns concrete IDs later in the pipeline.
740706 std::vector <LockOp >
741- createObjectFifoLocks(OpBuilder &builder , LockAnalysis &lockAnalysis ,
742- ObjectFifoCreateOp op , int numElem ,
707+ createObjectFifoLocks(OpBuilder &builder , ObjectFifoCreateOp op , int numElem ,
743708 int joinDistribFactor , TileOp creation_tile ,
744709 int repeatCount , ObjectFifoState &state) {
745710 std::vector <LockOp > locks;
@@ -767,10 +732,7 @@ struct AIEObjectFifoStatefulTransformPass
767732 for (int i = 0 ; i < numElem ; i ++) {
768733 // create corresponding aie1 locks
769734 int initValue = op.getInitValues().has_value() ? 1 : 0 ;
770- int lockID = lockAnalysis.getLockID(creation_tile);
771- assert(lockID >= 0 && " No more locks to allocate!" );
772- auto lock =
773- LockOp::create(builder , ofLoc , creation_tile , lockID , initValue);
735+ auto lock = LockOp::create(builder , ofLoc , creation_tile , initValue);
774736 lock.getOperation()->setAttr(SymbolTable::getSymbolAttrName(),
775737 builder.getStringAttr(op.name().str() +
776738 " _lock_" +
@@ -783,11 +745,9 @@ struct AIEObjectFifoStatefulTransformPass
783745 auto initValues = op.getInitValues().has_value()
784746 ? op.getInitValues().value().size()
785747 : 0 ;
786- int prodLockID = lockAnalysis.getLockID(creation_tile);
787- assert(prodLockID >= 0 && " No more locks to allocate!" );
788748 int prodLockValue = (numElem - initValues) * repeatCount;
789- auto prodLock = LockOp::create( builder , ofLoc , creation_tile ,
790- prodLockID , prodLockValue);
749+ auto prodLock =
750+ LockOp::create( builder , ofLoc , creation_tile , prodLockValue);
791751 prodLock.getOperation()->setAttr(
792752 SymbolTable::getSymbolAttrName(),
793753 builder.getStringAttr(op.name().str() + " _prod_lock_" +
@@ -796,11 +756,9 @@ struct AIEObjectFifoStatefulTransformPass
796756 " producer lock must land at SEMAPHORE_CORE_PROD_LOCK_IDX" );
797757 locks.push_back(prodLock);
798758
799- int consLockID = lockAnalysis.getLockID(creation_tile);
800- assert(consLockID >= 0 && " No more locks to allocate!" );
801759 int consLockValue = initValues * repeatCount;
802- auto consLock = LockOp::create( builder , ofLoc , creation_tile ,
803- consLockID , consLockValue);
760+ auto consLock =
761+ LockOp::create( builder , ofLoc , creation_tile , consLockValue);
804762 consLock.getOperation()->setAttr(
805763 SymbolTable::getSymbolAttrName(),
806764 builder.getStringAttr(op.name().str() + " _cons_lock_" +
@@ -943,9 +901,8 @@ struct AIEObjectFifoStatefulTransformPass
943901
944902 /// Function used to create objectFifo elements and their locks.
945903 /// It maps the input objectFifo to associated buffers and locks.
946- void createObjectFifoElements (OpBuilder &builder , LockAnalysis &lockAnalysis ,
947- ObjectFifoCreateOp op , int share_direction ,
948- ObjectFifoState &state ) {
904+ void createObjectFifoElements (OpBuilder &builder , ObjectFifoCreateOp op ,
905+ int share_direction , ObjectFifoState &state ) {
949906 if (!op.size ())
950907 return;
951908
@@ -1157,9 +1114,9 @@ struct AIEObjectFifoStatefulTransformPass
11571114 joinDistribFactor *= linkOp->getFifoIns().size();
11581115 state.objFifoLinks[*linkOp ] = op;
11591116 }
1160- std ::vector <LockOp > locks = createObjectFifoLocks (
1161- builder , lockAnalysis , op , numElem , joinDistribFactor , creation_tile ,
1162- repeatCount , state );
1117+ std ::vector <LockOp > locks =
1118+ createObjectFifoLocks ( builder , op , numElem , joinDistribFactor ,
1119+ creation_tile , repeatCount , state );
11631120 state.buffersPerFifo [op ] = buffers ;
11641121 state.locksPerFifo [op ] = locks ;
11651122 }
@@ -2264,7 +2221,6 @@ struct AIEObjectFifoStatefulTransformPass
22642221 // multi-device safety
22652222 ObjectFifoState state;
22662223
2267- LockAnalysis lockAnalysis(device);
22682224 DMAChannelAnalysis dmaAnalysis(device);
22692225 OpBuilder builder = OpBuilder::atBlockTerminator(device.getBody());
22702226 auto *ctx = device->getContext();
@@ -2459,8 +2415,7 @@ struct AIEObjectFifoStatefulTransformPass
24592415
24602416 // if split, the necessary size for producer fifo might change
24612417 if (shared) {
2462- createObjectFifoElements(builder , lockAnalysis , createOp ,
2463- share_direction , state);
2418+ createObjectFifoElements(builder , createOp , share_direction , state);
24642419 } else {
24652420 if (isa<ArrayAttr >(createOp.getElemNumber()))
24662421 createOp.setElemNumberAttr(
@@ -2474,8 +2429,7 @@ struct AIEObjectFifoStatefulTransformPass
24742429 builder.getI32 IntegerAttr(prodMaxAcquire));
24752430 }
24762431 }
2477- createObjectFifoElements(builder , lockAnalysis , createOp ,
2478- share_direction , state);
2432+ createObjectFifoElements(builder , createOp , share_direction , state);
24792433 }
24802434 }
24812435
0 commit comments