Skip to content

Commit f1b33ed

Browse files
committed
PathGroup use BoundedHeap
Signed-off-by: James Cherry <cherry@parallaxsw.com>
1 parent 9b2bdf8 commit f1b33ed

File tree

8 files changed

+91
-133
lines changed

8 files changed

+91
-133
lines changed

include/sta/BoundedHeap.hh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public:
6060
comp_(comp),
6161
min_heap_comp_(comp)
6262
{
63-
heap_.reserve(max_size);
6463
}
6564

6665
// Copy constructor
@@ -107,7 +106,12 @@ public:
107106
setMaxSize(size_t max_size)
108107
{
109108
max_size_ = max_size;
110-
heap_.reserve(max_size);
109+
}
110+
111+
void
112+
reserve(size_t size)
113+
{
114+
heap_.reserve(size);
111115
}
112116

113117
// Insert an element into the heap.
@@ -172,20 +176,17 @@ public:
172176
{
173177
// Convert heap to sorted vector (best to worst)
174178
std::sort_heap(heap_.begin(), heap_.end(), min_heap_comp_);
175-
// Reverse to get best first (according to user's comparison)
176-
std::reverse(heap_.begin(), heap_.end());
177179
std::vector<T> result = std::move(heap_);
178180
heap_.clear();
179181
return result;
180182
}
181183

182184
// Extract all elements sorted from best to worst (const version).
183185
// Creates a copy since we can't modify the heap.
184-
std::vector<T> extract() const
186+
std::vector<T> contents() const
185187
{
186188
std::vector<T> temp_heap = heap_;
187189
std::sort_heap(temp_heap.begin(), temp_heap.end(), min_heap_comp_);
188-
std::reverse(temp_heap.begin(), temp_heap.end());
189190
return temp_heap;
190191
}
191192

@@ -245,7 +246,7 @@ private:
245246
Compare comp_;
246247
explicit MinHeapCompare(const Compare& c) : comp_(c) {}
247248
bool operator()(const T& a, const T& b) const {
248-
return comp_(b, a); // Inverted: worst is at root
249+
return comp_(a, b); // comp = less puts largest at root (worst)
249250
}
250251
};
251252

include/sta/PathEnd.hh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ public:
153153

