diff --git a/include/sta/Search.hh b/include/sta/Search.hh index d54a8a5b..40ddc542 100644 --- a/include/sta/Search.hh +++ b/include/sta/Search.hh @@ -356,7 +356,8 @@ public: TagGroup *tagGroup(const Vertex *vertex) const; TagGroup *tagGroup(TagGroupIndex index) const; - void reportArrivals(Vertex *vertex) const; + void reportArrivals(Vertex *vertex, + bool report_tag_index) const; Slack wnsSlack(Vertex *vertex, PathAPIndex path_ap_index); void levelsChangedBefore(); @@ -410,6 +411,7 @@ public: TagGroupIndex tag_index); void checkPrevPaths() const; void deletePaths(Vertex *vertex); + void deleteTagGroup(TagGroup *group); protected: void init(StaState *sta); @@ -645,6 +647,7 @@ protected: // Capacity of tag_groups_. TagGroupIndex tag_group_capacity_; std::mutex tag_group_lock_; + std::mutex tag_group_ref_count_lock_; // Latches data outputs to queue on the next search pass. VertexSet *pending_latch_outputs_; std::mutex pending_latch_outputs_lock_; diff --git a/search/Search.cc b/search/Search.cc index 8677dab6..2023daca 100644 --- a/search/Search.cc +++ b/search/Search.cc @@ -554,15 +554,20 @@ Search::deleteFilterTagGroups() for (TagGroupIndex i = 0; i < tag_group_next_; i++) { TagGroup *group = tag_groups_[i]; if (group - && group->hasFilterTag()) { - tag_group_set_->erase(group); - tag_groups_[group->index()] = nullptr; - tag_group_free_indices_.push_back(i); - delete group; - } + && group->hasFilterTag()) + deleteTagGroup(group); } } +void +Search::deleteTagGroup(TagGroup *group) +{ + tag_group_set_->erase(group); + tag_groups_[group->index()] = nullptr; + tag_group_free_indices_.push_back(group->index()); + delete group; +} + void Search::deleteFilterTags() { @@ -2777,6 +2782,15 @@ Search::setVertexArrivals(Vertex *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,12 +2833,14 @@ ReportPathLess::operator()(const Path *path1, } 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()); TagGroup *tag_group = tagGroup(vertex); if (tag_group) { - report_->reportLine("Group %u", tag_group->index()); + if (report_tag_index) + report_->reportLine("Group %u", tag_group->index()); std::vector paths; VertexPathIterator path_iter(vertex, this); while (path_iter.hasNext()) { @@ -2859,7 +2875,7 @@ Search::reportArrivals(Vertex *vertex) const path_ap->pathMinMax()->to_string().c_str(), delayAsString(path->arrival(), this), req, - tag->to_string(true, false, this).c_str(), + tag->to_string(report_tag_index, false, this).c_str(), prev_str.c_str()); } } diff --git a/search/Search.i b/search/Search.i index 73f4761a..76338830 100644 --- a/search/Search.i +++ b/search/Search.i @@ -264,9 +264,10 @@ report_tag_groups() } 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 diff --git a/search/Tag.cc b/search/Tag.cc index d4e36bae..80578548 100644 --- a/search/Tag.cc +++ b/search/Tag.cc @@ -355,7 +355,7 @@ tagCmp(const Tag *tag1, return tagStateCmp(tag1, tag2); } -int +bool tagEqual(const Tag *tag1, const Tag *tag2) { diff --git a/search/Tag.hh b/search/Tag.hh index 3fa91de2..d0e44506 100644 --- a/search/Tag.hh +++ b/search/Tag.hh @@ -140,6 +140,9 @@ public: const Tag *tag2) const; }; +bool +tagEqual(const Tag *tag1, + const Tag *tag2); int tagCmp(const Tag *tag1, const Tag *tag2, diff --git a/search/TagGroup.cc b/search/TagGroup.cc index f060463b..5a79f7de 100644 --- a/search/TagGroup.cc +++ b/search/TagGroup.cc @@ -44,6 +44,7 @@ TagGroup::TagGroup(TagGroupIndex index, bool has_loop_tag) : path_index_map_(path_index_map), hash_(pathIndexMapHash(path_index_map)), + ref_count_(0), index_(index), has_clk_tag_(has_clk_tag), has_genclk_src_tag_(has_genclk_src_tag), @@ -56,6 +57,7 @@ TagGroup::TagGroup(TagGroupIndex index, TagGroup::TagGroup(TagGroupBldr *tag_bldr) : path_index_map_(&tag_bldr->pathIndexMap()), hash_(pathIndexMapHash(path_index_map_)), + ref_count_(0), own_path_map_(false) { } @@ -66,6 +68,18 @@ TagGroup::~TagGroup() delete path_index_map_; } +void +TagGroup::incrRefCount() +{ + ref_count_++; +} + +void +TagGroup::decrRefCount() +{ + ref_count_--; +} + size_t TagGroup::pathIndexMapHash(PathIndexMap *path_index_map) { diff --git a/search/TagGroup.hh b/search/TagGroup.hh index a54f9045..74b073ab 100644 --- a/search/TagGroup.hh +++ b/search/TagGroup.hh @@ -65,6 +65,9 @@ public: size_t pathIndex(Tag *tag) const; PathIndexMap *pathIndexMap() const { return path_index_map_; } bool hasTag(Tag *tag) const; + void incrRefCount(); + void decrRefCount(); + int refCount() const { return ref_count_; } protected: static size_t pathIndexMapHash(PathIndexMap *path_index_map); @@ -72,6 +75,7 @@ protected: // tag -> path index PathIndexMap *path_index_map_; size_t hash_; + int ref_count_; unsigned int index_:tag_group_index_bits; bool has_clk_tag_:1; bool has_genclk_src_tag_:1;