@@ -86,9 +86,11 @@ void ClusteringEngine::setTree(PhysicalHierarchy* tree)
8686
8787void ClusteringEngine::setHalos (
8888 const HardMacro::Halo& base_halo,
89+ const bool use_full_halo,
8990 const odb::PtrMap<odb::dbInst, HardMacro::Halo>& macro_to_halo)
9091{
9192 base_halo_ = base_halo;
93+ use_full_halo_ = use_full_halo;
9294 macro_to_halo_ = macro_to_halo;
9395}
9496
@@ -2063,6 +2065,7 @@ std::string ClusteringEngine::generateMacroAndCoreDimensionsTable(
20632065void ClusteringEngine::createHardMacros ()
20642066{
20652067 const odb::Rect& core = block_->getCoreArea ();
2068+ const int minimum_spacing = getMinimumSpacing ();
20662069
20672070 for (odb::dbInst* inst : block_->getInsts ()) {
20682071 if (inst->isBlock ()) {
@@ -2082,18 +2085,7 @@ void ClusteringEngine::createHardMacros()
20822085 tree_->has_fixed_macros = true ;
20832086 }
20842087
2085- HardMacro::Halo halo;
2086- if (macro_to_halo_.contains (inst)) {
2087- halo = macro_to_halo_.at (inst);
2088- } else if (inst->getHalo () != nullptr ) {
2089- const HardMacro::Halo inst_halo (inst->getHalo ());
2090- halo = inst_halo;
2091- if (!inst->getHalo ()->isSoft ()) {
2092- halo = inst_halo.floorTo (base_halo_);
2093- }
2094- } else {
2095- halo = base_halo_;
2096- }
2088+ HardMacro::Halo halo = buildMacroHalo (inst, minimum_spacing);
20972089
20982090 auto macro = std::make_unique<HardMacro>(inst, halo);
20992091
@@ -2163,6 +2155,145 @@ int ClusteringEngine::getNumberOfIOs(Cluster* target) const
21632155 return number_of_ios;
21642156}
21652157
2158+ HardMacro::Halo ClusteringEngine::buildMacroHalo (odb::dbInst* inst,
2159+ int minimum_spacing) const
2160+ {
2161+ if (macro_to_halo_.contains (inst)) {
2162+ return macro_to_halo_.at (inst);
2163+ }
2164+
2165+ HardMacro::Halo full_halo;
2166+ if (inst->getHalo () != nullptr ) {
2167+ odb::Rect inst_halo = inst->getHalo ()->getBox ();
2168+ if (inst->getHalo ()->isSoft ()) {
2169+ full_halo = HardMacro::Halo (inst->getHalo ());
2170+ } else {
2171+ full_halo = {std::max (inst_halo.xMin (), base_halo_.left ),
2172+ std::max (inst_halo.yMin (), base_halo_.bottom ),
2173+ std::max (inst_halo.xMax (), base_halo_.right ),
2174+ std::max (inst_halo.yMax (), base_halo_.top )};
2175+ }
2176+ } else {
2177+ full_halo = base_halo_;
2178+ }
2179+
2180+ if (use_full_halo_) {
2181+ return full_halo;
2182+ }
2183+
2184+ HardMacro::Halo halo (minimum_spacing);
2185+
2186+ odb::dbMaster* master = inst->getMaster ();
2187+
2188+ for (odb::dbMTerm* mterm : master->getMTerms ()) {
2189+ if (mterm->getSigType () != odb::dbSigType::SIGNAL ) {
2190+ continue ;
2191+ }
2192+
2193+ for (odb::dbMPin* mpin : mterm->getMPins ()) {
2194+ for (odb::dbBox* box : mpin->getGeometry ()) {
2195+ odb::Rect pin_rect = box->getBox ();
2196+
2197+ std::vector<std::pair<int , Boundary>> dist_to_boundary{
2198+ {pin_rect.xMin (), Boundary::L},
2199+ {pin_rect.yMin (), Boundary::B},
2200+ {master->getWidth () - pin_rect.xMax (), Boundary::R},
2201+ {master->getHeight () - pin_rect.yMax (), Boundary::T}};
2202+
2203+ std::ranges::sort (dist_to_boundary);
2204+
2205+ Boundary closest = dist_to_boundary[0 ].second ;
2206+
2207+ auto & candidate = dist_to_boundary[0 ];
2208+ auto & second_candidate = dist_to_boundary[1 ];
2209+
2210+ // When a pin is equally distant from two or more edges (i.e. in the
2211+ // corner) the pin's layer direction is used to choose between
2212+ // candidates
2213+ if (isEquidistantDifferentDirections (candidate, second_candidate)) {
2214+ auto direction
2215+ = (mpin->getGeometry ().begin ())->getTechLayer ()->getDirection ();
2216+ if (direction == odb::dbTechLayerDir::VERTICAL ) {
2217+ closest = isVertical (candidate.second ) ? second_candidate.second
2218+ : candidate.second ;
2219+ } else {
2220+ closest = isVertical (candidate.second ) ? candidate.second
2221+ : second_candidate.second ;
2222+ }
2223+ }
2224+
2225+ switch (closest) {
2226+ case Boundary::B:
2227+ halo.bottom = full_halo.bottom ;
2228+ break ;
2229+ case Boundary::L:
2230+ halo.left = full_halo.left ;
2231+ break ;
2232+ case Boundary::T:
2233+ halo.top = full_halo.top ;
2234+ break ;
2235+ case Boundary::R:
2236+ halo.right = full_halo.right ;
2237+ break ;
2238+ }
2239+ }
2240+ }
2241+ }
2242+
2243+ // Adjust halo orientation for fixed macros here, since those
2244+ // are skipped during orientation improve and thus never properly adjusted
2245+ if (inst->getPlacementStatus ().isFixed ()) {
2246+ auto orient = inst->getOrient ();
2247+ if (orient == odb::dbOrientType::MX || orient == odb::dbOrientType::R180 ) {
2248+ std::swap (halo.bottom , halo.top );
2249+ }
2250+ if (orient == odb::dbOrientType::MY || orient == odb::dbOrientType::R180 ) {
2251+ std::swap (halo.left , halo.right );
2252+ }
2253+ }
2254+
2255+ return halo;
2256+ }
2257+
2258+ int ClusteringEngine::getMinimumSpacing () const
2259+ {
2260+ int spacing = 0 ;
2261+
2262+ for (odb::dbInst* inst : block_->getInsts ()) {
2263+ if (inst->isBlock ()) {
2264+ odb::dbMaster* master = inst->getMaster ();
2265+
2266+ for (odb::dbBox* obs : master->getObstructions ()) {
2267+ if (auto layer = obs->getTechLayer ()) {
2268+ spacing = std::max (spacing, layer->getSpacing ());
2269+ }
2270+ }
2271+
2272+ for (odb::dbMTerm* mterm : master->getMTerms ()) {
2273+ for (odb::dbMPin* mpin : mterm->getMPins ()) {
2274+ for (odb::dbBox* geom : mpin->getGeometry ()) {
2275+ if (auto layer = geom->getTechLayer ()) {
2276+ spacing = std::max (spacing, layer->getSpacing ());
2277+ }
2278+ }
2279+ }
2280+ }
2281+ }
2282+ }
2283+ return spacing;
2284+ }
2285+
2286+ bool ClusteringEngine::isEquidistantDifferentDirections (
2287+ std::pair<int , Boundary> candidate,
2288+ std::pair<int , Boundary> second_candidate) const
2289+ {
2290+ return (candidate.first == second_candidate.first )
2291+ && ((isVertical (candidate.second )
2292+ && !isVertical (second_candidate.second ))
2293+ || (!isVertical (candidate.second )
2294+ && isVertical (second_candidate.second )));
2295+ }
2296+
21662297// /////////////////////////////////////////////
21672298
21682299void ClusteringEngine::reportThresholds () const
0 commit comments