Skip to content

Commit 184e6dd

Browse files
committed
checker: identify clock pins in graph
1 parent 9e32af1 commit 184e6dd

File tree

7 files changed

+174
-20
lines changed

7 files changed

+174
-20
lines changed

planning/src/file_readers/pln_blif_file.cpp

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,11 +1429,48 @@ bool BLIF_file::checkClockSepar(vector<const Node*>& clocked) noexcept {
14291429
flush_out(true); err_puts();
14301430
lprintf2("[Error] NOT createPinGraph()\n");
14311431
err_puts(); flush_out(true);
1432+
return true;
1433+
}
1434+
if (pg_.size() < 3)
1435+
return true;
1436+
1437+
if (not pg_.hasClockNodes())
1438+
return true;
1439+
1440+
// -- paint clock nodes and their incoming edges Red
1441+
for (NW::NI I(pg_); I.valid(); ++I) {
1442+
NW::Node& nd = *I;
1443+
if (nd.isClk()) {
1444+
nd.paintRed();
1445+
for (NW::IncoEI J(pg_, nd); J.valid(); ++J) {
1446+
uint eid = J->id_;
1447+
pg_.edgeRef(eid).paintRed();
1448+
}
1449+
}
14321450
}
14331451

14341452
return true;
14351453
}
14361454

1455+
struct qTup {
1456+
uint inpNid_ = 0;
1457+
uint cellId_ = 0;
1458+
uint inputPin_ = 0;
1459+
CStr outNet_ = nullptr;
1460+
1461+
qTup() noexcept = default;
1462+
1463+
qTup(uint inid, uint cid, uint ip, CStr z) noexcept
1464+
: inpNid_(inid),
1465+
cellId_(cid),
1466+
inputPin_(ip),
1467+
outNet_(z) {
1468+
assert(inid);
1469+
assert(cid);
1470+
assert(z and z[0]);
1471+
}
1472+
};
1473+
14371474
bool BLIF_file::createPinGraph() noexcept {
14381475
auto& ls = lout();
14391476
pg_.clear();
@@ -1468,8 +1505,10 @@ bool BLIF_file::createPinGraph() noexcept {
14681505
pg_.nodeRef(nid).markOut(true);
14691506
}
14701507

1508+
vector<qTup> Q;
1509+
Q.reserve(topInputs_.size());
1510+
14711511
// -- link from input ports to fabric
1472-
// lputs9();
14731512
for (Node* p : topInputs_) {
14741513
INP.clear();
14751514
Node& port = *p;
@@ -1493,11 +1532,17 @@ bool BLIF_file::createPinGraph() noexcept {
14931532
INP.clear();
14941533
pr_get_inputs(par.ptype_, INP);
14951534

1535+
const string& pinName = par.getInPin(pinIndex);
1536+
bool is_clock = pr_pin_is_clock(par.ptype_, pinName);
1537+
14961538
if (trace_ >= 5) {
1497-
lprintf(" FabricParent par: lnum_= %u kw_= %s ptype_= %s #inputs= %u\n",
1539+
lprintf(" FabricParent par: lnum_= %u kw_= %s ptype_= %s pin[%u nm= %s%s]\n",
14981540
par.lnum_, par.kw_.c_str(), par.cPrimType(),
1499-
pr_num_inputs(par.ptype_));
1500-
logVec(INP, " [par_inputs] ");
1541+
pinIndex, pinName.c_str(), is_clock ? " <C>" : "");
1542+
logVec(INP, " [par_inputs] ");
1543+
logVec(par.inPins_, " [inPins_] ");
1544+
if (trace_ >= 7)
1545+
logVec(par.inSigs_, " [inSigs_] ");
15011546
lputs();
15021547
}
15031548

@@ -1511,19 +1556,47 @@ bool BLIF_file::createPinGraph() noexcept {
15111556
assert(pg_.hasKey(port.id_)); //
15121557

15131558
pg_.nodeRef(kid).setCid(par.id_);
1514-
::snprintf(nm_buf, 510, "%s_%uL",
1515-
par.hasPrimType() ? par.cPrimType() : "NP", par.lnum_);
1559+
::snprintf(nm_buf, 510, "%s_%uL_%up%u",
1560+
par.hasPrimType() ? par.cPrimType() : "NP",
1561+
par.lnum_, par.id_, pinIndex);
15161562
pg_.setNodeName(kid, nm_buf);
1563+
pg_.nodeRef(kid).markClk(is_clock);
15171564

15181565
eid = pg_.linK(port.id_, key);
15191566
assert(eid);
1567+
1568+
Q.emplace_back(kid, par.id_, pinIndex, par.out_.c_str());
1569+
}
1570+
}
1571+
1572+
// -- link cell-edges and next level
1573+
if (trace_ >= 5) {
1574+
lprintf("|Q| .sz= %zu\n", Q.size());
1575+
for (uint i = 0; i < Q.size(); i++) {
1576+
const qTup& q = Q[i];
1577+
lprintf(" |%u| ( nid:%u %u.%u %s )\n",
1578+
i, q.inpNid_, q.cellId_, q.inputPin_, q.outNet_);
1579+
}
1580+
}
1581+
if (not Q.empty()) {
1582+
for (uint i = 0; i < Q.size(); i++) {
1583+
const qTup& q = Q[i];
1584+
uint64_t qk = hashComb(q.cellId_, q.outNet_);
1585+
assert(qk);
1586+
kid = pg_.insK(qk);
1587+
eid = pg_.linkNodes(q.inpNid_, kid, true);
1588+
1589+
::snprintf(nm_buf, 510, "nd%u_L%u_Q%u",
1590+
kid, nodeRef(q.cellId_).lnum_, q.cellId_);
1591+
pg_.setNodeName(kid, nm_buf);
15201592
}
15211593
}
15221594

15231595
if (1) {
15241596

1597+
flush_out(true);
15251598
pg_.setNwName("pin_graph");
1526-
pg_.dump("\t *** pg_ separ ***");
1599+
pg_.dump("\t *** pin_graph for clock-data separation ***");
15271600
lprintf("\t pg_. numN()= %u numE()= %u\n", pg_.numN(), pg_.numE());
15281601
lputs();
15291602
pg_.printSum(ls, 0);
@@ -1536,7 +1609,7 @@ bool BLIF_file::createPinGraph() noexcept {
15361609

15371610
}
15381611

1539-
return false;
1612+
return true;
15401613
}
15411614

15421615
}

planning/src/file_readers/pln_blif_file.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ struct BLIF_file : public fio::MMapReader
4747
if (keyword) kw_ = keyword;
4848
}
4949

