Skip to content

Commit 9aeb98b

Browse files
authored
Merge pull request #10141 from The-OpenROAD-Project-staging/secure-rsz-instance-outside-core
rsz: clamp buffer locations to core area during insertion
2 parents 3109b64 + 7ac212c commit 9aeb98b

21 files changed

Lines changed: 240 additions & 92 deletions

src/rsz/include/rsz/Resizer.hh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ class Resizer : public sta::dbStaState, public sta::dbNetworkObserver
778778
void insertBufferPostProcess(odb::dbInst* buffer_inst);
779779

780780
void setLocation(odb::dbInst* db_inst, const odb::Point& pt);
781+
odb::Point clampLocToCore(const odb::Point& loc, odb::dbMaster* master) const;
781782
sta::LibertyCell* findTargetCell(sta::LibertyCell* cell,
782783
float load_cap,
783784
bool revisiting_inst);
@@ -804,7 +805,6 @@ class Resizer : public sta::dbStaState, public sta::dbNetworkObserver
804805
float& limit,
805806
float& slack,
806807
const sta::Scene*& corner);
807-
void warnBufferMovedIntoCore();
808808
bool isLogicStdCell(const sta::Instance* inst);
809809

810810
bool okToBufferNet(const sta::Pin* driver_pin) const;
@@ -889,7 +889,6 @@ class Resizer : public sta::dbStaState, public sta::dbNetworkObserver
889889
int swap_pin_count_ = 0;
890890
int removed_buffer_count_ = 0;
891891
bool exclude_clock_buffers_ = true;
892-
bool buffer_moved_into_core_ = false;
893892
bool match_cell_footprint_ = false;
894893
bool equiv_cells_made_ = false;
895894

src/rsz/src/RecoverPower.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ bool RecoverPower::recoverPower(const float recover_power_percent, bool verbose)
6161
init();
6262
constexpr int digits = 3;
6363
resize_count_ = 0;
64-
resizer_->buffer_moved_into_core_ = false;
6564

6665
// Sort failing endpoints by slack.
6766
sta::VertexSet& endpoints = sta_->endpoints();

