File size: 12,326 Bytes
f61bac1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | // SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026, The OpenROAD Authors
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "../../src/object.h"
#include "../../src/pusher.h"
#include "MplTest.h"
#include "gtest/gtest.h"
#include "odb/db.h"
#include "odb/dbTypes.h"
#include "odb/geom.h"
namespace mpl {
namespace {
class TestPusher : public MplTest
{
protected:
void SetUp() override
{
MplTest::SetUp();
db_->getChip()->getBlock()->setCoreArea(
odb::Rect(0, 0, die_width_, die_height_));
odb::dbLib* lib = db_->findLib("lib");
master_ = odb::dbMaster::create(lib, "macro_master");
master_->setType(odb::dbMasterType::BLOCK);
master_->setWidth(macro_width_);
master_->setHeight(macro_height_);
master_->setFrozen();
}
odb::dbBlock* block() { return db_->getChip()->getBlock(); }
// Returns a root MixedCluster with a StdCellCluster child that has a
// non-zero area SoftMacro. This prevents Pusher from treating the design
// as a "single centralized macro array" and skipping the push entirely.
std::unique_ptr<Cluster> makeRootWithStdCells()
{
auto root = std::make_unique<Cluster>(next_id_++, "root", &logger_);
root->setClusterType(MixedCluster);
auto cluster = std::make_unique<Cluster>(next_id_++, "std_cells", &logger_);
cluster->setClusterType(StdCellCluster);
auto soft_macro = std::make_unique<SoftMacro>(cluster.get());
soft_macro->setShapeF(macro_width_, macro_height_);
cluster->setSoftMacro(std::move(soft_macro));
root->addChild(std::move(cluster));
return root;
}
// Appends a HardMacroCluster child to parent placed at (x, y).
// Returns the cluster's raw pointer.
Cluster* addMacroCluster(Cluster* parent,
const std::string& name,
int x,
int y,
int width,
int height)
{
auto cluster = std::make_unique<Cluster>(next_id_++, name, &logger_);
cluster->setClusterType(HardMacroCluster);
// The SoftMaro is the physical absraction for a cluster, needed for the
// cluster to have any meaningful spatical information
auto soft_macro = std::make_unique<SoftMacro>(cluster.get());
soft_macro->setLocationF(x, y);
soft_macro->setShapeF(width, height);
cluster->setSoftMacro(std::move(soft_macro));
auto hard_macro = std::make_unique<HardMacro>(
odb::Point(x, y), name + "_hard", width, height, cluster.get());
HardMacro* raw_hard_macro = hard_macro.get();
hard_macro_storage_.push_back(std::move(hard_macro));
std::vector<HardMacro*> hard_macros = {raw_hard_macro};
cluster->specifyHardMacros(hard_macros);
Cluster* raw_cluster = cluster.get();
parent->addChild(std::move(cluster));
return raw_cluster;
}
Cluster* addMacroCluster(Cluster* parent,
const std::string& name,
int x,
int y)
{
return addMacroCluster(parent, name, x, y, macro_width_, macro_height_);
}
const int macro_width_ = 100000;
const int macro_height_ = 100000;
int next_id_ = 0;
odb::dbMaster* master_ = nullptr;
std::vector<std::unique_ptr<HardMacro>> hard_macro_storage_;
};
// When the root cluster is a HardMacroCluster (the design is entirely made
// up of macros), pushMacrosToCoreBoundaries() returns immediately without
// touching any macro.
TEST_F(TestPusher, RootIsHardMacroCluster)
{
auto root = std::make_unique<Cluster>(next_id_++, "root", &logger_);
root->setClusterType(HardMacroCluster);
auto hard_macro = std::make_unique<HardMacro>(odb::Point(10000, 10000),
"root_macro",
macro_width_,
macro_height_,
root.get());
HardMacro* raw_hard_macro = hard_macro.get();
hard_macro_storage_.push_back(std::move(hard_macro));
std::vector<HardMacro*> hard_macros = {raw_hard_macro};
root->specifyHardMacros(hard_macros);
Pusher pusher(&logger_, root.get(), block(), {});
pusher.pushMacrosToCoreBoundaries();
EXPECT_EQ(raw_hard_macro->getX(), 10000);
EXPECT_EQ(raw_hard_macro->getY(), 10000);
}
// When the root has exactly one HardMacroCluster child and no MixedCluster
// or non-zero StdCellCluster children, the design is treated as a single
// centralized macro array and no push is performed.
TEST_F(TestPusher, SingleCentralizedMacroArray)
{
auto root = std::make_unique<Cluster>(next_id_++, "root", &logger_);
root->setClusterType(MixedCluster);
addMacroCluster(root.get(), "macro_cluster", 10000, 200000);
HardMacro* raw_hard_macro = hard_macro_storage_.back().get();
Pusher pusher(&logger_, root.get(), block(), {});
pusher.pushMacrosToCoreBoundaries();
EXPECT_EQ(raw_hard_macro->getX(), 10000);
EXPECT_EQ(raw_hard_macro->getY(), 200000);
}
// A macro cluster whose distance to the left boundary is less than one
// macro width should be pushed to the left edge of the core.
TEST_F(TestPusher, MacroPushedToLeftBoundary)
{
auto root = makeRootWithStdCells();
// xMin = 10000; distance_to_left = 10000 < macro_width_ (100000)
addMacroCluster(root.get(), "macro_cluster", 10000, 0);
HardMacro* raw_hard_macro = hard_macro_storage_.back().get();
Pusher pusher(&logger_, root.get(), block(), {});
pusher.pushMacrosToCoreBoundaries();
EXPECT_EQ(raw_hard_macro->getX(), 0);
}
// A macro cluster whose distance to the right boundary is less than one
// macro width should be pushed to the right edge of the core.
TEST_F(TestPusher, MacroPushedToRightBoundary)
{
auto root = makeRootWithStdCells();
// xMax = 490000; distance_to_right = |490000 - 500000| = 10000 < macro_width_
const int macro_x = die_width_ - macro_width_ - 10000;
addMacroCluster(root.get(), "macro_cluster", macro_x, 0);
HardMacro* raw_hard_macro = hard_macro_storage_.back().get();
Pusher pusher(&logger_, root.get(), block(), {});
pusher.pushMacrosToCoreBoundaries();
EXPECT_EQ(raw_hard_macro->getX(), die_width_ - macro_width_);
}
// A macro cluster whose distance to the bottom boundary is less than one
// macro height should be pushed to the bottom edge of the core.
TEST_F(TestPusher, MacroPushedToBottomBoundary)
{
auto root = makeRootWithStdCells();
// yMin = 5000; distance_to_bottom = 5000 < macro_height_ (100000)
addMacroCluster(root.get(), "macro_cluster", 0, 5000);
HardMacro* raw_hard_macro = hard_macro_storage_.back().get();
Pusher pusher(&logger_, root.get(), block(), {});
pusher.pushMacrosToCoreBoundaries();
EXPECT_EQ(raw_hard_macro->getY(), 0);
}
// A macro cluster whose distance to the top boundary is less than one
// macro height should be pushed to the top edge of the core.
TEST_F(TestPusher, MacroPushedToTopBoundary)
{
auto root = makeRootWithStdCells();
// yMax = 490000; distance_to_top = |490000 - 500000| = 10000 < macro_height_
const int macro_y = die_height_ - macro_height_ - 10000;
addMacroCluster(root.get(), "macro_cluster", 0, macro_y);
HardMacro* raw_hard_macro = hard_macro_storage_.back().get();
Pusher pusher(&logger_, root.get(), block(), {});
pusher.pushMacrosToCoreBoundaries();
EXPECT_EQ(raw_hard_macro->getY(), die_height_ - macro_height_);
}
// A macro cluster tagged as fixed must not be moved regardless of its
// proximity to any boundary.
TEST_F(TestPusher, FixedMacroCluster)
{
auto root = makeRootWithStdCells();
// Build a HardMacroCluster backed by a FIRM dbInst so that
// Cluster::setAsFixedMacro() can succeed (it requires isFixed() == true).
auto cluster
= std::make_unique<Cluster>(next_id_++, "fixed_cluster", &logger_);
cluster->setClusterType(HardMacroCluster);
odb::dbInst* inst = odb::dbInst::create(block(), master_, "fixed_inst");
inst->setLocation(10000, 10000);
inst->setPlacementStatus(odb::dbPlacementStatus::FIRM);
auto hard_macro = std::make_unique<HardMacro>(inst, HardMacro::Halo{});
hard_macro->setCluster(cluster.get());
HardMacro* raw_hard_macro = hard_macro.get();
hard_macro_storage_.push_back(std::move(hard_macro));
cluster->setAsFixedMacro(raw_hard_macro);
std::vector<HardMacro*> hard_macros = {raw_hard_macro};
cluster->specifyHardMacros(hard_macros);
root->addChild(std::move(cluster));
Pusher pusher(&logger_, root.get(), block(), {});
pusher.pushMacrosToCoreBoundaries();
EXPECT_EQ(raw_hard_macro->getX(), 10000);
EXPECT_EQ(raw_hard_macro->getY(), 10000);
}
// When pushing a macro cluster toward its closest horizontal boundary would
// cause it to overlap with another hard macro, the move is reverted and the
// cluster moves only vertically
TEST_F(TestPusher, PushRevertedHorizontal)
{
auto root = makeRootWithStdCells();
// macro1 is 10000 units from the bottom and left edges, it would normally be
// pushed to the origin.
addMacroCluster(root.get(), "macro1", 10000, 10000);
HardMacro* raw_hard_macro_1 = hard_macro_storage_.back().get();
// macro2 already occupies (0, 10000), blocking the horizontal push.
addMacroCluster(root.get(), "macro2", 0, 10000, 5000, 5000);
Pusher pusher(&logger_, root.get(), block(), {});
pusher.pushMacrosToCoreBoundaries();
// Horizontal push reverted: the destination overlaps macro2.
// Vertical push is kept.
EXPECT_EQ(raw_hard_macro_1->getX(), 10000);
EXPECT_EQ(raw_hard_macro_1->getY(), 0);
}
// When pushing a macro cluster toward its closest vertical boundary would cause
// it to overlap with another hard macro, the move is reverted and the cluster
// moves only horizontally
TEST_F(TestPusher, PushRevertedVertical)
{
auto root = makeRootWithStdCells();
// macro1 is 10000 units from the bottom and left edges, it would normally be
// pushed to the origin.
addMacroCluster(root.get(), "macro1", 10000, 10000);
HardMacro* raw_hard_macro_1 = hard_macro_storage_.back().get();
// macro2 already occupies (10000, 0), blocking the horizontal push.
addMacroCluster(root.get(), "macro2", 10000, 0, 5000, 5000);
Pusher pusher(&logger_, root.get(), block(), {});
pusher.pushMacrosToCoreBoundaries();
// Vertical push reverted: the destination overlaps macro2.
// Horizontal push is kept.
EXPECT_EQ(raw_hard_macro_1->getX(), 0);
EXPECT_EQ(raw_hard_macro_1->getY(), 10000);
}
// When pushing a macro cluster toward its closest boundaries would cause an
// overlap with a macro diagonal to the pushed macro, push the macro the bottom
// The Pusher is biased by the Boundary enum ordering (B > L > T > R).
TEST_F(TestPusher, PushRevertedBiased)
{
auto root = makeRootWithStdCells();
// macro1 is 10000 units from the bottom and left edges, it would normally be
// pushed to the origin.
addMacroCluster(root.get(), "macro1", 10000, 10000);
HardMacro* raw_hard_macro_1 = hard_macro_storage_.back().get();
// macro2 already occupies (0, 0), blocking the last push but not the first
// one.
addMacroCluster(root.get(), "macro2", 0, 0, 5000, 5000);
Pusher pusher(&logger_, root.get(), block(), {});
pusher.pushMacrosToCoreBoundaries();
// Last push (left) is reverted, bottom push is kept
EXPECT_EQ(raw_hard_macro_1->getX(), 10000);
EXPECT_EQ(raw_hard_macro_1->getY(), 0);
}
// When pushing a macro cluster toward its closest boundary would cause it to
// overlap with an IO blockage, the move is reverted and the cluster stays at
// its original position.
TEST_F(TestPusher, PushRevertedOnIOBlockageOverlap)
{
auto root = makeRootWithStdCells();
// Macro is 10000 units from the left; without the blockage it would be
// pushed to x = 0.
addMacroCluster(root.get(), "macro_cluster", 10000, 0);
HardMacro* raw_hard_macro = hard_macro_storage_.back().get();
// IO blockage covers the left side where the macro would land.
const std::vector<odb::Rect> io_blockages = {odb::Rect(0, 0, 50000, 100000)};
Pusher pusher(&logger_, root.get(), block(), io_blockages);
pusher.pushMacrosToCoreBoundaries();
// Push reverted: the moved cluster box overlaps the IO blockage.
EXPECT_EQ(raw_hard_macro->getX(), 10000);
EXPECT_EQ(raw_hard_macro->getY(), 0);
}
} // namespace
} // namespace mpl
|