|
3 | 3 |
|
4 | 4 | #include "UnbufferMove.hh" |
5 | 5 |
|
| 6 | +#include <algorithm> |
6 | 7 | #include <cmath> |
7 | 8 | #include <optional> |
8 | 9 | #include <string> |
|
14 | 15 | #include "SplitLoadMove.hh" |
15 | 16 | #include "SwapPinsMove.hh" |
16 | 17 | #include "odb/db.h" |
| 18 | +#include "odb/dbSet.h" |
17 | 19 | #include "rsz/Resizer.hh" |
18 | 20 | #include "sta/ArcDelayCalc.hh" |
19 | 21 | #include "sta/Delay.hh" |
@@ -373,13 +375,19 @@ bool UnbufferMove::removeBuffer(Instance* buffer) |
373 | 375 | odb::dbModNet* ip_modnet = db_network_->hierNet(in_pin); |
374 | 376 | odb::dbModNet* survivor_modnet = ip_modnet; |
375 | 377 | odb::dbModNet* removed_modnet = op_modnet; |
376 | | - bool in_net_has_port = db_network_->hasPort(in_net); |
377 | | - bool out_net_has_port = db_network_->hasPort(out_net); |
378 | | - if (!in_net_has_port && out_net_has_port) { |
379 | | - survivor = out_net; |
380 | | - removed = in_net; |
381 | | - survivor_modnet = op_modnet; |
382 | | - removed_modnet = ip_modnet; |
| 378 | + |
| 379 | + // When the buffer removal creates a feedthrough (input port directly |
| 380 | + // wired to output port), the input ModNet must survive so that |
| 381 | + // VerilogWriter sees port_name != net_name and emits the assign. |
| 382 | + if (!bufferRemovalCreatesFeedthrough(ip_modnet, op_modnet)) { |
| 383 | + bool in_net_has_port = db_network_->hasPort(in_net); |
| 384 | + bool out_net_has_port = db_network_->hasPort(out_net); |
| 385 | + if (!in_net_has_port && out_net_has_port) { |
| 386 | + survivor = out_net; |
| 387 | + removed = in_net; |
| 388 | + survivor_modnet = op_modnet; |
| 389 | + removed_modnet = ip_modnet; |
| 390 | + } |
383 | 391 | } |
384 | 392 |
|
385 | 393 | // Disconnect the buffer and handle the nets |
@@ -453,4 +461,29 @@ bool UnbufferMove::removeBuffer(Instance* buffer) |
453 | 461 | return true; |
454 | 462 | } |
455 | 463 |
|
| 464 | +// Check if removing a buffer creates a feedthrough: input port directly |
| 465 | +// wired to output port within the same module. |
| 466 | +bool UnbufferMove::bufferRemovalCreatesFeedthrough( |
| 467 | + odb::dbModNet* ip_modnet, |
| 468 | + odb::dbModNet* op_modnet) const |
| 469 | +{ |
| 470 | + if (!ip_modnet || !op_modnet |
| 471 | + || ip_modnet->getParent() != op_modnet->getParent()) { |
| 472 | + return false; |
| 473 | + } |
| 474 | + odb::dbSet<odb::dbModBTerm> ip_bterms = ip_modnet->getModBTerms(); |
| 475 | + const bool ip_has_input_port |
| 476 | + = std::ranges::any_of(ip_bterms, [](odb::dbModBTerm* bt) { |
| 477 | + return bt->getIoType() == odb::dbIoType::INPUT; |
| 478 | + }); |
| 479 | + |
| 480 | + odb::dbSet<odb::dbModBTerm> op_bterms = op_modnet->getModBTerms(); |
| 481 | + const bool op_has_output_port |
| 482 | + = std::ranges::any_of(op_bterms, [](odb::dbModBTerm* bt) { |
| 483 | + return bt->getIoType() == odb::dbIoType::OUTPUT; |
| 484 | + }); |
| 485 | + |
| 486 | + return ip_has_input_port && op_has_output_port; |
| 487 | +} |
| 488 | + |
456 | 489 | } // namespace rsz |
0 commit comments