143 DeviceOp device = getOperation();
144 OpBuilder builder = OpBuilder::atBlockTerminator(device.getBody());
148 LLVM_DEBUG(TA.
print(llvm::dbgs()));
149 SmallVector<std::pair<Operation *, Operation *>, 4> tokenChains(
151 SmallVector<std::pair<Operation *, Operation *>, 4> tokenPairs(
153 DenseMap<TileID, Operation *> tiles(TA.
getTiles());
155 DenseMap<std::pair<Operation *, int>,
int> locks;
156 DenseMap<std::pair<Operation *, Operation *>, std::pair<Value, int>>
158 DenseMap<Operation *, std::vector<std::pair<Value, int>>> acqLocks;
159 DenseMap<Operation *, std::vector<std::pair<Value, int>>> relLocks;
161 for (
auto map : tokenChains) {
162 Operation *release = map.first;
163 Operation *acquire = map.second;
167 bool IsRelUserCore = isa<CoreOp>(relUser);
168 bool IsAcqUserCore = isa<CoreOp>(acqUser);
172 LLVM_DEBUG(llvm::dbgs() <<
"\n=== CHECKING TOKEN CHAIN ===\n";
173 release->print(llvm::dbgs());
174 if (IsRelUserCore) llvm::dbgs() <<
" @Core";
175 else llvm::dbgs() <<
" @DMA";
176 llvm::dbgs() <<
" (" << TA.
getCoord(relUser).col <<
", "
177 << TA.
getCoord(relUser).row <<
")" <<
'\n';
178 acquire->print(llvm::dbgs());
179 if (IsAcqUserCore) llvm::dbgs() <<
" @Core";
180 else llvm::dbgs() <<
" @DMA";
181 llvm::dbgs() <<
" (" << TA.
getCoord(acqUser).col <<
", "
182 << TA.
getCoord(acqUser).row <<
")" <<
'\n';);
191 if (!tileOp && ((!IsRelUserCore && IsAcqUserCore) ||
192 (!IsAcqUserCore && IsRelUserCore)))
195 "Sorry, the lock users of this chain do not have a common lock");
197 TileOp tile = dyn_cast<TileOp>(tileOp);
198 int lockID = getLockID(locks, tileOp);
199 assert(lockID >= 0 &&
"No more locks to allocate!");
200 LLVM_DEBUG(llvm::dbgs() <<
"Shared tile \n"; tileOp->print(llvm::dbgs()));
201 LLVM_DEBUG(llvm::dbgs() <<
" LockID: " << lockID <<
'\n');
202 builder.setInsertionPointAfter(tileOp);
204 LockOp::create(builder, builder.getUnknownLoc(), tile, lockID, 0);
206 lockChains[std::make_pair(release, acquire)] = std::make_pair(lock, 1);
208 for (
auto pair : tokenPairs) {
209 Operation *acqFromPair = pair.first;
210 Operation *relFromPair = pair.second;
212 if (relFromPair == release)
213 acqLocks[acqFromPair].push_back(std::make_pair(lock, 0));
215 if (acqFromPair == acquire)
216 relLocks[relFromPair].push_back(std::make_pair(lock, 0));
220 ConversionTarget target(getContext());
221 target.addLegalOp<UseLockOp>();
223 RewritePatternSet patterns(&getContext());
227 if (failed(applyPartialConversion(device, target, std::move(patterns))))