2121#include " GRNet.h"
2222#include " GRTree.h"
2323#include " geo.h"
24+ #include " odb/dbTransform.h"
2425#include " robin_hood.h"
2526#include " utl/Logger.h"
2627
@@ -36,7 +37,8 @@ GridGraph::GridGraph(const Design* design,
3637 num_layers_(design->getNumLayers ()),
3738 x_size_(gridlines_[0 ].size() - 1),
3839 y_size_(gridlines_[1 ].size() - 1),
39- constants_(constants)
40+ constants_(constants),
41+ design_(design)
4042{
4143 grid_centers_.resize (2 );
4244 for (int dimension = 0 ; dimension <= 1 ; dimension++) {
@@ -365,6 +367,69 @@ CostT GridGraph::getViaCost(const int layer_index, const PointT loc) const
365367 return cost;
366368}
367369
370+ bool GridGraph::findODBAccessPoints (
371+ const GRNet* net,
372+ AccessPointSet& selected_access_points) const
373+ {
374+ std::vector<odb::dbAccessPoint*> access_points;
375+ int amount_per_x = design_->getDieRegion ().hx () / x_size_;
376+ int amount_per_y = design_->getDieRegion ().hy () / y_size_;
377+ odb::dbNet* db_net = net->getDbNet ();
378+ if (db_net->getBTermCount () != 0 ) {
379+ for (odb::dbBTerm* bterms : db_net->getBTerms ()) {
380+ for (const odb::dbBPin* bpin : bterms->getBPins ()) {
381+ const std::vector<odb::dbAccessPoint*>& bpin_pas
382+ = bpin->getAccessPoints ();
383+ // Iterates per each AP and converts to CUGR structures
384+ for (auto ap : bpin_pas) {
385+ auto point = ap->getPoint ();
386+ auto layer = ap->getLayer ();
387+ const PointT selected_point = PointT (point.getX () / amount_per_x,
388+ point.getY () / amount_per_y);
389+ const IntervalT selected_layer = IntervalT (layer->getNumber ());
390+ const AccessPoint ap_new{selected_point, selected_layer};
391+ selected_access_points.emplace (ap_new).first ;
392+ }
393+ }
394+ }
395+ } else {
396+ for (auto iterms : db_net->getITerms ()) {
397+ auto pref_access_points = iterms->getPrefAccessPoints ();
398+ if (!pref_access_points.empty ()) {
399+ // Iterates in ITerm prefered APs and convert to CUGR strucutres
400+ for (auto ap : pref_access_points) {
401+ int x, y;
402+ iterms->getInst ()->getLocation (x, y);
403+ auto point = ap->getPoint ();
404+ auto layer = ap->getLayer ();
405+ const PointT selected_point
406+ = PointT ((point.getX () + x) / amount_per_x,
407+ (point.getY () + y) / amount_per_y);
408+ const IntervalT selected_layer = IntervalT (layer->getNumber ());
409+ const AccessPoint ap_new{selected_point, selected_layer};
410+ selected_access_points.emplace (ap_new).first ;
411+ }
412+ }
413+ // Currently ignoring non preferred APs
414+ }
415+ }
416+ if (access_points.empty ()) {
417+ return false ;
418+ }
419+ // Update layers for each AP
420+ for (auto & selected_point : selected_access_points) {
421+ auto it = selected_access_points.find (selected_point);
422+ IntervalT& fixedLayerInterval = it->layers ;
423+ for (const auto & point : selected_access_points) {
424+ if (point.point .x () == selected_point.point .x ()
425+ && point.point .y () == selected_point.point .y ()) {
426+ fixedLayerInterval.Update (point.layers .high ());
427+ }
428+ }
429+ }
430+ return true ;
431+ }
432+
368433AccessPointSet GridGraph::selectAccessPoints (const GRNet* net) const
369434{
370435 AccessPointHash hasher (y_size_);
@@ -373,45 +438,51 @@ AccessPointSet GridGraph::selectAccessPoints(const GRNet* net) const
373438 selected_access_points.reserve (net->getNumPins ());
374439 const auto & boundingBox = net->getBoundingBox ();
375440 const PointT netCenter (boundingBox.cx (), boundingBox.cy ());
376- for (const std::vector<GRPoint>& accessPoints : net->getPinAccessPoints ()) {
377- std::pair<int , int > bestAccessDist = {0 , std::numeric_limits<int >::max ()};
378- int bestIndex = -1 ;
379- for (int index = 0 ; index < accessPoints.size (); index++) {
380- const GRPoint& point = accessPoints[index];
381- int accessibility = 0 ;
382- if (point.getLayerIdx () >= constants_.min_routing_layer ) {
383- const int direction = getLayerDirection (point.getLayerIdx ());
384- accessibility
385- += getEdge (point.getLayerIdx (), point.x (), point.y ()).capacity >= 1 ;
386- if (point[direction] > 0 ) {
387- auto lower = point;
388- lower[direction] -= 1 ;
441+ if (findODBAccessPoints (net, selected_access_points)) {
442+ // Skips calculations if DRT already created APs in ODB
443+ logger_->report (" Found ODB accesspoint for net {} \n " , net->getName ());
444+ } else {
445+ for (const std::vector<GRPoint>& accessPoints : net->getPinAccessPoints ()) {
446+ std::pair<int , int > bestAccessDist = {0 , std::numeric_limits<int >::max ()};
447+ int bestIndex = -1 ;
448+ for (int index = 0 ; index < accessPoints.size (); index++) {
449+ const GRPoint& point = accessPoints[index];
450+ int accessibility = 0 ;
451+ if (point.getLayerIdx () >= constants_.min_routing_layer ) {
452+ const int direction = getLayerDirection (point.getLayerIdx ());
389453 accessibility
390- += getEdge (lower .getLayerIdx (), lower .x (), lower .y ()).capacity
454+ += getEdge (point .getLayerIdx (), point .x (), point .y ()).capacity
391455 >= 1 ;
456+ if (point[direction] > 0 ) {
457+ auto lower = point;
458+ lower[direction] -= 1 ;
459+ accessibility
460+ += getEdge (lower.getLayerIdx (), lower.x (), lower.y ()).capacity
461+ >= 1 ;
462+ }
463+ } else {
464+ accessibility = 1 ;
465+ }
466+ const int distance
467+ = abs (netCenter.x () - point.x ()) + abs (netCenter.y () - point.y ());
468+ if (accessibility > bestAccessDist.first
469+ || (accessibility == bestAccessDist.first
470+ && distance < bestAccessDist.second )) {
471+ bestIndex = index;
472+ bestAccessDist = {accessibility, distance};
392473 }
393- } else {
394- accessibility = 1 ;
395474 }
396- const int distance
397- = abs (netCenter.x () - point.x ()) + abs (netCenter.y () - point.y ());
398- if (accessibility > bestAccessDist.first
399- || (accessibility == bestAccessDist.first
400- && distance < bestAccessDist.second )) {
401- bestIndex = index;
402- bestAccessDist = {accessibility, distance};
475+ if (bestAccessDist.first == 0 ) {
476+ logger_->warn (utl::GRT, 274 , " pin is hard to access." );
403477 }
404- }
405- if (bestAccessDist.first == 0 ) {
406- logger_->warn (utl::GRT, 274 , " pin is hard to access." );
407- }
408- const PointT selectedPoint = accessPoints[bestIndex];
409- const AccessPoint ap{selectedPoint, {}};
410- auto it = selected_access_points.emplace (ap).first ;
411- IntervalT& fixedLayerInterval = it->layers ;
412- for (const auto & point : accessPoints) {
413- if (point.x () == selectedPoint.x () && point.y () == selectedPoint.y ()) {
414- fixedLayerInterval.Update (point.getLayerIdx ());
478+ const PointT selectedPoint = accessPoints[bestIndex];
479+ const AccessPoint ap{selectedPoint, {}};
480+ auto it = selected_access_points.emplace (ap).first ;
481+ IntervalT& fixedLayerInterval = it->layers ;
482+ for (const auto & point : accessPoints) {
483+ if (point.x () == selectedPoint.x () && point.y () == selectedPoint.y ()) {
484+ fixedLayerInterval.Update (point.getLayerIdx ());
485+ }
415486 }
416487 }
417488 }
0 commit comments