From 81ebe34c4368f34e6b2b01015b5e276649826e96 Mon Sep 17 00:00:00 2001 From: Matt Liberty Date: Sun, 25 Feb 2024 16:58:27 -0800 Subject: [PATCH] drt: clang-tidy Signed-off-by: Matt Liberty --- src/drt/src/dr/FlexDR.cpp | 115 ++++--- src/drt/src/dr/FlexDR.h | 143 +++------ src/drt/src/dr/FlexDR_conn.cpp | 73 +++-- src/drt/src/dr/FlexDR_conn.h | 27 +- src/drt/src/dr/FlexDR_end.cpp | 10 +- src/drt/src/dr/FlexDR_graphics.cpp | 36 ++- src/drt/src/dr/FlexDR_graphics.h | 5 +- src/drt/src/dr/FlexDR_init.cpp | 62 ++-- src/drt/src/dr/FlexDR_maze.cpp | 440 ++++++++++++++++---------- src/drt/src/dr/FlexDR_rq.cpp | 4 +- src/drt/src/dr/FlexGridGraph.cpp | 60 ++-- src/drt/src/dr/FlexGridGraph.h | 104 +++--- src/drt/src/dr/FlexGridGraph_maze.cpp | 126 +++++--- src/drt/src/dr/FlexMazeTypes.h | 14 +- 14 files changed, 675 insertions(+), 544 deletions(-) diff --git a/src/drt/src/dr/FlexDR.cpp b/src/drt/src/dr/FlexDR.cpp index 7ff2efe99ec..524165b6485 100644 --- a/src/drt/src/dr/FlexDR.cpp +++ b/src/drt/src/dr/FlexDR.cpp @@ -30,12 +30,12 @@ #include #include -#include #include #include #include #include +#include #include #include #include @@ -55,11 +55,11 @@ #include "serialization.h" #include "utl/exception.h" -using namespace fr; +BOOST_CLASS_EXPORT(fr::RoutingJobDescription) -using utl::ThreadException; +namespace fr { -BOOST_CLASS_EXPORT(RoutingJobDescription) +using utl::ThreadException; enum class SerializationType { @@ -90,7 +90,7 @@ void deserializeWorker(FlexDRWorker* worker, ar >> *worker; } -void serializeViaData(FlexDRViaData viaData, std::string& serializedStr) +void serializeViaData(const FlexDRViaData& viaData, std::string& serializedStr) { std::stringstream stream(std::ios_base::binary | std::ios_base::in | std::ios_base::out); @@ -118,9 +118,7 @@ FlexDR::FlexDR(triton_route::TritonRoute* router, { } -FlexDR::~FlexDR() -{ -} +FlexDR::~FlexDR() = default; void FlexDR::setDebug(frDebugSettings* settings) { @@ -205,7 +203,7 @@ void FlexDRWorker::writeUpdates(const std::string& file_name) int FlexDRWorker::main(frDesign* design) { ProfileTask profile("DRW:main"); - using namespace std::chrono; + using std::chrono::high_resolution_clock; high_resolution_clock::time_point t0 = high_resolution_clock::now(); auto micronPerDBU = 1.0 / getTech()->getDBUPerUU(); if (VERBOSE > 1) { @@ -275,6 +273,8 @@ int FlexDRWorker::main(frDesign* design) cleanup(); high_resolution_clock::time_point t3 = high_resolution_clock::now(); + using std::chrono::duration; + using std::chrono::duration_cast; duration time_span0 = duration_cast>(t1 - t0); duration time_span1 = duration_cast>(t2 - t1); duration time_span2 = duration_cast>(t3 - t2); @@ -537,7 +537,7 @@ void FlexDR::searchRepair(const SearchRepairArgs& args) if (dist_on_) { if ((iter % 10 == 0 && iter != 60) || iter == 3 || iter == 15) { globals_path_ = fmt::format("{}globals.{}.ar", dist_dir_, iter); - router_->writeGlobals(globals_path_.c_str()); + router_->writeGlobals(globals_path_); } } frTime t; @@ -599,8 +599,9 @@ void FlexDR::searchRepair(const SearchRepairArgs& args) worker->setMazeEndIter(mazeEndIter); worker->setDRIter(iter); worker->setDebugSettings(router_->getDebugSettings()); - if (dist_on_) + if (dist_on_) { worker->setDistributed(dist_, dist_ip_, dist_port_, dist_dir_); + } if (!iter) { // if (routeBox.xMin() == 441000 && routeBox.yMin() == 816100) { // std::cout << "@@@ debug: " << i << " " << j << std::endl; @@ -652,20 +653,22 @@ void FlexDR::searchRepair(const SearchRepairArgs& args) std::string serializedViaData; serializeViaData(via_data_, serializedViaData); router_->sendGlobalsUpdates(globals_path_, serializedViaData); - } else + } else { router_->sendDesignUpdates(globals_path_); + } } { ProfileTask task("DIST: PROCESS_BATCH"); // multi thread ThreadException exception; #pragma omp parallel for schedule(dynamic) - for (int i = 0; i < (int) workersInBatch.size(); i++) { + for (int i = 0; i < (int) workersInBatch.size(); i++) { // NOLINT try { - if (dist_on_) + if (dist_on_) { workersInBatch[i]->distributedMain(getDesign()); - else + } else { workersInBatch[i]->main(getDesign()); + } #pragma omp critical { cnt++; @@ -705,7 +708,7 @@ void FlexDR::searchRepair(const SearchRepairArgs& args) { ProfileTask task("DIST: SERIALIZE+SEND"); #pragma omp parallel for schedule(dynamic) - for (int i = 0; i < distWorkerBatches.size(); i++) + for (int i = 0; i < distWorkerBatches.size(); i++) // NOLINT sendWorkers(distWorkerBatches.at(i), workersInBatch); } logger_->report(" Received Batches:{}.", t); @@ -714,7 +717,7 @@ void FlexDR::searchRepair(const SearchRepairArgs& args) { ProfileTask task("DIST: DESERIALIZING_BATCH"); #pragma omp parallel for schedule(dynamic) - for (int i = 0; i < workers.size(); i++) { + for (int i = 0; i < workers.size(); i++) { // NOLINT deserializeWorker(workersInBatch.at(workers.at(i).first).get(), design_, workers.at(i).second); @@ -727,11 +730,13 @@ void FlexDR::searchRepair(const SearchRepairArgs& args) { ProfileTask profile("DR:end_batch"); // single thread - for (int i = 0; i < (int) workersInBatch.size(); i++) { - if (workersInBatch[i]->end(getDesign())) + for (auto& worker : workersInBatch) { + if (worker->end(getDesign())) { numWorkUnits_ += 1; - if (workersInBatch[i]->isCongested()) + } + if (worker->isCongested()) { increaseClipsize_ = true; + } } workersInBatch.clear(); } @@ -779,11 +784,13 @@ void FlexDR::searchRepair(const SearchRepairArgs& args) {"Lef58CutSpacingTable", "CutSpcTbl"}, {"Lef58EolKeepOut", "eolKeepOut"}}; for (const auto& marker : getDesign()->getTopBlock()->getMarkers()) { - if (!marker->getConstraint()) + if (!marker->getConstraint()) { continue; + } auto type = marker->getConstraint()->getViolName(); - if (relabel.find(type) != relabel.end()) + if (relabel.find(type) != relabel.end()) { type = relabel.at(type); + } violations[type][marker->getLayerNum()]++; layers.insert(marker->getLayerNum()); } @@ -796,10 +803,11 @@ void FlexDR::searchRepair(const SearchRepairArgs& args) line += fmt::format("{:>7}", lName); } logger_->report(line); - for (auto [type, typeViolations] : violations) { + for (auto& [type, typeViolations] : violations) { std::string typeName = type; - if (typeName.size() >= 15) + if (typeName.size() >= 15) { typeName = typeName.substr(0, 12) + ".."; + } line = fmt::format("{:<15}", typeName); for (auto lNum : layers) { line += fmt::format("{:>7}", typeViolations[lNum]); @@ -828,7 +836,7 @@ void FlexDR::end(bool done) logger_->info(DRT, 198, "Complete detail routing."); } - using ULL = unsigned long long; + using ULL = uint64_t; const auto size = getTech()->getLayers().size(); std::vector wlen(size, 0); std::vector sCut(size, 0); @@ -1054,28 +1062,28 @@ static std::vector strategy() void addRectToPolySet(gtl::polygon_90_set_data& polySet, Rect rect) { - using namespace boost::polygon::operators; gtl::polygon_90_data poly; std::vector> points; for (const auto& point : rect.getPoints()) { - points.push_back({point.x(), point.y()}); + points.emplace_back(point.x(), point.y()); } poly.set(points.begin(), points.end()); + using boost::polygon::operators::operator+=; polySet += poly; } void FlexDR::reportGuideCoverage() { - using namespace boost::polygon::operators; + using boost::polygon::operators::operator&; const auto numLayers = getTech()->getLayers().size(); - std::vector totalAreaByLayerNum(numLayers, 0); - std::vector totalCoveredAreaByLayerNum(numLayers, 0); + std::vector totalAreaByLayerNum(numLayers, 0); + std::vector totalCoveredAreaByLayerNum(numLayers, 0); std::map> netsCoverage; const auto& nets = getDesign()->getTopBlock()->getNets(); omp_set_num_threads(MAX_THREADS); #pragma omp parallel for schedule(dynamic) - for (int i = 0; i < nets.size(); i++) { + for (int i = 0; i < nets.size(); i++) { // NOLINT const auto& net = nets.at(i); std::vector> routeSetByLayerNum( numLayers), @@ -1108,19 +1116,21 @@ void FlexDR::reportGuideCoverage() for (frLayerNum lNum = 0; lNum < numLayers; lNum++) { if (getTech()->getLayer(lNum)->getType() != dbTechLayerType::ROUTING - || lNum > TOP_ROUTING_LAYER) + || lNum > TOP_ROUTING_LAYER) { continue; + } float coveredPercentage = -1.0; - unsigned long long routingArea = 0; - unsigned long long coveredArea = 0; + uint64_t routingArea = 0; + uint64_t coveredArea = 0; if (!routeSetByLayerNum[lNum].empty()) { routingArea = gtl::area(routeSetByLayerNum[lNum]); coveredArea = gtl::area(routeSetByLayerNum[lNum] & guideSetByLayerNum[lNum]); - if (routingArea == 0.0) + if (routingArea == 0.0) { coveredPercentage = -1.0; - else + } else { coveredPercentage = (coveredArea / (double) routingArea) * 100; + } } #pragma omp critical @@ -1141,18 +1151,20 @@ void FlexDR::reportGuideCoverage() } } file << std::endl; - for (auto [net, coverage] : netsCoverage) { + for (const auto& [net, coverage] : netsCoverage) { file << net->getName() << ","; - for (auto coveredPercentage : coverage) - if (coveredPercentage < 0.0) + for (auto coveredPercentage : coverage) { + if (coveredPercentage < 0.0) { file << "NA,"; - else + } else { file << fmt::format("{:.2f}%,", coveredPercentage); + } + } file << std::endl; } file << "Total,"; - unsigned long long totalArea = 0; - unsigned long long totalCoveredArea = 0; + uint64_t totalArea = 0; + uint64_t totalCoveredArea = 0; for (const auto& layer : getTech()->getLayers()) { if (layer->getType() == dbTechLayerType::ROUTING && layer->getLayerNum() <= TOP_ROUTING_LAYER) { @@ -1169,9 +1181,9 @@ void FlexDR::reportGuideCoverage() file << fmt::format("{:.2f}%,", coveredPercentage); } } - if (totalArea == 0) + if (totalArea == 0) { file << "NA"; - else { + } else { auto totalCoveredPercentage = (totalCoveredArea / (double) totalArea) * 100; file << fmt::format("{:.2f}%,", totalCoveredPercentage); } @@ -1189,8 +1201,9 @@ int FlexDR::main() if (args.ripupMode != RipUpMode::ALL) { if (increaseClipsize_) { clipSizeInc_ += 2; - } else + } else { clipSizeInc_ = std::max((float) 0, clipSizeInc_ - 0.2f); + } clipSize += std::min(MAX_CLIPSIZE_INCREASE, (int) round(clipSizeInc_)); } args.size = clipSize; @@ -1215,8 +1228,9 @@ int FlexDR::main() } end(/* done */ true); - if (!GUIDE_REPORT_FILE.empty()) + if (!GUIDE_REPORT_FILE.empty()) { reportGuideCoverage(); + } if (VERBOSE > 0) { t.print(logger_); std::cout << std::endl; @@ -1228,19 +1242,20 @@ void FlexDR::sendWorkers( const std::vector>& remote_batch, std::vector>& batch) { - if (remote_batch.empty()) + if (remote_batch.empty()) { return; + } std::vector> workers; { ProfileTask task("DIST: SERIALIZE_BATCH"); for (auto& [idx, worker] : remote_batch) { std::string workerStr; serializeWorker(worker, workerStr); - workers.push_back({idx, workerStr}); + workers.emplace_back(idx, workerStr); } } std::string remote_ip = dist_ip_; - unsigned short remote_port = dist_port_; + uint16_t remote_port = dist_port_; if (router_->getCloudSize() > 1) { dst::JobMessage msg(dst::JobMessage::BALANCER), result(dst::JobMessage::NONE); @@ -1370,3 +1385,5 @@ template void FlexDRWorker::serialize( template void FlexDRWorker::serialize( frOArchive& ar, const unsigned int file_version); + +} // namespace fr diff --git a/src/drt/src/dr/FlexDR.h b/src/drt/src/dr/FlexDR.h index bd50c7b9a8a..ee60b54e616 100644 --- a/src/drt/src/dr/FlexDR.h +++ b/src/drt/src/dr/FlexDR.h @@ -51,7 +51,7 @@ class Distributed; namespace odb { class dbDatabase; } -namespace ord { +namespace utl { class Logger; } @@ -116,7 +116,7 @@ class FlexDR // distributed void setDistributed(dst::Distributed* dist, const std::string& remote_ip, - unsigned short remote_port, + uint16_t remote_port, const std::string& dir) { dist_on_ = true; @@ -151,7 +151,7 @@ class FlexDR dst::Distributed* dist_; bool dist_on_; std::string dist_ip_; - unsigned short dist_port_; + uint16_t dist_port_; std::string dist_dir_; std::string globals_path_; bool increaseClipsize_; @@ -167,7 +167,10 @@ class FlexDR void removeGCell2BoundaryPin(); std::map>, frBlockObjectComp> - initDR_mergeBoundaryPin(int i, int j, int size, const Rect& routeBox); + initDR_mergeBoundaryPin(int startX, + int startY, + int size, + const Rect& routeBox); }; class FlexDRWorker; @@ -179,10 +182,10 @@ class FlexDRWorkerRegionQuery void add(drConnFig* connFig); void remove(drConnFig* connFig); void query(const Rect& box, - const frLayerNum layerNum, + frLayerNum layerNum, std::vector& result) const; void query(const Rect& box, - const frLayerNum layerNum, + frLayerNum layerNum, std::vector>& result) const; void init(); void cleanup(); @@ -197,7 +200,7 @@ class FlexDRMinAreaVio { public: // constructors - FlexDRMinAreaVio() : net_(nullptr), gapArea_(0) {} + FlexDRMinAreaVio() = default; FlexDRMinAreaVio(drNet* netIn, FlexMazeIdx bpIn, FlexMazeIdx epIn, @@ -224,9 +227,9 @@ class FlexDRMinAreaVio frCoord getGapArea() const { return gapArea_; } private: - drNet* net_; + drNet* net_ = nullptr; FlexMazeIdx bp_, ep_; - frCoord gapArea_; + frCoord gapArea_ = 0; }; class FlexGCWorker; @@ -237,69 +240,19 @@ class FlexDRWorker FlexDRWorker(FlexDRViaData* via_data, frDesign* design, Logger* logger) : design_(design), logger_(logger), - graphics_(nullptr), - debugSettings_(nullptr), via_data_(via_data), - routeBox_(), - extBox_(), - drcBox_(), - drIter_(0), mazeEndIter_(1), - followGuide_(false), - needRecheck_(false), - skipRouting_(false), ripupMode_(RipUpMode::ALL), workerDRCCost_(ROUTESHAPECOST), workerMarkerCost_(MARKERCOST), - workerFixedShapeCost_(0), - workerMarkerDecay_(0), - boundaryPin_(), - pinCnt_(0), - initNumMarkers_(0), - apSVia_(), - planarHistoryMarkers_(), - viaHistoryMarkers_(), historyMarkers_(std::vector>(3)), - nets_(), - owner2nets_(), gridGraph_(design->getTech(), logger, this), - markers_(), - rq_(this), - gcWorker_(nullptr), - dist_(nullptr), - dist_port_(0), - dist_on_(false), - isCongested_(false), - save_updates_(false) + rq_(this) { } FlexDRWorker() : // for serialization - design_(nullptr), - logger_(nullptr), - graphics_(nullptr), - debugSettings_(nullptr), - via_data_(nullptr), - drIter_(0), - mazeEndIter_(0), - followGuide_(false), - needRecheck_(false), - skipRouting_(false), - ripupMode_(RipUpMode::DRC), - workerDRCCost_(0), - workerMarkerCost_(0), - workerFixedShapeCost_(0), - workerMarkerDecay_(0), - boundaryPin_(), - pinCnt_(0), - initNumMarkers_(0), - rq_(this), - gcWorker_(nullptr), - dist_(nullptr), - dist_port_(0), - dist_on_(false), - isCongested_(false), - save_updates_(false) + rq_(this) { } // setters @@ -415,9 +368,8 @@ class FlexDRWorker auto it = owner2nets_.find(net); if (it != owner2nets_.end()) { return &(it->second); - } else { - return nullptr; } + return nullptr; } frDesign* getDesign() { return design_; } void setDesign(frDesign* design) { design_ = design; } @@ -448,7 +400,7 @@ class FlexDRWorker gridGraph_.setLogger(logger); } - static std::unique_ptr load(const std::string& file_name, + static std::unique_ptr load(const std::string& workerStr, utl::Logger* logger, frDesign* design, FlexDRGraphics* graphics); @@ -456,7 +408,7 @@ class FlexDRWorker // distributed void setDistributed(dst::Distributed* dist, const std::string& remote_ip, - unsigned short remote_port, + uint16_t remote_port, const std::string& dir) { dist_on_ = true; @@ -488,35 +440,37 @@ class FlexDRWorker }; private: - typedef struct + struct RouteQueueEntry { frBlockObject* block; int numReroute; bool doRoute; - } RouteQueueEntry; - frDesign* design_; - Logger* logger_; - FlexDRGraphics* graphics_; // owned by FlexDR - frDebugSettings* debugSettings_; - FlexDRViaData* via_data_; + }; + frDesign* design_ = nullptr; + Logger* logger_ = nullptr; + FlexDRGraphics* graphics_ = nullptr; // owned by FlexDR + frDebugSettings* debugSettings_ = nullptr; + FlexDRViaData* via_data_ = nullptr; Rect routeBox_; Rect extBox_; Rect drcBox_; Rect gcellBox_; - int drIter_; - int mazeEndIter_; - bool followGuide_; - bool needRecheck_; - bool skipRouting_; - RipUpMode ripupMode_; + int drIter_ = 0; + int mazeEndIter_ = 0; + bool followGuide_ = false; + bool needRecheck_ = false; + bool skipRouting_ = false; + RipUpMode ripupMode_ = RipUpMode::DRC; // drNetOrderingEnum netOrderingMode; - frUInt4 workerDRCCost_, workerMarkerCost_, workerFixedShapeCost_; - float workerMarkerDecay_; + frUInt4 workerDRCCost_ = 0; + frUInt4 workerMarkerCost_ = 0; + frUInt4 workerFixedShapeCost_ = 0; + float workerMarkerDecay_ = 0; // used in init route as gr boundary pin std::map>, frBlockObjectComp> boundaryPin_; - int pinCnt_; - int initNumMarkers_; + int pinCnt_ = 0; + int initNumMarkers_ = 0; std::map apSVia_; std::set planarHistoryMarkers_; std::set viaHistoryMarkers_; @@ -537,13 +491,13 @@ class FlexDRWorker std::vector specialAccessAPs; // distributed - dst::Distributed* dist_; + dst::Distributed* dist_ = nullptr; std::string dist_ip_; - unsigned short dist_port_; + uint16_t dist_port_ = 0; std::string dist_dir_; - bool dist_on_; - bool isCongested_; - bool save_updates_; + bool dist_on_ = false; + bool isCongested_ = false; + bool save_updates_ = false; // hellpers bool isRoutePatchWire(const frPatchWire* pwire) const; @@ -752,7 +706,7 @@ class FlexDRWorker frCoord high, frCoord line, bool isVertical, - bool innerIsHigh, + bool innerDirIsIncreasing, frLayer* layer, ModCostType modType); void route_queue_resetRipup(); @@ -875,7 +829,7 @@ class FlexDRWorker void mazeNetEnd(drNet* net); bool routeNet(drNet* net); void routeNet_prep(drNet* net, - std::set& pins, + std::set& unConnPins, std::map>& mazeIdx2unConnPins, std::set& apMazeIdx, @@ -962,7 +916,7 @@ class FlexDRWorker frSegStyle& style, const std::set& apMazeIdx, const FlexMazeIdx& idx); - void checkViaConnectivityToAP(drVia* ps, + void checkViaConnectivityToAP(drVia* via, bool isBottom, frNet* net, const std::set& apMazeIdx, @@ -977,8 +931,8 @@ class FlexDRWorker const FlexMazeIdx& epIdx, frCoord gapArea, frCoord patchWidth, - bool bpPatchStyle = true, - bool epPatchStyle = false); + bool bpPatchLeft = true, + bool epPatchLeft = false); int routeNet_postAstarAddPathMetal_isClean(const FlexMazeIdx& bpIdx, bool isPatchHorz, bool isPatchLeft, @@ -1022,11 +976,10 @@ class FlexDRWorker void endAddMarkers(frDesign* design); // helper functions - frCoord snapCoordToManufacturingGrid(const frCoord coord, - const int lowerLeftCoord); + frCoord snapCoordToManufacturingGrid(frCoord coord, int lowerLeftCoord); template - void serialize(Archive& ar, const unsigned int version); + void serialize(Archive& ar, unsigned int version); friend class boost::serialization::access; }; } // namespace fr diff --git a/src/drt/src/dr/FlexDR_conn.cpp b/src/drt/src/dr/FlexDR_conn.cpp index 352b0e86cad..70815727a2e 100644 --- a/src/drt/src/dr/FlexDR_conn.cpp +++ b/src/drt/src/dr/FlexDR_conn.cpp @@ -35,7 +35,7 @@ #include "io/io.h" #include "utl/exception.h" -using namespace fr; +namespace fr { using utl::ThreadException; @@ -46,8 +46,7 @@ void FlexDRConnectivityChecker::pin2epMap_helper( const frLayerNum lNum, std::map>, - frBlockObjectComp>& pin2epMap, - const bool isPathSeg) + frBlockObjectComp>& pin2epMap) { auto regionQuery = getRegionQuery(); frRegionQuery::Objects result; @@ -90,13 +89,13 @@ void FlexDRConnectivityChecker::buildPin2epMap( } auto obj = static_cast(connFig); const auto [bp, ep] = obj->getPoints(); - frSegStyle style = obj->getStyle(); + const frSegStyle& style = obj->getStyle(); auto lNum = obj->getLayerNum(); if (style.getBeginStyle() == frEndStyle(frcTruncateEndStyle)) { - pin2epMap_helper(net, bp, lNum, pin2epMap, true); + pin2epMap_helper(net, bp, lNum, pin2epMap); } if (style.getEndStyle() == frEndStyle(frcTruncateEndStyle)) { - pin2epMap_helper(net, ep, lNum, pin2epMap, true); + pin2epMap_helper(net, ep, lNum, pin2epMap); } } @@ -108,10 +107,12 @@ void FlexDRConnectivityChecker::buildPin2epMap( const Point origin = obj->getOrigin(); auto l1Num = obj->getViaDef()->getLayer1Num(); auto l2Num = obj->getViaDef()->getLayer2Num(); - if (obj->isBottomConnected()) - pin2epMap_helper(net, origin, l1Num, pin2epMap, false); - if (obj->isTopConnected()) - pin2epMap_helper(net, origin, l2Num, pin2epMap, false); + if (obj->isBottomConnected()) { + pin2epMap_helper(net, origin, l1Num, pin2epMap); + } + if (obj->isTopConnected()) { + pin2epMap_helper(net, origin, l2Num, pin2epMap); + } } } @@ -211,8 +212,7 @@ void FlexDRConnectivityChecker::nodeMap_routeObjSplit( horzMergeHelper[lNum][bp.y()][ep.x()] = std::make_pair(bp.x(), i); } } - for (int i = 0; i < (int) netRouteObjs.size(); i++) { - const auto connFig = netRouteObjs[i]; + for (const auto connFig : netRouteObjs) { // ep on pathseg if (connFig->typeId() == frcPathSeg) { auto obj = static_cast(connFig); @@ -329,9 +329,8 @@ bool FlexDRConnectivityChecker::astar( { if (cost == b.cost) { return nodeIdx > b.nodeIdx; - } else { - return cost > b.cost; } + return cost > b.cost; } }; for (int findNode = nNetRouteObjs; findNode < nNetObjs - 1; findNode++) { @@ -498,9 +497,8 @@ void FlexDRConnectivityChecker::finish( if (bp == pr.first || ep == pr.first) { hasPinEP = true; break; - } else { - psIdx = idx; } + psIdx = idx; } else if (netRouteObjs[idx]->typeId() == frcVia) { hasPinEP = true; break; @@ -838,15 +836,17 @@ void FlexDRConnectivityChecker::splitPathSegs( frPathSeg* highestPs = nullptr; // overlapping ps with the highest endPoint int first = 0; std::vector splitPoints; - if (segSpans.empty()) + if (segSpans.empty()) { return; + } for (int i = 0; i < segSpans.size(); i++) { auto& curr = segSpans[i]; frPathSeg* currPs = static_cast(netRouteObjs[curr.second]); if (!highestPs || curr.first.lo >= highestPs->high()) { - if (!splitPoints.empty()) + if (!splitPoints.empty()) { splitPathSegs_commit( splitPoints, highestPs, first, i, segSpans, netRouteObjs); + } first = i; highestPs = currPs; } else { @@ -856,18 +856,22 @@ void FlexDRConnectivityChecker::splitPathSegs( frPathSeg* prevPs = static_cast(netRouteObjs[prev.second]); if (curr.first.lo != segSpans[first].first.lo && currPs->isBeginTruncated() - && !isRedundant(splitPoints, curr.first.lo)) + && !isRedundant(splitPoints, curr.first.lo)) { splitPoints.push_back(curr.first.lo); - if (currPs->isEndTruncated() && !isRedundant(splitPoints, curr.first.hi)) + } + if (currPs->isEndTruncated() + && !isRedundant(splitPoints, curr.first.hi)) { splitPoints.push_back(curr.first.hi); + } if (i - 1 == first) { if (prevPs->isEndTruncated() && !isRedundant(splitPoints, prevPs->high())) { splitPoints.push_back(prevPs->high()); } } - if (highestPs->high() < curr.first.hi) + if (highestPs->high() < curr.first.hi) { highestPs = currPs; + } } } if (!splitPoints.empty()) { @@ -886,9 +890,10 @@ void FlexDRConnectivityChecker::splitPathSegs_commit( { sort(splitPoints.begin(), splitPoints.end()); if (splitPoints[splitPoints.size() - 1] - == highestPs->high()) // we don't need this split point, only those - // inside the overlapping interval + == highestPs->high()) { // we don't need this split point, only those + // inside the overlapping interval splitPoints.erase(std::prev(splitPoints.end())); + } if (!splitPoints.empty()) { frEndStyle highestPsEndStyle = highestPs->getEndStyle(); int highestHi = highestPs->high(); @@ -930,8 +935,9 @@ void FlexDRConnectivityChecker::splitPathSegs_commit( segSpans[segSpnIdx].first.hi = highestHi; // if we have 2 or more splitting pathsegs than split points. This // will create redundant pathsegs that will be merged later - if (currIdxSplitSpanIdxs < splitSpanIdxs.size() - 1) + if (currIdxSplitSpanIdxs < splitSpanIdxs.size() - 1) { s--; + } } else { segSpans[segSpnIdx].first.hi = splitPoints[s]; ps->setHigh(splitPoints[s]); @@ -975,7 +981,7 @@ void FlexDRConnectivityChecker::splitPathSegs_commit( if (save_updates_) { drUpdate update(drUpdate::ADD_SHAPE); update.setNet(highestPs->getNet()); - update.setPathSeg(*newPs.get()); + update.setPathSeg(*newPs); design_->addUpdate(update); } } @@ -1027,10 +1033,12 @@ void FlexDRConnectivityChecker::merge_perform_helper( localVictims.push_back(segSpan.second); currEnd = std::max(currEnd, segSpan.first.hi); if (currEnd == currEndPs->high()) { - if (currEnd == ps->high() && !currEndPs->isEndTruncated()) + if (currEnd == ps->high() && !currEndPs->isEndTruncated()) { currEndPs = ps; - } else + } + } else { currEndPs = ps; + } } } if (hasOverlap) { @@ -1119,7 +1127,7 @@ void FlexDRConnectivityChecker::addMarker(frNet* net, marker->addAggressor(net, std::make_tuple(lNum, bbox, false)); if (save_updates_) { drUpdate update(drUpdate::ADD_SHAPE); - update.setMarker(*marker.get()); + update.setMarker(*marker); design_->addUpdate(update); } regionQuery->addMarker(marker.get()); @@ -1145,7 +1153,7 @@ void FlexDRConnectivityChecker::check(int iter) if ((int) batches.back().size() < batchSize) { batches.back().push_back(net); } else { - batches.push_back(std::vector()); + batches.emplace_back(std::vector()); batches.back().reserve(batchSize); batches.back().push_back(net); } @@ -1294,10 +1302,11 @@ void FlexDRConnectivityChecker::check(int iter) << "Objs not visited:\n"; for (int idx = 0; idx < (int) adjVisited.size(); idx++) { if (!adjVisited[idx]) { - if (idx < (int) netRouteObjs.size()) + if (idx < (int) netRouteObjs.size()) { std::cout << *(netRouteObjs[idx]) << "\n"; - else + } else { std::cout << *(netPins[idx - netRouteObjs.size()]) << "\n"; + } } } isWrong = true; @@ -1332,3 +1341,5 @@ FlexDRConnectivityChecker::FlexDRConnectivityChecker(frDesign* design, save_updates_(save_updates) { } + +} // namespace fr diff --git a/src/drt/src/dr/FlexDR_conn.h b/src/drt/src/dr/FlexDR_conn.h index ec92a440ac4..bb2b2b11bb7 100644 --- a/src/drt/src/dr/FlexDR_conn.h +++ b/src/drt/src/dr/FlexDR_conn.h @@ -33,7 +33,7 @@ namespace odb { class dbDatabase; } -namespace ord { +namespace utl { class Logger; } @@ -75,11 +75,10 @@ class FlexDRConnectivityChecker frBlockObjectComp>& pin2epMap); void pin2epMap_helper(const frNet* net, const Point& pt, - const frLayerNum lNum, + frLayerNum lNum, std::map>, - frBlockObjectComp>& pin2epMap, - const bool isWire); + frBlockObjectComp>& pin2epMap); void buildNodeMap( const frNet* net, const NetRouteObjs& netRouteObjs, @@ -98,9 +97,9 @@ class FlexDRConnectivityChecker std::map, std::set>& nodeMap); void nodeMap_routeObjSplit_helper( const Point& crossPt, - const frCoord trackCoord, - const frCoord splitCoord, - const frLayerNum lNum, + frCoord trackCoord, + frCoord splitCoord, + frLayerNum lNum, const std::vector< std::map>>>& mergeHelper, @@ -136,7 +135,7 @@ class FlexDRConnectivityChecker const std::vector& indices, std::vector& victims, std::vector& newSegSpans, - const bool isHorz); + bool isHorz); void splitPathSegs(NetRouteObjs& netRouteObjs, std::vector>& segSpans); void splitPathSegs_commit(std::vector& splitPoints, @@ -152,23 +151,23 @@ class FlexDRConnectivityChecker void merge_commit(frNet* net, std::vector& netRouteObjs, const std::vector& victims, - const frCoord trackCoord, + frCoord trackCoord, const std::vector& newSegSpans, - const bool isHorz); + bool isHorz); bool astar( const frNet* net, std::vector& adjVisited, std::vector& adjPrevIdx, const std::map, std::set>& nodeMap, const NetRouteObjs& netRouteObjs, - const int gCnt, - const int nCnt); + int nNetRouteObjs, + int nNetObjs); void finish(frNet* net, NetRouteObjs& netRouteObjs, const std::vector& netPins, const std::vector& adjVisited, - const int gCnt, - const int nCnt, + int gCnt, + int nCnt, std::map, std::set>& nodeMap); frRegionQuery* getRegionQuery() const { return design_->getRegionQuery(); } diff --git a/src/drt/src/dr/FlexDR_end.cpp b/src/drt/src/dr/FlexDR_end.cpp index 0e4a1508ba3..8cf9167189c 100644 --- a/src/drt/src/dr/FlexDR_end.cpp +++ b/src/drt/src/dr/FlexDR_end.cpp @@ -28,7 +28,7 @@ #include "dr/FlexDR.h" -using namespace fr; +namespace fr { void FlexDRWorker::endGetModNets(std::set& modNets) { @@ -68,8 +68,9 @@ void FlexDRWorker::endRemoveNets_pathSeg( && (begin.x() == routeBox.xMin() || begin.x() == routeBox.xMax())) { if (begin.y() < routeBox.yMin() || end.y() > routeBox.yMax() || pathSeg->getBeginStyle() != frcTruncateEndStyle - || pathSeg->getEndStyle() != frcTruncateEndStyle) + || pathSeg->getEndStyle() != frcTruncateEndStyle) { return; + } } bool condition2 = (begin.y() <= routeBox.yMax()); // orthogonal to wire if (routeBox.xMin() <= begin.x() && begin.x() <= routeBox.xMax() @@ -150,8 +151,9 @@ void FlexDRWorker::endRemoveNets_pathSeg( && (begin.y() == routeBox.yMin() || begin.y() == routeBox.yMax())) { if (begin.x() < routeBox.xMin() || end.x() > routeBox.xMax() || pathSeg->getBeginStyle() != frcTruncateEndStyle - || pathSeg->getEndStyle() != frcTruncateEndStyle) + || pathSeg->getEndStyle() != frcTruncateEndStyle) { return; + } } // if cross routeBBox bool condition2 = /*isInitDR() ? (begin.x() < routeBox.xMax()):*/ ( @@ -630,3 +632,5 @@ bool FlexDRWorker::end(frDesign* design) // release lock return true; } + +} // namespace fr diff --git a/src/drt/src/dr/FlexDR_graphics.cpp b/src/drt/src/dr/FlexDR_graphics.cpp index 1d12ab96d34..32f74e23848 100644 --- a/src/drt/src/dr/FlexDR_graphics.cpp +++ b/src/drt/src/dr/FlexDR_graphics.cpp @@ -281,8 +281,9 @@ const char* FlexDRGraphics::getDisplayControlGroupName() void FlexDRGraphics::drawLayer(odb::dbTechLayer* layer, gui::Painter& painter) { - if (layer_map_.empty()) + if (layer_map_.empty()) { return; + } frLayerNum layerNum = layer_map_.at(layer->getNumber()); if (layerNum < 0) { return; @@ -308,8 +309,9 @@ void FlexDRGraphics::drawLayer(odb::dbTechLayer* layer, gui::Painter& painter) std::vector figs; worker_->getWorkerRegionQuery().query(box, layerNum, figs); for (auto& fig : figs) { - if (draw_current_net_only_ && fig->getNet() != net_) + if (draw_current_net_only_ && fig->getNet() != net_) { continue; + } drawObj(fig, painter, layerNum); } } @@ -422,8 +424,9 @@ void FlexDRGraphics::drawLayer(odb::dbTechLayer* layer, gui::Painter& painter) } } } - if (!worker_) + if (!worker_) { return; + } // Draw markers painter.setPen(gui::Painter::green, /* cosmetic */ true); for (auto& marker : design_->getTopBlock()->getMarkers()) { @@ -557,8 +560,9 @@ void FlexDRGraphics::pause(drNet* net) void FlexDRGraphics::debugWholeDesign() { - if (!settings_->allowPause) + if (!settings_->allowPause) { return; + } drawWholeDesign_ = true; update(); gui_->pause(); @@ -593,35 +597,37 @@ void FlexDRGraphics::drawObjects(gui::Painter& painter) } } -void FlexDRGraphics::startWorker(FlexDRWorker* in) +void FlexDRGraphics::startWorker(FlexDRWorker* worker) { worker_ = nullptr; if (current_iter_ < settings_->iter) { return; } - const Rect& rBox = in->getRouteBox(); + const Rect& rBox = worker->getRouteBox(); if (settings_->box != odb::Rect(-1, -1, -1, -1) && !rBox.intersects(settings_->box)) { return; } - status("Start worker: origin " + workerOrigin(in) + " " - + std::to_string(in->getMarkers().size()) + " markers"); + status("Start worker: origin " + workerOrigin(worker) + " " + + std::to_string(worker->getMarkers().size()) + " markers"); - worker_ = in; + worker_ = worker; net_ = nullptr; grid_graph_ = &worker_->getGridGraph(); - points_by_layer_.resize(in->getTech()->getLayers().size()); + points_by_layer_.resize(worker->getTech()->getLayers().size()); if (settings_->netName.empty()) { Rect box; worker_->getExtBox(box); gui_->zoomTo({box.xMin(), box.yMin(), box.xMax(), box.yMax()}); - if (settings_->draw) + if (settings_->draw) { gui_->redraw(); - if (settings_->allowPause) + } + if (settings_->allowPause) { gui_->pause(); + } } } @@ -644,8 +650,9 @@ void FlexDRGraphics::searchNode(const FlexGridGraph* grid_graph, // Pause on any layer change if (settings_->debugMaze && last_pt_layer_ != layer && last_pt_layer_ != -1) { - if (settings_->draw) + if (settings_->draw) { gui_->redraw(); + } if (settings_->allowPause) { GridGraphDescriptor::Data data{ grid_graph, grid.x(), grid.y(), grid.z(), design_}; @@ -764,8 +771,9 @@ void FlexDRGraphics::startIter(int iter) void FlexDRGraphics::endWorker(int iter) { - if (worker_ == nullptr) + if (worker_ == nullptr) { return; + } if (iter >= settings_->iter) { gui_->removeSelected(); status("End Worker: " + std::to_string(iter)); diff --git a/src/drt/src/dr/FlexDR_graphics.h b/src/drt/src/dr/FlexDR_graphics.h index c8e88349d23..02220d4b711 100644 --- a/src/drt/src/dr/FlexDR_graphics.h +++ b/src/drt/src/dr/FlexDR_graphics.h @@ -76,9 +76,8 @@ class FlexDRGraphics : public gui::Renderer void status(const std::string& message); // From Renderer API - virtual void drawObjects(gui::Painter& painter) override; - virtual void drawLayer(odb::dbTechLayer* layer, - gui::Painter& painter) override; + void drawObjects(gui::Painter& painter) override; + void drawLayer(odb::dbTechLayer* layer, gui::Painter& painter) override; const char* getDisplayControlGroupName() override; // Is the GUI being displayed (true) or are we in batch mode (false) diff --git a/src/drt/src/dr/FlexDR_init.cpp b/src/drt/src/dr/FlexDR_init.cpp index d9fd4fd0be2..072c3bd0f70 100644 --- a/src/drt/src/dr/FlexDR_init.cpp +++ b/src/drt/src/dr/FlexDR_init.cpp @@ -31,7 +31,8 @@ #include "dr/FlexDR.h" #include "frRTree.h" -using namespace fr; +namespace fr { + namespace bgi = boost::geometry::index; bool FlexDRWorker::isRoutePatchWire(const frPatchWire* pwire) const @@ -283,9 +284,8 @@ static bool segOnBorder(const Rect& routeBox, { if (begin.x() == end.x()) { return begin.x() == routeBox.xMin() || begin.x() == routeBox.xMax(); - } else { - return begin.y() == routeBox.yMin() || begin.y() == routeBox.yMax(); } + return begin.y() == routeBox.yMin() || begin.y() == routeBox.yMax(); } void FlexDRWorker::initNets_segmentTerms( @@ -458,12 +458,14 @@ void FlexDRWorker::initNets_searchRepair_pin2epMap( const auto l1Num = obj->getViaDef()->getLayer1Num(); const auto l2Num = obj->getViaDef()->getLayer2Num(); if (getRouteBox().intersects(bp)) { - if (obj->isBottomConnected()) + if (obj->isBottomConnected()) { initNets_searchRepair_pin2epMap_helper( design, net, bp, l1Num, pin2epMap); - if (obj->isTopConnected()) + } + if (obj->isTopConnected()) { initNets_searchRepair_pin2epMap_helper( design, net, bp, l2Num, pin2epMap); + } } } else if (connFig->typeId() == drcPatchWire) { } else { @@ -556,11 +558,10 @@ void FlexDRWorker::initNets_searchRepair_nodeMap_routeObjSplit( } } } - for (int i = 0; i < (int) netRouteObjs.size(); i++) { - auto connFig = netRouteObjs[i].get(); + for (const auto& connFig : netRouteObjs) { // ep on pathseg if (connFig->typeId() == drcPathSeg) { - auto obj = static_cast(connFig); + auto obj = static_cast(connFig.get()); const auto [bp, ep] = obj->getPoints(); const auto lNum = obj->getLayerNum(); if (bp.x() == ep.x()) { // vert seg, find horz crossing seg @@ -579,7 +580,7 @@ void FlexDRWorker::initNets_searchRepair_nodeMap_routeObjSplit( ep, ep.x(), ep.y(), lNum, vertMergeHelper, nodeMap); } } else if (connFig->typeId() == drcVia) { - auto obj = static_cast(connFig); + auto obj = static_cast(connFig.get()); const Point bp = obj->getOrigin(); const auto lNum1 = obj->getViaDef()->getLayer1Num(); // find whether there is horz track at bp on layer1 @@ -790,8 +791,9 @@ bool FlexDRWorker::findAPTracks(const frLayerNum startLayerNum, getTrackLocs(false, lNum, xl(pinRect), xh(pinRect), xLocs); } // track found or is normal layer (so can jog) - if (!xLocs.empty() || !yLocs.empty() || !isRestrictedRouting(lNum)) + if (!xLocs.empty() || !yLocs.empty() || !isRestrictedRouting(lNum)) { return true; + } } return false; } @@ -804,7 +806,7 @@ bool FlexDRWorker::isRestrictedRouting(const frLayerNum lNum) void FlexDRWorker::initNet_termGenAp(const frDesign* design, drPin* dPin) { - using namespace boost::polygon::operators; + // FIXME using namespace boost::polygon::operators; using bPoint = boost::polygon::point_data; const auto routeBox = getRouteBox(); @@ -934,13 +936,15 @@ void FlexDRWorker::initNet_termGenAp(const frDesign* design, drPin* dPin) // pinRect now equals intersection of pinRect and routeRect auto currPrefRouteDir = layer->getDir(); bool restrictedRouting = isRestrictedRouting(currLayerNum); - if (currLayerNum + 2 <= getTech()->getTopLayerNum()) + if (currLayerNum + 2 <= getTech()->getTopLayerNum()) { restrictedRouting = restrictedRouting || isRestrictedRouting(currLayerNum + 2); + } if (currLayerNum - 2 >= getTech()->getBottomLayerNum() - && currLayerNum - 2 >= VIA_ACCESS_LAYERNUM) + && currLayerNum - 2 >= VIA_ACCESS_LAYERNUM) { restrictedRouting = restrictedRouting || isRestrictedRouting(currLayerNum - 2); + } // get intersecting tracks if any if (restrictedRouting) { bool found = findAPTracks( @@ -949,15 +953,17 @@ void FlexDRWorker::initNet_termGenAp(const frDesign* design, drPin* dPin) pinRect, xLocs, yLocs); - if (!found) + if (!found) { found = findAPTracks(currLayerNum - 2, std::max(BOTTOM_ROUTING_LAYER, getTech()->getBottomLayerNum()), pinRect, xLocs, yLocs); - if (!found) + } + if (!found) { continue; + } } else if (currPrefRouteDir == dbTechLayerDir::HORIZONTAL) { getTrackLocs(true, currLayerNum, yl(pinRect), yh(pinRect), yLocs); if (currLayerNum + 2 <= getTech()->getTopLayerNum()) { @@ -991,8 +997,9 @@ void FlexDRWorker::initNet_termGenAp(const frDesign* design, drPin* dPin) yLoc = (yl(pinRect) + yh(pinRect)) / 2; yLoc = snapCoordToManufacturingGrid(yLoc, routeBox.ll().y()); } - if (restrictedRouting) + if (restrictedRouting) { specialAccessAPs.emplace_back(xLoc, yLoc, currLayerNum); + } // TODO: update as drAccessPattern updated auto uap = std::make_unique(); Point pt(xLoc, yLoc); @@ -1023,8 +1030,9 @@ void FlexDRWorker::initNet_termGenAp(const frDesign* design, drPin* dPin) } dPin->addAccessPattern(std::move(uap)); - if (!restrictedRouting) + if (!restrictedRouting) { break; + } } else { std::cout << "Error: initNet_termGenAp unsupported pinFig\n"; } @@ -1369,8 +1377,9 @@ void FlexDRWorker::initNet_term_helper(const frDesign* design, dAp->setAccessViaDef(frDirEnum::U, &(ap->getViaDefs())); } } - if (getRouteBox().intersects(bp)) + if (getRouteBox().intersects(bp)) { dPin->addAccessPattern(std::move(dAp)); + } } pinIdx++; } @@ -1380,13 +1389,13 @@ void FlexDRWorker::initNet_term_helper(const frDesign* design, if (dPin->getAccessPatterns().empty()) { std::cout << "\nError: pin " << name << " still does not have temp ap" << std::endl; - if (graphics_) + if (graphics_) { graphics_->debugWholeDesign(); + } exit(1); } } - dPin->setId(pinCnt_); - pinCnt_++; + dPin->setId(pinCnt_++); dNet->addPin(std::move(dPin)); } @@ -2430,8 +2439,9 @@ void FlexDRWorker::route_queue_init_queue( for (auto& marker : markers_) { for (auto net : ripupNets) { if (marker.getSrcs().find(net->getFrNet()) != marker.getSrcs().end()) { - if (addedNets.find(net) != addedNets.end()) + if (addedNets.find(net) != addedNets.end()) { continue; + } addedNets.insert(net); net->setPriority(currId--); } @@ -2491,8 +2501,9 @@ void FlexDRWorker::route_queue_update_from_marker( break; } } - if (!overlaps) + if (!overlaps) { return; + } } } std::vector uniqueVictimOwners; // to maintain order @@ -2674,8 +2685,9 @@ void FlexDRWorker::getRipUpNetsFromMarker(frMarker* marker, break; } } - if (!overlaps) + if (!overlaps) { return; + } } } auto bbox = marker->getBBox(); @@ -3279,3 +3291,5 @@ frCoord FlexDRWorker::snapCoordToManufacturingGrid(const frCoord coord, return onGridCoord; } + +} // namespace fr diff --git a/src/drt/src/dr/FlexDR_maze.cpp b/src/drt/src/dr/FlexDR_maze.cpp index b86a8bb2de7..79fb6b82274 100644 --- a/src/drt/src/dr/FlexDR_maze.cpp +++ b/src/drt/src/dr/FlexDR_maze.cpp @@ -39,10 +39,11 @@ #include "frProfileTask.h" #include "gc/FlexGC.h" -using namespace fr; +namespace fr { + namespace gtl = boost::polygon; -int beginDebugIter = std::numeric_limits().max(); +int beginDebugIter = std::numeric_limits::max(); static frSquaredDistance pt2boxDistSquare(const Point& pt, const Rect& box) { @@ -291,8 +292,9 @@ void FlexDRWorker::modMinSpacingCostPlanar(const Rect& box, frCoord bloatDist = getTech()->getLayer(lNum)->getMinSpacingValue( width1, width2, length1, use_min_spacing); - if (ndr) + if (ndr) { bloatDist = std::max(bloatDist, ndr->getSpacing(z)); + } frSquaredDistance bloatDistSquare = bloatDist; bloatDistSquare *= bloatDist; @@ -356,30 +358,36 @@ void FlexDRWorker::modMinSpacingCostPlanar(const Rect& box, if (isMacroPin) { if (j >= mPinLL.y() && j <= mPinUR.y()) { gridGraph_.resetBlocked(i, j, z, frDirEnum::E); - if (i == 0) + if (i == 0) { gridGraph_.resetBlocked(i, j, z, frDirEnum::W); + } } if (i >= mPinLL.x() && i <= mPinUR.x()) { gridGraph_.resetBlocked(i, j, z, frDirEnum::N); - if (j == 0) + if (j == 0) { gridGraph_.resetBlocked(i, j, z, frDirEnum::S); + } } } else { gridGraph_.resetBlocked(i, j, z, frDirEnum::E); gridGraph_.resetBlocked(i, j, z, frDirEnum::N); - if (i == 0) + if (i == 0) { gridGraph_.resetBlocked(i, j, z, frDirEnum::W); - if (j == 0) + } + if (j == 0) { gridGraph_.resetBlocked(i, j, z, frDirEnum::S); + } } break; case setBlocked: // set blocked gridGraph_.setBlocked(i, j, z, frDirEnum::E); gridGraph_.setBlocked(i, j, z, frDirEnum::N); - if (i == 0) + if (i == 0) { gridGraph_.setBlocked(i, j, z, frDirEnum::W); - if (j == 0) + } + if (j == 0) { gridGraph_.setBlocked(i, j, z, frDirEnum::S); + } break; default:; } @@ -425,8 +433,9 @@ void FlexDRWorker::modMinSpacingCostVia_eol(const Rect& box, frMIdx j, frMIdx z) { - if (drCon.eolSpace == 0) + if (drCon.eolSpace == 0) { return; + } Rect testBox; frCoord eolSpace = drCon.eolSpace; frCoord eolWidth = drCon.eolWidth; @@ -659,8 +668,9 @@ void FlexDRWorker::modMinSpacingCostVia(const Rect& box, // no need to bloat eolWithin because eolWithin always < minSpacing frCoord bloatDistEolX = 0; frCoord bloatDistEolY = 0; - if (drCon.eolWidth == 0) + if (drCon.eolWidth == 0) { drCon = getTech()->getLayer(lNum)->getDrEolSpacingConstraint(); + } if (viaBox.dx() <= drCon.eolWidth) { bloatDistEolY = std::max(bloatDistEolY, drCon.eolSpace); } @@ -724,8 +734,9 @@ void FlexDRWorker::modMinSpacingCostVia(const Rect& box, frCoord reqDist = getTech()->getLayer(lNum)->getMinSpacingValue( width1, width2, prl, use_min_spacing); - if (ndr) + if (ndr) { reqDist = std::max(reqDist, ndr->getSpacing(z)); + } if (distSquare < (frSquaredDistance) reqDist * reqDist) { switch (type) { case subRouteShape: @@ -906,16 +917,19 @@ void FlexDRWorker::modEolSpacingRulesCost(const Rect& box, { auto layer = getTech()->getLayer(gridGraph_.getLayerNum(z)); drEolSpacingConstraint drCon; - if (ndr != nullptr) + if (ndr != nullptr) { drCon = ndr->getDrEolSpacingConstraint(z); - if (drCon.eolWidth == 0) + } + if (drCon.eolWidth == 0) { drCon = layer->getDrEolSpacingConstraint(); + } frCoord eolSpace, eolWidth, eolWithin; eolSpace = drCon.eolSpace; eolWithin = drCon.eolWithin; eolWidth = drCon.eolWidth; - if (eolSpace == 0) + if (eolSpace == 0) { return; + } Rect testBox; if (box.dx() <= eolWidth) { testBox.init(box.xMin() - eolWithin, @@ -1083,8 +1097,9 @@ void FlexDRWorker::modAdjCutSpacingCost_fixedObj(const frDesign* design, } frLef58CutSpacingTableConstraint* lef58con = nullptr; std::pair lef58conSpc; - if (cutLayer->hasLef58DiffNetCutSpcTblConstraint()) + if (cutLayer->hasLef58DiffNetCutSpcTblConstraint()) { lef58con = cutLayer->getLef58DiffNetCutSpcTblConstraint(); + } if (lef58con != nullptr) { lef58conSpc = lef58con->getDefaultSpacing(); @@ -1113,8 +1128,9 @@ void FlexDRWorker::modAdjCutSpacingCost_fixedObj(const frDesign* design, bool hasViol; for (int i = mIdx1.x(); i <= mIdx2.x(); i++) { for (int j = mIdx1.y(); j <= mIdx2.y(); j++) { - if (i == avoidI && j == avoidJ) + if (i == avoidI && j == avoidJ) { continue; + } for (auto& uFig : via.getViaDef()->getCutFigs()) { auto obj = static_cast(uFig.get()); gridGraph_.getPoint(pt, i, j); @@ -1159,28 +1175,35 @@ void FlexDRWorker::modAdjCutSpacingCost_fixedObj(const frDesign* design, } else if (currDistSquare < reqDistSquare) { hasViol = true; } - if (hasViol) + if (hasViol) { break; + } } if (!hasViol && lef58con != nullptr) { bool center2center = false; - if (prl > 0) + if (prl > 0) { reqDistSquare = lef58conSpc.second; - else + } else { reqDistSquare = lef58conSpc.first; - if (lef58con->getDefaultCenterAndEdge()) + } + if (lef58con->getDefaultCenterAndEdge()) { if ((frCoord) reqDistSquare - == std::max(lef58conSpc.first, lef58conSpc.second)) + == std::max(lef58conSpc.first, lef58conSpc.second)) { center2center = true; - if (lef58con->getDefaultCenterToCenter()) + } + } + if (lef58con->getDefaultCenterToCenter()) { center2center = true; + } reqDistSquare *= reqDistSquare; - if (center2center) + if (center2center) { currDistSquare = c2cSquare; - else + } else { currDistSquare = distSquare; - if (currDistSquare < reqDistSquare) + } + if (currDistSquare < reqDistSquare) { hasViol = true; + } } if (hasViol) { @@ -1216,8 +1239,9 @@ void FlexDRWorker::modInterLayerCutSpacingCost(const Rect& box, auto cutLayerNum2 = isUpperVia ? cutLayerNum1 + 2 : cutLayerNum1 - 2; auto z2 = isUpperVia ? z + 1 : z - 1; if (cutLayerNum2 > getTech()->getTopLayerNum() - || cutLayerNum2 < getTech()->getBottomLayerNum()) + || cutLayerNum2 < getTech()->getBottomLayerNum()) { return; + } frLayer* layer1 = getTech()->getLayer(cutLayerNum1); frLayer* layer2 = getTech()->getLayer(cutLayerNum2); @@ -1235,21 +1259,27 @@ void FlexDRWorker::modInterLayerCutSpacingCost(const Rect& box, // LEF58_SPACINGTABLE START frLef58CutSpacingTableConstraint* lef58con; std::pair lef58conSpc; - if (!isUpperVia) + if (!isUpperVia) { lef58con = layer1->getLef58DefaultInterCutSpcTblConstraint(); - else + } else { lef58con = layer2->getLef58DefaultInterCutSpcTblConstraint(); + } if (lef58con != nullptr) { auto dbRule = lef58con->getODBRule(); - if (!isUpperVia && dbRule->getSecondLayer()->getName() != layer2->getName()) + if (!isUpperVia + && dbRule->getSecondLayer()->getName() != layer2->getName()) { lef58con = nullptr; - if (isUpperVia && dbRule->getSecondLayer()->getName() != layer1->getName()) + } + if (isUpperVia + && dbRule->getSecondLayer()->getName() != layer1->getName()) { lef58con = nullptr; + } } // LEF58_SPACINGTABLE END - if (con == nullptr && lef58con == nullptr) + if (con == nullptr && lef58con == nullptr) { return; + } // obj1 = curr obj // obj2 = other obj @@ -1259,8 +1289,9 @@ void FlexDRWorker::modInterLayerCutSpacingCost(const Rect& box, // spacing value needed frCoord bloatDist = 0; - if (con != nullptr) + if (con != nullptr) { bloatDist = con->getCutSpacing(); + } if (lef58con != nullptr) { lef58conSpc = lef58con->getDefaultSpacing(); bloatDist @@ -1304,25 +1335,31 @@ void FlexDRWorker::modInterLayerCutSpacingCost(const Rect& box, reqDistSquare = con->getCutSpacing(); reqDistSquare *= reqDistSquare; currDistSquare = con->hasCenterToCenter() ? c2cSquare : distSquare; - if (currDistSquare < reqDistSquare) + if (currDistSquare < reqDistSquare) { hasViol = true; + } } if (!hasViol && lef58con != nullptr) { bool center2center = false; - if (prl > 0) + if (prl > 0) { reqDistSquare = lef58conSpc.second; - else + } else { reqDistSquare = lef58conSpc.first; - if (lef58con->getDefaultCenterAndEdge()) + } + if (lef58con->getDefaultCenterAndEdge()) { if ((frCoord) reqDistSquare - == std::max(lef58conSpc.first, lef58conSpc.second)) + == std::max(lef58conSpc.first, lef58conSpc.second)) { center2center = true; - if (lef58con->getDefaultCenterToCenter()) + } + } + if (lef58con->getDefaultCenterToCenter()) { center2center = true; + } reqDistSquare *= reqDistSquare; currDistSquare = center2center ? c2cSquare : distSquare; - if (currDistSquare < reqDistSquare) + if (currDistSquare < reqDistSquare) { hasViol = true; + } } if (hasViol) { @@ -1393,8 +1430,9 @@ void FlexDRWorker::modPathCost(drConnFig* connFig, modMinSpacingCostPlanar(box, zIdx, type, false, ndr); modMinSpacingCostVia(box, zIdx, type, true, true, false, ndr); modMinSpacingCostVia(box, zIdx, type, false, true, false, ndr); - if (modEol) + if (modEol) { modEolSpacingRulesCost(box, zIdx, type); + } } else if (connFig->typeId() == drcVia) { auto obj = static_cast(connFig); auto [bi, ei] = obj->getMazeIdx(); @@ -1406,8 +1444,9 @@ void FlexDRWorker::modPathCost(drConnFig* connFig, modMinSpacingCostPlanar(box, bi.z(), type, false, ndr); modMinSpacingCostVia(box, bi.z(), type, true, false, false, ndr); modMinSpacingCostVia(box, bi.z(), type, false, false, false, ndr); - if (modEol) + if (modEol) { modEolSpacingRulesCost(box, bi.z(), type, false, ndr); + } // assumes enclosure for via is always rectangle box = obj->getLayer2BBox(); @@ -1415,8 +1454,9 @@ void FlexDRWorker::modPathCost(drConnFig* connFig, modMinSpacingCostPlanar(box, ei.z(), type, false, ndr); modMinSpacingCostVia(box, ei.z(), type, true, false, false, ndr); modMinSpacingCostVia(box, ei.z(), type, false, false, false, ndr); - if (modEol) + if (modEol) { modEolSpacingRulesCost(box, ei.z(), type, false, ndr); + } dbTransform xform; Point pt = obj->getOrigin(); @@ -1425,8 +1465,9 @@ void FlexDRWorker::modPathCost(drConnFig* connFig, auto rect = static_cast(uFig.get()); box = rect->getBBox(); xform.apply(box); - if (modCutSpc) + if (modCutSpc) { modCutSpacingCost(box, bi.z(), type); + } modInterLayerCutSpacingCost(box, bi.z(), type, true); modInterLayerCutSpacingCost(box, bi.z(), type, false); } @@ -1438,14 +1479,20 @@ bool FlexDRWorker::mazeIterInit_sortRerouteNets( std::vector& rerouteNets) { auto rerouteNetsComp = [](drNet* const& a, drNet* const& b) { - if (a->getPriority() > b->getPriority()) + if (a->getPriority() > b->getPriority()) { return true; - if (a->getPriority() < b->getPriority()) + } + if (a->getPriority() < b->getPriority()) { return false; - if (a->getFrNet()->getAbsPriorityLvl() > b->getFrNet()->getAbsPriorityLvl()) + } + if (a->getFrNet()->getAbsPriorityLvl() + > b->getFrNet()->getAbsPriorityLvl()) { return true; - if (a->getFrNet()->getAbsPriorityLvl() < b->getFrNet()->getAbsPriorityLvl()) + } + if (a->getFrNet()->getAbsPriorityLvl() + < b->getFrNet()->getAbsPriorityLvl()) { return false; + } Rect boxA = a->getPinBox(); Rect boxB = b->getPinBox(); auto areaA = boxA.area(); @@ -1481,10 +1528,10 @@ bool FlexDRWorker::mazeIterInit_sortRerouteQueue( = [](RouteQueueEntry const& a, RouteQueueEntry const& b) { auto block1 = a.block; auto block2 = b.block; - if (block1->typeId() == block2->typeId()) + if (block1->typeId() == block2->typeId()) { return block1->getId() < block2->getId(); - else - return block1->typeId() < block2->typeId(); + } + return block1->typeId() < block2->typeId(); }; // sort if (mazeIter == 0) { @@ -1545,8 +1592,9 @@ void FlexDRWorker::route_queue() for (auto& marker : markers_) { std::cout << marker << "\n"; } - if (needRecheck_) + if (needRecheck_) { std::cout << "(Needs recheck)\n"; + } } // init net status @@ -1601,8 +1649,9 @@ void FlexDRWorker::route_queue() graphics_->show(true); } - if (getDRIter() >= 7 && getDRIter() <= 30) + if (getDRIter() >= 7 && getDRIter() <= 30) { identifyCongestionLevel(); + } } void FlexDRWorker::identifyCongestionLevel() @@ -1613,48 +1662,56 @@ void FlexDRWorker::identifyCongestionLevel() bool bpLow = false, bpHigh = false; for (auto& uPin : net->getPins()) { drPin* pin = uPin.get(); - if (pin->hasFrTerm()) + if (pin->hasFrTerm()) { continue; + } for (auto& uAP : pin->getAccessPatterns()) { drAccessPattern* ap = uAP.get(); if (design_->isVerticalLayer(ap->getBeginLayerNum())) { - if (ap->getPoint().y() == getRouteBox().yMin()) + if (ap->getPoint().y() == getRouteBox().yMin()) { bpLow = true; - else if (ap->getPoint().y() == getRouteBox().yMax()) + } else if (ap->getPoint().y() == getRouteBox().yMax()) { bpHigh = true; + } } else { - if (ap->getPoint().x() == getRouteBox().xMin()) + if (ap->getPoint().x() == getRouteBox().xMin()) { bpLow = true; - else if (ap->getPoint().x() == getRouteBox().xMax()) + } else if (ap->getPoint().x() == getRouteBox().xMax()) { bpHigh = true; + } } } } - if (bpLow && bpHigh) + if (bpLow && bpHigh) { bpNets.push_back(net); + } } std::vector nLowBorderCross(gridGraph_.getLayerCount(), 0); std::vector nHighBorderCross(gridGraph_.getLayerCount(), 0); for (drNet* net : bpNets) { for (auto& uPin : net->getPins()) { drPin* pin = uPin.get(); - if (pin->hasFrTerm()) + if (pin->hasFrTerm()) { continue; + } for (auto& uAP : pin->getAccessPatterns()) { drAccessPattern* ap = uAP.get(); frMIdx z = gridGraph_.getMazeZIdx(ap->getBeginLayerNum()); - if (z < 4) + if (z < 4) { continue; + } if (design_->isVerticalLayer(ap->getBeginLayerNum())) { - if (ap->getPoint().y() == getRouteBox().yMin()) + if (ap->getPoint().y() == getRouteBox().yMin()) { nLowBorderCross[z]++; - else if (ap->getPoint().y() == getRouteBox().yMax()) + } else if (ap->getPoint().y() == getRouteBox().yMax()) { nHighBorderCross[z]++; + } } else { - if (ap->getPoint().x() == getRouteBox().xMin()) + if (ap->getPoint().x() == getRouteBox().xMin()) { nLowBorderCross[z]++; - else if (ap->getPoint().x() == getRouteBox().xMax()) + } else if (ap->getPoint().x() == getRouteBox().xMax()) { nHighBorderCross[z]++; + } } } } @@ -1666,20 +1723,23 @@ void FlexDRWorker::identifyCongestionLevel() int workerSize; if (design_->isHorizontalLayer(lNum)) { for (auto& utp : trackPatterns) { - if (!utp->isHorizontal()) // reminder: trackPattern isHorizontal means - // vertical tracks + if (!utp->isHorizontal()) { // reminder: trackPattern isHorizontal + // means vertical tracks tp = utp.get(); + } } workerSize = getRouteBox().dy(); } else { for (auto& utp : trackPatterns) { - if (utp->isHorizontal()) + if (utp->isHorizontal()) { tp = utp.get(); + } } workerSize = getRouteBox().dx(); } - if (tp == nullptr) + if (tp == nullptr) { continue; + } int nTracks = workerSize / tp->getTrackSpacing(); // 1 track error margin float congestionFactorLow = nLowBorderCross[z] / (float) nTracks; float congestionFactorHigh = nHighBorderCross[z] / (float) nTracks; @@ -1715,8 +1775,9 @@ void FlexDRWorker::route_queue_main(std::queue& rerouteQueue) net->getFrNet()->setModified(true); } net->setNumMarkers(0); - if (graphics_) + if (graphics_) { graphics_->startNet(net); + } for (auto& uConnFig : net->getRouteConnFigs()) { subPathCost(uConnFig.get()); workerRegionQuery.remove(uConnFig.get()); // worker region query @@ -1731,8 +1792,9 @@ void FlexDRWorker::route_queue_main(std::queue& rerouteQueue) initMazeCost_via_helper(net, false); } net->clear(); - if (getDRIter() >= beginDebugIter) + if (getDRIter() >= beginDebugIter) { logger_->info(DRT, 2002, "Routing net {}", net->getFrNet()->getName()); + } // route mazeNetInit(net); bool isRouted = routeNet(net); @@ -1776,8 +1838,9 @@ void FlexDRWorker::route_queue_main(std::queue& rerouteQueue) drNet* currNet = net; for (auto& pwire : gcWorker_->getPWires()) { auto net = pwire->getNet(); - if (!net) + if (!net) { net = currNet; + } auto tmpPWire = std::make_unique(); tmpPWire->setLayerNum(pwire->getLayerNum()); Point origin = pwire->getOrigin(); @@ -1847,12 +1910,14 @@ void FlexDRWorker::modEolCosts_poly(gcPin* shape, ModCostType modType) { auto eol = layer->getDrEolSpacingConstraint(); - if (eol.eolSpace == 0) + if (eol.eolSpace == 0) { return; + } for (auto& edges : shape->getPolygonEdges()) { for (auto& edge : edges) { - if (edge->length() >= eol.eolWidth) + if (edge->length() >= eol.eolWidth) { continue; + } frCoord low, high, line; bool innerDirIsIncreasing; // x: increases to the east, y: increases to // the north @@ -1889,19 +1954,21 @@ void FlexDRWorker::modEolCost(frCoord low, Rect testBox; auto eol = layer->getDrEolSpacingConstraint(); if (isVertical) { - if (innerDirIsIncreasing) + if (innerDirIsIncreasing) { testBox.init( line - eol.eolSpace, low - eol.eolWithin, line, high + eol.eolWithin); - else + } else { testBox.init( line, low - eol.eolWithin, line + eol.eolSpace, high + eol.eolWithin); + } } else { - if (innerDirIsIncreasing) + if (innerDirIsIncreasing) { testBox.init( low - eol.eolWithin, line - eol.eolSpace, high + eol.eolWithin, line); - else + } else { testBox.init( low - eol.eolWithin, line, high + eol.eolWithin, line + eol.eolSpace); + } } frMIdx z = gridGraph_.getMazeZIdx(layer->getLayerNum()); modEolSpacingCost_helper(testBox, z, modType, 0); @@ -1914,22 +1981,26 @@ void FlexDRWorker::cleanUnneededPatches_poly(gcNet* drcNet, drNet* net) std::vector> areaMap(getTech()->getTopLayerNum() + 1); std::vector patchesToRemove; for (auto& shape : net->getRouteConnFigs()) { - if (shape->typeId() != frBlockObjectEnum::drcPatchWire) + if (shape->typeId() != frBlockObjectEnum::drcPatchWire) { continue; + } drPatchWire* patch = static_cast(shape.get()); gtl::point_data pt(patch->getOrigin().x(), patch->getOrigin().y()); frLayerNum lNum = patch->getLayerNum(); frCoord minArea = getTech()->getLayer(lNum)->getAreaConstraint()->getMinArea(); - if (areaMap[lNum].empty()) + if (areaMap[lNum].empty()) { areaMap[lNum].assign(drcNet->getPins(lNum).size(), -1); + } for (int i = 0; i < drcNet->getPins(lNum).size(); i++) { auto& pin = drcNet->getPins(lNum)[i]; - if (!gtl::contains(*pin->getPolygon(), pt)) + if (!gtl::contains(*pin->getPolygon(), pt)) { continue; + } frCoord area; - if (areaMap[lNum][i] == -1) + if (areaMap[lNum][i] == -1) { areaMap[lNum][i] = gtl::area(*pin->getPolygon()); + } area = areaMap[lNum][i]; if (area - patch->getOffsetBox().area() >= minArea) { patchesToRemove.push_back(patch); @@ -1949,8 +2020,9 @@ void FlexDRWorker::modEolCosts_poly(gcNet* net, ModCostType modType) lNum <= getTech()->getTopLayerNum(); lNum++) { auto layer = getTech()->getLayer(lNum); - if (layer->getType() != dbTechLayerType::ROUTING) + if (layer->getType() != dbTechLayerType::ROUTING) { continue; + } for (auto& pin : net->getPins(lNum)) { modEolCosts_poly(pin.get(), layer, modType); } @@ -1964,15 +2036,17 @@ void FlexDRWorker::routeNet_prep( mazeIdx2unConnPins, std::set& apMazeIdx, std::set& realPinAPMazeIdx, - std::map& mazeIdx2Tbox, + std::map& mazeIdx2TaperBox, std::list>& pinTaperBoxes) { frBox3D* tbx = nullptr; - if (getDRIter() >= beginDebugIter) + if (getDRIter() >= beginDebugIter) { logger_->info(DRT, 2005, "Creating dest search points from pins:"); + } for (auto& pin : net->getPins()) { - if (getDRIter() >= beginDebugIter) + if (getDRIter() >= beginDebugIter) { logger_->info(DRT, 2006, "Pin {}", pin->getName()); + } unConnPins.insert(pin.get()); if (gridGraph_.getNDR()) { if (AUTO_TAPER_NDR_NETS @@ -1989,14 +2063,16 @@ void FlexDRWorker::routeNet_prep( gridGraph_.getMazeYIdx(gridGraph_.yCoord(h.y()) + r * pitch), h.z()); frMIdx z = l.z() == 0 ? 1 : h.z(); - pinTaperBoxes.push_back(std::make_pair( - pin.get(), frBox3D(l.x(), l.y(), h.x(), h.y(), l.z(), z))); + pinTaperBoxes.emplace_back( + pin.get(), frBox3D(l.x(), l.y(), h.x(), h.y(), l.z(), z)); tbx = &std::prev(pinTaperBoxes.end())->second; for (z = tbx->zLow(); z <= tbx->zHigh(); z++) { // populate the map from points to taper boxes - for (int x = tbx->xMin(); x <= tbx->xMax(); x++) - for (int y = tbx->yMin(); y <= tbx->yMax(); y++) - mazeIdx2Tbox[FlexMazeIdx(x, y, z)] = tbx; + for (int x = tbx->xMin(); x <= tbx->xMax(); x++) { + for (int y = tbx->yMin(); y <= tbx->yMax(); y++) { + mazeIdx2TaperBox[FlexMazeIdx(x, y, z)] = tbx; + } + } } } } @@ -2054,6 +2130,9 @@ void FlexDRWorker::routeNet_setSrc( break; } } + if (totAPCnt == 0) { + logger_->error(DRT, 423, "No access points found"); + } const frCoord centerX = totX / totAPCnt; const frCoord centerY = totY / totAPCnt; const frCoord centerZ = totZ / totAPCnt; @@ -2279,16 +2358,19 @@ void FlexDRWorker::routeNet_postAstarWritePath( auto& workerRegionQuery = getWorkerRegionQuery(); frBox3D *srcBox = nullptr, *dstBox = nullptr; auto it = mazeIdx2TaperBox.find(points[0]); - if (it != mazeIdx2TaperBox.end()) + if (it != mazeIdx2TaperBox.end()) { dstBox = it->second; + } it = mazeIdx2TaperBox.find(points.back()); - if (it != mazeIdx2TaperBox.end()) + if (it != mazeIdx2TaperBox.end()) { srcBox = it->second; + } if (points.size() == 1) { if (net->getFrAccessPoint(gridGraph_.xCoord(points[0].x()), gridGraph_.yCoord(points[0].y()), - gridGraph_.getLayerNum(points[0].z()))) + gridGraph_.getLayerNum(points[0].z()))) { addApPathSegs(points[0], net); + } } for (int i = 0; i < (int) points.size() - 1; ++i) { FlexMazeIdx start, end; @@ -2401,15 +2483,17 @@ void FlexDRWorker::routeNet_postAstarWritePath( pin may still be over an unseen AP (this is checked by checkViaConnectivity) */ if (realPinApMazeIdx.find(mzIdxBot) != realPinApMazeIdx.end()) { - if (!addApPathSegs(mzIdxBot, net)) + if (!addApPathSegs(mzIdxBot, net)) { currVia->setBottomConnected(true); + } } else { checkViaConnectivityToAP( currVia.get(), true, net->getFrNet(), apMazeIdx, mzIdxBot); } if (realPinApMazeIdx.find(mzIdxTop) != realPinApMazeIdx.end()) { - if (!addApPathSegs(mzIdxTop, net)) + if (!addApPathSegs(mzIdxTop, net)) { currVia->setTopConnected(true); + } } else { checkViaConnectivityToAP( currVia.get(), false, net->getFrNet(), apMazeIdx, mzIdxTop); @@ -2437,34 +2521,39 @@ bool FlexDRWorker::addApPathSegs(const FlexMazeIdx& apIdx, drNet* net) frLayerNum lNum = gridGraph_.getLayerNum(apIdx.z()); frBlockObject* owner = nullptr; frAccessPoint* ap = net->getFrAccessPoint(x, y, lNum, &owner); - if (!ap) // on-the-fly ap + if (!ap) { // on-the-fly ap return false; + } assert(owner != nullptr); frInst* inst = nullptr; - if (owner->typeId() == frBlockObjectEnum::frcInstTerm) + if (owner->typeId() == frBlockObjectEnum::frcInstTerm) { inst = static_cast(owner)->getInst(); + } assert(ap != nullptr); - if (ap->getPathSegs().empty()) + if (ap->getPathSegs().empty()) { return false; + } for (auto& ps : ap->getPathSegs()) { std::unique_ptr drPs = std::make_unique(); Point begin = ps.getBeginPoint(); Point end = ps.getEndPoint(); Point* connecting = nullptr; - if (ps.getBeginStyle() == frEndStyle(frcTruncateEndStyle)) + if (ps.getBeginStyle() == frEndStyle(frcTruncateEndStyle)) { connecting = &begin; - else if (ps.getEndStyle() == frEndStyle(frcTruncateEndStyle)) + } else if (ps.getEndStyle() == frEndStyle(frcTruncateEndStyle)) { connecting = &end; + } if (inst) { dbTransform trans = inst->getTransform(); trans.setOrient(dbOrientType(dbOrientType::R0)); trans.apply(begin); trans.apply(end); if (end < begin) { // if rotation swapped order, correct it - if (connecting == &begin) + if (connecting == &begin) { connecting = &end; - else + } else { connecting = &begin; + } Point tmp = begin; begin = end; end = tmp; @@ -2474,14 +2563,16 @@ bool FlexDRWorker::addApPathSegs(const FlexMazeIdx& apIdx, drNet* net) drPs->setLayerNum(lNum); drPs->addToNet(net); auto currStyle = getTech()->getLayer(lNum)->getDefaultSegStyle(); - if (connecting == &begin) + if (connecting == &begin) { currStyle.setBeginStyle(frcTruncateEndStyle, 0); - else if (connecting == &end) + } else if (connecting == &end) { currStyle.setEndStyle(frcTruncateEndStyle, 0); + } - if (net->getFrNet()->getNondefaultRule()) + if (net->getFrNet()->getNondefaultRule()) { drPs->setTapered( true); // these tiny access pathsegs should all be tapered + } drPs->setStyle(currStyle); FlexMazeIdx startIdx, endIdx; gridGraph_.getMazeIdx(startIdx, begin, lNum); @@ -2518,37 +2609,34 @@ bool FlexDRWorker::splitPathSeg(frMIdx& midX, taperFirstPiece = true; if (bx->contains(endX, endY, z, 1, 1)) { return false; + } + if (startX == endX) { + midX = startX; + midY = bx->yMax() + 1; } else { - if (startX == endX) { - midX = startX; - midY = bx->yMax() + 1; - } else { - midX = bx->xMax() + 1; - midY = startY; - } - return true; + midX = bx->xMax() + 1; + midY = startY; } - } else { - if (srcBox && srcBox->contains(endX, endY, z)) { - bx = srcBox; - } else if (dstBox && dstBox->contains(endX, endY, z)) { - bx = dstBox; - } - if (bx) { - if (bx->contains(startX, startY, z, 1, 1)) { - taperFirstPiece = true; - return false; - } else { - if (startX == endX) { - midX = startX; - midY = bx->yMin() - 1; - } else { - midX = bx->xMin() - 1; - midY = startY; - } - return true; - } + return true; + } + if (srcBox && srcBox->contains(endX, endY, z)) { + bx = srcBox; + } else if (dstBox && dstBox->contains(endX, endY, z)) { + bx = dstBox; + } + if (bx) { + if (bx->contains(startX, startY, z, 1, 1)) { + taperFirstPiece = true; + return false; } + if (startX == endX) { + midX = startX; + midY = bx->yMin() - 1; + } else { + midX = bx->xMin() - 1; + midY = startY; + } + return true; } return false; } @@ -2577,21 +2665,23 @@ void FlexDRWorker::processPathSeg(frMIdx startX, auto layer = getTech()->getLayer(currLayerNum); auto currStyle = layer->getDefaultSegStyle(); if (realApMazeIdx.find(start) != realApMazeIdx.end()) { - if (!addApPathSegs(start, net)) + if (!addApPathSegs(start, net)) { currStyle.setBeginStyle(frcTruncateEndStyle, 0); + } } else { checkPathSegStyle(currPathSeg.get(), true, currStyle, apMazeIdx, start); } if (realApMazeIdx.find(end) != realApMazeIdx.end()) { - if (!addApPathSegs(end, net)) + if (!addApPathSegs(end, net)) { currStyle.setEndStyle(frcTruncateEndStyle, 0); + } } else { checkPathSegStyle(currPathSeg.get(), false, currStyle, apMazeIdx, end); } if (net->getFrNet()->getNondefaultRule()) { - if (taper) + if (taper) { currPathSeg->setTapered(true); - else + } else { setNDRStyle(net, currStyle, startX, @@ -2601,6 +2691,7 @@ void FlexDRWorker::processPathSeg(frMIdx startX, z, i - 1 >= 0 ? &points[i - 1] : nullptr, i + 2 < (int) points.size() ? &points[i + 2] : nullptr); + } } else if (layer->isVertical() != segIsVertical) { // wrong way segment currStyle.setWidth(layer->getWrongDirWidth()); } else { @@ -2655,14 +2746,16 @@ void FlexDRWorker::checkPathSegStyle(drPathSeg* ps, { const Point& pt = (isBegin ? ps->getBeginPoint() : ps->getEndPoint()); if (apMazeIdx.find(idx) == apMazeIdx.end() - && !isInWorkerBorder(pt.x(), pt.y())) + && !isInWorkerBorder(pt.x(), pt.y())) { return; + } if (hasAccessPoint(pt, ps->getLayerNum(), ps->getNet()->getFrNet())) { if (!addApPathSegs(idx, ps->getNet())) { - if (isBegin) + if (isBegin) { style.setBeginStyle(frEndStyle(frEndStyleEnum::frcTruncateEndStyle), 0); - else + } else { style.setEndStyle(frEndStyle(frEndStyleEnum::frcTruncateEndStyle), 0); + } } } } @@ -2677,15 +2770,17 @@ bool FlexDRWorker::hasAccessPoint(const Point& pt, frLayerNum lNum, frNet* net) case frcInstTerm: { auto instTerm = static_cast(rqObj.second); if (instTerm->getNet() == net - && instTerm->hasAccessPoint(pt.x(), pt.y(), lNum)) + && instTerm->hasAccessPoint(pt.x(), pt.y(), lNum)) { return true; + } break; } case frcBTerm: { auto term = static_cast(rqObj.second); if (term->getNet() == net - && term->hasAccessPoint(pt.x(), pt.y(), lNum, 0)) + && term->hasAccessPoint(pt.x(), pt.y(), lNum, 0)) { return true; + } break; } default: @@ -2704,19 +2799,22 @@ void FlexDRWorker::checkViaConnectivityToAP( const FlexMazeIdx& idx) { if (apMazeIdx.find(idx) == apMazeIdx.end() - && !isInWorkerBorder(via->getOrigin().x(), via->getOrigin().y())) + && !isInWorkerBorder(via->getOrigin().x(), via->getOrigin().y())) { return; + } if (isBottom) { if (hasAccessPoint( via->getOrigin(), via->getViaDef()->getLayer1Num(), net)) { - if (!addApPathSegs(idx, via->getNet())) + if (!addApPathSegs(idx, via->getNet())) { via->setBottomConnected(true); + } } } else { if (hasAccessPoint( via->getOrigin(), via->getViaDef()->getLayer2Num(), net)) { - if (!addApPathSegs(idx, via->getNet())) + if (!addApPathSegs(idx, via->getNet())) { via->setTopConnected(true); + } } } } @@ -2742,16 +2840,18 @@ void FlexDRWorker::setNDRStyle(drNet* net, hasBeginExt = hasEndExt = true; } else if (!prev) { if (abs(next->x() - startX) + abs(next->y() - startY) - < abs(next->x() - endX) + abs(next->y() - endY)) + < abs(next->x() - endX) + abs(next->y() - endY)) { hasEndExt = true; - else + } else { hasBeginExt = true; + } } else if (!next) { if (abs(prev->x() - startX) + abs(prev->y() - startY) - < abs(prev->x() - endX) + abs(prev->y() - endY)) + < abs(prev->x() - endX) + abs(prev->y() - endY)) { hasEndExt = true; - else + } else { hasBeginExt = true; + } } if (prev && prev->z() != z && prev->x() == startX && prev->y() == startY) { hasBeginExt = true; @@ -2766,14 +2866,16 @@ void FlexDRWorker::setNDRStyle(drNet* net, hasEndExt = true; } frEndStyle es(frEndStyleEnum::frcVariableEndStyle); - if (hasBeginExt) + if (hasBeginExt) { currStyle.setBeginStyle(es, std::max((int) currStyle.getBeginExt(), (int) ndr->getWireExtension(z))); - if (hasEndExt) + } + if (hasEndExt) { currStyle.setEndStyle(es, std::max((int) currStyle.getEndExt(), (int) ndr->getWireExtension(z))); + } } } @@ -2782,8 +2884,9 @@ inline bool segmentIsOrthogonal(FlexMazeIdx* idx, frMIdx x, bool isVertical) { - if (idx == nullptr) + if (idx == nullptr) { return false; + } bool seg_is_vertical = idx->x() == x; return idx->z() == z && (isVertical != seg_is_vertical); } @@ -2796,11 +2899,13 @@ void FlexDRWorker::editStyleExt(frSegStyle& currStyle, FlexMazeIdx* next) { auto layer = getTech()->getLayer(gridGraph_.getLayerNum(z)); - if (layer->getWrongDirWidth() >= layer->getWidth()) + if (layer->getWrongDirWidth() >= layer->getWidth()) { return; + } bool is_vertical = startX == endX; - if (layer->isVertical() != is_vertical) + if (layer->isVertical() != is_vertical) { return; + } if (segmentIsOrthogonal(next, z, endX, is_vertical) && currStyle.getEndStyle() == frcExtendEndStyle) { currStyle.setEndExt(layer->getWrongDirWidth() / 2); @@ -2820,8 +2925,9 @@ bool FlexDRWorker::isInsideTaperBox( { FlexMazeIdx idx(x, y, startZ); auto it = mazeIdx2TaperBox.find(idx); - if (it != mazeIdx2TaperBox.end()) + if (it != mazeIdx2TaperBox.end()) { return true; + } idx.setZ(endZ); it = mazeIdx2TaperBox.find(idx); return it != mazeIdx2TaperBox.end(); @@ -2836,9 +2942,10 @@ void FlexDRWorker::routeNet_postRouteAddPathCost(drNet* net) void FlexDRWorker::routeNet_AddCutSpcCost(std::vector& path) { - if (path.size() <= 1) + if (path.size() <= 1) { return; - for (unsigned long i = 1; i < path.size(); i++) { + } + for (uint64_t i = 1; i < path.size(); i++) { if (path[i].z() != path[i - 1].z()) { frMIdx z = std::min(path[i].z(), path[i - 1].z()); frViaDef* viaDef = design_->getTech() @@ -2885,8 +2992,9 @@ bool FlexDRWorker::routeNet(drNet* net) if (net->getPins().size() <= 1) { return true; } - if (graphics_) + if (graphics_) { graphics_->show(true); + } std::set unConnPins; std::map> mazeIdx2unConnPins; std::map @@ -3266,14 +3374,16 @@ frCoord FlexDRWorker::getHalfViaEncArea(frMIdx z, bool isLayer1, frNonDefaultRule* ndr) { - if (!ndr || !ndr->getPrefVia(z)) + if (!ndr || !ndr->getPrefVia(z)) { return gridGraph_.getHalfViaEncArea(z, isLayer1); + } frVia via(ndr->getPrefVia(z)); Rect box; - if (isLayer1) + if (isLayer1) { box = via.getLayer1BBox(); - else + } else { box = via.getLayer2BBox(); + } return box.area() / 2; } // assumes patchWidth == defaultWidth @@ -3303,8 +3413,8 @@ int FlexDRWorker::routeNet_postAstarAddPathMetal_isClean( } } // for wire, no need to bloat width - Point patchLL = std::min(origin, patchEnd); - Point patchUR = std::max(origin, patchEnd); + const Point& patchLL = std::min(origin, patchEnd); + const Point& patchUR = std::max(origin, patchEnd); if (!getRouteBox().intersects(patchEnd)) { cost = std::numeric_limits::max(); } else { @@ -3440,3 +3550,5 @@ void FlexDRWorker::routeNet_postAstarAddPatchMetal(drNet* net, net, epIdx, isPatchHorz, epPatchLeft, patchLength, patchWidth); } } + +} // namespace fr diff --git a/src/drt/src/dr/FlexDR_rq.cpp b/src/drt/src/dr/FlexDR_rq.cpp index 6484c6d1aa1..bd912e7aa2c 100644 --- a/src/drt/src/dr/FlexDR_rq.cpp +++ b/src/drt/src/dr/FlexDR_rq.cpp @@ -29,7 +29,7 @@ #include "dr/FlexDR.h" #include "frRTree.h" -using namespace fr; +namespace fr { // I believe it is safe not to sort the query results here despite the // use of the serializer. Most of the use of the query is in init() @@ -261,3 +261,5 @@ bool FlexDRWorkerRegionQuery::isEmpty() const { return impl_->shapes_.empty(); } + +} // namespace fr diff --git a/src/drt/src/dr/FlexGridGraph.cpp b/src/drt/src/dr/FlexGridGraph.cpp index 27232b9bf86..f20d96d0b64 100644 --- a/src/drt/src/dr/FlexGridGraph.cpp +++ b/src/drt/src/dr/FlexGridGraph.cpp @@ -34,7 +34,7 @@ #include "dr/FlexDR.h" -using namespace fr; +namespace fr { void FlexGridGraph::initGrids( const std::map>& xMap, @@ -77,14 +77,14 @@ void FlexGridGraph::initGrids( srcs_.clear(); dsts_.clear(); - prevDirs_.resize(capacity * 3, 0); - srcs_.resize(capacity, 0); - dsts_.resize(capacity, 0); + prevDirs_.resize(capacity * 3, false); + srcs_.resize(capacity, false); + dsts_.resize(capacity, false); guides_.clear(); if (followGuide) { - guides_.resize(capacity, 0); + guides_.resize(capacity, false); } else { - guides_.resize(capacity, 1); + guides_.resize(capacity, true); } } @@ -94,8 +94,9 @@ bool FlexGridGraph::outOfDieVia(frMIdx x, const Rect& dieBox) { frLayerNum lNum = getLayerNum(z) + 1; - if (lNum > getTech()->getTopLayerNum()) + if (lNum > getTech()->getTopLayerNum()) { return false; + } frViaDef* via = getTech()->getLayer(lNum)->getDefaultViaDef(); if (!via) { return true; @@ -150,9 +151,10 @@ bool FlexGridGraph::hasOutOfDieViol(frMIdx x, frMIdx y, frMIdx z) bool FlexGridGraph::isWorkerBorder(frMIdx v, bool isVert) { - if (isVert) + if (isVert) { return xCoords_[v] == drWorker_->getRouteBox().xMin() || xCoords_[v] == drWorker_->getRouteBox().xMax(); + } return yCoords_[v] == drWorker_->getRouteBox().yMin() || yCoords_[v] == drWorker_->getRouteBox().yMax(); } @@ -166,13 +168,15 @@ bool FlexGridGraph::hasAlignedUpDefTrack( lNum += 2) { auto it = xSubMap.find(lNum); if (it != xSubMap.end()) { // has x track in lNum - if (it->second) // has track pattern, i.e., the track is default + if (it->second) { // has track pattern, i.e., the track is default return true; + } } it = ySubMap.find(lNum); if (it != ySubMap.end()) { // has y track in lNum - if (it->second) // has track pattern, i.e., the track is default + if (it->second) { // has track pattern, i.e., the track is default return true; + } } } return false; @@ -302,8 +306,9 @@ void FlexGridGraph::initEdges( int inc = up ? 1 : -1; frMIdx startZ = getMazeZIdx(apPt.z()); frLayerNum nextLNum = getLayerNum(startZ) + 2 * inc; - if (!up) + if (!up) { startZ--; + } frMIdx xIdx = getMazeXIdx(apPt.x()); frMIdx yIdx = getMazeYIdx(apPt.y()); // create the edges @@ -317,14 +322,16 @@ void FlexGridGraph::initEdges( if (!restrictedRouting || nextLayer->isVertical()) { auto& xSubMap = xMap[apPt.x()]; auto xTrack = xSubMap.find(nextLNum); - if (xTrack != xSubMap.end() && xTrack->second != nullptr) + if (xTrack != xSubMap.end() && xTrack->second != nullptr) { break; + } } if (!restrictedRouting || nextLayer->isHorizontal()) { auto& ySubMap = yMap[apPt.y()]; auto yTrack = ySubMap.find(nextLNum); - if (yTrack != ySubMap.end() && yTrack->second != nullptr) + if (yTrack != ySubMap.end() && yTrack->second != nullptr) { break; + } } // didn't find default track, then create tracks if possible if (!restrictedRouting && nextLNum >= VIA_ACCESS_LAYERNUM) { @@ -383,9 +390,11 @@ void FlexGridGraph::init( // get all tracks intersecting with the Maze bbox, left/bottom are inclusive void FlexGridGraph::initTracks( const frDesign* design, - std::map>& xMap, - std::map>& yMap, - std::map& zMap, + std::map>& + horLoc2TrackPatterns, + std::map>& + vertLoc2TrackPatterns, + std::map& layerNum2PreRouteDir, const Rect& bbox) { for (auto& layer : getTech()->getLayers()) { @@ -421,14 +430,14 @@ void FlexGridGraph::initTracks( frCoord trackLoc = trackNum * tp->getTrackSpacing() + tp->getStartCoord(); if (tp->isHorizontal()) { - xMap[trackLoc][currLayerNum] = tp.get(); + horLoc2TrackPatterns[trackLoc][currLayerNum] = tp.get(); } else { - yMap[trackLoc][currLayerNum] = tp.get(); + vertLoc2TrackPatterns[trackLoc][currLayerNum] = tp.get(); } } } } - zMap[currLayerNum] = currPrefRouteDir; + layerNum2PreRouteDir[currLayerNum] = currPrefRouteDir; } } @@ -441,17 +450,17 @@ void FlexGridGraph::resetStatus() void FlexGridGraph::resetSrc() { - srcs_.assign(srcs_.size(), 0); + srcs_.assign(srcs_.size(), false); } void FlexGridGraph::resetDst() { - dsts_.assign(dsts_.size(), 0); + dsts_.assign(dsts_.size(), false); } void FlexGridGraph::resetPrevNodeDir() { - prevDirs_.assign(prevDirs_.size(), 0); + prevDirs_.assign(prevDirs_.size(), false); } // print the grid graph with edge and vertex for debug purpose @@ -471,10 +480,9 @@ void FlexGridGraph::print() const if (xDim == 0 || yDim == 0 || zDim == 0) { std::cout << "Error: dimension == 0\n"; return; - } else { - std::cout << "extBBox (xDim, yDim, zDim) = (" << xDim << ", " << yDim - << ", " << zDim << ")\n"; } + std::cout << "extBBox (xDim, yDim, zDim) = (" << xDim << ", " << yDim + << ", " << zDim << ")\n"; Point p; for (frMIdx xIdx = 0; xIdx < xDim; ++xIdx) { @@ -520,3 +528,5 @@ void FlexGridGraph::print() const std::cout << "Error: Fail to open maze log\n"; } } + +} // namespace fr diff --git a/src/drt/src/dr/FlexGridGraph.h b/src/drt/src/dr/FlexGridGraph.h index 8f5a63819ab..3aa2ab10890 100644 --- a/src/drt/src/dr/FlexGridGraph.h +++ b/src/drt/src/dr/FlexGridGraph.h @@ -47,20 +47,7 @@ class FlexGridGraph public: // constructors FlexGridGraph(frTechObject* techIn, Logger* loggerIn, FlexDRWorker* workerIn) - : tech_(techIn), - logger_(loggerIn), - drWorker_(workerIn), - graphics_(nullptr), - xCoords_(), - yCoords_(), - zCoords_(), - zHeights_(), - ggDRCCost_(0), - ggMarkerCost_(0), - ggFixedShapeCost_(0), - halfViaEncArea_(nullptr), - ndr_(nullptr), - dstTaperBox(nullptr) + : tech_(techIn), logger_(loggerIn), drWorker_(workerIn) { } // getters @@ -110,7 +97,7 @@ class FlexGridGraph void getBBox(Rect& in) const { - if (xCoords_.size() && yCoords_.size()) { + if (!xCoords_.empty() && !yCoords_.empty()) { in.init( xCoords_.front(), yCoords_.front(), xCoords_.back(), yCoords_.back()); } @@ -283,11 +270,10 @@ class FlexGridGraph { if (dir != frDirEnum::D && dir != frDirEnum::U) { return false; - } else { - correctU(x, y, z, dir); - auto idx = getIdx(x, y, z); - return nodes_[idx].overrideShapeCostVia; } + correctU(x, y, z, dir); + auto idx = getIdx(x, y, z); + return nodes_[idx].overrideShapeCostVia; } // gets route shape cost in the adjacent node following dir frUInt4 getRouteShapeCostAdj(frMIdx x, @@ -659,16 +645,16 @@ class FlexGridGraph } // unsafe access, no idx check - void setSrc(frMIdx x, frMIdx y, frMIdx z) { srcs_[getIdx(x, y, z)] = 1; } + void setSrc(frMIdx x, frMIdx y, frMIdx z) { srcs_[getIdx(x, y, z)] = true; } void setSrc(const FlexMazeIdx& mi) { - srcs_[getIdx(mi.x(), mi.y(), mi.z())] = 1; + srcs_[getIdx(mi.x(), mi.y(), mi.z())] = true; } // unsafe access, no idx check - void setDst(frMIdx x, frMIdx y, frMIdx z) { dsts_[getIdx(x, y, z)] = 1; } + void setDst(frMIdx x, frMIdx y, frMIdx z) { dsts_[getIdx(x, y, z)] = true; } void setDst(const FlexMazeIdx& mi) { - dsts_[getIdx(mi.x(), mi.y(), mi.z())] = 1; + dsts_[getIdx(mi.x(), mi.y(), mi.z())] = true; } // unsafe access void setSVia(frMIdx x, frMIdx y, frMIdx z) @@ -715,16 +701,22 @@ class FlexGridGraph nodes_[getIdx(x, y, z)].hasGridCostUp = true; } // unsafe access, no idx check - void resetSrc(frMIdx x, frMIdx y, frMIdx z) { srcs_[getIdx(x, y, z)] = 0; } + void resetSrc(frMIdx x, frMIdx y, frMIdx z) + { + srcs_[getIdx(x, y, z)] = false; + } void resetSrc(const FlexMazeIdx& mi) { - srcs_[getIdx(mi.x(), mi.y(), mi.z())] = 0; + srcs_[getIdx(mi.x(), mi.y(), mi.z())] = false; } // unsafe access, no idx check - void resetDst(frMIdx x, frMIdx y, frMIdx z) { dsts_[getIdx(x, y, z)] = 0; } + void resetDst(frMIdx x, frMIdx y, frMIdx z) + { + dsts_[getIdx(x, y, z)] = false; + } void resetDst(const FlexMazeIdx& mi) { - dsts_[getIdx(mi.x(), mi.y(), mi.z())] = 0; + dsts_[getIdx(mi.x(), mi.y(), mi.z())] = false; } void resetGridCost(frMIdx x, frMIdx y, frMIdx z, frDirEnum dir) { @@ -917,9 +909,9 @@ class FlexGridGraph } private: - frTechObject* tech_; - Logger* logger_; - FlexDRWorker* drWorker_; + frTechObject* tech_ = nullptr; + Logger* logger_ = nullptr; + FlexDRWorker* drWorker_ = nullptr; FlexDRGraphics* graphics_; // owned by FlexDR // #ifdef DEBUG_DRT_UNDERFLOW @@ -978,50 +970,36 @@ class FlexGridGraph frVector zHeights_; // accumulated Z diff std::vector layerRouteDirections_; Rect dieBox_; - frUInt4 ggDRCCost_; - frUInt4 ggMarkerCost_; + frUInt4 ggDRCCost_ = 0; + frUInt4 ggMarkerCost_ = 0; frUInt4 ggFixedShapeCost_; // temporary variables FlexWavefront wavefront_; - const std::vector>* - halfViaEncArea_; // std::pair + const std::vector>* halfViaEncArea_ + = nullptr; // std::pair // ndr related - frNonDefaultRule* ndr_; - const frBox3D* - dstTaperBox; // taper box for the current dest pin in the search + frNonDefaultRule* ndr_ = nullptr; + const frBox3D* dstTaperBox + = nullptr; // taper box for the current dest pin in the search - FlexGridGraph() - : tech_(nullptr), - drWorker_(nullptr), - graphics_(nullptr), - xCoords_(), - yCoords_(), - zCoords_(), - zHeights_(), - ggDRCCost_(0), - ggMarkerCost_(0), - halfViaEncArea_(nullptr), - ndr_(nullptr), - dstTaperBox(nullptr) - { - } + FlexGridGraph() = default; // unsafe access, no idx check void setPrevAstarNodeDir(frMIdx x, frMIdx y, frMIdx z, frDirEnum dir) { auto baseIdx = 3 * getIdx(x, y, z); - prevDirs_[baseIdx] = ((unsigned short) dir >> 2) & 1; - prevDirs_[baseIdx + 1] = ((unsigned short) dir >> 1) & 1; - prevDirs_[baseIdx + 2] = ((unsigned short) dir) & 1; + prevDirs_[baseIdx] = ((uint16_t) dir >> 2) & 1; + prevDirs_[baseIdx + 1] = ((uint16_t) dir >> 1) & 1; + prevDirs_[baseIdx + 2] = ((uint16_t) dir) & 1; } // unsafe access, no check frDirEnum getPrevAstarNodeDir(const FlexMazeIdx& idx) const { auto baseIdx = 3 * getIdx(idx.x(), idx.y(), idx.z()); - return (frDirEnum) (((unsigned short) (prevDirs_[baseIdx]) << 2) - + ((unsigned short) (prevDirs_[baseIdx + 1]) << 1) - + ((unsigned short) (prevDirs_[baseIdx + 2]) << 0)); + return (frDirEnum) (((uint16_t) (prevDirs_[baseIdx]) << 2) + + ((uint16_t) (prevDirs_[baseIdx + 1]) << 1) + + ((uint16_t) (prevDirs_[baseIdx + 2]) << 0)); } // unsafe access, no check @@ -1098,7 +1076,6 @@ class FlexGridGraph break; default:; } - return; } void correctU(frMIdx& x, frMIdx& y, frMIdx& z, frDirEnum& dir) const { @@ -1109,7 +1086,6 @@ class FlexGridGraph break; default:; } - return; } void reverse(frMIdx& x, frMIdx& y, frMIdx& z, frDirEnum& dir) const { @@ -1140,7 +1116,6 @@ class FlexGridGraph break; default:; } - return; } frMIdx getLowerBoundIndex(const frVector& tracks, frCoord v) const; frMIdx getUpperBoundIndex(const frVector& tracks, frCoord v) const; @@ -1148,19 +1123,18 @@ class FlexGridGraph void getPrevGrid(frMIdx& gridX, frMIdx& gridY, frMIdx& gridZ, - const frDirEnum dir) const; + frDirEnum dir) const; void getNextGrid(frMIdx& gridX, frMIdx& gridY, frMIdx& gridZ, - const frDirEnum dir) const; + frDirEnum dir) const; bool isValid(frMIdx x, frMIdx y, frMIdx z) const { if (x < 0 || y < 0 || z < 0 || x >= (frMIdx) xCoords_.size() || y >= (frMIdx) yCoords_.size() || z >= (frMIdx) zCoords_.size()) { return false; - } else { - return true; } + return true; } bool isValid(frMIdx x, frMIdx y, frMIdx z, frDirEnum dir) const { diff --git a/src/drt/src/dr/FlexGridGraph_maze.cpp b/src/drt/src/dr/FlexGridGraph_maze.cpp index 6635cb45dd3..232289fd68b 100644 --- a/src/drt/src/dr/FlexGridGraph_maze.cpp +++ b/src/drt/src/dr/FlexGridGraph_maze.cpp @@ -30,9 +30,9 @@ #include "dr/FlexDR_graphics.h" #include "dr/FlexGridGraph.h" -using namespace fr; +namespace fr { -int debugMazeIter = std::numeric_limits().max(); +int debugMazeIter = std::numeric_limits::max(); void FlexGridGraph::expand(FlexWavefrontGrid& currGrid, const frDirEnum& dir, const FlexMazeIdx& dstMazeIdx1, @@ -120,9 +120,11 @@ void FlexGridGraph::expand(FlexWavefrontGrid& currGrid, } } if (currGrid.getSrcTaperBox() - && currGrid.getSrcTaperBox()->contains( - nextWavefrontGrid.x(), nextWavefrontGrid.y(), nextWavefrontGrid.z())) + && currGrid.getSrcTaperBox()->contains(nextWavefrontGrid.x(), + nextWavefrontGrid.y(), + nextWavefrontGrid.z())) { nextWavefrontGrid.setSrcTaperBox(currGrid.getSrcTaperBox()); + } // update wavefront buffer auto tailDir = nextWavefrontGrid.shiftAddBuffer(dir); // non-buffer enablement is faster for ripup all @@ -138,14 +140,14 @@ void FlexGridGraph::expand(FlexWavefrontGrid& currGrid, // add to wavefront wavefront_.push(nextWavefrontGrid); } - if (drWorker_->getDRIter() >= debugMazeIter) + if (drWorker_->getDRIter() >= debugMazeIter) { std::cout << "Creating " << nextWavefrontGrid.x() << " " << nextWavefrontGrid.y() << " " << nextWavefrontGrid.z() << " coords: " << xCoords_[nextWavefrontGrid.x()] << " " << yCoords_[nextWavefrontGrid.y()] << " cost " << nextWavefrontGrid.getCost() << " g " << nextWavefrontGrid.getPathCost() << "\n"; - return; + } } void FlexGridGraph::expandWavefront(FlexWavefrontGrid& currGrid, @@ -285,9 +287,9 @@ void FlexGridGraph::getNextGrid(frMIdx& gridX, case frDirEnum::D: --gridZ; break; - default:; + case frDirEnum::UNKNOWN: + break; } - return; } void FlexGridGraph::getPrevGrid(frMIdx& gridX, @@ -314,9 +316,9 @@ void FlexGridGraph::getPrevGrid(frMIdx& gridX, case frDirEnum::D: ++gridZ; break; - default:; + case frDirEnum::UNKNOWN: + break; } - return; } frCost FlexGridGraph::getNextPathCost(const FlexWavefrontGrid& currGrid, @@ -406,8 +408,9 @@ frCost FlexGridGraph::getNextPathCost(const FlexWavefrontGrid& currGrid, if (isForbiddenVia2Via) { if (drWorker_) { - if (drWorker_->getDRIter() >= debugMazeIter) + if (drWorker_->getDRIter() >= debugMazeIter) { std::cout << "isForbiddenVia2Via\n"; + } if (drWorker_->getDRIter() >= 3) { nextPathCost += 2 * ggMarkerCost_ * edgeLength; } else { @@ -459,8 +462,9 @@ frCost FlexGridGraph::getNextPathCost(const FlexWavefrontGrid& currGrid, } if (isForbiddenTLen) { if (drWorker_) { - if (drWorker_->getDRIter() >= debugMazeIter) + if (drWorker_->getDRIter() >= debugMazeIter) { std::cout << "isForbiddenTLen\n"; + } if (drWorker_->getDRIter() >= 3) { nextPathCost += 2 * ggDRCCost_ * edgeLength; } else { @@ -470,9 +474,9 @@ frCost FlexGridGraph::getNextPathCost(const FlexWavefrontGrid& currGrid, } } - if (useNDRCosts(currGrid)) + if (useNDRCosts(currGrid)) { nextPathCost += getCostsNDR(gridX, gridY, gridZ, dir, currDir, layer); - else { + } else { nextPathCost += getCosts(gridX, gridY, gridZ, dir, layer); } @@ -486,8 +490,9 @@ frCoord FlexGridGraph::getCostsNDR(frMIdx gridX, frDirEnum prevDir, frLayer* layer) const { - if ((dir == frDirEnum::U || dir == frDirEnum::D)) + if ((dir == frDirEnum::U || dir == frDirEnum::D)) { return getViaCostsNDR(gridX, gridY, gridZ, dir, prevDir, layer); + } frCoord el = getEdgeLength(gridX, gridY, gridZ, dir); frCoord cost = el; cost += (hasGridCost(gridX, gridY, gridZ, dir) ? GRIDCOST * el : 0); @@ -510,21 +515,23 @@ frCoord FlexGridGraph::getCostsNDR(frMIdx gridX, startY = endY = gridY; y1 = y2 = yCoords_[startY]; if (prevDir == frDirEnum::UNKNOWN || prevDir != dir) { - if (dir == frDirEnum::N) + if (dir == frDirEnum::N) { startY = getLowerBoundIndex(yCoords_, y1 = (yCoords_[gridY] - r - wext)); - else + } else { endY = getUpperBoundIndex(yCoords_, y2 = (yCoords_[gridY] + r + wext)); + } } if (prevDir != frDirEnum::UNKNOWN) { getNextGrid(gridX, gridY, gridZ, dir); if (isDst(gridX, gridY, gridZ)) { - if (dir == frDirEnum::N) + if (dir == frDirEnum::N) { endY = getUpperBoundIndex(yCoords_, y2 = (yCoords_[gridY] + r + wext)); - else + } else { startY = getLowerBoundIndex(yCoords_, y1 = (yCoords_[gridY] - r - wext)); + } } getPrevGrid(gridX, gridY, gridZ, dir); } @@ -534,33 +541,39 @@ frCoord FlexGridGraph::getCostsNDR(frMIdx gridX, startX = endX = gridX; x1 = x2 = xCoords_[startX]; if (prevDir == frDirEnum::UNKNOWN || prevDir != dir) { - if (dir == frDirEnum::E) + if (dir == frDirEnum::E) { startX = getLowerBoundIndex(xCoords_, x1 = (xCoords_[gridX] - r - wext)); - else + } else { endX = getUpperBoundIndex(xCoords_, x2 = (xCoords_[gridX] + r + wext)); + } } if (prevDir != frDirEnum::UNKNOWN) { getNextGrid(gridX, gridY, gridZ, dir); if (isDst(gridX, gridY, gridZ)) { - if (dir == frDirEnum::E) + if (dir == frDirEnum::E) { endX = getUpperBoundIndex(xCoords_, x2 = (xCoords_[gridX] + r + wext)); - else + } else { startX = getLowerBoundIndex(xCoords_, x1 = (xCoords_[gridX] - r - wext)); + } } getPrevGrid(gridX, gridY, gridZ, dir); } } - if (xCoords_[startX] < x1) + if (xCoords_[startX] < x1) { startX++; - if (xCoords_[endX] > x2) + } + if (xCoords_[endX] > x2) { endX--; - if (yCoords_[startY] < y1) + } + if (yCoords_[startY] < y1) { startY++; - if (yCoords_[endY] > y2) + } + if (yCoords_[endY] > y2) { endY--; + } // get costs for (frMIdx x = startX; x <= endX; x++) { for (frMIdx y = startY; y <= endY; y++) { @@ -583,8 +596,9 @@ frCoord FlexGridGraph::getViaCostsNDR(frMIdx gridX, frDirEnum prevDir, frLayer* layer) const { - if (ndr_->getPrefVia(dir == frDirEnum::U ? gridZ : gridZ - 1) == nullptr) + if (ndr_->getPrefVia(dir == frDirEnum::U ? gridZ : gridZ - 1) == nullptr) { return getCosts(gridX, gridY, gridZ, dir, layer); + } frMIdx startX, startY, endX, endY; frCoord x1, x2, y1, y2; frCoord layerWidth = std::max((int) layer->getWidth(), ndr_->getWidth(gridZ)); @@ -613,14 +627,18 @@ frCoord FlexGridGraph::getViaCostsNDR(frMIdx gridX, : 0); dir = frDirEnum::UNKNOWN; - if (xCoords_[startX] < x1) + if (xCoords_[startX] < x1) { startX++; - if (xCoords_[endX] > x2) + } + if (xCoords_[endX] > x2) { endX--; - if (yCoords_[startY] < y1) + } + if (yCoords_[startY] < y1) { startY++; - if (yCoords_[endY] > y2) + } + if (yCoords_[endY] > y2) { endY--; + } switch (prevDir) { case frDirEnum::N: endY = gridY - 1; @@ -676,10 +694,13 @@ frCost FlexGridGraph::getCosts(frMIdx gridX, bool FlexGridGraph::useNDRCosts(const FlexWavefrontGrid& p) const { if (ndr_) { - if (p.getSrcTaperBox() && p.getSrcTaperBox()->contains(p.x(), p.y(), p.z())) + if (p.getSrcTaperBox() + && p.getSrcTaperBox()->contains(p.x(), p.y(), p.z())) { return false; - if (dstTaperBox && dstTaperBox->contains(p.x(), p.y(), p.z())) + } + if (dstTaperBox && dstTaperBox->contains(p.x(), p.y(), p.z())) { return false; + } return true; } return false; @@ -695,8 +716,9 @@ frMIdx FlexGridGraph::getUpperBoundIndex(const frVector& tracks, frCoord v) const { auto it = std::upper_bound(tracks.begin(), tracks.end(), v); - if (it == tracks.end()) + if (it == tracks.end()) { it = std::prev(it); + } return it - tracks.begin(); } @@ -743,12 +765,14 @@ bool FlexGridGraph::isExpandable(const FlexWavefrontGrid& currGrid, // the die box, forbid expansion if (dir == frDirEnum::N || dir == frDirEnum::S) { if (xCoords_[currGrid.x()] - halfWidth < dieBox_.xMin() - || xCoords_[currGrid.x()] + halfWidth > dieBox_.xMax()) + || xCoords_[currGrid.x()] + halfWidth > dieBox_.xMax()) { return false; + } } else if (dir == frDirEnum::E || dir == frDirEnum::W) { if (yCoords_[currGrid.y()] - halfWidth < dieBox_.yMin() - || yCoords_[currGrid.y()] + halfWidth > dieBox_.yMax()) + || yCoords_[currGrid.y()] + halfWidth > dieBox_.yMax()) { return false; + } } } } @@ -778,10 +802,10 @@ void FlexGridGraph::traceBackPath(const FlexWavefrontGrid& currGrid, std::cout << "Warning: unexpected direction in tracBackPath\n"; break; } - root.push_back(FlexMazeIdx(currX, currY, currZ)); + root.emplace_back(currX, currY, currZ); // push point to path if (currDir != prevDir) { - path.push_back(FlexMazeIdx(currX, currY, currZ)); + path.emplace_back(currX, currY, currZ); } getPrevGrid(currX, currY, currZ, currDir); prevDir = currDir; @@ -790,13 +814,13 @@ void FlexGridGraph::traceBackPath(const FlexWavefrontGrid& currGrid, while (isSrc(currX, currY, currZ) == false) { // get last direction currDir = getPrevAstarNodeDir({currX, currY, currZ}); - root.push_back(FlexMazeIdx(currX, currY, currZ)); + root.emplace_back(currX, currY, currZ); if (currDir == frDirEnum::UNKNOWN) { std::cout << "Warning: unexpected direction in tracBackPath\n"; break; } if (currDir != prevDir) { - path.push_back(FlexMazeIdx(currX, currY, currZ)); + path.emplace_back(currX, currY, currZ); } getPrevGrid(currX, currY, currZ, currDir); prevDir = currDir; @@ -804,7 +828,7 @@ void FlexGridGraph::traceBackPath(const FlexWavefrontGrid& currGrid, // add final path to src, only add when path exists; no path exists (src = // dst) if (!path.empty()) { - path.push_back(FlexMazeIdx(currX, currY, currZ)); + path.emplace_back(currX, currY, currZ); } for (auto& mi : path) { ccMazeIdx1.set(std::min(ccMazeIdx1.x(), mi.x()), @@ -827,10 +851,11 @@ bool FlexGridGraph::search(std::vector& connComps, if (drWorker_->getDRIter() >= debugMazeIter) { std::cout << "INIT search: target pin " << nextPin->getName() << "\nsource points:\n"; - for (auto& idx : connComps) + for (auto& idx : connComps) { std::cout << idx.x() << " " << idx.y() << " " << idx.z() << " coords: " << xCoords_[idx.x()] << " " << yCoords_[idx.y()] << "\n"; + } } // prep nextPinBox frMIdx xDim, yDim, zDim; @@ -852,7 +877,7 @@ bool FlexGridGraph::search(std::vector& connComps, Point currPt; for (auto& idx : connComps) { if (isDst(idx.x(), idx.y(), idx.z())) { - path.push_back(FlexMazeIdx(idx.x(), idx.y(), idx.z())); + path.emplace_back(idx.x(), idx.y(), idx.z()); return true; } getPoint(currPt, idx.x(), idx.y()); @@ -870,8 +895,9 @@ bool FlexGridGraph::search(std::vector& connComps, getEstCost(idx, dstMazeIdx1, dstMazeIdx2, frDirEnum::UNKNOWN)); if (ndr_ && AUTO_TAPER_NDR_NETS) { auto it = mazeIdx2TaperBox.find(idx); - if (it != mazeIdx2TaperBox.end()) + if (it != mazeIdx2TaperBox.end()) { currGrid.setSrcTaperBox(it->second); + } } wavefront_.push(currGrid); } @@ -885,18 +911,20 @@ bool FlexGridGraph::search(std::vector& connComps, if (graphics_) { graphics_->searchNode(this, currGrid); } - if (drWorker_->getDRIter() >= debugMazeIter) + if (drWorker_->getDRIter() >= debugMazeIter) { std::cout << "Expanding " << currGrid.x() << " " << currGrid.y() << " " << currGrid.z() << " coords: " << xCoords_[currGrid.x()] << " " << yCoords_[currGrid.y()] << " cost " << currGrid.getCost() << " g " << currGrid.getPathCost() << "\n"; + } if (isDst(currGrid.x(), currGrid.y(), currGrid.z())) { traceBackPath(currGrid, path, connComps, ccMazeIdx1, ccMazeIdx2); return true; - } else { - // expand and update wavefront - expandWavefront(currGrid, dstMazeIdx1, dstMazeIdx2, centerPt); } + // expand and update wavefront + expandWavefront(currGrid, dstMazeIdx1, dstMazeIdx2, centerPt); } return false; } + +} // namespace fr diff --git a/src/drt/src/dr/FlexMazeTypes.h b/src/drt/src/dr/FlexMazeTypes.h index bfd4110868c..42cb8638e68 100644 --- a/src/drt/src/dr/FlexMazeTypes.h +++ b/src/drt/src/dr/FlexMazeTypes.h @@ -34,7 +34,7 @@ namespace fr { class FlexMazeIdx { public: - FlexMazeIdx() : xIdx_(-1), yIdx_(-1), zIdx_(-1) {} + FlexMazeIdx() = default; FlexMazeIdx(frMIdx xIn, frMIdx yIn, frMIdx zIn) : xIdx_(xIn), yIdx_(yIn), zIdx_(zIn) { @@ -65,11 +65,11 @@ class FlexMazeIdx { if (xIdx_ != rhs.x()) { return xIdx_ < rhs.x(); - } else if (yIdx_ != rhs.y()) { + } + if (yIdx_ != rhs.y()) { return yIdx_ < rhs.y(); - } else { - return zIdx_ < rhs.z(); } + return zIdx_ < rhs.z(); } bool operator==(const FlexMazeIdx& rhs) const { @@ -83,9 +83,9 @@ class FlexMazeIdx } private: - frMIdx xIdx_; - frMIdx yIdx_; - frMIdx zIdx_; + frMIdx xIdx_ = -1; + frMIdx yIdx_ = -1; + frMIdx zIdx_ = -1; template void serialize(Archive& ar, const unsigned int version)