TaGGroup refcount to reclaim memory

commit cd7169f99ab8b67323c444d4c22d065487e439c1
Author: James Cherry <cherry@parallaxsw.com>
Date:   Sun Aug 31 16:02:03 2025 -0700

    reportArrivals report_tag_index

    Signed-off-by: James Cherry <cherry@parallaxsw.com>

commit 658f842a776bb43eef7dbfd9a08e191c31fb9f11
Author: James Cherry <cherry@parallaxsw.com>
Date:   Mon Aug 25 16:20:50 2025 -0700

    tag group ref count

    Signed-off-by: James Cherry <cherry@parallaxsw.com>

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2025-09-03 15:05:14 -07:00
parent 255988633f
commit e4a1ebf00e
7 changed files with 54 additions and 13 deletions

View File

@ -356,7 +356,8 @@ public:
TagGroup *tagGroup(const Vertex *vertex) const; TagGroup *tagGroup(const Vertex *vertex) const;
TagGroup *tagGroup(TagGroupIndex index) const; TagGroup *tagGroup(TagGroupIndex index) const;
void reportArrivals(Vertex *vertex) const; void reportArrivals(Vertex *vertex,
bool report_tag_index) const;
Slack wnsSlack(Vertex *vertex, Slack wnsSlack(Vertex *vertex,
PathAPIndex path_ap_index); PathAPIndex path_ap_index);
void levelsChangedBefore(); void levelsChangedBefore();
@ -410,6 +411,7 @@ public:
TagGroupIndex tag_index); TagGroupIndex tag_index);
void checkPrevPaths() const; void checkPrevPaths() const;
void deletePaths(Vertex *vertex); void deletePaths(Vertex *vertex);
void deleteTagGroup(TagGroup *group);
protected: protected:
void init(StaState *sta); void init(StaState *sta);
@ -645,6 +647,7 @@ protected:
// Capacity of tag_groups_. // Capacity of tag_groups_.
TagGroupIndex tag_group_capacity_; TagGroupIndex tag_group_capacity_;
std::mutex tag_group_lock_; std::mutex tag_group_lock_;
std::mutex tag_group_ref_count_lock_;
// Latches data outputs to queue on the next search pass. // Latches data outputs to queue on the next search pass.
VertexSet *pending_latch_outputs_; VertexSet *pending_latch_outputs_;
std::mutex pending_latch_outputs_lock_; std::mutex pending_latch_outputs_lock_;

View File

@ -554,14 +554,19 @@ Search::deleteFilterTagGroups()
for (TagGroupIndex i = 0; i < tag_group_next_; i++) { for (TagGroupIndex i = 0; i < tag_group_next_; i++) {
TagGroup *group = tag_groups_[i]; TagGroup *group = tag_groups_[i];
if (group if (group
&& group->hasFilterTag()) { && group->hasFilterTag())
deleteTagGroup(group);
}
}
void
Search::deleteTagGroup(TagGroup *group)
{
tag_group_set_->erase(group); tag_group_set_->erase(group);
tag_groups_[group->index()] = nullptr; tag_groups_[group->index()] = nullptr;
tag_group_free_indices_.push_back(i); tag_group_free_indices_.push_back(group->index());
delete group; delete group;
} }
}
}
void void
Search::deleteFilterTags() Search::deleteFilterTags()
@ -2777,6 +2782,15 @@ Search::setVertexArrivals(Vertex *vertex,
filtered_arrivals_->insert(vertex); filtered_arrivals_->insert(vertex);
} }
} }
if (tag_group != prev_tag_group) {
LockGuard lock(tag_group_ref_count_lock_);
tag_group->incrRefCount();
if (prev_tag_group) {
prev_tag_group->decrRefCount();
if (prev_tag_group->refCount() == 0)
deleteTagGroup(prev_tag_group);
}
}
} }
} }
@ -2819,11 +2833,13 @@ ReportPathLess::operator()(const Path *path1,
} }
void void
Search::reportArrivals(Vertex *vertex) const Search::reportArrivals(Vertex *vertex,
bool report_tag_index) const
{ {
report_->reportLine("Vertex %s", vertex->to_string(this).c_str()); report_->reportLine("Vertex %s", vertex->to_string(this).c_str());
TagGroup *tag_group = tagGroup(vertex); TagGroup *tag_group = tagGroup(vertex);
if (tag_group) { if (tag_group) {
if (report_tag_index)
report_->reportLine("Group %u", tag_group->index()); report_->reportLine("Group %u", tag_group->index());
std::vector<const Path*> paths; std::vector<const Path*> paths;
VertexPathIterator path_iter(vertex, this); VertexPathIterator path_iter(vertex, this);
@ -2859,7 +2875,7 @@ Search::reportArrivals(Vertex *vertex) const
path_ap->pathMinMax()->to_string().c_str(), path_ap->pathMinMax()->to_string().c_str(),
delayAsString(path->arrival(), this), delayAsString(path->arrival(), this),
req, req,
tag->to_string(true, false, this).c_str(), tag->to_string(report_tag_index, false, this).c_str(),
prev_str.c_str()); prev_str.c_str());
} }
} }

