Skip to content

Commit 3c23c30

Browse files
Merge pull request #8918 from The-OpenROAD-Project-staging/drt-incremental-pa
drt: incremental PA trial
2 parents 118204e + dd122d3 commit 3c23c30

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1692
-1526
lines changed

src/drt/include/drt/TritonRoute.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ class TritonRoute
182182
void prep();
183183
odb::dbDatabase* getDb() const { return db_; }
184184
void fixMaxSpacing(int num_threads);
185-
void deleteInstancePAData(frInst* inst);
185+
void deleteInstancePAData(frInst* inst, bool delete_inst = false);
186186
void addInstancePAData(frInst* inst);
187+
void updateDirtyPAData();
187188

188189
private:
189190
std::unique_ptr<frDesign> design_;

src/drt/src/DesignCallBack.cpp

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,31 @@
55

66
#include "drt/TritonRoute.h"
77
#include "frDesign.h"
8+
#include "io/io.h"
89
#include "odb/db.h"
910

1011
namespace drt {
1112

13+
void DesignCallBack::inDbInstCreate(odb::dbInst* db_inst)
14+
{
15+
auto design = router_->getDesign();
16+
if (design == nullptr || design->getTopBlock() == nullptr) {
17+
return;
18+
}
19+
io::Parser parser(router_->getDb(),
20+
design,
21+
router_->getLogger(),
22+
router_->getRouterConfiguration());
23+
24+
parser.setInst(db_inst);
25+
}
26+
27+
void DesignCallBack::inDbInstCreate(odb::dbInst* db_inst,
28+
odb::dbRegion* db_region)
29+
{
30+
inDbInstCreate(db_inst);
31+
}
32+
1233
void DesignCallBack::inDbPreMoveInst(odb::dbInst* db_inst)
1334
{
1435
auto design = router_->getDesign();
@@ -19,10 +40,10 @@ void DesignCallBack::inDbPreMoveInst(odb::dbInst* db_inst)
1940
if (inst == nullptr) {
2041
return;
2142
}
22-
router_->deleteInstancePAData(inst);
2343
if (design->getRegionQuery() != nullptr) {
2444
design->getRegionQuery()->removeBlockObj(inst);
2545
}
46+
router_->deleteInstancePAData(inst, false);
2647
}
2748

2849
void DesignCallBack::inDbPostMoveInst(odb::dbInst* db_inst)
@@ -55,11 +76,93 @@ void DesignCallBack::inDbInstDestroy(odb::dbInst* db_inst)
5576
if (inst == nullptr) {
5677
return;
5778
}
58-
router_->deleteInstancePAData(inst);
5979
if (design->getRegionQuery() != nullptr) {
6080
design->getRegionQuery()->removeBlockObj(inst);
6181
}
6282
design->getTopBlock()->removeInst(inst);
83+
router_->deleteInstancePAData(inst, true);
84+
}
85+
86+
void DesignCallBack::inDbInstSwapMasterBefore(odb::dbInst* db_inst,
87+
odb::dbMaster* db_master)
88+
{
89+
inDbInstDestroy(db_inst);
90+
}
91+
92+
void DesignCallBack::inDbInstSwapMasterAfter(odb::dbInst* db_inst)
93+
{
94+
inDbInstCreate(db_inst);
95+
inDbPostMoveInst(db_inst);
96+
for (auto inst_term : db_inst->getITerms()) {
97+
if (inst_term->getNet()) {
98+
inDbITermPostConnect(inst_term);
99+
}
100+
}
101+
}
102+
void DesignCallBack::inDbNetCreate(odb::dbNet* db_net)
103+
{
104+
auto design = router_->getDesign();
105+
if (design == nullptr || design->getTopBlock() == nullptr) {
106+
return;
107+
}
108+
io::Parser parser(router_->getDb(),
109+
design,
110+
router_->getLogger(),
111+
router_->getRouterConfiguration());
112+
parser.addNet(db_net);
113+
}
114+
115+
void DesignCallBack::inDbNetDestroy(odb::dbNet* db_net)
116+
{
117+
auto design = router_->getDesign();
118+
if (design == nullptr || design->getTopBlock() == nullptr) {
119+
return;
120+
}
121+
auto net = design->getTopBlock()->findNet(db_net->getName());
122+
if (net == nullptr) {
123+
return;
124+
}
125+
design->getTopBlock()->removeNet(net);
126+
}
127+
128+
void DesignCallBack::inDbITermPostDisconnect(odb::dbITerm* db_iterm,
129+
odb::dbNet* db_net)
130+
{
131+
auto design = router_->getDesign();
132+
if (design == nullptr || design->getTopBlock() == nullptr) {
133+
return;
134+
}
135+
auto inst = design->getTopBlock()->findInst(db_iterm->getInst());
136+
auto net = design->getTopBlock()->findNet(db_net->getName());
137+
if (inst == nullptr || net == nullptr) {
138+
return;
139+
}
140+
auto inst_term = inst->getInstTerm(db_iterm->getMTerm()->getIndex());
141+
if (inst_term == nullptr) {
142+
return;
143+
}
144+
net->removeInstTerm(inst_term);
145+
inst_term->addToNet(nullptr);
146+
}
147+
148+
void DesignCallBack::inDbITermPostConnect(odb::dbITerm* db_iterm)
149+
{
150+
auto design = router_->getDesign();
151+
if (design == nullptr || design->getTopBlock() == nullptr) {
152+
return;
153+
}
154+
auto inst = design->getTopBlock()->findInst(db_iterm->getInst());
155+
auto net = design->getTopBlock()->findNet(db_iterm->getNet()->getName());
156+
if (inst == nullptr || net == nullptr) {
157+
return;
158+
}
159+
auto inst_term = inst->getInstTerm(db_iterm->getMTerm()->getIndex());
160+
if (inst_term == nullptr) {
161+
return;
162+
}
163+
inst_term->addToNet(net);
164+
net->addInstTerm(inst_term);
165+
router_->addInstancePAData(inst);
63166
}
64167

