From 7d2f82d2321e3804de9cc6c864decb0d26300d42 Mon Sep 17 00:00:00 2001 From: Arthur Koucher Date: Tue, 22 Oct 2024 17:01:37 -0300 Subject: [PATCH] rsz: make new mechanism more generic Signed-off-by: Arthur Koucher --- src/rsz/include/rsz/Resizer.hh | 29 +++++------------- src/rsz/src/Resizer.cc | 54 +++++++++++----------------------- 2 files changed, 24 insertions(+), 59 deletions(-) diff --git a/src/rsz/include/rsz/Resizer.hh b/src/rsz/include/rsz/Resizer.hh index 54806880463..b85a8d7381b 100644 --- a/src/rsz/include/rsz/Resizer.hh +++ b/src/rsz/include/rsz/Resizer.hh @@ -182,32 +182,17 @@ struct BufferData class OdbCallBack; -// RAII mechanism to facilitate using operation specific settings, e.g., -// use only the clock buffers from cts when doing repairClkNets, don't -// use buffers marked as "clock" in hold repairing, etc. -// Can be instantiated in two ways: -// - Before resizePreamble(): set the "filters" used by the preamble. -// - After resizePreamble(): enforce the variables we want. -class OperationSettings +// RAII mechanism to facilitate using operation-specific settings. +template +class SetAndRestore { public: - // Call before preamble: - OperationSettings(bool* exclude_clock_buffers, - bool new_exclude_clock_buffers, - sta::LibertyCellSeq* buffer_cells); - - // Call after preamble: - OperationSettings(sta::LibertyCellSeq* buffer_cells, - const sta::LibertyCellSeq& new_buffer_cells); - - ~OperationSettings(); + SetAndRestore(T& storage, const T& new_value); + ~SetAndRestore(); private: - bool* exclude_clock_buffers_{nullptr}; - sta::LibertyCellSeq* buffer_cells_{nullptr}; - - // Previous settings (initialized to default): - bool prev_exclude_clock_buffers_{true}; + T& storage_; + T old_value_; }; class Resizer : public dbStaState diff --git a/src/rsz/src/Resizer.cc b/src/rsz/src/Resizer.cc index 5fc91a3b3a1..3f1f6d270c5 100644 --- a/src/rsz/src/Resizer.cc +++ b/src/rsz/src/Resizer.cc @@ -2689,7 +2689,7 @@ void Resizer::repairNet(Net* net, void Resizer::repairClkNets(double max_wire_length) { resizePreamble(); - OperationSettings operation_settings(&buffer_cells_, clk_buffers_); + SetAndRestore set_buffers(buffer_cells_, clk_buffers_); repair_design_->repairClkNets(max_wire_length); } @@ -2850,42 +2850,20 @@ void Resizer::rebufferNet(const Pin* drvr_pin) //////////////////////////////////////////////////////////////// -OperationSettings::OperationSettings(bool* exclude_clock_buffers, - const bool new_exclude_clock_buffers, - sta::LibertyCellSeq* buffer_cells) +template +SetAndRestore::SetAndRestore(T& storage, const T& new_value) + : storage_(storage), old_value_(storage) { - if (exclude_clock_buffers) { - exclude_clock_buffers_ = exclude_clock_buffers; - prev_exclude_clock_buffers_ = *exclude_clock_buffers_; - *exclude_clock_buffers_ = new_exclude_clock_buffers; - } - - if (buffer_cells) { - buffer_cells_ = buffer_cells; - buffer_cells_->clear(); - } + storage_ = new_value; } -OperationSettings::OperationSettings( - sta::LibertyCellSeq* buffer_cells, - const sta::LibertyCellSeq& new_buffer_cells) +template +SetAndRestore::~SetAndRestore() { - if (buffer_cells) { - buffer_cells_ = buffer_cells; - *buffer_cells_ = new_buffer_cells; - } + storage_ = old_value_; } -OperationSettings::~OperationSettings() -{ - if (exclude_clock_buffers_) { - *exclude_clock_buffers_ = prev_exclude_clock_buffers_; - } - - if (buffer_cells_) { - buffer_cells_->clear(); - } -} +//////////////////////////////////////////////////////////////// void Resizer::repairHold( double setup_margin, @@ -2900,9 +2878,11 @@ void Resizer::repairHold( // until we have a better approach, it's better to consider clock buffers // for hold violation repairing as these buffers' delay may be slighty // higher and we'll need fewer insertions. - OperationSettings operation_settings(&exclude_clock_buffers_, - false /*new_exclude_clock_buffers*/, - &buffer_cells_); + // Obs: We need to clear the buffer list for the preamble to select + // buffers again excluding the clock ones. + SetAndRestore set_exclude_clk_buffers(exclude_clock_buffers_, false); + SetAndRestore set_buffers(buffer_cells_, LibertyCellSeq()); + resizePreamble(); if (parasitics_src_ == ParasiticsSrc::global_routing) { opendp_->initMacrosAndGrid(); @@ -2923,9 +2903,9 @@ void Resizer::repairHold(const Pin* end_pin, int max_passes) { // See comment on the method above. - OperationSettings operation_settings(&exclude_clock_buffers_, - false /*new_exclude_clock_buffers*/, - &buffer_cells_); + SetAndRestore set_exclude_clk_buffers(exclude_clock_buffers_, false); + SetAndRestore set_buffers(buffer_cells_, LibertyCellSeq()); + resizePreamble(); repair_hold_->repairHold(end_pin, setup_margin,