154154
static bool less(const PathEnd *path_end1,
155155
const PathEnd *path_end2,
156+
// Compare slack (if constrained), or arrival when false.
157+
bool cmp_slack,
156158
const StaState *sta);
157159
static int cmp(const PathEnd *path_end1,
158160
const PathEnd *path_end2,
161+
// Compare slack (if constrained), or arrival when false.
162+
bool cmp_slack,
159163
const StaState *sta);
160164
static int cmpSlack(const PathEnd *path_end1,
161165
const PathEnd *path_end2,
@@ -611,23 +615,27 @@ protected:
611615
class PathEndLess
612616
{
613617
public:
614-
PathEndLess(const StaState *sta);
618+
PathEndLess(bool cmp_slack,
619+
const StaState *sta);
615620
bool operator()(const PathEnd *path_end1,
616621
const PathEnd *path_end2) const;
617622

618623
protected:
624+
bool cmp_slack_;
619625
const StaState *sta_;
620626
};
621627

622628
// Compare slack or arrival for unconstrained path ends.
623629
class PathEndSlackLess
624630
{
625631
public:
626-
PathEndSlackLess(const StaState *sta);
632+
PathEndSlackLess(bool cmp_slack,
633+
const StaState *sta);
627634
bool operator()(const PathEnd *path_end1,
628635
const PathEnd *path_end2) const;
629636

630637
protected:
638+
bool cmp_slack_;
631639
const StaState *sta_;
632640
};
633641

include/sta/PathGroup.hh

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
#include <map>
3030
#include <mutex>
3131

32+
#include "BoundedHeap.hh"
3233
#include "SdcClass.hh"
3334
#include "StaState.hh"
3435
#include "SearchClass.hh"
3536
#include "StringUtil.hh"
37+
#include "PathEnd.hh"
3638

3739
namespace sta {
3840

@@ -48,7 +50,6 @@ using PathGroupSeq = std::vector<PathGroup*>;
4850
class PathGroup
4951
{
5052
public:
51-
~PathGroup();
5253
// Path group that compares compare slacks.
5354
static PathGroup *makePathGroupArrival(const char *name,
5455
int group_path_count,
@@ -68,45 +69,40 @@ public:
6869
const StaState *sta);
6970
const std::string &name() const { return name_; }
7071
const MinMax *minMax() const { return min_max_;}
71-
const PathEndSeq &pathEnds() const { return path_ends_; }
72+
PathEndSeq pathEnds() const;
7273
void insert(PathEnd *path_end);
7374
// Push group_path_count into path_ends.
7475
void pushEnds(PathEndSeq &path_ends);
7576
// Predicate to determine if a PathEnd is worth saving.
7677
bool saveable(PathEnd *path_end);
7778
bool enumMinSlackUnderMin(PathEnd *path_end);
7879
int maxPaths() const { return group_path_count_; }
79-
PathEndSeq &pathEnds() { return path_ends_; }
8080
// This does NOT delete the path ends.
8181
void clear();
82-
static size_t group_path_count_max;
82+
static int group_path_count_max;
8383

8484
protected:
8585
PathGroup(const char *name,
86-
size_t group_path_count,
87-
size_t endpoint_path_count,
86+
int group_path_count,
87+
int endpoint_path_count,
8888
bool unique_pins,
8989
bool unique_edges,
9090
float min_slack,
9191
float max_slack,
9292
bool cmp_slack,
9393
const MinMax *min_max,
9494
const StaState *sta);
95-
void ensureSortedMaxPaths();
96-
void prune();
97-
void sort();
9895

9996
std::string name_;
100-
size_t group_path_count_;
101-
size_t endpoint_path_count_;
97+
int group_path_count_;
98+
int endpoint_path_count_;
10299
bool unique_pins_;
103100
bool unique_edges_;
104101
float slack_min_;
105102
float slack_max_;
106-
PathEndSeq path_ends_;
107103
const MinMax *min_max_;
108-
bool compare_slack_;
109-
float threshold_;
104+
bool cmp_slack_;
105+
BoundedHeap<PathEnd*, PathEndLess> heap_;
110106
std::mutex lock_;
111107
const StaState *sta_;
112108
};

include/sta/Search.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public:
100100
bool unconstrained,
101101
const SceneSeq &scenes,
102102
const MinMaxAll *min_max,
103-
size_t group_path_count,
104-
size_t endpoint_path_count,
103+
int group_path_count,
104+
int endpoint_path_count,
105105
bool unique_pins,
106106
bool unique_edges,
107107
float slack_min,

search/PathEnd.cc

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,32 +2030,22 @@ PathEndPathDelay::exceptPathCmp(const PathEnd *path_end,
20302030

20312031
////////////////////////////////////////////////////////////////
20322032

2033-
PathEndLess::PathEndLess(const StaState *sta) :
2034-
sta_(sta)
2035-
{
2036-
}
2037-
2038-
bool
2039-
PathEndLess::operator()(const PathEnd *path_end1,
2040-
const PathEnd *path_end2) const
2041-
{
2042-
return PathEnd::less(path_end1, path_end2, sta_);
2043-
}
2044-
20452033
bool
20462034
PathEnd::less(const PathEnd *path_end1,
20472035
const PathEnd *path_end2,
2036+
bool cmp_slack,
20482037
const StaState *sta)
20492038
{
2050-
return cmp(path_end1, path_end2, sta) < 0;
2039+
return cmp(path_end1, path_end2, cmp_slack, sta) < 0;
20512040
}
20522041

20532042
int
20542043
PathEnd::cmp(const PathEnd *path_end1,
20552044
const PathEnd *path_end2,
2045+
bool cmp_slack,
20562046
const StaState *sta)
20572047
{
2058-
int cmp = path_end1->isUnconstrained()
2048+
int cmp = !cmp_slack || path_end1->isUnconstrained()
20592049
? -cmpArrival(path_end1, path_end2, sta)
20602050
: cmpSlack(path_end1, path_end2, sta);
20612051
if (cmp == 0) {
@@ -2139,7 +2129,25 @@ PathEnd::cmpNoCrpr(const PathEnd *path_end1,
21392129

21402130
////////////////////////////////////////////////////////////////
21412131

2142-
PathEndSlackLess::PathEndSlackLess(const StaState *sta) :
2132+
PathEndLess::PathEndLess(bool cmp_slack,
2133+
const StaState *sta) :
2134+
cmp_slack_(cmp_slack),
2135+
sta_(sta)
2136+
{
2137+
}
2138+
2139+
bool
2140+
PathEndLess::operator()(const PathEnd *path_end1,
2141+
const PathEnd *path_end2) const
2142+
{
2143+
return PathEnd::less(path_end1, path_end2, cmp_slack_, sta_);
2144+
}
2145+
2146+
////////////////////////////////////////////////////////////////
2147+
2148+
PathEndSlackLess::PathEndSlackLess(bool cmp_slack,
2149+
const StaState *sta) :
2150+
cmp_slack_(cmp_slack),
21432151
sta_(sta)
21442152
{
21452153
}

search/PathEnum.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ DiversionGreater::operator()(Diversion *div1,
9191
{
9292
PathEnd *path_end1 = div1->pathEnd();
9393
PathEnd *path_end2 = div2->pathEnd();
94-
return PathEnd::cmp(path_end1, path_end2, sta_) > 0;
94+
return PathEnd::cmp(path_end1, path_end2, true, sta_) > 0;
9595
}
9696

9797
static void

0 commit comments

Comments
 (0)