30 int tileCol,
int tileRow) {
31 DenseMap<TileID, Operation *> tiles;
32 DenseMap<Operation *, SmallVector<BufferOp, 4>> buffers;
34 if (module.getOps<DeviceOp>().empty())
35 module.emitOpError("expected aie.device operation at toplevel");
36 DeviceOp targetOp = *(
module.getOps<DeviceOp>().begin());
38 collectTiles(targetOp, tiles);
39 collectBuffers(targetOp, buffers);
52 for (
auto tile : targetOp.getOps<TileOp>())
53 if (tile.colIndex() == tileCol && tile.rowIndex() == tileRow) {
55 TileID srcCoord = {tile.colIndex(), tile.rowIndex()};
57 std::string corefunc = std::string(
"core_") +
58 std::to_string(tile.getCol()) +
"_" +
59 std::to_string(tile.getRow());
60 output <<
"_entry_point _main_init\n";
61 output <<
"_symbol " << corefunc <<
" _after _main_init\n";
62 output <<
"_symbol _main_init 0\n";
63 int dataMemoryStart = targetModel.getMemSouthBaseAddress();
64 output <<
"_reserved DMb 0x00000 " <<
utohexstr(dataMemoryStart)
65 <<
" // Don't put data in code memory\n";
68 if (
auto core = tile.getCoreOp())
69 stacksize = core.getStackSize();
70 output <<
"_stack DM_stack "
71 <<
utohexstr(targetModel.getMemInternalBaseAddress(srcCoord))
72 <<
" " <<
utohexstr(stacksize) <<
" // stack for core\n";
74 auto doBuffer = [&](std::optional<TileID> tile,
int offset,
75 const std::string &dir) {
77 output <<
"// " + dir +
79 " -------------------------------------------------\n";
80 uint32_t localMemSize = targetModel.getLocalMemorySize();
82 output <<
"_reserved DMb " <<
utohexstr(offset) <<
" "
84 <<
" // Don't allocate variables in " << dir
88 if (tiles.count(*tile)) {
89 for (
auto buf : buffers[tiles[*tile]]) {
90 std::string bufName(buf.name().getValue());
92 int numBytes = buf.getAllocationSize();
93 if (buf.getInitialValue() && tile != srcCoord) {
94 output <<
"// skip initialization of " << buf.name()
95 <<
" which is initialized "
96 "in the neighboring tile\n";
99 }
else if (buf.getInitialValue() && tile == srcCoord) {
100 output <<
"_overlay " << bufName <<
" "
101 <<
utohexstr(offset + bufferBaseAddr) <<
" // "
102 << numBytes <<
" bytes\n";
104 output <<
"_symbol " << bufName <<
" "
105 <<
utohexstr(offset + bufferBaseAddr) <<
" " << numBytes
107 output <<
"_extern " << bufName <<
"\n";
108 output <<
"_reserved DMb " <<
utohexstr(offset + bufferBaseAddr)
109 <<
" " << numBytes <<
'\n';
115 uint32_t localMemSize = targetModel.getLocalMemorySize();
116 output <<
"_reserved DMb " <<
utohexstr(offset) <<
" "
118 <<
" // No tile with memory exists to the " << dir <<
".\n";
122 output <<
"\n// mapping neighbors tile memory\n";
123 doBuffer(targetModel.getMemSouth(srcCoord),
124 targetModel.getMemSouthBaseAddress(), std::string(
"south"));
125 doBuffer(targetModel.getMemWest(srcCoord),
126 targetModel.getMemWestBaseAddress(), std::string(
"west"));
127 doBuffer(targetModel.getMemNorth(srcCoord),
128 targetModel.getMemNorthBaseAddress(), std::string(
"north"));
129 doBuffer(targetModel.getMemEast(srcCoord),
130 targetModel.getMemEastBaseAddress(), std::string(
"east"));
131 output <<
"// end mapping neighbors tile memory\n\n";
133 int addressSpaceSize = 0x100000;
134 int dataMemoryEnd = targetModel.getMemEastBaseAddress() +
135 targetModel.getLocalMemorySize();
136 output <<
"_reserved DMb " <<
utohexstr(dataMemoryEnd) <<
" "
137 <<
utohexstr(addressSpaceSize - dataMemoryEnd)
138 <<
" // And everything else the core can't see\n";
140 if (tile.getCoreOp() && tile.getCoreOp().getLinkWith())
141 output <<
"_include _file "
142 << tile.getCoreOp().getLinkWith().value().str() <<
"\n";
143 output <<
"_resolve _main core_" << tile.getCol() <<
"_" << tile.getRow()