Skip to content
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
16 changes: 8 additions & 8 deletions src/rmp/include/rmp/Restructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ namespace rmp {

enum class Mode
{
AREA_1 = 0,
AREA_2,
AREA_3,
DELAY_1,
DELAY_2,
DELAY_3,
DELAY_4
kArea1 = 0,
kArea2,
kArea3,
kDelay1,
kDelay2,
kDelay3,
kDelay4
};

class Restructure
Expand Down Expand Up @@ -165,7 +165,7 @@ class Restructure
std::vector<std::string> lib_file_names_;
std::set<odb::dbInst*> path_insts_;

Mode opt_mode_{Mode::DELAY_1};
Mode opt_mode_{Mode::kDelay1};
bool is_area_mode_{false};
int blif_call_id_{0};
};
Expand Down
87 changes: 43 additions & 44 deletions src/rmp/src/Restructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ void Restructure::runABC()
"Constants before remap {}",
countConsts(block_));

Blif blif_(
Blif blif(
logger_, open_sta_, locell_, loport_, hicell_, hiport_, ++blif_call_id_);
blif_.setReplaceableInstances(path_insts_);
blif_.writeBlif(input_blif_file_name_.c_str(), !is_area_mode_);
blif.setReplaceableInstances(path_insts_);
blif.writeBlif(input_blif_file_name_.c_str(), !is_area_mode_);
debugPrint(
logger_, RMP, "remap", 1, "Writing blif file {}", input_blif_file_name_);
files_to_remove.emplace_back(input_blif_file_name_);
Expand All @@ -206,10 +206,10 @@ void Restructure::runABC()

if (is_area_mode_) {
// Area Mode
modes = {Mode::AREA_1, Mode::AREA_2, Mode::AREA_3};
modes = {Mode::kArea1, Mode::kArea2, Mode::kArea3};
} else {
// Delay Mode
modes = {Mode::DELAY_1, Mode::DELAY_2, Mode::DELAY_3, Mode::DELAY_4};
modes = {Mode::kDelay1, Mode::kDelay2, Mode::kDelay3, Mode::kDelay4};
}

child_proc.resize(modes.size(), 0);
Expand Down Expand Up @@ -274,8 +274,7 @@ void Restructure::runABC()
int num_instances = 0;
bool success = readAbcLog(abc_log_name, level_gain, delay);
if (success) {
success
= blif_.inspectBlif(output_blif_file_name_.c_str(), num_instances);
success = blif.inspectBlif(output_blif_file_name_.c_str(), num_instances);
logger_->report(
"Optimized to {} instances in iteration {} with max path depth "
"decrease of {}, delay of {}.",
Expand All @@ -293,7 +292,7 @@ void Restructure::runABC()
} else {
// Using only DELAY_4 for delay based gain since other modes not
// showing good gains
if (modes[curr_mode_idx] == Mode::DELAY_4) {
if (modes[curr_mode_idx] == Mode::kDelay4) {
best_delay_gain = delay;
best_blif = output_blif_file_name_;
}
Expand All @@ -307,7 +306,7 @@ void Restructure::runABC()
|| best_delay_gain < std::numeric_limits<float>::max()) {
// read back netlist
debugPrint(logger_, RMP, "remap", 1, "Reading blif file {}.", best_blif);
blif_.readBlif(best_blif.c_str(), block_);
blif.readBlif(best_blif.c_str(), block_);
debugPrint(logger_,
utl::RMP,
"remap",
Expand Down Expand Up @@ -373,21 +372,21 @@ void Restructure::getEndPoints(sta::PinSet& ends,
if (!errors.empty() && errors[0]->size() > 1) {
sta::CheckError* error = errors[0];
bool first = true;
for (auto pinName : *error) {
debugPrint(logger_, RMP, "remap", 1, "Unconstrained pin: {}", pinName);
if (!first && open_sta_->getDbNetwork()->findPin(pinName.c_str())) {
ends.insert(open_sta_->getDbNetwork()->findPin(pinName.c_str()));
for (auto pin_name : *error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy]

Suggested change
for (auto pin_name : *error) {
for (const auto& pin_name : *error) {

debugPrint(logger_, RMP, "remap", 1, "Unconstrained pin: {}", pin_name);
if (!first && open_sta_->getDbNetwork()->findPin(pin_name.c_str())) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: redundant call to 'c_str' [readability-redundant-string-cstr]

Suggested change
if (!first && open_sta_->getDbNetwork()->findPin(pin_name.c_str())) {
if (!first && open_sta_->getDbNetwork()->findPin(pin_name)) {

ends.insert(open_sta_->getDbNetwork()->findPin(pin_name.c_str()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: redundant call to 'c_str' [readability-redundant-string-cstr]

Suggested change
ends.insert(open_sta_->getDbNetwork()->findPin(pin_name.c_str()));
ends.insert(open_sta_->getDbNetwork()->findPin(pin_name));

}
first = false;
}
Comment on lines +375 to 381

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Iterating by value causes unnecessary string copies. Additionally, following the principle of analyzing loop structures to avoid redundancy, findPin should not be called multiple times for the same pin. Consider using a reference and caching the result to improve efficiency.

Suggested change
for (auto pin_name : *error) {
debugPrint(logger_, RMP, "remap", 1, "Unconstrained pin: {}", pin_name);
if (!first && open_sta_->getDbNetwork()->findPin(pin_name.c_str())) {
ends.insert(open_sta_->getDbNetwork()->findPin(pin_name.c_str()));
}
first = false;
}
for (const auto& pin_name : *error) {
debugPrint(logger_, RMP, "remap", 1, "Unconstrained pin: {}", pin_name);
if (!first) {
if (auto* pin = open_sta_->getDbNetwork()->findPin(pin_name.c_str())) {
ends.insert(pin);
}
}
first = false;
}
References
  1. When analyzing code within a loop, consider the entire loop structure to identify and remove redundant operations within the loop body.

}
if (errors.size() > 1 && errors[1]->size() > 1) {
sta::CheckError* error = errors[1];
bool first = true;
for (auto pinName : *error) {
debugPrint(logger_, RMP, "remap", 1, "Unclocked pin: {}", pinName);
if (!first && open_sta_->getDbNetwork()->findPin(pinName.c_str())) {
ends.insert(open_sta_->getDbNetwork()->findPin(pinName.c_str()));
for (auto pin_name : *error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: loop variable is copied but only used as const reference; consider making it a const reference [performance-for-range-copy]

Suggested change
for (auto pin_name : *error) {
for (const auto& pin_name : *error) {

debugPrint(logger_, RMP, "remap", 1, "Unclocked pin: {}", pin_name);
if (!first && open_sta_->getDbNetwork()->findPin(pin_name.c_str())) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: redundant call to 'c_str' [readability-redundant-string-cstr]

Suggested change
if (!first && open_sta_->getDbNetwork()->findPin(pin_name.c_str())) {
if (!first && open_sta_->getDbNetwork()->findPin(pin_name)) {

ends.insert(open_sta_->getDbNetwork()->findPin(pin_name.c_str()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: redundant call to 'c_str' [readability-redundant-string-cstr]

Suggested change
ends.insert(open_sta_->getDbNetwork()->findPin(pin_name.c_str()));
ends.insert(open_sta_->getDbNetwork()->findPin(pin_name));

}
first = false;
}
Comment on lines +386 to 392

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Iterating by value causes unnecessary string copies. Additionally, following the principle of analyzing loop structures to avoid redundancy, findPin should not be called multiple times for the same pin. Consider using a reference and caching the result to improve efficiency.

      for (const auto& pin_name : *error) {
        debugPrint(logger_, RMP, "remap", 1, "Unclocked pin: {}", pin_name);
        if (!first) {
          if (auto* pin = open_sta_->getDbNetwork()->findPin(pin_name.c_str())) {
            ends.insert(pin);
          }
        }
        first = false;
      }
References
  1. When analyzing code within a loop, consider the entire loop structure to identify and remove redundant operations within the loop body.

Expand Down Expand Up @@ -439,7 +438,7 @@ void Restructure::removeConstCells()

open_sta_->clearLogicConstants();
open_sta_->findLogicConstants();
std::set<odb::dbInst*> constInsts;
std::set<odb::dbInst*> const_insts;
int const_cnt = 1;
for (auto inst : block_->getInsts()) {
int outputs = 0;
Expand All @@ -462,16 +461,16 @@ void Restructure::removeConstCells()
}
outputs++;
auto pin = open_sta_->getDbNetwork()->dbToSta(iterm);
sta::LogicValue pinVal
sta::LogicValue pin_val
= open_sta_->simLogicValue(pin, open_sta_->cmdMode());
if (pinVal == sta::LogicValue::one || pinVal == sta::LogicValue::zero) {
if (pin_val == sta::LogicValue::one || pin_val == sta::LogicValue::zero) {
odb::dbNet* net = iterm->getNet();
if (net) {
odb::dbMaster* const_master = (pinVal == sta::LogicValue::one)
odb::dbMaster* const_master = (pin_val == sta::LogicValue::one)
? hicell_master
: locell_master;
odb::dbMTerm* const_port
= (pinVal == sta::LogicValue::one) ? hiterm : loterm;
= (pin_val == sta::LogicValue::one) ? hiterm : loterm;
Comment on lines +469 to +473

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The condition pin_val == sta::LogicValue::one is evaluated twice. Storing the result in a descriptive boolean variable improves readability and provides a minor performance optimization.

Suggested change
odb::dbMaster* const_master = (pin_val == sta::LogicValue::one)
? hicell_master
: locell_master;
odb::dbMTerm* const_port
= (pinVal == sta::LogicValue::one) ? hiterm : loterm;
= (pin_val == sta::LogicValue::one) ? hiterm : loterm;
const bool is_one = (pin_val == sta::LogicValue::one);
odb::dbMaster* const_master = is_one ? hicell_master : locell_master;
odb::dbMTerm* const_port = is_one ? hiterm : loterm;

std::string inst_name = "rmp_const_" + std::to_string(const_cnt);
debugPrint(logger_,
RMP,
Expand All @@ -495,19 +494,19 @@ void Restructure::removeConstCells()
}
}
if (outputs > 0 && outputs == const_outputs) {
constInsts.insert(inst);
const_insts.insert(inst);
}
}
open_sta_->clearLogicConstants();

debugPrint(
logger_, RMP, "remap", 2, "Removing {} instances...", constInsts.size());
logger_, RMP, "remap", 2, "Removing {} instances...", const_insts.size());

for (auto inst : constInsts) {
for (auto inst : const_insts) {
removeConstCell(inst);
}
logger_->report("Removed {} instances with constant outputs.",
constInsts.size());
const_insts.size());
}

void Restructure::removeConstCell(odb::dbInst* inst)
Expand Down Expand Up @@ -572,19 +571,19 @@ void Restructure::writeOptCommands(std::ofstream& script)
script << choice << '\n';
script << choice2 << '\n';

if (opt_mode_ == Mode::AREA_3) {
if (opt_mode_ == Mode::kArea3) {
script << "choice2\n"; // << "scleanup" << std::endl;
} else {
script << "resyn2\n"; // << "scleanup" << std::endl;
}

switch (opt_mode_) {
case Mode::DELAY_1: {
case Mode::kDelay1: {
script << "map -D 0.01 -A 0.9 -B 0.2 -M 0 -p\n";
script << "buffer -p -c\n";
break;
}
case Mode::DELAY_2: {
case Mode::kDelay2: {
script << "choice\n";
script << "map -D 0.01 -A 0.9 -B 0.2 -M 0 -p\n";
script << "choice\n";
Expand All @@ -593,7 +592,7 @@ void Restructure::writeOptCommands(std::ofstream& script)
<< "topo\n";
break;
}
case Mode::DELAY_3: {
case Mode::kDelay3: {
script << "choice2\n";
script << "map -D 0.01 -A 0.9 -B 0.2 -M 0 -p\n";
script << "choice2\n";
Expand All @@ -602,23 +601,23 @@ void Restructure::writeOptCommands(std::ofstream& script)
<< "topo\n";
break;
}
case Mode::DELAY_4: {
case Mode::kDelay4: {
script << "choice2\n";
script << "amap -F 20 -A 20 -C 5000 -Q 0.1 -m\n";
script << "choice2\n";
script << "map -D 0.01 -A 0.9 -B 0.2 -M 0 -p\n";
script << "buffer -p -c\n";
break;
}
case Mode::AREA_2:
case Mode::AREA_3: {
case Mode::kArea2:
case Mode::kArea3: {
script << "choice2\n";
script << "amap -m -Q 0.1 -F 20 -A 20 -C 5000\n";
script << "choice2\n";
script << "amap -m -Q 0.1 -F 20 -A 20 -C 5000\n";
break;
}
case Mode::AREA_1:
case Mode::kArea1:
default: {
script << "choice2\n";
script << "amap -m -Q 0.1 -F 20 -A 20 -C 5000\n";
Expand All @@ -633,27 +632,27 @@ void Restructure::setMode(const char* mode_name)

if (!strcmp(mode_name, "timing")) {
is_area_mode_ = false;
opt_mode_ = Mode::DELAY_1;
opt_mode_ = Mode::kDelay1;
} else if (!strcmp(mode_name, "area")) {
opt_mode_ = Mode::AREA_1;
opt_mode_ = Mode::kArea1;
} else {
logger_->warn(RMP, 10, "Mode {} not recognized.", mode_name);
}
}

void Restructure::setTieHiPort(sta::LibertyPort* tieHiPort)
void Restructure::setTieHiPort(sta::LibertyPort* tie_hi_port)
{
if (tieHiPort) {
hicell_ = tieHiPort->libertyCell()->name();
hiport_ = tieHiPort->name();
if (tie_hi_port) {
hicell_ = tie_hi_port->libertyCell()->name();
hiport_ = tie_hi_port->name();
}
}

void Restructure::setTieLoPort(sta::LibertyPort* tieLoPort)
void Restructure::setTieLoPort(sta::LibertyPort* tie_lo_port)
{
if (tieLoPort) {
locell_ = tieLoPort->libertyCell()->name();
loport_ = tieLoPort->name();
if (tie_lo_port) {
locell_ = tie_lo_port->libertyCell()->name();
loport_ = tie_lo_port->name();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/rmp/src/delay_optimization_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "utl/deleter.h"

namespace abc {
// NOLINTBEGIN(readability-identifier-naming)
extern Abc_Ntk_t* Abc_NtkMap(Abc_Ntk_t* pNtk,
Mio_Library_t* userLib,
double DelayTarget,
Expand All @@ -37,6 +38,7 @@ extern Abc_Ntk_t* Abc_NtkMap(Abc_Ntk_t* pNtk,
int fVerbose);
extern void Abc_FrameSetLibGen(void* pLib);
extern void Abc_FrameSetDrivingCell(char* pName);
// NOLINTEND(readability-identifier-naming)
} // namespace abc

namespace rmp {
Expand Down
14 changes: 7 additions & 7 deletions src/rmp/src/genetic_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ std::vector<GiaOp> GeneticStrategy::RunStrategy(
// Selection
std::ranges::stable_sort(
population, std::ranges::greater{}, &SolutionSlack::WorstSlack);
std::vector<SolutionSlack> newPopulation;
newPopulation.reserve(population_size_);
std::vector<SolutionSlack> new_population;
new_population.reserve(population_size_);
for (int j = 0; j < population_size_; j++) {
std::vector<size_t> tournament(tournament_size_);
std::generate_n(tournament.begin(), tournament_size_, [&]() {
Expand All @@ -141,17 +141,17 @@ std::vector<GiaOp> GeneticStrategy::RunStrategy(
static_cast<double>(tournament_probability_));
});
if (winner != tournament.end()) {
newPopulation.emplace_back(population[*winner]);
new_population.emplace_back(population[*winner]);
}
}
removeDuplicates(newPopulation, logger);
removeDuplicates(new_population, logger);

// No winners from tournament, use first candidate
if (newPopulation.empty()) {
newPopulation.emplace_back(population.front());
if (new_population.empty()) {
new_population.emplace_back(population.front());
}

population = std::move(newPopulation);
population = std::move(new_population);

for (const auto& candidate : population) {
debugPrint(logger, RMP, "genetic", 1, candidate.toString());
Expand Down
2 changes: 2 additions & 0 deletions src/rmp/src/gia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "utl/unique_name.h"

namespace abc {
// NOLINTBEGIN(readability-identifier-naming)
extern Abc_Ntk_t* Abc_NtkFromAigPhase(Aig_Man_t* pMan);
extern Abc_Ntk_t* Abc_NtkFromCellMappedGia(Gia_Man_t* p, int fUseBuffs);
extern Abc_Ntk_t* Abc_NtkFromDarChoices(Abc_Ntk_t* pNtkOld, Aig_Man_t* pMan);
Expand Down Expand Up @@ -79,6 +80,7 @@ extern Vec_Ptr_t* Abc_NtkCollectCiNames(Abc_Ntk_t* pNtk);
extern Vec_Ptr_t* Abc_NtkCollectCoNames(Abc_Ntk_t* pNtk);
extern void Abc_NtkRedirectCiCo(Abc_Ntk_t* pNtk);
extern void Abc_FrameSetLibGen(void* pLib);
// NOLINTEND(readability-identifier-naming)
} // namespace abc

namespace rmp {
Expand Down
14 changes: 7 additions & 7 deletions src/rmp/src/slack_tuning_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ std::string SolutionSlack::toString() const
return "[]";
}

std::ostringstream resStream;
resStream << '[' << std::to_string(solution_.front().id);
std::ostringstream res_stream;
res_stream << '[' << std::to_string(solution_.front().id);
for (int i = 1; i < solution_.size(); i++) {
resStream << ", " << std::to_string(solution_[i].id);
res_stream << ", " << std::to_string(solution_[i].id);
}
resStream << "], worst slack: ";
res_stream << "], worst slack: ";

if (worst_slack_) {
resStream << *worst_slack_;
res_stream << *worst_slack_;
} else {
resStream << "not computed";
res_stream << "not computed";
}
return resStream.str();
return res_stream.str();
}

SolutionSlack::ResultOps SolutionSlack::RandomNeighbor(
Expand Down
Loading
Loading