torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::physical::ModuleTransformer Class Reference

Utility class to modularize/flatten designs. More...

#include <ModuleTransformer.hpp>

+ Collaboration diagram for torc::physical::ModuleTransformer:

Public Member Functions

 ModuleTransformer (DesignSharedPtr &inDesignPtr)
 Public constructor. More...
 
bool modularize (const InstanceSharedPtrVector &inInstances, const string &inModuleDefinitionName, const string &inModuleInstanceName, bool inKeepPlacement=false, bool inKeepRouting=false)
 Group a set of instances into a module. More...
 
bool flatten (const string &inModuleInstanceName, bool inKeepPlacement=false, bool inKeepRouting=false)
 Flatten a module instance in a design. More...
 

Protected Types

enum  ENetConnectivity { eNetConnectivityNotConnected = 0, eNetConnectivityInternal, eNetConnectivityExternal }
 Net connectivity with respect to module instance, either not connected to module, internal to module, or external to module. More...
 
typedef
Design::InstanceSharedPtrConstIterator 
InstanceSharedPtrConstIterator
 Imported type. More...
 
typedef
Design::NetSharedPtrIterator 
NetSharedPtrIterator
 Imported type. More...
 
typedef
Design::ModuleSharedPtrIterator 
ModuleSharedPtrIterator
 Imported type. More...
 
typedef
Design::InstanceSharedPtrIterator 
InstanceSharedPtrIterator
 Imported type. More...
 
typedef
Module::PortSharedPtrConstIterator 
PortSharedPtrConstIterator
 Imported type. More...
 
typedef
Net::InstancePinSharedPtrIterator 
InstancePinSharedPtrIterator
 Imported type. More...
 
typedef
Net::InstancePinSharedPtrConstIterator 
InstancePinSharedPtrConstIterator
 Imported type. More...
 
typedef Net::PipConstIterator PipConstIterator
 Imported type. More...
 

Protected Attributes

DesignSharedPtr mDesignPtr
 Design pointer. More...
 

Static Protected Attributes

static const string sHierarchySeparator = "/"
 Hierarchy separator. More...
 
static const string sPortIndexSeparator = "_"
 Port index separator. More...
 
static const boost::regex sValidPinNameCharactersRegEx
 Valid characters in a pin name. More...
 
static const boost::regex sInvalidPinNameFirstCharactersRegEx
 Invalid first characters in a pin name. More...
 

Private Member Functions

ENetConnectivity getNetConnectivity (InstanceSharedPtrConstIterator inInstanceSharedPtrConstBegin, InstanceSharedPtrConstIterator inInstanceSharedPtrConstEnd, NetSharedPtr inNetPtr)
 Generate net connectivity type based on module boundary. More...
 
string sanitizePinName (string inPinName)
 Sanitize a pin name. More...
 
InstanceSharedPtr cloneInstance (InstanceSharedPtr inIntancePtr, const string &inCloneInstanceName)
 Clone an instance. More...
 
NetSharedPtr cloneNet (NetSharedPtr inNetPtr, const string &inNetCloneName, const string &inModuleInstanceName)
 Clone a net. More...
 

Detailed Description

Utility class to modularize/flatten designs.

Definition at line 34 of file ModuleTransformer.hpp.

Member Typedef Documentation

Imported type.

Definition at line 53 of file ModuleTransformer.hpp.

Member Enumeration Documentation

Net connectivity with respect to module instance, either not connected to module, internal to module, or external to module.

Enumerator
eNetConnectivityNotConnected 
eNetConnectivityInternal 
eNetConnectivityExternal 

Definition at line 68 of file ModuleTransformer.hpp.

Constructor & Destructor Documentation

torc::physical::ModuleTransformer::ModuleTransformer ( DesignSharedPtr inDesignPtr)
inline

Public constructor.

Parameters
inDesignPtrPointer to the design.

Definition at line 76 of file ModuleTransformer.hpp.

76 : mDesignPtr(inDesignPtr) {}
DesignSharedPtr mDesignPtr
Design pointer.

Member Function Documentation

InstanceSharedPtr torc::physical::ModuleTransformer::cloneInstance ( InstanceSharedPtr  inIntancePtr,
const string &  inCloneInstanceName 
)
inlineprivate

Clone an instance.

Parameters
inIntancePtrA pointer to the instance to be cloned.
inCloneInstanceNameThe name of the clone.

Clone an instance and its configuration. This function does not clone the instance pins. Instance pins are handled when cloning nets, in function cloneNet.

Definition at line 872 of file ModuleTransformer.hpp.

873  {
874 
875  // Clone inInstancePtr
876  InstanceSharedPtr inInstanceClonePtr = Factory::newInstancePtr(inCloneInstanceName,
877  inIntancePtr->getType(), inIntancePtr->getTile(), inIntancePtr->getSite(),
878  inIntancePtr->getBonding());
879 
880  // Begin clone inIntance configuration
881  // Get a begin iterator to inIntance config
882  ConfigMap::const_iterator instanceConfigBegin = inIntancePtr->configBegin();
883  // Get an end iterator to inIntance config
884  ConfigMap::const_iterator instanceConfigEnd = inIntancePtr->configEnd();
885  // Configuration map
886  ConfigMap configMap;
887 
888  // Iterate over all configuration
889  while(instanceConfigBegin != instanceConfigEnd) {
890 
891  // Get current setting
892  const string setting = instanceConfigBegin->first;
893  // Get current configuration
894  const Config config = instanceConfigBegin->second;
895  // Add (setting,configuration) to configuration map
896  configMap.setConfig(setting, config);
897  // Move to the next configuration
898  instanceConfigBegin++;
899 
900  }
901 
902  // Add configurations to instance clone
903  inInstanceClonePtr->addConfigs(configMap);
904  // End clone inInstance configuration
905 
906  // Return cloned instance
907  return inInstanceClonePtr;
908  }
const_iterator const_iterator
Constant iterator to {setting,Config} pairs.
Definition: ConfigMap.hpp:52
static InstanceSharedPtr newInstancePtr(const string &inName, const string &inType, const string &inTile, const string &inSite, EInstanceBonding inBonding=eInstanceBondingUnknown, InstanceReferenceSharedPtr inInstanceReferencePtr=InstanceReferenceSharedPtr())
Construct and return a new Instance shared pointer.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.