50+
const string& getInPin(uint pinIndex) const noexcept {
51+
assert(inPins_.size() == inSigs_.size());
52+
assert(pinIndex < inPins_.size());
53+
return inPins_[pinIndex];
54+
}
55+
const string& getInSig(uint pinIndex) const noexcept {
56+
assert(inPins_.size() == inSigs_.size());
57+
assert(pinIndex < inSigs_.size());
58+
return inSigs_[pinIndex];
59+
}
60+
5061
void setOutHash() noexcept {
5162
out_hc_ = str::hashf(out_.c_str());
5263
}

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

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

planning/src/util/geo/iv.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <utility>
2525
#include <vector>
2626

27+
#include "util/pln_log.h"
28+
2729
namespace pln {
2830

2931
inline constexpr uint64_t hashComb(uint64_t a, uint64_t b) noexcept {
@@ -35,6 +37,13 @@ inline constexpr uint64_t hashComb(uint64_t a, uint64_t b, uint64_t c) noexcept
3537
return hashComb(a, hashComb(b, c));
3638
}
3739

40+
inline uint64_t hashComb(uint64_t a, CStr s) noexcept {
41+
return hashComb(a, str::hashf(s));
42+
}
43+
inline uint64_t hashComb(uint64_t a, const std::string& s) noexcept {
44+
return hashComb(a, str::hashf(s));
45+
}
46+
3847
inline constexpr int protectedAdd(int a, int b) noexcept {
3948
int64_t c = int64_t(a) + int64_t(b);
4049
if (c > INT_MAX) return INT_MAX;

planning/src/util/nw/Nw.cpp

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,25 @@ uint NW::findNode(uint64_t k) const noexcept {
251251
return 0;
252252
}
253253

254+
uint NW::countClockNodes() const noexcept {
255+
uint cnt = 0;
256+
if (empty()) return 0;
257+
for (cNI I(*this); I.valid(); ++I) {
258+
if (I->isClk())
259+
cnt++;
260+
}
261+
return cnt;
262+
}
263+
264+
bool NW::hasClockNodes() const noexcept {
265+
if (empty()) return false;
266+
for (cNI I(*this); I.valid(); ++I) {
267+
if (I->isClk())
268+
return true;
269+
}
270+
return false;
271+
}
272+
254273
// ==== DEBUG
255274

256275
void NW::dot_comment(ostream& os, uint16_t dotMode, CStr msg) noexcept {
@@ -314,16 +333,31 @@ static void replace_bus_for_dot(char* buf) noexcept {
314333
}
315334

316335
void NW::Node::nprint_dot(ostream& os) const noexcept {
317-
char buf[2048] = {};
318-
getName(buf);
319-
replace_bus_for_dot(buf);
336+
char name_buf[2048] = {};
337+
getName(name_buf);
338+
replace_bus_for_dot(name_buf);
320339

321-
CStr attrib = "[ shape=record, style=rounded ];";
322-
if (inp_flag_)
323-
attrib = "[ shape=box, color=gray, style=filled ];";
340+
char attrib[512] = {};
341+
342+
if (!inp_flag_ and !clk_flag_) {
343+
if (isRed())
344+
::strcpy(attrib, "[ shape=record, color=red, style=rounded ];");
345+
else
346+
::strcpy(attrib, "[ shape=record, style=rounded ];");
347+
}
348+
else {
349+
if (inp_flag_) {
350+
CStr cs = isRed() ? "red" : "gray";
351+
::sprintf(attrib, "[ shape=box, color=%s, style=filled ];", cs);
352+
}
353+
else if (clk_flag_) {
354+
CStr cs = isRed() ? "red" : "orange";
355+
::sprintf(attrib, "[ shape=record, color=%s, style=filled ];", cs);
356+
}
357+
}
324358

325359
os_printf(os, "%s %s // deg= %u;\n",
326-
buf, attrib, degree());
360+
name_buf, attrib, degree());
327361
}
328362

329363
void NW::Edge::eprint_dot(ostream& os, char arrow, const NW& g) const noexcept {
@@ -417,10 +451,11 @@ uint NW::printSum(ostream& os, uint16_t forDot) const noexcept {
417451
upair mmD = getMinMaxDeg();
418452
upair mmL = getMinMaxLbl();
419453
upair rcnt = countRoots();
454+
uint numClkNodes = countClockNodes();
420455

421456
dot_comment(os, forDot);
422-
os_printf(os, "nn= %u ne= %u nr= %zu r0= %u",
423-
numN(), numE(), rids_.size(), first_rid());
457+
os_printf(os, "nn= %u ne= %u nr= %zu r0= %u #clkn= %u",
458+
numN(), numE(), rids_.size(), first_rid(), numClkNodes);
424459

425460
os_printf(os, " mm-deg: (%u,%u)", mmD.first, mmD.second);
426461
os_printf(os, " mm-lbl: (%u,%u)\n", mmL.first, mmL.second);

planning/src/util/nw/Nw.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,24 @@
2020

2121
namespace pln {
2222

23+
using std::string;
24+
using std::ostream;
2325
using veci = std::vector<int>;
2426
using vecu = std::vector<uint>;
2527
using ipair = std::pair<int, int>;
2628
using upair = std::pair<uint, uint>;
27-
using std::ostream;
28-
using std::string;
29+
using uspair = std::pair<uint, string>;
2930

3031
struct NW {
3132
struct Node;
3233
using NodeStor = std::deque<Node>;
3334

35+
static constexpr uint c_Red = 1;
36+
static constexpr uint c_Orange = 2;
37+
static constexpr uint c_Yellow = 3;
38+
static constexpr uint c_Green = 4;
39+
static constexpr uint c_Blue = 5;
40+
3441
struct Edge {
3542
uint id_ = 0;
3643
uint n1_ = 0, n2_ = 0;
@@ -46,6 +53,10 @@ struct NW {
4653
assert(n1 != n2);
4754
}
4855

56+
void paint(uint col) noexcept { color_ = col; }
57+
void paintRed() noexcept { color_ = c_Red; }
58+
bool isRed() const noexcept { return color_ == c_Red; }
59+
4960
bool valid() const noexcept { return n1_; }
5061
void inval() noexcept { ::memset(this, 0, sizeof(*this)); }
5162

@@ -131,6 +142,8 @@ struct NW {
131142
void markSink(bool val) noexcept { sink_flag_ = val; }
132143
void markInp(bool val) noexcept { inp_flag_ = val; }
133144
void markOut(bool val) noexcept { out_flag_ = val; }
145+
void markClk(bool val) noexcept { clk_flag_ = val; }
146+
bool isClk() const noexcept { return clk_flag_; }
134147
bool terminal() const noexcept { return sink_flag_ or root_flag_; }
135148

136149
void print(ostream& os) const noexcept;
@@ -139,6 +152,10 @@ struct NW {
139152
bool isCell() const noexcept { return cid_; }
140153
void setCid(uint ci) noexcept { cid_ = ci; }
141154

155+
void paint(uint col) noexcept { color_ = col; }
156+
void paintRed() noexcept { color_ = c_Red; }
157+
bool isRed() const noexcept { return color_ == c_Red; }
158+
142159
// DATA:
143160
vecu edges_;
144161

@@ -147,6 +164,7 @@ struct NW {
147164
uint id_ = 0;
148165
uint par_ = 0;
149166
uint cid_ = 0;
167+
uint color_ = 0;
150168

151169
uint lbl_ = 0;
152170
int rad_ = 0;
@@ -156,6 +174,7 @@ struct NW {
156174
bool sink_flag_ = false;
157175
bool inp_flag_ = false;
158176
bool out_flag_ = false;
177+
bool clk_flag_ = false;
159178
string name_;
160179
};
161180

@@ -236,6 +255,8 @@ struct NW {
236255
inline uint numE() const noexcept;
237256

238257
inline upair countRoots() const noexcept;
258+
bool hasClockNodes() const noexcept;
259+
uint countClockNodes() const noexcept;
239260

240261
void getNodes(vecu& V) const noexcept { V = nids_; }
241262

planning/src/util/pln_log.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ inline size_t hashf(CStr z) noexcept {
255255
std::hash<std::string_view> h;
256256
return h(std::string_view{z});
257257
}
258+
inline size_t hashf(const std::string& s) noexcept {
259+
if (s.empty()) return 1;
260+
std::hash<std::string> h;
261+
return h(s);
262+
}
258263

259264
} // NS str
260265

0 commit comments

Comments
 (0)