@@ -67,7 +67,7 @@ void FlexPA::removeFromInstsSet(frInst* inst)
6767
6868void FlexPA::addToInstsSet (frInst* inst)
6969{
70- if (insts_set_.find (inst) != insts_set_. end ( )) {
70+ if (insts_set_.contains (inst)) {
7171 return ;
7272 }
7373 if (!unique_insts_.hasUnique (inst)) {
@@ -455,9 +455,19 @@ int FlexPA::getEdgeCost(
455455 prev_acc_point_idx,
456456 curr_acc_point_idx,
457457 max_access_point_size);
458- if (vio_edges[edge_idx] != -1 ) {
459- has_vio = (vio_edges[edge_idx] == 1 );
460- } else {
458+
459+ // vio_edges caches whether a pair of aps have violations between themselves.
460+ // -1: No cache exists
461+ // 0: Already cached as no violation
462+ // 1: Already caches as having a violation
463+
464+ // Edge cached as having a violation
465+ if (vio_edges[edge_idx] == 1 ) {
466+ return kViolationCost ;
467+ }
468+
469+ // Violation status of the edge is not cached, has to be calculated
470+ if (vio_edges[edge_idx] == -1 ) {
461471 odb::dbTransform xform = unique_inst->getNoRotationTransform ();
462472 // check DRC
463473 std::vector<std::pair<frConnFig*, frBlockObject*>> objs;
@@ -496,64 +506,53 @@ int FlexPA::getEdgeCost(
496506
497507 has_vio = !genPatternsGC ({target_obj}, objs, Edge);
498508 vio_edges[edge_idx] = has_vio;
509+ if (has_vio) {
510+ return kViolationCost ;
511+ }
499512
500- // look back for GN14
501- if (!has_vio) {
502- // check one more back
503- if (prev_node->hasPrevNode ()) {
504- auto prev_prev_node = prev_node->getPrevNode ();
505- auto [prev_prev_pin_idx, prev_prev_acc_point_idx]
506- = prev_prev_node->getIdx ();
507- if (!prev_prev_node->isSource ()) {
508- const auto & [pin_3, inst_term_3] = pins[prev_prev_pin_idx];
509- const auto pa_3 = pin_3->getPinAccess (pin_access_idx);
510- const frAccessPoint* ap_3
511- = pa_3->getAccessPoint (prev_prev_acc_point_idx);
512- std::unique_ptr<frVia> via3;
513- if (ap_3->hasAccess (frDirEnum::U)) {
514- odb::Point pt3 (ap_3->getPoint ());
515- xform.apply (pt3);
516- via3 = std::make_unique<frVia>(ap_3->getViaDef (), pt3);
517- if (inst_term_3->hasNet ()) {
518- objs.emplace_back (via3.get (), inst_term_3->getNet ());
519- } else {
520- objs.emplace_back (via3.get (), inst_term_3);
521- }
513+ // check one more back
514+ if (prev_node->hasPrevNode ()) {
515+ auto prev_prev_node = prev_node->getPrevNode ();
516+ auto [prev_prev_pin_idx, prev_prev_acc_point_idx]
517+ = prev_prev_node->getIdx ();
518+ if (!prev_prev_node->isSource ()) {
519+ const auto & [pin_3, inst_term_3] = pins[prev_prev_pin_idx];
520+ const auto pa_3 = pin_3->getPinAccess (pin_access_idx);
521+ const frAccessPoint* ap_3
522+ = pa_3->getAccessPoint (prev_prev_acc_point_idx);
523+ std::unique_ptr<frVia> via3;
524+ if (ap_3->hasAccess (frDirEnum::U)) {
525+ odb::Point pt3 (ap_3->getPoint ());
526+ xform.apply (pt3);
527+ via3 = std::make_unique<frVia>(ap_3->getViaDef (), pt3);
528+ if (inst_term_3->hasNet ()) {
529+ objs.emplace_back (via3.get (), inst_term_3->getNet ());
530+ } else {
531+ objs.emplace_back (via3.get (), inst_term_3);
522532 }
533+ }
523534
524- has_vio = !genPatternsGC ({target_obj}, objs, Edge);
535+ if (!genPatternsGC ({target_obj}, objs, Edge)) {
536+ return kViolationCost ;
525537 }
526538 }
527539 }
528540 }
529541
530- if (!has_vio) {
531- if ((prev_pin_idx == 0
532- && used_access_points.find (
533- std::make_pair (prev_pin_idx, prev_acc_point_idx))
534- != used_access_points.end ())
535- || (curr_pin_idx == (int ) pins.size () - 1
536- && used_access_points.find (
537- std::make_pair (curr_pin_idx, curr_acc_point_idx))
538- != used_access_points.end ())) {
539- edge_cost = 100 ;
540- } else if (viol_access_points.find (
541- std::make_pair (prev_pin_idx, prev_acc_point_idx))
542- != viol_access_points.end ()
543- || viol_access_points.find (
544- std::make_pair (curr_pin_idx, curr_acc_point_idx))
545- != viol_access_points.end ()) {
546- edge_cost = 1000 ;
547- } else {
548- const int prev_node_cost = prev_node->getNodeCost ();
549- const int curr_node_cost = curr_node->getNodeCost ();
550- edge_cost = (prev_node_cost + curr_node_cost) / 2 ;
551- }
552- } else {
553- edge_cost = 1000 /* violation cost*/ ;
542+ if ((prev_pin_idx == 0 && used_access_points.contains (prev_node->getIdx ()))
543+ || (curr_pin_idx == (int ) pins.size () - 1
544+ && used_access_points.contains (curr_node->getIdx ()))) {
545+ return kRepeatedApCost ;
546+ }
547+
548+ if (viol_access_points.contains (prev_node->getIdx ())
549+ || viol_access_points.contains (curr_node->getIdx ())) {
550+ return kViolationCost ;
554551 }
555552
556- return edge_cost;
553+ const int prev_node_cost = prev_node->getNodeCost ();
554+ const int curr_node_cost = curr_node->getNodeCost ();
555+ return prev_node_cost + curr_node_cost;
557556}
558557
559558std::vector<int > FlexPA::extractAccessPatternFromNodes (
@@ -600,7 +599,7 @@ bool FlexPA::genPatternsCommit(
600599 std::vector<int > access_pattern = extractAccessPatternFromNodes (
601600 unique_inst, nodes, pins, used_access_points);
602601 // not a new access pattern
603- if (inst_access_patterns.find (access_pattern) != inst_access_patterns. end ( )) {
602+ if (inst_access_patterns.contains (access_pattern)) {
604603 return false ;
605604 }
606605
@@ -651,7 +650,7 @@ bool FlexPA::genPatternsCommit(
651650 }
652651 uint64_t n_no_ap_pins = 0 ;
653652 for (auto & pin : inst_term->getTerm ()->getPins ()) {
654- if (pin_to_access_point.find (pin.get ()) == pin_to_access_point. end ( )) {
653+ if (! pin_to_access_point.contains (pin.get ())) {
655654 n_no_ap_pins++;
656655 pin_access_pattern->addAccessPoint (nullptr );
657656 } else {
@@ -694,7 +693,7 @@ bool FlexPA::genPatternsCommit(
694693 if (inst_term->hasNet ()) {
695694 owner = inst_term->getNet ();
696695 }
697- if (owners.find (owner) != owners. end ( )) {
696+ if (owners.contains (owner)) {
698697 viol_access_points.insert ({pin_idx, acc_pattern_idx}); // idx ;
699698 }
700699 }
0 commit comments