Skip to content

Commit 69a7c63

Browse files
authored
Merge pull request #8689 from eder-matheus/rsz_max_iters
rsz: add -max_iterations option to repair_timing
2 parents 4f47673 + fb75878 commit 69a7c63

File tree

9 files changed

+55
-12
lines changed

9 files changed

+55
-12
lines changed

src/rsz/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ repair_timing
231231
[-skip_crit_vt_swap]
232232
[-repair_tns tns_end_percent]
233233
[-max_passes passes]
234+
[-max_iterations iterations]
234235
[-max_repairs_per_pass max_repairs_per_pass]
235236
[-max_utilization util]
236237
[-max_buffer_percent buffer_percent]
@@ -260,6 +261,7 @@ repair_timing
260261
| `-repair_tns` | Percentage of violating endpoints to repair (0-100). When `tns_end_percent` is zero, only the worst endpoint is repaired. When `tns_end_percent` is 100 (default), all violating endpoints are repaired. |
261262
| `-max_repairs_per_pass` | Maximum repairs per pass, default is 1. On the worst paths, the maximum number of repairs is attempted. It gradually decreases until the final violations which only get 1 repair per pass. |
262263
| `-max_utilization` | Defines the percentage of core area used. |
264+
| `-max_iterations` | Defines the maximum number of iterations executed when repairing setup and hold violations. The default is `-1`, which disables the limit of iterations. |
263265
| `-max_buffer_percent` | Specify a maximum number of buffers to insert to repair hold violations as a percentage of the number of instances in the design. The default value is `20`, and the allowed values are integers `[0, 100]`. |
264266
| `-match_cell_footprint` | Obey the Liberty cell footprint when swapping gates. |
265267
| `-verbose` | Enable verbose logging of the repair progress. |

