Skip to content

Commit 4247e7f

Browse files
authored
Merge pull request #825 from os-fpga/checker_fixed_bugs_in_PinGraph_construction
checker: fixed bugs in PinGraph construction
2 parents 51cbcec + d88f497 commit 4247e7f

File tree

5 files changed

+180
-132
lines changed

5 files changed

+180
-132
lines changed

planning/src/file_io/pln_blif_file.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,8 +1654,9 @@ bool BLIF_file::createPinGraph() noexcept {
16541654
assert(!port.out_.empty());
16551655
nid = pg_.insK(port.id_);
16561656
assert(nid);
1657-
pg_.setNodeName(nid, port.out_);
16581657
pg_.nodeRef(nid).markInp(true);
1658+
assert(not pg_.nodeRef(nid).isNamed());
1659+
pg_.setNodeName(nid, port.out_);
16591660
port.nw_id_ = nid;
16601661
pg2blif_.emplace(nid, port.id_);
16611662
}
@@ -1666,8 +1667,9 @@ bool BLIF_file::createPinGraph() noexcept {
16661667
assert(!port.out_.empty());
16671668
nid = pg_.insK(port.id_);
16681669
assert(nid);
1669-
pg_.setNodeName(nid, port.out_);
16701670
pg_.nodeRef(nid).markOut(true);
1671+
assert(not pg_.nodeRef(nid).isNamed());
1672+
pg_.setNodeName(nid, port.out_);
16711673
port.nw_id_ = nid;
16721674
pg2blif_.emplace(nid, port.id_);
16731675
}
@@ -1727,6 +1729,8 @@ bool BLIF_file::createPinGraph() noexcept {
17271729
::snprintf(nm_buf, 510, "%s_%uL_%up%u",
17281730
par.hasPrimType() ? par.cPrimType() : "NP",
17291731
par.lnum_, par.id_, pinIndex);
1732+
1733+
assert(not pg_.nodeRef(kid).inp_flag_);
17301734
pg_.setNodeName(kid, nm_buf);
17311735
pg_.nodeRef(kid).markClk(is_clock);
17321736

@@ -1749,15 +1753,20 @@ bool BLIF_file::createPinGraph() noexcept {
17491753
if (not Q.empty()) {
17501754
for (uint i = 0; i < Q.size(); i++) {
17511755
const qTup& q = Q[i];
1752-
uint64_t qk = hashComb(q.cellId_, q.outNet_);
1756+
BNode& bnode = bnodeRef(q.cellId_);
1757+
assert(not bnode.isTopPort());
1758+
1759+
uint64_t qk = bnode.cellHash0(); // hashComb(q.cellId_, q.outNet_);
17531760
assert(qk);
17541761
kid = pg_.insK(qk);
17551762
eid = pg_.linkNodes(q.inpNid_, kid, true);
17561763

17571764
::snprintf(nm_buf, 510, "nd%u_L%u_Q%u",
1758-
kid, bnodeRef(q.cellId_).lnum_, q.cellId_);
1765+
kid, bnode.lnum_, q.cellId_);
1766+
assert(not pg_.nodeRef(kid).inp_flag_);
17591767
pg_.setNodeName(kid, nm_buf);
1760-
pg2blif_.emplace(kid, q.cellId_);
1768+
bnode.nw_id_ = kid;
1769+
pg2blif_.emplace(kid, bnode.id_);
17611770
}
17621771
}
17631772

@@ -1789,6 +1798,7 @@ bool BLIF_file::createPinGraph() noexcept {
17891798

17901799
::snprintf(nm_buf, 510, "nd%u_L%u_cn",
17911800
kid, cn.lnum_);
1801+
assert(not pg_.nodeRef(kid).inp_flag_);
17921802
pg_.setNodeName(kid, nm_buf);
17931803
pg2blif_.emplace(kid, cn.id_);
17941804

@@ -1819,7 +1829,7 @@ bool BLIF_file::createPinGraph() noexcept {
18191829
return false;
18201830
}
18211831

1822-
uint64_t opin_key = hashComb(driver->id_, driver->out_);
1832+
uint64_t opin_key = driver->cellHash0(); // hashComb(driver->id_, driver->out_);
18231833
assert(opin_key);
18241834
uint opin_nid = pg_.findNode(opin_key);
18251835
if (opin_nid) {
@@ -1837,6 +1847,7 @@ bool BLIF_file::createPinGraph() noexcept {
18371847
assert(not outPin.empty());
18381848
::strcat(nm_buf, outPin.c_str());
18391849
}
1850+
assert(not pg_.nodeRef(opin_nid).inp_flag_);
18401851
pg_.setNodeName(opin_nid, nm_buf);
18411852
pg2blif_.emplace(opin_nid, driver->id_);
18421853
}
@@ -1881,6 +1892,7 @@ bool BLIF_file::createPinGraph() noexcept {
18811892
assert(not inpPin.empty());
18821893
::strcat(nm_buf, inpPin.c_str());
18831894
}
1895+
assert(not pg_.nodeRef(ipin_nid).inp_flag_);
18841896
pg_.setNodeName(ipin_nid, nm_buf);
18851897
pg2blif_.emplace(ipin_nid, dn.id_);
18861898
}
@@ -1939,7 +1951,7 @@ bool BLIF_file::createPinGraph() noexcept {
19391951
}
19401952
else {
19411953

1942-
drv_drv_outKey = hashComb(drv_drv->cell_hc_, drv_drv->out_);
1954+
drv_drv_outKey = drv_drv->cellHash0(); // hashComb(drv_drv->cell_hc_, drv_drv->out_);
19431955
assert(drv_drv_outKey);
19441956
drv_drv_outNid = pg_.insK(drv_drv_outKey);
19451957
assert(drv_drv_outNid);
@@ -1955,6 +1967,7 @@ bool BLIF_file::createPinGraph() noexcept {
19551967
assert(not outPin.empty());
19561968
::strcat(nm_buf, outPin.c_str());
19571969
}
1970+
assert(not pg_.nodeRef(drv_drv_outNid).inp_flag_);
19581971
pg_.setNodeName(drv_drv_outNid, nm_buf);
19591972
}
19601973

planning/src/file_io/pln_blif_file.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,36 @@ struct BLIF_file : public fio::MMapReader
6363
}
6464