View File

@ -264,9 +264,10 @@ report_tag_groups()
} }
void void
report_tag_arrivals_cmd(Vertex *vertex) report_tag_arrivals_cmd(Vertex *vertex,
bool report_tag_index)
{ {
Sta::sta()->search()->reportArrivals(vertex); Sta::sta()->search()->reportArrivals(vertex, report_tag_index);
} }
void void

View File

@ -355,7 +355,7 @@ tagCmp(const Tag *tag1,
return tagStateCmp(tag1, tag2); return tagStateCmp(tag1, tag2);
} }
int bool
tagEqual(const Tag *tag1, tagEqual(const Tag *tag1,
const Tag *tag2) const Tag *tag2)
{ {

View File

@ -140,6 +140,9 @@ public:
const Tag *tag2) const; const Tag *tag2) const;
}; };
bool
tagEqual(const Tag *tag1,
const Tag *tag2);
int int
tagCmp(const Tag *tag1, tagCmp(const Tag *tag1,
const Tag *tag2, const Tag *tag2,

View File

@ -44,6 +44,7 @@ TagGroup::TagGroup(TagGroupIndex index,
bool has_loop_tag) : bool has_loop_tag) :
path_index_map_(path_index_map), path_index_map_(path_index_map),
hash_(pathIndexMapHash(path_index_map)), hash_(pathIndexMapHash(path_index_map)),
ref_count_(0),
index_(index), index_(index),
has_clk_tag_(has_clk_tag), has_clk_tag_(has_clk_tag),
has_genclk_src_tag_(has_genclk_src_tag), has_genclk_src_tag_(has_genclk_src_tag),
@ -56,6 +57,7 @@ TagGroup::TagGroup(TagGroupIndex index,
TagGroup::TagGroup(TagGroupBldr *tag_bldr) : TagGroup::TagGroup(TagGroupBldr *tag_bldr) :
path_index_map_(&tag_bldr->pathIndexMap()), path_index_map_(&tag_bldr->pathIndexMap()),
hash_(pathIndexMapHash(path_index_map_)), hash_(pathIndexMapHash(path_index_map_)),
ref_count_(0),
own_path_map_(false) own_path_map_(false)
{ {
} }
@ -66,6 +68,18 @@ TagGroup::~TagGroup()
delete path_index_map_; delete path_index_map_;
} }
void
TagGroup::incrRefCount()
{
ref_count_++;
}
void
TagGroup::decrRefCount()
{
ref_count_--;
}
size_t size_t
TagGroup::pathIndexMapHash(PathIndexMap *path_index_map) TagGroup::pathIndexMapHash(PathIndexMap *path_index_map)
{ {

View File

@ -65,6 +65,9 @@ public:
size_t pathIndex(Tag *tag) const; size_t pathIndex(Tag *tag) const;
PathIndexMap *pathIndexMap() const { return path_index_map_; } PathIndexMap *pathIndexMap() const { return path_index_map_; }
bool hasTag(Tag *tag) const; bool hasTag(Tag *tag) const;
void incrRefCount();
void decrRefCount();
int refCount() const { return ref_count_; }
protected: protected:
static size_t pathIndexMapHash(PathIndexMap *path_index_map); static size_t pathIndexMapHash(PathIndexMap *path_index_map);
@ -72,6 +75,7 @@ protected:
// tag -> path index // tag -> path index
PathIndexMap *path_index_map_; PathIndexMap *path_index_map_;
size_t hash_; size_t hash_;
int ref_count_;
unsigned int index_:tag_group_index_bits; unsigned int index_:tag_group_index_bits;
bool has_clk_tag_:1; bool has_clk_tag_:1;
bool has_genclk_src_tag_:1; bool has_genclk_src_tag_:1;