+ Here is the call graph for this function:

NetSharedPtr torc::physical::ModuleTransformer::cloneNet ( NetSharedPtr  inNetPtr,
const string &  inNetCloneName,
const string &  inModuleInstanceName 
)
inlineprivate

Clone a net.

Parameters
inNetPtrA pointer to the net to be cloned.
inNetCloneNameThe name of the clone.
inModuleInstanceNameThe module instance name.

Clone a net, its configuration, its sources, sinks and pips. For pips, the routethrough instances are droppped and not cloned.

Todo:
We are dropping routethrough instances.

Definition at line 916 of file ModuleTransformer.hpp.

917  {
918 
919  // Clone inNetPtr
920  NetSharedPtr inNetClonePtr = Factory::newNetPtr(inNetCloneName, inNetPtr->getNetType());
921 
922  // Begin clone inNetPtr configuration
923  // Get a begin iterator to net config
924  ConfigMap::const_iterator netConfigBegin = inNetPtr->configBegin();
925  // Get an end iterator to net config
926  ConfigMap::const_iterator netConfigEnd = inNetPtr->configEnd();
927  // Configuration map
928  ConfigMap configMap;
929 
930  // Iterate over all configuration
931  while(netConfigBegin != netConfigEnd) {
932 
933  // Get current setting
934  const string setting = netConfigBegin->first;
935  // Get current configuration
936  const Config config = netConfigBegin->second;
937  // Add (setting,configuration) to configuration map
938  configMap.setConfig(setting, config);
939  // Move to the next configuration
940  netConfigBegin++;
941 
942  }
943 
944  // Add configurations to net clone
945  inNetClonePtr->addConfigs(configMap);
946  // End clone inNetPtr configuration
947 
948  // Begin clone inNetPtr sources
949  // Get a begin iterator to net sources
950  InstancePinSharedPtrConstIterator inNetSourcesBegin = inNetPtr->sourcesBegin();
951  // Get an end iterator to net sources
952  InstancePinSharedPtrConstIterator inNetSourcesEnd = inNetPtr->sourcesEnd();
953 
954  // Iterate over all source pins
955  while(inNetSourcesBegin != inNetSourcesEnd) {
956 
957  // Get pointer to current net pin
958  InstancePinSharedPtr instPinPtr = *inNetSourcesBegin;
959  // Get net pin reference instance
960  InstanceSharedPtr pinInstPtr = instPinPtr->getInstancePtr().lock();
961  // Find the cloned instance that correspond to the pin reference instance
962  InstanceSharedPtrIterator pinInstPtrCloneItr = mDesignPtr->findInstance(
963  inModuleInstanceName + sHierarchySeparator + pinInstPtr->getName());
964  // Clone source pin
965  InstancePinSharedPtr instPinPtrClone
966  = Factory::newInstancePinPtr(*pinInstPtrCloneItr, instPinPtr->getPinName());
967  // Add pin clone to the net clone
968  inNetClonePtr->addSource(instPinPtrClone);
969  // Move to next source
970  inNetSourcesBegin++;
971 
972  }
973  // End clone inNetPtr sources
974 
975  // Begin clone inNetPtr sinks
976  // Get a begin iterator to net sinks
977  InstancePinSharedPtrConstIterator inNetSinksBegin = inNetPtr->sinksBegin();
978  // Get an end iterator to net sinks
979  InstancePinSharedPtrConstIterator inNetSinksEnd = inNetPtr->sinksEnd();
980 
981  // Iterate over all sink pins
982  while(inNetSinksBegin != inNetSinksEnd) {
983 
984  // Get pointer to current net pin
985  InstancePinSharedPtr instPinPtr = *inNetSinksBegin;
986  // Get net pin reference instance
987  InstanceSharedPtr pinInstPtr = instPinPtr->getInstancePtr().lock();
988  // Find the cloned instance that correspond to the pin reference instance
989  InstanceSharedPtrIterator pinInstPtrCloneItr = mDesignPtr->findInstance(
990  inModuleInstanceName + sHierarchySeparator + pinInstPtr->getName());
991  // Clone sink pin
992  InstancePinSharedPtr instPinPtrClone
993  = Factory::newInstancePinPtr(*pinInstPtrCloneItr, instPinPtr->getPinName());
994  // Add pin clone to the net clone
995  inNetClonePtr->addSink(instPinPtrClone);
996  // Move to next sink
997  inNetSinksBegin++;
998 
999  }
1000  // End clone inNetPtr sinks
1001 
1002  // Begin clone inNetPtr pips
1003  // Get a begin iterator to net pips
1004  PipConstIterator inNetPipsBegin = inNetPtr->pipsBegin();
1005  // Get an end iterator to net pips
1006  PipConstIterator inNetPipsEnd = inNetPtr->pipsEnd();
1007 
1008  // Iterate over all pips
1009  while(inNetPipsBegin != inNetPipsEnd) {
1010 
1011  // Get a pointer to the current pip
1012  Pip pipPtr = *inNetPipsBegin;
1013  /// \todo We are dropping routethrough instances.
1014  // Clone the pip
1015  Pip pipClone = Factory::newPip(pipPtr.getTileName(), pipPtr.getSourceWireName(),
1016  pipPtr.getSinkWireName(), pipPtr.getDirection());
1017  // Add pip clone to cloned net
1018  inNetClonePtr->addPip(pipClone);
1019  // Move to next pip
1020  inNetPipsBegin++;
1021 
1022  }
1023  // End clone inNetPtr pips
1024 
1025  // Return cloned net
1026  return inNetClonePtr;
1027  }
Design::InstanceSharedPtrIterator InstanceSharedPtrIterator
Imported type.
static NetSharedPtr newNetPtr(const string &inName, ENetType inNetType=eNetTypeNormal)
Create and return a new Net share pointer.
DesignSharedPtr mDesignPtr
Design pointer.
Net::PipConstIterator PipConstIterator
Imported type.
const_iterator const_iterator
Constant iterator to {setting,Config} pairs.
Definition: ConfigMap.hpp:52
Net::InstancePinSharedPtrConstIterator InstancePinSharedPtrConstIterator
Imported type.
static torc::physical::Pip newPip(const string &inTileName, const string &inSourceWireName, const string &inSinkWireName, EPipDirection inPipDirection, RoutethroughSharedPtr inRoutethroughPtr=RoutethroughSharedPtr())
Construct a pip and return it.
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
static InstancePinSharedPtr newInstancePinPtr(InstanceSharedPtr inInstancePtr, const string &inPinName)
Construct and return a new InstancePin shared pointer.
static const string sHierarchySeparator
Hierarchy separator.
boost::shared_ptr< InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.