65168
} // namespace drt

src/drt/src/DesignCallBack.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ class DesignCallBack : public odb::dbBlockCallBackObj
1111
{
1212
public:
1313
DesignCallBack(TritonRoute* router) : router_(router) {}
14+
void inDbInstCreate(odb::dbInst*) override;
15+
void inDbInstCreate(odb::dbInst*, odb::dbRegion*) override;
1416
void inDbPreMoveInst(odb::dbInst* inst) override;
1517
void inDbPostMoveInst(odb::dbInst* inst) override;
1618
void inDbInstDestroy(odb::dbInst* inst) override;
19+
void inDbInstSwapMasterBefore(odb::dbInst*, odb::dbMaster*) override;
20+
void inDbInstSwapMasterAfter(odb::dbInst*) override;
21+
void inDbNetCreate(odb::dbNet* net) override;
22+
void inDbNetDestroy(odb::dbNet* net) override;
23+
void inDbITermPostDisconnect(odb::dbITerm* iterm, odb::dbNet* net) override;
24+
void inDbITermPostConnect(odb::dbITerm* iterm) override;
1725

1826
private:
1927
TritonRoute* router_;

src/drt/src/PACallBack.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#pragma once
55

66
#include "drt/TritonRoute.h"
7+
#include "frDesign.h"
78
#include "utl/CallBack.h"
89
#include "utl/Logger.h"
9-
1010
namespace drt {
1111

1212
class frDesign;
@@ -21,7 +21,11 @@ class PACallBack : public utl::CallBack
2121

2222
void onPinAccessUpdateRequired() override
2323
{
24-
// TODO: Implement
24+
auto design = router_->getDesign();
25+
if (design == nullptr || design->getTopBlock() == nullptr) {
26+
return;
27+
}
28+
router_->updateDirtyPAData();
2529
}
2630

2731
private:

src/drt/src/TritonRoute.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,17 +1106,30 @@ void TritonRoute::pinAccess(const std::vector<odb::dbInst*>& target_insts)
11061106
writer.updateDb(db_, router_cfg_.get(), true);
11071107
}
11081108

1109-
void TritonRoute::deleteInstancePAData(frInst* inst)
1109+
void TritonRoute::deleteInstancePAData(frInst* inst, bool delete_inst)
11101110
{
11111111
if (pa_) {
1112-
pa_->deleteInst(inst);
1112+
pa_->removeFromInstsSet(inst);
1113+
if (delete_inst) {
1114+
pa_->deleteInst(inst);
1115+
}
11131116
}
11141117
}
11151118

11161119
void TritonRoute::addInstancePAData(frInst* inst)
11171120
{
11181121
if (pa_) {
1119-
pa_->addInst(inst);
1122+
pa_->addDirtyInst(inst);
1123+
}
1124+
}
1125+
1126+
void TritonRoute::updateDirtyPAData()
1127+
{
1128+
if (pa_) {
1129+
design_->getTopBlock()->removeDeletedObjects();
1130+
pa_->updateDirtyInsts();
1131+
io::Writer writer(getDesign(), logger_);
1132+
writer.updateDb(getDb(), getRouterConfiguration(), true);
11201133
}
11211134
}
11221135

src/drt/src/db/obj/frAccess.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include "db/obj/frShape.h"
1717
#include "frBaseTypes.h"
1818
#include "odb/geom.h"
19+
namespace odb {
20+
class dbAccessPoint;
21+
}
1922

2023
namespace drt {
2124
class frViaDef;
@@ -191,6 +194,8 @@ class frAccessPoint : public frBlockObject
191194

192195
void addPathSeg(const frPathSeg& ps) { pathSegs_.emplace_back(ps); }
193196
std::vector<frPathSeg>& getPathSegs() { return pathSegs_; }
197+
void setDbAccessPoint(odb::dbAccessPoint* in) { db_ap_ = in; }
198+
odb::dbAccessPoint* getDbAccessPoint() const { return db_ap_; }
194199

195200
private:
196201
odb::Point point_;
@@ -204,6 +209,7 @@ class frAccessPoint : public frBlockObject
204209
frPinAccess* aps_{nullptr};
205210
std::vector<frPathSeg> pathSegs_;
206211
bool allow_via_{false};
212+
odb::dbAccessPoint* db_ap_{nullptr};
207213
template <class Archive>
208214
void serialize(Archive& ar, unsigned int version);
209215
friend class boost::serialization::access;
@@ -240,6 +246,7 @@ class frPinAccess : public frBlockObject
240246
void setPin(frPin* in) { pin_ = in; }
241247
// others
242248
frBlockObjectEnum typeId() const override { return frcPinAccess; }
249+
void clearAccessPoints() { aps_.clear(); }
243250

244251
private:
245252
std::vector<std::unique_ptr<frAccessPoint>> aps_;

src/drt/src/db/obj/frBTerm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class frBTerm : public frTerm
2626
bool hasNet() const override { return (net_); }
2727
frNet* getNet() const override { return net_; }
2828
const std::vector<std::unique_ptr<frBPin>>& getPins() const { return pins_; }
29+
bool hasPinAccessUpdate() const { return has_pin_access_update_; }
30+
void setHasPinAccessUpdate(bool in) { has_pin_access_update_ = in; }
2931
// setters
3032
void addToNet(frNet* in) { net_ = in; }
3133
void addPin(std::unique_ptr<frBPin> in)
@@ -89,6 +91,7 @@ class frBTerm : public frTerm
8991
std::vector<std::unique_ptr<frBPin>> pins_; // set later
9092
frNet* net_{nullptr};
9193
bool isAboveTopLayer_{false};
94+
bool has_pin_access_update_{true};
9295
};
9396

9497
} // namespace drt

