Skip to content

Commit

Permalink
cts: clang-tidy cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Liberty <[email protected]>
  • Loading branch information
maliberty committed Jan 24, 2025
1 parent 1b033ea commit ae97cf1
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/cts/src/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Box<int> Clock::computeSinkRegion()
}

Box<double> Clock::computeSinkRegionClustered(
std::vector<std::pair<float, float>> sinks)
const std::vector<std::pair<float, float>>& sinks)
{
auto xMin = std::numeric_limits<float>::max();
auto xMax = std::numeric_limits<float>::lowest();
Expand Down
2 changes: 1 addition & 1 deletion src/cts/src/Clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class Clock

Box<int> computeSinkRegion();
Box<double> computeSinkRegionClustered(
std::vector<std::pair<float, float>> sinks);
const std::vector<std::pair<float, float>>& sinks);
Box<double> computeNormalizedSinkRegion(double factor);

void report(utl::Logger* logger) const;
Expand Down
6 changes: 4 additions & 2 deletions src/cts/src/Clustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ using utl::CTS;
struct Sink
{
Sink(const float x, const float y, const unsigned idx)
: x(x), y(y), cluster_idx(-1), sink_idx(idx){};
: x(x), y(y), sink_idx(idx)
{
}

// location
const float x, y;
int cluster_idx;
int cluster_idx{-1};
const unsigned sink_idx; // index in sinks_
};

Expand Down
12 changes: 6 additions & 6 deletions src/cts/src/HTreeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ void HTreeBuilder::preSinkClustering(
(float) inst.getY() / wireSegmentUnit_);
mapLocationToSink_[normLocation] = &inst;
if (!fuzzyEqual(inst.getInsertionDelay(), 0.0, 1e-6)) {
setSinkInsertionDelay(
normLocation, (double) inst.getInsertionDelay() / wireSegmentUnit_);
setSinkInsertionDelay(normLocation,
inst.getInsertionDelay() / wireSegmentUnit_);
// clang-format off
debugPrint(logger_, CTS, "clustering", 1, "sink {} has insDelay {} at {}",
inst.getName(), getSinkInsertionDelay(normLocation),
Expand Down Expand Up @@ -358,7 +358,7 @@ void plotBlockage(std::ofstream& file, odb::dbDatabase* db_, int scalingFactor)
int h = bbox->yMax() / scalingFactor - bbox->yMin() / scalingFactor;
file << i++ << " " << x << " " << y << " " << w << " " << h
<< " block scalingFactor=";
file << scalingFactor << " " << blockage->getId() << std::endl;
file << scalingFactor << " " << blockage->getId() << '\n';
}
}

Expand All @@ -385,7 +385,7 @@ void plotSinks(std::ofstream& file, const std::vector<Point<double>>& sinks)
double h = 1;
auto name = "sink_";
file << cnt++ << " " << x << " " << y << " " << w << " " << h;
file << " " << name << " " << std::endl;
file << " " << name << '\n';
}
}

Expand Down Expand Up @@ -1252,7 +1252,7 @@ std::string HTreeBuilder::plotHTree()
double y2 = branchPoint.getY();
std::string name = "buffer";
file << levelIdx << " " << x1 << " " << y1 << " " << x2 << " " << y2;
file << " " << name << std::endl;
file << " " << name << '\n';
});
}

Expand All @@ -1271,7 +1271,7 @@ std::string HTreeBuilder::plotHTree()

file << numSinks << " " << loc.getX() << " " << loc.getY();
file << " " << px << " " << py << " leafbuffer " << name2;
file << " z=" << wireSegmentUnit_ << std::endl;
file << " z=" << wireSegmentUnit_ << '\n';
++numSinks;
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/cts/src/HTreeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class HTreeBuilder : public TreeBuilder
public:
static constexpr unsigned NO_PARENT = std::numeric_limits<unsigned>::max();

explicit LevelTopology(double length) : length_(length){};
explicit LevelTopology(double length) : length_(length) {}

void addWireSegment(unsigned idx) { wireSegments_.push_back(idx); }

Expand Down
2 changes: 1 addition & 1 deletion src/cts/src/LevelBalancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ unsigned LevelBalancer::computeMaxTreeDepth(TreeBuilder* parent)
}

