MLIR-AIE
AIELocalizeLocks.cpp
Go to the documentation of this file.
1//===- AIELocalizeLocks.cpp ---------------------------------------*- C++
2//-*-===//
3//
4// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8// (c) Copyright 2019 Xilinx Inc.
9//
10//===----------------------------------------------------------------------===//
11
14
15#include "mlir/Dialect/Arith/IR/Arith.h"
16#include "mlir/Pass/Pass.h"
17
18#define DEBUG_TYPE "aie-localize-locks"
19
20using namespace mlir;
21using namespace xilinx;
22using namespace xilinx::AIE;
23
24struct AIELocalizeLocksPass : AIELocalizeLocksBase<AIELocalizeLocksPass> {
25 void getDependentDialects(DialectRegistry &registry) const override {
26 registry.insert<arith::ArithDialect>();
27 }
28 void runOnOperation() override {
29
30 DeviceOp deviceOp = getOperation();
31
32 for (auto coreOp : deviceOp.getOps<CoreOp>()) {
33 // Collect the locks used in this core.
34 const auto &targetModel = getTargetModel(coreOp);
35
36 auto thisTile = dyn_cast<TileOp>(coreOp.getTile().getDefiningOp());
37 int col = thisTile.colIndex();
38 int row = thisTile.rowIndex();
39
40 // Find the neighboring tiles
41 SmallVector<TileOp, 4> accessibleTiles;
42 for (auto tile : deviceOp.getOps<TileOp>())
43 if (int dstRow = tile.rowIndex();
44 targetModel.isLegalMemAffinity(col, row, tile.colIndex(), dstRow))
45 accessibleTiles.push_back(tile);
46
47 for (auto tile : accessibleTiles) {
48 int dstCol = tile.colIndex();
49 int dstRow = tile.rowIndex();
50
51 const auto &targetModel = getTargetModel(tile);
52 for (auto user : tile.getResult().getUsers())
53 if (auto lock = dyn_cast<LockOp>(user)) {
54 auto lockIndexOffset =
55 targetModel.getLockLocalBaseIndex(col, row, dstCol, dstRow);
56 if (!lockIndexOffset)
57 llvm_unreachable("Found illegal lock user!");
58
59 int localLockIndex =
60 lockIndexOffset.value() + lock.getLockIDValue();
61
62 OpBuilder builder =
63 OpBuilder::atBlockBegin(&coreOp.getBody().front());
64
65 Value coreLockIDValue = builder.create<arith::ConstantIndexOp>(
66 builder.getUnknownLoc(), localLockIndex);
67 lock.getResult().replaceUsesWithIf(
68 coreLockIDValue, [&](OpOperand &opOperand) {
69 return opOperand.getOwner()->getParentOp() == coreOp;
70 });
71 }
72 }
73 }
74 }
75};
76
77std::unique_ptr<OperationPass<DeviceOp>> AIE::createAIELocalizeLocksPass() {
78 return std::make_unique<AIELocalizeLocksPass>();
79}
Include the generated interface declarations.
const AIETargetModel & getTargetModel(mlir::Operation *op)
std::unique_ptr< mlir::OperationPass< DeviceOp > > createAIELocalizeLocksPass()
void runOnOperation() override
void getDependentDialects(DialectRegistry &registry) const override