2018-09-28 17:54:21 +02:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2025-01-22 02:54:33 +01:00
|
|
|
// Copyright (c) 2025, Parallax Software, Inc.
|
2018-09-28 17:54:21 +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
|
2018-09-28 17:54:21 +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.
|
2018-09-28 17:54:21 +02:00
|
|
|
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "PathExpanded.hh"
|
2020-04-05 20:35:51 +02:00
|
|
|
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "TimingRole.hh"
|
|
|
|
|
#include "PortDirection.hh"
|
|
|
|
|
#include "Network.hh"
|
|
|
|
|
#include "Clock.hh"
|
|
|
|
|
#include "Search.hh"
|
2025-03-27 02:21:03 +01:00
|
|
|
#include "Path.hh"
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "Latches.hh"
|
|
|
|
|
#include "Genclks.hh"
|
2018-09-28 17:54:21 +02:00
|
|
|
|
|
|
|
|
namespace sta {
|
|
|
|
|
|
2019-01-01 21:25:25 +01:00
|
|
|
PathExpanded::PathExpanded(const StaState *sta) :
|
|
|
|
|
sta_(sta)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
PathExpanded::PathExpanded(const Path *path,
|
|
|
|
|
// Expand generated clk source paths.
|
|
|
|
|
bool expand_genclks,
|
|
|
|
|
const StaState *sta) :
|
|
|
|
|
sta_(sta)
|
|
|
|
|
{
|
|
|
|
|
expand(path, expand_genclks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PathExpanded::PathExpanded(const Path *path,
|
|
|
|
|
const StaState *sta) :
|
|
|
|
|
sta_(sta)
|
|
|
|
|
{
|
|
|
|
|
expand(path, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PathExpanded::expand(const Path *path,
|
|
|
|
|
bool expand_genclks)
|
|
|
|
|
{
|
|
|
|
|
const Latches *latches = sta_->latches();
|
2025-03-27 02:21:03 +01:00
|
|
|
// Push the paths from the end into an array of Paths.
|
|
|
|
|
const Path *p = path;
|
|
|
|
|
const Path *last_path = nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
size_t i = 0;
|
|
|
|
|
bool found_start = false;
|
2025-03-27 02:21:03 +01:00
|
|
|
while (p) {
|
|
|
|
|
const Path *prev_path = p->prevPath();
|
2018-09-28 17:54:21 +02:00
|
|
|
if (!found_start) {
|
2025-07-02 17:32:04 +02:00
|
|
|
if (prev_path) {
|
|
|
|
|
const TimingArc *prev_arc = p->prevArc(sta_);
|
2025-03-27 02:21:03 +01:00
|
|
|
const TimingRole *prev_role = prev_arc->role();
|
2018-09-28 17:54:21 +02:00
|
|
|
if (prev_role == TimingRole::regClkToQ()
|
|
|
|
|
|| prev_role == TimingRole::latchEnToQ()) {
|
|
|
|
|
start_index_ = i;
|
|
|
|
|
found_start = true;
|
|
|
|
|
}
|
|
|
|
|
else if (prev_role == TimingRole::latchDtoQ()) {
|
2025-03-27 02:21:03 +01:00
|
|
|
const Edge *prev_edge = p->prevEdge(sta_);
|
2022-01-15 20:51:05 +01:00
|
|
|
if (prev_edge && latches->isLatchDtoQ(prev_edge)) {
|
2018-09-28 17:54:21 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
paths_.push_back(p);
|
2025-03-27 02:21:03 +01:00
|
|
|
last_path = p;
|
|
|
|
|
p = prev_path;
|
2018-09-28 17:54:21 +02:00
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
if (!found_start)
|
|
|
|
|
start_index_ = i - 1;
|
|
|
|
|
|
|
|
|
|
if (expand_genclks)
|
2025-03-27 02:21:03 +01:00
|
|
|
expandGenclk(last_path);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2025-03-27 02:21:03 +01:00
|
|
|
PathExpanded::expandGenclk(const Path *clk_path)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2025-03-27 02:21:03 +01:00
|
|
|
if (clk_path) {
|
2023-01-19 19:23:45 +01:00
|
|
|
const Clock *src_clk = clk_path->clock(sta_);
|
2018-09-28 17:54:21 +02:00
|
|
|
if (src_clk && src_clk->isGenerated()) {
|
2025-03-27 02:21:03 +01:00
|
|
|
const Path *src_path = sta_->search()->genclks()->srcPath(clk_path);
|
|
|
|
|
if (src_path) {
|
2018-09-28 17:54:21 +02:00
|
|
|
// The head of the genclk src path is already in paths_,
|
|
|
|
|
// so skip past it.
|
2025-03-27 02:21:03 +01:00
|
|
|
Path *prev_path = src_path->prevPath();
|
|
|
|
|
Path *p = prev_path;
|
|
|
|
|
Path *last_path = nullptr;
|
|
|
|
|
while (p) {
|
|
|
|
|
prev_path = p->prevPath();
|
2018-09-28 17:54:21 +02:00
|
|
|
paths_.push_back(p);
|
2025-03-27 02:21:03 +01:00
|
|
|
last_path = p;
|
|
|
|
|
p = prev_path;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
2025-03-27 02:21:03 +01:00
|
|
|
expandGenclk(last_path);
|
2018-09-28 17:54:21 +02: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-27 02:21:03 +01:00
|
|
|
const Path *
|
2024-09-17 02:04:31 +02:00
|
|
|
PathExpanded::path(size_t index) const
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
if (index < paths_.size())
|
2025-03-27 02:21:03 +01:00
|
|
|
return paths_[pathsIndex(index)];
|
2018-09-28 17:54:21 +02:00
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
2025-03-27 02:21:03 +01:00
|
|
|
const Path *
|
2025-02-01 23:53:28 +01:00
|
|
|
PathExpanded::startPath() const
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2025-03-27 02:21:03 +01:00
|
|
|
return paths_[start_index_];
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
2025-03-27 02:21:03 +01:00
|
|
|
const Path *
|
2025-02-01 23:53:28 +01:00
|
|
|
PathExpanded::endPath() const
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2025-03-27 02:21:03 +01:00
|
|
|
return paths_[0];
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
2025-03-27 02:21:03 +01:00
|
|
|
const TimingArc *
|
2025-02-01 23:53:28 +01:00
|
|
|
PathExpanded::startPrevArc() const
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2025-03-27 02:21:03 +01:00
|
|
|
return paths_[start_index_]->prevArc(sta_);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
2025-03-27 02:21:03 +01:00
|
|
|
const Path *
|
2025-02-01 23:53:28 +01:00
|
|
|
PathExpanded::startPrevPath() const
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
size_t start1 = start_index_ + 1;
|
|
|
|
|
if (start1 < paths_.size())
|
2025-03-27 02:21:03 +01:00
|
|
|
return paths_[start1];
|
2018-09-28 17:54:21 +02:00
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
2025-03-27 02:21:03 +01:00
|
|
|
const Path *
|
|
|
|
|
PathExpanded::clkPath() const
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
const Latches *latches = sta_->latches();
|
2025-03-27 02:21:03 +01:00
|
|
|
const Path *start = startPath();
|
2025-02-01 23:53:28 +01:00
|
|
|
const TimingArc *prev_arc = startPrevArc();
|
2022-01-15 20:51:05 +01:00
|
|
|
if (start && prev_arc) {
|
2025-03-31 00:27:53 +02:00
|
|
|
const TimingRole *role = prev_arc->role();
|
2018-09-28 17:54:21 +02:00
|
|
|
if (role == TimingRole::latchDtoQ()) {
|
2025-03-27 02:21:03 +01:00
|
|
|
Edge *prev_edge = start->prevEdge(sta_);
|
2022-01-15 20:51:05 +01:00
|
|
|
if (prev_edge && latches->isLatchDtoQ(prev_edge)) {
|
2025-03-27 02:21:03 +01:00
|
|
|
return latches->latchEnablePath(start, prev_edge);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (role == TimingRole::regClkToQ()
|
2022-01-15 20:51:05 +01:00
|
|
|
|| role == TimingRole::latchEnToQ()) {
|
2025-03-27 02:21:03 +01:00
|
|
|
const Path *start_prev = startPrevPath();
|
2022-01-15 20:51:05 +01:00
|
|
|
if (start_prev)
|
2025-03-27 02:21:03 +01:00
|
|
|
return start_prev;
|
2022-01-15 20:51:05 +01:00
|
|
|
}
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
2022-01-15 20:51:05 +01:00
|
|
|
else if (start && start->isClock(sta_))
|
2025-03-27 02:21:03 +01:00
|
|
|
return start;
|
|
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PathExpanded::latchPaths(// Return values.
|
2025-03-27 02:21:03 +01:00
|
|
|
const Path *&d_path,
|
|
|
|
|
const Path *&q_path,
|
2025-02-01 23:53:28 +01:00
|
|
|
Edge *&d_q_edge) const
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2019-03-13 01:25:53 +01:00
|
|
|
d_path = nullptr;
|
|
|
|
|
q_path = nullptr;
|
|
|
|
|
d_q_edge = nullptr;
|
2025-03-27 02:21:03 +01:00
|
|
|
const Path *start = startPath();
|
2025-02-01 23:53:28 +01:00
|
|
|
const TimingArc *prev_arc = startPrevArc();
|
2022-01-15 20:51:05 +01:00
|
|
|
if (start
|
|
|
|
|
&& prev_arc
|
2018-09-28 17:54:21 +02:00
|
|
|
&& prev_arc->role() == TimingRole::latchDtoQ()) {
|
2025-03-27 02:21:03 +01:00
|
|
|
Edge *prev_edge = start->prevEdge(sta_);
|
2018-09-28 17:54:21 +02:00
|
|
|
// This breaks latch loop paths.
|
2022-01-15 20:51:05 +01:00
|
|
|
if (prev_edge
|
|
|
|
|
&& sta_->latches()->isLatchDtoQ(prev_edge)) {
|
2018-09-28 17:54:21 +02:00
|
|
|
d_path = startPrevPath();
|
|
|
|
|
q_path = start;
|
|
|
|
|
d_q_edge = prev_edge;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|