diff --git a/src/rsz/src/Resizer.cc b/src/rsz/src/Resizer.cc index ce6a7303876..19ff1b7af6f 100644 --- a/src/rsz/src/Resizer.cc +++ b/src/rsz/src/Resizer.cc @@ -66,6 +66,7 @@ #include "sta/TimingModel.hh" #include "sta/Units.hh" #include "utl/Logger.h" +#include "utl/scope.h" // http://vlsicad.eecs.umich.edu/BK/Slots/cache/dropzone.tamu.edu/~zhuoli/GSRC/fast_buffer_insertion.html @@ -2689,14 +2690,9 @@ void Resizer::repairNet(Net* net, void Resizer::repairClkNets(double max_wire_length) { resizePreamble(); - - // Use the buffers that were selected by CTS. - buffer_cells_ = clk_buffers_; + utl::SetAndRestore set_buffers(buffer_cells_, clk_buffers_); repair_design_->repairClkNets(max_wire_length); - - // Reset so that the next preamble select data buffers again. - buffer_cells_.clear(); } //////////////////////////////////////////////////////////////// @@ -2864,13 +2860,16 @@ void Resizer::repairHold( int max_passes, bool verbose) { - buffer_cells_.clear(); - // Some technologies such as nangate45 don't have delay cells. Hence, // 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. - exclude_clock_buffers_ = false; + // Obs: We need to clear the buffer list for the preamble to select + // buffers again excluding the clock ones. + utl::SetAndRestore set_exclude_clk_buffers(exclude_clock_buffers_, + false); + utl::SetAndRestore set_buffers(buffer_cells_, + LibertyCellSeq()); resizePreamble(); if (parasitics_src_ == ParasiticsSrc::global_routing) { @@ -2882,10 +2881,6 @@ void Resizer::repairHold( max_buffer_percent, max_passes, verbose); - - // Reset buffer selection strategy for the subsequent RSZ operation. - exclude_clock_buffers_ = true; - buffer_cells_.clear(); } void Resizer::repairHold(const Pin* end_pin, @@ -2895,10 +2890,11 @@ void Resizer::repairHold(const Pin* end_pin, float max_buffer_percent, int max_passes) { - buffer_cells_.clear(); - - // See comments on previous method. - exclude_clock_buffers_ = false; + // See comment on the method above. + utl::SetAndRestore set_exclude_clk_buffers(exclude_clock_buffers_, + false); + utl::SetAndRestore set_buffers(buffer_cells_, + LibertyCellSeq()); resizePreamble(); repair_hold_->repairHold(end_pin, @@ -2907,10 +2903,6 @@ void Resizer::repairHold(const Pin* end_pin, allow_setup_violations, max_buffer_percent, max_passes); - - // Ditto. - exclude_clock_buffers_ = true; - buffer_cells_.clear(); } int Resizer::holdBufferCount() const diff --git a/src/utl/include/utl/scope.h b/src/utl/include/utl/scope.h new file mode 100644 index 00000000000..959ca84f5e8 --- /dev/null +++ b/src/utl/include/utl/scope.h @@ -0,0 +1,58 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2024, Precision Innovations Inc +// All rights reserved. +// +// BSD 3-Clause License +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +#pragma once + +namespace utl { + +// RAII mechanism to facilitate using operation-specific settings. +template +class SetAndRestore +{ + public: + SetAndRestore(T& storage, const T& new_value) + : storage_(storage), old_value_(storage) + { + storage_ = new_value; + } + + ~SetAndRestore() { storage_ = old_value_; } + + private: + T& storage_; + T old_value_; +}; + +} // namespace utl \ No newline at end of file