Skip to content

Commit 801ffb5

Browse files
committed
expose levelizeobserver
Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
1 parent 8cbd400 commit 801ffb5

4 files changed

Lines changed: 71 additions & 22 deletions

File tree

include/sta/LevelizeObserver.hh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// OpenSTA, Static Timing Analyzer
2+
// Copyright (c) 2026, Parallax Software, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
//
17+
// The origin of this software must not be misrepresented; you must not
18+
// claim that you wrote the original software.
19+
//
20+
// Altered source versions must be plainly marked as such, and must not be
21+
// misrepresented as being the original software.
22+
//
23+
// This notice may not be removed or altered from any source distribution.
24+
25+
#pragma once
26+
27+
namespace sta {
28+
29+
class Vertex;
30+
class Search;
31+
class GraphDelayCalc;
32+
33+
// Observer fired by Levelize during (re)levelization. Downstream consumers
34+
// override the two hooks to invalidate caches that depend on vertex levels.
35+
class LevelizeObserver
36+
{
37+
public:
38+
virtual ~LevelizeObserver() = default;
39+
virtual void levelsChangedBefore() = 0;
40+
virtual void levelChangedBefore(Vertex *vertex) = 0;
41+
};
42+
43+
// Default observer installed by Sta::makeObservers. Forwards level-change
44+
// events to Search and GraphDelayCalc so their internal caches stay
45+
// consistent. Subclass and override to extend (call the base methods first,
46+
// then add your own invalidation).
47+
class StaLevelizeObserver : public LevelizeObserver
48+
{
49+
public:
50+
StaLevelizeObserver(Search *search, GraphDelayCalc *graph_delay_calc);
51+
void levelsChangedBefore() override;
52+
void levelChangedBefore(Vertex *vertex) override;
53+
54+
private:
55+
Search *search_;
56+
GraphDelayCalc *graph_delay_calc_;
57+
};
58+
59+
} // namespace sta

include/sta/Sta.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class ClkSkews;
7373
class ReportField;
7474
class EquivCells;
7575
class StaSimObserver;
76+
class LevelizeObserver;
7677
class GraphLoop;
7778

7879
using ModeNameMap = std::map<std::string, Mode*, std::less<>>;
@@ -1321,6 +1322,10 @@ public:
13211322
// Ensure a network has been read, linked and liberty libraries exist.
13221323
Network *ensureLibLinked();
13231324
void ensureLevelized();
1325+
// Replace the Levelize observer. Takes ownership; deletes any prior
1326+
// observer. Subclass StaLevelizeObserver to extend the default behavior
1327+
// (Search + GraphDelayCalc forwarding) without re-implementing it.
1328+
void setLevelizeObserver(LevelizeObserver *observer);
13241329
// Ensure that the timing graph has been built.
13251330
Graph *ensureGraph();
13261331
void ensureClkArrivals();

search/Levelize.hh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
#include "Graph.hh"
3232
#include "StaState.hh"
33+
#include "sta/LevelizeObserver.hh"
3334

3435
namespace sta {
3536

3637
class SearchPred;
37-
class LevelizeObserver;
3838
class GraphLoop;
3939

4040
using VertexEdgeIterPair = std::pair<Vertex*,VertexOutEdgeIterator*>;
@@ -133,12 +133,4 @@ private:
133133
EdgeSeq *edges_;
134134
};
135135

136-
class LevelizeObserver
137-
{
138-
public:
139-
virtual ~LevelizeObserver() = default;
140-
virtual void levelsChangedBefore() = 0;
141-
virtual void levelChangedBefore(Vertex *vertex) = 0;
142-
};
143-
144136
} // namespace sta

search/Sta.cc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,6 @@ StaSimObserver::fanoutEdgesChangeAfter(const Pin *pin)
217217

218218
////////////////////////////////////////////////////////////////
219219

220-
class StaLevelizeObserver : public LevelizeObserver
221-
{
222-
public:
223-
StaLevelizeObserver(Search *search,
224-
GraphDelayCalc *graph_delay_calc);
225-
void levelsChangedBefore() override;
226-
void levelChangedBefore(Vertex *vertex) override;
227-
228-
private:
229-
Search *search_;
230-
GraphDelayCalc *graph_delay_calc_;
231-
};
232-
233220
StaLevelizeObserver::StaLevelizeObserver(Search *search,
234221
GraphDelayCalc *graph_delay_calc) :
235222
search_(search),
@@ -3746,6 +3733,12 @@ Sta::ensureLevelized()
37463733
levelize_->ensureLevelized();
37473734
}
37483735

3736+
void
3737+
Sta::setLevelizeObserver(LevelizeObserver *observer)
3738+
{
3739+
levelize_->setObserver(observer);
3740+
}
3741+
37493742
void
37503743
Sta::updateGeneratedClks()
37513744
{

0 commit comments

Comments
 (0)