From b0bede4c6d2638a2f5fb2452c51d6925c23cf886 Mon Sep 17 00:00:00 2001 From: James Cherry Date: Thu, 15 Jun 2023 09:52:32 -0700 Subject: [PATCH] Set::intersects Signed-off-by: James Cherry --- include/sta/ExceptionPath.hh | 18 +++++--- include/sta/NetworkClass.hh | 9 ++++ include/sta/Set.hh | 22 +++++----- network/Network.cc | 28 +++++++++++++ sdc/ExceptionPath.cc | 80 ++++++++++++++++++++---------------- sdc/Sdc.cc | 8 ++-- search/Crpr.cc | 2 +- 7 files changed, 110 insertions(+), 57 deletions(-) diff --git a/include/sta/ExceptionPath.hh b/include/sta/ExceptionPath.hh index f29e99bb..75d7f287 100644 --- a/include/sta/ExceptionPath.hh +++ b/include/sta/ExceptionPath.hh @@ -61,7 +61,8 @@ public: ExceptionThruSeq *thrus() const { return thrus_; } ExceptionTo *to() const { return to_; } ExceptionPt *firstPt(); - bool intersectsPts(ExceptionPath *exception) const; + bool intersectsPts(ExceptionPath *exception, + const Network *network) const; const MinMaxAll *minMax() const { return min_max_; } virtual bool matches(const MinMax *min_max, bool exact) const; @@ -71,7 +72,8 @@ public: virtual bool resetMatch(ExceptionFrom *from, ExceptionThruSeq *thrus, ExceptionTo *to, - const MinMaxAll *min_max); + const MinMaxAll *min_max, + const Network *network); // The priority remains the same even though pin/clock/net/inst objects // are added to the exceptions points during exception merging because // only exceptions with the same priority are merged. @@ -262,7 +264,8 @@ public: virtual bool resetMatch(ExceptionFrom *from, ExceptionThruSeq *thrus, ExceptionTo *to, - const MinMaxAll *min_max); + const MinMaxAll *min_max, + const Network *network); virtual int typePriority() const; virtual bool tighterThan(ExceptionPath *exception) const; }; @@ -424,7 +427,8 @@ public: const Network *network); ExceptionFrom *clone(const Network *network); virtual bool isFrom() const { return true; } - bool intersectsPts(ExceptionFrom *from) const; + bool intersectsPts(ExceptionFrom *from, + const Network *network) const; virtual int typePriority() const { return 0; } protected: @@ -448,7 +452,8 @@ public: virtual bool isTo() const { return true; } const char *asString(const Network *network) const; const RiseFallBoth *endTransition() { return end_rf_; } - bool intersectsPts(ExceptionTo *to) const; + bool intersectsPts(ExceptionTo *to, + const Network *network) const; virtual int typePriority() const { return 1; } bool matches(const Pin *pin, const ClockEdge *clk_edge, @@ -511,7 +516,8 @@ public: const Network *network) const; virtual void mergeInto(ExceptionPt *pt, const Network *network); - bool intersectsPts(ExceptionThru *thru) const; + bool intersectsPts(ExceptionThru *thru, + const Network *network) const; virtual int typePriority() const { return 2; } virtual size_t objectCount() const; virtual void connectPinAfter(PinSet *drvrs, diff --git a/include/sta/NetworkClass.hh b/include/sta/NetworkClass.hh index dc2b98d5..1fd75778 100644 --- a/include/sta/NetworkClass.hh +++ b/include/sta/NetworkClass.hh @@ -146,6 +146,9 @@ public: static int compare(const InstanceSet *set1, const InstanceSet *set2, const Network *network); + static bool intersects(const InstanceSet *set1, + const InstanceSet *set2, + const Network *network); }; class PinSet : public Set @@ -156,6 +159,9 @@ public: static int compare(const PinSet *set1, const PinSet *set2, const Network *network); + static bool intersects(const PinSet *set1, + const PinSet *set2, + const Network *network); }; class NetSet : public Set @@ -166,6 +172,9 @@ public: static int compare(const NetSet *set1, const NetSet *set2, const Network *network); + static bool intersects(const NetSet *set1, + const NetSet *set2, + const Network *network); }; } // namespace diff --git a/include/sta/Set.hh b/include/sta/Set.hh index 9d0dd92e..a18c42ae 100644 --- a/include/sta/Set.hh +++ b/include/sta/Set.hh @@ -70,7 +70,8 @@ public: static bool intersects(const std::set *set1, - const std::set *set2); + const std::set *set2, + CMP key_less); // Java style container itererator // Set::Iterator iter(set); @@ -170,20 +171,21 @@ Set::isSubset(const std::set *set2) template bool Set::intersects(const std::set *set1, - const std::set *set2) + const std::set *set2, + CMP key_less) { - if (set1 && !set1->empty() - && set2 && !set2->empty()) { - if (set2->size() > set1->size()) - std::swap(set1, set2); + if (set1 && set2) { + auto iter1 = set1->begin(); auto end1 = set1->end(); auto iter2 = set2->begin(); auto end2 = set2->end(); - while (iter2 != end2) { - const KEY key2 = *iter2; - if (set1->find(key2) != end1) + while (iter1 != end1 && iter2 != end2) { + if (key_less(*iter1, *iter2)) + iter1++; + else if (key_less(*iter2, *iter1)) + iter2++; + else return true; - iter2++; } } return false; diff --git a/network/Network.cc b/network/Network.cc index c26f38fe..e6f0b99a 100644 --- a/network/Network.cc +++ b/network/Network.cc @@ -2093,6 +2093,16 @@ InstanceSet::compare(const InstanceSet *set1, return (size1 > size2) ? 1 : -1; } +bool +InstanceSet::intersects(const InstanceSet *set1, + const InstanceSet *set2, + const Network *network) +{ + return Set::intersects(set1, set2, InstanceIdLess(network)); +} + +//////////////////////////////////////////////////////////////// + PinSet::PinSet() : Set(PinIdLess(nullptr)) { @@ -2130,6 +2140,16 @@ PinSet::compare(const PinSet *set1, return (size1 > size2) ? 1 : -1; } +bool +PinSet::intersects(const PinSet *set1, + const PinSet *set2, + const Network *network) +{ + return Set::intersects(set1, set2, PinIdLess(network)); +} + +//////////////////////////////////////////////////////////////// + NetSet::NetSet() : Set(NetIdLess(nullptr)) { @@ -2167,4 +2187,12 @@ NetSet::compare(const NetSet *set1, return (size1 > size2) ? 1 : -1; } +bool +NetSet::intersects(const NetSet *set1, + const NetSet *set2, + const Network *network) +{ + return Set::intersects(set1, set2, NetIdLess(network)); +} + } // namespace diff --git a/sdc/ExceptionPath.cc b/sdc/ExceptionPath.cc index d04946ff..ed885a69 100644 --- a/sdc/ExceptionPath.cc +++ b/sdc/ExceptionPath.cc @@ -31,7 +31,8 @@ namespace sta { static bool thrusIntersectPts(ExceptionThruSeq *thrus1, - ExceptionThruSeq *thrus2); + ExceptionThruSeq *thrus2, + const Network *network); static void insertPinPairsThruHierPin(const Pin *hpin, const Network *network, @@ -273,23 +274,24 @@ ExceptionPath::mergeablePts(ExceptionPath *exception2, } bool -ExceptionPath::intersectsPts(ExceptionPath *exception) const +ExceptionPath::intersectsPts(ExceptionPath *exception, + const Network *network) const { ExceptionFrom *from2 = exception->from(); ExceptionThruSeq *thrus2 = exception->thrus(); ExceptionTo *to2 = exception->to(); if (((from_ == nullptr && from2 == nullptr) - || (from_ && from2 && from_->intersectsPts(from2))) + || (from_ && from2 && from_->intersectsPts(from2, network))) && ((thrus_ == nullptr && thrus2 == nullptr) || (thrus_ && thrus2 && thrus_->size() == thrus2->size())) && ((to_ == nullptr && to2 == nullptr) - || (to_ && to2 && to_->intersectsPts(to2)))) { + || (to_ && to2 && to_->intersectsPts(to2, network)))) { ExceptionThruSeq::Iterator thrus_iter1(thrus_); ExceptionThruSeq::Iterator thrus_iter2(thrus2); while (thrus_iter1.hasNext() && thrus_iter2.hasNext()) { ExceptionThru *thru1 = thrus_iter1.next(); ExceptionThru *thru2 = thrus_iter2.next(); - if (!thru1->intersectsPts(thru2)) + if (!thru1->intersectsPts(thru2, network)) return false; } return true; @@ -373,7 +375,8 @@ bool ExceptionPath::resetMatch(ExceptionFrom *from, ExceptionThruSeq *thrus, ExceptionTo *to, - const MinMaxAll *min_max) + const MinMaxAll *min_max, + const Network *network) { // Only the reset expception points need to match. // For example, if the reset is -from, it matches any @@ -382,56 +385,57 @@ ExceptionPath::resetMatch(ExceptionFrom *from, return ((from && from_ && thrus == nullptr && to == nullptr - && from_->intersectsPts(from)) + && from_->intersectsPts(from, network)) // -thru || (from == nullptr && thrus && thrus_ && to == nullptr - && thrusIntersectPts(thrus_, thrus)) + && thrusIntersectPts(thrus_, thrus, network)) // -to || (from == nullptr && thrus == nullptr && to && to_ - && to_->intersectsPts(to)) + && to_->intersectsPts(to, network)) // -from -thru || (from && from_ && thrus && thrus_ && to == nullptr - && from_->intersectsPts(from) - && thrusIntersectPts(thrus_, thrus)) + && from_->intersectsPts(from, network) + && thrusIntersectPts(thrus_, thrus, network)) // -from -to || (from && from_ && thrus == nullptr && to && to_ - && from_->intersectsPts(from) - && to_->intersectsPts(to)) + && from_->intersectsPts(from, network) + && to_->intersectsPts(to, network)) // -thru -to || (from == nullptr && thrus && thrus_ && to && to_ - && thrusIntersectPts(thrus_, thrus) - && to_->intersectsPts(to)) + && thrusIntersectPts(thrus_, thrus, network) + && to_->intersectsPts(to, network)) // -from -thru -to || (from && from_ && thrus && thrus_ && to && to_ - && from_->intersectsPts(from) - && thrusIntersectPts(thrus_, thrus) - && to_->intersectsPts(to))) + && from_->intersectsPts(from, network) + && thrusIntersectPts(thrus_, thrus, network) + && to_->intersectsPts(to, network))) && (min_max == MinMaxAll::all() || min_max_ == min_max); } static bool thrusIntersectPts(ExceptionThruSeq *thrus1, - ExceptionThruSeq *thrus2) + ExceptionThruSeq *thrus2, + const Network *network) { ExceptionThruSeq::Iterator thrus_iter1(thrus1); ExceptionThruSeq::Iterator thrus_iter2(thrus2); while (thrus_iter1.hasNext() && thrus_iter2.hasNext()) { ExceptionThru *thru1 = thrus_iter1.next(); ExceptionThru *thru2 = thrus_iter2.next(); - if (!thru1->intersectsPts(thru2)) + if (!thru1->intersectsPts(thru2, network)) return false; } return true; @@ -774,7 +778,8 @@ bool FilterPath::resetMatch(ExceptionFrom *, ExceptionThruSeq *, ExceptionTo *, - const MinMaxAll *) + const MinMaxAll *, + const Network *) { return false; } @@ -1220,12 +1225,13 @@ ExceptionFrom::clone(const Network *network) } bool -ExceptionFrom::intersectsPts(ExceptionFrom *from) const +ExceptionFrom::intersectsPts(ExceptionFrom *from, + const Network *network) const { return from->transition() == rf_ - && ((pins_ && PinSet::intersects(pins_, from->pins())) - || (clks_ && ClockSet::intersects(clks_, from->clks())) - || (insts_ && InstanceSet::intersects(insts_, from->instances()))); + && ((pins_ && PinSet::intersects(pins_, from->pins(), network)) + || (clks_ && ClockSet::intersects(clks_, from->clks(), ClockIndexLess())) + || (insts_ && InstanceSet::intersects(insts_, from->instances(), network))); } const char * @@ -1284,13 +1290,14 @@ ExceptionTo::asString(const Network *network) const } bool -ExceptionTo::intersectsPts(ExceptionTo *to) const +ExceptionTo::intersectsPts(ExceptionTo *to, + const Network *network) const { return to->transition() == rf_ && to->endTransition() == end_rf_ - && ((pins_ && PinSet::intersects(pins_, to->pins())) - || (clks_ && ClockSet::intersects(clks_, to->clks())) - || (insts_ && InstanceSet::intersects(insts_, to->instances()))); + && ((pins_ && PinSet::intersects(pins_, to->pins(), network)) + || (clks_ && ClockSet::intersects(clks_, to->clks(), ClockIndexLess())) + || (insts_ && InstanceSet::intersects(insts_, to->instances(), network))); } bool @@ -1926,12 +1933,13 @@ ExceptionThru::deleteObjects(ExceptionThru *pt, } bool -ExceptionThru::intersectsPts(ExceptionThru *thru) const +ExceptionThru::intersectsPts(ExceptionThru *thru, + const Network *network) const { return thru->transition() == rf_ - && ((pins_ && PinSet::intersects(pins_, thru->pins())) - || (nets_ && NetSet::intersects(nets_, thru->nets())) - || (insts_ && InstanceSet::intersects(insts_, thru->instances()))); + && ((pins_ && PinSet::intersects(pins_, thru->pins(), network)) + || (nets_ && NetSet::intersects(nets_, thru->nets(), network)) + || (insts_ && InstanceSet::intersects(insts_, thru->instances(), network))); } size_t @@ -1973,7 +1981,7 @@ ExceptionThru::connectPinAfter(PinSet *drvrs, for (const Pin *thru_pin : *pins_) { if (network->isHierarchical(thru_pin)) { PinSet *thru_pin_drvrs = network->drivers(thru_pin); - if (PinSet::intersects(drvrs, thru_pin_drvrs)) + if (PinSet::intersects(drvrs, thru_pin_drvrs, network)) makePinEdges(thru_pin, network); } } @@ -1985,7 +1993,7 @@ ExceptionThru::connectPinAfter(PinSet *drvrs, while (inst_pin_iter->hasNext()) { Pin *inst_pin = inst_pin_iter->next(); PinSet *inst_pin_drvrs = network->drivers(inst_pin); - if (PinSet::intersects(drvrs, inst_pin_drvrs)) + if (PinSet::intersects(drvrs, inst_pin_drvrs, network)) makePinEdges(inst_pin, network); } delete inst_pin_iter; @@ -1995,7 +2003,7 @@ ExceptionThru::connectPinAfter(PinSet *drvrs, if (nets_) { for (const Net *net : *nets_) { PinSet *net_drvrs = network->drivers(net); - if (PinSet::intersects(drvrs, net_drvrs)) + if (PinSet::intersects(drvrs, net_drvrs, network)) makeNetEdges(net, network); } } diff --git a/sdc/Sdc.cc b/sdc/Sdc.cc index b0c512c8..adf86689 100644 --- a/sdc/Sdc.cc +++ b/sdc/Sdc.cc @@ -4355,7 +4355,7 @@ Sdc::findMatchingExceptionsFirstThru(ExceptionPath *exception, ExceptionThru *match_thru = (*match->thrus())[0]; if (match_thru->nets()->hasKey(net) && match->overrides(exception) - && match->intersectsPts(exception)) + && match->intersectsPts(exception, network_)) matches.insert(match); } } @@ -4427,7 +4427,7 @@ Sdc::findMatchingExceptions(ExceptionPath *exception, if (potential_matches) { for (ExceptionPath *match : *potential_matches) { if (match->overrides(exception) - && match->intersectsPts(exception)) + && match->intersectsPts(exception, network_)) matches.insert(match); } } @@ -5072,7 +5072,7 @@ Sdc::resetPath(ExceptionFrom *from, ExceptionPathSet::Iterator except_iter(exceptions_); while (except_iter.hasNext()) { ExceptionPath *match = except_iter.next(); - if (match->resetMatch(from, thrus, to, min_max)) { + if (match->resetMatch(from, thrus, to, min_max, network_)) { debugPrint(debug_, "exception_match", 3, "reset match %s", match->asString(network_)); ExceptionPathSet expansions; @@ -5081,7 +5081,7 @@ Sdc::resetPath(ExceptionFrom *from, ExceptionPathSet::Iterator expand_iter(expansions); while (expand_iter.hasNext()) { ExceptionPath *expand = expand_iter.next(); - if (expand->resetMatch(from, thrus, to, min_max)) { + if (expand->resetMatch(from, thrus, to, min_max, network_)) { unrecordPathDelayInternalStartpoints(expand->from()); unrecordPathDelayInternalEndpoints(expand); delete expand; diff --git a/search/Crpr.cc b/search/Crpr.cc index d06f4a6f..effa5b1d 100644 --- a/search/Crpr.cc +++ b/search/Crpr.cc @@ -402,7 +402,7 @@ CheckCrpr::crprPossible(const Clock *clk1, || clk1->isGenerated() || clk2->isGenerated() // Different non-generated clocks with the same source pins (using -add). - || PinSet::intersects(&clk1->pins(), &clk2->pins())); + || PinSet::intersects(&clk1->pins(), &clk2->pins(), network_)); } } // namespace