Hurricane VLSI Database


Query.h
1 // -*- C++ -*-
2 //
3 // Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
4 //
5 // This file is part of Hurricane.
6 //
7 // Hurricane is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
11 //
12 // Hurricane is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-
14 // TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the Lesser GNU General Public
18 // License along with Hurricane. If not, see
19 // <http://www.gnu.org/licenses/>.
20 //
21 // +-----------------------------------------------------------------+
22 // | H U R R I C A N E |
23 // | V L S I B a c k e n d D a t a - B a s e |
24 // | |
25 // | Author : Jean-Paul CHAPUT |
26 // | E-mail : Jean-Paul.Chaput@lip6.fr |
27 // | =============================================================== |
28 // | C++ Header : "./hurricane/Query.h" |
29 // +-----------------------------------------------------------------+
30 
31 
32 #pragma once
33 #include <vector>
34 #include <iomanip>
35 #include "hurricane/Commons.h"
36 #include "hurricane/Box.h"
37 #include "hurricane/Transformation.h"
38 #include "hurricane/Cell.h"
39 #include "hurricane/Instance.h"
40 
41 
42 namespace Hurricane {
43 
44  class BasicLayer;
45  class Go;
46  class QueryStack;
47 
48 
49 // -------------------------------------------------------------------
50 // Slave Class : "QueryState".
51 
52  class QueryState {
53  private:
54  inline QueryState ( Locator<Instance*>* locator );
55  inline QueryState ( Locator<Instance*>* locator
56  , const Box& area
57  , const Transformation& transformation
58  , const Path& path
59  );
60  QueryState ( const QueryState& );
61  QueryState& operator= ( const QueryState& );
62  inline ~QueryState ();
63  private:
64  Locator<Instance*>* _locator;
65  Box _area;
66  Transformation _transformation;
67  Path _path;
68 
69  friend class QueryStack;
70  };
71 
72 
73 // QueryState Inline Functions.
74 
75 
76  inline QueryState::QueryState ( Locator<Instance*>* locator )
77  : _locator (locator)
78  , _area ()
79  , _transformation()
80  , _path ()
81  { }
82 
83 
84  inline QueryState::QueryState ( Locator<Instance*>* locator
85  , const Box& area
86  , const Transformation& transformation
87  , const Path& path
88  )
89  : _locator (locator)
90  , _area (area)
91  , _transformation(transformation)
92  , _path (path)
93  { }
94 
95 
96  inline QueryState::~QueryState ()
97  {
98  if ( _locator ) delete _locator;
99  }
100 
101 
102 // -------------------------------------------------------------------
103 // Class : "QueryStack".
104 
105 
106  class QueryStack : public vector<QueryState*> {
107  public:
108  // Constructor & destructor.
109  QueryStack ();
110  ~QueryStack ();
111  // Accessors.
112  inline Cell* getTopCell ();
113  inline const Box& getTopArea () const;
114  inline const Transformation& getTopTransformation () const;
115  inline unsigned int getStartLevel () const;
116  inline unsigned int getStopLevel () const;
117  inline Cell::Flags getStopCellFlags () const;
118  inline Cell* getMasterCell ();
119  inline Instance* getInstance ();
120  inline const Box& getArea () const;
121  inline DbU::Unit getThreshold () const;
122  inline const Transformation& getTransformation () const;
123  inline const Path& getPath () const;
124  //inline const Tabulation& getTab () const;
125  // Modifiers.
126  inline void setTopCell ( Cell* cell );
127  inline void setTopArea ( const Box& area );
128  inline void setTopTransformation ( const Transformation& transformation );
129  inline void setThreshold ( DbU::Unit threshold );
130  inline void setStartLevel ( unsigned int level );
131  inline void setStopLevel ( unsigned int level );
132  inline void setStopCellFlags ( Cell::Flags );
133  inline void init ();
134  inline void updateTransformation ();
135  inline bool levelDown ();
136  inline void levelUp ();
137  inline void levelProgress ();
138  inline bool levelCompleted ();
139  inline void progress ( bool init=false );
140  inline size_t getInstanceCount () const;
141 
142  protected:
143  // Internal: Attributes.
144  // Tabulation _tab;
145  Cell* _topCell;
146  Box _topArea;
147  DbU::Unit _threshold;
148  Transformation _topTransformation;
149  unsigned int _startLevel;
150  unsigned int _stopLevel;
151  Cell::Flags _stopCellFlags;
152  size_t _instanceCount;
153 
154  private:
155  // Internal: Constructors.
156  QueryStack ( const QueryStack& );
157  QueryStack& operator= ( const QueryStack& );
158  };
159 
160 
161 // QueryStack Inline Functions.
162 
163 
164  inline Cell* QueryStack::getTopCell () { return _topCell; }
165  inline const Box& QueryStack::getTopArea () const { return _topArea; }
166  inline const Transformation& QueryStack::getTopTransformation () const { return _topTransformation; }
167  inline DbU::Unit QueryStack::getThreshold () const { return _threshold; }
168  inline unsigned int QueryStack::getStartLevel () const { return _startLevel; }
169  inline unsigned int QueryStack::getStopLevel () const { return _stopLevel; }
170  inline Cell::Flags QueryStack::getStopCellFlags () const { return _stopCellFlags; }
171  inline const Box& QueryStack::getArea () const { return back()->_area; }
172  inline const Transformation& QueryStack::getTransformation () const { return back()->_transformation; }
173  inline const Path& QueryStack::getPath () const { return back()->_path; }
174 //inline const Tabulation& QueryStack::getTab () const { return _tab; }
175  inline size_t QueryStack::getInstanceCount () const { return _instanceCount; }
176 
177 
178  inline Instance* QueryStack::getInstance ()
179  {
180  if ( levelCompleted() ) return NULL;
181  return back()->_locator->getElement();
182  }
183 
184 
185  inline Cell* QueryStack::getMasterCell ()
186  {
187  if ( size() == 1 ) return _topCell;
188  if ( !getInstance() ) return NULL;
189  return getInstance()->getMasterCell();
190  }
191 
192 
193  inline void QueryStack::setTopCell ( Cell* cell ) { _topCell = cell; }
194  inline void QueryStack::setTopArea ( const Box& area ) { _topArea = area; }
195  inline void QueryStack::setTopTransformation ( const Transformation& transformation ) { _topTransformation = transformation; }
196  inline void QueryStack::setThreshold ( DbU::Unit threshold ) { _threshold = threshold; }
197  inline void QueryStack::setStartLevel ( unsigned int level ) { _startLevel = level; }
198  inline void QueryStack::setStopLevel ( unsigned int level ) { _stopLevel = level; }
199  inline void QueryStack::setStopCellFlags ( Cell::Flags flags ) { _stopCellFlags = flags; }
200 
201 
202  inline void QueryStack::init ()
203  {
204  _instanceCount = 0;
205  while (not empty()) levelUp();
206 
207  push_back( new QueryState(NULL,_topArea,_topTransformation,Path()) );
208  //_tab++;
209 
210  progress( true );
211  }
212 
213 
214  inline void QueryStack::updateTransformation ()
215  {
216  QueryState* child = *(rbegin() );
217  QueryState* parent = *(rbegin()+1);
218  Instance* instance = child->_locator->getElement();
219 
220  //cerr << "Processing " << instance << endl;
221 
222  child->_area = parent->_area;
223  child->_transformation = instance->getTransformation ();
224 
225  instance->getTransformation().getInvert().applyOn ( child->_area );
226  parent->_transformation.applyOn ( child->_transformation );
227 
228  //child->_path = Path ( Path(parent->_path,instance->getCell()->getShuntedPath()) , instance );
229  child->_path = Path ( parent->_path, instance );
230  //cerr << "QueryStack::updateTransformation() " << child->_path << endl;
231  }
232 
233 
234  inline bool QueryStack::levelDown ()
235  {
236  if (size() > _stopLevel) return false;
237  if (getMasterCell()->getFlags().isset(_stopCellFlags)) return false;
238 
239  //cerr << "QueryStack::levelDown(): t:" << DbU::getValueString(getThreshold()) << endl;
240  Locator<Instance*>* locator =
241  getMasterCell()->getInstancesUnder(getArea(),getThreshold()).getLocator();
242 
243  if ( locator->isValid() ) {
244  push_back ( new QueryState ( locator ) );
245 
246  updateTransformation ();
247  //_tab++;
248 
249  return true;
250  } else
251  delete locator;
252 
253  //cerr << " Aborting level down" << endl;
254  return false;
255  }
256 
257 
258  inline void QueryStack::levelUp ()
259  {
260  delete back ();
261  pop_back ();
262  //_tab--;
263  }
264 
265 
266  inline bool QueryStack::levelCompleted ()
267  {
268  if ( !back()->_locator || !back()->_locator->isValid () ) return true;
269  return false;
270  }
271 
272 
273  inline void QueryStack::levelProgress ()
274  {
275  if (levelCompleted()) return;
276 
277  back()->_locator->progress();
278  if (not back()->_locator->isValid()) return;
279 
280  //cerr << " stack:" << std::setw(3) << _instanceCount << ":" << getPath() << endl;
281  ++_instanceCount;
282  updateTransformation();
283  }
284 
285 
286  inline void QueryStack::progress ( bool init )
287  {
288  if (not init) levelProgress ();
289  else {
290  if (not levelDown() and (size() > _startLevel))
291  return;
292  }
293 
294  while (not empty()) {
295  if (levelCompleted()) {
296  levelUp ();
297  } else {
298  if (levelDown()) continue;
299  }
300 
301  if (size() > _startLevel) return;
302  if (empty()) break;
303  levelProgress();
304  }
305  }
306 
307 
308 // -------------------------------------------------------------------
309 // Class : "Query".
310 
311  class Query {
312  public:
313  typedef Hurricane::Mask<int> Mask;
314  public:
315  // Types.
316  enum QueryFilter { DoMasterCells = 1
317  , DoTerminalCells = 2
318  , DoComponents = 4
319  , DoMarkers = 8
320  , DoRubbers = 16
321  , DoExtensionGos = 32
322  , DoAll = DoMasterCells
323  | DoTerminalCells
324  | DoComponents
325  | DoMarkers
326  | DoRubbers
327  | DoExtensionGos
328  };
329  public:
330  // Constructors & Destructors.
331  Query ();
332  virtual ~Query ();
333  // Accessors.
334  inline unsigned int getStartLevel () const;
335  inline unsigned int getStopLevel () const;
336  inline Cell::Flags getStopCellFlags () const;
337  inline size_t getDepth () const;
338  inline const Transformation& getTransformation () const;
339  inline const Box& getArea () const;
340  inline DbU::Unit getThreshold () const;
341  inline const BasicLayer* getBasicLayer () const;
342  inline Cell* getMasterCell ();
343  inline Instance* getInstance ();
344  inline Path getPath () const;
345  //inline const Tabulation& getTab () const;
346  virtual bool hasGoCallback () const;
347  virtual bool hasMarkerCallback () const;
348  virtual bool hasRubberCallback () const;
349  virtual bool hasExtensionGoCallback () const;
350  virtual bool hasMasterCellCallback () const;
351  virtual void goCallback ( Go* ) = 0;
352  virtual void markerCallback ( Marker* );
353  virtual void rubberCallback ( Rubber* );
354  virtual void extensionGoCallback ( Go* ) = 0;
355  virtual void masterCellCallback () = 0;
356  // Modifiers.
357  void setQuery ( Cell* cell
358  , const Box& area
359  , const Transformation& transformation
360  , const BasicLayer* basicLayer
361  , ExtensionSlice::Mask extensionMask
362  , Mask filter
363  , DbU::Unit threshold=0
364  );
365  inline void setCell ( Cell* cell );
366  inline void setArea ( const Box& area );
367  inline void setThreshold ( DbU::Unit threshold );
368  inline void setTransformation ( const Transformation& transformation );
369  virtual void setBasicLayer ( const BasicLayer* basicLayer );
370  inline void setExtensionMask ( ExtensionSlice::Mask mode );
371  inline void setFilter ( Mask mode );
372  inline void setStartLevel ( unsigned int level );
373  inline void setStopLevel ( unsigned int level );
374  inline void setStopCellFlags ( Cell::Flags );
375  virtual void doQuery ();
376 
377  protected:
378  // Internal: Attributes.
379  QueryStack _stack;
380  const BasicLayer* _basicLayer;
381  ExtensionSlice::Mask _extensionMask;
382  Mask _filter;
383  };
384 
385 
386 // Query Inline Functions.
387 
388  inline void Query::setCell ( Cell* cell ) { _stack.setTopCell(cell); }
389  inline void Query::setArea ( const Box& area ) { _stack.setTopArea(area); }
390  inline void Query::setThreshold ( DbU::Unit threshold ) { _stack.setThreshold(threshold); }
391  inline void Query::setTransformation ( const Transformation& transformation ) { _stack.setTopTransformation(transformation); }
392  inline void Query::setFilter ( Mask filter ) { _filter = filter; }
393  inline void Query::setExtensionMask ( ExtensionSlice::Mask mask ) { _extensionMask = mask; }
394  inline void Query::setStartLevel ( unsigned int level ) { _stack.setStartLevel(level); }
395  inline void Query::setStopLevel ( unsigned int level ) { _stack.setStopLevel(level); }
396  inline void Query::setStopCellFlags ( Cell::Flags flags ) { _stack.setStopCellFlags(flags); }
397 
398  inline unsigned int Query::getStartLevel () const { return _stack.getStartLevel(); }
399  inline unsigned int Query::getStopLevel () const { return _stack.getStopLevel(); }
400  inline Cell::Flags Query::getStopCellFlags () const { return _stack.getStopCellFlags(); }
401  inline size_t Query::getDepth () const { return _stack.size(); }
402  inline const Box& Query::getArea () const { return _stack.getArea(); }
403  inline const Transformation& Query::getTransformation () const { return _stack.getTransformation(); }
404  inline Path Query::getPath () const { return _stack.getPath(); }
405  inline const BasicLayer* Query::getBasicLayer () const { return _basicLayer; }
406  inline Cell* Query::getMasterCell () { return _stack.getMasterCell(); }
407  inline Instance* Query::getInstance () { return _stack.getInstance(); }
408 //inline const Tabulation& Query::getTab () const { return _stack.getTab(); }
409 
410 
411 } // Hurricane namespace.
BasicLayer description (API)
Definition: BasicLayer.h:44
Box description (API)
Definition: Box.h:31
The model (API).
Definition: Cell.h:64
std::int64_t Unit
Definition: DbU.h:67
Go description (API)
Definition: Go.h:34
Instance description (API)
Definition: Instance.h:35
Path description (API)
Definition: Path.h:35
Query description (API)
Definition: Query.h:311
QueryFilter
Definition: Query.h:316
virtual void doQuery()
virtual void markerCallback(Marker *)
virtual bool hasMarkerCallback() const
virtual void goCallback(Go *)=0
virtual bool hasRubberCallback() const
void setQuery(Cell *cell, const Box &area, const Transformation &transformation, const BasicLayer *basicLayer, ExtensionSlice::Mask extensionMask, Mask filter, DbU::Unit threshold=0)
virtual void extensionGoCallback(Go *)=0
virtual bool hasMasterCellCallback() const
virtual void masterCellCallback()=0
virtual bool hasExtensionGoCallback() const
virtual void setBasicLayer(const BasicLayer *basicLayer)
virtual ~Query()
virtual void rubberCallback(Rubber *)
virtual bool hasGoCallback() const
Rubber description (API)
Definition: Rubber.h:36
Transformation description (API)
Definition: Transformation.h:32
Transformation getTransformation(const Transformation &transformation) const
The namespace dedicated to Hurricane.
Definition: Generalities.dox:5


Generated by doxygen 1.9.1 on Thu Aug 11 2022 Return to top of page
Hurricane VLSI Database Copyright © 2000-2020 Bull S.A. All rights reserved