Files
OpenSTA/search/PathExpanded.cc
T

240 lines
6.0 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 "PathExpanded.hh"
2020-04-05 11:35:51 -07:00
2020-04-05 14:53:44 -07:00
#include "Clock.hh"
#include "Genclks.hh"
2026-04-13 14:58:16 -07:00
#include "Latches.hh"
2026-01-03 16:59:35 -08:00
#include "Mode.hh"
2026-04-13 14:58:16 -07:00
#include "Network.hh"
#include "Path.hh"
#include "PortDirection.hh"
#include "Search.hh"
#include "TimingRole.hh"
2018-09-28 08:54:21 -07:00
namespace sta {
2019-01-01 12:25:25 -08:00
PathExpanded::PathExpanded(const StaState *sta) :
sta_(sta)
{
}
2018-09-28 08:54:21 -07:00
PathExpanded::PathExpanded(const Path *path,
2026-01-03 16:59:35 -08:00
// Expand generated clk source paths.
bool expand_genclks,
const StaState *sta) :
2018-09-28 08:54:21 -07:00
sta_(sta)
{
expand(path, expand_genclks);
}
PathExpanded::PathExpanded(const Path *path,
2026-01-03 16:59:35 -08:00
const StaState *sta) :
2018-09-28 08:54:21 -07:00
sta_(sta)
{
expand(path, false);
}
void
PathExpanded::expand(const Path *path,
2026-01-03 16:59:35 -08:00
bool expand_genclks)
2018-09-28 08:54:21 -07:00
{
const Latches *latches = sta_->latches();
2026-01-03 16:59:35 -08:00
const Mode *mode = path->mode(sta_);
2025-03-26 18:21:03 -07:00
// Push the paths from the end into an array of Paths.
const Path *p = path;
const Path *last_path = nullptr;
2018-09-28 08:54:21 -07:00
size_t i = 0;
bool found_start = false;
2025-03-26 18:21:03 -07:00
while (p) {
const Path *prev_path = p->prevPath();
2018-09-28 08:54:21 -07:00
if (!found_start) {
2025-07-02 08:32:04 -07:00
if (prev_path) {
const TimingArc *prev_arc = p->prevArc(sta_);
2026-01-03 16:59:35 -08:00
const TimingRole *prev_role = prev_arc->role();
if (prev_role == TimingRole::regClkToQ()
|| prev_role == TimingRole::latchEnToQ()) {
start_index_ = i;
found_start = true;
}
else if (prev_role->isLatchDtoQ()) {
const Edge *prev_edge = p->prevEdge(sta_);
if (prev_edge && latches->isLatchDtoQ(prev_edge, mode)) {
start_index_ = i;
found_start = true;
paths_.push_back(p);
// Push latch D path.
paths_.push_back(prev_path);
// This breaks latch loop paths.
break;
}
}
2018-09-28 08:54:21 -07:00
}
}
paths_.push_back(p);
2025-03-26 18:21:03 -07:00
last_path = p;
p = prev_path;
2018-09-28 08:54:21 -07:00
i++;
}
if (!found_start)
start_index_ = i - 1;
if (expand_genclks)
2025-03-26 18:21:03 -07:00
expandGenclk(last_path);
2018-09-28 08:54:21 -07:00
}
void
2025-03-26 18:21:03 -07:00
PathExpanded::expandGenclk(const Path *clk_path)
2018-09-28 08:54:21 -07:00
{
2025-03-26 18:21:03 -07:00
if (clk_path) {
2023-01-19 11:23:45 -07:00
const Clock *src_clk = clk_path->clock(sta_);
2018-09-28 08:54:21 -07:00
if (src_clk && src_clk->isGenerated()) {
2026-01-03 16:59:35 -08:00
const Mode *mode = clk_path->mode(sta_);
const Path *src_path = mode->genclks()->srcPath(clk_path);
2025-03-26 18:21:03 -07:00
if (src_path) {
2026-01-03 16:59:35 -08:00
// The head of the genclk src path is already in paths_,
// so skip past it.
Path *prev_path = src_path->prevPath();
Path *p = prev_path;
Path *last_path = nullptr;
while (p) {
prev_path = p->prevPath();
paths_.push_back(p);
last_path = p;
p = prev_path;
}
expandGenclk(last_path);
2018-09-28 08:54:21 -07:00
}
}
}
}
// Convert external index that starts at the path root
// and increases to an index for paths_ (reversed).
size_t
PathExpanded::pathsIndex(size_t index) const
{
return paths_.size() - index - 1;
}
size_t
PathExpanded::startIndex() const
{
return pathsIndex(start_index_);
}
2025-03-26 18:21:03 -07:00
const Path *
2024-09-16 17:04:31 -07:00
PathExpanded::path(size_t index) const
2018-09-28 08:54:21 -07:00
{
if (index < paths_.size())
2025-03-26 18:21:03 -07:00
return paths_[pathsIndex(index)];
2018-09-28 08:54:21 -07:00
else
2019-03-12 17:25:53 -07:00
return nullptr;
2018-09-28 08:54:21 -07:00
}
2025-03-26 18:21:03 -07:00
const Path *
2025-02-01 14:53:28 -08:00
PathExpanded::startPath() const
2018-09-28 08:54:21 -07:00
{
2025-03-26 18:21:03 -07:00
return paths_[start_index_];
2018-09-28 08:54:21 -07:00
}
2025-03-26 18:21:03 -07:00
const Path *
2025-02-01 14:53:28 -08:00
PathExpanded::endPath() const
2018-09-28 08:54:21 -07:00
{
2025-03-26 18:21:03 -07:00
return paths_[0];
2018-09-28 08:54:21 -07:00
}
2025-03-26 18:21:03 -07:00
const TimingArc *
2025-02-01 14:53:28 -08:00
PathExpanded::startPrevArc() const
2018-09-28 08:54:21 -07:00
{
2025-03-26 18:21:03 -07:00
return paths_[start_index_]->prevArc(sta_);
2018-09-28 08:54:21 -07:00
}
2025-03-26 18:21:03 -07:00
const Path *
2025-02-01 14:53:28 -08:00
PathExpanded::startPrevPath() const
2018-09-28 08:54:21 -07:00
{
size_t start1 = start_index_ + 1;
if (start1 < paths_.size())
2025-03-26 18:21:03 -07:00
return paths_[start1];
2018-09-28 08:54:21 -07:00
else
2019-03-12 17:25:53 -07:00
return nullptr;
2018-09-28 08:54:21 -07:00
}
2025-03-26 18:21:03 -07:00
const Path *
PathExpanded::clkPath() const
2018-09-28 08:54:21 -07:00
{
const Latches *latches = sta_->latches();
2025-03-26 18:21:03 -07:00
const Path *start = startPath();
2025-02-01 14:53:28 -08:00
const TimingArc *prev_arc = startPrevArc();
2022-01-15 12:51:05 -07:00
if (start && prev_arc) {
2025-03-30 15:27:53 -07:00
const TimingRole *role = prev_arc->role();
2026-01-03 16:59:35 -08:00
if (role->isLatchDtoQ()) {
2025-03-26 18:21:03 -07:00
Edge *prev_edge = start->prevEdge(sta_);
2026-01-03 16:59:35 -08:00
const Mode *mode = start->mode(sta_);
if (prev_edge && latches->isLatchDtoQ(prev_edge, mode)) {
return latches->latchEnablePath(start, prev_edge);
2018-09-28 08:54:21 -07:00
}
}
else if (role == TimingRole::regClkToQ()
2026-01-03 16:59:35 -08:00
|| role == TimingRole::latchEnToQ()) {
2025-03-26 18:21:03 -07:00
const Path *start_prev = startPrevPath();
2022-01-15 12:51:05 -07:00
if (start_prev)
2025-03-26 18:21:03 -07:00
return start_prev;
2022-01-15 12:51:05 -07:00
}
2018-09-28 08:54:21 -07:00
}
2022-01-15 12:51:05 -07:00
else if (start && start->isClock(sta_))
2025-03-26 18:21:03 -07:00
return start;
return nullptr;
2018-09-28 08:54:21 -07:00
}
void
PathExpanded::latchPaths(// Return values.
2026-01-03 16:59:35 -08:00
const Path *&d_path,
const Path *&q_path,
Edge *&d_q_edge) const
2018-09-28 08:54:21 -07:00
{
2019-03-12 17:25:53 -07:00
d_path = nullptr;
q_path = nullptr;
d_q_edge = nullptr;
2025-03-26 18:21:03 -07:00
const Path *start = startPath();
2025-02-01 14:53:28 -08:00
const TimingArc *prev_arc = startPrevArc();
2022-01-15 12:51:05 -07:00
if (start
&& prev_arc
2018-09-28 08:54:21 -07:00
&& prev_arc->role() == TimingRole::latchDtoQ()) {
2025-03-26 18:21:03 -07:00
Edge *prev_edge = start->prevEdge(sta_);
2026-01-03 16:59:35 -08:00
const Mode *mode = start->mode(sta_);
2018-09-28 08:54:21 -07:00
// This breaks latch loop paths.
2022-01-15 12:51:05 -07:00
if (prev_edge
2026-01-03 16:59:35 -08:00
&& sta_->latches()->isLatchDtoQ(prev_edge, mode)) {
2018-09-28 08:54:21 -07:00
d_path = startPrevPath();
q_path = start;
d_q_edge = prev_edge;
}
}
}
2026-04-13 14:58:16 -07:00
} // namespace sta