6565
void setOutHash() noexcept {
66-
out_hc_ = str::hashf(out_.c_str());
66+
assert(id_);
67+
out_hc_ = is_top_ ? id_ : str::hashf(out_.c_str());
6768
}
6869
uint64_t outHash() const noexcept {
70+
assert(id_);
71+
if (is_top_)
72+
return id_;
6973
return out_hc_ ? out_hc_ : str::hashf(out_.c_str());
7074
}
7175

7276
void setCellHash() noexcept {
73-
cell_hc_ = hashComb(id_, is_top_, str::hashf(out_.c_str()));
77+
assert(id_);
78+
if (is_top_) {
79+
cell_hc_ = id_;
80+
return;
81+
}
82+
cell_hc_ = hashComb(id_, out_);
7483
}
7584
uint64_t cellHash() const noexcept {
85+
assert(id_);
86+
if (is_top_)
87+
return id_;
7688
if (cell_hc_) return cell_hc_;
77-
return hashComb(id_, is_top_, str::hashf(out_.c_str()));
89+
return hashComb(id_, out_);
90+
}
91+
uint64_t cellHash0() const noexcept {
92+
assert(id_);
93+
if (is_top_)
94+
return id_;
95+
return hashComb(id_, out_);
7896
}
7997

8098
bool isTopPort() const noexcept { return is_top_ != 0; }

planning/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static const char* _pln_VERSION_STR = "pln0328";
1+
static const char* _pln_VERSION_STR = "pln0329";
22

33
#include "RS/rsEnv.h"
44
#include "util/pln_log.h"

planning/src/util/nw/Nw.h

Lines changed: 12 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ struct NW {
140140
}
141141
bool edgeOutg(const Edge& e) const noexcept { return not edgeInco(e); }
142142

143-
inline void getFanout(const NW& g, vecu& A) const noexcept;
144-
inline void getFanin(const NW& g, vecu& A) const noexcept;
145-
inline void getAdj(const NW& g, vecu& A) const noexcept;
146-
inline void getFanoutE(const NW& g, vecu& E) const noexcept;
143+
void getFanout(const NW& g, vecu& A) const noexcept;
144+
void getFanin(const NW& g, vecu& A) const noexcept;
145+
void getAdj(const NW& g, vecu& A) const noexcept;
146+
void getFanoutE(const NW& g, vecu& E) const noexcept;
147147

148148
uint degree() const noexcept { return edges_.size(); }
149-
inline uint outDeg(const NW& g) const noexcept;
150-
inline uint inDeg(const NW& g) const noexcept;
149+
uint outDeg(const NW& g) const noexcept;
150+
uint inDeg(const NW& g) const noexcept;
151151

152152
uint parent() const noexcept { return par_; }
153153
bool isTreeRoot() const noexcept { return !par_; }
@@ -267,7 +267,7 @@ struct NW {
267267
}
268268
uint numN() const noexcept { return size(); }
269269
inline uint numE() const noexcept;
270-
inline uint countRedEdges() const noexcept;
270+
uint countRedEdges() const noexcept;
271271

272272
inline upair countRoots() const noexcept;
273273
bool hasClockNodes() const noexcept;
@@ -330,17 +330,8 @@ struct NW {
330330
nodeRef(id).markSink(val);
331331
}
332332

333-
void setNodeName(uint id, CStr nm) noexcept {
334-
assert(hasNode(id));
335-
if (nm)
336-
nodeRefCk(id).name_ = nm;
337-
else
338-
nodeRefCk(id).name_.clear();
339-
}
340-
void setNodeName(uint id, const string& nm) noexcept {
341-
assert(hasNode(id));
342-
nodeRefCk(id).name_ = nm;
343-
}
333+
void setNodeName(uint id, CStr nm) noexcept;
334+
void setNodeName(uint id, const string& nm) noexcept { setNodeName(id, nm.c_str()); }
344335

