PathGroup revert f1b33edd9

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2026-03-15 08:33:49 -07:00
parent d6e7b4256c
commit 464d4047ad
2 changed files with 82 additions and 35 deletions

View File

@ -29,7 +29,6 @@
#include <map> #include <map>
#include <mutex> #include <mutex>
#include "BoundedHeap.hh"
#include "SdcClass.hh" #include "SdcClass.hh"
#include "StaState.hh" #include "StaState.hh"
#include "SearchClass.hh" #include "SearchClass.hh"
@ -70,7 +69,7 @@ public:
~PathGroup(); ~PathGroup();
const std::string &name() const { return name_; } const std::string &name() const { return name_; }
const MinMax *minMax() const { return min_max_;} const MinMax *minMax() const { return min_max_;}
PathEndSeq pathEnds() const; PathEndSeq pathEnds() const { return path_ends_; }
void insert(PathEnd *path_end); void insert(PathEnd *path_end);
// Push group_path_count into path_ends. // Push group_path_count into path_ends.
void pushEnds(PathEndSeq &path_ends); void pushEnds(PathEndSeq &path_ends);
@ -93,6 +92,9 @@ protected:
bool cmp_slack, bool cmp_slack,
const MinMax *min_max, const MinMax *min_max,
const StaState *sta); const StaState *sta);
void ensureSortedMaxPaths();
void prune();
void sort();
std::string name_; std::string name_;
int group_path_count_; int group_path_count_;
@ -101,9 +103,11 @@ protected:
bool unique_edges_; bool unique_edges_;
float slack_min_; float slack_min_;
float slack_max_; float slack_max_;
PathEndSeq path_ends_;
const MinMax *min_max_; const MinMax *min_max_;
bool cmp_slack_; bool cmp_slack_;
BoundedHeap<PathEnd*, PathEndLess> heap_; float threshold_;
std::mutex lock_; std::mutex lock_;
const StaState *sta_; const StaState *sta_;
}; };

View File

