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))
136 auto doBuffer = [&](std::optional<TileID> tile,
int offset,
139 if (tiles.count(*tile))
140 for (
auto buf : buffers[tiles[*tile]])
141 writeLDScriptMap(output, buf, offset);
143 output <<
"/* No tile with memory exists to the " << dir <<
". */\n";
144 output <<
". = 0x" << llvm::utohexstr(offset) <<
";\n";
145 uint32_t localMemSize = targetModel.getLocalMemorySize();
146 output <<
". += 0x" << llvm::utohexstr(localMemSize) <<
";\n";
152 << llvm::utohexstr(targetModel.getMemInternalBaseAddress(srcCoord))
154 output <<
"_sp_start_value_DM_stack = .;\n";
156 if (
auto core = tile.getCoreOp())
157 output <<
". += 0x" << llvm::utohexstr(core.getStackSize())
158 <<
"; /* stack */\n";
160 output <<
"/* no stack allocated */\n";
162 doBuffer(targetModel.getMemSouth(srcCoord),
163 targetModel.getMemSouthBaseAddress(), std::string(
"south"));
164 doBuffer(targetModel.getMemWest(srcCoord),
165 targetModel.getMemWestBaseAddress(), std::string(
"west"));
166 doBuffer(targetModel.getMemNorth(srcCoord),
167 targetModel.getMemNorthBaseAddress(), std::string(
"north"));
168 doBuffer(targetModel.getMemEast(srcCoord),
169 targetModel.getMemEastBaseAddress(), std::string(
"east"));
171 output <<
" .bss : { *(.bss*) } > data\n";
173 if (
auto coreOp = tile.getCoreOp()) {
174 if (
auto fileAttr = coreOp.getLinkWith())
175 output <<
"INPUT(" << fileAttr.value().str() <<
")\n";
177 output <<
"PROVIDE(main = core_" << tile.getCol() <<
"_"
178 << 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)