33
44#pragma once
55
6+ #include < boost/icl/interval_map.hpp>
67#include < functional>
78#include < map>
89#include < memory>
@@ -39,9 +40,8 @@ struct Pixel
3940 bool is_valid = false ; // false for dummy cells
4041 bool is_hopeless = false ; // too far from sites for diamond search
4142 uint8_t blocked_layers = 0 ;
42- std::map<dbSite*, dbOrientType> sites;
43- std::unordered_set<Node*>
44- padding_reserved_by; // Cells that reserved this pixel for padding
43+ // Cells that reserved this pixel for padding
44+ std::unordered_set<Node*> padding_reserved_by;
4545};
4646
4747// Return value for grid searches.
@@ -132,6 +132,11 @@ class Grid
132132 Pixel& pixel (GridY y, GridX x) { return pixels_[y.v ][x.v ]; }
133133 const Pixel& pixel (GridY y, GridX x) const { return pixels_[y.v ][x.v ]; }
134134
135+ std::optional<dbOrientType> getSiteOrientation (GridX x,
136+ GridY y,
137+ dbSite* site) const ;
138+ std::pair<dbSite*, dbOrientType> getShortestSite (GridX grid_x, GridY grid_y);
139+
135140 void resize (int size) { pixels_.resize (size); }
136141 void resize (GridY size) { pixels_.resize (size.v ); }
137142 void resize (GridY y, GridX size) { pixels_[y.v ].resize (size.v ); }
@@ -147,14 +152,40 @@ class Grid
147152 bool isMultiHeight (dbMaster* master) const ;
148153
149154 private:
155+ // Maps a site to the right orientation to use in a given row
156+ using SiteToOrientation = std::map<dbSite*, dbOrientType>;
157+
158+ // Used to combine the SiteToOrientation for two intervals when merged
159+ template <typename MapType>
160+ struct SitesCombiner
161+ {
162+ using first_argument_type = MapType&;
163+ using second_argument_type = const MapType&;
164+
165+ static MapType identity_element () { return MapType (); }
166+
167+ void operator ()(MapType& target, const MapType& source) const
168+ {
169+ target.insert (source.begin (), source.end ());
170+ }
171+ };
172+
173+ // Map intervals in rows to the site/orientation mapping
174+ using RowSitesMap = boost::icl::interval_map<int ,
175+ SiteToOrientation,
176+ boost::icl::total_absorber,
177+ std::less,
178+ SitesCombiner>;
179+
180+ using Pixels = std::vector<std::vector<Pixel>>;
181+
150182 void markHopeless (dbBlock* block,
151183 int max_displacement_x,
152184 int max_displacement_y);
153185 void markBlocked (dbBlock* block);
154186 void visitDbRows (dbBlock* block,
155187 const std::function<void (odb::dbRow*)>& func) const ;
156188
157- using Pixels = std::vector<std::vector<Pixel>>;
158189 Logger* logger_ = nullptr ;
159190 dbBlock* block_ = nullptr ;
160191 std::shared_ptr<Padding> padding_;
@@ -165,6 +196,9 @@ class Grid
165196 std::vector<DbuY> row_index_to_y_dbu_; // index is GridY
166197 std::vector<DbuY> row_index_to_pixel_height_; // index is GridY
167198
199+ // Indexed by row (GridY)
200+ std::vector<RowSitesMap> row_sites_;
201+
168202 bool has_hybrid_rows_ = false ;
169203 Rect core_;
170204
0 commit comments