+ Here is the call graph for this function:

bool torc::physical::ModuleTransformer::flatten ( const string &  inModuleInstanceName,
bool  inKeepPlacement = false,
bool  inKeepRouting = false 
)
inline

Flatten a module instance in a design.

Parameters
inModuleInstanceNameThe name of the module instance to be flattened.
inKeepPlacementA flag specifying whether placement should be retained after flattening. Default to false.
inKeepRoutingA flag specifying whether routing should be retained afer flattening. Defaults to false.

Definition at line 481 of file ModuleTransformer.hpp.

482  {
483 
484  // Flattened module source pins
485  InstancePinSharedPtrVector flattenedModuleSourcePinPtrVector;
486  // Flattened module sink pins
487  InstancePinSharedPtrVector flattenedModuleSinkPinPtrVector;
488  // Look for the module instance in the design
489  InstanceSharedPtrConstIterator designModInstPtrConstIter
490  = mDesignPtr->findInstance(inModuleInstanceName);
491 
492  // Check for a non-existent module instance
493  if(designModInstPtrConstIter == mDesignPtr->instancesEnd()) {
494 
495  // Warn the user that the module instance was not found in the design
496  std::clog << "WARNING: Module instance of name " << inModuleInstanceName
497  << " was not found in design " << mDesignPtr->getName() << "." << std::endl;
498 
499  // Operation did not complete successfully
500  return false;
501 
502  }
503 
504  // Get a pointer to the instance
505  InstanceSharedPtr instPtr = *designModInstPtrConstIter;
506  // Look for the module in the design
507  ModuleSharedPtrIterator designModPtrConstIter
508  = mDesignPtr->findModule(instPtr->getType());
509 
510  // Check for a non-existent module
511  if(designModPtrConstIter == mDesignPtr->modulesEnd()) {
512 
513  // Warn the user that the module was not found in the design
514  std::clog << "WARNING: Module of name " << instPtr->getType()
515  << " was not found in design " << mDesignPtr->getName() << "." << std::endl;
516 
517  // Operation did not complete successfully
518  return false;
519 
520  }
521 
522  // Current design module
523  ModuleSharedPtr module = *designModPtrConstIter;
524 
525  // Check whether tile/site for module instance is same as tile/site for module def.
526  // In case they don't match, the flattened module instance will be unplaced and any
527  // external/internal nets to the module instance will be unrouted.
528  InstanceSharedPtrIterator moduleAnchorInstIterator
529  = module->findInstance(module->getAnchor());
530  InstanceSharedPtr moduleAnchorInst = *moduleAnchorInstIterator;
531  // Begin handle instances inside module
532  // Get a begin iterator to module instances
533  InstanceSharedPtrIterator moduleInstancesIter = module->instancesBegin();
534  // Get an end iterator to module instances
535  InstanceSharedPtrIterator moduleInstancesEnd = module->instancesEnd();
536 
537  // Iterate over all instances hosted by the module
538  while(moduleInstancesIter != moduleInstancesEnd) {
539 
540  // Get a pointer to the current instance hosted by the module
541  InstanceSharedPtr modInstPtr = *moduleInstancesIter;
542  // Clone the instance
543  InstanceSharedPtr modInstPtrClone = cloneInstance(modInstPtr,
544  inModuleInstanceName + sHierarchySeparator + modInstPtr->getName());
545  // Set clone instance reference
546  modInstPtrClone->setInstanceReferencePtr(Factory::newInstanceReferencePtr(
547  inModuleInstanceName, module, modInstPtr));
548 
549  // Unplace the instance if so requested
550  if(!inKeepPlacement) modInstPtrClone->unplace();
551 
552  // Add clone of instance to design
553  mDesignPtr->addInstance(modInstPtrClone);
554 
555  // Next instance
556  moduleInstancesIter++;
557 
558  } // while(moduleInstancesIter != moduleInstancesEnd)
559  // End handle instances inside module
560 
561  // Begin handle internal module nets
562  // Get a begin iterator to module nets
563  NetSharedPtrIterator moduleNetsIter = module->netsBegin();
564  // Get an end iterator to module nets
565  NetSharedPtrIterator moduleNetsEnd = module->netsEnd();
566 
567  // Iterate over all nets inside module
568  while(moduleNetsIter != moduleNetsEnd) {
569 
570  // Get a pointer to the current net
571  NetSharedPtr moduleNetPtr = *moduleNetsIter;
572  // Clone the net
573  NetSharedPtr moduleNetPtrClone = cloneNet(moduleNetPtr, inModuleInstanceName
574  + sHierarchySeparator + moduleNetPtr->getName(), inModuleInstanceName);
575 
576  // Unroute the net if so requested
577  if(!inKeepRouting) moduleNetPtrClone->unroute();
578 
579  // Add net to design
580  mDesignPtr->addNet(moduleNetPtrClone);
581  // Next net
582  moduleNetsIter++;
583 
584  } // End handle internal module nets
585 
586  // Begin handle external module nets
587  // Get a begin iterator to design nets
588  NetSharedPtrIterator designNetsIter = mDesignPtr->netsBegin();
589  // Get an end iterator to design nets
590  NetSharedPtrIterator designNetsEnd = mDesignPtr->netsEnd();
591 
592  // Iterate over all nets connected to module and other instances outside module
593  while(designNetsIter != designNetsEnd) {
594 
595  // Get a pointer to the current net
596  NetSharedPtr designNetPtr = *designNetsIter;
597 
598  // Get a begin iterator to net sources
599  InstancePinSharedPtrIterator designNetSourcesIter = designNetPtr->sourcesBegin();
600  // Get an end iterator to net sources
601  InstancePinSharedPtrIterator designNetSourcesEnd = designNetPtr->sourcesEnd();
602 
603  // Iterate over all net sources
604  while(designNetSourcesIter != designNetSourcesEnd) {
605 
606  // Net pin
607  InstancePinSharedPtr instPinPtr = *designNetSourcesIter;
608  // Pin instance
609  InstanceSharedPtr pinInstPtr = instPinPtr->getInstancePtr().lock();
610 
611  // Net connects to module instance
612  if(pinInstPtr == instPtr) {
613 
614  // Unroute the net if so requested
615  if(!inKeepRouting) designNetPtr->unroute();
616 
617  // Look for the port in the module
618  PortSharedPtrConstIterator modulePortConstIter
619  = module->findPort(instPinPtr->getPinName());
620 
621  // Check if port was found
622  if(modulePortConstIter != module->portsEnd()) {
623 
624  // Get a pointer to the current port
625  PortSharedPtr modPortPtr = *modulePortConstIter;
626  // Get module port reference instance
627  InstanceSharedPtr portInstPtr = modPortPtr->getInstancePtr().lock();
628  // Find the cloned instance corresponding to the pin reference instance
629  InstanceSharedPtrIterator pinInstPtrCloneItr
630  = mDesignPtr->findInstance(inModuleInstanceName
631  + sHierarchySeparator + portInstPtr->getName());
632  // Create new pin referencing the port reference instance
633  flattenedModuleSourcePinPtrVector.push_back(
634  Factory::newInstancePinPtr(*pinInstPtrCloneItr,
635  modPortPtr->getPinName()));
636  // Remove pin reference module instance
637  designNetPtr->removeSource(instPinPtr);
638  // Update designNetSourcesEnd iterator
639  designNetSourcesEnd = designNetPtr->sourcesEnd();
640 
641  }
642 
643  } else {
644 
645  // Move to next source
646  designNetSourcesIter++;
647 
648  }
649  } // while(designNetSourcesIter != designNetSourcesEnd)
650 
651  // Get a begin iterator to flattened module source pins
652  InstancePinSharedPtrIterator flattenedModuleSourcesIter
653  = flattenedModuleSourcePinPtrVector.begin();
654  // Get an end iterator to flattened module source pins
655  InstancePinSharedPtrIterator flattenedModuleSourcesEnd
656  = flattenedModuleSourcePinPtrVector.end();
657 
658  // Update net sources with new source pins
659  while(flattenedModuleSourcesIter != flattenedModuleSourcesEnd) {
660 
661  // Add source pin to net
662  designNetPtr->addSource(*flattenedModuleSourcesIter);
663  // Move to next source
664  flattenedModuleSourcesIter++;
665  }
666 
667  // Reset vector
668  flattenedModuleSourcePinPtrVector.clear();
669  // Get a begin iterator to net sinks
670  InstancePinSharedPtrIterator designNetSinksIter = designNetPtr->sinksBegin();
671  // Get an end iterator to net sinks
672  InstancePinSharedPtrIterator designNetSinksEnd = designNetPtr->sinksEnd();
673 
674  // Iterate over all net sinks
675  while(designNetSinksIter != designNetSinksEnd) {
676 
677  // Net pin
678  InstancePinSharedPtr instPinPtr = *designNetSinksIter;
679  // Pin instance
680  InstanceSharedPtr pinInstPtr = instPinPtr->getInstancePtr().lock();
681 
682  // Net connets to module instance
683  if(pinInstPtr == instPtr) {
684 
685  // Unroute the net if so requested
686  if(!inKeepRouting) designNetPtr->unroute();
687 
688  // Look for the port in the module
689  PortSharedPtrConstIterator modulePortConstIter
690  = module->findPort(instPinPtr->getPinName());
691 
692  // Check if port was found
693  if(modulePortConstIter != module->portsEnd()) {
694 
695  // Get a pointer to the current port
696  PortSharedPtr modPortPtr = *modulePortConstIter;
697  // Get module port reference instance
698  InstanceSharedPtr portInstPtr = modPortPtr->getInstancePtr().lock();
699  // Find the cloned instance corresponding to the pin reference instance
700  InstanceSharedPtrIterator pinInstPtrCloneItr
701  = mDesignPtr->findInstance(inModuleInstanceName
702  + sHierarchySeparator + portInstPtr->getName());
703  // Create new pin referencing the port reference instance
704  flattenedModuleSinkPinPtrVector.push_back(
705  Factory::newInstancePinPtr(*pinInstPtrCloneItr,
706  modPortPtr->getPinName()));
707  // Remove pin reference module instance
708  designNetPtr->removeSink(instPinPtr);
709  // Update designNetSinksEnd iterator
710  designNetSinksEnd = designNetPtr->sinksEnd();
711  }
712 
713  } else {
714 
715  // Move to next source
716  designNetSinksIter++;
717 
718  }
719  } // while(designNetSinksIter != designNetSinksEnd)
720 
721  // Get a begin iterator to flattened module sink pins
722  InstancePinSharedPtrIterator flattenedModuleSinksBegin
723  = flattenedModuleSinkPinPtrVector.begin();
724  // Get an end iterator to flattened module sink pins
725  InstancePinSharedPtrIterator flattenedModuleSinksEnd
726  = flattenedModuleSinkPinPtrVector.end();
727 
728  // Update net sources with new source pins
729  while(flattenedModuleSinksBegin != flattenedModuleSinksEnd) {
730 
731  // Add sink pin to net
732  designNetPtr->addSink(*flattenedModuleSinksBegin);
733  // Move to next sink
734  flattenedModuleSinksBegin++;
735 
736  }
737 
738  // Reset vector
739  flattenedModuleSinkPinPtrVector.clear();
740 
741  // Move to next net
742  designNetsIter++;
743 
744  } // while(designNetsIter != designNetsEnd)
745  // End handle external module nets
746 
747  // Remove module instance from design
748  mDesignPtr->removeInstance(instPtr);
749 
750  // Operation successfully completed
751  return true;
752  }
Design::NetSharedPtrIterator NetSharedPtrIterator
Imported type.
Module::PortSharedPtrConstIterator PortSharedPtrConstIterator
Imported type.
Design::InstanceSharedPtrIterator InstanceSharedPtrIterator
Imported type.
boost::shared_ptr< Port > PortSharedPtr
Shared pointer encapsulation of a Port.
DesignSharedPtr mDesignPtr
Design pointer.
InstanceSharedPtr cloneInstance(InstanceSharedPtr inIntancePtr, const string &inCloneInstanceName)
Clone an instance.
Design::ModuleSharedPtrIterator ModuleSharedPtrIterator
Imported type.
Net::InstancePinSharedPtrIterator InstancePinSharedPtrIterator
Imported type.
boost::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
Definition: Module.hpp:114
std::vector< InstancePinSharedPtr > InstancePinSharedPtrVector
Vector of InstancePin shared pointers.
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
NetSharedPtr cloneNet(NetSharedPtr inNetPtr, const string &inNetCloneName, const string &inModuleInstanceName)
Clone a net.
static InstancePinSharedPtr newInstancePinPtr(InstanceSharedPtr inInstancePtr, const string &inPinName)
Construct and return a new InstancePin shared pointer.
Design::InstanceSharedPtrConstIterator InstanceSharedPtrConstIterator
Imported type.
static const string sHierarchySeparator
Hierarchy separator.
boost::shared_ptr< InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
static InstanceReferenceSharedPtr newInstanceReferencePtr(const string &inInstantiationName, ModuleSharedPtr inModulePtr, InstanceSharedPtr inInstancePtr)
Create and return a new InstanceReference shared pointer.

