Skip to content

Commit 074578c

Browse files
authored
Merge pull request #776 from os-fpga/checker_method_createPinGraph
checker: added method createPinGraph() for clock-data
2 parents ce6723f + 208f0e9 commit 074578c

File tree

5 files changed

+183
-32
lines changed

5 files changed

+183
-32
lines changed

planning/src/file_readers/pln_blif_file.cpp

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void BLIF_file::reset(CStr nm, uint16_t tr) noexcept {
2323
inputs_lnum_ = outputs_lnum_ = 0;
2424
err_lnum_ = 0;
2525
err_msg_.clear();
26+
pg_.clear();
2627
}
2728

2829
// "model "
@@ -1149,7 +1150,7 @@ BLIF_file::Node* BLIF_file::findFabricDriver(uint of, const string& contact) noe
11491150
return nullptr;
11501151
}
11511152

1152-
void BLIF_file::link(Node& from, Node& to) noexcept {
1153+
void BLIF_file::link2(Node& from, Node& to) noexcept {
11531154
assert(from.id_);
11541155
assert(to.id_);
11551156
assert(!to.parent_);
@@ -1178,7 +1179,7 @@ bool BLIF_file::linkNodes() noexcept {
11781179
}
11791180
Node* port = findOutputPort(nd.out_);
11801181
if (port) {
1181-
link(*port, nd);
1182+
link2(*port, nd);
11821183
}
11831184
}
11841185

@@ -1248,7 +1249,7 @@ bool BLIF_file::linkNodes() noexcept {
12481249
err_lnum_ = nd.lnum_;
12491250
return false;
12501251
}
1251-
link(*par, nd);
1252+
link2(*par, nd);
12521253
}
12531254

12541255
// 3. link input ports
@@ -1268,11 +1269,20 @@ bool BLIF_file::linkNodes() noexcept {
12681269
err_lnum_ = nd.lnum_;
12691270
return false;
12701271
}
1271-
link(*par, nd);
1272+
link2(*par, nd);
12721273
}
12731274
}
12741275