src/drt/src/db/obj/frBlock.h

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <algorithm>
77
#include <map>
88
#include <memory>
9+
#include <set>
910
#include <string>
1011
#include <type_traits>
1112
#include <utility>
@@ -270,6 +271,39 @@ class frBlock : public frBlockObject
270271
}
271272
return odb::Point(idxX, idxY);
272273
}
274+
275+
std::vector<odb::Point> getGCellIndices(const odb::Point& pt) const
276+
{
277+
const auto& gp = getGCellPatterns();
278+
const auto& xgp = gp[0];
279+
const auto& ygp = gp[1];
280+
frCoord coord_x = pt.x() - xgp.getStartCoord();
281+
frCoord coord_y = pt.y() - ygp.getStartCoord();
282+
const frCoord max_coord_x = xgp.getSpacing() * (frCoord) xgp.getCount();
283+
const frCoord max_coord_y = ygp.getSpacing() * (frCoord) ygp.getCount();
284+
coord_x = std::clamp(coord_x, 0, max_coord_x - 1);
285+
coord_y = std::clamp(coord_y, 0, max_coord_y - 1);
286+
287+
const frCoord base_idxX = coord_x / (frCoord) xgp.getSpacing();
288+
const frCoord base_idxY = coord_y / (frCoord) ygp.getSpacing();
289+
std::set<frCoord> x_indices{base_idxX};
290+
std::set<frCoord> y_indices{base_idxY};
291+
// TODO: handle case where gcell size is 1 unit
292+
if (coord_x % xgp.getSpacing() == 0 && base_idxX != 0) {
293+
x_indices.insert(base_idxX - 1);
294+
}
295+
if (coord_y % ygp.getSpacing() == 0 && base_idxY != 0) {
296+
y_indices.insert(base_idxY - 1);
297+
}
298+
std::vector<odb::Point> sol;
299+
for (auto& x : x_indices) {
300+
for (auto& y : y_indices) {
301+
sol.emplace_back(x, y);
302+
}
303+
}
304+
return sol;
305+
}
306+
273307
bool isValidGCellIdx(const odb::Point& pt) const
274308
{
275309
const auto& gp = getGCellPatterns();
@@ -319,18 +353,41 @@ class frBlock : public frBlockObject
319353
name2inst_.erase(inst->getName());
320354
inst->setToBeDeleted(true);
321355
}
322-
void removeDeletedInsts()
356+
357+
void removeNet(frNet* net)
358+
{
359+
name2net_.erase(net->getName());
360+
for (auto term : net->getInstTerms()) {
361+
term->addToNet(nullptr);
362+
}
363+
for (auto term : net->getBTerms()) {
364+
term->addToNet(nullptr);
365+
}
366+
net->setToBeDeleted(true);
367+
}
368+
369+
void removeDeletedObjects()
323370
{
324371
insts_.erase(std::remove_if(insts_.begin(),
325372
insts_.end(),
326373
[](const std::unique_ptr<frInst>& inst) {
327374
return inst->isToBeDeleted();
328375
}),
329376
insts_.end());
377+
nets_.erase(std::remove_if(nets_.begin(),
378+
nets_.end(),
379+
[](const std::unique_ptr<frNet>& net) {
380+
return net->toBeDeleted();
381+
}),
382+
nets_.end());
330383
int id = 0;
331384
for (const auto& inst : insts_) {
332385
inst->setId(id++);
333386
}
387+
id = 0;
388+
for (const auto& net : nets_) {
389+
net->setId(id++);
390+
}
334391
}
335392
void addNet(std::unique_ptr<frNet> in)
336393
{

src/drt/src/db/obj/frInst.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ class frInst : public frRef
129129
odb::Rect getBoundaryBBox() const;
130130

131131
frInstTerm* getInstTerm(int index);
132+
bool hasPinAccessUpdate() const { return has_pin_access_update_; }
133+
void setHasPinAccessUpdate(bool in) { has_pin_access_update_ = in; }
134+
odb::dbTransform getLatestPATransform() const { return latest_pa_xform_; }
135+
void setLatestPATransform() { latest_pa_xform_ = xform_; }
132136

133137
private:
134138
frString name_;
@@ -137,8 +141,10 @@ class frInst : public frRef
137141
std::vector<std::unique_ptr<frInstBlockage>> instBlockages_;
138142
odb::dbInst* db_inst_;
139143
odb::dbTransform xform_;
144+
odb::dbTransform latest_pa_xform_;
140145
int pinAccessIdx_{-1};
141146
bool toBeDeleted_{false};
147+
bool has_pin_access_update_{true};
142148
};
143149

144150
} // namespace drt

0 commit comments

Comments
 (0)