+ Here is the caller graph for this function:

ENetConnectivity torc::physical::ModuleTransformer::getNetConnectivity ( InstanceSharedPtrConstIterator  inInstanceSharedPtrConstBegin,
InstanceSharedPtrConstIterator  inInstanceSharedPtrConstEnd,
NetSharedPtr  inNetPtr 
)
inlineprivate

Generate net connectivity type based on module boundary.

Parameters
inInstanceSharedPtrConstBeginA begin iterator to instances contained in module.
inInstanceSharedPtrConstEndAn end iterator to instances contained in module.
inNetPtrA pointer to a net.

Definition at line 760 of file ModuleTransformer.hpp.

762  {
763 
764  // Net connectivity type
766  // Is net connected to module?
767  bool isNetConnectedToModule = false;
768  // Is net crossing module boundary?
769  bool isNetInterToModule = false;
770  // Get a begin iterator to net sources
771  InstancePinSharedPtrIterator sourcesBegin = inNetPtr->sourcesBegin();
772  // Get an end iterator to net sources
773  InstancePinSharedPtrIterator sourcesEnd = inNetPtr->sourcesEnd();
774 
775  // Iterate over all sources
776  while(sourcesBegin != sourcesEnd) {
777 
778  // Get a pointer to the current source pin
779  InstancePinSharedPtr instPinPtr = *sourcesBegin;
780  // Get a pointer to the instance that hosts the pin
781  InstanceSharedPtr pinInst = instPinPtr->getInstancePtr().lock();
782 
783  // Look for the instance in the vector of instances
784  if((std::find(inInstanceSharedPtrConstBegin, inInstanceSharedPtrConstEnd, pinInst))
785  != inInstanceSharedPtrConstEnd) {
786 
787  // Net connects to instance inside module boundary
788  isNetConnectedToModule = true;
789 
790  } else {
791 
792  // Net connects to instance outside module boundary
793  isNetInterToModule = true;
794 
795  }
796 
797  // Move to next source
798  sourcesBegin++;
799  }
800 
801  // Get a begin iterator to net sinks
802  InstancePinSharedPtrIterator sinksBegin = inNetPtr->sinksBegin();
803  // Get an end iterator to net sinks
804  InstancePinSharedPtrIterator sinksEnd = inNetPtr->sinksEnd();
805 
806  // Iterate over all sinks
807  while(sinksBegin != sinksEnd) {
808 
809  // Get a pointer to the current sink pin
810  InstancePinSharedPtr instPinPtr = *sinksBegin;
811  // Get a pointer to the instance that hosts the pin
812  InstanceSharedPtr pinInst = instPinPtr->getInstancePtr().lock();
813  // Look for the instance in the vector of instances
814  if((std::find(inInstanceSharedPtrConstBegin, inInstanceSharedPtrConstEnd, pinInst))
815  != inInstanceSharedPtrConstEnd) {
816  // Net connects to instance inside module boundary
817  isNetConnectedToModule = true;
818  } else {
819  // Net connects to instance outside module boundary
820  isNetInterToModule = true;
821  }
822  // Move to the next sink
823  sinksBegin++;
824  }
825 
826  if(isNetConnectedToModule) { // Net connects to module
827  if(isNetInterToModule) {
828  netConnectivity = eNetConnectivityExternal; // Net crosses module boundary
829  } else {
830  netConnectivity = eNetConnectivityInternal; // Net lies within module boundary
831  }
832  }
833 
834  // Return net connectivity type
835  return netConnectivity;
836  }
Net::InstancePinSharedPtrIterator InstancePinSharedPtrIterator
Imported type.
ENetConnectivity
Net connectivity with respect to module instance, either not connected to module, internal to module...
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
boost::shared_ptr< InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
bool torc::physical::ModuleTransformer::modularize ( const InstanceSharedPtrVector inInstances,
const string &  inModuleDefinitionName,
const string &  inModuleInstanceName,
bool  inKeepPlacement = false,
bool  inKeepRouting = false 
)
inline

