34 using namespace torc::generic;
40 InstanceSharedPtrVector instances;
41 inViewPtr->getInstances(instances);
42 InstanceSharedPtrVector::iterator ip = instances.begin();
43 InstanceSharedPtrVector::iterator ie = instances.end();
51 inoutCellUsageMap[masterCellPtr]++;
64 typedef std::vector<LibrarySharedPtr> LibrarySharedPtrVector;
65 LibrarySharedPtrVector libraries;
66 inRootPtr->getLibraries(libraries);
67 LibrarySharedPtrVector::iterator lp = libraries.begin();
68 LibrarySharedPtrVector::iterator le = libraries.end();
73 typedef std::vector<CellSharedPtr> CellSharedPtrVector;
74 CellSharedPtrVector cells;
75 libraryPtr->getCells(cells);
76 CellSharedPtrVector::iterator cp = cells.begin();
77 CellSharedPtrVector::iterator ce = cells.end();
81 cellUsageMap[cellPtr] = 0;
87 DesignSharedPtrVector designs;
88 inRootPtr->getDesigns(designs);
89 DesignSharedPtrVector::iterator dp = designs.begin();
90 DesignSharedPtrVector::iterator de = designs.end();
96 std::string libraryName = designPtr->getLibraryRefName();
100 log(
"Examining library %s, cell %s, design %s.\n", libraryName.c_str(), cellName.c_str(),
103 cellUsageMap[cellPtr]++;
105 typedef std::vector<ViewSharedPtr> ViewSharedPtrVector;
106 ViewSharedPtrVector views;
107 cellPtr->getViews(views);
108 ViewSharedPtrVector::iterator vp = views.begin();
109 ViewSharedPtrVector::iterator ve = views.end();
119 CellUsageMap::iterator cp = cellUsageMap.begin();
120 CellUsageMap::iterator ce = cellUsageMap.end();
123 CellUsageMap::value_type cellUsage = *cp++;
128 log(
" library %s, cell %s: %d\n", libraryName.c_str(), cellName.c_str(),
130 if(cellUsage.second == 0) {
131 log(
" removing unused cell %s from library %s: %s.\n", cellName.c_str(),
132 libraryName.c_str(), libraryPtr->findCell(cellName) ?
"found" :
"not found");
133 libraryPtr->removeCell(cellName);
138 for(LibrarySharedPtrVector::size_type i = 0; i < libraries.size(); i++) {
143 typedef std::vector<CellSharedPtr> CellSharedPtrVector;
144 CellSharedPtrVector cells;
145 libraryPtr->getCells(cells);
146 if(cells.size() == 0) {
147 log(
" removing unused library %s.\n", libraryName.c_str());
148 inRootPtr->removeLibrary(libraryName);
void log(const char *fmt,...)
boost::shared_ptr< Instance > InstanceSharedPtr
std::vector< InstanceSharedPtr > InstanceSharedPtrVector
Vector of Instance shared pointers.
std::vector< DesignSharedPtr > DesignSharedPtrVector
Vector of Design shared pointers.
boost::shared_ptr< Design > DesignSharedPtr
boost::shared_ptr< Library > LibrarySharedPtr
void prune(RootSharedPtr &inRootPtr)
Prune all unused cells and libraries from the given root.
void collectCells(ViewSharedPtr &inViewPtr, CellUsageMap &inoutCellUsageMap)
Recursively collect and count all cells used in the given view. The CellUsageMap must already be ini...
boost::shared_ptr< View > ViewSharedPtr
boost::shared_ptr< Cell > CellSharedPtr
std::map< CellSharedPtr, int > CellUsageMap
A map from cell shared pointer to usage count.
boost::shared_ptr< Root > RootSharedPtr