345336
void setNwName(CStr nm) noexcept {
346337
if (nm and nm[0])
@@ -362,11 +353,11 @@ struct NW {
362353
return edStor_[i];
363354
}
364355

365-
inline void getIncoE(const Node& nd, vecu& E) const noexcept;
366-
inline void getOutgE(const Node& nd, vecu& E) const noexcept;
356+
void getIncoE(const Node& nd, vecu& E) const noexcept;
357+
void getOutgE(const Node& nd, vecu& E) const noexcept;
367358

368359
inline void clear() noexcept;
369-
inline void clearEdges() noexcept;
360+
void clearEdges() noexcept;
370361

371362
const Node* parPtr(const Node& nd) const noexcept {
372363
return nd.par_ > 0 ? &nodeRefCk(nd.par_) : nullptr;
@@ -749,112 +740,12 @@ inline uint NW::addNode(const XY& p, uint64_t k) noexcept {
749740
return id;
750741
}
751742

752-
inline uint NW::Node::outDeg(const NW& g) const noexcept {
753-
if (edges_.empty()) return 0;
754-
755-
uint deg = 0;
756-
for (uint eid : edges_) {
757-
const Edge& ed = g.edgeRef(eid);
758-
assert(ed.valid());
759-
if (ed.n1_ == id_) deg++;
760-
}
761-
762-
return deg;
763-
}
764-
765-
inline uint NW::Node::inDeg(const NW& g) const noexcept {
766-
if (edges_.empty()) return 0;
767-
768-
uint deg = 0;
769-
for (uint eid : edges_) {
770-
const Edge& ed = g.edgeRef(eid);
771-
assert(ed.valid());
772-
if (ed.n2_ == id_) deg++;
773-
}
774-
775-
return deg;
776-
}
777-
778-
inline void NW::Node::getFanoutE(const NW& g, vecu& E) const noexcept {
779-
for (OutgEI I(g, id_); I.valid(); ++I) {
780-
const Edge& e = *I;
781-
assert(e.n1_ == id_);
782-
E.push_back(e.id_);
783-
}
784-
}
785-
786-
inline void NW::Node::getFanout(const NW& g, vecu& A) const noexcept {
787-
for (OutgEI I(g, id_); I.valid(); ++I) {
788-
const Edge& e = *I;
789-
assert(e.n1_ == id_);
790-
uint v = otherSide(e);
791-
assert(g.hasNode(v));
792-
A.push_back(v);
793-
}
794-
}
795-
796-
inline void NW::Node::getFanin(const NW& g, vecu& A) const noexcept {
797-
for (IncoEI I(g, id_); I.valid(); ++I) {
798-
const Edge& e = *I;
799-
assert(e.n2_ == id_);
800-
uint v = otherSide(e);
801-
assert(g.hasNode(v));
802-
A.push_back(v);
803-
}
804-
}
805-
806-
inline void NW::Node::getAdj(const NW& g, vecu& A) const noexcept {
807-
A.reserve(edges_.size());
808-
getFanin(g, A);
809-
getFanout(g, A);
810-
}
811-
812-
inline void NW::getIncoE(const Node& nd, vecu& E) const noexcept {
813-
E.clear();
814-
if (empty()) return;
815-
for (int i = nd.degree() - 1; i >= 0; i--) {
816-
uint ei = nd.edges_[i];
817-
const Edge& e = edgeRef(ei);
818-
if (not nd.edgeInco(e)) continue;
819-
E.push_back(ei);
820-
}
821-
}
822-
823-
inline void NW::getOutgE(const Node& nd, vecu& E) const noexcept {
824-
E.clear();
825-
if (empty()) return;
826-
for (int i = nd.degree() - 1; i >= 0; i--) {
827-
uint ei = nd.edges_[i];
828-
const Edge& e = edgeRef(ei);
829-
if (nd.edgeInco(e)) continue;
830-
E.push_back(ei);
831-
}
832-
}
833-
834743
inline uint NW::numE() const noexcept {
835744
uint cnt = 0;
836745
for (cEI I(*this); I.valid(); ++I) cnt++;
837746
return cnt;
838747
}
839748

840-
inline uint NW::countRedEdges() const noexcept {
841-
uint cnt = 0;
842-
for (cEI I(*this); I.valid(); ++I) {
843-
if (I->isRed())
844-
cnt++;
845-
}
846-
return cnt;
847-
}
848-
849-
inline void NW::clearEdges() noexcept {
850-
edStor_.clear();
851-
edStor_.emplace_back();
852-
if (empty()) return;
853-
for (NI I(*this); I.valid(); ++I) {
854-
I->edges_.clear();
855-
}
856-
}
857-
858749
inline uint NW::findEdge(uint a, uint b) const noexcept {
859750
if (!hasNode(a) or !hasNode(b)) return 0;
860751
assert(a != b);

0 commit comments

Comments
 (0)