Group a set of instances into a module.

Parameters
inInstancesThe vector of instances to group.
inModuleDefinitionNameThe module definition name.
inModuleInstanceNameThe module instance name.
inKeepPlacementA flag specifying whether placement should be retained after modularization. Default to false.
inKeepRoutingA flag specifying whether routing should be retained afer modularization. Defaults to false.

Definition at line 147 of file ModuleTransformer.hpp.

149  {
150 
151  // Get a current iterator to inInstances
152  InstanceSharedPtrConstIterator inInstanceSharedPtrConstIter = inInstances.begin();
153  // Get an end iterator to inInstances
154  InstanceSharedPtrConstIterator inInstanceSharedPtrConstEnd = inInstances.end();
155 
156  // Check if inInstances is empty
157  if(inInstanceSharedPtrConstIter == inInstanceSharedPtrConstEnd) {
158 
159  // Warn the user that none of the instances specified are found in the design
160  std::clog << "WARNING: There were no instances specified to be modularized. "
161  << std::endl;
162 
163  // Operation did not complete successfully
164  return false;
165 
166  }
167 
168  // Set the first returned instance as a reference point
169  InstanceSharedPtr moduleReferenceInst = *inInstanceSharedPtrConstIter;
170  // Create module definition
171  ModuleSharedPtr moduleDefinition = Factory::newModulePtr(inModuleDefinitionName,
172  moduleReferenceInst->getName());
173  // Create module instance
174  InstanceSharedPtr moduleInst = Factory::newInstancePtr(inModuleInstanceName,
175  inModuleDefinitionName, moduleReferenceInst->getTile(),
176  moduleReferenceInst->getSite());
177 
178  // Unplace module instance if so requested
179  if(!inKeepPlacement) moduleInst->unplace();
180 
181  // Begin handle instances
182  // Iterate over all instances in inInstances
183  while(inInstanceSharedPtrConstIter != inInstanceSharedPtrConstEnd) {
184 
185  // Get a pointer to the current instance
186  InstanceSharedPtr instPtr = *inInstanceSharedPtrConstIter;
187 
188  // Look for the current instance in the design
189  InstanceSharedPtrConstIterator instPtrIter
190  = mDesignPtr->findInstance(instPtr->getName());
191 
192  // Warn if the instance was not found
193  if(instPtrIter == mDesignPtr->instancesEnd()) {
194 
195  // Warn the user that the instance was not found in the design.
196  std::clog << "WARNING: Instance " << instPtr->getName()
197  << "was not found in design " << mDesignPtr->getName() << std::endl;
198  // Operation did not complete successfully
199  return false;
200 
201  }
202 
203  // Get a pointer to the looked up instance
204  InstanceSharedPtr designInstPtr = *instPtrIter;
205 
206  // Unplace instance if so requested
207  if(!inKeepPlacement) designInstPtr->unplace();
208 
209  // Add instance to module
210  moduleDefinition->addInstance(designInstPtr);
211  // Remove instance from design
212  mDesignPtr->removeInstance(designInstPtr);
213 
214  // Move to next instance
215  inInstanceSharedPtrConstIter++;
216 
217  } // while(inInstanceSharedPtrConstIter != inInstanceSharedPtrConstEnd)
218  // End handle instances
219 
220  // Begin handle connectivity
221  // Get a begin iterator to design nets
222  NetSharedPtrIterator designNetsIter = mDesignPtr->netsBegin();
223  // Get an end iterator to design nets
224  NetSharedPtrIterator designNetsEnd = mDesignPtr->netsEnd();
225  // Get a begin iterator to module hosted instances
226  InstanceSharedPtrConstIterator modHostedInstPtrConstBegin
227  = moduleDefinition->instancesBegin();
228  // Get an end iterator to module hosted instances
229  InstanceSharedPtrConstIterator modHostedInstPtrConstEnd
230  = moduleDefinition->instancesEnd();
231  // Module instance source pins
232  InstancePinSharedPtrVector modInstSourcePinPtrVector;
233  // Module instance sink pins
234  InstancePinSharedPtrVector modInstSinkPinPtrVector;
235 
236  // Iterate over all design nets
237  while(designNetsIter != designNetsEnd) {
238 
239  // Get a pointer to the current net
240  NetSharedPtr designNetPtr = *designNetsIter;
241  // Compute net connectivity type
242  ENetConnectivity eNet = getNetConnectivity(modHostedInstPtrConstBegin,
243  modHostedInstPtrConstEnd, designNetPtr);
244 
245  // For internal nets, move net from design to module
246  if(eNet == eNetConnectivityInternal) {
247 
248  // Unroute the net if so requested
249  if(!inKeepRouting) designNetPtr->unroute();
250 
251  // Add net to module
252  moduleDefinition->addNet(designNetPtr);
253  // Remove net from design
254  mDesignPtr->removeNet(designNetPtr);
255  // Update designNetsEnd iterator
256  designNetsEnd = mDesignPtr->netsEnd();
257 
258  } else {
259 
260  // For unconnected nets, increment the iterator and continue looping
261  if(eNet == eNetConnectivityNotConnected) {
262 
263  // Move to next net
264  designNetsIter++;
265  continue;
266 
267  }
268 
269  // For external nets, expose corresponding pins and update connectivity
270  // Unroute the net if so requested
271  if(!inKeepRouting) designNetPtr->unroute();
272 
273  // Get a begin iterator to net sources
274  InstancePinSharedPtrIterator designNetSourcesIter
275  = designNetPtr->sourcesBegin();
276  // Get an end iterator to net sources
277  InstancePinSharedPtrIterator designNetSourcesEnd = designNetPtr->sourcesEnd();
278  // Wire index used when creating ports
279  u_int32_t portIndex = 0;
280 
281  // Iterate over all net sources
282  while(designNetSourcesIter != designNetSourcesEnd) {
283 
284  // Get a pointer to the current net source pin
285  InstancePinSharedPtr instPinPtr = *designNetSourcesIter;
286  // Get a pointer to the instance hosting the net source pin
287  InstanceSharedPtr pinInstPtr = instPinPtr->getInstancePtr().lock();
288 
289  // Look for the instance in the vector of instances
290  if((std::find(modHostedInstPtrConstBegin, modHostedInstPtrConstEnd,
291  pinInstPtr)) != modHostedInstPtrConstEnd) {
292 
293  // Build port name: netName_portIndex
294  string portName = sanitizePinName(designNetPtr->getName())
296  + boost::lexical_cast<std::string>(portIndex++);
297  // Create port
298  PortSharedPtr portPtr = Factory::newPortPtr(portName, *(std::find(
299  modHostedInstPtrConstBegin, modHostedInstPtrConstEnd,
300  pinInstPtr)), instPinPtr->getPinName());
301  // Add port to module
302  moduleDefinition->addPort(portPtr);
303  // Create source pin from the module instance
304  modInstSourcePinPtrVector.push_back(
305  Factory::newInstancePinPtr(moduleInst, portName));
306  // Remove old source pin from net
307  designNetPtr->removeSource(instPinPtr);
308  // Update designNetSourcesEnd iterator
309  designNetSourcesEnd = designNetPtr->sourcesEnd();
310 
311  } else {
312 
313  // Move to next source
314  designNetSourcesIter++;
315 
316  }
317  } // while(designNetSourcesIter != designNetSourcesEnd)
318 
319  // Get a begin iterator to module source pins
320  InstancePinSharedPtrIterator modInstSourcesIter =
321  modInstSourcePinPtrVector.begin();
322  // Get an end iterator to module source pins
323  InstancePinSharedPtrIterator modInstSourcesEnd =
324  modInstSourcePinPtrVector.end();
325 
326  // Update net sources with new source pins
327  while(modInstSourcesIter != modInstSourcesEnd) {
328 
329  // Add source pin to net
330  designNetPtr->addSource(*modInstSourcesIter);
331  // Move to next source
332  modInstSourcesIter++;
333 
334  }
335 
336  // Reset module instance source pins vector
337  modInstSourcePinPtrVector.clear();
338  // Get a begin iterator to net sinks
339  InstancePinSharedPtrIterator designNetSinksIter = designNetPtr->sinksBegin();
340  // Get an end iterator to net sinks
341  InstancePinSharedPtrIterator designNetSinksEnd = designNetPtr->sinksEnd();
342 
343  // Iterate over all net sinks
344  while(designNetSinksIter != designNetSinksEnd) {
345 
346  // Get a pointer to the current net sink pin
347  InstancePinSharedPtr instPinPtr = *designNetSinksIter;
348  // Get a pointer to the instance hosting the net source pin
349  InstanceSharedPtr pinInstPtr = instPinPtr->getInstancePtr().lock();
350 
351  // Look for the instance in the vector of instances
352  if((std::find(modHostedInstPtrConstBegin, modHostedInstPtrConstEnd,
353  pinInstPtr)) != modHostedInstPtrConstEnd) {
354 
355  // Build port name: netName_portIndex
356  string portName = sanitizePinName(designNetPtr->getName())
357  + sPortIndexSeparator + boost::lexical_cast<std::string>(
358  portIndex++);
359  // Create port
360  PortSharedPtr portPtr = Factory::newPortPtr(portName, *(std::find(
361  modHostedInstPtrConstBegin, modHostedInstPtrConstEnd,
362  pinInstPtr)), instPinPtr->getPinName());
363  // Add port to module
364  moduleDefinition->addPort(portPtr);
365  // Create sink pin to the module instance
366  modInstSinkPinPtrVector.push_back(Factory::newInstancePinPtr(
367  moduleInst, portName));
368  // Remove old sink pin from net
369  designNetPtr->removeSink(instPinPtr);
370  // Update designNetSinksEnd iterator
371  designNetSinksEnd = designNetPtr->sinksEnd();
372 
373  } else {
374 
375  // Move to next sink
376  designNetSinksIter++;
377 
378  }
379  } // while(designNetSinksIter != designNetSinksEnd)
380 
381  // Get a begin iterator to module sink pins
382  InstancePinSharedPtrIterator modInstSinksIter =
383  modInstSinkPinPtrVector.begin();
384  // Get an end iterator to module sink pins
385  InstancePinSharedPtrIterator modInstSinksEnd =
386  modInstSinkPinPtrVector.end();
387 
388  // Update net sources with new source pins
389  while(modInstSinksIter != modInstSinksEnd) {
390 
391  // Add sink pin to net
392  designNetPtr->addSink(*modInstSinksIter);
393  // Move to next sink
394  modInstSinksIter++;
395 
396  }
397 
398  // Reset module instance sink pins vector
399  modInstSinkPinPtrVector.clear();
400 
401  // Move to next net
402  designNetsIter++;
403 
404  } // else
405  } // while(designNetsIter != designNetsEnd)
406  // End handle connectivity
407 
408  // Add module to design
409  mDesignPtr->addModule(moduleDefinition);
410  // Add module instance to design
411  mDesignPtr->addInstance(moduleInst);
412 
413  // Operation successfully completed
414  return true;
415  }
Design::NetSharedPtrIterator NetSharedPtrIterator
Imported type.
static PortSharedPtr newPortPtr(const string &inName, InstanceSharedPtr inInstancePtr, const string &inPinName)
Create and return a new Port shared pointer.
boost::shared_ptr< Port > PortSharedPtr
Shared pointer encapsulation of a Port.
string sanitizePinName(string inPinName)
Sanitize a pin name.
DesignSharedPtr mDesignPtr
Design pointer.
ENetConnectivity getNetConnectivity(InstanceSharedPtrConstIterator inInstanceSharedPtrConstBegin, InstanceSharedPtrConstIterator inInstanceSharedPtrConstEnd, NetSharedPtr inNetPtr)
Generate net connectivity type based on module boundary.
Net::InstancePinSharedPtrIterator InstancePinSharedPtrIterator
Imported type.
boost::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
Definition: Module.hpp:114
ENetConnectivity
Net connectivity with respect to module instance, either not connected to module, internal to module...
std::vector< InstancePinSharedPtr > InstancePinSharedPtrVector
Vector of InstancePin shared pointers.
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
static InstanceSharedPtr newInstancePtr(const string &inName, const string &inType, const string &inTile, const string &inSite, EInstanceBonding inBonding=eInstanceBondingUnknown, InstanceReferenceSharedPtr inInstanceReferencePtr=InstanceReferenceSharedPtr())
Construct and return a new Instance shared pointer.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
static InstancePinSharedPtr newInstancePinPtr(InstanceSharedPtr inInstancePtr, const string &inPinName)
Construct and return a new InstancePin shared pointer.
static ModuleSharedPtr newModulePtr(const string &inName, const string &inAnchor)
Create and return a new Module shared pointer.
Design::InstanceSharedPtrConstIterator InstanceSharedPtrConstIterator
Imported type.
static const string sPortIndexSeparator
Port index separator.
boost::shared_ptr< InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.