src/rsz/include/rsz/Resizer.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ class Resizer : public dbStaState, public dbNetworkObserver
276276
bool repairSetup(double setup_margin,
277277
double repair_tns_end_percent,
278278
int max_passes,
279+
int max_iterations,
279280
int max_repairs_per_pass,
280281
bool match_cell_footprint,
281282
bool verbose,
@@ -304,6 +305,7 @@ class Resizer : public dbStaState, public dbNetworkObserver
304305
// Max buffer count as percent of design instance count.
305306
float max_buffer_percent,
306307
int max_passes,
308+
int max_iterations,
307309
bool match_cell_footprint,
308310
bool verbose);
309311
void repairHold(const Pin* end_pin,

src/rsz/src/RepairHold.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ bool RepairHold::repairHold(
7171
// Max buffer count as percent of design instance count.
7272
const float max_buffer_percent,
7373
const int max_passes,
74+
const int max_iterations,
7475
const bool verbose)
7576
{
7677
bool repaired = false;
@@ -100,6 +101,7 @@ bool RepairHold::repairHold(
100101
allow_setup_violations,
101102
max_buffer_count,
102103
max_passes,
104+
max_iterations,
103105
verbose);
104106
}
105107

@@ -135,6 +137,8 @@ void RepairHold::repairHold(const Pin* end_pin,
135137
allow_setup_violations,
136138
max_buffer_count,
137139
max_passes,
140+
// set max_iterations to max_passes for testing
141+
max_passes,
138142
false);
139143
}
140144
}
@@ -382,6 +386,7 @@ bool RepairHold::repairHold(VertexSeq& ends,
382386
const bool allow_setup_violations,
383387
const int max_buffer_count,
384388
const int max_passes,
389+
const int max_iterations,
385390
const bool verbose)
386391
{
387392
bool repaired = false;
@@ -399,8 +404,8 @@ bool RepairHold::repairHold(VertexSeq& ends,
399404
printProgress(0, true, false);
400405
int pass = 1;
401406
while (worst_slack < hold_margin && progress && !resizer_->overMaxArea()
402-
&& inserted_buffer_count_ <= max_buffer_count
403-
&& pass <= max_passes) {
407+
&& inserted_buffer_count_ <= max_buffer_count && pass <= max_passes
408+
&& (max_iterations < 0 || pass <= max_iterations)) {
404409
if (verbose || pass == 1) {
405410
printProgress(pass, false, false);
406411
}

src/rsz/src/RepairHold.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class RepairHold : public sta::dbStaState
4646
// Max buffer count as percent of design instance count.
4747
float max_buffer_percent,
4848
int max_passes,
49+
int max_iterations,
4950
bool verbose);
5051
void repairHold(const Pin* end_pin,
5152
double setup_margin,
@@ -84,6 +85,7 @@ class RepairHold : public sta::dbStaState
8485
bool allow_setup_violations,
8586
int max_buffer_count,
8687
int max_passes,
88+
int max_iterations,
8789
bool verbose);
8890
void repairHoldPass(VertexSeq& hold_failures,
8991
LibertyCell* buffer_cell,

src/rsz/src/RepairSetup.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void RepairSetup::init()
8585
bool RepairSetup::repairSetup(const float setup_slack_margin,
8686
const double repair_tns_end_percent,
8787
const int max_passes,
88+
const int max_iterations,
8889
const int max_repairs_per_pass,
8990
const bool verbose,
9091
const std::vector<MoveType>& sequence,
@@ -448,6 +449,9 @@ bool RepairSetup::repairSetup(const float setup_slack_margin,
448449
end = worst_vertex;
449450
}
450451
pass++;
452+
if (max_iterations > 0 && opto_iteration >= max_iterations) {
453+
break;
454+
}
451455
} // while pass <= max_passes
452456
if (verbose || opto_iteration == 1) {
453457
printProgress(opto_iteration, true, false, false, num_viols);
@@ -459,6 +463,9 @@ bool RepairSetup::repairSetup(const float setup_slack_margin,
459463
// clang-format on
460464
break;
461465
}
466+
if (max_iterations > 0 && opto_iteration >= max_iterations) {
467+
break;
468+
}
462469
} // for each violating endpoint
463470

464471
if (!skip_last_gasp) {
@@ -473,7 +480,7 @@ bool RepairSetup::repairSetup(const float setup_slack_margin,
473480
skip_vt_swap);
474481
params.iteration = opto_iteration;
475482
params.initial_tns = initial_tns;
476-
repairSetupLastGasp(params, num_viols);
483+
repairSetupLastGasp(params, num_viols, max_iterations);
477484
}
478485

479486
if (!skip_crit_vt_swap && !skip_vt_swap
@@ -865,7 +872,9 @@ bool RepairSetup::terminateProgress(const int iteration,
865872

866873
// Perform some last fixing based on sizing only.
867874
// This is a greedy opto that does not degrade WNS or TNS.
868-
void RepairSetup::repairSetupLastGasp(const OptoParams& params, int& num_viols)
875+
void RepairSetup::repairSetupLastGasp(const OptoParams& params,
876+
int& num_viols,
877+
const int max_iterations)
869878
{
870879
move_sequence.clear();
871880
if (!params.skip_vt_swap) {
@@ -926,6 +935,10 @@ void RepairSetup::repairSetupLastGasp(const OptoParams& params, int& num_viols)
926935
float fix_rate_threshold = inc_fix_rate_threshold_;
927936

928937
for (const auto& end_original_slack : violating_ends) {
938+
if (max_iterations > 0 && opto_iteration >= max_iterations) {
939+
break;
940+
}
941+
929942
fallback_ = false;
930943
Vertex* end = end_original_slack.first;
931944
Slack end_slack = sta_->vertexSlack(end, max_);
@@ -1015,6 +1028,9 @@ void RepairSetup::repairSetupLastGasp(const OptoParams& params, int& num_viols)
10151028
end = worst_vertex;
10161029
}
10171030
pass++;
1031+
if (max_iterations > 0 && opto_iteration >= max_iterations) {
1032+
break;
1033+
}
10181034
} // while pass <= max_last_gasp_passes_
10191035
if (params.verbose || opto_iteration == 1) {
10201036
printProgress(opto_iteration, true, false, true, num_viols);

src/rsz/src/RepairSetup.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class RepairSetup : public sta::dbStaState
9696
// reduce tns (0.0-1.0).
9797
double repair_tns_end_percent,
9898
int max_passes,
99+
int max_iterations,
99100
int max_repairs_per_pass,
100101
bool verbose,
101102
const std::vector<MoveType>& sequence,
@@ -131,7 +132,9 @@ class RepairSetup : public sta::dbStaState
131132
float& fix_rate_threshold,
132133
int endpt_index,
133134
int num_endpts);
134-
void repairSetupLastGasp(const OptoParams& params, int& num_viols);
135+
void repairSetupLastGasp(const OptoParams& params,
136+
int& num_viols,
137+
int max_iterations);
135138
bool swapVTCritCells(const OptoParams& params, int& num_viols);
136139
void traverseFaninCone(Vertex* endpoint,
137140
std::unordered_map<Instance*, float>& crit_insts,

src/rsz/src/Resizer.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4354,6 +4354,7 @@ void Resizer::cloneClkInverter(Instance* inv)
43544354
bool Resizer::repairSetup(double setup_margin,
43554355
double repair_tns_end_percent,
43564356
int max_passes,
4357+
int max_iterations,
43574358
int max_repairs_per_pass,
43584359
bool match_cell_footprint,
43594360
bool verbose,
@@ -4379,6 +4380,7 @@ bool Resizer::repairSetup(double setup_margin,
43794380
return repair_setup_->repairSetup(setup_margin,
43804381
repair_tns_end_percent,
43814382
max_passes,
4383+
max_iterations,
43824384
max_repairs_per_pass,
43834385
verbose,
43844386
sequence,
@@ -4419,6 +4421,7 @@ bool Resizer::repairHold(
44194421
// Max buffer count as percent of design instance count.
44204422
float max_buffer_percent,
44214423
int max_passes,
4424+
int max_iterations,
44224425
bool match_cell_footprint,
44234426
bool verbose)
44244427
{
@@ -4445,6 +4448,7 @@ bool Resizer::repairHold(
44454448
allow_setup_violations,
44464449
max_buffer_percent,
44474450
max_passes,
4451+
max_iterations,
44484452
verbose);
44494453
}
44504454

src/rsz/src/Resizer.i

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ bool
362362
repair_setup(double setup_margin,
363363
double repair_tns_end_percent,
364364
int max_passes,
365+
int max_iterations,
365366
int max_repairs_per_pass,
366367
bool match_cell_footprint,
367368
bool verbose,
@@ -378,9 +379,9 @@ repair_setup(double setup_margin,
378379
ensureLinked();
379380
Resizer *resizer = getResizer();
380381
return resizer->repairSetup(setup_margin, repair_tns_end_percent,
381-
max_passes, max_repairs_per_pass,
382-
match_cell_footprint, verbose,
383-
sequence,
382+
max_passes, max_iterations,
383+
max_repairs_per_pass, match_cell_footprint,
384+
verbose, sequence,
384385
skip_pin_swap, skip_gate_cloning,
385386
skip_size_down,
386387
skip_buffering, skip_buffer_removal,
@@ -409,6 +410,7 @@ repair_hold(double setup_margin,
409410
bool allow_setup_violations,
410411
float max_buffer_percent,
411412
int max_passes,
413+
int max_iterations,
412414
bool match_cell_footprint,
413415
bool verbose)
414416
{
@@ -417,7 +419,8 @@ repair_hold(double setup_margin,
417419
return resizer->repairHold(setup_margin, hold_margin,
418420
allow_setup_violations,
419421
max_buffer_percent, max_passes,
420-
match_cell_footprint, verbose);
422+
max_iterations, match_cell_footprint,
423+
verbose);
421424
}
422425

423426
void

src/rsz/src/Resizer.tcl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ sta::define_cmd_args "repair_timing" {[-setup] [-hold]\
251251
[-skip_crit_vt_swap]\
252252
[-repair_tns tns_end_percent]\
253253
[-max_passes passes]\
254+
[-max_iterations iterations]\
254255
[-max_buffer_percent buffer_percent]\
255256
[-max_utilization util] \
256257
[-match_cell_footprint] \
@@ -261,7 +262,7 @@ proc repair_timing { args } {
261262
sta::parse_key_args "repair_timing" args \
262263
keys {-setup_margin -hold_margin -slack_margin \
263264
-libraries -max_utilization -max_buffer_percent -sequence \
264-
-recover_power -repair_tns -max_passes -max_repairs_per_pass} \
265+
-recover_power -repair_tns -max_passes -max_iterations -max_repairs_per_pass} \
265266
flags {-setup -hold -allow_setup_violations -skip_pin_swap -skip_gate_cloning \
266267
-skip_size_down -skip_buffering -skip_buffer_removal -skip_last_gasp \
267268
-skip_vt_swap -skip_crit_vt_swap -match_cell_footprint -verbose}
@@ -336,6 +337,11 @@ proc repair_timing { args } {
336337
set max_passes $keys(-max_passes)
337338
}
338339

340+
set max_iterations -1
341+
if { [info exists keys(-max_iterations)] } {
342+
set max_iterations $keys(-max_iterations)
343+
}
344+
339345
set match_cell_footprint [info exists flags(-match_cell_footprint)]
340346
if { [design_is_routed] } {
341347
est::set_parasitics_src "detailed_routing"
@@ -357,15 +363,15 @@ proc repair_timing { args } {
357363
} else {
358364
if { $setup } {
359365
set repaired_setup [rsz::repair_setup $setup_margin $repair_tns_end_percent $max_passes \
360-
$max_repairs_per_pass $match_cell_footprint $verbose \
366+
$max_iterations $max_repairs_per_pass $match_cell_footprint $verbose \
361367
$sequence \
362368
$skip_pin_swap $skip_gate_cloning $skip_size_down $skip_buffering \
363369
$skip_buffer_removal $skip_last_gasp $skip_vt_swap $skip_crit_vt_swap]
364370
}
365371
if { $hold } {
366372
set repaired_hold [rsz::repair_hold $setup_margin $hold_margin \
367373
$allow_setup_violations $max_buffer_percent $max_passes \
368-
$match_cell_footprint $verbose]
374+
$max_iterations $match_cell_footprint $verbose]
369375
}
370376
}
371377

0 commit comments

Comments
 (0)