21static void writeLDScriptMap(raw_ostream &output, BufferOp buf,
int offset) {
22 std::string bufName(buf.name().getValue());
24 int numBytes = buf.getAllocationSize();
25 output <<
". = 0x" << llvm::utohexstr(offset + bufferBaseAddr) <<
";\n";
26 output << bufName <<
" = .;\n";
27 output <<
". += 0x" << llvm::utohexstr(numBytes) <<
";\n";
66 int tileCol,
int tileRow) {
67 DenseMap<TileID, Operation *> tiles;
68 DenseMap<Operation *, SmallVector<BufferOp, 4>> buffers;
70 if (module.getOps<DeviceOp>().empty()) {
71 module.emitOpError("expected AIE.device operation at toplevel");
73 DeviceOp targetOp = *(
module.getOps<DeviceOp>().begin());
75 collectTiles(targetOp, tiles);
76 collectBuffers(targetOp, buffers);
78 for (
auto tile : targetOp.getOps<TileOp>())
79 if (tile.colIndex() == tileCol && tile.rowIndex() == tileRow) {
80 TileID srcCoord = {tile.colIndex(), tile.rowIndex()};
84 auto core = tile.getCoreOp();
85 int max = core.getStackSize();
86 for (
auto buf : buffers[tiles[srcCoord]]) {
88 int numBytes = buf.getAllocationSize();
89 max = std::max(max, bufferBaseAddr + numBytes);
91 int origin = targetModel.getMemInternalBaseAddress(srcCoord) + max;
92 int length = targetModel.getLocalMemorySize() - max;
93 output << R
"THESCRIPT(
96 program (RX) : ORIGIN = 0, LENGTH = 0x0020000
98 output << " data (!RX) : ORIGIN = 0x" << llvm::utohexstr(origin)
99 <<
", LENGTH = 0x" << llvm::utohexstr(length);
100 output << R
"THESCRIPT(
107 /* the __start symbol has to come at address zero. */
110 _init_array_start = .;
111 KEEP(SORT(*.init_array))
139 auto doBuffer = [&](std::optional<TileID> tile,
int offset,
142 if (tiles.count(*tile))
143 for (
auto buf : buffers[tiles[*tile]])
144 writeLDScriptMap(output, buf, offset);
146 output <<
"/* No tile with memory exists to the " << dir <<
". */\n";
147 output <<
". = 0x" << llvm::utohexstr(offset) <<
";\n";
148 uint32_t localMemSize = targetModel.getLocalMemorySize();
149 output <<
". += 0x" << llvm::utohexstr(localMemSize) <<
";\n";
155 << llvm::utohexstr(targetModel.getMemInternalBaseAddress(srcCoord))
157 output <<
"_sp_start_value_DM_stack = .;\n";
159 if (
auto core = tile.getCoreOp())
160 output <<
". += 0x" << llvm::utohexstr(core.getStackSize())
161 <<
"; /* stack */\n";
163 output <<
"/* no stack allocated */\n";
165 doBuffer(targetModel.getMemSouth(srcCoord),
166 targetModel.getMemSouthBaseAddress(), std::string(
"south"));
167 doBuffer(targetModel.getMemWest(srcCoord),
168 targetModel.getMemWestBaseAddress(), std::string(
"west"));
169 doBuffer(targetModel.getMemNorth(srcCoord),
170 targetModel.getMemNorthBaseAddress(), std::string(
"north"));
171 doBuffer(targetModel.getMemEast(srcCoord),
172 targetModel.getMemEastBaseAddress(), std::string(
"east"));
174 output <<
" .bss : { *(.bss*) } > data\n";
176 if (
auto coreOp = tile.getCoreOp()) {
177 if (
auto fileAttr = coreOp.getLinkWith())
178 output <<
"INPUT(" << fileAttr.value().str() <<
")\n";
180 output <<
"PROVIDE(main = core_" << tile.getCol() <<
"_"
181 << tile.getRow() <<
");\n";
Include the generated interface declarations.
TileID { friend std::ostream &operator<<(std::ostream &os, const TileID &s) { os<< "TileID("<< s.col<< ", "<< s.row<< ")" TileID
int32_t getBufferBaseAddress(mlir::Operation *bufOp)
mlir::LogicalResult AIETranslateToLdScript(mlir::ModuleOp module, llvm::raw_ostream &output, int tileCol, int tileRow)
const AIETargetModel & getTargetModel(mlir::Operation *op)