Files
OpenSTA/include/sta/GraphDelayCalc.hh
T

360 lines
14 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-02-15 17:13:16 -07:00
#pragma once
2018-09-28 08:54:21 -07:00
2026-01-03 16:59:35 -08:00
#include <array>
#include <map>
2024-01-31 17:14:07 -07:00
#include <mutex>
2026-04-15 09:38:10 -07:00
#include <vector>
2023-11-19 10:04:45 -07:00
2026-04-15 09:38:10 -07:00
#include "ArcDelayCalc.hh"
2020-04-05 14:53:44 -07:00
#include "GraphClass.hh"
2026-04-15 09:38:10 -07:00
#include "NetworkClass.hh"
2026-01-03 16:59:35 -08:00
#include "SdcClass.hh"
2026-04-15 09:38:10 -07:00
#include "SearchClass.hh"
2020-04-05 14:53:44 -07:00
#include "StaState.hh"
2018-09-28 08:54:21 -07:00
namespace sta {
class DelayCalcObserver;
2023-11-11 12:33:55 -07:00
class MultiDrvrNet;
class FindVertexDelays;
2023-11-19 10:04:45 -07:00
class NetCaps;
2026-01-03 16:59:35 -08:00
class SearchPred;
2018-09-28 08:54:21 -07:00
2026-01-03 16:59:35 -08:00
using MultiDrvrNetMap = std::map<const Vertex*, MultiDrvrNet*>;
using DrvrLoadSlews = std::vector<SlewSeq>;
2023-11-11 12:33:55 -07:00
// This class traverses the graph calling the arc delay calculator and
// annotating delays on graph edges.
2018-09-28 08:54:21 -07:00
class GraphDelayCalc : public StaState
{
public:
2023-11-11 12:33:55 -07:00
GraphDelayCalc(StaState *sta);
2026-04-13 14:58:16 -07:00
~GraphDelayCalc() override;
void copyState(const StaState *sta) override;
2023-11-11 12:33:55 -07:00
// Set the observer for edge delay changes.
virtual void setObserver(DelayCalcObserver *observer);
2018-09-28 08:54:21 -07:00
// Invalidate all delays/slews.
2023-11-11 12:33:55 -07:00
virtual void delaysInvalid();
virtual void levelsChangedBefore();
2018-09-28 08:54:21 -07:00
// Invalidate vertex and downstream delays/slews.
2023-11-11 12:33:55 -07:00
virtual void delayInvalid(Vertex *vertex);
virtual void delayInvalid(const Pin *pin);
virtual void deleteVertexBefore(Vertex *vertex);
virtual void levelChangedBefore(Vertex *vertex);
2018-09-28 08:54:21 -07:00
// Reset to virgin state.
2023-11-11 12:33:55 -07:00
virtual void clear();
// Find arc delays and vertex slews thru level.
virtual void findDelays(Level level);
// Find and annotate drvr_vertex gate and load delays/slews.
virtual void findDelays(Vertex *drvr_vertex);
2018-09-28 08:54:21 -07:00
// Returned string is owned by the caller.
2025-05-22 09:25:56 -07:00
virtual std::string reportDelayCalc(const Edge *edge,
const TimingArc *arc,
2026-01-03 16:59:35 -08:00
const Scene *scene,
2025-05-22 09:25:56 -07:00
const MinMax *min_max,
int digits);
2018-09-28 08:54:21 -07:00
// Percentage (0.0:1.0) change in delay that causes downstream
// delays to be recomputed during incremental delay calculation.
virtual float incrementalDelayTolerance();
2023-11-11 12:33:55 -07:00
virtual void setIncrementalDelayTolerance(float tol);
2024-02-08 13:54:52 -07:00
float loadCap(const Pin *drvr_pin,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max) const;
2023-11-19 10:04:45 -07:00
float loadCap(const Pin *drvr_pin,
2024-02-08 13:54:52 -07:00
const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max) const;
2024-02-08 13:54:52 -07:00
void loadCap(const Pin *drvr_pin,
const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
2024-02-08 13:54:52 -07:00
// Return values.
float &pin_cap,
float &wire_cap) const;
void netCaps(const Pin *drvr_pin,
const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
2024-02-08 13:54:52 -07:00
// Return values.
float &pin_cap,
float &wire_cap,
float &fanout,
2026-04-15 09:38:10 -07:00
bool &has_net_load) const;
2024-02-27 10:00:48 -07:00
void parasiticLoad(const Pin *drvr_pin,
const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
2024-02-27 10:00:48 -07:00
const MultiDrvrNet *multi_drvr,
ArcDelayCalc *arc_delay_calc,
// Return values.
float &cap,
const Parasitic *&parasitic) const;
LoadPinIndexMap makeLoadPinIndexMap(Vertex *drvr_vertex);
void findDriverArcDelays(Vertex *drvr_vertex,
Edge *edge,
const TimingArc *arc,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
ArcDelayCalc *arc_delay_calc);
2018-09-28 08:54:21 -07:00
// Precedence:
// SDF annotation
// Liberty port timing group timing_type minimum_period.
// Liberty port min_period attribute.
2018-09-28 08:54:21 -07:00
void minPeriod(const Pin *pin,
2026-01-03 16:59:35 -08:00
const Scene *scene,
2018-09-28 08:54:21 -07:00
// Return values.
float &min_period,
bool &exists);
2023-11-11 12:33:55 -07:00
2023-11-19 10:04:45 -07:00
Slew edgeFromSlew(const Vertex *from_vertex,
const RiseFall *from_rf,
const Edge *edge,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max);
2024-06-27 13:57:58 -07:00
Slew edgeFromSlew(const Vertex *from_vertex,
const RiseFall *from_rf,
const TimingRole *role,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max);
2025-04-09 16:35:15 -07:00
bool bidirectDrvrSlewFromLoad(const Pin *pin) const;
2023-11-19 10:04:45 -07:00
2023-11-11 12:33:55 -07:00
protected:
void seedInvalidDelays();
void initSlew(Vertex *vertex);
void seedRootSlew(Vertex *vertex,
ArcDelayCalc *arc_delay_calc);
void seedRootSlews();
void seedDrvrSlew(Vertex *vertex,
ArcDelayCalc *arc_delay_calc);
void seedNoDrvrSlew(Vertex *drvr_vertex,
const Pin *drvr_pin,
const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
2023-11-11 12:33:55 -07:00
ArcDelayCalc *arc_delay_calc);
void seedNoDrvrCellSlew(Vertex *drvr_vertex,
const Pin *drvr_pin,
const RiseFall *rf,
2025-02-01 14:53:28 -08:00
const InputDrive *drive,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
2023-11-11 12:33:55 -07:00
ArcDelayCalc *arc_delay_calc);
void seedLoadSlew(Vertex *vertex);
void setInputPortWireDelays(Vertex *vertex);
void findInputDriverDelay(const LibertyCell *drvr_cell,
const Pin *drvr_pin,
Vertex *drvr_vertex,
const RiseFall *rf,
const LibertyPort *from_port,
2026-04-15 09:38:10 -07:00
const DriveCellSlews *from_slews,
2023-11-11 12:33:55 -07:00
const LibertyPort *to_port,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
ArcDelayCalc *arc_delay_calc);
2023-11-11 12:33:55 -07:00
LibertyPort *driveCellDefaultFromPort(const LibertyCell *cell,
const LibertyPort *to_port);
int findPortIndex(const LibertyCell *cell,
const LibertyPort *port);
2023-11-19 10:04:45 -07:00
void findInputArcDelay(const Pin *drvr_pin,
2023-11-11 12:33:55 -07:00
Vertex *drvr_vertex,
const TimingArc *arc,
float from_slew,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
ArcDelayCalc *arc_delay_calc);
void findDriverDelays(Vertex *drvr_vertex,
ArcDelayCalc *arc_delay_calc,
LoadPinIndexMap &load_pin_index_map);
2024-01-31 17:14:07 -07:00
MultiDrvrNet *multiDrvrNet(const Vertex *drvr_vertex) const;
2026-04-15 09:38:10 -07:00
MultiDrvrNet *findMultiDrvrNet(Vertex *drvr_vertex);
2024-01-31 17:14:07 -07:00
MultiDrvrNet *makeMultiDrvrNet(Vertex *drvr_vertex);
bool hasMultiDrvrs(Vertex *drvr_vertex);
Vertex *firstLoad(Vertex *drvr_vertex);
2023-11-11 12:33:55 -07:00
bool findDriverDelays1(Vertex *drvr_vertex,
MultiDrvrNet *multi_drvr,
ArcDelayCalc *arc_delay_calc,
LoadPinIndexMap &load_pin_index_map);
2023-11-12 18:39:02 -07:00
void initLoadSlews(Vertex *drvr_vertex);
bool findDriverEdgeDelays(Vertex *drvr_vertex,
const MultiDrvrNet *multi_drvr,
Edge *edge,
ArcDelayCalc *arc_delay_calc,
LoadPinIndexMap &load_pin_index_map,
// Return value.
2025-04-11 16:59:48 -07:00
std::array<bool, RiseFall::index_count> &delay_exists);
bool findDriverArcDelays(Vertex *drvr_vertex,
const MultiDrvrNet *multi_drvr,
Edge *edge,
const TimingArc *arc,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
ArcDelayCalc *arc_delay_calc,
LoadPinIndexMap &load_pin_index_map);
ArcDcalcArgSeq makeArcDcalcArgs(Vertex *drvr_vertex,
const MultiDrvrNet *multi_drvr,
Edge *edge,
const TimingArc *arc,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
ArcDelayCalc *arc_delay_calc);
void findParallelEdge(Vertex *vertex,
const TimingArc *drvr_arc,
// Return values.
Edge *&edge,
const TimingArc *&arc);
2023-11-12 18:39:02 -07:00
void initWireDelays(Vertex *drvr_vertex);
2023-11-11 12:33:55 -07:00
void initRootSlews(Vertex *vertex);
2024-07-19 19:55:52 -07:00
void zeroSlewAndWireDelays(Vertex *drvr_vertex,
const RiseFall *rf);
2023-11-11 12:33:55 -07:00
void findVertexDelay(Vertex *vertex,
2026-07-12 10:00:34 -07:00
ArcDelayCalc *arc_delay_calc);
DrvrLoadSlews loadSlews(LoadPinIndexMap &load_pin_index_map);
2026-07-12 12:15:14 -07:00
void enqueueCheckEdges(Vertex *vertex);
bool loadSlewChanged(Vertex *load_vertex,
DrvrLoadSlews &load_slews_prev,
LoadPinIndexMap &load_pin_index_map);
bool annotateDelaysSlews(Edge *edge,
const TimingArc *arc,
ArcDcalcResult &dcalc_result,
LoadPinIndexMap &load_pin_index_map,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max);
bool annotateDelaySlew(Edge *edge,
const TimingArc *arc,
2026-03-13 14:06:35 -07:00
const ArcDelay &gate_delay,
const Slew &gate_slew,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max);
2026-07-12 12:15:14 -07:00
void annotateLoadDelays(Vertex *drvr_vertex,
const RiseFall *drvr_rf,
ArcDcalcResult &dcalc_result,
LoadPinIndexMap &load_pin_index_map,
const ArcDelay &extra_delay,
bool merge,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max);
2023-11-11 12:33:55 -07:00
void findLatchEdgeDelays(Edge *edge);
void findCheckEdgeDelays(Edge *edge,
ArcDelayCalc *arc_delay_calc);
void deleteMultiDrvrNets();
Slew checkEdgeClkSlew(const Vertex *from_vertex,
const RiseFall *from_rf,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max);
2024-02-08 13:54:52 -07:00
float loadCap(const Pin *drvr_pin,
const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
2024-02-08 13:54:52 -07:00
ArcDelayCalc *arc_delay_calc) const;
void parasiticLoad(const Pin *drvr_pin,
const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
2024-02-08 13:54:52 -07:00
const MultiDrvrNet *multi_drvr,
ArcDelayCalc *arc_delay_calc,
// Return values.
float &pin_cap,
float &wire_cap,
const Parasitic *&parasitic) const;
void netCaps(const Pin *drvr_pin,
const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
2024-02-08 13:54:52 -07:00
const MultiDrvrNet *multi_drvr,
// Return values.
float &pin_cap,
float &wire_cap,
float &fanout,
bool &has_net_load) const;
2023-11-11 12:33:55 -07:00
// Observer for edge delay changes.
2026-04-15 09:38:10 -07:00
DelayCalcObserver *observer_{nullptr};
bool delays_seeded_{false};
bool delays_exist_{false};
2023-11-11 12:33:55 -07:00
// Vertices with invalid -to delays.
2026-01-03 16:59:35 -08:00
VertexSet invalid_delays_;
2023-11-11 12:33:55 -07:00
// Timing check edges with invalid delays.
EdgeSet invalid_check_edges_;
// Latch D->Q edges with invalid delays.
EdgeSet invalid_latch_edges_;
// shared by invalid_check_edges_ and invalid_latch_edges_
std::mutex invalid_edge_lock_;
SearchPred *search_pred_;
SearchPred *search_non_latch_pred_;
BfsFwdIterator *iter_;
MultiDrvrNetMap multi_drvr_net_map_;
2024-01-31 17:14:07 -07:00
std::mutex multi_drvr_lock_;
2023-11-11 12:33:55 -07:00
// Percentage (0.0:1.0) change in delay that causes downstream
// delays to be recomputed during incremental delay calculation.
2026-04-15 09:38:10 -07:00
float incremental_delay_tolerance_{0.0};
2023-11-11 12:33:55 -07:00
friend class FindVertexDelays;
friend class MultiDrvrNet;
2018-09-28 08:54:21 -07:00
};
// Abstract base class for edge delay change observer.
class DelayCalcObserver
{
public:
2026-04-13 14:58:16 -07:00
virtual ~DelayCalcObserver() = default;
2018-09-28 08:54:21 -07:00
virtual void delayChangedFrom(Vertex *vertex) = 0;
virtual void delayChangedTo(Vertex *vertex) = 0;
virtual void checkDelayChangedTo(Vertex *vertex) = 0;
};
2023-11-19 10:04:45 -07:00
// Nets with multiple drivers (tristate, bidirect or output).
// Cache net caps to prevent N^2 net pin walk.
class MultiDrvrNet
{
public:
2024-01-31 17:14:07 -07:00
VertexSeq &drvrs() { return drvrs_; }
const VertexSeq &drvrs() const { return drvrs_; }
2023-11-19 10:04:45 -07:00
bool parallelGates(const Network *network) const;
Vertex *dcalcDrvr() const { return dcalc_drvr_; }
void setDcalcDrvr(Vertex *drvr);
void netCaps(const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const Scene *scene,
const MinMax *min_max,
2023-11-19 10:04:45 -07:00
// Return values.
float &pin_cap,
float &wire_cap,
float &fanout,
bool &has_net_load) const;
2026-01-03 16:59:35 -08:00
void findCaps(const StaState *sta);
2023-11-19 10:04:45 -07:00
private:
// Driver that triggers delay calculation for all the drivers on the net.
2026-04-15 09:38:10 -07:00
Vertex *dcalc_drvr_{nullptr};
2024-01-31 17:14:07 -07:00
VertexSeq drvrs_;
2023-11-19 10:04:45 -07:00
// [drvr_rf->index][dcalc_ap->index]
2025-04-11 16:59:48 -07:00
std::vector<NetCaps> net_caps_;
2023-11-19 10:04:45 -07:00
};
2026-04-13 14:58:16 -07:00
} // namespace sta