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 llvm::StringRef deviceName) {
68 DenseMap<TileID, Operation *> tiles;
69 DenseMap<Operation *, SmallVector<BufferOp, 4>> buffers;
72 AIE::DeviceOp::getForSymbolInModuleOrError(module, deviceName);
81 for (
auto tile : targetOp.getOps<TileOp>())
82 if (tile.colIndex() == tileCol && tile.rowIndex() == tileRow) {
83 TileID srcCoord = {tile.colIndex(), tile.rowIndex()};
87 auto core = tile.getCoreOp();
88 int max = core.getStackSize();
89 for (
auto buf : buffers[tiles[srcCoord]]) {
91 int numBytes = buf.getAllocationSize();
92 max = std::max(max, bufferBaseAddr + numBytes);
94 int origin = targetModel.getMemInternalBaseAddress(srcCoord) + max;
95 int length = targetModel.getLocalMemorySize() - max;
96 output << R
"THESCRIPT(
99 program (RX) : ORIGIN = 0, LENGTH = 0x0020000
101 output << " data (!RX) : ORIGIN = 0x" << llvm::utohexstr(origin)
102 <<
", LENGTH = 0x" << llvm::utohexstr(length);
103 output << R
"THESCRIPT(
110 /* the __start symbol has to come at address zero. */
113 _init_array_start = .;
114 KEEP(SORT(*.init_array))
142 auto doBuffer = [&](std::optional<TileID> tile,
int offset,
145 if (tiles.count(*tile))
146 for (
auto buf : buffers[tiles[*tile]])
147 writeLDScriptMap(output, buf, offset);
149 output <<
"/* No tile with memory exists to the " << dir <<
". */\n";
150 output <<
". = 0x" << llvm::utohexstr(offset) <<
";\n";
151 uint32_t localMemSize = targetModel.getLocalMemorySize();
152 output <<
". += 0x" << llvm::utohexstr(localMemSize) <<
";\n";
158 << llvm::utohexstr(targetModel.getMemInternalBaseAddress(srcCoord))
160 output <<
"_sp_start_value_DM_stack = .;\n";
162 if (
auto core = tile.getCoreOp())
163 output <<
". += 0x" << llvm::utohexstr(core.getStackSize())
164 <<
"; /* stack */\n";
166 output <<
"/* no stack allocated */\n";
168 doBuffer(targetModel.getMemSouth(srcCoord),
169 targetModel.getMemSouthBaseAddress(), std::string(
"south"));
170 doBuffer(targetModel.getMemWest(srcCoord),
171 targetModel.getMemWestBaseAddress(), std::string(
"west"));
172 doBuffer(targetModel.getMemNorth(srcCoord),
173 targetModel.getMemNorthBaseAddress(), std::string(
"north"));
174 doBuffer(targetModel.getMemEast(srcCoord),
175 targetModel.getMemEastBaseAddress(), std::string(
"east"));
177 output <<
" .bss : { *(.bss*) } > data\n";
181 if (
auto coreOp = tile.getCoreOp()) {
182 if (
auto filesAttr = coreOp.getLinkFiles()) {
184 for (
auto f : filesAttr->getAsRange<
mlir::StringAttr>())
185 output <<
"INPUT(" << f.getValue() <<
")\n";
186 }
else if (
auto fileAttr = coreOp.getLinkWith()) {
189 output <<
"INPUT(" << fileAttr.value().str() <<
")\n";
192 output <<
"PROVIDE(main = core_" << tile.getCol() <<
"_"
193 << tile.getRow() <<
");\n";
Include the generated interface declarations.
void collectTiles(DeviceOp &device, llvm::DenseMap< TileID, mlir::Operation * > &tiles)
void collectBuffers(DeviceOp &device, llvm::DenseMap< mlir::Operation *, llvm::SmallVector< BufferOp, 4 > > &buffers)
mlir::LogicalResult AIETranslateToLdScript(mlir::ModuleOp module, llvm::raw_ostream &output, int tileCol, int tileRow, llvm::StringRef deviceName="")
TileID { friend std::ostream &operator<<(std::ostream &os, const TileID &s) { os<< "TileID("<< s.col<< ", "<< s.row<< ")" TileID
int32_t getBufferBaseAddress(mlir::Operation *bufOp)
const AIETargetModel & getTargetModel(mlir::Operation *op)