Skip to content

Commit

Permalink
Merge pull request #6472 from The-OpenROAD-Project-staging/readabilit…
Browse files Browse the repository at this point in the history
…y-else-after-return

Fix readability-else-after-return in src/...
  • Loading branch information
maliberty authored Jan 5, 2025
2 parents 21623fa + b3b36ea commit d4eec05
Show file tree
Hide file tree
Showing 41 changed files with 447 additions and 542 deletions.
86 changes: 40 additions & 46 deletions src/dbSta/src/dbNetwork.cc
Original file line number Diff line number Diff line change
Expand Up @@ -677,35 +677,33 @@ const char* dbNetwork::name(const Port* port) const
if (isConcretePort(port)) {
const ConcretePort* cport = reinterpret_cast<const ConcretePort*>(port);
return cport->name();
} else {
dbMTerm* mterm = nullptr;
dbModBTerm* modbterm = nullptr;
dbBTerm* bterm = nullptr;
staToDb(port, bterm, mterm, modbterm);
std::string name;
if (bterm) {
name = bterm->getName();
}
if (mterm) {
name = mterm->getName();
}
if (modbterm) {
name = modbterm->getName();
}
}
dbMTerm* mterm = nullptr;
dbModBTerm* modbterm = nullptr;
dbBTerm* bterm = nullptr;
staToDb(port, bterm, mterm, modbterm);
std::string name;
if (bterm) {
name = bterm->getName();
}
if (mterm) {
name = mterm->getName();
}
if (modbterm) {
name = modbterm->getName();
}

if (name.empty()) {
return nullptr;
}
if (name.empty()) {
return nullptr;
}

if (hierarchy_) {
size_t last_idx = name.find_last_of('/');
if (last_idx != string::npos) {
name = name.substr(last_idx + 1);
}
if (hierarchy_) {
size_t last_idx = name.find_last_of('/');
if (last_idx != string::npos) {
name = name.substr(last_idx + 1);
}
return tmpStringCopy(name.c_str());
}
return nullptr;
return tmpStringCopy(name.c_str());
}

const char* dbNetwork::busName(const Port* port) const
Expand Down Expand Up @@ -1137,13 +1135,12 @@ ObjectId dbNetwork::id(const Pin* pin) const
dbObject* obj = reinterpret_cast<dbObject*>(const_cast<Pin*>(pin));
dbObjectType type = obj->getObjectType();
return getDbNwkObjectId(type, obj->getId());
} else {
if (iterm != nullptr) {
return iterm->getId() << 1;
}
if (bterm != nullptr) {
return (bterm->getId() << 1) + 1;
}
}
if (iterm != nullptr) {
return iterm->getId() << 1;
}
if (bterm != nullptr) {
return (bterm->getId() << 1) + 1;
}
return 0;
}
Expand Down Expand Up @@ -1499,10 +1496,8 @@ ObjectId dbNetwork::id(const Net* net) const
dbObject* obj = reinterpret_cast<dbObject*>(const_cast<Net*>(net));
dbObjectType type = obj->getObjectType();
return getDbNwkObjectId(type, obj->getId());
} else {
return dnet->getId();
}
return 0;
return dnet->getId();
}

