Skip to content

Commit

Permalink
Merge pull request The-OpenROAD-Project#5791 from gadfort/tap-speedup
Browse files Browse the repository at this point in the history
tap: avoid iterating over insts multiple times when placing tapcells
  • Loading branch information
maliberty authored Sep 23, 2024
2 parents e21fbdf + 5eb52e8 commit 38cab49
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
17 changes: 16 additions & 1 deletion src/tap/include/tap/tapcell.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <boost/polygon/polygon.hpp>

#include "odb/db.h"
#include "odb/geom_boost.h"

namespace ord {
class OpenRoad;
Expand Down Expand Up @@ -163,6 +164,19 @@ class Tapcell
using Polygon90 = boost::polygon::polygon_90_with_holes_data<int>;
using CornerMap = std::map<odb::dbRow*, std::set<odb::dbInst*>>;

struct InstIndexableGetter
{
using result_type = odb::Rect;
odb::Rect operator()(odb::dbInst* inst) const
{
return inst->getBBox()->getBox();
}
};
using InstTree
= boost::geometry::index::rtree<odb::dbInst*,
boost::geometry::index::quadratic<16>,
InstIndexableGetter>;

std::vector<odb::dbBox*> findBlockages();
bool checkSymmetry(odb::dbMaster* master, const odb::dbOrientType& ori);
odb::dbInst* makeInstance(odb::dbBlock* block,
Expand Down Expand Up @@ -190,7 +204,8 @@ class Tapcell
int dist,
odb::dbRow* row,
bool is_edge,
bool disallow_one_site_gaps);
bool disallow_one_site_gaps,
const InstTree& fixed_instances);

int defaultDistance() const;

Expand Down
32 changes: 19 additions & 13 deletions src/tap/src/tapcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,23 @@ int Tapcell::placeTapcells(odb::dbMaster* tapcell_master,
edge_rows.insert(rows.begin(), rows.end());
}

std::vector<odb::dbInst*> fixed_insts;
for (auto* inst : db_->getChip()->getBlock()->getInsts()) {
if (inst->isFixed()) {
fixed_insts.push_back(inst);
}
}
InstTree instancetree(fixed_insts.begin(), fixed_insts.end());

int inst = 0;
for (auto* row : db_->getChip()->getBlock()->getRows()) {
const bool is_edge = edge_rows.find(row) != edge_rows.end();
inst += placeTapcells(
tapcell_master, dist, row, is_edge, disallow_one_site_gaps);
inst += placeTapcells(tapcell_master,
dist,
row,
is_edge,
disallow_one_site_gaps,
instancetree);
}
logger_->info(utl::TAP, 5, "Inserted {} tapcells.", inst);
return inst;
Expand All @@ -174,7 +186,8 @@ int Tapcell::placeTapcells(odb::dbMaster* tapcell_master,
const int dist,
odb::dbRow* row,
const bool is_edge,
const bool disallow_one_site_gaps)
const bool disallow_one_site_gaps,
const InstTree& fixed_instances)
{
if (row->getSite()->getName() != tapcell_master->getSite()->getName()) {
return 0;
Expand Down Expand Up @@ -202,16 +215,9 @@ int Tapcell::placeTapcells(odb::dbMaster* tapcell_master,

const odb::Rect row_bb = row->getBBox();

std::set<odb::dbInst*> row_insts;
for (auto* inst : db_->getChip()->getBlock()->getInsts()) {
if (!inst->isFixed()) {
continue;
}

if (row_bb.contains(inst->getBBox()->getBox())) {
row_insts.insert(inst);
}
}
std::set<odb::dbInst*> row_insts(
fixed_instances.qbegin(boost::geometry::index::covered_by(row_bb)),
fixed_instances.qend());

const int llx = row_bb.xMin();
const int urx = row_bb.xMax();
Expand Down

0 comments on commit 38cab49

Please sign in to comment.