Files
OpenSTA/graph/Graph.cc
T

1677 lines
39 KiB
C++
Raw Normal View History

2018-09-28 08:54:21 -07:00
// OpenSTA, Static Timing Analyzer
2026-03-10 13:21:17 -07:00
// Copyright (c) 2026, Parallax Software, Inc.
2018-09-28 08:54:21 -07: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 10:17:08 -07:00
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2018-09-28 08:54:21 -07:00
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
2022-01-04 10:17:08 -07:00
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2025-01-21 18:54:33 -07: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.
2018-09-28 08:54:21 -07:00
2020-04-05 14:53:44 -07:00
#include "Graph.hh"
2020-04-05 11:35:51 -07:00
2026-01-03 16:59:35 -08:00
#include "ContainerHelpers.hh"
2020-04-05 14:53:44 -07:00
#include "Debug.hh"
2026-04-15 09:38:10 -07:00
#include "FuncExpr.hh"
#include "Liberty.hh"
2020-04-05 14:53:44 -07:00
#include "MinMax.hh"
#include "Mutex.hh"
#include "Network.hh"
2026-04-15 09:38:10 -07:00
#include "PortDirection.hh"
2026-06-23 15:09:08 -07:00
#include "SearchPred.hh"
2026-04-15 09:38:10 -07:00
#include "Stats.hh"
#include "TimingArc.hh"
#include "TimingRole.hh"
#include "Transition.hh"
2026-03-13 14:06:35 -07:00
#include "Variables.hh"
2018-09-28 08:54:21 -07:00
namespace sta {
////////////////////////////////////////////////////////////////
//
// Graph
//
////////////////////////////////////////////////////////////////
Graph::Graph(StaState *sta,
2026-01-03 16:59:35 -08:00
DcalcAPIndex ap_count) :
2018-09-28 08:54:21 -07:00
StaState(sta),
2026-03-28 19:13:35 -07:00
period_check_annotations_(network_),
2026-06-26 20:20:09 -07:00
reg_clk_vertices_(makeVertexSet(this)),
ap_count_(ap_count)
2018-09-28 08:54:21 -07:00
{
2022-03-01 06:55:25 -07:00
// For the benifit of reg_clk_vertices_ that references graph_.
graph_ = this;
2018-09-28 08:54:21 -07:00
}
Graph::~Graph()
{
2025-02-10 17:31:45 -07:00
edges_->clear();
2018-09-28 08:54:21 -07:00
delete edges_;
2025-02-10 17:31:45 -07:00
vertices_->clear();
delete vertices_;
2019-07-07 09:58:47 -07:00
removePeriodCheckAnnotations();
2018-09-28 08:54:21 -07:00
}
void
Graph::makeGraph()
{
2020-12-29 10:33:22 -08:00
Stats stats(debug_, report_);
2018-09-28 08:54:21 -07:00
makeVerticesAndEdges();
makeWireEdges();
stats.report("Make graph");
}
// Make vertices for each pin.
// Iterate over instances and top level port pins rather than nets
// because network may not connect floating pins to a net
// (ie, Intime occurence tree bleachery).
void
Graph::makeVerticesAndEdges()
{
2019-11-11 08:28:42 -07:00
vertices_ = new VertexTable;
edges_ = new EdgeTable;
2018-09-28 08:54:21 -07:00
LeafInstanceIterator *leaf_iter = network_->leafInstanceIterator();
while (leaf_iter->hasNext()) {
const Instance *inst = leaf_iter->next();
makePinVertices(inst);
makeInstanceEdges(inst);
}
delete leaf_iter;
makePinVertices(network_->topInstance());
}
class FindNetDrvrLoadCounts : public PinVisitor
{
public:
FindNetDrvrLoadCounts(Pin *drvr_pin,
2026-01-03 16:59:35 -08:00
PinSet &visited_drvrs,
int &drvr_count,
int &bidirect_count,
int &load_count,
const Network *network);
2026-03-09 17:43:03 -07:00
void operator()(const Pin *pin) override;
2018-09-28 08:54:21 -07:00
protected:
Pin *drvr_pin_;
PinSet &visited_drvrs_;
int &drvr_count_;
int &bidirect_count_;
int &load_count_;
const Network *network_;
};
FindNetDrvrLoadCounts::FindNetDrvrLoadCounts(Pin *drvr_pin,
2026-01-03 16:59:35 -08:00
PinSet &visited_drvrs,
int &drvr_count,
int &bidirect_count,
int &load_count,
const Network *network) :
2018-09-28 08:54:21 -07:00
drvr_pin_(drvr_pin),
visited_drvrs_(visited_drvrs),
drvr_count_(drvr_count),
bidirect_count_(bidirect_count),
load_count_(load_count),
network_(network)
{
}
void
2024-01-18 11:26:08 -08:00
FindNetDrvrLoadCounts::operator()(const Pin *pin)
2018-09-28 08:54:21 -07:00
{
if (network_->isDriver(pin)) {
if (pin != drvr_pin_)
visited_drvrs_.insert(pin);
if (network_->direction(pin)->isBidirect())
bidirect_count_++;
else
drvr_count_++;
}
if (network_->isLoad(pin))
load_count_++;
}
void
Graph::makePinVertices(const Instance *inst)
{
InstancePinIterator *pin_iter = network_->pinIterator(inst);
while (pin_iter->hasNext()) {
Pin *pin = pin_iter->next();
makePinVertices(pin);
}
delete pin_iter;
}
// Make edges corresponding to library timing arcs.
void
Graph::makeInstanceEdges(const Instance *inst)
{
LibertyCell *cell = network_->libertyCell(inst);
if (cell)
2019-03-12 17:25:53 -07:00
makePortInstanceEdges(inst, cell, nullptr);
2018-09-28 08:54:21 -07:00
}
void
2023-01-19 11:23:45 -07:00
Graph::makePinInstanceEdges(const Pin *pin)
2018-09-28 08:54:21 -07:00
{
const Instance *inst = network_->instance(pin);
if (inst) {
LibertyCell *cell = network_->libertyCell(inst);
if (cell) {
LibertyPort *port = network_->libertyPort(pin);
makePortInstanceEdges(inst, cell, port);
}
}
}
void
Graph::makePortInstanceEdges(const Instance *inst,
2026-01-03 16:59:35 -08:00
LibertyCell *cell,
LibertyPort *from_to_port)
2018-09-28 08:54:21 -07:00
{
for (TimingArcSet *arc_set : cell->timingArcSets()) {
2018-09-28 08:54:21 -07:00
LibertyPort *from_port = arc_set->from();
LibertyPort *to_port = arc_set->to();
2019-05-03 21:23:12 -07:00
if ((from_to_port == nullptr
2026-01-03 16:59:35 -08:00
|| from_port == from_to_port
|| to_port == from_to_port)
&& from_port) {
2018-09-28 08:54:21 -07:00
Pin *from_pin = network_->findPin(inst, from_port);
Pin *to_pin = network_->findPin(inst, to_port);
if (from_pin && to_pin) {
2026-01-03 16:59:35 -08:00
Vertex *from_vertex, *from_bidirect_drvr_vertex;
Vertex *to_vertex, *to_bidirect_drvr_vertex;
pinVertices(from_pin, from_vertex, from_bidirect_drvr_vertex);
pinVertices(to_pin, to_vertex, to_bidirect_drvr_vertex);
// From pin and/or to pin can be bidirect.
// For combinational arcs edge is to driver.
// For timing checks edge is to load.
// Vertices can be missing from the graph if the pins
// are power or ground.
if (from_vertex) {
2025-03-30 15:27:53 -07:00
const TimingRole *role = arc_set->role();
2026-01-03 16:59:35 -08:00
bool is_check = role->isTimingCheckBetween();
if (to_bidirect_drvr_vertex && !is_check)
makeEdge(from_vertex, to_bidirect_drvr_vertex, arc_set);
else if (to_vertex) {
makeEdge(from_vertex, to_vertex, arc_set);
if (is_check) {
to_vertex->setHasChecks(true);
from_vertex->setIsCheckClk(true);
}
}
if (from_bidirect_drvr_vertex && to_vertex) {
// Internal path from bidirect output back into the
// instance.
Edge *edge = makeEdge(from_bidirect_drvr_vertex, to_vertex,
arc_set);
edge->setIsBidirectInstPath(true);
}
}
2018-09-28 08:54:21 -07:00
}
}
}
}
void
Graph::makeWireEdges()
{
2023-01-19 11:23:45 -07:00
PinSet visited_drvrs(network_);
2018-09-28 08:54:21 -07:00
LeafInstanceIterator *inst_iter = network_->leafInstanceIterator();
while (inst_iter->hasNext()) {
Instance *inst = inst_iter->next();
makeInstDrvrWireEdges(inst, visited_drvrs);
}
delete inst_iter;
makeInstDrvrWireEdges(network_->topInstance(), visited_drvrs);
}
void
2023-01-19 11:23:45 -07:00
Graph::makeInstDrvrWireEdges(const Instance *inst,
2026-01-03 16:59:35 -08:00
PinSet &visited_drvrs)
2018-09-28 08:54:21 -07:00
{
InstancePinIterator *pin_iter = network_->pinIterator(inst);
while (pin_iter->hasNext()) {
Pin *pin = pin_iter->next();
if (network_->isDriver(pin)
2026-01-03 16:59:35 -08:00
&& !visited_drvrs.contains(pin))
2018-09-28 08:54:21 -07:00
makeWireEdgesFromPin(pin, visited_drvrs);
if (network_->isTopInstance(inst)
&& network_->direction(pin)->isBidirect()) {
Vertex *bidir_load, *bidir_drvr;
pinVertices(pin, bidir_load, bidir_drvr);
Edge *edge = makeEdge(bidir_load, bidir_drvr, TimingArcSet::wireTimingArcSet());
edge->setIsBidirectPortPath(true);
}
2018-09-28 08:54:21 -07:00
}
delete pin_iter;
}
void
2023-01-19 11:23:45 -07:00
Graph::makeWireEdgesFromPin(const Pin *drvr_pin)
2018-09-28 08:54:21 -07:00
{
PinSeq loads, drvrs;
2023-01-19 11:23:45 -07:00
PinSet visited_drvrs(network_);
2018-09-28 08:54:21 -07:00
FindNetDrvrLoads visitor(drvr_pin, visited_drvrs, loads, drvrs, network_);
network_->visitConnectedPins(drvr_pin, visitor);
2019-03-12 17:25:53 -07:00
for (auto load_pin : loads) {
2018-09-28 08:54:21 -07:00
if (drvr_pin != load_pin)
makeWireEdge(drvr_pin, load_pin);
}
}
void
2023-01-19 11:23:45 -07:00
Graph::makeWireEdgesFromPin(const Pin *drvr_pin,
2026-01-03 16:59:35 -08:00
PinSet &visited_drvrs)
2018-09-28 08:54:21 -07:00
{
// Find all drivers and loads on the net to avoid N*M run time
// for large fanin/fanout nets.
PinSeq drvrs, loads;
2018-09-28 08:54:21 -07:00
FindNetDrvrLoads visitor(drvr_pin, visited_drvrs, loads, drvrs, network_);
network_->visitConnectedPins(drvr_pin, visitor);
if (isIsolatedNet(drvrs, loads)) {
for (auto drvr_pin : drvrs) {
visited_drvrs.insert(drvr_pin);
2026-03-15 14:35:24 -07:00
debugPrint(debug_, "graph", 1, "ignoring isolated driver {}",
network_->pathName(drvr_pin));
}
return;
}
2019-03-12 17:25:53 -07:00
for (auto drvr_pin : drvrs) {
for (auto load_pin : loads) {
2018-09-28 08:54:21 -07:00
if (drvr_pin != load_pin)
2026-01-03 16:59:35 -08:00
makeWireEdge(drvr_pin, load_pin);
2018-09-28 08:54:21 -07:00
}
}
}
// Check for nets with bidirect drivers that have no fanin or
// fanout. One example of these nets are bidirect pad ring pins
// are connected together but have no function but are marked
// as signal nets.
// These nets tickle N^2 behaviors that have no function.
bool
Graph::isIsolatedNet(PinSeq &drvrs,
PinSeq &loads) const
{
if (drvrs.size() < 10)
return false;
// Check that all drivers have no fanin.
for (auto drvr_pin : drvrs) {
Vertex *drvr_vertex = pinDrvrVertex(drvr_pin);
if (network_->isTopLevelPort(drvr_pin)
|| drvr_vertex->hasFanin())
return false;
}
// Check for fanout on the load pins.
for (auto load_pin : loads) {
Vertex *load_vertex = pinLoadVertex(load_pin);
if (load_vertex->hasFanout()
|| load_vertex->hasChecks()) {
return false;
}
}
return true;
}
2018-09-28 08:54:21 -07:00
void
2023-01-19 11:23:45 -07:00
Graph::makeWireEdgesToPin(const Pin *to_pin)
2018-09-28 08:54:21 -07:00
{
PinSet *drvrs = network_->drivers(to_pin);
if (drvrs) {
2019-03-12 17:25:53 -07:00
for (auto drvr : *drvrs) {
2018-09-28 08:54:21 -07:00
if (drvr != to_pin)
2026-01-03 16:59:35 -08:00
makeWireEdge(drvr, to_pin);
2018-09-28 08:54:21 -07:00
}
}
}
class MakeEdgesThruHierPin : public HierPinThruVisitor
{
public:
2019-03-12 17:25:53 -07:00
MakeEdgesThruHierPin(Graph *graph);
2026-03-09 17:43:03 -07:00
void visit(const Pin *drvr,
const Pin *load) override;
2018-09-28 08:54:21 -07:00
2026-04-15 09:38:10 -07:00
private:
2018-09-28 08:54:21 -07:00
Graph *graph_;
};
2019-03-12 17:25:53 -07:00
MakeEdgesThruHierPin::MakeEdgesThruHierPin(Graph *graph) :
2018-09-28 08:54:21 -07:00
HierPinThruVisitor(),
2019-03-12 17:25:53 -07:00
graph_(graph)
2018-09-28 08:54:21 -07:00
{
}
void
2023-01-19 11:23:45 -07:00
MakeEdgesThruHierPin::visit(const Pin *drvr,
2026-01-03 16:59:35 -08:00
const Pin *load)
2018-09-28 08:54:21 -07:00
{
graph_->makeWireEdge(drvr, load);
}
void
2023-01-19 11:23:45 -07:00
Graph::makeWireEdgesThruPin(const Pin *hpin)
2018-09-28 08:54:21 -07:00
{
2019-03-12 17:25:53 -07:00
MakeEdgesThruHierPin visitor(this);
2018-09-28 08:54:21 -07:00
visitDrvrLoadsThruHierPin(hpin, network_, &visitor);
}
void
2023-01-19 11:23:45 -07:00
Graph::makeWireEdge(const Pin *from_pin,
2026-01-03 16:59:35 -08:00
const Pin *to_pin)
2018-09-28 08:54:21 -07:00
{
TimingArcSet *arc_set = TimingArcSet::wireTimingArcSet();
Vertex *from_vertex, *from_bidirect_drvr_vertex;
pinVertices(from_pin, from_vertex, from_bidirect_drvr_vertex);
Vertex *to_vertex = pinLoadVertex(to_pin);
if (from_vertex && to_vertex) {
// From and/or to can be bidirect, but edge is always from driver to load.
if (from_bidirect_drvr_vertex)
makeEdge(from_bidirect_drvr_vertex, to_vertex, arc_set);
else
makeEdge(from_vertex, to_vertex, arc_set);
}
2018-09-28 08:54:21 -07:00
}
////////////////////////////////////////////////////////////////
Vertex *
2019-11-11 09:38:25 -07:00
Graph::vertex(VertexId vertex_id) const
2018-09-28 08:54:21 -07:00
{
2019-11-11 09:38:25 -07:00
return vertices_->pointer(vertex_id);
2018-09-28 08:54:21 -07:00
}
2019-11-11 09:38:25 -07:00
VertexId
Graph::id(const Vertex *vertex) const
2018-09-28 08:54:21 -07:00
{
2019-11-11 08:28:42 -07:00
return vertices_->objectId(vertex);
2018-09-28 08:54:21 -07:00
}
void
Graph::makePinVertices(Pin *pin)
{
Vertex *vertex, *bidir_drvr_vertex;
makePinVertices(pin, vertex, bidir_drvr_vertex);
}
void
Graph::makePinVertices(Pin *pin,
2026-01-03 16:59:35 -08:00
Vertex *&vertex,
Vertex *&bidir_drvr_vertex)
2018-09-28 08:54:21 -07:00
{
2026-07-09 10:29:46 -07:00
vertex = nullptr;
bidir_drvr_vertex = nullptr;
2018-09-28 08:54:21 -07:00
PortDirection *dir = network_->direction(pin);
if (!dir->isPowerGround()) {
bool is_reg_clk = network_->isRegClkPin(pin);
vertex = makeVertex(pin, false, is_reg_clk);
2019-11-11 09:38:25 -07:00
network_->setVertexId(pin, id(vertex));
2018-09-28 08:54:21 -07:00
if (dir->isBidirect()) {
bidir_drvr_vertex = makeVertex(pin, true, is_reg_clk);
pin_bidirect_drvr_vertex_map_[pin] = bidir_drvr_vertex;
}
}
}
Vertex *
Graph::makeVertex(Pin *pin,
2026-01-03 16:59:35 -08:00
bool is_bidirect_drvr,
bool is_reg_clk)
2018-09-28 08:54:21 -07:00
{
2019-11-11 08:28:42 -07:00
Vertex *vertex = vertices_->make();
2018-09-28 08:54:21 -07:00
vertex->init(pin, is_bidirect_drvr, is_reg_clk);
2025-02-10 17:31:45 -07:00
initSlews(vertex);
2018-09-28 08:54:21 -07:00
if (is_reg_clk)
2026-01-03 16:59:35 -08:00
reg_clk_vertices_.insert(vertex);
2018-09-28 08:54:21 -07:00
return vertex;
}
void
Graph::pinVertices(const Pin *pin,
2026-01-03 16:59:35 -08:00
// Return values.
Vertex *&vertex,
Vertex *&bidirect_drvr_vertex) const
2018-09-28 08:54:21 -07:00
{
2019-11-11 09:38:25 -07:00
vertex = Graph::vertex(network_->vertexId(pin));
2018-09-28 08:54:21 -07:00
if (network_->direction(pin)->isBidirect())
2026-01-03 16:59:35 -08:00
bidirect_drvr_vertex = findKey(pin_bidirect_drvr_vertex_map_, pin);
2018-09-28 08:54:21 -07:00
else
2019-03-12 17:25:53 -07:00
bidirect_drvr_vertex = nullptr;
2018-09-28 08:54:21 -07:00
}
Vertex *
Graph::pinDrvrVertex(const Pin *pin) const
{
if (network_->direction(pin)->isBidirect())
2026-01-03 16:59:35 -08:00
return findKey(pin_bidirect_drvr_vertex_map_, pin);
2018-09-28 08:54:21 -07:00
else
2019-11-11 09:38:25 -07:00
return Graph::vertex(network_->vertexId(pin));
2018-09-28 08:54:21 -07:00
}
Vertex *
Graph::pinLoadVertex(const Pin *pin) const
{
2019-11-11 09:38:25 -07:00
return vertex(network_->vertexId(pin));
2018-09-28 08:54:21 -07:00
}
void
Graph::deleteVertex(Vertex *vertex)
{
if (vertex->isRegClk())
2026-01-03 16:59:35 -08:00
reg_clk_vertices_.erase(vertex);
2018-09-28 08:54:21 -07:00
Pin *pin = vertex->pin_;
if (vertex->isBidirectDriver())
pin_bidirect_drvr_vertex_map_.erase(pin_bidirect_drvr_vertex_map_
2026-01-03 16:59:35 -08:00
.find(pin));
2018-09-28 08:54:21 -07:00
else
2019-11-11 09:38:25 -07:00
network_->setVertexId(pin, vertex_id_null);
2018-09-28 08:54:21 -07:00
// Delete edges to vertex.
2019-11-11 09:38:25 -07:00
EdgeId edge_id, next_id;
for (edge_id = vertex->in_edges_; edge_id; edge_id = next_id) {
Edge *edge = Graph::edge(edge_id);
2026-06-23 15:09:08 -07:00
next_id = edge->vertex_in_next_;
2018-09-28 08:54:21 -07:00
deleteOutEdge(edge->from(this), edge);
2025-02-10 17:31:45 -07:00
edge->clear();
2019-11-11 08:28:42 -07:00
edges_->destroy(edge);
2018-09-28 08:54:21 -07:00
}
// Delete edges from vertex.
2019-11-11 09:38:25 -07:00
for (edge_id = vertex->out_edges_; edge_id; edge_id = next_id) {
Edge *edge = Graph::edge(edge_id);
next_id = edge->vertex_out_next_;
2018-09-28 08:54:21 -07:00
deleteInEdge(edge->to(this), edge);
2025-02-10 17:31:45 -07:00
edge->clear();
2019-11-11 08:28:42 -07:00
edges_->destroy(edge);
2018-09-28 08:54:21 -07:00
}
2025-02-10 17:31:45 -07:00
vertex->clear();
2019-11-11 08:28:42 -07:00
vertices_->destroy(vertex);
2018-09-28 08:54:21 -07:00
}
bool
Graph::hasFaninOne(Vertex *vertex) const
{
return vertex->in_edges_
2026-06-23 15:09:08 -07:00
&& edge(vertex->in_edges_)->vertex_in_next_ == 0;
2018-09-28 08:54:21 -07:00
}
void
Graph::deleteInEdge(Vertex *vertex,
2026-01-03 16:59:35 -08:00
Edge *edge)
2018-09-28 08:54:21 -07:00
{
2019-11-11 09:38:25 -07:00
EdgeId edge_id = id(edge);
EdgeId prev = 0;
for (EdgeId i = vertex->in_edges_;
i && i != edge_id;
2026-06-23 15:09:08 -07:00
i = Graph::edge(i)->vertex_in_next_)
2018-09-28 08:54:21 -07:00
prev = i;
if (prev)
2026-06-23 15:09:08 -07:00
Graph::edge(prev)->vertex_in_next_ = edge->vertex_in_next_;
2018-09-28 08:54:21 -07:00
else
2026-06-23 15:09:08 -07:00
vertex->in_edges_ = edge->vertex_in_next_;
2018-09-28 08:54:21 -07:00
}
void
Graph::deleteOutEdge(Vertex *vertex,
2026-01-03 16:59:35 -08:00
Edge *edge)
2018-09-28 08:54:21 -07:00
{
2019-11-11 09:38:25 -07:00
EdgeId next = edge->vertex_out_next_;
EdgeId prev = edge->vertex_out_prev_;
2018-09-28 08:54:21 -07:00
if (prev)
Graph::edge(prev)->vertex_out_next_ = next;
else
vertex->out_edges_ = next;
if (next)
Graph::edge(next)->vertex_out_prev_ = prev;
}
2024-02-27 10:00:48 -07:00
void
Graph::gateEdgeArc(const Pin *in_pin,
const RiseFall *in_rf,
const Pin *drvr_pin,
const RiseFall *drvr_rf,
// Return values.
Edge *&edge,
const TimingArc *&arc) const
{
Vertex *in_vertex = pinLoadVertex(in_pin);
Vertex *drvr_vertex = pinDrvrVertex(drvr_pin);
// Iterate over load drivers to avoid driver fanout^2.
VertexInEdgeIterator edge_iter(drvr_vertex, this);
while (edge_iter.hasNext()) {
Edge *edge1 = edge_iter.next();
if (edge1->from(this) == in_vertex) {
TimingArcSet *arc_set = edge1->timingArcSet();
for (TimingArc *arc1 : arc_set->arcs()) {
if (arc1->fromEdge()->asRiseFall() == in_rf
&& arc1->toEdge()->asRiseFall() == drvr_rf) {
edge = edge1;
arc = arc1;
return;
}
}
}
}
edge = nullptr;
arc = nullptr;
}
2021-09-16 16:18:55 -07:00
////////////////////////////////////////////////////////////////
2026-06-23 15:09:08 -07:00
void
Graph::visitFanouts(Vertex *vertex,
SearchPred *pred,
const VertexFn &fn)
{
if (pred->searchFrom(vertex)) {
2026-07-04 09:04:31 -07:00
VertexOutEdgeIterator edge_iter(vertex, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
2026-06-23 15:09:08 -07:00
Vertex *to_vertex = this->vertex(edge->to_);
2026-06-24 16:55:51 -07:00
if (pred->searchThru(edge)
&& pred->searchTo(to_vertex))
2026-06-23 15:09:08 -07:00
fn(to_vertex);
}
}
}
void
Graph::visitFanoutEdges(Vertex *vertex,
SearchPred *pred,
const EdgeFn &fn)
{
if (pred->searchFrom(vertex)) {
2026-07-04 09:04:31 -07:00
VertexOutEdgeIterator edge_iter(vertex, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
2026-06-23 15:09:08 -07:00
Vertex *to_vertex = this->vertex(edge->to_);
2026-06-24 16:55:51 -07:00
if (pred->searchThru(edge)
&& pred->searchTo(to_vertex))
2026-06-23 15:09:08 -07:00
fn(edge, to_vertex);
}
}
}
void
Graph::visitFanins(Vertex *vertex,
SearchPred *pred,
const VertexFn &fn)
{
if (pred->searchFrom(vertex)) {
2026-07-04 09:04:31 -07:00
VertexInEdgeIterator edge_iter(vertex, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
2026-06-23 15:09:08 -07:00
Vertex *from_vertex = this->vertex(edge->from_);
2026-06-24 16:55:51 -07:00
if (pred->searchThru(edge)
&& pred->searchFrom(from_vertex))
2026-06-23 15:09:08 -07:00
fn(from_vertex);
}
}
}
void
Graph::visitFaninEdges(Vertex *vertex,
SearchPred *pred,
const EdgeFn &fn)
{
if (pred->searchFrom(vertex)) {
2026-07-10 17:07:55 -07:00
VertexInEdgeIterator edge_iter(vertex, graph_);
2026-07-04 09:04:31 -07:00
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
2026-06-23 15:09:08 -07:00
Vertex *from_vertex = this->vertex(edge->from_);
2026-06-24 16:55:51 -07:00
if (pred->searchThru(edge)
&& pred->searchFrom(from_vertex))
2026-06-23 15:09:08 -07:00
fn(edge, from_vertex);
}
}
}
////////////////////////////////////////////////////////////////
2026-03-16 14:53:02 -07:00
Slew
2018-09-28 08:54:21 -07:00
Graph::slew(const Vertex *vertex,
2025-02-10 17:31:45 -07:00
const RiseFall *rf,
DcalcAPIndex ap_index)
2018-09-28 08:54:21 -07:00
{
2026-03-13 14:06:35 -07:00
size_t slew_index = ap_index * RiseFall::index_count + rf->index();
const float *slews_flt = vertex->slewsFloat();
if (variables_->pocvEnabled()) {
2026-04-15 09:38:10 -07:00
const Slew *slews = reinterpret_cast<const Slew*>(slews_flt);
2025-02-10 17:31:45 -07:00
return slews[slew_index];
2018-09-28 08:54:21 -07:00
}
2026-03-16 14:53:02 -07:00
else
return slews_flt[slew_index];
2026-03-13 14:06:35 -07:00
}
2026-03-16 14:53:02 -07:00
Slew
2026-03-13 14:06:35 -07:00
Graph::slew(const Vertex *vertex,
size_t index)
{
const float *slews_flt = vertex->slewsFloat();
if (variables_->pocvEnabled()) {
2026-04-15 09:38:10 -07:00
const Slew *slews = reinterpret_cast<const Slew*>(slews_flt);
2026-03-13 14:06:35 -07:00
return slews[index];
}
2026-03-16 14:53:02 -07:00
else
return slews_flt[index];
2018-09-28 08:54:21 -07:00
}
void
Graph::setSlew(Vertex *vertex,
2025-02-10 17:31:45 -07:00
const RiseFall *rf,
DcalcAPIndex ap_index,
const Slew &slew)
2018-09-28 08:54:21 -07:00
{
2026-03-13 14:06:35 -07:00
size_t slew_index = ap_index * RiseFall::index_count + rf->index();
if (variables_->pocvEnabled()) {
2025-02-10 17:31:45 -07:00
Slew *slews = vertex->slews();
slews[slew_index] = slew;
}
2026-03-13 14:06:35 -07:00
else {
float *slews_flt = vertex->slewsFloat();
slews_flt[slew_index] = slew.mean();
}
}
2018-09-28 08:54:21 -07:00
////////////////////////////////////////////////////////////////
Edge *
2019-11-11 09:38:25 -07:00
Graph::edge(EdgeId edge_id) const
2018-09-28 08:54:21 -07:00
{
2019-11-11 09:38:25 -07:00
return edges_->pointer(edge_id);
2018-09-28 08:54:21 -07:00
}
2019-11-11 09:38:25 -07:00
EdgeId
Graph::id(const Edge *edge) const
2018-09-28 08:54:21 -07:00
{
2019-11-11 08:28:42 -07:00
return edges_->objectId(edge);
2018-09-28 08:54:21 -07:00
}
Edge *
Graph::makeEdge(Vertex *from,
2026-01-03 16:59:35 -08:00
Vertex *to,
TimingArcSet *arc_set)
2018-09-28 08:54:21 -07:00
{
2019-11-11 08:28:42 -07:00
Edge *edge = edges_->make();
2019-11-11 09:38:25 -07:00
edge->init(id(from), id(to), arc_set);
2018-09-28 08:54:21 -07:00
// Add out edge to from vertex.
2019-11-11 08:28:42 -07:00
EdgeId next = from->out_edges_;
2018-09-28 08:54:21 -07:00
edge->vertex_out_next_ = next;
2019-11-11 08:28:42 -07:00
edge->vertex_out_prev_ = edge_id_null;
EdgeId edge_id = edges_->objectId(edge);
2018-09-28 08:54:21 -07:00
if (next)
2019-11-11 08:28:42 -07:00
Graph::edge(next)->vertex_out_prev_ = edge_id;
from->out_edges_ = edge_id;
2018-09-28 08:54:21 -07:00
// Add in edge to to vertex.
2026-06-23 15:09:08 -07:00
edge->vertex_in_next_ = to->in_edges_;
2019-11-11 08:28:42 -07:00
to->in_edges_ = edge_id;
2018-09-28 08:54:21 -07:00
2025-02-10 17:31:45 -07:00
initArcDelays(edge);
2018-09-28 08:54:21 -07:00
return edge;
}
void
Graph::deleteEdge(Edge *edge)
{
Vertex *from = edge->from(this);
Vertex *to = edge->to(this);
deleteOutEdge(from, edge);
deleteInEdge(to, edge);
2025-02-10 17:31:45 -07:00
edge->clear();
2019-11-11 08:28:42 -07:00
edges_->destroy(edge);
2018-09-28 08:54:21 -07:00
}
2026-03-16 14:53:02 -07:00
ArcDelay
2018-09-28 08:54:21 -07:00
Graph::arcDelay(const Edge *edge,
2026-01-03 16:59:35 -08:00
const TimingArc *arc,
DcalcAPIndex ap_index) const
2018-09-28 08:54:21 -07:00
{
2025-02-10 17:31:45 -07:00
size_t index = arc->index() * ap_count_ + ap_index;
2026-03-13 14:06:35 -07:00
if (variables_->pocvEnabled()) {
2026-04-15 09:38:10 -07:00
const ArcDelay *delays = reinterpret_cast<const ArcDelay*>(edge->arcDelays());
2026-03-13 14:06:35 -07:00
return delays[index];
}
else {
const float *delays = edge->arcDelays();
2026-03-16 14:53:02 -07:00
return delays[index];
2026-03-13 14:06:35 -07:00
}
2018-09-28 08:54:21 -07:00
}
void
Graph::setArcDelay(Edge *edge,
2026-01-03 16:59:35 -08:00
const TimingArc *arc,
DcalcAPIndex ap_index,
2026-03-13 14:06:35 -07:00
const ArcDelay &delay)
2018-09-28 08:54:21 -07:00
{
2025-02-10 17:31:45 -07:00
size_t index = arc->index() * ap_count_ + ap_index;
2026-03-13 14:06:35 -07:00
if (variables_->pocvEnabled()) {
2026-04-15 09:38:10 -07:00
ArcDelay *delays = reinterpret_cast<ArcDelay*>(edge->arcDelays());
2026-03-13 14:06:35 -07:00
delays[index] = delay;
}
else {
float *delays = edge->arcDelays();
delays[index] = delay.mean();
}
2018-09-28 08:54:21 -07:00
}
2026-03-16 14:53:02 -07:00
ArcDelay
2018-09-28 08:54:21 -07:00
Graph::wireArcDelay(const Edge *edge,
2026-01-03 16:59:35 -08:00
const RiseFall *rf,
DcalcAPIndex ap_index)
2018-09-28 08:54:21 -07:00
{
2025-02-10 17:31:45 -07:00
size_t index = rf->index() * ap_count_ + ap_index;
2026-03-13 14:06:35 -07:00
if (variables_->pocvEnabled()) {
2026-04-15 09:38:10 -07:00
const ArcDelay *delays = reinterpret_cast<const ArcDelay*>(edge->arcDelays());
2026-03-13 14:06:35 -07:00
return delays[index];
}
else {
const float *delays = edge->arcDelays();
2026-03-16 14:53:02 -07:00
return delays[index];
2026-03-13 14:06:35 -07:00
}
2018-09-28 08:54:21 -07:00
}
void
Graph::setWireArcDelay(Edge *edge,
2026-01-03 16:59:35 -08:00
const RiseFall *rf,
DcalcAPIndex ap_index,
const ArcDelay &delay)
2018-09-28 08:54:21 -07:00
{
2025-02-10 17:31:45 -07:00
size_t index = rf->index() * ap_count_ + ap_index;
2026-03-13 14:06:35 -07:00
if (variables_->pocvEnabled()) {
2026-04-15 09:38:10 -07:00
ArcDelay *delays = reinterpret_cast<ArcDelay*>(edge->arcDelays());
2026-03-13 14:06:35 -07:00
delays[index] = delay;
}
else {
float *delays = edge->arcDelays();
delays[index] = delay.mean();
}
2018-09-28 08:54:21 -07:00
}
2025-02-10 17:31:45 -07:00
////////////////////////////////////////////////////////////////
bool
2023-11-19 10:04:45 -07:00
Graph::arcDelayAnnotated(const Edge *edge,
2026-01-03 16:59:35 -08:00
const TimingArc *arc,
DcalcAPIndex ap_index) const
{
2025-02-10 17:31:45 -07:00
return edge->arcDelayAnnotated(arc, ap_index, ap_count_);
}
void
Graph::setArcDelayAnnotated(Edge *edge,
2026-01-03 16:59:35 -08:00
const TimingArc *arc,
DcalcAPIndex ap_index,
bool annotated)
{
2026-04-15 09:38:10 -07:00
edge->setArcDelayAnnotated(arc, ap_index, ap_count_, annotated);
}
bool
2025-02-10 17:31:45 -07:00
Graph::wireDelayAnnotated(const Edge *edge,
2026-01-03 16:59:35 -08:00
const RiseFall *rf,
DcalcAPIndex ap_index) const
{
2025-02-10 17:31:45 -07:00
int arc_index = TimingArcSet::wireArcIndex(rf);
TimingArc *arc = TimingArcSet::wireTimingArcSet()->findTimingArc(arc_index);
return edge->arcDelayAnnotated(arc, ap_index, ap_count_);
}
void
Graph::setWireDelayAnnotated(Edge *edge,
2026-01-03 16:59:35 -08:00
const RiseFall *rf,
DcalcAPIndex ap_index,
bool annotated)
{
2025-02-10 17:31:45 -07:00
int arc_index = TimingArcSet::wireArcIndex(rf);
TimingArc *arc = TimingArcSet::wireTimingArcSet()->findTimingArc(arc_index);
2026-04-15 09:38:10 -07:00
edge->setArcDelayAnnotated(arc, ap_index, ap_count_, annotated);
2025-02-10 17:31:45 -07:00
}
void
Graph::removeDelayAnnotated(Edge *edge)
{
edge->removeDelayAnnotated();
}
2025-02-10 17:31:45 -07:00
////////////////////////////////////////////////////////////////
2018-09-28 08:54:21 -07:00
void
2026-06-10 10:38:15 -07:00
Graph::delayCountChanged()
2018-09-28 08:54:21 -07:00
{
2026-06-10 10:38:15 -07:00
ap_count_ = dcalcAnalysisPtCount();
// Discard any existing delays.
removePeriodCheckAnnotations();
initSlews();
2018-09-28 08:54:21 -07:00
}
void
2025-02-10 17:31:45 -07:00
Graph::initSlews()
2018-09-28 08:54:21 -07:00
{
2025-02-10 17:31:45 -07:00
VertexIterator vertex_iter(graph_);
2018-09-28 08:54:21 -07:00
while (vertex_iter.hasNext()) {
Vertex *vertex = vertex_iter.next();
2025-02-10 17:31:45 -07:00
initSlews(vertex);
VertexOutEdgeIterator edge_iter(vertex, graph_);
2018-09-28 08:54:21 -07:00
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
2025-02-10 17:31:45 -07:00
initArcDelays(edge);
}
}
}
void
2025-02-10 17:31:45 -07:00
Graph::initSlews(Vertex *vertex)
{
2025-02-10 17:31:45 -07:00
size_t slew_count = slewCount();
2026-03-13 14:06:35 -07:00
if (variables_->pocvEnabled()) {
2026-04-15 09:38:10 -07:00
float *slews = reinterpret_cast<float*>(new Slew[slew_count]{});
2026-03-13 14:06:35 -07:00
vertex->setSlews(slews);
}
else {
float *slews = new float[slew_count]{};
vertex->setSlews(slews);
}
2025-02-10 17:31:45 -07:00
}
size_t
Graph::slewCount()
{
2026-03-13 14:06:35 -07:00
return RiseFall::index_count * ap_count_;
2025-02-10 17:31:45 -07:00
}
void
Graph::initArcDelays(Edge *edge)
{
size_t arc_count = edge->timingArcSet()->arcCount();
size_t delay_count = arc_count * ap_count_;
2026-03-13 14:06:35 -07:00
if (variables_->pocvEnabled()) {
2026-04-15 09:38:10 -07:00
float *delays = reinterpret_cast<float*>(new ArcDelay[delay_count]{});
2026-03-13 14:06:35 -07:00
edge->setArcDelays(delays);
}
else {
float *delays = new float[delay_count]{};
edge->setArcDelays(delays);
}
}
2018-09-28 08:54:21 -07:00
////////////////////////////////////////////////////////////////
void
Graph::minPulseWidthArc(Vertex *vertex,
// high = rise, low = fall
const RiseFall *hi_low,
// Return values.
Edge *&edge,
TimingArc *&arc)
{
VertexOutEdgeIterator edge_iter(vertex, this);
while (edge_iter.hasNext()) {
edge = edge_iter.next();
TimingArcSet *arc_set = edge->timingArcSet();
if (arc_set->role() == TimingRole::width()) {
for (TimingArc *arc1 : arc_set->arcs()) {
if (arc1->fromEdge()->asRiseFall() == hi_low) {
arc = arc1;
return;
}
}
2018-09-28 08:54:21 -07:00
}
}
edge = nullptr;
arc = nullptr;
2018-09-28 08:54:21 -07:00
}
void
Graph::minPeriodArc(Vertex *vertex,
2026-01-03 16:59:35 -08:00
const RiseFall *rf,
// Return values.
Edge *&edge,
TimingArc *&arc)
{
VertexOutEdgeIterator edge_iter(vertex, this);
while (edge_iter.hasNext()) {
edge = edge_iter.next();
TimingArcSet *arc_set = edge->timingArcSet();
if (arc_set->role() == TimingRole::period()) {
for (TimingArc *arc1 : arc_set->arcs()) {
if (arc1->fromEdge()->asRiseFall() == rf) {
arc = arc1;
return;
}
}
}
}
edge = nullptr;
arc = nullptr;
}
2018-09-28 08:54:21 -07:00
////////////////////////////////////////////////////////////////
void
Graph::periodCheckAnnotation(const Pin *pin,
2026-01-03 16:59:35 -08:00
DcalcAPIndex ap_index,
// Return values.
float &period,
bool &exists)
2018-09-28 08:54:21 -07:00
{
exists = false;
2026-03-28 19:13:35 -07:00
float *periods = findKey(period_check_annotations_, pin);
if (periods) {
period = periods[ap_index];
if (period >= 0.0)
exists = true;
2018-09-28 08:54:21 -07:00
}
}
void
Graph::setPeriodCheckAnnotation(const Pin *pin,
2026-01-03 16:59:35 -08:00
DcalcAPIndex ap_index,
float period)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
float *periods = findKey(period_check_annotations_, pin);
2019-03-12 17:25:53 -07:00
if (periods == nullptr) {
2019-07-07 09:58:47 -07:00
periods = new float[ap_count_];
2018-09-28 08:54:21 -07:00
// Use negative (illegal) period values to indicate unannotated checks.
2019-07-07 09:58:47 -07:00
for (int i = 0; i < ap_count_; i++)
2018-09-28 08:54:21 -07:00
periods[i] = -1;
2026-03-28 19:13:35 -07:00
period_check_annotations_[pin] = periods;
2018-09-28 08:54:21 -07:00
}
periods[ap_index] = period;
}
void
Graph::removePeriodCheckAnnotations()
{
2026-03-28 19:13:35 -07:00
for (auto& [pin, periods] : period_check_annotations_)
delete [] periods;
period_check_annotations_.clear();
2018-09-28 08:54:21 -07:00
}
void
Graph::removeDelaySlewAnnotations()
{
VertexIterator vertex_iter(graph_);
while (vertex_iter.hasNext()) {
Vertex *vertex = vertex_iter.next();
VertexOutEdgeIterator edge_iter(vertex, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
removeDelayAnnotated(edge);
2018-09-28 08:54:21 -07:00
}
vertex->removeSlewAnnotated();
}
removePeriodCheckAnnotations();
}
////////////////////////////////////////////////////////////////
//
// Vertex
//
////////////////////////////////////////////////////////////////
Vertex::Vertex()
{
2019-03-12 17:25:53 -07:00
init(nullptr, false, false);
2019-11-11 08:28:42 -07:00
object_idx_ = object_idx_null;
2018-09-28 08:54:21 -07:00
}
void
Vertex::init(Pin *pin,
2026-01-03 16:59:35 -08:00
bool is_bidirect_drvr,
bool is_reg_clk)
2018-09-28 08:54:21 -07:00
{
pin_ = pin;
2019-11-11 08:28:42 -07:00
in_edges_ = edge_id_null;
out_edges_ = edge_id_null;
2025-02-10 17:31:45 -07:00
slews_ = nullptr;
2025-03-26 18:21:03 -07:00
paths_ = nullptr;
2018-09-28 08:54:21 -07:00
tag_group_index_ = tag_group_index_max;
2026-06-26 20:20:09 -07:00
is_bidirect_drvr_ = is_bidirect_drvr;
is_reg_clk_ = is_reg_clk;
2018-09-28 08:54:21 -07:00
has_checks_ = false;
is_check_clk_ = false;
has_downstream_clk_pin_ = false;
2025-04-17 16:53:55 -07:00
visited1_ = false;
visited2_ = false;
2026-01-03 16:59:35 -08:00
has_sim_value_ = false;
2026-06-26 20:20:09 -07:00
level_ = 0;
slew_annotated_ = false;
2026-07-19 10:28:43 -07:00
bfs_in_queue_ = 0;
bfs_predecessor_changed_ = false;
2018-09-28 08:54:21 -07:00
}
2025-02-10 17:31:45 -07:00
Vertex::~Vertex()
{
clear();
}
void
Vertex::clear()
{
delete [] slews_;
slews_ = nullptr;
2025-03-26 18:21:03 -07:00
delete [] paths_;
paths_ = nullptr;
2025-02-10 17:31:45 -07:00
}
2019-11-11 08:28:42 -07:00
void
Vertex::setObjectIdx(ObjectIdx idx)
{
object_idx_ = idx;
}
2026-03-02 12:13:13 -08:00
std::string
2025-03-30 15:27:53 -07:00
Vertex::to_string(const StaState *sta) const
2018-09-28 08:54:21 -07:00
{
2025-07-03 18:43:50 -07:00
const Network *network = sta->sdcNetwork();
2018-09-28 08:54:21 -07:00
if (network->direction(pin_)->isBidirect()) {
2026-03-28 19:13:35 -07:00
std::string str(network->pathName(pin_));
2025-03-30 15:27:53 -07:00
str += ' ';
str += is_bidirect_drvr_ ? "driver" : "load";
return str;
2018-09-28 08:54:21 -07:00
}
else
return network->pathName(pin_);
}
2026-03-28 19:13:35 -07:00
std::string
2025-03-30 15:27:53 -07:00
Vertex::name(const Network *network) const
{
2026-03-28 19:13:35 -07:00
return to_string(network);
2025-03-30 15:27:53 -07:00
}
2019-06-12 21:41:33 -07:00
bool
Vertex::isDriver(const Network *network) const
{
PortDirection *dir = network->direction(pin_);
bool top_level_port = network->isTopLevelPort(pin_);
return ((top_level_port
2026-01-03 16:59:35 -08:00
&& (dir->isInput()
|| (dir->isBidirect()
&& is_bidirect_drvr_)))
|| (!top_level_port
&& (dir->isOutput()
|| dir->isTristate()
|| (dir->isBidirect()
&& is_bidirect_drvr_)
|| dir->isInternal())));
2019-06-12 21:41:33 -07:00
}
bool
Vertex::isLoad(const Network *network) const
{
PortDirection *dir = network->direction(pin_);
bool top_level_port = network->isTopLevelPort(pin_);
return ((top_level_port
&& (dir->isOutput()
|| (dir->isBidirect()
&& !is_bidirect_drvr_)))
|| (!top_level_port
&& (dir->isInput()
|| dir->isTristate()
|| (dir->isBidirect()
&& !is_bidirect_drvr_)
|| dir->isInternal())));
}
2018-09-28 08:54:21 -07:00
void
Vertex::setLevel(Level level)
{
level_ = level;
}
void
2025-04-17 16:53:55 -07:00
Vertex::setVisited(bool visited)
2018-09-28 08:54:21 -07:00
{
2025-04-17 16:53:55 -07:00
visited1_ = visited;
}
void
Vertex::setVisited2(bool visited)
{
visited2_ = visited;
2018-09-28 08:54:21 -07:00
}
2025-02-10 17:31:45 -07:00
void
2026-03-13 14:06:35 -07:00
Vertex::setSlews(float *slews)
2025-02-10 17:31:45 -07:00
{
delete [] slews_;
slews_ = slews;
}
2026-01-03 16:59:35 -08:00
void
Vertex::setHasSimValue(bool has_sim)
{
has_sim_value_ = has_sim;
}
2018-09-28 08:54:21 -07:00
bool
2019-11-11 15:30:19 -07:00
Vertex::slewAnnotated(const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const MinMax *min_max) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
int index = min_max->index() * RiseFall::index_count+ rf->index();
2018-09-28 08:54:21 -07:00
return ((1 << index) & slew_annotated_) != 0;
}
bool
Vertex::slewAnnotated() const
{
return slew_annotated_ != 0;
}
void
Vertex::setSlewAnnotated(bool annotated,
2026-01-03 16:59:35 -08:00
const RiseFall *rf,
DcalcAPIndex ap_index)
2018-09-28 08:54:21 -07:00
{
// Track rise/fall/min/max annotations separately, but after that
// only rise/fall.
if (ap_index > 1)
ap_index = 0;
2026-01-03 16:59:35 -08:00
int index = ap_index * RiseFall::index_count + rf->index();
2018-09-28 08:54:21 -07:00
if (annotated)
slew_annotated_ |= (1 << index);
else
slew_annotated_ &= ~(1 << index);
}
void
Vertex::removeSlewAnnotated()
{
slew_annotated_ = 0;
}
TagGroupIndex
Vertex::tagGroupIndex() const
{
return tag_group_index_;
}
void
Vertex::setTagGroupIndex(TagGroupIndex tag_index)
{
tag_group_index_ = tag_index;
}
2026-01-03 16:59:35 -08:00
Path *
Vertex::makePaths(uint32_t count)
2021-09-16 14:31:35 -07:00
{
2025-03-26 18:21:03 -07:00
delete [] paths_;
2026-01-03 16:59:35 -08:00
Path *paths = new Path[count];
2025-03-26 18:21:03 -07:00
paths_ = paths;
2026-01-03 16:59:35 -08:00
return paths;
2018-09-28 08:54:21 -07:00
}
void
2026-01-03 16:59:35 -08:00
Vertex::setPaths(Path *paths)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
delete [] paths_;
paths_ = paths;
2018-09-28 08:54:21 -07:00
}
void
2026-01-03 16:59:35 -08:00
Vertex::deletePaths()
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
delete [] paths_;
paths_ = nullptr;
tag_group_index_ = tag_group_index_max;
2018-09-28 08:54:21 -07:00
}
bool
Vertex::hasFanin() const
{
return in_edges_ != edge_id_null;
}
bool
Vertex::hasFanout() const
{
return out_edges_ != edge_id_null;
}
2018-09-28 08:54:21 -07:00
void
Vertex::setHasChecks(bool has_checks)
{
has_checks_ = has_checks;
}
void
Vertex::setIsCheckClk(bool is_check_clk)
{
is_check_clk_ = is_check_clk;
}
void
Vertex::setHasDownstreamClkPin(bool has_clk_pin)
{
has_downstream_clk_pin_ = has_clk_pin;
}
bool
Vertex::bfsInQueue(BfsIndex index) const
{
2026-04-15 09:38:10 -07:00
return (bfs_in_queue_ >> static_cast<unsigned>(index)) & 1;
2018-09-28 08:54:21 -07:00
}
void
Vertex::setBfsInQueue(BfsIndex index,
2026-01-03 16:59:35 -08:00
bool value)
2018-09-28 08:54:21 -07:00
{
if (value)
2026-04-15 09:38:10 -07:00
bfs_in_queue_ |= 1 << static_cast<unsigned>(index);
2018-09-28 08:54:21 -07:00
else
2026-04-15 09:38:10 -07:00
bfs_in_queue_ &= ~(1 << static_cast<unsigned>(index));
2018-09-28 08:54:21 -07:00
}
2026-07-12 12:15:14 -07:00
void
Vertex::setBfsPredecessorChanged(bool changed)
{
bfs_predecessor_changed_ = changed;
}
2018-09-28 08:54:21 -07:00
////////////////////////////////////////////////////////////////
//
// Edge
//
////////////////////////////////////////////////////////////////
Edge::Edge()
{
2019-03-12 17:25:53 -07:00
init(0, 0, nullptr);
2019-11-11 08:28:42 -07:00
object_idx_ = object_idx_null;
2018-09-28 08:54:21 -07:00
}
void
2019-11-11 09:38:25 -07:00
Edge::init(VertexId from,
2026-01-03 16:59:35 -08:00
VertexId to,
TimingArcSet *arc_set)
2018-09-28 08:54:21 -07:00
{
2026-06-26 20:20:09 -07:00
arc_set_ = arc_set;
arc_delays_ = nullptr;
arc_delay_annotated_is_bits_ = true;
arc_delay_annotated_.bits_ = 0;
2018-09-28 08:54:21 -07:00
from_ = from;
to_ = to;
2026-06-23 15:09:08 -07:00
vertex_in_next_ = edge_id_null;
2019-11-11 08:28:42 -07:00
vertex_out_next_ = edge_id_null;
vertex_out_prev_ = edge_id_null;
2026-06-26 20:20:09 -07:00
delay_annotation_is_incremental_ = false;
2018-09-28 08:54:21 -07:00
is_bidirect_inst_path_ = false;
is_bidirect_net_path_ = false;
is_bidirect_port_path_ = false;
2018-09-28 08:54:21 -07:00
is_disabled_loop_ = false;
2026-01-03 16:59:35 -08:00
has_sim_sense_ = false;
has_disabled_cond_ = false;
2018-09-28 08:54:21 -07:00
}
2025-02-10 17:31:45 -07:00
Edge::~Edge()
{
clear();
}
void
Edge::clear()
{
delete [] arc_delays_;
arc_delays_ = nullptr;
if (!arc_delay_annotated_is_bits_)
delete arc_delay_annotated_.seq_;
arc_delay_annotated_is_bits_ = true;
arc_delay_annotated_.seq_ = nullptr;
}
2018-09-28 08:54:21 -07:00
void
2019-11-11 08:28:42 -07:00
Edge::setObjectIdx(ObjectIdx idx)
{
object_idx_ = idx;
}
2026-03-02 12:13:13 -08:00
std::string
2025-03-30 15:27:53 -07:00
Edge::to_string(const StaState *sta) const
{
const Graph *graph = sta->graph();
2026-03-02 12:13:13 -08:00
std::string str = from(graph)->to_string(sta);
2025-03-30 15:27:53 -07:00
str += " -> ";
str += to(graph)->to_string(sta);
2026-02-27 16:57:08 -08:00
str += " ";
str += role()->to_string();
FuncExpr *when = arc_set_->cond();
if (when) {
str += " ";
str += when->to_string();
}
2025-03-30 15:27:53 -07:00
return str;
}
2019-11-11 08:28:42 -07:00
void
2018-09-28 08:54:21 -07:00
Edge::setTimingArcSet(TimingArcSet *set)
{
arc_set_ = set;
}
void
2026-03-13 14:06:35 -07:00
Edge::setArcDelays(float *delays)
2018-09-28 08:54:21 -07:00
{
2025-02-10 17:31:45 -07:00
delete [] arc_delays_;
2026-03-13 14:06:35 -07:00
arc_delays_ = delays;
2018-09-28 08:54:21 -07:00
}
bool
2025-02-10 17:31:45 -07:00
Edge::arcDelayAnnotated(const TimingArc *arc,
DcalcAPIndex ap_index,
DcalcAPIndex ap_count) const
2018-09-28 08:54:21 -07:00
{
2025-02-10 17:31:45 -07:00
size_t index = arc->index() * ap_count + ap_index;
if (arc_delay_annotated_is_bits_)
return arc_delay_annotated_.bits_ & arcDelayAnnotateBit(index);
2025-02-10 17:31:45 -07:00
else
return (*arc_delay_annotated_.seq_)[index];
}
void
Edge::setArcDelayAnnotated(const TimingArc *arc,
DcalcAPIndex ap_index,
DcalcAPIndex ap_count,
bool annotated)
{
size_t index = arc->index() * ap_count + ap_index;
if (index > sizeof(uintptr_t) * 8
2025-02-10 17:31:45 -07:00
&& arc_delay_annotated_is_bits_) {
arc_delay_annotated_is_bits_ = false;
2025-04-11 16:59:48 -07:00
size_t bit_count = ap_count * RiseFall::index_count * 2;
arc_delay_annotated_.seq_ = new std::vector<bool>(bit_count);
2025-02-10 17:31:45 -07:00
}
if (arc_delay_annotated_is_bits_) {
if (annotated)
arc_delay_annotated_.bits_ |= arcDelayAnnotateBit(index);
2025-02-10 17:31:45 -07:00
else
arc_delay_annotated_.bits_ &= ~arcDelayAnnotateBit(index);
2025-02-10 17:31:45 -07:00
}
else
(*arc_delay_annotated_.seq_)[index] = annotated;
}
void
Edge::removeDelayAnnotated()
{
delay_annotation_is_incremental_ = false;
if (arc_delay_annotated_is_bits_)
arc_delay_annotated_.bits_ = 0;
else {
delete arc_delay_annotated_.seq_;
arc_delay_annotated_.seq_ = nullptr;
}
2018-09-28 08:54:21 -07:00
}
void
Edge::setDelayAnnotationIsIncremental(bool is_incr)
{
delay_annotation_is_incremental_ = is_incr;
}
uintptr_t
Edge::arcDelayAnnotateBit(size_t index)
{
return static_cast<uintptr_t>(1) << index;
}
2025-03-30 15:27:53 -07:00
const TimingRole *
2018-09-28 08:54:21 -07:00
Edge::role() const
{
return arc_set_->role();
}
bool
Edge::isWire() const
{
return arc_set_->role()->isWire();
}
2026-01-03 16:59:35 -08:00
2018-09-28 08:54:21 -07:00
TimingSense
Edge::sense() const
{
return arc_set_->sense();
}
void
2026-01-03 16:59:35 -08:00
Edge::setIsDisabledLoop(bool disabled)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
is_disabled_loop_ = disabled;
2018-09-28 08:54:21 -07:00
}
void
2026-01-03 16:59:35 -08:00
Edge::setIsBidirectInstPath(bool is_bidir)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
is_bidirect_inst_path_ = is_bidir;
2018-09-28 08:54:21 -07:00
}
void
2026-01-03 16:59:35 -08:00
Edge::setIsBidirectNetPath(bool is_bidir)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
is_bidirect_net_path_ = is_bidir;
2018-09-28 08:54:21 -07:00
}
void
Edge::setIsBidirectPortPath(bool is_bidir)
{
is_bidirect_port_path_ = is_bidir;
}
2018-09-28 08:54:21 -07:00
void
2026-01-03 16:59:35 -08:00
Edge::setHasSimSense(bool has_sense)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
has_sim_sense_ = has_sense;
2018-09-28 08:54:21 -07:00
}
void
2026-01-03 16:59:35 -08:00
Edge::setHasDisabledCond(bool has_disabled)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
has_disabled_cond_ = has_disabled;
2018-09-28 08:54:21 -07:00
}
////////////////////////////////////////////////////////////////
VertexIterator::VertexIterator(Graph *graph) :
graph_(graph),
network_(graph->network()),
top_inst_(network_->topInstance()),
2026-04-15 09:38:10 -07:00
inst_iter_(network_->leafInstanceIterator())
2018-09-28 08:54:21 -07:00
{
if (inst_iter_)
findNext();
}
Vertex *
VertexIterator::next()
{
2019-03-12 17:25:53 -07:00
Vertex *next = nullptr;
2018-09-28 08:54:21 -07:00
if (vertex_) {
next = vertex_;
2019-03-12 17:25:53 -07:00
vertex_ = nullptr;
2018-09-28 08:54:21 -07:00
}
else if (bidir_vertex_) {
next = bidir_vertex_;
2019-03-12 17:25:53 -07:00
bidir_vertex_ = nullptr;
2018-09-28 08:54:21 -07:00
}
2019-03-12 17:25:53 -07:00
if (bidir_vertex_ == nullptr)
2018-09-28 08:54:21 -07:00
findNext();
return next;
}
bool
VertexIterator::findNextPin()
{
while (pin_iter_->hasNext()) {
Pin *pin = pin_iter_->next();
2019-11-11 09:38:25 -07:00
vertex_ = graph_->vertex(network_->vertexId(pin));
2018-09-28 08:54:21 -07:00
bidir_vertex_ = network_->direction(pin)->isBidirect()
2026-01-03 16:59:35 -08:00
? findKey(graph_->pin_bidirect_drvr_vertex_map_, pin)
2019-03-12 17:25:53 -07:00
: nullptr;
2018-09-28 08:54:21 -07:00
if (vertex_ || bidir_vertex_)
return true;
}
delete pin_iter_;
2019-03-12 17:25:53 -07:00
pin_iter_ = nullptr;
2018-09-28 08:54:21 -07:00
return false;
}
void
VertexIterator::findNext()
{
while (inst_iter_) {
if (pin_iter_
&& findNextPin())
return;
if (inst_iter_->hasNext()) {
Instance *inst = inst_iter_->next();
pin_iter_ = network_->pinIterator(inst);
} else {
delete inst_iter_;
2019-03-12 17:25:53 -07:00
inst_iter_ = nullptr;
2018-09-28 08:54:21 -07:00
if (top_inst_) {
pin_iter_ = network_->pinIterator(top_inst_);
2019-03-12 17:25:53 -07:00
top_inst_ = nullptr;
2018-09-28 08:54:21 -07:00
}
}
}
if (pin_iter_)
findNextPin();
}
2026-06-23 15:09:08 -07:00
////////////////////////////////////////////////////////////////
2018-09-28 08:54:21 -07:00
VertexInEdgeIterator::VertexInEdgeIterator(Vertex *vertex,
2026-01-03 16:59:35 -08:00
const Graph *graph) :
2018-09-28 08:54:21 -07:00
next_(graph->edge(vertex->in_edges_)),
graph_(graph)
{
}
2019-11-11 09:38:25 -07:00
VertexInEdgeIterator::VertexInEdgeIterator(VertexId vertex_id,
2026-01-03 16:59:35 -08:00
const Graph *graph) :
2019-11-11 09:38:25 -07:00
next_(graph->edge(graph->vertex(vertex_id)->in_edges_)),
2018-09-28 08:54:21 -07:00
graph_(graph)
{
}
Edge *
VertexInEdgeIterator::next()
{
Edge *next = next_;
if (next_)
2026-06-23 15:09:08 -07:00
next_ = graph_->edge(next_->vertex_in_next_);
2018-09-28 08:54:21 -07:00
return next;
}
VertexOutEdgeIterator::VertexOutEdgeIterator(Vertex *vertex,
2026-01-03 16:59:35 -08:00
const Graph *graph) :
2018-09-28 08:54:21 -07:00
next_(graph->edge(vertex->out_edges_)),
graph_(graph)
{
}
Edge *
VertexOutEdgeIterator::next()
{
Edge *next = next_;
if (next_)
next_ = graph_->edge(next_->vertex_out_next_);
return next;
}
////////////////////////////////////////////////////////////////
class FindEdgesThruHierPinVisitor : public HierPinThruVisitor
{
public:
FindEdgesThruHierPinVisitor(EdgeSet &edges,
2026-01-03 16:59:35 -08:00
Graph *graph);
2026-03-09 17:43:03 -07:00
void visit(const Pin *drvr,
const Pin *load) override;
2018-09-28 08:54:21 -07:00
protected:
EdgeSet &edges_;
Graph *graph_;
};
FindEdgesThruHierPinVisitor::FindEdgesThruHierPinVisitor(EdgeSet &edges,
2026-01-03 16:59:35 -08:00
Graph *graph) :
2018-09-28 08:54:21 -07:00
HierPinThruVisitor(),
edges_(edges),
graph_(graph)
{
}
void
2023-01-19 11:23:45 -07:00
FindEdgesThruHierPinVisitor::visit(const Pin *drvr,
2026-01-03 16:59:35 -08:00
const Pin *load)
2018-09-28 08:54:21 -07:00
{
Vertex *drvr_vertex = graph_->pinDrvrVertex(drvr);
Vertex *load_vertex = graph_->pinLoadVertex(load);
// Iterate over load drivers to avoid driver fanout^2.
VertexInEdgeIterator edge_iter(load_vertex, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
if (edge->from(graph_) == drvr_vertex)
edges_.insert(edge);
}
}
EdgesThruHierPinIterator::EdgesThruHierPinIterator(const Pin *hpin,
2026-01-03 16:59:35 -08:00
Network *network,
Graph *graph)
2018-09-28 08:54:21 -07:00
{
FindEdgesThruHierPinVisitor visitor(edges_, graph);
visitDrvrLoadsThruHierPin(hpin, network, &visitor);
2026-01-03 16:59:35 -08:00
edge_iter_ = edges_.begin();
}
bool
EdgesThruHierPinIterator::hasNext()
{
return edge_iter_ != edges_.end();
}
Edge *
EdgesThruHierPinIterator::next()
{
return *edge_iter_++;
2018-09-28 08:54:21 -07:00
}
2022-03-01 06:55:25 -07:00
////////////////////////////////////////////////////////////////
VertexIdLess::VertexIdLess(Graph *&graph) :
graph_(graph)
{
}
bool
VertexIdLess::operator()(const Vertex *vertex1,
const Vertex *vertex2) const
{
return graph_->id(vertex1) < graph_->id(vertex2);
}
2026-04-13 14:58:16 -07:00
} // namespace sta