/*
Expand Down Expand Up @@ -2609,17 +2604,16 @@ void dbNetwork::staToDb(const Port* port,
const ConcretePort* cport = reinterpret_cast<const ConcretePort*>(port);
mterm = reinterpret_cast<dbMTerm*>(cport->extPort());
return;
} else {
// just get the port directly from odb
dbObject* obj = reinterpret_cast<dbObject*>(const_cast<Port*>(port));
dbObjectType type = obj->getObjectType();
if (type == dbModBTermObj) {
Port* port_unconst = const_cast<Port*>(port);
modbterm = reinterpret_cast<dbModBTerm*>(port_unconst);
} else if (type == dbBTermObj) {
Port* port_unconst = const_cast<Port*>(port);
bterm = reinterpret_cast<dbBTerm*>(port_unconst);
}
}
// just get the port directly from odb
dbObject* obj = reinterpret_cast<dbObject*>(const_cast<Port*>(port));
dbObjectType type = obj->getObjectType();
if (type == dbModBTermObj) {
Port* port_unconst = const_cast<Port*>(port);
modbterm = reinterpret_cast<dbModBTerm*>(port_unconst);
} else if (type == dbBTermObj) {
Port* port_unconst = const_cast<Port*>(port);
bterm = reinterpret_cast<dbBTerm*>(port_unconst);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/drt/src/io/GuideProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ std::string getPinName(const frBlockObject* pin)
{
if (pin->typeId() == frcBTerm) {
return static_cast<const frBTerm*>(pin)->getName();
} else {
return static_cast<const frInstTerm*>(pin)->getName();
}
return static_cast<const frInstTerm*>(pin)->getName();
}
/**
* Returns the preferred access point for required pin.
Expand Down Expand Up @@ -2022,4 +2021,4 @@ void GuideProcessor::processGuides()
}
}

} // namespace drt::io
} // namespace drt::io
26 changes: 11 additions & 15 deletions src/grt/src/GlobalRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3102,14 +3102,14 @@ bool GlobalRouter::pinOverlapsWithSingleTrack(const Pin& pin,
? odb::Point(track_position.x(), nearest_track)
: odb::Point(nearest_track, track_position.y());
return true;
} else if (nearest_track2 > min && nearest_track2 < max) {
}
if (nearest_track2 > min && nearest_track2 < max) {
track_position = horizontal
? odb::Point(track_position.x(), nearest_track2)
: odb::Point(nearest_track2, track_position.y());
return true;
} else {
return false;
}
return false;
}

return false;
Expand Down Expand Up @@ -4269,15 +4269,14 @@ std::map<int, odb::dbTechVia*> GlobalRouter::getDefaultVias(

if (prop == nullptr) {
continue;
} else {
debugPrint(logger_,
utl::GRT,
"l2v_pitch",
1,
"Default via: {}.",
via->getConstName());
default_vias[via->getBottomLayer()->getRoutingLevel()] = via;
}
debugPrint(logger_,
utl::GRT,
"l2v_pitch",
1,
"Default via: {}.",
via->getConstName());
default_vias[via->getBottomLayer()->getRoutingLevel()] = via;
}

if (default_vias.empty()) {
Expand Down Expand Up @@ -4645,10 +4644,7 @@ void GlobalRouter::reportNetDetailedRouteWL(odb::dbWire* wire,
void GlobalRouter::createWLReportFile(const char* file_name, bool verbose)
{
std::ofstream out(file_name);
out << "tool "
<< "net "
<< "total_wl "
<< "#pins ";
out << "tool net total_wl #pins ";

if (verbose) {
out << "#vias ";
Expand Down
4 changes: 2 additions & 2 deletions src/grt/src/MakeWireParasitics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ sta::Pin* MakeWireParasitics::staPin(Pin& pin) const
{
if (pin.isPort())
return network_->dbToSta(pin.getBTerm());
else
return network_->dbToSta(pin.getITerm());

return network_->dbToSta(pin.getITerm());
}

void MakeWireParasitics::makeRouteParasitics(
Expand Down
19 changes: 9 additions & 10 deletions src/grt/src/Pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,35 +159,34 @@ odb::dbITerm* Pin::getITerm() const
{
if (is_port_)
return nullptr;
else
return iterm_;

return iterm_;
}

odb::dbBTerm* Pin::getBTerm() const
{
if (is_port_)
return bterm_;
else
return nullptr;

return nullptr;
}

std::string Pin::getName() const
{
if (is_port_)
return bterm_->getName();
else
return getITermName(iterm_);

return getITermName(iterm_);
}

bool Pin::isDriver()
{
if (is_port_) {
return (bterm_->getIoType() == odb::dbIoType::INPUT);
} else {
odb::dbMTerm* mterm = iterm_->getMTerm();
odb::dbIoType type = mterm->getIoType();
return type == odb::dbIoType::OUTPUT || type == odb::dbIoType::INOUT;
}
odb::dbMTerm* mterm = iterm_->getMTerm();
odb::dbIoType type = mterm->getIoType();
return type == odb::dbIoType::OUTPUT || type == odb::dbIoType::INOUT;
}

int Pin::getConnectionLayer() const
Expand Down
7 changes: 2 additions & 5 deletions src/grt/src/RepairAntennas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,9 @@ odb::dbWire* RepairAntennas::makeNetWire(
wire_encoder.end();

return wire;
} else {
logger_->error(
GRT, 221, "Cannot create wire for net {}.", db_net->getConstName());
// suppress gcc warning
return nullptr;
}
logger_->error(
GRT, 221, "Cannot create wire for net {}.", db_net->getConstName());
}

RoutePtPinsMap RepairAntennas::findRoutePtPins(Net* net)
Expand Down
17 changes: 8 additions & 9 deletions src/grt/src/fastroute/src/FastRoute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,14 @@ int FastRouteCore::getEdgeCapacity(int x1, int y1, int x2, int y2, int layer)

if (y1 == y2) { // horizontal edge
return h_edges_3D_[k][y1][x1].cap;
} else if (x1 == x2) { // vertical edge
}
if (x1 == x2) { // vertical edge
return v_edges_3D_[k][y1][x1].cap;
} else {
logger_->error(
GRT,
214,
"Cannot get edge capacity: edge is not vertical or horizontal.");
return 0;
}
logger_->error(
GRT,
214,
"Cannot get edge capacity: edge is not vertical or horizontal.");
}

int FastRouteCore::getEdgeCapacity(FrNet* net,
Expand Down Expand Up @@ -1610,8 +1609,8 @@ int FrNet::getLayerEdgeCost(int layer) const
{
if (edge_cost_per_layer_)
return (*edge_cost_per_layer_)[layer];
else
return 1;

return 1;
}

void FrNet::addPin(int x, int y, int layer)
Expand Down
12 changes: 2 additions & 10 deletions src/grt/src/fastroute/src/RSMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,7 @@ bool FastRouteCore::VTreeSuite(const int netID)
}
}

if ((ymax - ymin) > 3 * (xmax - xmin)) {
return true;
} else {
return false;
}
return (ymax - ymin) > 3 * (xmax - xmin);
}

bool FastRouteCore::HTreeSuite(const int netID)
Expand All @@ -562,11 +558,7 @@ bool FastRouteCore::HTreeSuite(const int netID)
}
}

if (5 * (ymax - ymin) < (xmax - xmin)) {
return true;
} else {
return false;
}
return 5 * (ymax - ymin) < (xmax - xmin);
}

float FastRouteCore::coeffADJ(const int netID)
Expand Down
Loading

0 comments on commit d4eec05

Please sign in to comment.