2020-08-09 03:44:19 +02:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2025-01-22 02:54:33 +01:00
|
|
|
// Copyright (c) 2025, Parallax Software, Inc.
|
2020-08-09 03:44:19 +02:00
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2022-01-04 18:17:08 +01:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2020-08-09 03:44:19 +02:00
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2022-01-04 18:17:08 +01:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2025-01-22 02:54:33 +01:00
|
|
|
//
|
|
|
|
|
// The origin of this software must not be misrepresented; you must not
|
|
|
|
|
// claim that you wrote the original software.
|
|
|
|
|
//
|
|
|
|
|
// Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
// misrepresented as being the original software.
|
|
|
|
|
//
|
|
|
|
|
// This notice may not be removed or altered from any source distribution.
|
2020-08-09 03:44:19 +02:00
|
|
|
|
|
|
|
|
#include "ClkNetwork.hh"
|
|
|
|
|
|
|
|
|
|
#include "Debug.hh"
|
|
|
|
|
#include "Network.hh"
|
|
|
|
|
#include "Graph.hh"
|
|
|
|
|
#include "Bfs.hh"
|
|
|
|
|
#include "Sdc.hh"
|
|
|
|
|
#include "SearchPred.hh"
|
|
|
|
|
#include "Search.hh"
|
|
|
|
|
|
|
|
|
|
namespace sta {
|
|
|
|
|
|
|
|
|
|
ClkNetwork::ClkNetwork(StaState *sta) :
|
|
|
|
|
StaState(sta),
|
|
|
|
|
clk_pins_valid_(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 19:23:45 +01:00
|
|
|
ClkNetwork::~ClkNetwork()
|
|
|
|
|
{
|
|
|
|
|
clk_pins_map_.deleteContentsClear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 03:44:19 +02:00
|
|
|
void
|
|
|
|
|
ClkNetwork::ensureClkNetwork()
|
|
|
|
|
{
|
|
|
|
|
if (!clk_pins_valid_)
|
|
|
|
|
findClkPins();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClkNetwork::clear()
|
|
|
|
|
{
|
|
|
|
|
clk_pins_valid_ = false;
|
|
|
|
|
pin_clks_map_.clear();
|
2023-01-19 19:23:45 +01:00
|
|
|
clk_pins_map_.deleteContentsClear();
|
2020-08-09 03:44:19 +02:00
|
|
|
pin_ideal_clks_map_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClkNetwork::clkPinsInvalid()
|
|
|
|
|
{
|
2021-03-13 01:36:13 +01:00
|
|
|
debugPrint(debug_, "clk_network", 1, "clk network invalid");
|
2020-08-09 03:44:19 +02:00
|
|
|
clk_pins_valid_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClkNetwork::deletePinBefore(const Pin *pin)
|
|
|
|
|
{
|
|
|
|
|
if (isClock(pin))
|
|
|
|
|
clkPinsInvalid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClkNetwork::disconnectPinBefore(const Pin *pin)
|
|
|
|
|
{
|
|
|
|
|
if (isClock(pin))
|
|
|
|
|
clkPinsInvalid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClkNetwork::connectPinAfter(const Pin *pin)
|
|
|
|
|
{
|
|
|
|
|
if (isClock(pin))
|
|
|
|
|
clkPinsInvalid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ClkSearchPred : public ClkTreeSearchPred
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ClkSearchPred(const StaState *sta);
|
|
|
|
|
virtual bool searchTo(const Vertex *to);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ClkSearchPred::ClkSearchPred(const StaState *sta) :
|
|
|
|
|
ClkTreeSearchPred(sta)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ClkSearchPred::searchTo(const Vertex *to)
|
|
|
|
|
{
|
|
|
|
|
const Sdc *sdc = sta_->sdc();
|
|
|
|
|
return !sdc->isLeafPinClock(to->pin());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClkNetwork::findClkPins()
|
|
|
|
|
{
|
2021-03-13 01:36:13 +01:00
|
|
|
debugPrint(debug_, "clk_network", 1, "find clk network");
|
2020-08-09 03:44:19 +02:00
|
|
|
clear();
|
|
|
|
|
findClkPins(false, pin_clks_map_);
|
|
|
|
|
findClkPins(true, pin_ideal_clks_map_);
|
|
|
|
|
clk_pins_valid_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClkNetwork::findClkPins(bool ideal_only,
|
|
|
|
|
PinClksMap &pin_clks_map)
|
|
|
|
|
{
|
|
|
|
|
ClkSearchPred srch_pred(this);
|
|
|
|
|
BfsFwdIterator bfs(BfsIndex::other, &srch_pred, this);
|
|
|
|
|
for (Clock *clk : sdc_->clks()) {
|
|
|
|
|
if (!ideal_only
|
|
|
|
|
|| !clk->isPropagated()) {
|
2023-01-19 19:23:45 +01:00
|
|
|
PinSet *clk_pins = clk_pins_map_[clk];
|
|
|
|
|
if (clk_pins == nullptr) {
|
|
|
|
|
clk_pins = new PinSet(network_);
|
|
|
|
|
clk_pins_map_[clk] = clk_pins;
|
|
|
|
|
}
|
|
|
|
|
for (const Pin *pin : clk->leafPins()) {
|
2020-08-09 03:44:19 +02:00
|
|
|
if (!ideal_only
|
|
|
|
|
|| !sdc_->isPropagatedClock(pin)) {
|
|
|
|
|
Vertex *vertex, *bidirect_drvr_vertex;
|
|
|
|
|
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
|
|
|
|
|
bfs.enqueue(vertex);
|
|
|
|
|
if (bidirect_drvr_vertex)
|
|
|
|
|
bfs.enqueue(bidirect_drvr_vertex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (bfs.hasNext()) {
|
|
|
|
|
Vertex *vertex = bfs.next();
|
2023-01-19 19:23:45 +01:00
|
|
|
const Pin *pin = vertex->pin();
|
2020-08-09 03:44:19 +02:00
|
|
|
if (!ideal_only
|
|
|
|
|
|| !sdc_->isPropagatedClock(pin)) {
|
2023-01-19 19:23:45 +01:00
|
|
|
clk_pins->insert(pin);
|
2020-08-09 03:44:19 +02:00
|
|
|
ClockSet &pin_clks = pin_clks_map[pin];
|
2023-01-19 19:23:45 +01:00
|
|
|
pin_clks.insert(clk);
|
2020-08-09 03:44:19 +02:00
|
|
|
bfs.enqueueAdjacentVertices(vertex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ClkNetwork::isClock(const Pin *pin) const
|
|
|
|
|
{
|
2022-07-12 23:56:17 +02:00
|
|
|
return network_->isRegClkPin(pin)
|
|
|
|
|
|| pin_clks_map_.hasKey(pin);
|
2020-08-09 03:44:19 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 03:31:20 +02:00
|
|
|
bool
|
|
|
|
|
ClkNetwork::isClock(const Net *net) const
|
|
|
|
|
{
|
|
|
|
|
bool is_clk = false;
|
|
|
|
|
NetConnectedPinIterator *pin_iter = network_->pinIterator(net);
|
|
|
|
|
while (pin_iter->hasNext()) {
|
2023-01-19 19:23:45 +01:00
|
|
|
const Pin *pin = pin_iter->next();
|
2020-08-11 03:31:20 +02:00
|
|
|
if (isClock(pin)) {
|
|
|
|
|
is_clk = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete pin_iter;
|
|
|
|
|
return is_clk;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 03:44:19 +02:00
|
|
|
bool
|
|
|
|
|
ClkNetwork::isIdealClock(const Pin *pin) const
|
|
|
|
|
{
|
2020-08-10 07:33:32 +02:00
|
|
|
return pin_ideal_clks_map_.hasKey(pin);
|
2020-08-09 03:44:19 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-06 19:33:16 +02:00
|
|
|
bool
|
|
|
|
|
ClkNetwork::isPropagatedClock(const Pin *pin) const
|
|
|
|
|
{
|
|
|
|
|
return pin_clks_map_.hasKey(pin)
|
|
|
|
|
&& !pin_ideal_clks_map_.hasKey(pin);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 03:44:19 +02:00
|
|
|
const ClockSet *
|
|
|
|
|
ClkNetwork::clocks(const Pin *pin)
|
|
|
|
|
{
|
|
|
|
|
if (pin_clks_map_.hasKey(pin))
|
|
|
|
|
return &pin_clks_map_[pin];
|
|
|
|
|
else
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ClockSet *
|
|
|
|
|
ClkNetwork::idealClocks(const Pin *pin)
|
|
|
|
|
{
|
|
|
|
|
if (pin_ideal_clks_map_.hasKey(pin))
|
|
|
|
|
return &pin_ideal_clks_map_[pin];
|
|
|
|
|
else
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 03:31:20 +02:00
|
|
|
const PinSet *
|
|
|
|
|
ClkNetwork::pins(const Clock *clk)
|
|
|
|
|
{
|
|
|
|
|
if (clk_pins_map_.hasKey(clk))
|
2023-01-19 19:23:45 +01:00
|
|
|
return clk_pins_map_[clk];
|
2020-08-11 03:31:20 +02:00
|
|
|
else
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 03:50:43 +02:00
|
|
|
float
|
|
|
|
|
ClkNetwork::idealClkSlew(const Pin *pin,
|
|
|
|
|
const RiseFall *rf,
|
|
|
|
|
const MinMax *min_max)
|
|
|
|
|
{
|
|
|
|
|
const ClockSet *clks = clk_network_->idealClocks(pin);
|
|
|
|
|
if (clks && !clks->empty()) {
|
|
|
|
|
float slew = min_max->initValue();
|
|
|
|
|
ClockSet::ConstIterator clk_iter(clks);
|
|
|
|
|
while (clk_iter.hasNext()) {
|
|
|
|
|
Clock *clk = clk_iter.next();
|
|
|
|
|
float clk_slew = clk->slew(rf, min_max);
|
|
|
|
|
if (min_max->compare(clk_slew, slew))
|
|
|
|
|
slew = clk_slew;
|
|
|
|
|
}
|
|
|
|
|
return slew;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 03:44:19 +02:00
|
|
|
} // namespace
|