void LevelBalancer::addBufferLevels(TreeBuilder* builder,
const std::vector<ClockInst*> cluster,
const std::vector<ClockInst*>& cluster,
ClockSubNet* driverNet,
const unsigned bufLevels,
const std::string& nameSuffix)
Expand Down
2 changes: 1 addition & 1 deletion src/cts/src/LevelBalancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class LevelBalancer

void run();
void addBufferLevels(TreeBuilder* builder,
std::vector<ClockInst*> cluster,
const std::vector<ClockInst*>& cluster,
ClockSubNet* driverNet,
unsigned bufLevels,
const std::string& nameSuffix);
Expand Down
26 changes: 14 additions & 12 deletions src/cts/src/SinkClustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
Expand Down Expand Up @@ -307,9 +308,9 @@ bool SinkClustering::findBestMatching(const unsigned groupSize)
// Add vectors in case they are no allocated yet. (Depends if a new
// cluster was defined above)
if (solutions[j].size() < (clusters[j] + 1)) {
solutions[j].push_back({});
solutionPoints[j].push_back({});
solutionPointsIdx[j].push_back({});
solutions[j].emplace_back();
solutionPoints[j].emplace_back();
solutionPointsIdx[j].emplace_back();
}
// Save the current Point in it's respective cluster. (Depends if a new
// cluster was defined above)
Expand All @@ -326,9 +327,9 @@ bool SinkClustering::findBestMatching(const unsigned groupSize)
// one late).
for (unsigned j = (i + 1); j < groupSize; ++j) {
if (solutions[j].size() < (clusters[j] + 1)) {
solutions[j].push_back({});
solutionPoints[j].push_back({});
solutionPointsIdx[j].push_back({});
solutions[j].emplace_back();
solutionPoints[j].emplace_back();
solutionPointsIdx[j].emplace_back();
}
// Thus here we will assign the Points missing from those solutions.
const unsigned idx = thetaIndexVector_[i].second;
Expand Down Expand Up @@ -372,9 +373,9 @@ bool SinkClustering::findBestMatching(const unsigned groupSize)
}
}
if (solutions[j].size() < (clusters[j] + 1)) {
solutions[j].push_back({});
solutionPoints[j].push_back({});
solutionPointsIdx[j].push_back({});
solutions[j].emplace_back();
solutionPoints[j].emplace_back();
solutionPointsIdx[j].emplace_back();
}
solutionPoints[j][clusters[j]].push_back(p);
solutionPointsIdx[j][clusters[j]].push_back(idx);
Expand Down Expand Up @@ -417,11 +418,12 @@ bool SinkClustering::findBestMatching(const unsigned groupSize)
if (logger_->debugCheck(CTS, "clustering", 2)) {
size_t solnIndex = 0;
for (const std::vector<unsigned>& soln : bestSolution_) {
std::cout << "Solution " << solnIndex << "[" << soln.size() << "]: ";
std::ostringstream s;
s << "Solution " << solnIndex << "[" << soln.size() << "]: ";
for (const unsigned i : soln) {
std::cout << i << " ";
s << i << " ";
}
std::cout << std::endl;
logger_->debug(CTS, "clustering", "{}", s.str());
++solnIndex;
}
}
Expand Down
74 changes: 41 additions & 33 deletions src/cts/src/TechChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,32 +480,34 @@ void TechChar::initCharacterization()
float maxBuffCap = 0.0;
std::string bufMasterName;
std::vector<float> axisSlews, axisLoads;
for (int i = 0; i < masterVector.size(); i++) {
for (const std::string& master_name : masterVector) {
float maxCap = 0.0;
bool maxCapExist = false;
odb::dbMaster* buf = db_->findMaster(masterVector[i].c_str());
odb::dbMaster* buf = db_->findMaster(master_name.c_str());
sta::Cell* masterCell = db_network_->dbToSta(buf);
sta::LibertyCell* libertyCell = db_network_->libertyCell(masterCell);
sta::LibertyPort *input, *output;
libertyCell->bufferPorts(input, output);
output->capacitanceLimit(sta::MinMax::max(), maxCap, maxCapExist);
sta::LibertyLibrary* lib = libertyCell->libertyLibrary();
if (!maxCapExist)
if (!maxCapExist) {
lib->defaultMaxCapacitance(maxCap, maxCapExist);
if (!maxCapExist)
}
if (!maxCapExist) {
logger_->error(
CTS, 111, "No max capacitance found for cell {}.", masterVector[i]);
CTS, 111, "No max capacitance found for cell {}.", master_name);
}
if (maxCap >= maxBuffCap) {
maxBuffCap = maxCap;
charBuf_ = buf;
bufMasterName = masterVector[i];
bufMasterName = master_name;
}
// collect slews and caps from NLDM table axis from all buffers in list
collectSlewsLoadsFromTableAxis(
libertyCell, input, output, axisSlews, axisLoads);
}

if (bufMasterName == "") {
if (bufMasterName.empty()) {
logger_->error(
CTS,
113,
Expand Down Expand Up @@ -573,7 +575,7 @@ void TechChar::initCharacterization()
wirelengthsToTest_.push_back(wirelengthInter);
}

if (wirelengthsToTest_.size() < 1) {
if (wirelengthsToTest_.empty()) {
logger_->error(
CTS,
75,
Expand Down Expand Up @@ -608,16 +610,19 @@ void TechChar::initCharacterization()
if (!maxSlewExist) {
lib->defaultMaxSlew(maxSlew, maxSlewExist);
}
if (!maxSlewExist)
if (!maxSlewExist) {
logger_->error(
CTS, 107, "No max slew found for cell {}.", bufMasterName);
}

output->capacitanceLimit(sta::MinMax::max(), maxCap, maxCapExist);
if (!maxCapExist)
if (!maxCapExist) {
lib->defaultMaxCapacitance(maxCap, maxCapExist);
if (!maxCapExist)
}
if (!maxCapExist) {
logger_->error(
CTS, 108, "No max capacitance found for cell {}.", bufMasterName);
}
options_->setMaxCharSlew(maxSlew);
options_->setMaxCharCap(maxCap);
}
Expand Down Expand Up @@ -812,13 +817,13 @@ void TechChar::collectSlewsLoadsFromTableAxis(sta::LibertyCell* libCell,
}
}
if (slews) {
for (size_t i = 0; i < slews->size(); ++i) {
axisSlews.push_back((*slews)[i]);
for (const float slew : *slews) {
axisSlews.push_back(slew);
}
}
if (loads) {
for (size_t i = 0; i < loads->size(); ++i) {
axisLoads.push_back((*loads)[i]);
for (const float load : *loads) {
axisLoads.push_back(load);
}
}
}
Expand Down Expand Up @@ -960,18 +965,19 @@ std::vector<TechChar::SolutionData> TechChar::createPatterns(
solutionCounterInt++) {
// Creates a bitset that represents the buffer locations.
const std::bitset<5> solutionCounter(solutionCounterInt);
unsigned short int wireCounter = 0;
int wireCounter = 0;
SolutionData topology;
// Creates the starting net.
const std::string netName = "net_" + std::to_string(setupWirelength) + "_"
+ solutionCounter.to_string() + "_"
+ std::to_string(wireCounter);
const std::string netName = fmt::format("net_{}_{}_{}",
setupWirelength,
solutionCounter.to_string(),
wireCounter);
net = odb::dbNet::create(charBlock_, netName.c_str());
odb::dbWire::create(net);
net->setSigType(odb::dbSigType::SIGNAL);
// Creates the input port.
const std::string inPortName
= "in_" + std::to_string(setupWirelength) + solutionCounter.to_string();
= fmt::format("in_{}{}", setupWirelength, solutionCounter.to_string());
odb::dbBTerm* inPort = odb::dbBTerm::create(
net, inPortName.c_str()); // sig type is signal by default
inPort->setIoType(odb::dbIoType::INPUT);
Expand All @@ -993,9 +999,10 @@ std::vector<TechChar::SolutionData> TechChar::createPatterns(
// Buffer, need to create the instance and a new net.
nodesWithoutBuf++;
// Creates a new buffer instance.
const std::string bufName = "buf_" + std::to_string(setupWirelength)
+ "_" + solutionCounter.to_string() + "_"
+ std::to_string(wireCounter);
const std::string bufName = fmt::format("buf_{}_{}_{}",
setupWirelength,
solutionCounter.to_string(),
wireCounter);
// clang-format off
debugPrint(logger_, CTS, "tech char", 1, " buffer {} at node:{} "
"topo:{}", bufName, nodeIndex, solutionCounterInt);
Expand All @@ -1011,9 +1018,10 @@ std::vector<TechChar::SolutionData> TechChar::createPatterns(
topology.nodesWithoutBufVector.push_back(nodesWithoutBuf);
// Creates a new net.
wireCounter++;
const std::string netName = "net_" + std::to_string(setupWirelength)
+ "_" + solutionCounter.to_string() + "_"
+ std::to_string(wireCounter);
const std::string netName = fmt::format("net_{}_{}_{}",
setupWirelength,
solutionCounter.to_string(),
wireCounter);
net = odb::dbNet::create(charBlock_, netName.c_str());
odb::dbWire::create(net);
bufInstanceOutPin->connect(net);
Expand All @@ -1034,8 +1042,8 @@ std::vector<TechChar::SolutionData> TechChar::createPatterns(
}
}
// Finishing up the topology with the output port.
const std::string outPortName = "out_" + std::to_string(setupWirelength)
+ solutionCounter.to_string();
const std::string outPortName
= fmt::format("out_{}{}", setupWirelength, solutionCounter.to_string());
odb::dbBTerm* outPort = odb::dbBTerm::create(
net, outPortName.c_str()); // sig type is signal by default
outPort->setIoType(odb::dbIoType::OUTPUT);
Expand Down Expand Up @@ -1454,7 +1462,7 @@ std::vector<TechChar::ResultData> TechChar::characterizationPostProcess()
// select only 3 of them.
for (auto& keyResults : solutionMap_) {
std::vector<ResultData> resultVector = keyResults.second;
for (ResultData selectedResults : resultVector) {
for (const ResultData& selectedResults : resultVector) {
selectedSolutions.push_back(selectedResults);
}
}
Expand Down Expand Up @@ -1506,8 +1514,8 @@ std::vector<TechChar::ResultData> TechChar::characterizationPostProcess()
if (std::find(masterNames_.begin(), masterNames_.end(), topologyS)
== masterNames_.end()) {
// Is a number (i.e. a wire segment).
topologyResult.push_back(std::to_string(
std::stod(topologyS) / static_cast<float>(solution.wirelength)));
topologyResult.push_back(
std::to_string(std::stod(topologyS) / solution.wirelength));
} else {
topologyResult.push_back(topologyS);
}
Expand Down Expand Up @@ -1559,7 +1567,7 @@ void TechChar::create()
}
// Setup of the attributes required to run the characterization.
initCharacterization();
long unsigned int topologiesCreated = 0;
int64_t topologiesCreated = 0;
for (unsigned setupWirelength : wirelengthsToTest_) {
// Creates the topologies for the current wirelength.
std::vector<SolutionData> topologiesVector
Expand Down Expand Up @@ -1738,7 +1746,7 @@ unsigned TechChar::getBufferingCombo(size_t numBuffers, size_t numNodes)
auto iter = bufferingComboTable_.find(iPair);
if (iter != bufferingComboTable_.end()) {
if (logger_->debugCheck(CTS, "tech char", 1)) {
tmp << "Monotonic entries (hashed): " << iter->second << std::endl;
tmp << "Monotonic entries (hashed): " << iter->second << '\n';
logger_->report(tmp.str());
}
return iter->second;
Expand Down
4 changes: 2 additions & 2 deletions src/cts/src/TritonCTS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ void TritonCTS::populateTritonCTS()
// Since a set is unique, only the nets not found by dbSta are added.
clockNets.insert(net);
}
clockNetsInfo.emplace_back(std::make_pair(clockNets, std::string("")));
clockNetsInfo.emplace_back(clockNets, "");
} else {
std::set<odb::dbNet*> allClkNets;
staClockNets_ = openSta_->findClkNets();
Expand All @@ -955,7 +955,7 @@ void TritonCTS::populateTritonCTS()
CTS, 114, "Clock {} overlaps a previous clock.", clkName);
}
}
clockNetsInfo.emplace_back(std::make_pair(clkNets, clkName));
clockNetsInfo.emplace_back(clkNets, clkName);
allClkNets.insert(clkNets.begin(), clkNets.end());
}
}
Expand Down

0 comments on commit ae97cf1

Please sign in to comment.