torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WireUsage.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 WireUsage class.
18 
19 #ifndef TORC_ARCHITECTURE_WIREUSAGE_HPP
20 #define TORC_ARCHITECTURE_WIREUSAGE_HPP
21 
25 #include <boost/dynamic_bitset.hpp>
26 
27 namespace torc {
28 namespace architecture {
29 
30  /// \brief Encapsulation the design wire usage.
31  /// \details This class uses a compact bitset representation to very efficiently track the wire
32  /// usage of a design in an entire device. Internal bitset objects are maintained on a
33  /// per-tile basis, and are not allocated until at least one wire in the tile has been
34  /// marked used.
35  class WireUsage {
36  protected:
37  // types
38  typedef boost::dynamic_bitset<> dynamic_bitset; ///< \brief Imported type name.
39  typedef xilinx::TileIndex TileIndex; ///< \brief Imported type name.
40  typedef xilinx::TileCount TileCount; ///< \brief Imported type name.
41  typedef xilinx::TileTypeIndex TileTypeIndex; ///< \brief Imported type name.
42  typedef xilinx::WireIndex WireIndex; ///< \brief Imported type name.
43  // members
44  /// \brief Reference to the database Tiles object.
45  const Tiles& mTiles;
46  /// \brief The number of tiles for which bitsets are allocated.
48  /// \brief The wire usage bitset array.
50  /// \brief The number of bits allocated by the usage bitsets.
51  uint32_t mBitCount;
52  /// \brief The mask of tile bitsets that contain changes.
54  public:
55  // constructors
56  /// \brief Public constructor.
57  WireUsage(const Tiles& inTiles) : mTiles(inTiles), mTileUsageCount(), mBitsets(0),
58  mBitCount(0), mTileDirty(0) {}
59  /// \brief Non-virtual destructor.
60  ~WireUsage(void) {
61  size_t tileCount = mBitsets.getSize();
62  for(TileIndex i; i < tileCount; i++) {
63  if(mBitsets[i] != 0) { delete mBitsets[i]; mBitsets[i] = 0; }
64  }
65  }
66  // functions
67  /// \brief Size the wire usage according to the number of device tiles.
68  void autosize(void) {
69  // release any existing bitsets
70  for(TileCount i; i < mBitsets.getSize(); i++) {
71  if(mBitsets[i] != 0) { delete mBitsets[i]; mBitsets[i] = 0; }
72  mTileDirty.reset(i);
73  }
74  // resize for the new dimensions
75  TileCount tileCount = mTiles.getTileCount();
76  mBitsets.setSize(tileCount);
77  for(TileCount i; i < tileCount; i++) mBitsets[i] = 0;
78  mTileDirty.resize(tileCount);
79  }
80  /// \brief Marks the specified tilewire as being used.
81  void use(const Tilewire& inTilewire) {
82  // extract the tile and wire indexes
83  TileIndex tileIndex = inTilewire.getTileIndex();
84  WireIndex wireIndex = inTilewire.getWireIndex();
85 
86  // look up the appropriate bitset, allocating it if necessary
87  dynamic_bitset* bitset = mBitsets[tileIndex];
88  if(bitset == 0) {
89  // determine how many wires are in this tile
90  const TileInfo& tileInfo = mTiles.getTileInfo(tileIndex);
91  TileTypeIndex tileTypeIndex = tileInfo.getTypeIndex();
92  size_t size = mTiles.getWireInfo(tileTypeIndex).getSize();
93  bitset = mBitsets[tileIndex] = new dynamic_bitset(size);
94  // track the statistics
96  mBitCount += size;
97  }
98 
99  // set the bit and mark the tile dirty
100  bitset->set(wireIndex, true);
101  mTileDirty.set(tileIndex, true);
102  }
103  /// \brief Marks the specified tilewire as being unused.
104  void release(const Tilewire& inTilewire) {
105  // extract the tile and wire indexes
106  TileIndex tileIndex = inTilewire.getTileIndex();
107  WireIndex wireIndex = inTilewire.getWireIndex();
108 
109  // if there is no entry for the tile, the tilewire is already implicitly unused.
110  dynamic_bitset* bitset = mBitsets[tileIndex];
111  if(bitset == 0) return;
112 
113  // otherwise clear the bit and mark the tile dirty
114  bitset->set(wireIndex, false);
115  mTileDirty.set(tileIndex, true);
116  }
117  /// \brief Marks all wires as being unused, without releasing the bitset objects.
118  /// \details This capability allows the tracer to track the wires that it has visited while
119  /// processing a particular net, and then to start again from scratch without incurring
120  /// allocation and construction overheads.
121  void clear(void) {
122  // iterate over all of the tiles
123  size_t tileCount = mBitsets.getSize();
124  for(TileIndex i; i < tileCount; i++) {
125  // skip this tile if it isn't dirty
126  if(!mTileDirty[i]) continue;
127  // mark the tile clean
128  mTileDirty.reset(i);
129  // look up the bitset for this tile
130  dynamic_bitset* bitset = mBitsets[i];
131  // skip tiles without an associated bitset (should never happen for dirty tiles)
132  if(bitset == 0) continue;
133  // clear the entire bitset
134  bitset->reset();
135  }
136  }
137  /// \brief Determines whether the specified tilewire is in use.
138  bool isUsed(const Tilewire& inTilewire) {
139  // extract the tile and wire indexes
140  TileIndex tileIndex = inTilewire.getTileIndex();
141  WireIndex wireIndex = inTilewire.getWireIndex();
142 
143  // if there is no entry for the tile, the tilewire is already implicitly unused.
144  dynamic_bitset* bitset = mBitsets[tileIndex];
145  if(bitset == 0) return false;
146 
147  // otherwise, interrogate the bit
148  return bitset->test(wireIndex);
149  }
150  /// \brief Returns the number of wires in use.
151  uint32_t getWireUsageCount(void) const {
152  uint32_t usageCount = 0;
153  size_t tileCount = mBitsets.getSize();
154  for(TileIndex i; i < tileCount; i++) {
155  /// \todo Question: can we get away with only checking dirty bitsets?
156  //// skip this tile if it isn't dirty
157  //if(!mTileDirty[i]) continue;
158  // look up the bitset for this tile
159  dynamic_bitset* bitset = mBitsets[i];
160  // skip tiles without an associated bitset
161  if(bitset == 0) continue;
162  // clear the entire bitset
163  usageCount += bitset->count();
164  }
165  return usageCount;
166  }
167  // accessors
168  /// \brief Returns the number of tiles that have been touched.
170  /// \brief Returns the number of bits allocated.
171  uint32_t getBitCount(void) const { return mBitCount; }
172  };
173 
174 } // namespace architecture
175 } // namespace torc
176 
177 #endif // TORC_ARCHITECTURE_WIREUSAGE_HPP
const WireIndex & getWireIndex(void) const
Returns the wire index.
Definition: Tilewire.hpp:66
Encapsulation of a tile index in an unsigned 32-bit integer.
xilinx::TileCount TileCount
Imported type name.
Definition: WireUsage.hpp:40
boost::dynamic_bitset dynamic_bitset
Imported type name.
Definition: WireUsage.hpp:38
const Tiles & mTiles
Reference to the database Tiles object.
Definition: WireUsage.hpp:45
const TileInfo & getTileInfo(TileIndex inTileIndex) const
Returns the TileInfo object for the specified tile.
Definition: Tiles.hpp:137
Encapsulation the design wire usage.
Definition: WireUsage.hpp:35
xilinx::TileIndex TileIndex
Imported type name.
Definition: WireUsage.hpp:39
const Array< const WireInfo > & getWireInfo(TileTypeIndex inTileTypeIndex) const
Returns the WireInfo array for the specified tile type.
Definition: Tiles.hpp:140
Encapsulation of a wire index in an unsigned 16-bit integer.
TileCount getTileCount(void) const
Returns the tile count for this device.
Definition: Tiles.hpp:149
uint32_t getWireUsageCount(void) const
Returns the number of wires in use.
Definition: WireUsage.hpp:151
void clear(void)
Marks all wires as being unused, without releasing the bitset objects.
Definition: WireUsage.hpp:121
WireUsage(const Tiles &inTiles)
Public constructor.
Definition: WireUsage.hpp:57
TileCount getTileUsageCount(void) const
Returns the number of tiles that have been touched.
Definition: WireUsage.hpp:169
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
xilinx::TileTypeIndex TileTypeIndex
Imported type name.
Definition: WireUsage.hpp:41
Tile map, tile type, and wire information for the family and device.
Definition: Tiles.hpp:36
Encapsulation of a tile count in an unsigned 32-bit integer.
Encapsulation of a tile within a device tile map.
Definition: TileInfo.hpp:33
const TileTypeIndex & getTypeIndex(void) const
Returns the tile type index for this tile.
Definition: TileInfo.hpp:92
void use(const Tilewire &inTilewire)
Marks the specified tilewire as being used.
Definition: WireUsage.hpp:81
dynamic_bitset mTileDirty
The mask of tile bitsets that contain changes.
Definition: WireUsage.hpp:53
Header for the Tilewire class.
TileCount mTileUsageCount
The number of tiles for which bitsets are allocated.
Definition: WireUsage.hpp:47
Header for the Array class.
uint32_t mBitCount
The number of bits allocated by the usage bitsets.
Definition: WireUsage.hpp:51
uint32_t getBitCount(void) const
Returns the number of bits allocated.
Definition: WireUsage.hpp:171
Encapsulation of a tile type index in an unsigned 16-bit integer.
void release(const Tilewire &inTilewire)
Marks the specified tilewire as being unused.
Definition: WireUsage.hpp:104
~WireUsage(void)
Non-virtual destructor.
Definition: WireUsage.hpp:60
const TileIndex & getTileIndex(void) const
Returns the tile index.
Definition: Tilewire.hpp:64
void setSize(uint32_t inSize)
Discards all contents and resizes the array.
Definition: Array.hpp:107
Header for the Tiles class.
bool isUsed(const Tilewire &inTilewire)
Determines whether the specified tilewire is in use.
Definition: WireUsage.hpp:138
void autosize(void)
Size the wire usage according to the number of device tiles.
Definition: WireUsage.hpp:68
uint32_t getSize(void) const
Returns the array size.
Definition: Array.hpp:104
xilinx::WireIndex WireIndex
Imported type name.
Definition: WireUsage.hpp:42
Array< dynamic_bitset * > mBitsets
The wire usage bitset array.
Definition: WireUsage.hpp:49