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

rmp: use std::atomic for Blif::call_id_ static data member #5989

Closed
Closed
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
6 changes: 5 additions & 1 deletion src/rmp/include/rmp/blif.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <stdio.h>
#include <unistd.h>

#include <atomic>
#include <map>
#include <set>
#include <string>
Expand Down Expand Up @@ -90,7 +91,10 @@ class Blif
std::string const1_cell_port_;
std::map<std::string, std::pair<float, float>> requireds_;
std::map<std::string, std::pair<float, float>> arrivals_;
static int call_id_;
// uniquely identifies an instantiation of this class
int instance_id_;
// class member: keeps track of how many instances were created; thread safe.
static std::atomic<int> instance_counter_;
};

} // namespace rmp
16 changes: 8 additions & 8 deletions src/rmp/src/blif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ using utl::RMP;

namespace rmp {

int Blif::call_id_ = 0;
std::atomic<int> Blif::instance_counter_{1};

Blif::Blif(Logger* logger,
sta::dbSta* sta,
Expand All @@ -77,7 +77,7 @@ Blif::Blif(Logger* logger,
{
logger_ = logger;
open_sta_ = sta;
call_id_++;
instance_id_ = instance_counter_.fetch_add(1);
Copy link
Member

Choose a reason for hiding this comment

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

Equivalent to instance_id_ = instance_counter_++;

}

void Blif::setReplaceableInstances(std::set<odb::dbInst*>& insts)
Expand Down Expand Up @@ -484,7 +484,7 @@ bool Blif::readBlif(const char* file_name, odb::dbBlock* block)
odb::dbNet* net = block->findNet(constNetName.c_str());
if (net == nullptr) {
std::string net_name_modified
= std::string("or_") + std::to_string(call_id_) + constNetName;
= std::string("or_") + std::to_string(instance_id_) + constNetName;
net = odb::dbNet::create(block, net_name_modified.c_str());
}

Expand All @@ -495,7 +495,7 @@ bool Blif::readBlif(const char* file_name, odb::dbBlock* block)
= (masterName == "_const0_") ? const0_cell_port_ : const1_cell_port_;
instIds[constMaster]
= (instIds[constMaster]) ? instIds[constMaster] + 1 : 1;
std::string instName = constMaster + "_" + std::to_string(call_id_)
std::string instName = constMaster + "_" + std::to_string(instance_id_)
+ std::to_string(instIds[constMaster]);
for (auto&& lib : block->getDb()->getLibs()) {
master = lib->findMaster(constMaster.c_str());
Expand All @@ -507,7 +507,7 @@ bool Blif::readBlif(const char* file_name, odb::dbBlock* block)
if (master != nullptr) {
while (block->findInst(instName.c_str())) {
instIds[constMaster]++;
instName = constMaster + "_" + std::to_string(call_id_)
instName = constMaster + "_" + std::to_string(instance_id_)
+ std::to_string(instIds[constMaster]);
}
auto newInst = odb::dbInst::create(block, master, instName.c_str());
Expand All @@ -527,11 +527,11 @@ bool Blif::readBlif(const char* file_name, odb::dbBlock* block)
}

instIds[masterName] = (instIds[masterName]) ? instIds[masterName] + 1 : 1;
std::string instName = masterName + "_" + std::to_string(call_id_) + "_"
std::string instName = masterName + "_" + std::to_string(instance_id_) + "_"
+ std::to_string(instIds[masterName]);
while (block->findInst(instName.c_str())) {
instIds[masterName]++;
instName = masterName + "_" + std::to_string(call_id_) + "_"
instName = masterName + "_" + std::to_string(instance_id_) + "_"
+ std::to_string(instIds[masterName]);
}

Expand Down Expand Up @@ -585,7 +585,7 @@ bool Blif::readBlif(const char* file_name, odb::dbBlock* block)
odb::dbNet* net = block->findNet(netName.c_str());
if (net == nullptr) {
std::string net_name_modified
= std::string("or_") + std::to_string(call_id_) + netName;
= std::string("or_") + std::to_string(instance_id_) + netName;
net = block->findNet(net_name_modified.c_str());
if (!net)
net = odb::dbNet::create(block, net_name_modified.c_str());
Expand Down