+ Here is the caller graph for this function:

string torc::physical::ModuleTransformer::sanitizePinName ( string  inPinName)
inlineprivate

Sanitize a pin name.

Parameters
inPinNameThe pin name to be sanitized.

Definition at line 840 of file ModuleTransformer.hpp.

840  {
841 
842  // Sanitized pin name
843  string sanitizedPinName;
844 
845  // Iterate over all characters in inString
846  for(u_int32_t i = 0; i < inPinName.length(); i++) {
847 
848  // Match character against valid characters
849  if(boost::regex_match(inPinName.substr(i, 1), sValidPinNameCharactersRegEx)) {
850  sanitizedPinName += inPinName.substr(i, 1);
851  }
852  }
853 
854  // Make sure sanitizedPinName does not start with an invalid first character
855  while(sanitizedPinName.size() > 0 && boost::regex_match(sanitizedPinName.substr(0, 1),
857 
858  // Remove invalid character
859  sanitizedPinName = sanitizedPinName.substr(1, sanitizedPinName.size() - 1);
860 
861  }
862 
863  // Return sanitizedPinName
864  return sanitizedPinName;
865  }
static const boost::regex sValidPinNameCharactersRegEx
Valid characters in a pin name.
static const boost::regex sInvalidPinNameFirstCharactersRegEx
Invalid first characters in a pin name.

Field Documentation

DesignSharedPtr torc::physical::ModuleTransformer::mDesignPtr
protected

Design pointer.

Definition at line 56 of file ModuleTransformer.hpp.

const std::string torc::physical::ModuleTransformer::sHierarchySeparator = "/"
staticprotected

Hierarchy separator.

Definition at line 58 of file ModuleTransformer.hpp.

const boost::regex torc::physical::ModuleTransformer::sInvalidPinNameFirstCharactersRegEx
staticprotected

Invalid first characters in a pin name.

Definition at line 64 of file ModuleTransformer.hpp.

const std::string torc::physical::ModuleTransformer::sPortIndexSeparator = "_"
staticprotected

Port index separator.

Definition at line 60 of file ModuleTransformer.hpp.

const boost::regex torc::physical::ModuleTransformer::sValidPinNameCharactersRegEx
staticprotected

Valid characters in a pin name.

Definition at line 62 of file ModuleTransformer.hpp.


The documentation for this class was generated from the following files: