Add local tag caches to PathVisitors (#316)

* Add tag caches to PathVisitor and Search for visit_parallel

Signed-off-by: Drew Lewis <cannada@google.com>

* Apply clang-format

* Update to avoid Search storing caches and touching Bfs.cc

Signed-off-by: Drew Lewis <cannada@google.com>

* Update to avoid Search storing caches and touching Bfs.cc

Signed-off-by: Drew Lewis <cannada@google.com>

* Fixed long lines and moved nullptr assignment to constructors

Signed-off-by: Drew Lewis <cannada@google.com>

---------

Signed-off-by: Drew Lewis <cannada@google.com>
This commit is contained in:
Drew Lewis 2025-11-03 18:53:17 -05:00 committed by GitHub
parent 9f3123cff1
commit 423c12c8f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 90 additions and 61 deletions

View File

@ -256,7 +256,8 @@ public:
Edge *edge, Edge *edge,
const RiseFall *to_rf, const RiseFall *to_rf,
const MinMax *min_max, const MinMax *min_max,
const PathAnalysisPt *path_ap); const PathAnalysisPt *path_ap,
TagSet *tag_cache = nullptr);
Tag *thruClkTag(Path *from_path, Tag *thruClkTag(Path *from_path,
Vertex *from_vertex, Vertex *from_vertex,
Tag *from_tag, Tag *from_tag,
@ -331,7 +332,8 @@ public:
InputDelay *input_delay, InputDelay *input_delay,
bool is_segment_start, bool is_segment_start,
ExceptionStateSet *states, ExceptionStateSet *states,
bool own_states); bool own_states,
TagSet *tag_cache = nullptr);
void reportTags() const; void reportTags() const;
void reportClkInfos() const; void reportClkInfos() const;
const ClkInfo *findClkInfo(const ClockEdge *clk_edge, const ClkInfo *findClkInfo(const ClockEdge *clk_edge,
@ -527,7 +529,8 @@ protected:
const ClkInfo *to_clk_info, const ClkInfo *to_clk_info,
InputDelay *to_input_delay, InputDelay *to_input_delay,
const MinMax *min_max, const MinMax *min_max,
const PathAnalysisPt *path_ap); const PathAnalysisPt *path_ap,
TagSet *tag_cache = nullptr);
ExceptionPath *exceptionTo(const Path *path, ExceptionPath *exceptionTo(const Path *path,
const Pin *pin, const Pin *pin,
const RiseFall *rf, const RiseFall *rf,
@ -706,6 +709,7 @@ public:
const StaState *sta); const StaState *sta);
virtual void visitFaninPaths(Vertex *to_vertex); virtual void visitFaninPaths(Vertex *to_vertex);
virtual void visitFanoutPaths(Vertex *from_vertex); virtual void visitFanoutPaths(Vertex *from_vertex);
void initTagCache();
protected: protected:
// Return false to stop visiting. // Return false to stop visiting.
@ -752,6 +756,7 @@ protected:
const MinMax *min_max, const MinMax *min_max,
const PathAnalysisPt *path_ap) = 0; const PathAnalysisPt *path_ap) = 0;
SearchPred *pred_; SearchPred *pred_;
std::unique_ptr<TagSet> tag_cache_;
}; };
// Visitor called during forward search to record an // Visitor called during forward search to record an

View File

