|
1 | 1 | #include "Design.h" |
2 | 2 |
|
| 3 | +#include <cmath> |
3 | 4 | #include <cstdint> |
4 | 5 | #include <iostream> |
5 | 6 | #include <set> |
| 7 | +#include <tuple> |
6 | 8 | #include <utility> |
7 | 9 | #include <vector> |
8 | 10 |
|
9 | 11 | #include "CUGR.h" |
10 | 12 | #include "GeoTypes.h" |
| 13 | +#include "Layers.h" |
11 | 14 | #include "Netlist.h" |
12 | 15 | #include "db_sta/dbSta.hh" |
13 | 16 | #include "odb/PtrSetMap.h" |
@@ -57,6 +60,8 @@ void Design::read() |
57 | 60 |
|
58 | 61 | computeGrid(); |
59 | 62 |
|
| 63 | + computeViaDemandLengths(); |
| 64 | + |
60 | 65 | if (verbose_) { |
61 | 66 | logger_->report("Design statistics"); |
62 | 67 | logger_->report("Nets: {}", nets_.size()); |
@@ -347,6 +352,135 @@ void Design::setUnitCosts() |
347 | 352 | } |
348 | 353 | } |
349 | 354 |
|
| 355 | +odb::dbTechVia* Design::chooseViaForPair(odb::dbTechLayer* lower_tl, |
| 356 | + odb::dbTechLayer* upper_tl) const |
| 357 | +{ |
| 358 | + // Rank vias connecting the pair by a drt-like priority: OR_DEFAULT, then |
| 359 | + // fewest cuts, then LEF-default, then smallest enclosure. |
| 360 | + odb::dbTechLayer* cut_tl = lower_tl->getUpperLayer(); |
| 361 | + odb::dbTechVia* best = nullptr; |
| 362 | + std::tuple<bool, int, bool, int64_t> best_key; |
| 363 | + for (odb::dbTechVia* via : tech_->getVias()) { |
| 364 | + if (via->getBottomLayer() != lower_tl || via->getTopLayer() != upper_tl) { |
| 365 | + continue; |
| 366 | + } |
| 367 | + int cuts = 0; |
| 368 | + int64_t enc_area = 0; |
| 369 | + for (odb::dbBox* box : via->getBoxes()) { |
| 370 | + odb::dbTechLayer* bl = box->getTechLayer(); |
| 371 | + if (bl == cut_tl) { |
| 372 | + cuts++; |
| 373 | + } else if (bl == lower_tl || bl == upper_tl) { |
| 374 | + enc_area += box->getBox().area(); |
| 375 | + } |
| 376 | + } |
| 377 | + const bool or_default |
| 378 | + = odb::dbStringProperty::find(via, "OR_DEFAULT") != nullptr; |
| 379 | + const std::tuple<bool, int, bool, int64_t> key{ |
| 380 | + !or_default, cuts, !via->isDefault(), enc_area}; |
| 381 | + if (best == nullptr || key < best_key) { |
| 382 | + best = via; |
| 383 | + best_key = key; |
| 384 | + } |
| 385 | + } |
| 386 | + return best; |
| 387 | +} |
| 388 | + |
| 389 | +void Design::computeViaDemandLengths() |
| 390 | +{ |
| 391 | + const int num_layers = getNumLayers(); |
| 392 | + // Fallback proxy (min-area stub x via_multiplier) for pairs with no via. |
| 393 | + via_demand_length_lower_.assign(num_layers, 0.0); |
| 394 | + via_demand_length_upper_.assign(num_layers, 0.0); |
| 395 | + |
| 396 | + const bool debug = logger_->debugCheck(utl::GRT, "via_geom", 1); |
| 397 | + int fallback_pairs = 0; |
| 398 | + for (int i = 0; i + 1 < num_layers; i++) { |
| 399 | + const MetalLayer& lower = layers_[i]; |
| 400 | + const MetalLayer& upper = layers_[i + 1]; |
| 401 | + odb::dbTechLayer* lower_tl = lower.getTechLayer(); |
| 402 | + odb::dbTechLayer* upper_tl = upper.getTechLayer(); |
| 403 | + odb::dbTechVia* via = chooseViaForPair(lower_tl, upper_tl); |
| 404 | + if (via == nullptr) { |
| 405 | + fallback_pairs++; |
| 406 | + } |
| 407 | + |
| 408 | + double num_lower = lower.getMinLength() * constants_.via_multiplier; |
| 409 | + double num_upper = upper.getMinLength() * constants_.via_multiplier; |
| 410 | + // Union the boxes on each layer; a via may have several rects per layer. |
| 411 | + odb::Rect lo_box, up_box; |
| 412 | + lo_box.mergeInit(); |
| 413 | + up_box.mergeInit(); |
| 414 | + if (via != nullptr) { |
| 415 | + for (odb::dbBox* box : via->getBoxes()) { |
| 416 | + if (box->getTechLayer() == lower_tl) { |
| 417 | + lo_box.merge(box->getBox()); |
| 418 | + } else if (box->getTechLayer() == upper_tl) { |
| 419 | + up_box.merge(box->getBox()); |
| 420 | + } |
| 421 | + } |
| 422 | + if (!lo_box.isInverted() && lo_box.dx() > 0 && lo_box.dy() > 0) { |
| 423 | + num_lower = viaDemandLength(lower, lo_box.dx(), lo_box.dy()); |
| 424 | + } |
| 425 | + if (!up_box.isInverted() && up_box.dx() > 0 && up_box.dy() > 0) { |
| 426 | + num_upper = viaDemandLength(upper, up_box.dx(), up_box.dy()); |
| 427 | + } |
| 428 | + } |
| 429 | + via_demand_length_lower_[i] = num_lower; |
| 430 | + via_demand_length_upper_[i] = num_upper; |
| 431 | + |
| 432 | + if (debug) { |
| 433 | + // Report enclosures, lengths, and per-track demand for each pair. |
| 434 | + const int gcell = default_gridline_spacing_; |
| 435 | + const std::string via_src |
| 436 | + = via != nullptr ? via->getName() : std::string("min_area-fallback"); |
| 437 | + debugPrint( |
| 438 | + logger_, |
| 439 | + utl::GRT, |
| 440 | + "via_geom", |
| 441 | + 1, |
| 442 | + "via {}->{} [{}]: encl lower={}x{} upper={}x{} -> len " |
| 443 | + "lower={:.1f} upper={:.1f} -> demand lower={:.4f} upper={:.4f}", |
| 444 | + lower.getName(), |
| 445 | + upper.getName(), |
| 446 | + via_src, |
| 447 | + lo_box.isInverted() ? 0 : lo_box.dx(), |
| 448 | + lo_box.isInverted() ? 0 : lo_box.dy(), |
| 449 | + up_box.isInverted() ? 0 : up_box.dx(), |
| 450 | + up_box.isInverted() ? 0 : up_box.dy(), |
| 451 | + num_lower, |
| 452 | + num_upper, |
| 453 | + gcell > 0 ? num_lower / gcell : 0.0, |
| 454 | + gcell > 0 ? num_upper / gcell : 0.0); |
| 455 | + } |
| 456 | + } |
| 457 | + |
| 458 | + if (fallback_pairs > 0) { |
| 459 | + logger_->warn(utl::GRT, |
| 460 | + 173, |
| 461 | + "{} layer pair(s) have no via; using min-area via demand.", |
| 462 | + fallback_pairs); |
| 463 | + } |
| 464 | +} |
| 465 | + |
| 466 | +double Design::viaDemandLength(const MetalLayer& layer, |
| 467 | + const int dx, |
| 468 | + const int dy) const |
| 469 | +{ |
| 470 | + const int pitch = layer.getPitch(); |
| 471 | + // getSpacing() is 0 on parallel-table-only techs; use default spacing then. |
| 472 | + const int spacing |
| 473 | + = layer.getSpacing() > 0 ? layer.getSpacing() : layer.getDefaultSpacing(); |
| 474 | + // Split the pad into extent along the routing direction and across tracks. |
| 475 | + const int along = (layer.getDirection() == MetalLayer::H) ? dx : dy; |
| 476 | + const int perp = (layer.getDirection() == MetalLayer::H) ? dy : dx; |
| 477 | + // A via blocks whole tracks; ceil the keep-out to an integer track count. |
| 478 | + const double tracks_blocked |
| 479 | + = pitch > 0 ? std::ceil(static_cast<double>(perp + 2 * spacing) / pitch) |
| 480 | + : 1.0; |
| 481 | + return along * tracks_blocked; |
| 482 | +} |
| 483 | + |
350 | 484 | void Design::getAllObstacles(std::vector<std::vector<BoxT>>& all_obstacles, |
351 | 485 | const bool skip_m1) const |
352 | 486 | { |
|
0 commit comments