4343#include " DbWrapper.h"
4444#include " TritonCTSKernel.h"
4545#include " HTreeBuilder.h"
46+ #include " db_sta/dbSta.hh"
4647
4748// DB includes
4849#include " db.h"
@@ -66,6 +67,8 @@ void DbWrapper::populateTritonCTS() {
6667}
6768
6869void DbWrapper::initDB () {
70+ ord::OpenRoad* openRoad = ord::OpenRoad::openRoad ();
71+ _openSta = openRoad->getSta ();
6972 _db = odb::dbDatabase::getDatabase (_options->getDbId ());
7073 _chip = _db->getChip ();
7174 _block = _chip->getBlock ();
@@ -74,32 +77,50 @@ void DbWrapper::initDB() {
7477
7578void DbWrapper::initAllClocks () {
7679 std::cout << " Initializing clock nets\n " ;
77-
78- std::vector<std::string> clockNetNames;
79- parseClockNames (clockNetNames);
80+
81+ clearNumClocks ();
8082
8183 std::cout << " Looking for clock nets in the design\n " ;
82- for (const std::string& name: clockNetNames) {
83- odb::dbNet* net = _block->findNet (name.c_str ());
84- if (!net) {
85- odb::dbITerm* iterm = _block->findITerm (name.c_str ());
86- net = iterm->getNet ();
84+
85+ // Uses dbSta to find all clock nets in the design.
86+
87+ std::set<odb::dbNet*> clockNets;
88+
89+ _openSta->findClkNets (clockNets);
90+
91+ // Checks the user input in case there are other nets that need to be added to the set.
92+ std::vector<odb::dbNet*> inputClkNets = _options->getClockNetsObjs ();
93+
94+ for (odb::dbNet* net : inputClkNets) {
95+ // Since a set is unique, only the nets not found by dbSta are added.
96+ clockNets.insert (net);
97+ }
98+
99+ // Iterate over all the nets found by the user-input and dbSta
100+ for (odb::dbNet* net : clockNets){
101+ if (net != nullptr ) {
102+ std::cout << " Net \" " << net->getName () << " \" found\n " ;
103+ // Initializes the net in TritonCTS. If the number of sinks is less than 2, the net is discarded.
104+ initClock (net);
105+ } else {
106+ std::cout << " [WARNING] A net was not found in the design. Skipping...\n " ;
87107 }
88- if (!net) {
89- std::cout << " [WARNING] Net \" " << name << " \" not in design. Skipping...\n " ;
90- continue ;
91- }
92-
93- std::cout << " Net \" " << name << " \" found\n " ;
94- initClock (net);
95108 }
109+
110+ if (getNumClocks () <= 0 ) {
111+ std::cout << " \n " ;
112+ std::cout << " [ERROR] No clock nets have been found.\n " ;
113+ std::exit (1 );
114+ }
115+
116+ std::cout << " TritonCTS found " << getNumClocks () << " clock nets." << std::endl;
96117}
97118
98119void DbWrapper::initClock (odb::dbNet* net) {
99120 std::string driver = " " ;
100121 odb::dbITerm* iterm = net->getFirstOutput ();
101122 int xPin, yPin;
102- if (! iterm) {
123+ if (iterm == nullptr ) {
103124 odb::dbBTerm* bterm = net->get1stBTerm (); // Clock pin
104125 driver = bterm->getConstName ();
105126 bterm->getFirstPinLocation (xPin, yPin);
@@ -114,18 +135,15 @@ void DbWrapper::initClock(odb::dbNet* net) {
114135 }
115136
116137 // Initialize clock net
117- std::cout << net->getConstName () << std::endl;
138+ std::cout << " Initializing clock net for : \" " << net ->getConstName () << " \" " << std::endl;
118139
119140 Clock clockNet (net->getConstName (),
120141 driver,
121142 xPin, yPin);
122143
123- odb::dbSet<odb::dbITerm> iterms = net->getITerms ();
124- odb::dbSet<odb::dbITerm>::iterator itr;
125- for (itr = iterms.begin (); itr != iterms.end (); ++itr) {
126- odb::dbITerm* iterm = *itr;
127-
128- if (iterm->getIoType () != odb::dbIoType::INPUT) {
144+ for (odb::dbITerm* iterm : net->getITerms ()) {
145+
146+ if (!(iterm->isInputSignal ())) {
129147 continue ;
130148 }
131149
@@ -145,6 +163,10 @@ void DbWrapper::initClock(odb::dbNet* net) {
145163
146164 }
147165
166+ std::cout << " Clock net \" " << net->getConstName () << " \" has " << clockNet.getNumSinks () << " sinks" << std::endl;
167+
168+ incrementNumClocks ();
169+
148170 _kernel->addBuilder (new HTreeBuilder (*_options, clockNet));
149171}
150172
@@ -157,19 +179,14 @@ void DbWrapper::parseClockNames(std::vector<std::string>& clockNetNames) const {
157179 }
158180
159181 unsigned numClocks = clockNetNames.size ();
160- std::cout << " Number of user-input clocks: " << numClocks;
182+ std::cout << " Number of user-input clocks: " << numClocks << " . \n " ;
161183
162184 if (numClocks > 0 ) {
163185 std::cout << " (" ;
164186 for (const std::string& name: clockNetNames) {
165187 std::cout << " \" " << name << " \" " ;
166188 }
167189 std::cout << " )\n " ;
168- } else {
169- std::cout << " \n " ;
170- std::cout << " [ERROR] No clock nets have been found.\n " ;
171- std::exit (1 );
172-
173190 }
174191}
175192
@@ -189,9 +206,10 @@ void DbWrapper::computeITermPosition(odb::dbITerm* term, DBU &x, DBU &y) const {
189206 ++numShapes;
190207 }
191208 }
192-
193- x /= numShapes;
194- y /= numShapes;
209+ if (numShapes > 0 ){
210+ x /= numShapes;
211+ y /= numShapes;
212+ }
195213};
196214
197215void DbWrapper::writeClockNetsToDb (const Clock& clockNet) {
0 commit comments