00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef TORC_PLACER_PLACERNETLIST_HPP
00020 #define TORC_PLACER_PLACERNETLIST_HPP
00021
00022
00023
00024 #include "torc/physical/Design.hpp"
00025 #include "torc/placer/NetlistInstance.hpp"
00026 #include "torc/placer/NetlistNet.hpp"
00027 #include "torc/placer/NetlistPin.hpp"
00028 #include "torc/placer/DeviceWrapper.hpp"
00029 #include <map>
00030 #include <vector>
00031
00032 namespace torc {
00033 namespace placer {
00034 class PlacerNetlist {
00035
00036 typedef physical::DesignSharedPtr DesignSharedPtr;
00037 typedef physical::InstanceSharedPtr InstanceSharedPtr;
00038 typedef physical::InstanceSharedPtrVector InstanceSharedPtrVector;
00039 typedef physical::Circuit::InstanceSharedPtrConstIterator InstanceSharedPtrConstIterator;
00040 typedef physical::Circuit::NetSharedPtrConstIterator NetSharedPtrConstIterator;
00041 typedef physical::Net::InstancePinSharedPtrConstIterator InstancePinSharedPtrConstIterator;
00042 typedef physical::ENetType ENetType;
00043 typedef boost::uint32_t uint32;
00044 protected:
00045
00046 DesignSharedPtr mDesign;
00047 DeviceWrapper& mDevice;
00048
00049 std::vector<NetlistInstance*> mInstances;
00050 std::vector<NetlistNet*> mNets;
00051 std::vector<NetlistPin*> mPins;
00052
00053 std::vector<std::vector<NetlistInstance*> > mInstancesByType;
00054
00055
00056 std::map<std::string, uint32> mInstanceLookup;
00057 std::map<std::string, uint32> mNetLookup;
00058
00059
00060
00061
00062 public:
00063 PlacerNetlist(DesignSharedPtr inDesign, DeviceWrapper& inDevice)
00064 : mDesign(inDesign), mDevice(inDevice) {
00065
00066
00067
00068
00069 InstanceSharedPtrConstIterator p = inDesign->instancesBegin();
00070 InstanceSharedPtrConstIterator e = inDesign->instancesEnd();
00071 for ( ; p != e; p++) {
00072
00073
00074 addInstance(*p);
00075 }
00076
00077 NetSharedPtrConstIterator q = inDesign->netsBegin();
00078 NetSharedPtrConstIterator f = inDesign->netsEnd();
00079 for ( ; q != f; q++) {
00080 const std::string& netName = (*q)->getName();
00081
00082 addNet(netName, (*q)->getNetType());
00083
00084 InstancePinSharedPtrConstIterator r;
00085 InstancePinSharedPtrConstIterator g;
00086 r = (*q)->sourcesBegin();
00087 g = (*q)->sourcesEnd();
00088 for ( ; r != g; r++) {
00089 InstanceSharedPtr instance = (*r)->getInstancePtr().lock();
00090 addNetTerminal(netName, instance->getName(), (*r)->getPinName(), true);
00091 }
00092 r = (*q)->sinksBegin();
00093 g = (*q)->sinksEnd();
00094 for ( ; r != g; r++) {
00095 InstanceSharedPtr instance = (*r)->getInstancePtr().lock();
00096 addNetTerminal(netName, instance->getName(), (*r)->getPinName(), false);
00097 }
00098 }
00099 }
00100 ~PlacerNetlist() {}
00101 void printInstances() {
00102 std::cout << "### PlacerNetlist Instances ###" << std::endl;
00103 std::vector<NetlistInstance*>::iterator p = mInstances.begin();
00104 std::vector<NetlistInstance*>::iterator e = mInstances.end();
00105 for ( ; p != e; p++) {
00106 std::cout << (*p)->getInstance()->getName() << " : "
00107 << (*p)->getInstance()->getType() << " ";
00108 if ((*p)->getSite() == NULL)
00109 std::cout << "UNPLACED!!!" << std::endl;
00110 else
00111 std::cout << (*p)->getSite()->getName() << std::endl;
00112 }
00113 }
00114 uint32 getInstanceType(std::string& inType) {
00115 throw "getInstanceType(string) not used";
00116
00117
00118 return 0;
00119 }
00120
00121 uint32 addInstance(InstanceSharedPtr inInstance) {
00122 uint32 index = mInstances.size();
00123
00124 mInstanceLookup.insert(std::pair<std::string, uint32>(inInstance->getName(), index));
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 NetlistInstance* instance = new NetlistInstance(inInstance,
00136 mDevice.mTypeMapping.getTypeIndex(inInstance->getType()));
00137 mInstances.push_back(instance);
00138
00139
00140 return index;
00141
00142 }
00143 uint32 addNet(std::string inName, ENetType inType) {
00144 uint32 index = mNets.size();
00145 mNets.push_back(new NetlistNet(inName, inType, index));
00146 mNetLookup.insert(std::pair<std::string, uint32>(inName, index));
00147 return index;
00148 }
00149 uint32 addNetTerminal(std::string inNetName, std::string inInstanceName, std::string inPortName, bool isNetSource) {
00150 NetlistPin* pin = new NetlistPin(inPortName, isNetSource);
00151 NetlistNet* net = getNet(inNetName);
00152 NetlistInstance* instance = getInstance(inInstanceName);
00153 mPins.push_back(pin);
00154 pin->setInstance(instance);
00155 pin->setNet(net);
00156 instance->addPin(pin);
00157 if (isNetSource) {
00158 return net->addSource(pin);
00159 } else {
00160 return net->addSink(pin);
00161 }
00162 if (pin->getInstance() == NULL) {
00163 std::cout << "BAD PIN DEFINITION!!! " << pin->getName() << " " << net->getName() << std::endl;
00164 }
00165 }
00166
00167 NetlistInstance* getInstance(std::string inName) {
00168 return mInstances[mInstanceLookup[inName]];
00169 }
00170 NetlistInstance* getInstance(uint32 i) {
00171 return mInstances[i];
00172 }
00173 NetlistInstance* getInstance(uint32 type, uint32 index) {
00174 return mInstancesByType[type][index];
00175 }
00176
00177 NetlistNet* getNet(std::string inName) {
00178 return mNets[mNetLookup[inName]];
00179 }
00180 NetlistNet* getNet(uint32 i) {
00181 return mNets[i];
00182 }
00183 uint32 getNumNets() {
00184 return mNets.size();
00185 }
00186 uint32 getNumInstances() {
00187 return mInstances.size();
00188 }
00189 uint32 getNumInstancesByType(uint32 type) {
00190 if (type >= mInstancesByType.size()) {
00191 return -1;
00192 }
00193 return mInstancesByType[type].size();
00194 }
00195 uint32 getNumTypes() {
00196 return mInstancesByType.size();
00197 }
00198 void print() {
00199 std::cout << "### INSTANCES ###" << std::endl;
00200 for (uint32 i = 0; i < mInstances.size(); i++) {
00201 NetlistInstance* instance = mInstances[i];
00202 std::cout << "\t" << instance->getInstance()->getName()
00203 << " type: " << instance->getType() << std::endl;
00204 for (uint32 j = 0; j < instance->getNumPins(); j++) {
00205 NetlistPin* pin = instance->getPin(j);
00206 std::cout << "\t\tpin: " << pin->getName() << std::endl;
00207 }
00208 }
00209 std::cout << "### NETS ###" << std::endl;
00210 for (uint32 i = 0; i < mNets.size(); i++) {
00211 NetlistNet* net = mNets[i];
00212 std::cout << "\t" << net->getName() << " type: " << net->getType() << std::endl;
00213 for (uint32 j = 0; j < net->getNumSources(); j++) {
00214 NetlistPin* pin = net->getSource(j);
00215 std::cout << "\t\tsource: " << pin->getInstance()->getInstance()->getName() << " pin " << pin->getName() << std::endl;
00216 }
00217 for (uint32 j = 0; j < net->getNumSinks(); j++) {
00218 NetlistPin* pin = net->getSink(j);
00219 std::cout << "\t\tsink: " << pin->getInstance()->getInstance()->getName() << " pin " << pin->getName() << std::endl;
00220 }
00221 }
00222
00223 }
00224 void temporaryPrune() {
00225 std::vector<NetlistNet*> newNets;
00226 for (uint32 i = 0; i < mNets.size(); i++) {
00227
00228 NetlistNet* net = mNets[i];
00229 NetlistPin* pin;
00230 bool killnet = false;
00231
00232 for (uint32 j = 0; j < net->getNumSources(); j++) {
00233 pin = net->getSource(j);
00234
00235
00236
00237
00238
00239 }
00240 for (uint32 j = 0; j < net->getNumSinks(); j++) {
00241 pin = net->getSink(j);
00242
00243
00244
00245
00246
00247
00248 }
00249 if (!killnet) {
00250 newNets.push_back(net);
00251 } else {
00252 std::cout << "KILL NET: " << net->getName() << std::endl;
00253 }
00254 }
00255 std::cout << "PRUNE: " << mNets.size() << " " << newNets.size() << std::endl;
00256 mNets.clear();
00257 for (uint32 i = 0; i < newNets.size(); i++) {
00258 mNets.push_back(newNets[i]);
00259 }
00260 }
00261 };
00262 }
00263 }
00264 #endif // TORC_PLACER_PLACERNETLIST_HPP