1275-
// 4. every node except topInputs_ should be driven
1276+
// 4. set hashes
1277+
uint nn = numNodes();
1278+
for (uint i = 1; i <= nn; i++) {
1279+
Node& nd = nodePool_[i];
1280+
assert(nd.id_ == i);
1281+
nd.setCellHash();
1282+
nd.setOutHash();
1283+
}
1284+
1285+
// 5. every node except topInputs_ should be driven
12761286
string inp1;
12771287
for (Node* fab_nd : fabricNodes_) {
12781288
Node& nd = *fab_nd;
@@ -1301,10 +1311,18 @@ bool BLIF_file::linkNodes() noexcept {
13011311
return true;
13021312
}
13031313

1304-
bool BLIF_file::checkClockSepar(vector<const Node*>& clocked) const noexcept {
1314+
bool BLIF_file::checkClockSepar(vector<const Node*>& clocked) noexcept {
13051315
if (1|| clocked.empty())
13061316
return true;
13071317

1318+
bool ok = createPinGraph();
1319+
if (!ok) {
1320+
flush_out(true); err_puts();
1321+
lprintf2("[Error] NOT createPinGraph()\n");
1322+
err_puts(); flush_out(true);
1323+
}
1324+
1325+
#if 0
13081326
NW g;
13091327
auto& ls = lout();
13101328
char nm_buf[512] = {};
@@ -1355,9 +1373,72 @@ bool BLIF_file::checkClockSepar(vector<const Node*>& clocked) const noexcept {
13551373
lputs("\n\t***** break; // TMP");
13561374
break; // TMP
13571375
}
1376+
#endif //////////0000000000
13581377

13591378
return true;
13601379
}
13611380

1381+
bool BLIF_file::createPinGraph() noexcept {
1382+
auto& ls = lout();
1383+
pg_.clear();
1384+
if (!rd_ok_) return false;
1385+
if (topInputs_.empty() and topOutputs_.empty()) return false;
1386+
if (fabricNodes_.empty()) return false;
1387+
1388+
err_msg_.clear();
1389+
uint64_t key = 0;
1390+
uint nid = 0, kid = 0, eid = 0;
1391+
1392+
// -- create pg-nodes for topInputs_
1393+
for (const Node* p : topInputs_) {
1394+
const Node& port = *p;
1395+
assert(!port.out_.empty());
1396+
nid = pg_.insK(port.id_);
1397+
assert(nid);
1398+
pg_.setNodeName(nid, port.out_);
1399+
}
1400+
1401+
// -- create pg-nodes for topOutputs_
1402+
for (const Node* p : topOutputs_) {
1403+
const Node& port = *p;
1404+
assert(!port.out_.empty());
1405+
nid = pg_.insK(port.id_);
1406+
assert(nid);
1407+
pg_.setNodeName(nid, port.out_);
1408+
}
1409+
1410+
// -- link from input ports to fabric
1411+
for (Node* p : topInputs_) {
1412+
Node& port = *p;
1413+
assert(!port.out_.empty());
1414+
int pinIndex = -1;
1415+
Node* par = findFabricParent(port.id_, port.out_, pinIndex);
1416+
if (!par) {
1417+
continue;
1418+
}
1419+
assert(par->cell_hc_);
1420+
key = hashComb(par->cell_hc_, pinIndex);
1421+
assert(key);
1422+
kid = pg_.insK(key);
1423+
assert(kid);
1424+
1425+
eid = pg_.linK(port.id_, kid);
1426+
assert(eid);
1427+
}
1428+
1429+
if (1) {
1430+
1431+
pg_.dump("\t *** pg_ separ ***");
1432+
lprintf("\t pg_. numN()= %u numE()= %u\n", pg_.numN(), pg_.numE());
1433+
lputs();
1434+
pg_.printSum(ls, 0);
1435+
lputs();
1436+
pg_.dumpEdges("|edges|");
1437+
1438+
}
1439+
1440+
return false;
1441+
}
1442+
13621443
}
13631444

planning/src/file_readers/pln_blif_file.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "file_readers/pln_Fio.h"
66
#include "file_readers/pln_primitives.h"
77
#include "util/geo/xyz.h"
8+
#include "util/nw/Nw.h"
89

910
namespace pln {
1011

@@ -32,6 +33,8 @@ struct BLIF_file : public fio::MMapReader
3233

3334
prim::Prim_t ptype_ = prim::A_ZERO;
3435

36+
uint64_t cell_hc_ = 0, out_hc_ = 0;
37+
3538
int16_t is_top_ = 0; // -1:top input 1:top output
3639
bool is_mog_ = false;
3740

@@ -41,10 +44,19 @@ struct BLIF_file : public fio::MMapReader
4144
if (keyword) kw_ = keyword;
4245
}
4346

44-
uint64_t outHash() const noexcept { return str::hashf(out_.c_str()); }
47+
void setOutHash() noexcept {
48+
out_hc_ = str::hashf(out_.c_str());
49+
}
50+
uint64_t outHash() const noexcept {
51+
return out_hc_ ? out_hc_ : str::hashf(out_.c_str());
52+
}
4553

46-
uint64_t hashCode() const noexcept {
47-
return hashComb(id_, is_top_, outHash());
54+
void setCellHash() noexcept {
55+
cell_hc_ = hashComb(id_, is_top_, str::hashf(out_.c_str()));
56+
}
57+
uint64_t cellHash() const noexcept {
58+
if (cell_hc_) return cell_hc_;
59+
return hashComb(id_, is_top_, str::hashf(out_.c_str()));
4860
}
4961

5062
bool isTopPort() const noexcept { return is_top_ != 0; }
@@ -202,9 +214,12 @@ struct BLIF_file : public fio::MMapReader
202214
private:
203215
bool createNodes() noexcept;
204216
bool linkNodes() noexcept;
205-
void link(Node& from, Node& to) noexcept;
217+
void link2(Node& from, Node& to) noexcept;
218+
219+
bool createPinGraph() noexcept;
220+
bool linkPinGraph() noexcept;
206221

207-
bool checkClockSepar(vector<const Node*>& clocked) const noexcept;
222+
bool checkClockSepar(vector<const Node*>& clocked) noexcept;
208223

209224
Node* findOutputPort(const string& contact) noexcept;
210225
Node* findInputPort(const string& contact) noexcept;
@@ -218,6 +233,8 @@ struct BLIF_file : public fio::MMapReader
218233
std::vector<Node*> fabricNodes_, constantNodes_;
219234

220235
std::vector<Node*> latches_; // latches are not checked for now
236+
237+
NW pg_; // Pin Graph
221238
};
222239

223240
}

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

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