@ -100,41 +100,42 @@ PathGroup::PathGroup(const char *name,
slack_max_(slack_max), slack_max_(slack_max),
min_max_(min_max), min_max_(min_max),
cmp_slack_(cmp_slack), cmp_slack_(cmp_slack),
heap_(group_path_count, PathEndLess(cmp_slack, sta)), threshold_(min_max->initValue()),
sta_(sta) sta_(sta)
{ {
} }
PathGroup::~PathGroup() PathGroup::~PathGroup()
{ {
PathEndSeq path_ends = heap_.extract(); deleteContents(path_ends_);
deleteContents(path_ends);
}
PathEndSeq
PathGroup::pathEnds() const
{
return heap_.contents();
} }
bool bool
PathGroup::saveable(PathEnd *path_end) PathGroup::saveable(PathEnd *path_end)
{ {
float threshold;
{
LockGuard lock(lock_);
threshold = threshold_;
}
if (cmp_slack_) { if (cmp_slack_) {
// Crpr increases the slack, so check the slack // Crpr increases the slack, so check the slack
// without crpr first because it is expensive to find. // without crpr first because it is expensive to find.
Slack slack = path_end->slackNoCrpr(sta_); Slack slack_no_crpr = path_end->slackNoCrpr(sta_);
if (!delayIsInitValue(slack, min_max_) if (!delayIsInitValue(slack_no_crpr, min_max_)
&& delayLessEqual(slack, slack_max_, sta_)) { && delayLessEqual(slack_no_crpr, threshold, sta_)
&& delayLessEqual(slack_no_crpr, slack_max_, sta_)) {
// Now check with crpr. // Now check with crpr.
slack = path_end->slack(sta_); Slack slack = path_end->slack(sta_);
return delayLessEqual(slack, slack_max_, sta_) return delayLessEqual(slack, threshold, sta_)
&& delayLessEqual(slack, slack_max_, sta_)
&& delayGreaterEqual(slack, slack_min_, sta_); && delayGreaterEqual(slack, slack_min_, sta_);
} }
} }
else { else {
const Arrival &arrival = path_end->dataArrivalTime(sta_); const Arrival &arrival = path_end->dataArrivalTime(sta_);
return !delayIsInitValue(arrival, min_max_); return !delayIsInitValue(arrival, min_max_)
&& delayGreaterEqual(arrival, threshold, min_max_, sta_);
} }
return false; return false;
} }
@ -176,33 +177,72 @@ void
PathGroup::insert(PathEnd *path_end) PathGroup::insert(PathEnd *path_end)
{ {
LockGuard lock(lock_); LockGuard lock(lock_);
auto [inserted, displaced] = heap_.insert(path_end); path_ends_.push_back(path_end);
if (inserted) path_end->setPathGroup(this);
path_end->setPathGroup(this); if (group_path_count_ != group_path_count_max
&& path_ends_.size() > static_cast<size_t>(group_path_count_) * 2)
prune();
}
void
PathGroup::prune()
{
sort();
VertexPathCountMap path_counts;
size_t end_count = 0;
for (unsigned i = 0; i < path_ends_.size(); i++) {
PathEnd *path_end = path_ends_[i];
Vertex *vertex = path_end->vertex(sta_);
// Squish up to endpoint_path_count path ends per vertex
// up to the front of path_ends_.
if (end_count < static_cast<size_t>(group_path_count_)
&& path_counts[vertex] < static_cast<size_t>(endpoint_path_count_)) {
path_ends_[end_count++] = path_end;
path_counts[vertex]++;
}
else
delete path_end;
}
path_ends_.resize(end_count);
// Set a threshold to the bottom of the sorted list that future
// inserts need to beat.
PathEnd *last_end = path_ends_[end_count - 1];
if (cmp_slack_)
threshold_ = delayAsFloat(last_end->slack(sta_));
else else
delete path_end; threshold_ = delayAsFloat(last_end->dataArrivalTime(sta_));
if (displaced)
delete *displaced;
} }
void void
PathGroup::pushEnds(PathEndSeq &path_ends) PathGroup::pushEnds(PathEndSeq &path_ends)
{ {
if (!heap_.empty()) { ensureSortedMaxPaths();
PathEndSeq ends = heap_.contents(); for (PathEnd *path_end : path_ends_)
path_ends.reserve(path_ends.size() + ends.size()); path_ends.push_back(path_end);
// Append heap path ends to path_ends. }
path_ends.insert(path_ends.end(),
std::make_move_iterator(ends.begin()), void
std::make_move_iterator(ends.end())); PathGroup::ensureSortedMaxPaths()
} {
if (path_ends_.size() > static_cast<size_t>(group_path_count_))
prune();
else
sort();
}
void
PathGroup::sort()
{
sta::sort(path_ends_, PathEndLess(cmp_slack_, sta_));
} }
void void
PathGroup::clear() PathGroup::clear()
{ {
threshold_ = min_max_->initValue();
LockGuard lock(lock_); LockGuard lock(lock_);
heap_.clear(); path_ends_.clear();
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -857,8 +897,11 @@ PathGroups::enumPathEnds(PathGroup *group,
// enumerator. // enumerator.
PathEnum path_enum(group_path_count, endpoint_path_count, PathEnum path_enum(group_path_count, endpoint_path_count,
unique_pins, unique_edges, cmp_slack, this); unique_pins, unique_edges, cmp_slack, this);
for (PathEnd *end : group->pathEnds()) for (PathEnd *end : group->pathEnds()) {
path_enum.insert(end); if (group->saveable(end)
|| group->enumMinSlackUnderMin(end))
path_enum.insert(end);
}
group->clear(); group->clear();
// Parallel path enumeratation to find the endpoint_path_count/max path ends. // Parallel path enumeratation to find the endpoint_path_count/max path ends.