Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utl: add mechanism to make it easier to handle operation-specific settings #5995

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions src/rsz/src/Resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<LibertyCellSeq> 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();
}

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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<bool> set_exclude_clk_buffers(exclude_clock_buffers_,
false);
utl::SetAndRestore<LibertyCellSeq> set_buffers(buffer_cells_,
LibertyCellSeq());

resizePreamble();
if (parasitics_src_ == ParasiticsSrc::global_routing) {
Expand All @@ -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,
Expand All @@ -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<bool> set_exclude_clk_buffers(exclude_clock_buffers_,
false);
utl::SetAndRestore<LibertyCellSeq> set_buffers(buffer_cells_,
LibertyCellSeq());

resizePreamble();
repair_hold_->repairHold(end_pin,
Expand All @@ -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
Expand Down
58 changes: 58 additions & 0 deletions src/utl/include/utl/scope.h
Original file line number Diff line number Diff line change
@@ -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 <typename T>
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
Loading