@@ -660,7 +660,10 @@ void TritonCTS::setBufferList(const char* buffers)
660660 std::vector<std::string> bufferList (begin, end);
661661 // If the vector is empty, then the buffers are inferred
662662 if (bufferList.empty ()) {
663- inferBufferList (bufferList);
663+ const char * lib_name
664+ = options_->isCtsLibrarySet () ? options_->getCtsLibrary () : nullptr ;
665+ resizer_->inferClockBufferList (lib_name, bufferList);
666+ options_->setBufferListInferred (true );
664667 } else {
665668 // Iterate the user-defined buffer list
666669 sta::Vector<sta::LibertyCell*> selected_buffers;
@@ -684,169 +687,6 @@ void TritonCTS::setBufferList(const char* buffers)
684687 options_->setBufferList (bufferList);
685688}
686689
687- void TritonCTS::inferBufferList (std::vector<std::string>& buffers)
688- {
689- sta::Vector<sta::LibertyCell*> selected_buffers;
690-
691- // first, look for buffers with "is_clock_cell: true" cell attribute
692- sta::LibertyLibraryIterator* lib_iter = network_->libertyLibraryIterator ();
693- while (lib_iter->hasNext ()) {
694- sta::LibertyLibrary* lib = lib_iter->next ();
695- if (options_->isCtsLibrarySet ()
696- && strcmp (lib->name (), options_->getCtsLibrary ()) != 0 ) {
697- continue ;
698- }
699- for (sta::LibertyCell* buffer : *lib->buffers ()) {
700- if (buffer->isClockCell () && isClockCellCandidate (buffer)) {
701- // "is_clock_cell: true"
702- selected_buffers.emplace_back (buffer);
703- debugPrint (logger_,
704- CTS,
705- " buffering" ,
706- 1 ,
707- " {} has clock cell attribute" ,
708- buffer->name ());
709- }
710- }
711- }
712- delete lib_iter;
713-
714- // second, look for buffers with an input port that has
715- // LEF USE as "CLOCK"
716- if (selected_buffers.empty ()) {
717- sta::LibertyLibraryIterator* lib_iter = network_->libertyLibraryIterator ();
718- while (lib_iter->hasNext ()) {
719- sta::LibertyLibrary* lib = lib_iter->next ();
720- if (options_->isCtsLibrarySet ()
721- && strcmp (lib->name (), options_->getCtsLibrary ()) != 0 ) {
722- continue ;
723- }
724- for (sta::LibertyCell* buffer : *lib->buffers ()) {
725- odb::dbMaster* master = db_->findMaster (buffer->name ());
726- for (odb::dbMTerm* mterm : master->getMTerms ()) {
727- if (mterm->getIoType () == odb::dbIoType::INPUT
728- && mterm->getSigType () == odb::dbSigType::CLOCK
729- && isClockCellCandidate (buffer)) {
730- // input port with LEF USE as "CLOCK"
731- selected_buffers.emplace_back (buffer);
732- debugPrint (logger_,
733- CTS,
734- " buffering" ,
735- 1 ,
736- " {} has input port {} with LEF USE as CLOCK" ,
737- buffer->name (),
738- mterm->getName ());
739- }
740- }
741- }
742- }
743- delete lib_iter;
744- }
745-
746- // third, look for all buffers with name CLKBUF or clkbuf
747- if (selected_buffers.empty ()) {
748- sta::PatternMatch patternClkBuf (" .*CLKBUF.*" ,
749- /* is_regexp */ true ,
750- /* nocase */ true ,
751- /* Tcl_interp* */ nullptr );
752- sta::LibertyLibraryIterator* lib_iter = network_->libertyLibraryIterator ();
753- while (lib_iter->hasNext ()) {
754- sta::LibertyLibrary* lib = lib_iter->next ();
755- if (options_->isCtsLibrarySet ()
756- && strcmp (lib->name (), options_->getCtsLibrary ()) != 0 ) {
757- continue ;
758- }
759- for (sta::LibertyCell* buffer :
760- lib->findLibertyCellsMatching (&patternClkBuf)) {
761- if (buffer->isBuffer () && isClockCellCandidate (buffer)) {
762- debugPrint (logger_,
763- CTS,
764- " buffering" ,
765- 1 ,
766- " {} found by 'CLKBUF' pattern match" ,
767- buffer->name ());
768- selected_buffers.emplace_back (buffer);
769- }
770- }
771- }
772- delete lib_iter;
773- }
774-
775- // fourth, look for all buffers with name BUF or buf
776- if (selected_buffers.empty ()) {
777- sta::PatternMatch patternBuf (" .*BUF.*" ,
778- /* is_regexp */ true ,
779- /* nocase */ true ,
780- /* Tcl_interp* */ nullptr );
781- lib_iter = network_->libertyLibraryIterator ();
782- while (lib_iter->hasNext ()) {
783- sta::LibertyLibrary* lib = lib_iter->next ();
784- if (options_->isCtsLibrarySet ()
785- && strcmp (lib->name (), options_->getCtsLibrary ()) != 0 ) {
786- continue ;
787- }
788- for (sta::LibertyCell* buffer :
789- lib->findLibertyCellsMatching (&patternBuf)) {
790- if (buffer->isBuffer () && isClockCellCandidate (buffer)) {
791- debugPrint (logger_,
792- CTS,
793- " buffering" ,
794- 1 ,
795- " {} found by 'BUF' pattern match" ,
796- buffer->name ());
797- selected_buffers.emplace_back (buffer);
798- }
799- }
800- }
801- delete lib_iter;
802- }
803-
804- // abandon attributes & name patterns, just look for all buffers
805- if (selected_buffers.empty ()) {
806- debugPrint (logger_,
807- CTS,
808- " buffering" ,
809- 1 ,
810- " No buffers with clock atributes or name patterns found, using "
811- " all buffers" );
812- lib_iter = network_->libertyLibraryIterator ();
813- while (lib_iter->hasNext ()) {
814- sta::LibertyLibrary* lib = lib_iter->next ();
815- if (options_->isCtsLibrarySet ()
816- && strcmp (lib->name (), options_->getCtsLibrary ()) != 0 ) {
817- continue ;
818- }
819- for (sta::LibertyCell* buffer : *lib->buffers ()) {
820- if (isClockCellCandidate (buffer)) {
821- selected_buffers.emplace_back (buffer);
822- }
823- }
824- }
825- delete lib_iter;
826-
827- if (selected_buffers.empty ()) {
828- logger_->error (
829- CTS,
830- 110 ,
831- " No clock buffer candidates could be found from any libraries." );
832- }
833- }
834-
835- resizer_->setClockBuffersList (selected_buffers);
836-
837- for (sta::LibertyCell* buffer : selected_buffers) {
838- buffers.emplace_back (buffer->name ());
839- debugPrint (logger_,
840- CTS,
841- " buffering" ,
842- 1 ,
843- " {} has been inferred as clock buffer" ,
844- buffer->name ());
845- }
846-
847- options_->setBufferListInferred (true );
848- }
849-
850690std::string toLowerCase (std::string str)
851691{
852692 std::transform (str.begin (), str.end (), str.begin (), [](unsigned char c) {
@@ -855,12 +695,6 @@ std::string toLowerCase(std::string str)
855695 return str;
856696}
857697
858- bool TritonCTS::isClockCellCandidate (sta::LibertyCell* cell)
859- {
860- return (!cell->dontUse () && !resizer_->dontUse (cell) && !cell->alwaysOn ()
861- && !cell->isIsolationCell () && !cell->isLevelShifter ());
862- }
863-
864698std::string TritonCTS::getRootBufferToString ()
865699{
866700 std::ostringstream buffer_names;
@@ -2557,7 +2391,7 @@ void TritonCTS::findCandidateDummyCells(
25572391 while (lib_iter->hasNext ()) {
25582392 sta::LibertyLibrary* lib = lib_iter->next ();
25592393 for (sta::LibertyCell* inv : *lib->inverters ()) {
2560- if (inv->isClockCell () && isClockCellCandidate (inv)) {
2394+ if (inv->isClockCell () && resizer_-> isClockCellCandidate (inv)) {
25612395 inverters.emplace_back (inv);
25622396 dummyCandidates.emplace_back (inv);
25632397 }
@@ -2576,7 +2410,7 @@ void TritonCTS::findCandidateDummyCells(
25762410 sta::LibertyLibrary* lib = lib_iter->next ();
25772411 for (sta::LibertyCell* inv :
25782412 lib->findLibertyCellsMatching (&patternClkInv)) {
2579- if (inv->isInverter () && isClockCellCandidate (inv)) {
2413+ if (inv->isInverter () && resizer_-> isClockCellCandidate (inv)) {
25802414 inverters.emplace_back (inv);
25812415 dummyCandidates.emplace_back (inv);
25822416 }
@@ -2595,7 +2429,7 @@ void TritonCTS::findCandidateDummyCells(
25952429 while (lib_iter->hasNext ()) {
25962430 sta::LibertyLibrary* lib = lib_iter->next ();
25972431 for (sta::LibertyCell* inv : lib->findLibertyCellsMatching (&patternInv)) {
2598- if (inv->isInverter () && isClockCellCandidate (inv)) {
2432+ if (inv->isInverter () && resizer_-> isClockCellCandidate (inv)) {
25992433 inverters.emplace_back (inv);
26002434 dummyCandidates.emplace_back (inv);
26012435 }
@@ -2610,7 +2444,7 @@ void TritonCTS::findCandidateDummyCells(
26102444 while (lib_iter->hasNext ()) {
26112445 sta::LibertyLibrary* lib = lib_iter->next ();
26122446 for (sta::LibertyCell* inv : *lib->inverters ()) {
2613- if (isClockCellCandidate (inv)) {
2447+ if (resizer_-> isClockCellCandidate (inv)) {
26142448 inverters.emplace_back (inv);
26152449 dummyCandidates.emplace_back (inv);
26162450 }
0 commit comments