1 2 // This file is part of the Alliance Project. 3 // Copyright (C) Laboratoire LIP6 - Departement ASIM 4 // Universite Pierre et Marie Curie 5 // 6 // The Alliance Project is free software; you can redistribute it and/or 7 // modify it under the terms of the GNU General Public License as 8 // published by the Free Software Foundation; either version 2 of the 9 // License, or (at your option) any later version. 10 // 11 // The Alliance Project is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 // General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with the Alliance Project; if not, write to the Free Software 18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 // 20 // 21 // License-Tag 22 // 23 // Date : 29/01/2004 24 // Author : Christophe Alexandre <Christophe.Alexandre@lip6.fr> 25 // 26 // Authors-Tag 27 #ifndef __PPLACEMENT_H 28 #define __PPLACEMENT_H 29 30 #include <iostream> 31 #include <fstream> 32 #include <vector> 33 #include <map> 34 #include <unordered_map> 35 36 using namespace std; 37 38 #include "mut.h" 39 #include "mlo.h" 40 41 #include "PToPlaceIns.h" 42 #include "PFixedIns.h" 43 #include "PCon.h" 44 #include "PONet.h" 45 #include "PBBox.h" 46 #include "PDetSubRow.h" 47 #include "iocheader.h" 48 49 struct eqstr 50 { operatoreqstr51 inline size_t operator()(const char *s) const 52 { 53 size_t hash = 1; 54 for (; *s; ++s) hash = hash * 5 + *s; 55 return hash; 56 } 57 operatoreqstr58 inline bool operator()(const char* s1, const char* s2) const 59 { 60 return strcmp(s1, s2) == 0; 61 } 62 }; 63 64 class PPlacement { 65 public: 66 typedef vector<PRow*> PRows; 67 typedef vector<PONet*> PONets; 68 typedef vector<PToPlaceIns*> PToPlaceInss; 69 typedef vector<PFixedIns*> PFixedInss; 70 typedef vector<PCon*> PCons; 71 typedef vector <bool> PrePlaceRow; 72 typedef vector<PrePlaceRow> PrePlaceTab; 73 typedef vector<PDetSubRow*> PDetSubRows; 74 75 private: 76 typedef map< double, unsigned, less<double> > PRowsYMax; 77 typedef map< double, unsigned, greater<double> > PRowsYMinInv; 78 typedef unordered_map<long, PONet*> PNetMap; 79 typedef unordered_map<const char*, PIns*, eqstr, eqstr> PInsMap; 80 typedef unordered_map<const char*, PCon*, eqstr, eqstr> PConMap; 81 typedef unordered_map<const char*, locon*, eqstr, eqstr> PLoconMap; 82 typedef unordered_map<const char*, int, eqstr, eqstr> PFixedMap; 83 typedef unordered_map<const char*, PDetToPlaceIns*, eqstr, eqstr> PDetInsMap; 84 85 PBBox BBox; 86 int _dx; 87 int _dy; 88 89 lofig* _fig; 90 phfig* _prePlaceFig; 91 PToPlaceInss _toPlaceInss; 92 PFixedInss _fixedInss; 93 PCons _cons; 94 PONets _nets; 95 PRows _rows; 96 PRowsYMax _rowsYMax; 97 PRowsYMinInv _rowsYMinInv; 98 // placement detaille 99 PDetSubRows _detSubRows; 100 double _detInitNetCost; 101 102 bool _rowZeroOrientation; 103 104 double _initNetCost; 105 double _initRowCost; 106 double _initBinCost; 107 108 // parametres 109 double _margin; 110 double _realMargin; 111 int _maxDetLoop; // Maximum nb of loops for detailed placement 112 double RowMult; 113 double BinMult; 114 double NetMult; 115 bool _placeCons; 116 bool _ringPlaceCons; 117 con_list* _PtList; 118 bool _iocFile; 119 char* _iocFileName; 120 bool _boolPlot; 121 bool _verbose; 122 bool _prePlace; 123 bool _eqMargin; 124 unsigned _totalMoves; 125 unsigned _sourceEqualTargetMovementNumber; 126 unsigned _surOccupationTargetMovementNumber; 127 unsigned _impossibleExchangeMovementNumber; 128 unsigned _acceptedMoveNumber; 129 unsigned _acceptedExchangeNumber; 130 unsigned _rejectedMoveNumber; 131 unsigned _rejectedExchangeNumber; 132 133 // Placement caracteristics 134 char* _fileName; 135 unsigned _elems; 136 unsigned _nIns; 137 unsigned _nInsToPlace; 138 double _binsWidth; 139 double _binsCapa; 140 double _binsMinWidth; 141 double _binsMaxWidth; 142 double _sumToPlaceInssWidth; 143 double _biggestToPlaceInsWidth; 144 145 void Init(lofig* cell, int NbRows); 146 double GetRowCost(); 147 double GetBinCost(); 148 double GetNetCost(); 149 double GetCost(double RowCost, double BinCost, double NetCost); 150 void PlaceGlobal(); 151 void PlaceFinal(); 152 153 public: PPlacement(bool conflg,bool ringflg,double rowmult,double binmult,double netmult,bool iocfile,char * iocfilename,bool plotflg,bool verbose,bool preflg,bool eqmargin,struct phfig * physfig,char * filename)154 PPlacement(bool conflg, bool ringflg, double rowmult, double binmult, double netmult, 155 bool iocfile, char *iocfilename, bool plotflg, 156 bool verbose, bool preflg, bool eqmargin, 157 struct phfig* physfig, 158 char* filename) 159 : _dx (0) 160 , _dy (0) 161 , _fig (NULL) 162 , _prePlaceFig (physfig) 163 , _detInitNetCost (0.0) 164 , _rowZeroOrientation (false) 165 , _initNetCost (0.0) 166 , _initRowCost (0.0) 167 , _initBinCost (0.0) 168 , _margin (0.0) 169 , _realMargin (0.0) 170 , _maxDetLoop (0) 171 , RowMult (rowmult) 172 , BinMult (binmult) 173 , NetMult (netmult) 174 , _placeCons (conflg) 175 , _ringPlaceCons (ringflg) 176 , _PtList (NULL) 177 , _iocFile (iocfile) 178 , _iocFileName (iocfilename) 179 , _boolPlot (plotflg) 180 , _verbose (verbose) 181 , _prePlace (preflg) 182 , _eqMargin (eqmargin) 183 , _totalMoves (0) 184 , _sourceEqualTargetMovementNumber (0) 185 , _surOccupationTargetMovementNumber(0) 186 , _impossibleExchangeMovementNumber (0) 187 , _acceptedMoveNumber (0) 188 , _acceptedExchangeNumber (0) 189 , _rejectedMoveNumber (0) 190 , _rejectedExchangeNumber (0) 191 , _fileName (filename) 192 , _elems (0) 193 , _nIns (0) 194 , _nInsToPlace (0) 195 , _binsWidth (0.0) 196 , _binsCapa (0.0) 197 , _binsMinWidth (0.0) 198 , _binsMaxWidth (0.0) 199 , _sumToPlaceInssWidth (0.0) 200 , _biggestToPlaceInsWidth (0.0) 201 { } 202 203 ~PPlacement(); 204 SetMargin(const double Value)205 void SetMargin(const double Value) { _margin = Value; } GetMargin()206 double GetMargin() const { return _margin; } SetMaxDetLoop(const int loop)207 void SetMaxDetLoop(const int loop) { _maxDetLoop = loop; } SetRowMult(const double Value)208 void SetRowMult(const double Value) { RowMult = Value; } GetRowMult()209 double GetRowMult() const { return RowMult; } SetBinMult(const double Value)210 void SetBinMult(const double Value) { BinMult = Value; } GetBinMult()211 double GetBinMult() const { return BinMult; } SetNetMult(const double Value)212 void SetNetMult(const double Value) { NetMult = Value; } GetNetMult()213 double GetNetMult() const { return NetMult; } 214 void Place(lofig* cell, int NbRows); 215 216 void PlotAll(const string& output) const; 217 void PlotFinal(const string& output) const; 218 void PlotOnlyInstances(const string& output) const; 219 void PlotStat(); 220 void PlotOnlyBins(const string& output) const; 221 222 double GetBinsSize() const; 223 double GetBinsCapa() const; 224 double GetSubRowsCapa() const; 225 GetMinX()226 double GetMinX() const { return BBox.GetMinX(); } GetMinY()227 double GetMinY() const { return BBox.GetMinY(); } GetMaxX()228 double GetMaxX() const { return BBox.GetMaxX(); } GetMaxY()229 double GetMaxY() const { return BBox.GetMaxY(); } GetWidth()230 double GetWidth() const { return BBox.GetWidth(); } GetHeight()231 double GetHeight() const { return BBox.GetHeight(); } GetNInsToPlace()232 int GetNInsToPlace() const { return _nInsToPlace; } 233 GetBoolPlot()234 bool GetBoolPlot() const { return _boolPlot; } SetBoolPlot(bool value)235 void SetBoolPlot(bool value) { _boolPlot = value; } 236 IncrImpossibleExchangeMovementNumber()237 void IncrImpossibleExchangeMovementNumber() 238 { ++_impossibleExchangeMovementNumber; } IncrSourceEqualTargetMovementNumber()239 void IncrSourceEqualTargetMovementNumber() 240 { ++_sourceEqualTargetMovementNumber; } IncrSurOccupationTargetMovementNumber()241 void IncrSurOccupationTargetMovementNumber() 242 { ++_surOccupationTargetMovementNumber; } IncrAcceptedMoveNumber()243 void IncrAcceptedMoveNumber() 244 { ++_acceptedMoveNumber; } IncrAcceptedExchangeNumber()245 void IncrAcceptedExchangeNumber() 246 { ++_acceptedExchangeNumber; } IncrRejectedMoveNumber()247 void IncrRejectedMoveNumber() 248 { ++_rejectedMoveNumber; } IncrRejectedExchangeNumber()249 void IncrRejectedExchangeNumber() 250 { ++_rejectedExchangeNumber; } 251 252 double GetOccCost() const; 253 void InitBBoxCost(); 254 double TempBBoxCost(); 255 void ParseIocFile(PLoconMap& ploconmap); 256 void SetPosIocFile(PConMap& pconmap); 257 258 PToPlaceIns& GetRandIns(); 259 PRow& GetRow(const PRow* row, const double distance); 260 261 void FinalInitialize(); 262 bool FinalOptimize(); 263 264 ostream& Print(ostream& os) const; 265 266 int Save(); 267 268 // Debug Methods 269 270 double DetPlaceDebugNetCost(); 271 double GlobalPlaceDebugNetCost(); 272 double DebugRowCost(); 273 double DebugBinCost(); 274 275 private: 276 PFixedIns* InsertFixedIns(const loins* ins, const phins* pins, const int dx, const int dy); 277 PToPlaceIns* InsertToPlaceIns(const loins* ins); 278 PCon* InsertCon(const locon* con, phcon* pcon=NULL, int dx=0, int dy=0); 279 PCon* InsertCon(const locon* con, PPos position, const char orientation); 280 PONet* InsertNet(const losig* sig); 281 int AddRowend(struct phfig* physicalfig); 282 double DetPlaceNetCost(); 283 void GenerateConsPlacement(); 284 void GenerateRingConsPlacement(); 285 void InitPlace(int nbrows); 286 void InitPlaceWithPrePlace(); 287 void CreateSubRows(PRow* row, PrePlaceTab& tabpreplace,int coordy, int nbsubrows, int Width); 288 int CheckCreateRow(PrePlaceTab& tabpreplace, int coordy, int Width); 289 void PlotInstances(ofstream& out) const; 290 }; 291 292 static inline ostream& operator<<(ostream& os, const PPlacement& placement) 293 { 294 return placement.Print(os); 295 } 296 297 static inline ostream& operator<<(ostream& os, const PPlacement* placement) 298 { 299 return placement ? placement->Print(os) : os << "(nil)"; 300 } 301 302 #endif /* __PPLACEMENT_H */ 303