Skip to content

Commit a5bf37c

Browse files
committed
pln: fixed bugs in clock-data checker
1 parent 697e272 commit a5bf37c

File tree

5 files changed

+162
-16
lines changed

5 files changed

+162
-16
lines changed

planning/src/file_io/pln_blif_file.cpp

Lines changed: 105 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ bool BLIF_file::linkNodes() noexcept {
14761476
}
14771477

14781478
bool BLIF_file::checkClockSepar(vector<const Node*>& clocked) noexcept {
1479+
auto& ls = lout();
14791480
if (::getenv("pln_dont_check_clock_separation"))
14801481
return true;
14811482
if (clocked.empty())
@@ -1491,15 +1492,23 @@ bool BLIF_file::checkClockSepar(vector<const Node*>& clocked) noexcept {
14911492
if (pg_.size() < 3)
14921493
return true;
14931494

1495+
flush_out(true);
1496+
14941497
if (trace_ >= 3) {
1495-
lprintf(" number of clock nodes = %u\n",
1498+
lprintf(" (Pin Graph) number of clock nodes = %u\n",
14961499
pg_.countClockNodes());
14971500
}
14981501

14991502
if (not pg_.hasClockNodes()) {
15001503
return true;
15011504
}
15021505

1506+
if (trace_ >= 4) {
1507+
lputs(" (Pin Graph) *** summary before coloring ***");
1508+
pg_.printSum(ls, 0);
1509+
lputs();
1510+
}
1511+
15031512
// -- paint clock nodes and their incoming edges Red
15041513
for (NW::NI I(pg_); I.valid(); ++I) {
15051514
NW::Node& nd = *I;
@@ -1511,25 +1520,55 @@ bool BLIF_file::checkClockSepar(vector<const Node*>& clocked) noexcept {
15111520
}
15121521
}
15131522
}
1514-
// -- paint nodes contacted by red edges
1523+
1524+
if (trace_ >= 6) {
1525+
lputs(" (Pin Graph) *** summary after A ***");
1526+
pg_.printSum(ls, 0);
1527+
lputs();
1528+
}
1529+
1530+
// -- paint CLK_BUF and iport nodes contacted by red edges
15151531
for (NW::cEI E(pg_); E.valid(); ++E) {
15161532
const NW::Edge& ed = *E;
15171533
if (ed.isRed()) {
1518-
pg_.nodeRef(ed.n1_).paintRed();
1519-
pg_.nodeRef(ed.n2_).paintRed();
1534+
NW::Node& nd1 = pg_.nodeRef(ed.n1_);
1535+
NW::Node& nd2 = pg_.nodeRef(ed.n2_);
1536+
assert(pg2blif_.count(nd1.id_));
1537+
assert(pg2blif_.count(nd2.id_));
1538+
const Node& bnd1 = bnodeRef(map_pg2blif(nd1.id_));
1539+
const Node& bnd2 = bnodeRef(map_pg2blif(nd2.id_));
1540+
if (bnd1.is_CLK_BUF() or bnd1.isTopInput())
1541+
nd1.paintRed();
1542+
if (bnd2.is_CLK_BUF() or bnd2.isTopInput())
1543+
nd2.paintRed();
15201544
}
15211545
}
1546+
1547+
if (trace_ >= 6) {
1548+
lputs(" (Pin Graph) *** summary after B ***");
1549+
pg_.printSum(ls, 0);
1550+
lputs();
1551+
}
1552+
15221553
// -- for red input ports, paint their outgoing edges Red
15231554
for (const Node* p : topInputs_) {
15241555
const Node& port = *p;
15251556
assert(port.nw_id_);
15261557
NW::Node& nw_node = pg_.nodeRefCk(port.nw_id_);
1527-
for (NW::OutgEI J(pg_, nw_node); J.valid(); ++J) {
1528-
uint eid = J->id_;
1529-
pg_.edgeRef(eid).paintRed();
1558+
if (nw_node.isRed()) {
1559+
for (NW::OutgEI J(pg_, nw_node); J.valid(); ++J) {
1560+
uint eid = J->id_;
1561+
pg_.edgeRef(eid).paintRed();
1562+
}
15301563
}
15311564
}
15321565

1566+
if (trace_ >= 4) {
1567+
lputs(" (Pin Graph) *** summary after coloring ***");
1568+
pg_.printSum(ls, 0);
1569+
lputs();
1570+
}
1571+
15331572
if (trace_ >= 4)
15341573
writePinGraph("pin_graph_2.dot");
15351574

@@ -1751,7 +1790,6 @@ bool BLIF_file::createPinGraph() noexcept {
17511790
::snprintf(nm_buf, 510, "nd%u_L%u_cn",
17521791
kid, cn.lnum_);
17531792
pg_.setNodeName(kid, nm_buf);
1754-
17551793
pg2blif_.emplace(kid, cn.id_);
17561794

17571795
const string& inet = cn.inSigs_[i];
@@ -1790,6 +1828,7 @@ bool BLIF_file::createPinGraph() noexcept {
17901828
if (driver->ptype_ == prim::CLK_BUF)
17911829
::strcat(nm_buf, "CBUF");
17921830
pg_.setNodeName(pid, nm_buf);
1831+
pg2blif_.emplace(pid, driver->id_);
17931832

17941833
eid = pg_.linK(qk, key);
17951834
assert(eid);
@@ -1811,11 +1850,12 @@ bool BLIF_file::createPinGraph() noexcept {
18111850
lprintf( "\t\t CLOCK_TRACE_inp1 %s\n",
18121851
inp1.c_str() );
18131852
}
1814-
1853+
18151854
const Node& dn = *driver;
1816-
Node* drv_drv = findFabricDriver(dn.id_, inp1); // driver-of-driver
1855+
Node* drv_drv = findDriverNode(dn.id_, inp1); // driver-of-driver
18171856

18181857
if (!drv_drv) {
1858+
lputs8();
18191859
flush_out(true); err_puts();
18201860
lprintf2("[Error] no driver for clock-buf node #%u %s line:%u\n",
18211861
dn.id_, dn.cPrimType(), dn.lnum_);
@@ -1838,6 +1878,47 @@ bool BLIF_file::createPinGraph() noexcept {
18381878
return false;
18391879
}
18401880

1881+
qk = 0;
1882+
1883+
assert(dn.cell_hc_);
1884+
key = hashComb(dn.cell_hc_, inp);
1885+
assert(key);
1886+
kid = pg_.insK(key);
1887+
assert(kid);
1888+
pg_.nodeRef(kid).markClk(true);
1889+
pg2blif_.emplace(kid, dn.id_);
1890+
1891+
if (drv_drv->isTopInput()) {
1892+
assert(drv_drv->nw_id_);
1893+
uint nw_id = drv_drv->nw_id_;
1894+
assert(pg_.hasNode(nw_id));
1895+
assert(pg2blif_.count(nw_id));
1896+
assert(map_pg2blif(nw_id) == drv_drv->id_);
1897+
qk = pg_.nodeRefCk(nw_id).key_;
1898+
assert(qk);
1899+
}
1900+
else {
1901+
1902+
qk = hashComb(drv_drv->id_, drv_drv->out_);
1903+
assert(qk);
1904+
bool qk_inserted = not pg_.hasKey(qk);
1905+
pid = pg_.insK(qk);
1906+
1907+
if (qk_inserted) {
1908+
::snprintf(nm_buf, 510, "nd%u_L%u_",
1909+
pid, drv_drv->lnum_);
1910+
if (drv_drv->is_CLK_BUF())
1911+
::strcat(nm_buf, "CBUF");
1912+
pg_.setNodeName(pid, nm_buf);
1913+
}
1914+
pg2blif_.emplace(pid, drv_drv->id_);
1915+
}
1916+
1917+
assert(qk);
1918+
eid = pg_.linK(qk, key);
1919+
assert(eid);
1920+
if (trace_ >= 11)
1921+
lprintf("\t\t\t eid= %u\n", eid);
18411922
}
18421923
}
18431924
}
@@ -1847,6 +1928,20 @@ bool BLIF_file::createPinGraph() noexcept {
18471928

18481929
// writePinGraph("pin_graph_1.dot");
18491930

1931+
#ifndef NDEBUG
1932+
// -- verify that all NW IDs are mapped to BNodes:
1933+
for (NW::cNI I(pg_); I.valid(); ++I) {
1934+
const NW::Node& nd = *I;
1935+
if (not pg2blif_.count(nd.id_)) {
1936+
lputs9("\n !!! ASSERT !!!");
1937+
lprintf(" !!! nd.id_= %u\n", nd.id_);
1938+
lprintf(" "); nd.print(lout());
1939+
flush_out(true);
1940+
}
1941+
assert(pg2blif_.count(nd.id_));
1942+
}
1943+
#endif
1944+
18501945
return true;
18511946
}
18521947

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 = "pln0321";
1+
static const char* _pln_VERSION_STR = "pln0324";
22

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

planning/src/util/nw/Nw.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ uint NW::insK(uint64_t k) noexcept {
3838
}
3939

4040
assert(nodeRef(newNid).key_ == k);
41+
//if (newNid == 44)
42+
// lputs1();
4143
return newNid;
4244
}
4345

@@ -272,6 +274,26 @@ uint NW::countClockNodes() const noexcept {
272274
return cnt;
273275
}
274276

277+
uint NW::countNamedNodes() const noexcept {
278+
uint cnt = 0;
279+
if (empty()) return 0;
280+
for (cNI I(*this); I.valid(); ++I) {
281+
if (I->isNamed())
282+
cnt++;
283+
}
284+
return cnt;
285+
}
286+
287+
uint NW::countRedNodes() const noexcept {
288+
uint cnt = 0;
289+
if (empty()) return 0;
290+
for (cNI I(*this); I.valid(); ++I) {
291+
if (I->isRed())
292+
cnt++;
293+
}
294+
return cnt;
295+
}
296+
275297
bool NW::hasClockNodes() const noexcept {
276298
if (empty()) return false;
277299
for (cNI I(*this); I.valid(); ++I) {

planning/src/util/nw/Nw.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ struct NW {
9999
key_ = 0;
100100
}
101101

102+
bool isNamed() const noexcept {
103+
return not name_.empty();
104+
}
102105
string getName() const noexcept {
103106
if (name_.empty()) {
104107
string nm{"nd_"};
@@ -264,10 +267,13 @@ struct NW {
264267
}
265268
uint numN() const noexcept { return size(); }
266269
inline uint numE() const noexcept;
270+
inline uint countRedEdges() const noexcept;
267271

268272
inline upair countRoots() const noexcept;
269273
bool hasClockNodes() const noexcept;
270274
uint countClockNodes() const noexcept;
275+
uint countRedNodes() const noexcept;
276+
uint countNamedNodes() const noexcept;
271277

272278
void getNodes(vecu& V) const noexcept { V = nids_; }
273279

@@ -831,6 +837,15 @@ inline uint NW::numE() const noexcept {
831837
return cnt;
832838
}
833839

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+
834849
inline void NW::clearEdges() noexcept {
835850
edStor_.clear();
836851
edStor_.emplace_back();

planning/src/util/nw/Nw_io.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,25 @@ void NW::Node::print(ostream& os) const noexcept {
312312
os << endl;
313313
}
314314

315-
static void replace_bus_for_dot(char* buf) noexcept {
315+
static void be_dot_friendly(char* buf) noexcept {
316316
assert(buf);
317317
// replace [] by __
318+
// replace $ by S
318319
for (char* p = buf; *p; p++) {
319-
if (*p == '[' or *p == ']')
320+
if (*p == '[' or *p == ']') {
320321
*p = '_';
322+
continue;
323+
}
324+
if (*p == '$') {
325+
*p = 'S';
326+
}
321327
}
322328
}
323329

324330
void NW::Node::nprint_dot(ostream& os) const noexcept {
325331
char name_buf[2048] = {};
326332
getName(name_buf);
327-
replace_bus_for_dot(name_buf);
333+
be_dot_friendly(name_buf);
328334

329335
char attrib[512] = {};
330336

@@ -353,12 +359,12 @@ void NW::Edge::eprint_dot(ostream& os, char arrow, const NW& g) const noexcept {
353359
assert(arrow == '>' or arrow == '-');
354360
char buf[2048] = {};
355361
g.nodeRef(n1_).getName(buf);
356-
replace_bus_for_dot(buf);
362+
be_dot_friendly(buf);
357363
os_printf(os, "%s -%c ", buf, arrow);
358364

359365
buf[0] = 0;
360366
g.nodeRef(n2_).getName(buf);
361-
replace_bus_for_dot(buf);
367+
be_dot_friendly(buf);
362368
os << buf;
363369

364370
char attrib[512] = {};
@@ -452,6 +458,14 @@ uint NW::printSum(ostream& os, uint16_t forDot) const noexcept {
452458
os_printf(os, " mm-deg: (%u,%u)", mmD.first, mmD.second);
453459
os_printf(os, " mm-lbl: (%u,%u)\n", mmL.first, mmL.second);
454460

461+
uint numNamedNodes = countNamedNodes();
462+
uint numRedNodes = countRedNodes();
463+
uint numRedEdges = countRedEdges();
464+
465+
dot_comment(os, forDot);
466+
os_printf(os, "#NamedNodes=%u #RedNodes= %u #RedEdges= %u\n",
467+
numNamedNodes, numRedNodes, numRedEdges);
468+
455469
dot_comment(os, forDot);
456470
os_printf(os, "nr=(%u,%u)\n", rcnt.first, rcnt.second);
457471

0 commit comments

Comments
 (0)