@ -1149,7 +1149,9 @@ ArrivalVisitor::init(bool always_to_endpoints,
VertexVisitor * VertexVisitor *
ArrivalVisitor::copy() const ArrivalVisitor::copy() const
{ {
return new ArrivalVisitor(always_to_endpoints_, pred_, this); auto visitor = new ArrivalVisitor(always_to_endpoints_, pred_, this);
visitor->initTagCache();
return visitor;
} }
ArrivalVisitor::~ArrivalVisitor() ArrivalVisitor::~ArrivalVisitor()
@ -2035,17 +2037,25 @@ Search::inputDelayTag(const Pin *pin,
PathVisitor::PathVisitor(const StaState *sta) : PathVisitor::PathVisitor(const StaState *sta) :
StaState(sta), StaState(sta),
pred_(sta->search()->evalPred()) pred_(sta->search()->evalPred()),
tag_cache_(nullptr)
{ {
} }
PathVisitor::PathVisitor(SearchPred *pred, PathVisitor::PathVisitor(SearchPred *pred,
const StaState *sta) : const StaState *sta) :
StaState(sta), StaState(sta),
pred_(pred) pred_(pred),
tag_cache_(nullptr)
{ {
} }
void
PathVisitor::initTagCache()
{
tag_cache_ = std::make_unique<TagSet>(128, TagSet::hasher(this), TagSet::key_equal(this));
}
void void
PathVisitor::visitFaninPaths(Vertex *to_vertex) PathVisitor::visitFaninPaths(Vertex *to_vertex)
{ {
@ -2233,7 +2243,7 @@ PathVisitor::visitFromPath(const Pin *from_pin,
to_clk_info, to_pin, to_rf, min_max, to_clk_info, to_pin, to_rf, min_max,
path_ap); path_ap);
if (to_tag) if (to_tag)
to_tag = search_->thruTag(to_tag, edge, to_rf, min_max, path_ap); to_tag = search_->thruTag(to_tag, edge, to_rf, min_max, path_ap, tag_cache_.get());
from_arrival = search_->clkPathArrival(from_path, from_clk_info, from_arrival = search_->clkPathArrival(from_path, from_clk_info,
clk_edge, min_max, path_ap); clk_edge, min_max, path_ap);
to_arrival = from_arrival + arc_delay; to_arrival = from_arrival + arc_delay;
@ -2249,7 +2259,7 @@ PathVisitor::visitFromPath(const Pin *from_pin,
latches_->latchOutArrival(from_path, arc, edge, path_ap, latches_->latchOutArrival(from_path, arc, edge, path_ap,
to_tag, arc_delay, to_arrival); to_tag, arc_delay, to_arrival);
if (to_tag) if (to_tag)
to_tag = search_->thruTag(to_tag, edge, to_rf, min_max, path_ap); to_tag = search_->thruTag(to_tag, edge, to_rf, min_max, path_ap, tag_cache_.get());
} }
} }
else if (from_tag->isClock()) { else if (from_tag->isClock()) {
@ -2288,7 +2298,7 @@ PathVisitor::visitFromPath(const Pin *from_pin,
else { else {
if (!(sdc_->isPathDelayInternalFromBreak(to_pin) if (!(sdc_->isPathDelayInternalFromBreak(to_pin)
|| sdc_->isPathDelayInternalToBreak(from_pin))) { || sdc_->isPathDelayInternalToBreak(from_pin))) {
to_tag = search_->thruTag(from_tag, edge, to_rf, min_max, path_ap); to_tag = search_->thruTag(from_tag, edge, to_rf, min_max, path_ap, tag_cache_.get());
arc_delay = search_->deratedDelay(from_vertex, arc, edge, false, path_ap); arc_delay = search_->deratedDelay(from_vertex, arc, edge, false, path_ap);
if (!delayInf(arc_delay)) if (!delayInf(arc_delay))
to_arrival = from_arrival + arc_delay; to_arrival = from_arrival + arc_delay;
@ -2453,7 +2463,8 @@ Search::thruTag(Tag *from_tag,
Edge *edge, Edge *edge,
const RiseFall *to_rf, const RiseFall *to_rf,
const MinMax *min_max, const MinMax *min_max,
const PathAnalysisPt *path_ap) const PathAnalysisPt *path_ap,
TagSet *tag_cache)
{ {
const Pin *from_pin = edge->from(graph_)->pin(); const Pin *from_pin = edge->from(graph_)->pin();
Vertex *to_vertex = edge->to(graph_); Vertex *to_vertex = edge->to(graph_);
@ -2464,7 +2475,8 @@ Search::thruTag(Tag *from_tag,
Tag *to_tag = mutateTag(from_tag, from_pin, from_rf, false, from_clk_info, Tag *to_tag = mutateTag(from_tag, from_pin, from_rf, false, from_clk_info,
to_pin, to_rf, false, to_is_reg_clk, false, to_pin, to_rf, false, to_is_reg_clk, false,
// input delay is not propagated. // input delay is not propagated.
from_clk_info, nullptr, min_max, path_ap); from_clk_info, nullptr, min_max, path_ap,
tag_cache);
return to_tag; return to_tag;
} }
@ -2629,7 +2641,8 @@ Search::mutateTag(Tag *from_tag,
const ClkInfo *to_clk_info, const ClkInfo *to_clk_info,
InputDelay *to_input_delay, InputDelay *to_input_delay,
const MinMax *min_max, const MinMax *min_max,
const PathAnalysisPt *path_ap) const PathAnalysisPt *path_ap,
TagSet *tag_cache)
{ {
ExceptionStateSet *new_states = nullptr; ExceptionStateSet *new_states = nullptr;
ExceptionStateSet *from_states = from_tag->states(); ExceptionStateSet *from_states = from_tag->states();
@ -2713,8 +2726,8 @@ Search::mutateTag(Tag *from_tag,
if (new_states) if (new_states)
return findTag(to_rf, path_ap, to_clk_info, to_is_clk, return findTag(to_rf, path_ap, to_clk_info, to_is_clk,
from_tag->inputDelay(), to_is_segment_start, from_tag->inputDelay(), to_is_segment_start, new_states,
new_states, true); true, tag_cache);
else { else {
// No state change. // No state change.
if (to_clk_info == from_clk_info if (to_clk_info == from_clk_info
@ -2724,9 +2737,8 @@ Search::mutateTag(Tag *from_tag,
&& from_tag->inputDelay() == to_input_delay) && from_tag->inputDelay() == to_input_delay)
return from_tag; return from_tag;
else else
return findTag(to_rf, path_ap, to_clk_info, to_is_clk, return findTag(to_rf, path_ap, to_clk_info, to_is_clk, to_input_delay,
to_input_delay, to_is_segment_start, to_is_segment_start, from_states, false, tag_cache);
from_states, false);
} }
} }
@ -2978,10 +2990,16 @@ Search::findTag(const RiseFall *rf,
InputDelay *input_delay, InputDelay *input_delay,
bool is_segment_start, bool is_segment_start,
ExceptionStateSet *states, ExceptionStateSet *states,
bool own_states) bool own_states,
TagSet *tag_cache)
{ {
Tag probe(0, rf->index(), path_ap->index(), clk_info, is_clk, input_delay, Tag probe(0, rf->index(), path_ap->index(), clk_info, is_clk, input_delay,
is_segment_start, states, false, this); is_segment_start, states, false, this);
if (tag_cache) {
auto tag = tag_cache->findKey(&probe);
if (tag)
return tag;
}
LockGuard lock(tag_lock_); LockGuard lock(tag_lock_);
Tag *tag = tag_set_->findKey(&probe); Tag *tag = tag_set_->findKey(&probe);
if (tag == nullptr) { if (tag == nullptr) {
@ -3019,6 +3037,10 @@ Search::findTag(const RiseFall *rf,
} }
if (own_states) if (own_states)
delete states; delete states;
if (tag_cache)
tag_cache->insert(tag);
return tag; return tag;
} }
@ -3540,7 +3562,9 @@ RequiredVisitor::~RequiredVisitor()
VertexVisitor * VertexVisitor *
RequiredVisitor::copy() const RequiredVisitor::copy() const
{ {
return new RequiredVisitor(this); auto visitor = new RequiredVisitor(this);
visitor->initTagCache();
return visitor;
} }
void void