planning/src/util/nw/Nw.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace pln {
1515

1616
uint NW::insK(uint64_t k) noexcept {
17+
assert(k);
1718
if (empty()) return addNode(k);
1819

1920
uint newNid = 0;
@@ -359,6 +360,22 @@ uint NW::printNodes(ostream& os, CStr msg, uint16_t forDot) const noexcept {
359360
}
360361
uint NW::dumpNodes(CStr msg) const noexcept { return printNodes(lout(), msg, 0); }
361362

363+
uint NW::printEdges(ostream& os, CStr msg) const noexcept {
364+
using std::endl;
365+
if (msg) os << msg << endl;
366+
367+
uint esz = numE();
368+
os_printf(os, " esz= %u\n", esz);
369+
if (esz) {
370+
for (cEI I(*this); I.valid(); ++I) {
371+
I->print(os);
372+
os << endl;
373+
}
374+
}
375+
return esz;
376+
}
377+
uint NW::dumpEdges(CStr msg) const noexcept { return printEdges(lout(), msg); }
378+
362379
uint NW::printSum(ostream& os, uint16_t forDot) const noexcept {
363380
dot_comment(os, forDot);
364381
if (empty()) {

planning/src/util/nw/Nw.h

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ struct NW {
360360
}
361361

362362
uint linkNodes(uint i1, uint i2, bool in_cel = false) noexcept;
363+
inline uint linK(uint64_t k1, uint64_t k2) noexcept;
363364

364365
uint insK(uint64_t k) noexcept;
365366

@@ -370,8 +371,6 @@ struct NW {
370371
return id;
371372
}
372373

373-
uint linK(uint64_t k1, uint64_t k2) noexcept;
374-
375374
inline uint findEdge(uint a, uint b) const noexcept;
376375

377376
uint findNode(uint64_t k) const noexcept {
@@ -413,6 +412,8 @@ struct NW {
413412
uint dump(CStr msg = nullptr) const noexcept;
414413
uint printNodes(ostream& os, CStr msg, uint16_t forDot) const noexcept;
415414
uint dumpNodes(CStr msg = nullptr) const noexcept;
415+
uint printEdges(ostream& os, CStr msg = nullptr) const noexcept;
416+
uint dumpEdges(CStr msg = nullptr) const noexcept;
416417

417418
uint printSum(ostream& os, uint16_t forDot) const noexcept;
418419

@@ -499,24 +500,7 @@ struct NW {
499500
uint16_t trace_ = 0;
500501
};
501502

502-
inline void NW::clear() noexcept {
503-
nids_.clear();
504-
rids_.clear();
505-
ndStor_.clear();
506-
edStor_.clear();
507-
ndStor_.emplace_back();
508-
edStor_.emplace_back();
509-
}
510-
511-
inline uint NW::addNode(const XY& p, uint64_t k) noexcept {
512-
if (ndStor_.empty()) ndStor_.emplace_back();
513-
514-
uint id = ndStor_.size();
515-
ndStor_.emplace_back(p, k, id, 0, false);
516-
nids_.push_back(id);
517-
return id;
518-
}
519-
503+
// ==== Outgoing Edge Iterator
520504
struct NW::OutgEI {
521505
OutgEI(const NW& g, uint nid) noexcept : g_(g), nid_(nid) { reset(); }
522506
OutgEI(const NW& g, const Node& nd) noexcept : g_(g), nid_(nd.id_) { reset(); }
@@ -560,6 +544,7 @@ struct NW::OutgEI {
560544
uint esz_ = 0;
561545
};
562546

547+
// ==== Incoming Edge Iterator
563548
struct NW::IncoEI {
564549
IncoEI(const NW& g, uint nid) noexcept : g_(g), nid_(nid) { reset(); }
565550
IncoEI(const NW& g, const Node& nd) noexcept : g_(g), nid_(nd.id_) { reset(); }
@@ -604,6 +589,7 @@ struct NW::IncoEI {
604589
uint esz_ = 0;
605590
};
606591

592+
// ==== Edge Iterator
607593
struct NW::EI {
608594
EI(NW& g) noexcept : stor_(g.edStor_), cur_(1) {
609595
while (valid() and !stor_[cur_].valid()) cur_++;
@@ -628,6 +614,7 @@ struct NW::EI {
628614
uint cur_ = 0;
629615
};
630616

617+
// ==== const Edge Iterator
631618
struct NW::cEI {
632619
cEI(const NW& g) noexcept : stor_(g.edStor_), cur_(1) {
633620
while (valid() and !stor_[cur_].valid()) cur_++;
@@ -653,6 +640,7 @@ struct NW::cEI {
653640
uint cur_ = 0;
654641
};
655642

643+
// ==== Child Node Iterator
656644
struct NW::ChldNI : public NW::OutgEI {
657645
ChldNI(const NW& g, uint nid) noexcept : OutgEI(g, nid) {}
658646
ChldNI& operator++() noexcept {
@@ -673,6 +661,24 @@ struct NW::ChldNI : public NW::OutgEI {
673661
}
674662
};
675663

664+
inline void NW::clear() noexcept {
665+
nids_.clear();
666+
rids_.clear();
667+
ndStor_.clear();
668+
edStor_.clear();
669+
ndStor_.emplace_back();
670+
edStor_.emplace_back();
671+
}
672+
673+
inline uint NW::addNode(const XY& p, uint64_t k) noexcept {
674+
if (ndStor_.empty()) ndStor_.emplace_back();
675+
676+
uint id = ndStor_.size();
677+
ndStor_.emplace_back(p, k, id, 0, false);
678+
nids_.push_back(id);
679+
return id;
680+
}
681+
676682
inline uint NW::Node::outDeg(const NW& g) const noexcept {
677683
if (edges_.empty()) return 0;
678684

@@ -783,6 +789,36 @@ inline uint NW::findEdge(uint a, uint b) const noexcept {
783789
return 0;
784790
}
785791

792+
inline uint NW::linK(uint64_t k1, uint64_t k2) noexcept {
793+
assert(k1 != k2);
794+
uint n1 = 0, n2 = 0;
795+
796+
if (empty()) {
797+
uint e = 0;
798+
if (k1 < k2) {
799+
addNode(k1);
800+
addNode(k2);
801+
e = linkNodes(1, 2);
802+
} else {
803+
addNode(k2);
804+
addNode(k1);
805+
e = linkNodes(2, 1);
806+
}
807+
return e;
808+
}
809+
810+
if (k1 < k2) {
811+
n1 = insK(k1);
812+
n2 = insK(k2);
813+
} else {
814+
n2 = insK(k2);
815+
n1 = insK(k1);
816+
}
817+
818+
assert(n1 and n2);
819+
return linkNodes(n1, n2);
820+
}
821+
786822
inline upair NW::countRoots() const noexcept {
787823
uint cnt = 0, mark_cnt = 0;
788824
if (empty()) return {cnt, mark_cnt};

0 commit comments

Comments
 (0)