Skip to content

Commit

Permalink
Use boost::flat_map instead of std::map
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Bieganski <kbieganski@antmicro.com>
  • Loading branch information
kbieganski committed Oct 28, 2024
1 parent 4ee14b4 commit 2f9926c
Show file tree
Hide file tree
Showing 53 changed files with 1,471 additions and 1,030 deletions.
22 changes: 12 additions & 10 deletions src/drt/src/TritonRoute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ std::string TritonRoute::runDRWorker(const std::string& workerStr,
{
bool on = debug_->debugDR;
std::unique_ptr<FlexDRGraphics> graphics_
= on && FlexDRGraphics::guiActive() ? std::make_unique<FlexDRGraphics>(
debug_.get(), design_.get(), db_, logger_)
: nullptr;
= on && FlexDRGraphics::guiActive()
? std::make_unique<FlexDRGraphics>(
debug_.get(), design_.get(), db_, logger_)
: nullptr;
auto worker
= FlexDRWorker::load(workerStr, logger_, design_.get(), graphics_.get());
worker->setViaData(viaData);
Expand Down Expand Up @@ -243,9 +244,10 @@ void TritonRoute::debugSingleWorker(const std::string& dumpDir,
ar >> viaData;

std::unique_ptr<FlexDRGraphics> graphics_
= on && FlexDRGraphics::guiActive() ? std::make_unique<FlexDRGraphics>(
debug_.get(), design_.get(), db_, logger_)
: nullptr;
= on && FlexDRGraphics::guiActive()
? std::make_unique<FlexDRGraphics>(
debug_.get(), design_.get(), db_, logger_)
: nullptr;
std::ifstream workerFile(fmt::format("{}/worker.bin", dumpDir),
std::ios::binary);
std::string workerStr((std::istreambuf_iterator<char>(workerFile)),
Expand Down Expand Up @@ -744,7 +746,7 @@ void TritonRoute::repairPDNVias()
}

const RTree<odb::dbId<odb::dbSBox>> pdnBlockViaTree(block_vias);
std::set<odb::dbId<odb::dbSBox>> removedBoxes;
boost::container::flat_set<odb::dbId<odb::dbSBox>> removedBoxes;
for (const auto& marker : markers) {
odb::Rect queryBox;
marker->getBBox().bloat(1, queryBox);
Expand Down Expand Up @@ -1088,7 +1090,7 @@ void TritonRoute::getDRCMarkers(frList<std::unique_ptr<frMarker>>& markers,
workersBatches.back().push_back(std::move(gcWorker));
}
}
std::map<MarkerId, frMarker*> mapMarkers;
boost::container::flat_map<MarkerId, frMarker*> mapMarkers;
omp_set_num_threads(MAX_THREADS);
for (auto& workers : workersBatches) {
#pragma omp parallel for schedule(dynamic)
Expand Down Expand Up @@ -1180,7 +1182,7 @@ void TritonRoute::stackVias(odb::dbBTerm* bterm,

odb::dbTech* tech = db_->getTech();
auto fr_tech = getDesign()->getTech();
std::map<int, odb::dbTechVia*> default_vias;
boost::container::flat_map<int, odb::dbTechVia*> default_vias;

for (auto layer : tech->getLayers()) {
if (layer->getType() == odb::dbTechLayerType::CUT) {
Expand Down Expand Up @@ -1271,7 +1273,7 @@ bool TritonRoute::netHasStackedVias(odb::dbNet* net)
odb::dbWire* wire = net->getWire();

odb::dbWirePathItr pitr;
std::set<odb::Point> via_points;
boost::container::flat_set<odb::Point> via_points;
for (pitr.begin(wire); pitr.getNextPath(path);) {
while (pitr.getNextShape(pshape)) {
via_points.insert(path.point);
Expand Down
10 changes: 8 additions & 2 deletions src/drt/src/db/drObj/drMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

#pragma once

#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>

#include "db/drObj/drBlockObject.h"

namespace drt {
Expand Down Expand Up @@ -66,7 +69,10 @@ class drMazeMarker : public drBlockObject
// getters
frConstraint* getConstraint() const { return constraint_; }
drNet* getTrigNet() const { return trigNets_.cbegin()->first; }
const std::map<drNet*, int>& getTrigNets() const { return trigNets_; }
const boost::container::flat_map<drNet*, int>& getTrigNets() const
{
return trigNets_;
}
int getCnt() const { return cnt_; }
// others
frBlockObjectEnum typeId() const override { return drcMazeMarker; }
Expand All @@ -77,7 +83,7 @@ class drMazeMarker : public drBlockObject

private:
frConstraint* constraint_{nullptr};
std::map<drNet*, int> trigNets_;
boost::container::flat_map<drNet*, int> trigNets_;
int cnt_{0};

template <class Archive>
Expand Down
28 changes: 18 additions & 10 deletions src/drt/src/db/grObj/grNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#pragma once

#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <memory>

#include "db/grObj/grBlockObject.h"
Expand Down Expand Up @@ -73,12 +75,13 @@ class grNet : public grBlockObject
{
return pinGCellNodePairs;
}
const std::map<grNode*, std::vector<grNode*>, frBlockObjectComp>&
getGCell2PinNodes() const
const boost::container::
flat_map<grNode*, std::vector<grNode*>, frBlockObjectComp>&
getGCell2PinNodes() const
{
return gcell2PinNodes;
}
std::map<grNode*, std::vector<grNode*>, frBlockObjectComp>&
boost::container::flat_map<grNode*, std::vector<grNode*>, frBlockObjectComp>&
getGCell2PinNodes()
{
return gcell2PinNodes;
Expand All @@ -93,11 +96,13 @@ class grNet : public grBlockObject
{
return pinNodePairs;
}
const std::map<grNode*, frNode*, frBlockObjectComp>& getGR2FrPinNode() const
const boost::container::flat_map<grNode*, frNode*, frBlockObjectComp>&
getGR2FrPinNode() const
{
return gr2FrPinNode;
}
std::map<grNode*, frNode*, frBlockObjectComp>& getGR2FrPinNode()
boost::container::flat_map<grNode*, frNode*, frBlockObjectComp>&
getGR2FrPinNode()
{
return gr2FrPinNode;
}
Expand Down Expand Up @@ -146,7 +151,8 @@ class grNet : public grBlockObject
pinGCellNodePairs = in;
}
void setGCell2PinNodes(
const std::map<grNode*, std::vector<grNode*>, frBlockObjectComp>& in)
const boost::container::
flat_map<grNode*, std::vector<grNode*>, frBlockObjectComp>& in)
{
gcell2PinNodes = in;
}
Expand All @@ -155,7 +161,8 @@ class grNet : public grBlockObject
{
pinNodePairs = in;
}
void setGR2FrPinNode(const std::map<grNode*, frNode*, frBlockObjectComp>& in)
void setGR2FrPinNode(
const boost::container::flat_map<grNode*, frNode*, frBlockObjectComp>& in)
{
gr2FrPinNode = in;
}
Expand Down Expand Up @@ -214,12 +221,13 @@ class grNet : public grBlockObject

// pair of <pinNode, gcellNode> with first (0th) element always being root
std::vector<std::pair<grNode*, grNode*>> pinGCellNodePairs;
std::map<grNode*, std::vector<grNode*>, frBlockObjectComp> gcell2PinNodes;
boost::container::flat_map<grNode*, std::vector<grNode*>, frBlockObjectComp>
gcell2PinNodes;
// unique, first (0th) element always being root
std::vector<grNode*> pinGCellNodes;
std::vector<std::pair<frNode*, grNode*>> pinNodePairs;
std::map<grNode*, frNode*, frBlockObjectComp> gr2FrPinNode;
// std::set<frBlockObject*> fNetTerms;
boost::container::flat_map<grNode*, frNode*, frBlockObjectComp> gr2FrPinNode;
// boost::container::flat_set<frBlockObject*> fNetTerms;
std::list<std::unique_ptr<grNode>> nodes;
grNode* root{nullptr};
frNet* fNet{nullptr};
Expand Down
10 changes: 6 additions & 4 deletions src/drt/src/db/obj/frBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#pragma once

#include <algorithm>
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <type_traits>

#include "db/obj/frBTerm.h"
Expand Down Expand Up @@ -409,16 +411,16 @@ class frBlock : public frBlockObject
frString name_;
frUInt4 dbUnit_{0};

std::map<std::string, frInst*> name2inst_;
boost::container::flat_map<std::string, frInst*> name2inst_;
std::vector<std::unique_ptr<frInst>> insts_;

std::map<std::string, frBTerm*> name2term_;
boost::container::flat_map<std::string, frBTerm*> name2term_;
std::vector<std::unique_ptr<frBTerm>> terms_;

std::map<std::string, frNet*> name2net_;
boost::container::flat_map<std::string, frNet*> name2net_;
std::vector<std::unique_ptr<frNet>> nets_;

std::map<std::string, frNet*> name2snet_;
boost::container::flat_map<std::string, frNet*> name2snet_;
std::vector<std::unique_ptr<frNet>> snets_;

std::vector<std::unique_ptr<frBlockage>> blockages_;
Expand Down
6 changes: 4 additions & 2 deletions src/drt/src/db/obj/frBlockObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ struct frBlockObjectComp
}
};

using frBlockObjectSet = std::set<frBlockObject*, frBlockObjectComp>;
using frBlockObjectSet
= boost::container::flat_set<frBlockObject*, frBlockObjectComp>;
template <typename T>
using frBlockObjectMap = std::map<frBlockObject*, T, frBlockObjectComp>;
using frBlockObjectMap
= boost::container::flat_map<frBlockObject*, T, frBlockObjectComp>;
} // namespace drt
14 changes: 11 additions & 3 deletions src/drt/src/db/obj/frMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#pragma once

#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <set>
#include <tuple>

Expand Down Expand Up @@ -82,9 +84,15 @@ class frMarker : public frFig
Rect getBBox() const override { return bbox_; }
frLayerNum getLayerNum() const { return layerNum_; }

const std::set<frBlockObject*>& getSrcs() const { return srcs_; }
const boost::container::flat_set<frBlockObject*>& getSrcs() const
{
return srcs_;
}

void setSrcs(const std::set<frBlockObject*>& srcs) { srcs_ = srcs; }
void setSrcs(const boost::container::flat_set<frBlockObject*>& srcs)
{
srcs_ = srcs;
}

std::vector<std::pair<frBlockObject*, std::tuple<frLayerNum, Rect, bool>>>&
getAggressors()
Expand Down Expand Up @@ -120,7 +128,7 @@ class frMarker : public frFig
frConstraint* constraint_{nullptr};
Rect bbox_;
frLayerNum layerNum_{0};
std::set<frBlockObject*> srcs_;
boost::container::flat_set<frBlockObject*> srcs_;
std::vector<std::pair<frBlockObject*, std::tuple<frLayerNum, Rect, bool>>>
victims_; // obj, isFixed
std::vector<std::pair<frBlockObject*, std::tuple<frLayerNum, Rect, bool>>>
Expand Down
13 changes: 9 additions & 4 deletions src/drt/src/db/tech/frConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#pragma once

#include <algorithm>
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <iterator>
#include <map>
#include <memory>
Expand Down Expand Up @@ -115,7 +117,8 @@ class frLef58CutClassConstraint : public frConstraint
}

private:
std::map<frString, std::shared_ptr<frLef58CutClass>> cutClasses_;
boost::container::flat_map<frString, std::shared_ptr<frLef58CutClass>>
cutClasses_;

friend class io::Parser;
};
Expand Down Expand Up @@ -1346,7 +1349,7 @@ class frLef58SpacingTableConstraint : public frSpacingTableConstraint
frLef58SpacingTableConstraint(
const std::shared_ptr<fr2DLookupTbl<frCoord, frCoord, frCoord>>&
parallelRunLengthConstraintIn,
const std::map<int, std::pair<frCoord, frCoord>>&
const boost::container::flat_map<int, std::pair<frCoord, frCoord>>&
exceptWithinConstraintIn)
: frSpacingTableConstraint(parallelRunLengthConstraintIn),
exceptWithinConstraint_(exceptWithinConstraintIn)
Expand All @@ -1370,7 +1373,8 @@ class frLef58SpacingTableConstraint : public frSpacingTableConstraint
frUInt4 getEolWidth() const { return eolWidth_; }
// setters
void setExceptWithinConstraint(
std::map<int, std::pair<frCoord, frCoord>>& exceptWithinConstraintIn)
boost::container::flat_map<int, std::pair<frCoord, frCoord>>&
exceptWithinConstraintIn)
{
exceptWithinConstraint_ = exceptWithinConstraintIn;
}
Expand Down Expand Up @@ -1402,7 +1406,8 @@ class frLef58SpacingTableConstraint : public frSpacingTableConstraint
}

protected:
std::map<frCoord, std::pair<frCoord, frCoord>> exceptWithinConstraint_;
boost::container::flat_map<frCoord, std::pair<frCoord, frCoord>>
exceptWithinConstraint_;
bool wrongDirection_{false};
bool sameMask_{false};
bool exceptEol_{false};
Expand Down
46 changes: 25 additions & 21 deletions src/drt/src/db/tech/frLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class frLayer
return secondaryViaDefs_.at(idx);
}
bool hasVia2ViaMinStepViol() { return hasMinStepViol_; }
std::set<frViaDef*> getViaDefs() const { return viaDefs_; }
boost::container::flat_set<frViaDef*> getViaDefs() const { return viaDefs_; }
dbTechLayerType getType() const
{
if (fakeCut_) {
Expand Down Expand Up @@ -413,7 +413,7 @@ class frLayer
}
return interLayerCutSpacingSamenetConstraints_;
}
const std::map<std::string, frCutSpacingConstraint*>&
const boost::container::flat_map<std::string, frCutSpacingConstraint*>&
getInterLayerCutSpacingConstraintMap(bool samenet = false) const
{
if (!samenet) {
Expand Down Expand Up @@ -746,17 +746,17 @@ class frLayer

void addLef58EnclosureConstraint(frLef58EnclosureConstraint* con)
{
auto addToLef58EncConstraints
= [](std::vector<
std::map<frCoord, std::vector<frLef58EnclosureConstraint*>>>&
lef58EncConstraints,
frLef58EnclosureConstraint* con) {
int cutClassIdx = con->getCutClassIdx();
if (lef58EncConstraints.size() <= cutClassIdx) {
lef58EncConstraints.resize(cutClassIdx + 1);
}
lef58EncConstraints[cutClassIdx][con->getWidth()].push_back(con);
};
auto addToLef58EncConstraints =
[](std::vector<boost::container::flat_map<
frCoord,
std::vector<frLef58EnclosureConstraint*>>>& lef58EncConstraints,
frLef58EnclosureConstraint* con) {
int cutClassIdx = con->getCutClassIdx();
if (lef58EncConstraints.size() <= cutClassIdx) {
lef58EncConstraints.resize(cutClassIdx + 1);
}
lef58EncConstraints[cutClassIdx][con->getWidth()].push_back(con);
};
if (!con->isAboveOnly()) {
addToLef58EncConstraints(con->isEol() ? belowLef58EncEolConstraints_
: belowLef58EncConstraints_,
Expand Down Expand Up @@ -833,9 +833,9 @@ class frLayer
std::vector<frViaDef*> secondaryViaDefs_;
bool hasMinStepViol_{false};
bool unidirectional_{false};
std::set<frViaDef*> viaDefs_;
boost::container::flat_set<frViaDef*> viaDefs_;
std::vector<frLef58CutClass*> cutClasses_;
std::map<std::string, int> name2CutClassIdxMap_;
boost::container::flat_map<std::string, int> name2CutClassIdxMap_;
frCollection<frConstraint*> constraints_;

frCollection<frLef58SpacingEndOfLineConstraint*>
Expand All @@ -856,9 +856,9 @@ class frLayer
// vector.size() == layers.size()
std::vector<frCutSpacingConstraint*> interLayerCutSpacingSamenetConstraints_;
// temp storage for inter-layer cut spacing before postProcess
std::map<std::string, frCutSpacingConstraint*>
boost::container::flat_map<std::string, frCutSpacingConstraint*>
interLayerCutSpacingConstraintsMap_;
std::map<std::string, frCutSpacingConstraint*>
boost::container::flat_map<std::string, frCutSpacingConstraint*>
interLayerCutSpacingSamenetConstraintsMap_;

std::vector<frLef58CutSpacingConstraint*> lef58CutSpacingConstraints_;
Expand Down Expand Up @@ -901,13 +901,17 @@ class frLayer
std::vector<frLef58TwoWiresForbiddenSpcConstraint*>
twForbiddenSpcConstraints_;
std::vector<frLef58ForbiddenSpcConstraint*> forbiddenSpcConstraints_;
std::vector<std::map<frCoord, std::vector<frLef58EnclosureConstraint*>>>
std::vector<boost::container::
flat_map<frCoord, std::vector<frLef58EnclosureConstraint*>>>
aboveLef58EncConstraints_;
std::vector<std::map<frCoord, std::vector<frLef58EnclosureConstraint*>>>
std::vector<boost::container::
flat_map<frCoord, std::vector<frLef58EnclosureConstraint*>>>
belowLef58EncConstraints_;
std::vector<std::map<frCoord, std::vector<frLef58EnclosureConstraint*>>>
std::vector<boost::container::
flat_map<frCoord, std::vector<frLef58EnclosureConstraint*>>>
aboveLef58EncEolConstraints_;
std::vector<std::map<frCoord, std::vector<frLef58EnclosureConstraint*>>>
std::vector<boost::container::
flat_map<frCoord, std::vector<frLef58EnclosureConstraint*>>>
belowLef58EncEolConstraints_;
// vector of maxspacing constraints
std::vector<frLef58MaxSpacingConstraint*> maxSpacingConstraints_;
Expand Down
Loading

0 comments on commit 2f9926c

Please sign in to comment.