@@ -51,6 +51,13 @@ namespace {
5151
5252constexpr int kDigits = 3 ;
5353
54+ Net* mutableNet (const Net* net)
55+ {
56+ // OpenSTA/Network APIs used by the limit checks are not const-correct.
57+ // They take Net* but do not mutate the net, so casting away const is safe.
58+ return const_cast <Net*>(net);
59+ }
60+
5461} // namespace
5562
5663RecoverPowerMore::RecoverPowerMore (Resizer* resizer) : resizer_(resizer)
@@ -287,7 +294,7 @@ std::vector<const Net*> RecoverPowerMore::slewCheckNetCone(
287294 if (net == nullptr ) {
288295 continue ;
289296 }
290- net = network_->highestConnectedNet (const_cast <Net*> (net));
297+ net = network_->highestConnectedNet (mutableNet (net));
291298 if (net == nullptr || network_->isPower (net) || network_->isGround (net)) {
292299 continue ;
293300 }
@@ -333,7 +340,7 @@ std::vector<const Net*> RecoverPowerMore::slewCheckNetCone(
333340 if (out_net == nullptr ) {
334341 continue ;
335342 }
336- out_net = network_->highestConnectedNet (const_cast <Net*> (out_net));
343+ out_net = network_->highestConnectedNet (mutableNet (out_net));
337344 if (out_net == nullptr || network_->isPower (out_net)
338345 || network_->isGround (out_net)) {
339346 continue ;
@@ -360,8 +367,8 @@ size_t RecoverPowerMore::countSlewViolations(
360367 size_t count = 0 ;
361368 for (const Net* net : nets) {
362369 if (net != nullptr ) {
363- count += sta_-> checkSlewLimits ( const_cast <Net*>(net), true , nullptr , max_)
364- .size ();
370+ count
371+ += sta_-> checkSlewLimits ( mutableNet (net), true , nullptr , max_) .size ();
365372 }
366373 }
367374 return count;
@@ -373,9 +380,9 @@ size_t RecoverPowerMore::countCapViolations(
373380 size_t count = 0 ;
374381 for (const Net* net : nets) {
375382 if (net != nullptr ) {
376- count += sta_-> checkCapacitanceLimits (
377- const_cast <Net*> (net), true , nullptr , max_)
378- .size ();
383+ count
384+ += sta_-> checkCapacitanceLimits ( mutableNet (net), true , nullptr , max_)
385+ .size ();
379386 }
380387 }
381388 return count;
@@ -387,8 +394,7 @@ size_t RecoverPowerMore::countFanoutViolations(
387394 size_t count = 0 ;
388395 for (const Net* net : nets) {
389396 if (net != nullptr ) {
390- count
391- += sta_->checkFanoutLimits (const_cast <Net*>(net), true , max_).size ();
397+ count += sta_->checkFanoutLimits (mutableNet (net), true , max_).size ();
392398 }
393399 }
394400 return count;
@@ -488,7 +494,7 @@ Slack RecoverPowerMore::instanceWorstSlack(sta::Instance* inst) const
488494 found = true ;
489495 }
490496
491- return found ? worst_slack : - std::numeric_limits<Slack>::infinity ();
497+ return found ? worst_slack : std::numeric_limits<Slack>::infinity ();
492498}
493499
494500bool RecoverPowerMore::instanceDrivesClock (sta::Instance* inst) const
@@ -635,29 +641,24 @@ std::vector<LibertyCell*> RecoverPowerMore::nextSmallerCells(
635641
636642 // Prefer weaker (higher resistance) and lower leakage candidates first;
637643 // the full STA check will decide which are actually acceptable.
638- std::stable_sort (candidates.begin (),
639- candidates.end (),
640- [this ](LibertyCell* a, LibertyCell* b) {
641- float ra = resizer_->cellDriveResistance (a);
642- float rb = resizer_->cellDriveResistance (b);
643- if (ra <= 0 .0f ) {
644- ra = 0 .0f ;
645- }
646- if (rb <= 0 .0f ) {
647- rb = 0 .0f ;
648- }
649- const float la = resizer_->cellLeakage (a).value_or (
650- std::numeric_limits<float >::infinity ());
651- const float lb = resizer_->cellLeakage (b).value_or (
652- std::numeric_limits<float >::infinity ());
653- if (ra != rb) {
654- return ra > rb;
655- }
656- if (la != lb) {
657- return la < lb;
658- }
659- return std::strcmp (a->name (), b->name ()) < 0 ;
660- });
644+ std::stable_sort (
645+ candidates.begin (),
646+ candidates.end (),
647+ [this ](LibertyCell* a, LibertyCell* b) {
648+ float ra = std::max (0 .0f , resizer_->cellDriveResistance (a));
649+ float rb = std::max (0 .0f , resizer_->cellDriveResistance (b));
650+ const float la = resizer_->cellLeakage (a).value_or (
651+ std::numeric_limits<float >::infinity ());
652+ const float lb = resizer_->cellLeakage (b).value_or (
653+ std::numeric_limits<float >::infinity ());
654+ if (ra != rb) {
655+ return ra > rb;
656+ }
657+ if (la != lb) {
658+ return la < lb;
659+ }
660+ return std::strcmp (a->name (), b->name ()) < 0 ;
661+ });
661662
662663 return candidates;
663664}
@@ -830,10 +831,10 @@ bool RecoverPowerMore::tryRemoveBuffer(sta::Instance* inst,
830831 const Net* out_net
831832 = (out_pin != nullptr ) ? network_->net (out_pin) : nullptr ;
832833 if (in_net != nullptr ) {
833- in_net = network_->highestConnectedNet (const_cast <Net*> (in_net));
834+ in_net = network_->highestConnectedNet (mutableNet (in_net));
834835 }
835836 if (out_net != nullptr ) {
836- out_net = network_->highestConnectedNet (const_cast <Net*> (out_net));
837+ out_net = network_->highestConnectedNet (mutableNet (out_net));
837838 }
838839 // Mirror UnbufferMove::removeBuffer() survivor selection to avoid
839840 // dereferencing a net that is destroyed by mergeNet().
0 commit comments