src/rsz/src/RepairDesign.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ void RepairDesign::repairNet(sta::Net* net,
539539
inserted_buffer_count_ = 0;
540540
resize_count_ = 0;
541541
resizer_->resized_multi_output_insts_.clear();
542-
resizer_->buffer_moved_into_core_ = false;
543542

544543
sta_->checkSlewsPreamble();
545544
sta_->checkCapacitancesPreamble(sta_->scenes());

src/rsz/src/RepairSetup.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ bool RepairSetup::repairSetup(const float setup_slack_margin,
206206
// IMPROVE ME: rebuffering always looks at cmd corner
207207
resizer_->rebuffer_->initOnCorner(sta_->cmdScene());
208208
max_repairs_per_pass_ = max_repairs_per_pass;
209-
resizer_->buffer_moved_into_core_ = false;
210209

211210
violator_collector_->init(setup_slack_margin);
212211
violator_collector_->setMaxPassesPerEndpoint(max_passes);

src/rsz/src/Resizer.cc

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,6 @@ void Resizer::bufferInputs(sta::LibertyCell* buffer_cell, bool verbose)
10011001

10021002
sta_->ensureClkNetwork(sta_->cmdMode());
10031003
inserted_buffer_count_ = 0;
1004-
buffer_moved_into_core_ = false;
10051004

10061005
{
10071006
est::IncrementalParasiticsGuard guard(estimate_parasitics_);
@@ -1139,7 +1138,6 @@ void Resizer::bufferOutputs(sta::LibertyCell* buffer_cell, bool verbose)
11391138
}
11401139

11411140
inserted_buffer_count_ = 0;
1142-
buffer_moved_into_core_ = false;
11431141

11441142
{
11451143
est::IncrementalParasiticsGuard guard(estimate_parasitics_);
@@ -5123,6 +5121,11 @@ sta::Instance* Resizer::makeInstance(sta::LibertyCell* cell,
51235121

51245122
void Resizer::insertBufferPostProcess(dbInst* buffer_inst)
51255123
{
5124+
// ODB's insertBuffer* already placed the instance; re-run through
5125+
// setLocation so clampLocToCore can pull it back inside the core if
5126+
// the insertion point landed in the die-core gap.
5127+
setLocation(buffer_inst, buffer_inst->getLocation());
5128+
51265129
// Legalize the cell position for accurate parasitic estimation
51275130
if (estimate_parasitics_->getParasiticsSrc()
51285131
== est::ParasiticsSrc::kGlobalRouting
@@ -5145,33 +5148,35 @@ void Resizer::insertBufferPostProcess(dbInst* buffer_inst)
51455148

51465149
void Resizer::setLocation(dbInst* db_inst, const odb::Point& pt)
51475150
{
5148-
int x = pt.x();
5149-
int y = pt.y();
5150-
// Stay inside the lines.
5151-
if (core_exists_) {
5152-
dbMaster* master = db_inst->getMaster();
5153-
int width = master->getWidth();
5154-
if (x < core_.xMin()) {
5155-
x = core_.xMin();
5156-
buffer_moved_into_core_ = true;
5157-
} else if (x > core_.xMax() - width) {
5158-
// Make sure the instance is entirely inside core.
5159-
x = core_.xMax() - width;
5160-
buffer_moved_into_core_ = true;
5161-
}
5162-
5163-
int height = master->getHeight();
5164-
if (y < core_.yMin()) {
5165-
y = core_.yMin();
5166-
buffer_moved_into_core_ = true;
5167-
} else if (y > core_.yMax() - height) {
5168-
y = core_.yMax() - height;
5169-
buffer_moved_into_core_ = true;
5170-
}
5151+
const odb::Point loc = clampLocToCore(pt, db_inst->getMaster());
5152+
db_inst->setPlacementStatus(dbPlacementStatus::PLACED);
5153+
db_inst->setLocation(loc.x(), loc.y());
5154+
if (loc != pt) {
5155+
debugPrint(logger_,
5156+
RSZ,
5157+
"buffer_clamp",
5158+
1,
5159+
"{} clamped to core ({}, {}) -> ({}, {})",
5160+
db_inst->getName(),
5161+
pt.x(),
5162+
pt.y(),
5163+
loc.x(),
5164+
loc.y());
51715165
}
5166+
}
51725167

5173-
db_inst->setPlacementStatus(dbPlacementStatus::PLACED);
5174-
db_inst->setLocation(x, y);
5168+
odb::Point Resizer::clampLocToCore(const odb::Point& loc,
5169+
odb::dbMaster* master) const
5170+
{
5171+
if (!core_exists_) {
5172+
return loc;
5173+
}
5174+
const int x_max = std::max(
5175+
core_.xMin(), core_.xMax() - static_cast<int>(master->getWidth()));
5176+
const int y_max = std::max(
5177+
core_.yMin(), core_.yMax() - static_cast<int>(master->getHeight()));
5178+
return {std::clamp(loc.x(), core_.xMin(), x_max),
5179+
std::clamp(loc.y(), core_.yMin(), y_max)};
51755180
}
51765181

51775182
float Resizer::portCapacitance(sta::LibertyPort* input,
@@ -5281,13 +5286,6 @@ void Resizer::checkLoadSlews(const sta::Pin* drvr_pin,
52815286
delete pin_iter;
52825287
}
52835288

5284-
void Resizer::warnBufferMovedIntoCore()
5285-
{
5286-
if (buffer_moved_into_core_) {
5287-
logger_->warn(RSZ, 77, "some buffers were moved inside the core.");
5288-
}
5289-
}
5290-
52915289
void Resizer::setDebugPin(const sta::Pin* pin)
52925290
{
52935291
debug_pin_ = pin;

src/rsz/test/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ TESTS = [
6868
"repair_design3_verbose",
6969
"repair_design4",
7070
"repair_design5",
71+
"repair_design_outside_core",
7172
"repair_fanout1",
7273
"repair_fanout1_hier",
7374
"repair_fanout2",

src/rsz/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ or_integration_tests(
5959
repair_design3_verbose
6060
repair_design4
6161
repair_design5
62+
repair_design_outside_core
6263
repair_fanout1
6364
repair_fanout2
6465
repair_fanout3

src/rsz/test/buffer_ports10.defok

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ TRACKS Y 3340 DO 62 STEP 3200 LAYER metal9 ;
8181
TRACKS X 3390 DO 62 STEP 3200 LAYER metal10 ;
8282
TRACKS Y 3340 DO 62 STEP 3200 LAYER metal10 ;
8383
COMPONENTS 5 ;
84-
- input1 BUF_X1 + SOURCE TIMING + PLACED ( 101270 199930 ) N ;
85-
- input2 BUF_X1 + SOURCE TIMING + PLACED ( 99750 199930 ) N ;
86-
- output3 BUF_X1 + SOURCE TIMING + PLACED ( 100510 199930 ) N ;
87-
- output4 BUF_X1 + SOURCE TIMING + PLACED ( 98990 199930 ) N ;
84+
- input1 BUF_X1 + SOURCE TIMING + PLACED ( 101270 176400 ) N ;
85+
- input2 BUF_X1 + SOURCE TIMING + PLACED ( 99750 176400 ) N ;
86+
- output3 BUF_X1 + SOURCE TIMING + PLACED ( 100510 176400 ) N ;
87+
- output4 BUF_X1 + SOURCE TIMING + PLACED ( 98990 176400 ) N ;
8888
- r1 DFF_X1 + PLACED ( 96726 170871 ) N ;
8989
END COMPONENTS
9090
PINS 4 ;

src/rsz/test/buffer_ports8.defok

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ TRACKS Y 3340 DO 62 STEP 3200 LAYER metal9 ;
8181
TRACKS X 3390 DO 62 STEP 3200 LAYER metal10 ;
8282
TRACKS Y 3340 DO 62 STEP 3200 LAYER metal10 ;
8383
COMPONENTS 5 ;
84-
- input1 BUF_X1 + SOURCE TIMING + PLACED ( 101270 199930 ) N ;
85-
- input2 BUF_X1 + SOURCE TIMING + PLACED ( 99750 199930 ) N ;
86-
- output3 BUF_X1 + SOURCE TIMING + PLACED ( 100510 199930 ) N ;
87-
- output4 BUF_X1 + SOURCE TIMING + PLACED ( 98990 199930 ) N ;
84+
- input1 BUF_X1 + SOURCE TIMING + PLACED ( 101270 176400 ) N ;
85+
- input2 BUF_X1 + SOURCE TIMING + PLACED ( 99750 176400 ) N ;
86+
- output3 BUF_X1 + SOURCE TIMING + PLACED ( 100510 176400 ) N ;
87+
- output4 BUF_X1 + SOURCE TIMING + PLACED ( 98990 176400 ) N ;
8888
- r1 DFF_X1 + PLACED ( 96726 170871 ) N ;
8989
END COMPONENTS
9090
PINS 4 ;

src/rsz/test/buffer_ports9.defok

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ TRACKS Y 3340 DO 62 STEP 3200 LAYER metal9 ;
8181
TRACKS X 3390 DO 62 STEP 3200 LAYER metal10 ;
8282
TRACKS Y 3340 DO 62 STEP 3200 LAYER metal10 ;
8383
COMPONENTS 5 ;
84-
- input1 BUF_X16 + SOURCE TIMING + PLACED ( 101270 199930 ) N ;
85-
- input2 BUF_X16 + SOURCE TIMING + PLACED ( 99750 199930 ) N ;
86-
- output3 BUF_X16 + SOURCE TIMING + PLACED ( 100510 199930 ) N ;
87-
- output4 BUF_X16 + SOURCE TIMING + PLACED ( 98990 199930 ) N ;
84+
- input1 BUF_X16 + SOURCE TIMING + PLACED ( 101270 176400 ) N ;
85+
- input2 BUF_X16 + SOURCE TIMING + PLACED ( 99750 176400 ) N ;
86+
- output3 BUF_X16 + SOURCE TIMING + PLACED ( 100510 176400 ) N ;
87+
- output4 BUF_X16 + SOURCE TIMING + PLACED ( 98990 176400 ) N ;
8888
- r1 DFF_X1 + PLACED ( 96726 170871 ) N ;
8989
END COMPONENTS
9090
PINS 4 ;

0 commit comments

Comments
 (0)