Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize BFS search #214

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions graph/Graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1286,16 +1286,6 @@ Vertex::bfsInQueue(BfsIndex index) const
return (bfs_in_queue_ >> unsigned(index)) & 1;
}

void
Vertex::setBfsInQueue(BfsIndex index,
bool value)
{
if (value)
bfs_in_queue_ |= 1 << int(index);
else
bfs_in_queue_ &= ~(1 << int(index));
}

////////////////////////////////////////////////////////////////
//
// Edge
Expand Down
7 changes: 6 additions & 1 deletion include/sta/Graph.hh
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,12 @@ public:
bool isConstrained() const { return is_constrained_; }
void setIsConstrained(bool constrained);
bool bfsInQueue(BfsIndex index) const;
void setBfsInQueue(BfsIndex index, bool value);
void setBfsInQueue(BfsIndex index) {
bfs_in_queue_ |= (1 << int(index));
}
void clrBfsInQueue(BfsIndex index) {
bfs_in_queue_ &= ~(1 << int(index));
}
bool isRegClk() const { return is_reg_clk_; }
bool crprPathPruningDisabled() const { return crpr_path_pruning_disabled_;}
void setCrprPathPruningDisabled(bool disabled);
Expand Down
2 changes: 1 addition & 1 deletion include/sta/SearchClass.hh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ typedef StringSet PathGroupNameSet;
typedef Vector<PathEnd*> PathEndSeq;
typedef Vector<Arrival> ArrivalSeq;
typedef Map<Vertex*, int> VertexPathCountMap;
typedef UnorderedMap<Tag*, int, TagMatchHash, TagMatchEqual> ArrivalMap;
typedef Map<Tag*, int, TagMatchLess> ArrivalMap;
typedef Vector<PathVertex> PathVertexSeq;
typedef Vector<Slack> SlackSeq;
typedef Delay Crpr;
Expand Down
23 changes: 10 additions & 13 deletions search/Bfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ BfsIterator::clear()
while (levelLessOrEqual(level, last_level_)) {
VertexSeq &level_vertices = queue_[level];
for (auto vertex : level_vertices) {
if (vertex)
vertex->setBfsInQueue(bfs_index_, false);
if (vertex) vertex->clrBfsInQueue(bfs_index_);
}
level_vertices.clear();
incrLevel(level);
Expand Down Expand Up @@ -102,8 +101,7 @@ BfsIterator::deleteEntries(Level level)
{
VertexSeq &level_vertices = queue_[level];
for (auto vertex : level_vertices) {
if (vertex)
vertex->setBfsInQueue(bfs_index_, false);
if (vertex) vertex->clrBfsInQueue(bfs_index_);
}
level_vertices.clear();
}
Expand Down Expand Up @@ -140,7 +138,7 @@ BfsIterator::visit(Level to_level,
{
int visit_count = 0;
while (levelLessOrEqual(first_level_, last_level_)
&& levelLessOrEqual(first_level_, to_level)) {
&& levelLessOrEqual(first_level_, to_level)) {
VertexSeq &level_vertices = queue_[first_level_];
incrLevel(first_level_);
// Note that ArrivalVisitor::enqueueRefPinInputDelays may enqueue
Expand All @@ -149,12 +147,11 @@ BfsIterator::visit(Level to_level,
Vertex *vertex = level_vertices.back();
level_vertices.pop_back();
if (vertex) {
vertex->setBfsInQueue(bfs_index_, false);
vertex->clrBfsInQueue(bfs_index_);
visitor->visit(vertex);
visit_count++;
}
}
level_vertices.clear();
visitor->levelFinished();
}
return visit_count;
Expand Down Expand Up @@ -182,7 +179,7 @@ BfsIterator::visitParallel(Level to_level,
if (vertex_count < thread_count) {
for (Vertex *vertex : level_vertices) {
if (vertex) {
vertex->setBfsInQueue(bfs_index_, false);
vertex->clrBfsInQueue(bfs_index_);
visitor->visit(vertex);
}
}
Expand All @@ -197,7 +194,7 @@ BfsIterator::visitParallel(Level to_level,
for (size_t i = from; i < to; i++) {
Vertex *vertex = level_vertices[i];
if (vertex) {
vertex->setBfsInQueue(bfs_index_, false);
vertex->clrBfsInQueue(bfs_index_);
visitors[k]->visit(vertex);
}
}
Expand Down Expand Up @@ -237,7 +234,7 @@ BfsIterator::next()
VertexSeq &level_vertices = queue_[first_level_];
Vertex *vertex = level_vertices.back();
level_vertices.pop_back();
vertex->setBfsInQueue(bfs_index_, false);
vertex->clrBfsInQueue(bfs_index_);
return vertex;
}

Expand All @@ -258,7 +255,7 @@ BfsIterator::enqueue(Vertex *vertex)
Level level = vertex->level();
UniqueLock lock(queue_lock_);
if (!vertex->bfsInQueue(bfs_index_)) {
vertex->setBfsInQueue(bfs_index_, true);
vertex->setBfsInQueue(bfs_index_);
queue_[level].push_back(vertex);

if (levelLess(last_level_, level))
Expand Down Expand Up @@ -310,8 +307,8 @@ BfsIterator::remove(Vertex *vertex)
&& static_cast<Level>(queue_.size()) > level) {
for (auto &v : queue_[level]) {
if (v == vertex) {
v = nullptr;
vertex->setBfsInQueue(bfs_index_, false);
v = nullptr;
vertex->clrBfsInQueue(bfs_index_);
break;
}
}
Expand Down
22 changes: 2 additions & 20 deletions search/TagGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@ TagGroup::arrivalMapHash(ArrivalMap *arrival_map)
return hash;
}

bool
TagGroup::hasTag(Tag *tag) const
{
return arrival_map_->hasKey(tag);
}

void
TagGroup::arrivalIndex(Tag *tag,
int &arrival_index,
bool &exists) const
{
arrival_map_->findKey(tag, arrival_index, exists);
}

void
TagGroup::report(const StaState *sta) const
{
Expand Down Expand Up @@ -124,9 +110,7 @@ TagGroupBldr::TagGroupBldr(bool match_crpr_clk_pin,
default_arrival_count_(sta->corners()->count()
* RiseFall::index_count
* MinMax::index_count),
arrival_map_(default_arrival_count_,
TagMatchHash(match_crpr_clk_pin, sta),
TagMatchEqual(match_crpr_clk_pin, sta)),
arrival_map_(TagMatchLess(match_crpr_clk_pin, sta)),
arrivals_(default_arrival_count_),
prev_paths_(default_arrival_count_),
has_clk_tag_(false),
Expand Down Expand Up @@ -259,9 +243,7 @@ TagGroupBldr::makeTagGroup(TagGroupIndex index,
ArrivalMap *
TagGroupBldr::makeArrivalMap(const StaState *sta)
{
ArrivalMap *arrival_map = new ArrivalMap(arrival_map_.size(),
TagMatchHash(true, sta),
TagMatchEqual(true, sta));
ArrivalMap *arrival_map = new ArrivalMap(TagMatchLess(true, sta));
int arrival_index = 0;
ArrivalMap::Iterator arrival_iter(arrival_map_);
while (arrival_iter.hasNext()) {
Expand Down
13 changes: 9 additions & 4 deletions search/TagGroup.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ public:
bool hasLoopTag() const { return has_loop_tag_; }
bool ownArrivalMap() const { return own_arrival_map_; }
int arrivalCount() const { return arrival_map_->size(); }
void arrivalIndex(Tag *tag,
int &arrival_index,
bool &exists) const;

void arrivalIndex(Tag *tag, int &arrival_index, bool &exists) const {
arrival_map_->findKey(tag, arrival_index, exists);
}

bool hasTag(Tag *tag) const {
return arrival_map_->hasKey(tag);
}

ArrivalMap *arrivalMap() const { return arrival_map_; }
bool hasTag(Tag *tag) const;

protected:
size_t arrivalMapHash(ArrivalMap *arrival_map);
Expand Down