torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PlacerNetlist.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Header for the PlacerNetlist class.
18 
19 #ifndef TORC_PLACER_PLACERNETLIST_HPP
20 #define TORC_PLACER_PLACERNETLIST_HPP
21 
22 //#include <boost/timer.hpp>
23 //#include <math.h>
24 #include "torc/physical/Design.hpp"
29 #include <map>
30 #include <vector>
31 
32 namespace torc {
33 namespace placer {
34  class PlacerNetlist {
35  // types
43  typedef boost::uint32_t uint32;
44  protected:
45 
48 
49  std::vector<NetlistInstance*> mInstances;
50  std::vector<NetlistNet*> mNets;
51  std::vector<NetlistPin*> mPins; // probably not useful at all
52 
53  std::vector<std::vector<NetlistInstance*> > mInstancesByType;
54 
55  // looks up string name of instance, returns index in the vector
56  std::map<std::string, uint32> mInstanceLookup; // used for construction of the netlist
57  std::map<std::string, uint32> mNetLookup; // used for nothing maybe....
58  //std::map<std::string, int> mInstanceTypeLookup;
59 
60 
61 
62  public:
64  : mDesign(inDesign), mDevice(inDevice) {
65 
66  // populate the netlist with the design information (or at least wrap it)
67 
68 
69  InstanceSharedPtrConstIterator p = inDesign->instancesBegin();
70  InstanceSharedPtrConstIterator e = inDesign->instancesEnd();
71  for ( ; p != e; p++) {
72  //mInstances.push_back(new NetlistInstance(*p,
73  // mDevice.mTypeMapping.getType((*p)->getType())));
74  addInstance(*p);
75  }
76 
77  NetSharedPtrConstIterator q = inDesign->netsBegin();
78  NetSharedPtrConstIterator f = inDesign->netsEnd();
79  for ( ; q != f; q++) {
80  const std::string& netName = (*q)->getName();
81  //mNets.push_back(new NetlistNet((*q)->getName(), (*q)->getNetType(), mNets.size()));
82  addNet(netName, (*q)->getNetType());
83 
86  r = (*q)->sourcesBegin();
87  g = (*q)->sourcesEnd();
88  for ( ; r != g; r++) {
89  InstanceSharedPtr instance = (*r)->getInstancePtr().lock();
90  addNetTerminal(netName, instance->getName(), (*r)->getPinName(), true);
91  }
92  r = (*q)->sinksBegin();
93  g = (*q)->sinksEnd();
94  for ( ; r != g; r++) {
95  InstanceSharedPtr instance = (*r)->getInstancePtr().lock();
96  addNetTerminal(netName, instance->getName(), (*r)->getPinName(), false);
97  }
98  }
99  }
101  void printInstances() {
102  std::cout << "### PlacerNetlist Instances ###" << std::endl;
103  std::vector<NetlistInstance*>::iterator p = mInstances.begin();
104  std::vector<NetlistInstance*>::iterator e = mInstances.end();
105  for ( ; p != e; p++) {
106  std::cout << (*p)->getInstance()->getName() << " : "
107  << (*p)->getInstance()->getType() << " ";
108  if ((*p)->getSite() == NULL)
109  std::cout << "UNPLACED!!!" << std::endl;
110  else
111  std::cout << (*p)->getSite()->getName() << std::endl;
112  }
113  }
115  throw "getInstanceType(string) not used";
116  //std::map<std::string, int>::iterator typeit = mInstanceTypeLookup.find(inType);
117  //return typeit->second;
118  return 0;
119  }
120  //int addInstance(std::string inName, std::string inType, uint32 inIntType) {
122  uint32 index = mInstances.size(); // return index of added instance
123  //mInstanceLookup.insert(std::pair<std::string, uint32>(inName, index));
124  mInstanceLookup.insert(std::pair<std::string, uint32>(inInstance->getName(), index));
125 
126  // put the instance in a type indexed structure
127  // this time, the same as the database!!
128  //if (inIntType >= mInstancesByType.size()) {
129  // for (uint32 i = mInstancesByType.size(); i < inIntType + 1; i++) {
130  // mInstancesByType.push_back(std::vector<NetlistInstance*>());
131  // }
132  //}
133 
134  //NetlistInstance* instance = new NetlistInstance(inName, inType, inIntType);
135  NetlistInstance* instance = new NetlistInstance(inInstance,
136  mDevice.mTypeMapping.getTypeIndex(inInstance->getType()));
137  mInstances.push_back(instance);
138  //mInstancesByType[inIntType].push_back(instance);
139 
140  return index;
141 
142  }
143  uint32 addNet(std::string inName, ENetType inType) {
144  uint32 index = mNets.size(); // returns index of added instance
145  mNets.push_back(new NetlistNet(inName, inType, index));
146  mNetLookup.insert(std::pair<std::string, uint32>(inName, index));
147  return index;
148  }
149  uint32 addNetTerminal(std::string inNetName, std::string inInstanceName, std::string inPortName, bool isNetSource) {
150  NetlistPin* pin = new NetlistPin(inPortName, isNetSource);
151  NetlistNet* net = getNet(inNetName);
152  NetlistInstance* instance = getInstance(inInstanceName);
153  mPins.push_back(pin);
154  pin->setInstance(instance);
155  pin->setNet(net);
156  instance->addPin(pin);
157  if (isNetSource) {
158  return net->addSource(pin);
159  } else {
160  return net->addSink(pin);
161  }
162  if (pin->getInstance() == NULL) {
163  std::cout << "BAD PIN DEFINITION!!! " << pin->getName() << " " << net->getName() << std::endl;
164  }
165  }
166  // instance accessors
168  return mInstances[mInstanceLookup[inName]];
169  }
171  return mInstances[i];
172  }
174  return mInstancesByType[type][index];
175  }
176  // net accessors
178  return mNets[mNetLookup[inName]];
179  }
181  return mNets[i];
182  }
184  return mNets.size();
185  }
187  return mInstances.size();
188  }
190  if (type >= mInstancesByType.size()) {
191  return -1; // does not exist
192  }
193  return mInstancesByType[type].size();
194  }
196  return mInstancesByType.size();
197  }
198  void print() {
199  std::cout << "### INSTANCES ###" << std::endl;
200  for (uint32 i = 0; i < mInstances.size(); i++) {
201  NetlistInstance* instance = mInstances[i];
202  std::cout << "\t" << instance->getInstance()->getName()
203  << " type: " << instance->getType() << std::endl;
204  for (uint32 j = 0; j < instance->getNumPins(); j++) {
205  NetlistPin* pin = instance->getPin(j);
206  std::cout << "\t\tpin: " << pin->getName() << std::endl;
207  }
208  }
209  std::cout << "### NETS ###" << std::endl;
210  for (uint32 i = 0; i < mNets.size(); i++) {
211  NetlistNet* net = mNets[i];
212  std::cout << "\t" << net->getName() << " type: " << net->getType() << std::endl;
213  for (uint32 j = 0; j < net->getNumSources(); j++) {
214  NetlistPin* pin = net->getSource(j);
215  std::cout << "\t\tsource: " << pin->getInstance()->getInstance()->getName() << " pin " << pin->getName() << std::endl;
216  }
217  for (uint32 j = 0; j < net->getNumSinks(); j++) {
218  NetlistPin* pin = net->getSink(j);
219  std::cout << "\t\tsink: " << pin->getInstance()->getInstance()->getName() << " pin " << pin->getName() << std::endl;
220  }
221  }
222 
223  }
224  void temporaryPrune() {
225  std::vector<NetlistNet*> newNets;
226  for (uint32 i = 0; i < mNets.size(); i++) {
227  // if any part of a net is not touching a sliceL, kill it
228  NetlistNet* net = mNets[i];
229  NetlistPin* pin;
230  bool killnet = false;
231  //std::cout << "net: " << net->getName() << std::endl;
232  for (uint32 j = 0; j < net->getNumSources(); j++) {
233  pin = net->getSource(j);
234  //std::cout << "\tsource: " << pin->getInstance()->getName() << " " << pin->getInstance()->getIntType() << std::endl;
235  //if (pin->getInstance()->getInstance()->getIntType() != 46) {
236  // std::cout << "\t\tKILLED" << std::endl;
237  // killnet = true;
238  //}
239  }
240  for (uint32 j = 0; j < net->getNumSinks(); j++) {
241  pin = net->getSink(j);
242  //std::cout << "\tsink: " << pin->getInstance()->getName() << " " << pin->getInstance()->getIntType() << std::endl;
243  //if (pin->getInstance()->getInstance()->getIntType() != 46) {
244  // std::cout << "\t\tKILLED" << std::endl;
245  // killnet = true;
246  //} else {
247  //}
248  }
249  if (!killnet) {
250  newNets.push_back(net);
251  } else {
252  std::cout << "KILL NET: " << net->getName() << std::endl;
253  }
254  }
255  std::cout << "PRUNE: " << mNets.size() << " " << newNets.size() << std::endl;
256  mNets.clear();
257  for (uint32 i = 0; i < newNets.size(); i++) {
258  mNets.push_back(newNets[i]);
259  }
260  }
261  }; //class PlacerNetlist
262 } // namespace placer
263 } // namespace torc
264 #endif // TORC_PLACER_PLACERNETLIST_HPP
NetlistInstance * getInstance(uint32 i)
ENetType
Enumeration of net power types.
physical::ENetType ENetType
std::map< std::string, uint32 > mInstanceLookup
physical::DesignSharedPtr DesignSharedPtr
std::string & getName()
Definition: NetlistPin.hpp:43
std::vector< InstanceSharedPtr > InstanceSharedPtrVector
Vector of Instance shared pointers.
Wrapper of the device database for placing the design.
std::string & getName()
Definition: NetlistNet.hpp:65
std::vector< NetlistInstance * > mInstances
uint32 addSink(NetlistPin *newPin)
Definition: NetlistNet.hpp:48
physical::InstanceSharedPtr InstanceSharedPtr
NetlistInstance * getInstance()
Definition: NetlistPin.hpp:52
std::vector< std::vector< NetlistInstance * > > mInstancesByType
InstanceSharedPtrVector::const_iterator InstanceSharedPtrConstIterator
Constant iterator to Instance shared pointers.
Definition: Circuit.hpp:72
InstanceSharedPtr getInstance()
NetlistPin * getSink(uint32 i)
Definition: NetlistNet.hpp:62
NetlistNet * getNet(std::string inName)
uint32 getInstanceType(std::string &inType)
std::vector< NetlistPin * > mPins
void setInstance(NetlistInstance *inInstance)
Definition: NetlistPin.hpp:46
uint32 addNet(std::string inName, ENetType inType)
std::string string
std::vector< NetlistNet * > mNets
uint32 addNetTerminal(std::string inNetName, std::string inInstanceName, std::string inPortName, bool isNetSource)
Header for the Design class.
NetlistPin * getSource(uint32 i)
Definition: NetlistNet.hpp:59
NetlistInstance * getInstance(std::string inName)
void setNet(NetlistNet *inNet)
Definition: NetlistPin.hpp:49
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
uint32 addInstance(InstanceSharedPtr inInstance)
InstancePinSharedPtrVector::const_iterator InstancePinSharedPtrConstIterator
Constant iterator to InstancePin shared pointer objects.
physical::Circuit::InstanceSharedPtrConstIterator InstanceSharedPtrConstIterator
void addPin(NetlistPin *pin)
NetlistNet * getNet(uint32 i)
NetlistPin * getPin(uint32 index)
physical::Circuit::NetSharedPtrConstIterator NetSharedPtrConstIterator
std::map< std::string, uint32 > mNetLookup
NetlistInstance * getInstance(uint32 type, uint32 index)
uint32 getTypeIndex(const std::string &inType)
Get the type index for a given type name, creates a new entry if not found.
uint32 addSource(NetlistPin *newPin)
Definition: NetlistNet.hpp:43
PlacementSiteTypeMapping & mTypeMapping
uint32 getNumInstancesByType(uint32 type)
Header for the DeviceWrapper class.
physical::Net::InstancePinSharedPtrConstIterator InstancePinSharedPtrConstIterator
NetSharedPtrVector::const_iterator NetSharedPtrConstIterator
Constant iterator to Net shared pointers.
Definition: Circuit.hpp:76
PlacerNetlist(DesignSharedPtr inDesign, DeviceWrapper &inDevice)
physical::InstanceSharedPtrVector InstanceSharedPtrVector