Files
OpenSTA/search/SearchPred.cc
T

328 lines
8.4 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 "SearchPred.hh"
2020-04-05 11:35:51 -07:00
2026-04-13 14:58:16 -07:00
#include "Graph.hh"
#include "Latches.hh"
#include "Levelize.hh"
2020-04-05 14:53:44 -07:00
#include "Liberty.hh"
2026-04-13 14:58:16 -07:00
#include "Mode.hh"
2020-04-05 14:53:44 -07:00
#include "Network.hh"
#include "Sdc.hh"
#include "Search.hh"
2026-01-03 16:59:35 -08:00
#include "Sim.hh"
2026-04-13 14:58:16 -07:00
#include "TimingArc.hh"
#include "TimingRole.hh"
2025-04-09 16:35:15 -07:00
#include "Variables.hh"
2018-09-28 08:54:21 -07:00
namespace sta {
static bool
2026-01-03 16:59:35 -08:00
searchThruSimEdge(const Vertex *vertex,
const RiseFall *rf,
const Mode *mode);
2018-09-28 08:54:21 -07:00
static bool
2026-01-03 16:59:35 -08:00
searchThruTimingSense(const Edge *edge,
const RiseFall *from_rf,
const RiseFall *to_rf,
const Mode *mode);
2018-09-28 08:54:21 -07:00
2026-01-03 16:59:35 -08:00
SearchPred::SearchPred(const StaState *sta) :
2018-09-28 08:54:21 -07:00
sta_(sta)
{
}
2026-01-03 16:59:35 -08:00
void
SearchPred::copyState(const StaState *sta)
{
sta_ = sta;
}
2018-09-28 08:54:21 -07:00
bool
2026-01-03 16:59:35 -08:00
SearchPred::searchFrom(const Vertex *from_vertex) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
for (const Mode *mode : sta_->modes()) {
if (searchFrom(from_vertex, mode))
return true;
}
return false;
2018-09-28 08:54:21 -07:00
}
bool
2026-01-03 16:59:35 -08:00
SearchPred::searchThru(Edge *edge) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
for (const Mode *mode : sta_->modes()) {
if (searchThru(edge, mode))
return true;
}
return false;
2018-09-28 08:54:21 -07:00
}
bool
2026-01-03 16:59:35 -08:00
SearchPred::searchTo(const Vertex *to_vertex) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
for (const Mode *mode : sta_->modes()) {
if (searchTo(to_vertex, mode))
return true;
}
return false;
2018-09-28 08:54:21 -07:00
}
////////////////////////////////////////////////////////////////
2026-01-03 16:59:35 -08:00
SearchPred0::SearchPred0(const StaState *sta) :
SearchPred(sta)
2018-09-28 08:54:21 -07:00
{
}
bool
2026-01-03 16:59:35 -08:00
SearchPred0::searchFrom(const Vertex *from_vertex,
const Mode *mode) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
const Pin *from_pin = from_vertex->pin();
const Sdc *sdc = mode->sdc();
const Sim *sim = mode->sim();
return !(sdc->isDisabledConstraint(from_pin)
|| sim->isConstant(from_vertex));
2018-09-28 08:54:21 -07:00
}
2026-01-03 16:59:35 -08:00
bool
SearchPred0::searchThru(Edge *edge,
const Mode *mode) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
const TimingRole *role = edge->role();
const Variables *variables = sta_->variables();
const Sdc *sdc = mode->sdc();
const Sim *sim = mode->sim();
2026-01-15 16:14:42 -07:00
return !(role->isTimingCheck()
|| sdc->isDisabledConstraint(edge)
2026-01-03 16:59:35 -08:00
// Constants disable edge cond expression.
|| sim->isDisabledCond(edge)
|| sdc->isDisabledCondDefault(edge)
// Register/latch preset/clr edges are disabled by default.
|| (role == TimingRole::regSetClr()
&& !variables->presetClrArcsEnabled())
// Constants on other pins disable this edge (ie, a mux select).
|| sim->simTimingSense(edge) == TimingSense::none
|| (edge->isBidirectInstPath()
&& !variables->bidirectInstPathsEnabled())
|| (role == TimingRole::latchDtoQ()
&& sta_->latches()->latchDtoQState(edge, mode)
== LatchEnableState::closed));
2018-09-28 08:54:21 -07:00
}
bool
2026-01-03 16:59:35 -08:00
SearchPred0::searchTo(const Vertex *to_vertex,
2026-02-17 11:03:05 -07:00
const Mode *mode) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
return !mode->sim()->isConstant(to_vertex);
2018-09-28 08:54:21 -07:00
}
////////////////////////////////////////////////////////////////
2026-01-03 16:59:35 -08:00
SearchPred1::SearchPred1(const StaState *sta) :
SearchPred0(sta)
2018-09-28 08:54:21 -07:00
{
}
bool
2026-01-03 16:59:35 -08:00
SearchPred1::searchThru(Edge *edge,
const Mode *mode) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
return SearchPred0::searchThru(edge, mode)
&& !edge->isDisabledLoop();
2018-09-28 08:54:21 -07:00
}
////////////////////////////////////////////////////////////////
2026-01-03 16:59:35 -08:00
ClkTreeSearchPred::ClkTreeSearchPred(const StaState *sta) :
SearchPred(sta)
2018-09-28 08:54:21 -07:00
{
}
bool
2026-01-03 16:59:35 -08:00
ClkTreeSearchPred::searchFrom(const Vertex *from_vertex,
const Mode *mode) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
const Pin *from_pin = from_vertex->pin();
const Sdc *sdc = mode->sdc();
return !sdc->isDisabledConstraint(from_pin);
2018-09-28 08:54:21 -07:00
}
2026-01-03 16:59:35 -08:00
bool
ClkTreeSearchPred::searchThru(Edge *edge,
const Mode *mode) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
const TimingRole *role = edge->role();
const Sdc *sdc = mode->sdc();
return searchThruAllow(role)
&& !((role == TimingRole::tristateEnable()
&& !sta_->variables()->clkThruTristateEnabled())
|| role == TimingRole::regSetClr()
|| sdc->isDisabledConstraint(edge)
|| sdc->isDisabledCondDefault(edge)
|| edge->isBidirectInstPath()
|| edge->isBidirectPortPath()
2026-01-03 16:59:35 -08:00
|| edge->isDisabledLoop());
2018-09-28 08:54:21 -07:00
}
bool
2026-01-03 16:59:35 -08:00
ClkTreeSearchPred::searchThruAllow(const TimingRole *role) const
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
return role->isWire()
|| role == TimingRole::combinational();
2018-09-28 08:54:21 -07:00
}
bool
isClkEnd(Vertex *vertex,
2026-01-03 16:59:35 -08:00
const Mode *mode)
2018-09-28 08:54:21 -07:00
{
2026-04-13 14:58:16 -07:00
Graph *graph = mode->sta()->graph();
2018-09-28 08:54:21 -07:00
ClkTreeSearchPred pred(graph);
VertexOutEdgeIterator edge_iter(vertex, graph);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
2026-01-03 16:59:35 -08:00
if (pred.searchThru(edge, mode))
2018-09-28 08:54:21 -07:00
return false;
}
return true;
}
2026-01-03 16:59:35 -08:00
bool
ClkTreeSearchPred::searchTo(const Vertex *,
const Mode *) const
{
return true;
}
2018-09-28 08:54:21 -07:00
////////////////////////////////////////////////////////////////
bool
searchThru(const Edge *edge,
2026-01-03 16:59:35 -08:00
const TimingArc *arc,
const Mode *mode)
2018-09-28 08:54:21 -07:00
{
2026-04-13 14:58:16 -07:00
const Graph *graph = mode->sta()->graph();
2025-03-30 15:27:53 -07:00
const RiseFall *from_rf = arc->fromEdge()->asRiseFall();
const RiseFall *to_rf = arc->toEdge()->asRiseFall();
2018-09-28 08:54:21 -07:00
// Ignore transitions other than rise/fall.
2019-11-11 15:30:19 -07:00
return from_rf && to_rf
2026-01-03 16:59:35 -08:00
&& searchThru(edge->from(graph), from_rf, edge, edge->to(graph), to_rf, mode);
2018-09-28 08:54:21 -07:00
}
bool
searchThru(Vertex *from_vertex,
2026-01-03 16:59:35 -08:00
const RiseFall *from_rf,
const Edge *edge,
Vertex *to_vertex,
const RiseFall *to_rf,
const Mode *mode)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
return searchThruTimingSense(edge, from_rf, to_rf, mode)
&& searchThruSimEdge(from_vertex, from_rf, mode)
&& searchThruSimEdge(to_vertex, to_rf, mode);
2018-09-28 08:54:21 -07:00
}
// set_case_analysis rising/falling filters rise/fall edges during search.
static bool
2019-11-11 15:30:19 -07:00
searchThruSimEdge(const Vertex *vertex,
2026-01-03 16:59:35 -08:00
const RiseFall *rf,
const Mode *mode)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
LogicValue sim_value = mode->sim()->simValue(vertex->pin());
2018-09-28 08:54:21 -07:00
switch (sim_value) {
2019-03-12 17:25:53 -07:00
case LogicValue::rise:
2019-11-11 15:30:19 -07:00
return rf == RiseFall::rise();
2019-03-12 17:25:53 -07:00
case LogicValue::fall:
2019-11-11 15:30:19 -07:00
return rf == RiseFall::fall();
2018-09-28 08:54:21 -07:00
default:
return true;
};
}
static bool
2026-01-03 16:59:35 -08:00
searchThruTimingSense(const Edge *edge,
const RiseFall *from_rf,
const RiseFall *to_rf,
const Mode *mode)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
switch (mode->sim()->simTimingSense(edge)) {
2019-03-12 17:25:53 -07:00
case TimingSense::unknown:
2018-09-28 08:54:21 -07:00
return true;
2019-03-12 17:25:53 -07:00
case TimingSense::positive_unate:
2019-11-11 15:30:19 -07:00
return from_rf == to_rf;
2019-03-12 17:25:53 -07:00
case TimingSense::negative_unate:
2019-11-11 15:30:19 -07:00
return from_rf != to_rf;
2019-03-12 17:25:53 -07:00
case TimingSense::non_unate:
2018-09-28 08:54:21 -07:00
return true;
2019-03-12 17:25:53 -07:00
case TimingSense::none:
2018-09-28 08:54:21 -07:00
return false;
default:
return true;
}
}
////////////////////////////////////////////////////////////////
bool
hasFanin(Vertex *vertex,
2026-01-03 16:59:35 -08:00
SearchPred *pred,
const Graph *graph,
const Mode *mode)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
if (pred->searchTo(vertex, mode)) {
2018-09-28 08:54:21 -07:00
VertexInEdgeIterator edge_iter(vertex, graph);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
Vertex *from_vertex = edge->from(graph);
2026-01-03 16:59:35 -08:00
if (pred->searchFrom(from_vertex, mode)
&& pred->searchThru(edge, mode))
return true;
2018-09-28 08:54:21 -07:00
}
}
return false;
}
bool
hasFanout(Vertex *vertex,
2026-01-03 16:59:35 -08:00
SearchPred *pred,
const Graph *graph,
const Mode *mode)
2018-09-28 08:54:21 -07:00
{
2026-01-03 16:59:35 -08:00
if (pred->searchFrom(vertex, mode)) {
2018-09-28 08:54:21 -07:00
VertexOutEdgeIterator edge_iter(vertex, graph);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
Vertex *to_vertex = edge->to(graph);
2026-01-03 16:59:35 -08:00
if (pred->searchTo(to_vertex, mode)
&& pred->searchThru(edge, mode))
return true;
2018-09-28 08:54:21 -07:00
}
}
return false;
}
2026-04-13 14:58:16 -07:00
} // namespace sta