Debian Codegraph @

himbaechel/uarch/xilinx/xilinx_place.cc

raw
1 /*
2 * nextpnr -- Next Generation Place and Route
3 *
4 * Copyright (C) 2019-2023 gatecat <[email protected]>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 */
19
20 #include <boost/algorithm/string.hpp>
21 #include <regex>
22
23 #include "extra_data.h"
24 #include "himbaechel_api.h"
25 #include "log.h"
26 #include "nextpnr.h"
27 #include "util.h"
28
29 #include "xilinx.h"
30
31 #define HIMBAECHEL_CONSTIDS "uarch/xilinx/constids.inc"
32 #include "himbaechel_constids.h"
33
34 NEXTPNR_NAMESPACE_BEGIN
35
36 // #define DEBUG_VALIDITY
37 #ifdef DEBUG_VALIDITY
38 #define DBG() log_info("invalid: %s %d\n", __FILE__, __LINE__)
39 #else
40 #define DBG()
41 #endif
42
43 bool XilinxImpl::xc7_logic_tile_valid(IdString tile_type, const LogicTileStatus &lts) const
44 {
45 bool is_slicem = (tile_type == id_CLBLM_L) || (tile_type == id_CLBLM_R);
46 bool tile_is_memory = false;
47 if (lts.cells[(3 << 4) | BEL_6LUT] != nullptr && get_tags(lts.cells[(3 << 4) | BEL_6LUT])->lut.is_memory)
48 tile_is_memory = true;
49 bool small_memory = false;
50 if (lts.cells[(3 << 4) | BEL_5LUT] != nullptr && get_tags(lts.cells[(3 << 4) | BEL_5LUT])->lut.is_memory)
51 small_memory = true;
52 NetInfo *wclk = nullptr;
53 // Check eight-tiles (mostly LUT-related validity)
54 for (int i = 0; i < 8; i++) {
55 if (lts.eights[i].dirty) {
56 lts.eights[i].dirty = false;
57 lts.eights[i].valid = false;
58
59 auto lut6 = get_tags(lts.cells[(i << 4) | BEL_6LUT]);
60 auto lut5 = get_tags(lts.cells[(i << 4) | BEL_5LUT]);
61
62 // Check 6LUT
63 if (lut6) {
64 if (!is_slicem && (lut6->lut.is_memory || lut6->lut.is_srl)) {
65 DBG();
66 return false;
67 } // Memory and SRLs only valid in SLICEMs
68 if (lut6->lut.is_srl && (i >= 4)) {
69 DBG();
70 return false;
71 }
72 if (lut6->lut.is_memory || lut6->lut.is_srl) {
73 if (wclk == nullptr)
74 wclk = lut6->lut.wclk;
75 else if (lut6->lut.wclk != wclk) {
76 DBG();
77 return false;
78 }
79 }
80 if (lut5) {
81 // Can't mix memory and non-memory
82 if (lut6->lut.is_memory != lut5->lut.is_memory || lut6->lut.is_srl != lut5->lut.is_srl) {
83 DBG();
84 return false;
85 }
86 // If all 6 inputs or 2 outputs are used, 5LUT can't also be present
87 if (lut6->lut.input_count == 6 || lut6->lut.output_count == 2) {
88 DBG();
89 return false;
90 }
91 // If more than 5 total inputs are used, need to check number of shared input
92 if ((lut6->lut.input_count + lut5->lut.input_count) > 5) {
93 int shared = 0, need_shared = (lut6->lut.input_count + lut5->lut.input_count - 5);
94 for (int j = 0; j < lut6->lut.input_count; j++) {
95 for (int k = 0; k < lut5->lut.input_count; k++) {
96 if (lut6->lut.input_sigs[j] == lut5->lut.input_sigs[k])
97 shared++;
98 if (shared >= need_shared)
99 break;
100 }
101 }
102 if (shared < need_shared) {
103 DBG();
104 return false;
105 }
106 }
107 }
108 }
109 if (lut5 != nullptr) {
110 if (!is_slicem && (lut5->lut.is_memory || lut5->lut.is_srl)) {
111 DBG();
112 return false; // Memory and SRLs only valid in SLICEMs
113 }
114 if (lut5->lut.is_srl) {
115 if (wclk == nullptr)
116 wclk = lut5->lut.wclk;
117 else if (lut5->lut.wclk != wclk) {
118 DBG();
119 return false;
120 }
121 }
122 // 5LUT can use at most 5 inputs and 1 output
123 if (lut5->lut.input_count > 5 || lut5->lut.output_count == 2) {
124 DBG();
125 return false; // Memory and SRLs only valid in SLICEMs
126 }
127 }
128
129 // Check (over)usage ofX inputs
130 NetInfo *x_net = nullptr;
131 if (lut6) {
132 x_net = lut6->lut.di2_net;
133 }
134
135 CellInfo *mux_cell = nullptr;
136 // Eights A, C, E, G: F7MUX uses X input
137 if (i == 0 || i == 2 || i == 4 || i == 6)
138 mux_cell = lts.cells[i << 4 | BEL_F7MUX];
139 // Eights B, F: F8MUX uses X input
140 if (i == 1 || i == 5)
141 mux_cell = lts.cells[(i - 1) << 4 | BEL_F8MUX];
142 auto mux = get_tags(mux_cell);
143 if (mux) {
144 if (!x_net)
145 x_net = mux->mux.sel;
146 else if (x_net != mux->mux.sel) {
147 DBG();
148 return false; // conflict between existing X use and mux select
149 }
150 }
151
152 CellInfo *out_fmux_cell = nullptr;
153 // Subslices A, C: F7MUX connects to F7F8 out
154 if (i == 0 || i == 2 || i == 4 || i == 6)
155 out_fmux_cell = lts.cells[(i << 4) | BEL_F7MUX];
156 // Subslices B: F8MUX connects to F7F8 out
157 if (i == 1 || i == 5)
158 out_fmux_cell = lts.cells[(i - 1) << 4 | BEL_F8MUX];
159
160 auto carry4 = get_tags(lts.cells[((i / 4) << 6) | BEL_CARRY4]);
161
162 if (carry4 != nullptr && carry4->carry.x_sigs[i % 4] != nullptr) {
163 if (x_net == nullptr)
164 x_net = carry4->carry.x_sigs[i % 4];
165 else if (x_net != carry4->carry.x_sigs[i % 4]) {
166 DBG();
167 return false;
168 }
169 }
170
171 // FF1 might use X, if it isn't driven directly
172 auto ff1 = get_tags(lts.cells[i << 4 | BEL_FF]);
173 if (ff1 != nullptr && ff1->ff.d != nullptr && ff1->ff.d->driver.cell != nullptr) {
174 auto &drv = ff1->ff.d->driver;
175 if ((drv.cell == lts.cells[(i << 4) | BEL_6LUT] && drv.port != id_MC31) ||
176 drv.cell == lts.cells[(i << 4) | BEL_5LUT] || drv.cell == out_fmux_cell) {
177 // Direct, OK
178 } else {
179 // Indirect, must use X input
180 if (x_net == nullptr)
181 x_net = ff1->ff.d;
182 else if (x_net != ff1->ff.d) {
183 DBG();
184 return false;
185 }
186 }
187 }
188
189 // FF2 might use X, if it isn't driven directly
190 auto ff2 = get_tags(lts.cells[i << 4 | BEL_FF2]);
191 if (ff2 != nullptr && ff2->ff.d != nullptr && ff2->ff.d->driver.cell != nullptr) {
192 auto &drv = ff2->ff.d->driver;
193 if (drv.cell == lts.cells[(i << 4) | BEL_5LUT]) {
194 // Direct, OK
195 } else {
196 // Indirect, must use X input
197 if (x_net == nullptr)
198 x_net = ff2->ff.d;
199 else if (x_net != ff2->ff.d) {
200 DBG();
201 return false;
202 }
203 }
204 }
205
206 // collision with top address bits
207 if (tile_is_memory && !small_memory) {
208 auto top_lut = get_tags(lts.cells[(3 << 4) | BEL_6LUT]);
209 if (top_lut) {
210 if ((i == 2) && x_net != top_lut->lut.address_msb[0]) {
211 DBG();
212 return false;
213 }
214 if ((i == 1) && x_net != top_lut->lut.address_msb[1]) {
215 DBG();
216 return false;
217 }
218 }
219 }
220
221 bool mux_output_used = false;
222 NetInfo *out5 = nullptr;
223 if (lut6 != nullptr && lut6->lut.output_count == 2)
224 out5 = lut6->lut.output_sigs[1];
225 else if (lut5 != nullptr && !lut5->lut.only_drives_carry)
226 out5 = lut5->lut.output_sigs[0];
227 if (out5 != nullptr && (out5->users.entries() > 1 ||
228 ((ff1 == nullptr || out5 != ff1->ff.d) && (ff2 == nullptr || out5 != ff2->ff.d)))) {
229 mux_output_used = true;
230 }
231
232 if (carry4 != nullptr && carry4->carry.out_sigs[i % 4] != nullptr) {
233 // FIXME: direct connections to FF
234 if (mux_output_used) {
235 DBG();
236 return false; // Memory and SRLs only valid in SLICEMs
237 }
238 mux_output_used = true;
239 }
240 if (out_fmux_cell != nullptr) {
241 auto out_fmux = get_tags(out_fmux_cell);
242 NetInfo *f7f8 = out_fmux->mux.out;
243 if (f7f8 != nullptr && (f7f8->users.entries() > 1 || ((ff1 == nullptr || f7f8 != ff1->ff.d)))) {
244 if (mux_output_used) {
245 DBG();
246 return false; // Memory and SRLs only valid in SLICEMs
247 }
248 mux_output_used = true;
249 }
250 }
251 if (ff2 != nullptr) {
252 if (mux_output_used) {
253 DBG();
254 return false; // Memory and SRLs only valid in SLICEMs
255 }
256 mux_output_used = true;
257 }
258
259 lts.eights[i].valid = true;
260 } else if (!lts.eights[i].valid) {
261 DBG();
262 return false;
263 }
264 }
265 // Check half-tiles
266 for (int i = 0; i < 2; i++) {
267 if (lts.halfs[i].dirty) {
268 lts.halfs[i].valid = false;
269 bool found_ff[2] = {false, false};
270 if (i == 0 && wclk == nullptr) {
271 // Need to check wclk too
272 for (int z = 4 * i; z < 4 * (i + 1); z++) {
273 for (int k = 0; k < 2; k++) {
274 auto lut = get_tags(lts.cells[z << 4 | (BEL_6LUT + k)]);
275 if (!lut)
276 continue;
277 if (!lut->lut.is_memory && !lut->lut.is_srl)
278 continue;
279 if (lut->lut.wclk != nullptr) {
280 wclk = lut->lut.wclk;
281 break;
282 }
283 }
284 }
285 }
286 NetInfo *clk = nullptr, *sr = nullptr, *ce = nullptr;
287 bool clkinv = false, srinv = false, islatch = false, ffsync = false;
288 for (int z = 4 * i; z < 4 * (i + 1); z++) {
289 for (int k = 0; k < 2; k++) {
290 auto ff = get_tags(lts.cells[z << 4 | (BEL_FF + k)]);
291 if (ff == nullptr)
292 continue;
293 if (ff->ff.is_latch && k == 1) {
294 DBG();
295 return false;
296 }
297 if (found_ff[0] || found_ff[1]) {
298 if (ff->ff.clk != clk) {
299 DBG();
300 return false;
301 }
302 if (ff->ff.sr != sr) {
303 DBG();
304 return false;
305 }
306 if (ff->ff.ce != ce) {
307 DBG();
308 return false;
309 }
310 if (ff->ff.is_clkinv != clkinv) {
311 DBG();
312 return false;
313 }
314 if (ff->ff.is_srinv != srinv) {
315 DBG();
316 return false;
317 }
318 if (ff->ff.is_latch != islatch) {
319 DBG();
320 return false;
321 }
322 if (ff->ff.ffsync != ffsync) {
323 DBG();
324 return false;
325 }
326 } else {
327 clk = ff->ff.clk;
328 if (i == 0 && wclk != nullptr && clk != wclk) {
329 DBG();
330 return false;
331 }
332 sr = ff->ff.sr;
333 ce = ff->ff.ce;
334 clkinv = ff->ff.is_clkinv;
335 srinv = ff->ff.is_srinv;
336 islatch = ff->ff.is_latch;
337 ffsync = ff->ff.ffsync;
338 }
339 found_ff[k] = true;
340 }
341 }
342 lts.halfs[i].valid = true;
343 } else if (!lts.halfs[i].valid) {
344 DBG();
345 return false;
346 }
347 }
348 return true;
349 }
350
351 bool XilinxImpl::isBelLocationValid(BelId bel, bool explain_invalid) const
352 {
353 if (is_logic_tile(bel)) {
354 if (!tile_status.at(bel.tile).lts)
355 return true;
356 return xc7_logic_tile_valid(bel_tile_type(bel), *tile_status.at(bel.tile).lts);
357 } else if (is_bram_tile(bel)) {
358 const auto &bts = tile_status.at(bel.tile).bts;
359 if (!bts)
360 return true;
361 auto onehot = [&](CellInfo *a, CellInfo *b, CellInfo *c) {
362 return (((a != nullptr) ? 1 : 0) + ((b != nullptr) ? 1 : 0) + ((c != nullptr) ? 1 : 0)) <= 1;
363 };
364 // Only one type of BRAM cell at any given location
365 if (!onehot(bts->cells[BEL_RAMFIFO36], bts->cells[BEL_RAM36], bts->cells[BEL_FIFO36])) {
366 DBG();
367 return false;
368 }
369 if (!onehot(bts->cells[BEL_RAMFIFO18_L], bts->cells[BEL_RAM18_L], bts->cells[BEL_FIFO18_L])) {
370 DBG();
371 return false;
372 }
373 // 18-bit BRAMs cannot be used whilst 36-bit is used
374 if (bts->cells[BEL_RAMFIFO36] || bts->cells[BEL_RAM36] || bts->cells[BEL_FIFO36]) {
375 for (int i = 4; i < 12; i++)
376 if (bts->cells[i]) {
377 DBG();
378 return false;
379 }
380 }
381 }
382 return true;
383 }
384
385 void XilinxImpl::fixup_placement()
386 {
387 log_info("Running post-placement legalisation...\n");
388 for (auto &ts : tile_status) {
389 if (!ts.lts)
390 continue;
391 auto &lt = *(ts.lts);
392 for (int z = 0; z < 8; z++) {
393 // Fixup LUT connectivity - applies whenever a LUT5 is used
394 CellInfo *lut5 = lt.cells[z << 4 | BEL_5LUT];
395 if (!lut5)
396 continue;
397 auto l5_tags = get_tags(lut5);
398 dict<IdString, std::vector<int>> lut5Inputs, lut6Inputs;
399 for (int i = 0; i < l5_tags->lut.input_count; i++)
400 if (l5_tags->lut.input_sigs[i])
401 lut5Inputs[l5_tags->lut.input_sigs[i]->name].push_back(i);
402 CellInfo *lut6 = lt.cells[z << 4 | BEL_6LUT];
403 if (lut6) {
404 auto l6_tags = get_tags(lut6);
405 for (int i = 0; i < l6_tags->lut.input_count; i++)
406 if (l6_tags->lut.input_sigs[i])
407 lut6Inputs[l6_tags->lut.input_sigs[i]->name].push_back(i);
408 }
409 if (l5_tags->lut.is_memory || l5_tags->lut.is_srl) {
410 if (lut6) {
411 if (!lut6->ports.count(id_A6)) {
412 lut6->addInput(id_A6);
413 }
414 lut6->connectPort(id_A6, ctx->nets.at(ctx->id("$PACKER_VCC_NET")).get());
415 }
416 continue;
417 }
418 std::set<IdString> uniqueInputs;
419 for (auto i5 : lut5Inputs)
420 uniqueInputs.insert(i5.first);
421 for (auto i6 : lut6Inputs)
422 uniqueInputs.insert(i6.first);
423 // Disconnect LUT inputs, and re-connect them to not overlap
424 IdString ports[6] = {id_A1, id_A2, id_A3, id_A4, id_A5, id_A6};
425 for (auto p : ports) {
426 lut5->disconnectPort(p);
427 lut5->attrs.erase(ctx->idf("X_ORIG_PORT_%s", p.c_str(ctx)));
428 if (lut6) {
429 lut6->attrs.erase(ctx->idf("X_ORIG_PORT_%s", p.c_str(ctx)));
430 lut6->disconnectPort(p);
431 }
432 }
433 int index = 0;
434 for (auto i : uniqueInputs) {
435 if (lut5Inputs.count(i)) {
436 if (!lut5->ports.count(ports[index])) {
437 lut5->ports[ports[index]].name = ports[index];
438 lut5->ports[ports[index]].type = PORT_IN;
439 }
440 lut5->connectPort(ports[index], ctx->nets.at(i).get());
441 lut5->attrs[ctx->idf("X_ORIG_PORT_%s", ports[index].c_str(ctx))] = std::string("");
442 bool first = true;
443 for (auto inp : lut5Inputs[i]) {
444 lut5->attrs[ctx->idf("X_ORIG_PORT_%s", ports[index].c_str(ctx))].str +=
445 (first ? "I" : " I") + std::to_string(inp);
446 first = false;
447 }
448 }
449 if (lut6 && lut6Inputs.count(i)) {
450 if (!lut6->ports.count(ports[index])) {
451 lut6->ports[ports[index]].name = ports[index];
452 lut6->ports[ports[index]].type = PORT_IN;
453 }
454 lut6->connectPort(ports[index], ctx->nets.at(i).get());
455
456 lut6->attrs[ctx->idf("X_ORIG_PORT_%s", ports[index].c_str(ctx))] = std::string("");
457 bool first = true;
458 for (auto inp : lut6Inputs[i]) {
459 lut6->attrs[ctx->idf("X_ORIG_PORT_%s", ports[index].c_str(ctx))].str +=
460 (first ? "I" : " I") + std::to_string(inp);
461 first = false;
462 }
463 }
464 ++index;
465 }
466 lut5->renamePort(id_O6, id_O5);
467 lut5->attrs.erase(id_X_ORIG_PORT_O6);
468 lut5->attrs[id_X_ORIG_PORT_O5] = std::string("O");
469
470 if (lut6) {
471 if (!lut6->ports.count(id_A6)) {
472 lut6->addInput(id_A6);
473 }
474 lut6->connectPort(id_A6, ctx->nets.at(ctx->id("$PACKER_VCC_NET")).get());
475 }
476 }
477 }
478 for (auto &cell : ctx->cells) {
479 CellInfo *ci = cell.second.get();
480 if (ci->type == id_PS7_PS7) {
481 log_info("Tieing unused PS7 inputs to constants...\n");
482 for (IdString pname : ctx->getBelPins(ci->bel)) {
483 if (ci->ports.count(pname) && ci->ports.at(pname).net != nullptr &&
484 ci->ports.at(pname).net->driver.cell != nullptr)
485 continue;
486 if (ctx->getBelPinType(ci->bel, pname) != PORT_IN)
487 continue;
488 std::string name = pname.str(ctx);
489 if (name.find("_PAD_") != std::string::npos)
490 continue;
491 if (boost::starts_with(name, "TEST") || boost::starts_with(name, "DEBUGSELECT") ||
492 boost::starts_with(name, "MIO") || boost::starts_with(name, "DDR"))
493 continue;
494 bool constval = false;
495 ci->ports[pname].name = pname;
496 ci->ports[pname].type = PORT_IN;
497 if (ci->ports[pname].net != nullptr) {
498 ci->disconnectPort(pname);
499 ci->attrs.erase(ctx->idf("X_ORIG_PORT_", name.c_str()));
500 }
501 ci->connectPort(pname,
502 ctx->nets.at(constval ? ctx->id("$PACKER_VCC_NET") : ctx->id("$PACKER_GND_NET")).get());
503 }
504 }
505 }
506 }
507
508 void XilinxImpl::fixup_routing()
509 {
510 log_info("Running post-routing legalisation...\n");
511 /*
512 * Convert LUT permutation into correct physical connections (i.e. effectively eliminating the permutation pips),
513 * then specifying the permutation as a new physical-to-logical mapping using X_ORIG_PORT. This keeps RapidWright
514 * and Vivado happy, preserving the original logical netlist
515 */
516 dict<int, std::vector<int>> used_perm_pips; // tile -> [extra_data] for LUT perm pips
517
518 for (auto &net : ctx->nets) {
519 NetInfo *ni = net.second.get();
520 for (auto &wire : ni->wires) {
521 PipId pip = wire.second.pip;
522 if (pip == PipId())
523 continue;
524 auto &pd = chip_pip_info(ctx->chip_info, pip);
525 if (pd.flags != PIP_LUT_PERMUTATION)
526 continue;
527 const auto &extra_data = *reinterpret_cast<const XlnxPipExtraDataPOD *>(pd.extra_data.get());
528 used_perm_pips[pip.tile].push_back(extra_data.pip_config);
529 }
530 }
531
532 for (size_t ti = 0; ti < tile_status.size(); ti++) {
533 if (!used_perm_pips.count(int(ti)))
534 continue;
535 auto &ts = tile_status.at(ti);
536 if (!ts.lts)
537 continue;
538
539 auto &lt = *ts.lts;
540 for (int z = 0; z < 8; z++) {
541 CellInfo *lut5 = lt.cells[z << 4 | BEL_5LUT];
542 CellInfo *lut6 = lt.cells[z << 4 | BEL_6LUT];
543 if (lut5 == nullptr && lut6 == nullptr)
544 continue;
545 auto &pp = used_perm_pips.at(ti);
546 // from -> to
547 dict<IdString, std::vector<IdString>> new_connections;
548 IdString ports[6] = {id_A1, id_A2, id_A3, id_A4, id_A5, id_A6};
549 for (auto pip : pp) {
550 if (((pip >> 8) & 0xF) != z)
551 continue;
552 new_connections[ports[(pip >> 4) & 0xF]].push_back(ports[pip & 0xF]);
553 }
554 dict<IdString, NetInfo *> orig_nets;
555 dict<IdString, std::string> orig_ports_l6, orig_ports_l5;
556 for (int i = 0; i < 6; i++) {
557 NetInfo *l6net = lut6 ? lut6->getPort(ports[i]) : nullptr;
558 NetInfo *l5net = lut5 ? lut5->getPort(ports[i]) : nullptr;
559 orig_nets[ports[i]] = (l6net ? l6net : l5net);
560 if (lut6)
561 orig_ports_l6[ports[i]] =
562 str_or_default(lut6->attrs, ctx->idf("X_ORIG_PORT_%s", ports[i].c_str(ctx)));
563 if (lut5)
564 orig_ports_l5[ports[i]] =
565 str_or_default(lut5->attrs, ctx->idf("X_ORIG_PORT_%s", ports[i].c_str(ctx)));
566 }
567 for (auto &nc : new_connections) {
568 if (lut6)
569 lut6->disconnectPort(nc.first);
570 if (lut5)
571 lut5->disconnectPort(nc.first);
572 for (auto &dst : nc.second) {
573 if (lut6)
574 lut6->disconnectPort(dst);
575 if (lut5)
576 lut5->disconnectPort(dst);
577 }
578 }
579 for (int i = 0; i < 6; i++) {
580 if (lut6)
581 lut6->attrs.erase(ctx->idf("X_ORIG_PORT_%s", ports[i].c_str(ctx)));
582 if (lut5)
583 lut5->attrs.erase(ctx->idf("X_ORIG_PORT_%s", ports[i].c_str(ctx)));
584 }
585 for (int i = 0; i < 6; i++) {
586 auto p = ports[i];
587 if (!new_connections.count(p) || new_connections.at(p).empty())
588 continue;
589 if (lut6) {
590 if (!lut6->ports.count(p)) {
591 lut6->addInput(p);
592 }
593 lut6->connectPort(p, orig_nets[new_connections.at(p).front()]);
594 lut6->attrs[ctx->idf("X_ORIG_PORT_%s", p.c_str(ctx))] = std::string("");
595 auto &orig_attr = lut6->attrs[ctx->idf("X_ORIG_PORT_%s", p.c_str(ctx))].str;
596 bool first = true;
597 for (auto &nc : new_connections.at(p)) {
598 orig_attr += orig_ports_l6[nc] + (first ? "" : " ");
599 first = false;
600 }
601 if (orig_attr.empty())
602 lut6->attrs.erase(ctx->idf("X_ORIG_PORT_%s", p.c_str(ctx)));
603 }
604 if (lut5) {
605 if (!lut5->ports.count(p)) {
606 lut5->addInput(p);
607 }
608 lut5->connectPort(p, orig_nets[new_connections.at(p).front()]);
609 lut5->attrs[ctx->idf("X_ORIG_PORT_%s", p.c_str(ctx))] = std::string("");
610 auto &orig_attr = lut5->attrs[ctx->idf("X_ORIG_PORT_%s", p.c_str(ctx))].str;
611 bool first = true;
612 for (auto &nc : new_connections.at(p)) {
613 orig_attr += orig_ports_l5[nc] + (first ? "" : " ");
614 first = false;
615 }
616 if (orig_attr.empty())
617 lut5->attrs.erase(ctx->idf("X_ORIG_PORT_%s", p.c_str(ctx)));
618 }
619 }
620 }
621 }
622
623 /*
624 * Legalise route through OSERDESE3s
625 */
626 for (auto &cell : ctx->cells) {
627 CellInfo *ci = cell.second.get();
628 if (ci->type == id_OSERDESE3) {
629 if (ci->getPort(id_T_OUT) != nullptr)
630 continue;
631 ci->params[id_OSERDES_T_BYPASS] = std::string("TRUE");
632 }
633 }
634 }
635
636 NEXTPNR_NAMESPACE_END