ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
Rewire::Miaig Class Reference

#include <rewire_miaig.h>

Public Member Functions

 Miaig (void)
 
 ~Miaig (void)
 
 Miaig (const Miaig &m)
 
Miaigoperator= (const Miaig &m)
 
 Miaig (int nIns, int nOuts, int nObjsAlloc)
 
 Miaig (Gia_Man_t *pGia)
 
 Miaig (Abc_Ntk_t *pNtk)
 
 Miaig (Mini_Aig_t *pMiniAig)
 
void setExc (Gia_Man_t *pExc)
 
void addref (void)
 
void release (void)
 
bool operator== (const Miaig &m) const
 
int fromGia (Gia_Man_t *pGia)
 
int fromMiniAig (Mini_Aig_t *pMiniAig)
 
int & nIns (void)
 
int & nOuts (void)
 
int & nObjs (void)
 
int & nObjsAlloc (void)
 
int objIsPi (int i)
 
int objIsPo (int i)
 
int objIsNode (int i)
 
int objPiIdx (int i)
 
int objPoIdx (int i)
 
void print (void)
 
int appendObj (void)
 
void appendFanin (int i, int iLit)
 
int objFaninNum (int i)
 
int objFanin0 (int i)
 
int objFanin1 (int i)
 
int & objLevel (int i)
 
int & objRef (int i)
 
int & objTravId (int i)
 
int & objCopy (int i)
 
int & objDist (int i)
 
int & nTravIds (void)
 
wordobjTruth (int i, int n)
 
viobjFanins (int i)
 
int objType (int i)
 
int nWords (void)
 
void refObj (int iObj)
 
void derefObj (int iObj)
 
void derefObj_rec (int iObj, int iLitSkip)
 
void setName (char *pName)
 
float countAnd2 (int reset=0, int fDummy=0)
 
float countTransistors (int reset=0, int nMode=0)
 
int countLevel (int min=0)
 
Miaig dup (int fRemDangle, int fMapped=0)
 
Miaig dupDfs (void)
 
Miaig dupStrash (int fCprop, int fStrash, int fCascade)
 
Miaig dupMulti (int nFaninMax_, int nGrowth)
 
Miaig expand (int nFaninAddLimitAll, int nDist, int nExpandableLevel, word *pExc, int fCheck, int nVerbose)
 
Miaig share (int nNewNodesMax)
 
Miaig reduce (word *pExc, int fCheck, int fVerbose)
 
Miaig expandThenReduce (int nFaninAddLimit, int nDist, int nExpandableLevel, word *pExc, int fCheck, int fVerbose)
 
Miaig expandShareReduce (int nFaninAddLimitAll, int nDivs, int nDist, int nExpandableLevel, word *pExc, int fCheck, int nVerbose)
 
Miaig rewire (int nIters, float levelGrowRatio, int nExpands, int nGrowth, int nDivs, int nFaninMax, int nTimeOut, int nMode, int nMappedMode, int nDist, int fCheck, Gia_ChMan_t *pChMan, int nVerbose)
 
Gia_Man_ttoGia (void)
 
Abc_Ntk_ttoNtk (int fMapped=0)
 
Mini_Aig_ttoMiniAig (void)
 

Detailed Description

Definition at line 191 of file rewire_miaig.h.

Constructor & Destructor Documentation

◆ Miaig() [1/6]

Rewire::Miaig::Miaig ( void )
inline

Definition at line 332 of file rewire_miaig.h.

333 : _refcount(nullptr), _data(nullptr) {
334}
Here is the caller graph for this function:

◆ ~Miaig()

Rewire::Miaig::~Miaig ( void )
inline

Definition at line 357 of file rewire_miaig.h.

357 {
358 release();
359}
void release(void)
Here is the call graph for this function:

◆ Miaig() [2/6]

Rewire::Miaig::Miaig ( const Miaig & m)
inline

Definition at line 361 of file rewire_miaig.h.

362 : _refcount(m._refcount), _data(m._data) {
363 addref();
364}
void addref(void)
Here is the call graph for this function:

◆ Miaig() [3/6]

Rewire::Miaig::Miaig ( int nIns,
int nOuts,
int nObjsAlloc )
inline

Definition at line 336 of file rewire_miaig.h.

337 : Miaig() {
338 create(nIns, nOuts, nObjsAlloc);
339}
int & nObjsAlloc(void)
int & nOuts(void)
int & nIns(void)
Here is the call graph for this function:

◆ Miaig() [4/6]

Rewire::Miaig::Miaig ( Gia_Man_t * pGia)
inline

Definition at line 342 of file rewire_miaig.h.

342 : Miaig() {
343 fromGia(pGia);
344}
int fromGia(Gia_Man_t *pGia)
Here is the call graph for this function:

◆ Miaig() [5/6]

Rewire::Miaig::Miaig ( Abc_Ntk_t * pNtk)
inline

Definition at line 346 of file rewire_miaig.h.

346 : Miaig() {
347 Mini_Aig_t *pMiniAig = Abc_ManRewireMiniAigFromNtk(pNtk);
348 fromMiniAig(pMiniAig);
349 Mini_AigStop(pMiniAig);
350}
int fromMiniAig(Mini_Aig_t *pMiniAig)
struct Mini_Aig_t_ Mini_Aig_t
BASIC TYPES ///.
Definition miniaig.h:48
Mini_Aig_t * Abc_ManRewireMiniAigFromNtk(Abc_Ntk_t *pNtk)
Definition rewire_map.c:86
Here is the call graph for this function:

◆ Miaig() [6/6]

Rewire::Miaig::Miaig ( Mini_Aig_t * pMiniAig)
inline

Definition at line 352 of file rewire_miaig.h.

352 : Miaig() {
353 fromMiniAig(pMiniAig);
354}
Here is the call graph for this function:

Member Function Documentation

◆ addref()

void Rewire::Miaig::addref ( void )
inline

Definition at line 383 of file rewire_miaig.h.

383 {
384 if (_refcount) {
385 RW_XADD(_refcount, 1);
386 }
387}
Here is the caller graph for this function:

◆ appendFanin()

void Rewire::Miaig::appendFanin ( int i,
int iLit )
inline

Definition at line 467 of file rewire_miaig.h.

467 {
468 Vi_PushOrder(objFanins(i), iLit);
469}
vi * objFanins(int i)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ appendObj()

int Rewire::Miaig::appendObj ( void )
inline

Definition at line 462 of file rewire_miaig.h.

462 {
463 assert(nObjs() < nObjsAlloc());
464 return nObjs()++;
465}
int & nObjs(void)
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ countAnd2()

float Rewire::Miaig::countAnd2 ( int reset = 0,
int fDummy = 0 )
inline

Definition at line 512 of file rewire_miaig.h.

512 {
513 int i, Counter = 0;
515 Counter += objFaninNum(i) - 1;
516 }
517 return Counter;
518}
int objFaninNum(int i)
#define Miaig_ForEachNode(i)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ countLevel()

int Rewire::Miaig::countLevel ( int min = 0)
inline

Definition at line 520 of file rewire_miaig.h.

520 {
521 initializeLevels();
522 int i, Level = (min) ? RW_INT_MAX : -1;
523 int (*compareFunc)(int, int) = (min) ? Rw_MinInt : Rw_MaxInt;
525 Level = compareFunc(Level, objLevel(i));
526 }
527 return Level;
528}
int & objLevel(int i)
#define Miaig_ForEachOutput(i)
#define Rw_MaxInt
#define RW_INT_MAX
#define Rw_MinInt
Here is the call graph for this function:
Here is the caller graph for this function:

◆ countTransistors()

float Rewire::Miaig::countTransistors ( int reset = 0,
int nMode = 0 )

Definition at line 272 of file rewire_miaig.cpp.

272 {
273 if (!reset && _data->nTransistor) return _data->nTransistor;
274#ifdef RW_ABC
275 float area = 0;
276 Abc_Ntk_t *pNtkMapped = NULL, *pNtkMappedTemp = NULL;
277 if (nMappedMode == 0) { // amap
278 Abc_Ntk_t *pNtk = toNtk();
279 pNtkMapped = Abc_ManRewireMapAmap(pNtk);
280 Abc_NtkDelete(pNtk);
281 } else if (nMappedMode == 1) { // &nf
282 Gia_Man_t *pGia = toGia();
283 pNtkMapped = Gia_ManRewireMapNf(pGia);
284 Gia_ManStop(pGia);
285 } else if (nMappedMode == 2) { // &simap
286 Abc_Ntk_t *pNtk = toNtk();
287 pNtkMapped = Abc_ManRewireMapAmap(pNtk);
288 area = Abc_NtkGetMappedArea(pNtkMapped);
289 Gia_Man_t *pGia = toGia();
290 while ((pNtkMappedTemp = Gia_ManRewireMapSimap(pGia, area - 2, 0, 40))) {
291 area -= 2;
292 Abc_NtkDelete(pNtkMapped);
293 pNtkMapped = pNtkMappedTemp;
294 }
295 Gia_ManStop(pGia);
296 }
297 if (pNtkMapped) {
298 area = Abc_NtkGetMappedArea(pNtkMapped);
299 Vec_Int_t *vMapping = Abc_ManRewireNtkWriteMiniMapping(pNtkMapped);
300 _data->pNtkMapped = moveVecToVi(vMapping);
301 Abc_NtkDelete(pNtkMapped);
302 }
303#else
304 float area = countAnd2(reset, 0);
305#endif // RW_ABC
306
307 return _data->nTransistor = area;
308}
ABC_DLL double Abc_NtkGetMappedArea(Abc_Ntk_t *pNtk)
Definition abcUtil.c:347
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Gia_Man_t * toGia(void)
float countAnd2(int reset=0, int fDummy=0)
Abc_Ntk_t * toNtk(int fMapped=0)
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
vi * moveVecToVi(Vec_Int_t *v)
Abc_Ntk_t * Gia_ManRewireMapNf(Gia_Man_t *pGia)
Definition rewire_map.c:57
Abc_Ntk_t * Abc_ManRewireMapAmap(Abc_Ntk_t *pNtk)
Definition rewire_map.c:46
Vec_Int_t * Abc_ManRewireNtkWriteMiniMapping(Abc_Ntk_t *pNtk)
Definition rewire_map.c:78
Abc_Ntk_t * Gia_ManRewireMapSimap(Gia_Man_t *pGia, int nBound, int nBTLimit, int nTimeout)
Definition rewire_map.c:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ derefObj()

void Rewire::Miaig::derefObj ( int iObj)

Definition at line 427 of file rewire_miaig.cpp.

427 {
428 int k, iLit;
429 Miaig_ForEachObjFanin(iObj, iLit, k)
430 objRef(Rw_Lit2Var(iLit))--;
431}
int & objRef(int i)
#define Rw_Lit2Var
#define Miaig_ForEachObjFanin(i, iLit, k)
Here is the call graph for this function:

◆ derefObj_rec()

void Rewire::Miaig::derefObj_rec ( int iObj,
int iLitSkip )

Definition at line 433 of file rewire_miaig.cpp.

433 {
434 int k, iLit;
435 Miaig_ForEachObjFanin(iObj, iLit, k) {
436 if (iLit != iLitSkip && --objRef(Rw_Lit2Var(iLit)) == 0 && objIsNode(Rw_Lit2Var(iLit))) {
437 derefObj_rec(Rw_Lit2Var(iLit), -1);
438 Vi_Fill(objFanins(Rw_Lit2Var(iLit)), 1, 0);
439 refObj(Rw_Lit2Var(iLit));
440 }
441 }
442}
void derefObj_rec(int iObj, int iLitSkip)
void refObj(int iObj)
int objIsNode(int i)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dup()

Miaig Rewire::Miaig::dup ( int fRemDangle,
int fMapped = 0 )

Definition at line 486 of file rewire_miaig.cpp.

486 {
487 // Miaig pNew = Maig_Alloc(nIns(), nOuts(), nObjs());
488 Miaig pNew(nIns(), nOuts(), nObjs());
489 memset(_data->pCopy, 0, sizeof(int) * nObjs());
490 int i, k, iLit; // obj2obj
491 if (fRemDangle)
492 markDfs();
494 objCopy(i) = i;
496 assert(objFaninNum(i) > 0);
497 if (fRemDangle && objTravId(i) != nTravIds())
498 continue;
499 objCopy(i) = pNew.appendObj();
500 Miaig_ForEachObjFanin(i, iLit, k)
501 pNew.appendFanin(objCopy(i), Rw_Lit2LitV(_data->pCopy, iLit));
502 }
503 if (_data->pNtkMapped && fMapped)
504 pNew._data->pNtkMapped = Vi_Dup(_data->pNtkMapped);
505 return pNew;
506}
int & objCopy(int i)
int & objTravId(int i)
int & nTravIds(void)
#define Miaig_ForEachInput(i)
#define Miaig_ForEachNodeOutput(i)
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dupDfs()

Miaig Rewire::Miaig::dupDfs ( void )

Definition at line 527 of file rewire_miaig.cpp.

527 {
528 Miaig pNew(nIns(), nOuts(), nObjsAlloc());
529 // 1. the array is filled with -1 to distinct visited nodes from unvisited
530 memset(_data->pCopy, 0xFF, sizeof(int) * nObjsAlloc());
531 int i; // obj2obj
532 // for each primary input we mark it with it's index
534 objCopy(i) = i;
535 // 2. for each primary output we call recursive function for it's fanin
537 dupDfs_rec(pNew, Rw_Lit2Var(objFanin0(i)));
538 // 3. for each primary output append it's fanin
540 pNew.appendFanin(pNew.appendObj(), Rw_Lit2LitV(_data->pCopy, objFanin0(i)));
541 return pNew;
542}
int objFanin0(int i)
#define Miaig_ForEachConstInput(i)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dupMulti()

Miaig Rewire::Miaig::dupMulti ( int nFaninMax_,
int nGrowth )

Definition at line 693 of file rewire_miaig.cpp.

693 {
694 Miaig pNew(nIns(), nOuts(), nObjs());
695 int *pStop = createStops();
696 int i, k, iLit;
697 vi *vArray = Vi_Alloc(100);
698 assert(nFaninMax_ >= 2 && nGrowth >= 1);
699 memset(_data->pCopy, 0, sizeof(int) * nObjs()); // obj2lit
701 objCopy(i) = Rw_Var2Lit(i, 0);
703 if (pStop[i] == 1)
704 continue;
705 assert(pStop[i] > 1); // no dangling
706 Vi_Shrink(vArray, 0);
707 collectSuper_rec(objFanin0(i), pStop, vArray);
708 collectSuper_rec(objFanin1(i), pStop, vArray);
709 assert(Vi_Size(vArray) > 1);
710 reduceFanins(vArray);
711 assert(Vi_Size(vArray) > 0);
712 if (Vi_Size(vArray) == 1)
713 objCopy(i) = Vi_Read(vArray, 0);
714 else {
715 int nFaninMaxLocal = 2 + (Random_Num(0) % (nFaninMax_ - 1));
716 int nGrowthLocal = 1 + (Random_Num(0) % nGrowth);
717 assert(nFaninMaxLocal >= 2 && nFaninMaxLocal <= nFaninMax_);
718 assert(nGrowthLocal >= 1 && nGrowthLocal <= nGrowth);
719
720 if (Vi_Size(vArray) > nFaninMaxLocal)
721 Vi_Randomize(vArray);
722 // create a cascade of nodes
723 while (Vi_Size(vArray) > nFaninMaxLocal) {
724 int iObj = pNew.appendObj();
725 vi *vFanins = pNew.objFanins(iObj);
726 assert(vFanins->ptr == NULL);
727 vFanins->cap = nFaninMaxLocal + nGrowthLocal;
728 vFanins->ptr = (int *)malloc(sizeof(int) * vFanins->cap);
729 Vi_ForEachEntryStop(vArray, iLit, k, nFaninMaxLocal)
730 pNew.appendFanin(iObj, iLit);
731 assert(Vi_Space(vFanins) == nGrowthLocal);
732 for (k = 0; k < nFaninMaxLocal; k++)
733 Vi_Drop(vArray, 0);
734 Vi_Push(vArray, Rw_Var2Lit(iObj, 0));
735 }
736 // create the last node
737 int iObj = pNew.appendObj();
738 vi *vFanins = pNew.objFanins(iObj);
739 assert(vFanins->ptr == NULL);
740 vFanins->cap = Vi_Size(vArray) + nGrowthLocal;
741 vFanins->ptr = (int *)malloc(sizeof(int) * vFanins->cap);
742 Vi_ForEachEntry(vArray, iLit, k)
743 pNew.appendFanin(iObj, iLit);
744 assert(Vi_Space(vFanins) == nGrowthLocal);
745 objCopy(i) = Rw_Var2Lit(iObj, 0);
746 }
747 }
749 pNew.appendFanin(pNew.appendObj(), Rw_Lit2LitL(_data->pCopy, objFanin0(i)));
750 Vi_Free(vArray);
751 free(pStop);
752 return pNew;
753}
int objFanin1(int i)
#define Rw_Var2Lit
unsigned Random_Num(int Seed)
Definition rewire_rng.c:43
struct vi_ vi
#define Vi_ForEachEntry(v, entry, i)
Definition rewire_vec.h:52
#define Vi_ForEachEntryStop(v, entry, i, stop)
Definition rewire_vec.h:55
int cap
Definition rewire_vec.h:47
int * ptr
Definition rewire_vec.h:48
VOID_HACK free()
char * malloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dupStrash()

Miaig Rewire::Miaig::dupStrash ( int fCprop,
int fStrash,
int fCascade )

Definition at line 643 of file rewire_miaig.cpp.

643 {
644 int i, nObjsAlloc = 1 + nIns() + nOuts() + countAnd2();
645 Miaig pNew(nIns(), nOuts(), nObjsAlloc);
646 memset(_data->pCopy, 0, sizeof(int) * nObjs()); // obj2lit
647 if (fStrash) {
648 assert(pNew._data->pTable == NULL);
649 pNew._data->TableSize = Abc_PrimeCudd(3 * countAnd2());
650 pNew._data->pTable = (int *)calloc(sizeof(int), 3 * pNew._data->TableSize);
651 }
653 objCopy(i) = Rw_Var2Lit(i, 0);
655 assert(objFaninNum(i) > 0);
656 if (fCascade)
657 objCopy(i) = buildNodeCascade(pNew, objFanins(i), fCprop, fStrash);
658 else
659 objCopy(i) = buildNodeBalance(pNew, objFanins(i), fCprop, fStrash);
660 }
662 pNew.appendFanin(pNew.appendObj(), Rw_Lit2LitL(_data->pCopy, objFanin0(i)));
663 return pNew.dup(1);
664}
char * calloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ expand()

Miaig Rewire::Miaig::expand ( int nFaninAddLimitAll,
int nDist,
int nExpandableLevel,
word * pExc,
int fCheck,
int nVerbose )

Definition at line 1146 of file rewire_miaig.cpp.

1146 {
1147 int i, iNode, nAdded = 0;
1148 assert(nFaninAddLimitAll > 0);
1149 vi *vOrder = createRandomOrder();
1150
1151 initializeTruth();
1152 initializeRefs();
1153 initializeLevels();
1154 if (nDist) initializeDists();
1155 Vi_ForEachEntry(vOrder, iNode, i) {
1156 nAdded += expandOne(iNode, std::min(Vi_Space(objFanins(iNode)), nFaninAddLimitAll - nAdded), nDist, nExpandableLevel, pExc, fCheck, fVerbose);
1157 if (nAdded >= nFaninAddLimitAll)
1158 break;
1159 }
1160 assert(nAdded <= nFaninAddLimitAll);
1161 if (fCheck) verifyRefs();
1162 return dupDfs();
1163}
Miaig dupDfs(void)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ expandShareReduce()

Miaig Rewire::Miaig::expandShareReduce ( int nFaninAddLimitAll,
int nDivs,
int nDist,
int nExpandableLevel,
word * pExc,
int fCheck,
int nVerbose )

Definition at line 1208 of file rewire_miaig.cpp.

1208 {
1209 // expand
1210 Miaig pNew = expand(nFaninAddLimitAll, nDist, nExpandableLevel, pExc, fCheck, nVerbose);
1211 // share
1212 pNew = pNew.share(nDivs == -1 ? pNew.nObjs() : nDivs);
1213 // reduce
1214 pNew = pNew.reduce(pExc, fCheck, nVerbose);
1215 return pNew;
1216}
pcover expand()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ expandThenReduce()

Miaig Rewire::Miaig::expandThenReduce ( int nFaninAddLimit,
int nDist,
int nExpandableLevel,
word * pExc,
int fCheck,
int fVerbose )

Definition at line 1192 of file rewire_miaig.cpp.

1192 {
1193 Miaig pTemp;
1194 int i, iNode;
1195 vi *vOrder = topoCollect();
1196
1197 initializeTruth();
1198 initializeRefs();
1199 initializeLevels();
1200 if (nDist) initializeDists();
1201 Vi_ForEachEntry(vOrder, iNode, i) {
1202 expandThenReduceOne(iNode, nFaninAddLimit, nDist, nExpandableLevel, pExc, fCheck, fVerbose);
1203 }
1204 if (fCheck) verifyRefs();
1205 return dupDfs().dupStrash(1, 1, 1);
1206}
Miaig dupStrash(int fCprop, int fStrash, int fCascade)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromGia()

int Rewire::Miaig::fromGia ( Gia_Man_t * pGia)

Definition at line 137 of file rewire_miaig.cpp.

137 {
138 Gia_Obj_t *pObj;
139 int *pCopy = (int *)calloc(sizeof(int), Gia_ManObjNum(pGia)); // obj2obj
140 // printf("[INFO] Converting GIA into MIAIG\n");
141 // printf("[INFO] PI/PO/OBJ = %d/%d/%d\n", Gia_ManPiNum(pGia), Gia_ManPoNum(pGia), Gia_ManObjNum(pGia));
142 create(Gia_ManPiNum(pGia), Gia_ManPoNum(pGia), Gia_ManObjNum(pGia));
143 int i;
144 pCopy[0] = Gia_ObjId(pGia, Gia_ManConst0(pGia));
146 pCopy[i] = i;
147 }
148 Gia_ManForEachAnd(pGia, pObj, i) {
149 pCopy[i] = appendObj();
150 assert(pCopy[i] == i);
151 appendFanin(pCopy[i], Rw_Lit2LitV(pCopy, Gia_Obj2Lit(pGia, Gia_ObjChild1(pObj))));
152 appendFanin(pCopy[i], Rw_Lit2LitV(pCopy, Gia_Obj2Lit(pGia, Gia_ObjChild0(pObj))));
153 }
154 Gia_ManForEachPo(pGia, pObj, i)
155 appendFanin(appendObj(), Rw_Lit2LitV(pCopy, Gia_Obj2Lit(pGia, Gia_ObjChild0(pObj))));
156 free(pCopy);
157 return 1;
158}
int appendObj(void)
void appendFanin(int i, int iLit)
#define Gia_ManForEachPo(p, pObj, i)
Definition gia.h:1250
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromMiniAig()

int Rewire::Miaig::fromMiniAig ( Mini_Aig_t * pMiniAig)

Definition at line 160 of file rewire_miaig.cpp.

160 {
161 int *pCopy = (int *)calloc(sizeof(int), Mini_AigNodeNum(pMiniAig)); // obj2obj
162 create(Mini_AigPiNum(pMiniAig), Mini_AigPoNum(pMiniAig), Mini_AigNodeNum(pMiniAig));
163 int i;
165 pCopy[i] = i;
166 Mini_AigForEachAnd( pMiniAig, i ) {
167 pCopy[i] = appendObj();
168 assert( pCopy[i] == i );
169 appendFanin(pCopy[i], Rw_Lit2LitV(pCopy, Mini_AigNodeFanin0(pMiniAig, i)));
170 appendFanin(pCopy[i], Rw_Lit2LitV(pCopy, Mini_AigNodeFanin1(pMiniAig, i)));
171 }
172 Mini_AigForEachPo( pMiniAig, i )
173 appendFanin(appendObj(), Rw_Lit2LitV(pCopy, Mini_AigNodeFanin0(pMiniAig, i)));
174 free(pCopy);
175 return 1;
176}
#define Mini_AigForEachPo(p, i)
Definition miniaig.h:139
#define Mini_AigForEachAnd(p, i)
Definition miniaig.h:140
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nIns()

int & Rewire::Miaig::nIns ( void )
inline

Definition at line 424 of file rewire_miaig.h.

424 {
425 return _data->nIns;
426}
Here is the caller graph for this function:

◆ nObjs()

int & Rewire::Miaig::nObjs ( void )
inline

Definition at line 432 of file rewire_miaig.h.

432 {
433 return _data->nObjs;
434}
Here is the caller graph for this function:

◆ nObjsAlloc()

int & Rewire::Miaig::nObjsAlloc ( void )
inline

Definition at line 436 of file rewire_miaig.h.

436 {
437 return _data->nObjsAlloc;
438}
Here is the caller graph for this function:

◆ nOuts()

int & Rewire::Miaig::nOuts ( void )
inline

Definition at line 428 of file rewire_miaig.h.

428 {
429 return _data->nOuts;
430}
Here is the caller graph for this function:

◆ nTravIds()

int & Rewire::Miaig::nTravIds ( void )
inline

Definition at line 504 of file rewire_miaig.h.

504 {
505 return _data->nTravIds;
506}
Here is the caller graph for this function:

◆ nWords()

int Rewire::Miaig::nWords ( void )
inline

Definition at line 508 of file rewire_miaig.h.

508 {
509 return _data->nWords;
510}
Here is the caller graph for this function:

◆ objCopy()

int & Rewire::Miaig::objCopy ( int i)
inline

Definition at line 496 of file rewire_miaig.h.

496 {
497 return _data->pCopy[i];
498}
Here is the caller graph for this function:

◆ objDist()

int & Rewire::Miaig::objDist ( int i)
inline

Definition at line 500 of file rewire_miaig.h.

500 {
501 return _data->pDist[i];
502}

◆ objFanin0()

int Rewire::Miaig::objFanin0 ( int i)
inline

Definition at line 475 of file rewire_miaig.h.

475 {
476 return Vi_Read(objFanins(i), 0);
477}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ objFanin1()

int Rewire::Miaig::objFanin1 ( int i)
inline

Definition at line 479 of file rewire_miaig.h.

479 {
480 assert(objFaninNum(i) == 2);
481 return Vi_Read(objFanins(i), 1);
482}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ objFaninNum()

int Rewire::Miaig::objFaninNum ( int i)
inline

Definition at line 471 of file rewire_miaig.h.

471 {
472 return Vi_Size(objFanins(i));
473}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ objFanins()

vi * Rewire::Miaig::objFanins ( int i)
inline

Definition at line 534 of file rewire_miaig.h.

534 {
535 return _data->pvFans + i;
536}
Here is the caller graph for this function:

◆ objIsNode()

int Rewire::Miaig::objIsNode ( int i)
inline

Definition at line 448 of file rewire_miaig.h.

448 {
449 return i > nIns() && i < nObjs() - nOuts();
450}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ objIsPi()

int Rewire::Miaig::objIsPi ( int i)
inline

Definition at line 440 of file rewire_miaig.h.

440 {
441 return i > 0 && i <= nIns();
442}
Here is the call graph for this function:

◆ objIsPo()

int Rewire::Miaig::objIsPo ( int i)
inline

Definition at line 444 of file rewire_miaig.h.

444 {
445 return i >= nObjs() - nOuts();
446}
Here is the call graph for this function:

◆ objLevel()

int & Rewire::Miaig::objLevel ( int i)
inline

Definition at line 484 of file rewire_miaig.h.

484 {
485 return _data->pLevel[i];
486}
Here is the caller graph for this function:

◆ objPiIdx()

int Rewire::Miaig::objPiIdx ( int i)
inline

Definition at line 452 of file rewire_miaig.h.

452 {
453 // assert(objIsPi(i));
454 return i - 1;
455}

◆ objPoIdx()

int Rewire::Miaig::objPoIdx ( int i)
inline

Definition at line 457 of file rewire_miaig.h.

457 {
458 // assert(objIsPo(i));
459 return i - (nObjs() - nOuts());
460}
Here is the call graph for this function:

◆ objRef()

int & Rewire::Miaig::objRef ( int i)
inline

Definition at line 488 of file rewire_miaig.h.

488 {
489 return _data->pRefs[i];
490}
Here is the caller graph for this function:

◆ objTravId()

int & Rewire::Miaig::objTravId ( int i)
inline

Definition at line 492 of file rewire_miaig.h.

492 {
493 return _data->pTravIds[i];
494}
Here is the caller graph for this function:

◆ objTruth()

word * Rewire::Miaig::objTruth ( int i,
int n )
inline

Definition at line 530 of file rewire_miaig.h.

530 {
531 return _data->pTruths[n] + nWords() * i;
532}
int nWords(void)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ objType()

int Rewire::Miaig::objType ( int i)
inline

Definition at line 538 of file rewire_miaig.h.

538 {
539 return objTravId(i) == nTravIds();
540}
Here is the call graph for this function:

◆ operator=()

Miaig & Rewire::Miaig::operator= ( const Miaig & m)
inline

Definition at line 366 of file rewire_miaig.h.

366 {
367 if (this == &m) {
368 return *this;
369 }
370
371 if (m._refcount) {
372 RW_XADD(m._refcount, 1);
373 }
374
375 release();
376
377 _refcount = m._refcount;
378 _data = m._data;
379
380 return *this;
381}
Here is the call graph for this function:

◆ operator==()

bool Rewire::Miaig::operator== ( const Miaig & m) const
inline

Definition at line 420 of file rewire_miaig.h.

420 {
421 return (_data == m._data);
422}
Here is the call graph for this function:

◆ print()

void Rewire::Miaig::print ( void )

Definition at line 116 of file rewire_miaig.cpp.

116 {
117 int i, k, iLit;
118 printf("\nAIG printout:\n");
119 printf("Const0\n");
121 printf("Pi%d\n", i);
123 printf("Node%d {", i);
124 Miaig_ForEachObjFanin(i, iLit, k)
125 printf(" %d", iLit);
126 printf(" }\n");
127 }
129 printf("Po%d ", i);
130 Miaig_ForEachObjFanin(i, iLit, k)
131 printf(" %d", iLit);
132 printf("\n");
133 }
134}

◆ reduce()

Miaig Rewire::Miaig::reduce ( word * pExc,
int fCheck,
int fVerbose )

Definition at line 1178 of file rewire_miaig.cpp.

1178 {
1179 int i, iNode;
1180 vi *vOrder = topoCollect();
1181
1182 initializeTruth();
1183 initializeRefs();
1184 initializeLevels();
1185 // works best for final
1186 Vi_ForEachEntry(vOrder, iNode, i)
1187 reduceOne(iNode, 0, 0, 1, pExc, fCheck, fVerbose);
1188 if (fCheck) verifyRefs();
1189 return dupStrash(1, 1, 1);
1190}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ refObj()

void Rewire::Miaig::refObj ( int iObj)

Definition at line 421 of file rewire_miaig.cpp.

421 {
422 int k, iLit;
423 Miaig_ForEachObjFanin(iObj, iLit, k)
424 objRef(Rw_Lit2Var(iLit))++;
425}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ release()

void Rewire::Miaig::release ( void )
inline

Definition at line 389 of file rewire_miaig.h.

389 {
390 if (_refcount && RW_XADD(_refcount, -1) == 1) {
391 if (_data) {
392 if (_data->pName) free(_data->pName);
393 for (int i = 0; i < _data->nObjsAlloc; ++i)
394 if (_data->pvFans[i].ptr)
395 free(_data->pvFans[i].ptr);
396 free(_data->pvFans);
397 Vi_Free(_data->vOrder);
398 Vi_Free(_data->vOrderF);
399 Vi_Free(_data->vOrderF2);
400 Vi_Free(_data->vTfo);
401 free(_data->pTravIds);
402 free(_data->pCopy);
403 free(_data->pRefs);
404 free(_data->pTruths[0]);
405 if (_data->pCare) free(_data->pCare);
406 if (_data->pProd) free(_data->pProd);
407 if (_data->pExc) free(_data->pExc);
408 if (_data->pLevel) free(_data->pLevel);
409 if (_data->pDist) free(_data->pDist);
410 if (_data->pTable) free(_data->pTable);
411 if (_data->pNtkMapped) Vi_Free(_data->pNtkMapped);
412 delete _data;
413 }
414 }
415
416 _data = nullptr;
417 _refcount = nullptr;
418}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rewire()

Miaig Rewire::Miaig::rewire ( int nIters,
float levelGrowRatio,
int nExpands,
int nGrowth,
int nDivs,
int nFaninMax,
int nTimeOut,
int nMode,
int nMappedMode,
int nDist,
int fCheck,
Gia_ChMan_t * pChMan,
int nVerbose )

Definition at line 1241 of file rewire_miaig.cpp.

1241 {
1242 const int nRootSave = 8;
1243 const int nBestSave = 4;
1244 int nRestart = 5000;
1245 std::vector<Miaig> pRoots = {this->dup(0)};
1246 std::vector<Miaig> pBests = {this->dup(0)}; Miaig pInit = pBests[0];
1247 iword clkStart = Time_Clock();
1248 Miaig pNew;
1249 Miaig pRoot = pRoots[0];
1250 Miaig pBest = this->dup(0); int improved = 0;
1251 float (Miaig::*Miaig_ObjectiveFunction)(int, int) = (nMode == 0) ? &Miaig::countAnd2 : &Miaig::countTransistors;
1252 int maxLevel = levelGrowRatio != 0 ? this->countLevel() * levelGrowRatio : 0;
1253 int nExpandableLevel = maxLevel ? maxLevel - this->countLevel() : 0;
1254 int fMapped = nMode > 0;
1255 word *pExc = _data->pExc;
1256
1257 float PrevBest = ((&pBest)->*Miaig_ObjectiveFunction)(1, nMappedMode);
1258 int iterNotImproveAfterRestart = 0;
1259 if (nVerbose && maxLevel) printf("Max level : %5d\n", maxLevel);
1260 if (nVerbose) printf("Initial target : %5g (AND2 = %5g Level = %3d)\n", PrevBest, this->countAnd2(1), this->countLevel());
1261 for (int i = 0; nIters ? i < nIters : 1; i++) {
1262 if (nVerbose) printf("\rIteration %7d(%zu) : %5g -> ", i + 1, pBests.size(), ((&pRoot)->*Miaig_ObjectiveFunction)(0, nMappedMode));
1263 if (nTimeOut && nTimeOut < 1.0 * (Time_Clock() - clkStart) / CLOCKS_PER_SEC) break;
1264 if (PrevBest == 0) break;
1265 pNew = pRoot.dupMulti(nFaninMax, nGrowth);
1266
1267 if (i % 2 == 0) {
1268 pNew = pNew.expandThenReduce(nGrowth, nDist, nExpandableLevel, pExc, fCheck, nVerbose > 1);
1269 }
1270 pNew = pNew.expandShareReduce(nExpands, nDivs, nDist, nExpandableLevel, pExc, fCheck, nVerbose > 1);
1271
1272 ++iterNotImproveAfterRestart;
1273 // report
1274 float rootTarget = ((&pRoot)->*Miaig_ObjectiveFunction)(0, nMappedMode);
1275 float newTarget = ((&pNew)->*Miaig_ObjectiveFunction)(1, nMappedMode);
1276 if (maxLevel ? pNew.countLevel() > maxLevel : 0) {
1277 } else if (PrevBest > newTarget) {
1278 if (nVerbose) printf("%5g (AND2 = %5g Level = %3d) ", newTarget, pNew.countAnd2(), pNew.countLevel());
1279 if (nVerbose) Time_PrintEndl("Elapsed time", Time_Clock() - clkStart);
1280 PrevBest = newTarget;
1281 pBests = {pNew.dup(0), pNew.dup(0)};
1282 pBest = pNew.dup(0, fMapped), improved = 1;
1283 iterNotImproveAfterRestart = 0;
1284 } else if (PrevBest == newTarget) {
1285 randomAddBest(pBests, pNew.dup(0), nBestSave, pChMan);
1286 }
1287 // compare
1288 if (maxLevel ? pNew.countLevel() > maxLevel : 0) {
1289 } else if (rootTarget < newTarget) {
1290 if (iterNotImproveAfterRestart > nRestart) {
1291 pNew = randomRead(pBests).dupMulti(nFaninMax, nGrowth);
1292 pNew = pNew.expand(nExpands, nDist, nExpandableLevel, pExc, fCheck, nVerbose > 1);
1293 pNew = pNew.share(nDivs == -1 ? pNew.nObjs() : nDivs);
1294 pNew = pNew.dupStrash(1, 1, 0);
1295 pRoots = {pNew};
1296 iterNotImproveAfterRestart = 0;
1297 } else if (rootTarget * 1.05 > newTarget) {
1298 pRoots = {pNew};
1299 }
1300 } else if (rootTarget == newTarget) {
1301 randomAddBest(pRoots, pNew, nRootSave, pChMan);
1302 } else {
1303 pRoots = {pNew};
1304 }
1305 pRoot = randomRead(pRoots);
1306 }
1307 if (nVerbose) Time_PrintEndl("Total solving time", Time_Clock() - clkStart);
1308 return improved ? pBest : randomReadExcept(pBests, pInit);
1309}
ABC_INT64_T iword
Definition abc_global.h:244
Miaig dup(int fRemDangle, int fMapped=0)
Miaig share(int nNewNodesMax)
int countLevel(int min=0)
Miaig expand(int nFaninAddLimitAll, int nDist, int nExpandableLevel, word *pExc, int fCheck, int nVerbose)
Miaig dupMulti(int nFaninMax_, int nGrowth)
float countTransistors(int reset=0, int nMode=0)
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
Miaig randomRead(std::vector< Miaig > &pBests)
void randomAddBest(std::vector< Miaig > &pBests, Miaig pNew, int nBestSave, Gia_ChMan_t *pChMan)
Miaig randomReadExcept(std::vector< Miaig > &pBests, Miaig &pExcept)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setExc()

void Rewire::Miaig::setExc ( Gia_Man_t * pExc)

Definition at line 252 of file rewire_miaig.cpp.

252 {
253 int i;
254 assert(Gia_ManCiNum(pExc) == nIns());
255 assert(Gia_ManCoNum(pExc) == nOuts() || Gia_ManCoNum(pExc) == 1);
256 if (Gia_ManCoNum(pExc) != nOuts() && Gia_ManCoNum(pExc) == 1) {
257 printf("[Warning] The external careset has only a single output that will be applied to all other outputs.\n");
258 }
259 if (!_data->pExc) {
260 _data->pExc = (word *)malloc(sizeof(word) * nWords() * nOuts());
261 }
262 Miaig Exc(pExc);
263 Exc.initializeTruth();
264 for (i = 0; i < nOuts(); ++i) {
265 word *tExc = Exc.objTruth(Exc.nObjs() - Exc.nOuts() + std::min(i, Gia_ManCoNum(pExc)-1), 0);
266 Tt_Dup(_data->pExc + nWords() * i, tExc, nWords());
267 }
268}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setName()

void Rewire::Miaig::setName ( char * pName)

Definition at line 103 of file rewire_miaig.cpp.

103 {
104 if (_data) {
105 if (_data->pName) {
106 free(_data->pName);
107 }
108 if (pName == NULL || pName[0] == '\0') {
109 _data->pName = strdup("rewire_miaig");
110 } else {
111 _data->pName = strdup(pName);
112 }
113 }
114}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ share()

Miaig Rewire::Miaig::share ( int nNewNodesMax)

Definition at line 1166 of file rewire_miaig.cpp.

1166 {
1167 Miaig pCopy = dup(0);
1168 int nNewNodes = pCopy.findShared(nNewNodesMax);
1169 if (nNewNodes == 0)
1170 return pCopy;
1171 // temporarily create "hidden" nodes for DFS duplicator
1172 pCopy.nObjs() -= nNewNodes;
1173 Miaig pNew = pCopy.dupDfs();
1174 pCopy.nObjs() += nNewNodes;
1175 return pNew;
1176}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toGia()

Gia_Man_t * Rewire::Miaig::toGia ( void )

Definition at line 178 of file rewire_miaig.cpp.

178 {
179 int i, k, iLit, And2 = countAnd2();
180 Gia_Man_t *pGia = Gia_ManStart(1 + nIns() + And2 + nOuts()), *pTemp;
181 pGia->pName = Abc_UtilStrsav(_data->pName);
182 Gia_ManHashAlloc(pGia);
183 memset(_data->pCopy, 0, sizeof(int) * nObjs());
185 objCopy(i) = Gia_ManAppendCi(pGia);
187 assert(objFaninNum(i) > 0);
188 Miaig_ForEachObjFanin(i, iLit, k) {
189 if (k == 0)
190 objCopy(i) = Rw_Lit2LitL(_data->pCopy, iLit);
191 else
192 objCopy(i) = Gia_ManHashAnd(pGia, objCopy(i), Rw_Lit2LitL(_data->pCopy, iLit));
193 }
194 }
196 assert(objFaninNum(i) == 1);
197 Miaig_ForEachObjFanin(i, iLit, k)
198 Gia_ManAppendCo(pGia, Rw_Lit2LitL(_data->pCopy, iLit));
199 }
200 // assert(Gia_ManObjNum(pGia) == (1 + nIns() + nOuts() + And2));
201 pGia = Gia_ManCleanup(pTemp = pGia);
202 Gia_ManStop(pTemp);
203 return pGia;
204}
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
char * Abc_UtilStrsav(char *s)
Definition starter.c:47
char * pName
Definition gia.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toMiniAig()

Mini_Aig_t * Rewire::Miaig::toMiniAig ( void )

Definition at line 206 of file rewire_miaig.cpp.

206 {
207 int i, k, iLit;
208 Mini_Aig_t * pMini = Mini_AigStart();
209 memset(_data->pCopy, 0, sizeof(int) * nObjs());
211 objCopy(i) = Mini_AigCreatePi(pMini);
213 assert(objFaninNum(i) > 0);
214 Miaig_ForEachObjFanin(i, iLit, k)
215 if (k == 0)
216 objCopy(i) = Rw_Lit2LitL(_data->pCopy, iLit);
217 else
218 objCopy(i) = Mini_AigAnd(pMini, objCopy(i), Rw_Lit2LitL(_data->pCopy, iLit));
219 }
221 assert(objFaninNum(i) == 1);
222 Miaig_ForEachObjFanin(i, iLit, k)
223 Mini_AigCreatePo(pMini, Rw_Lit2LitL(_data->pCopy, iLit));
224 }
225 assert(pMini->nSize == 2 * (1 + nIns() + nOuts() + countAnd2()));
226 return pMini;
227}
int nSize
Definition miniaig.h:52
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toNtk()

Abc_Ntk_t * Rewire::Miaig::toNtk ( int fMapped = 0)

Definition at line 229 of file rewire_miaig.cpp.

229 {
230 Abc_Ntk_t *pNtk;
231 if (_data->pNtkMapped && fMapped) {
232 pNtk = Abc_ManRewireNtkFromMiniMapping(Vi_Array(_data->pNtkMapped));
233 ABC_FREE(pNtk->pName);
234 Abc_NtkSetName(pNtk, Abc_UtilStrsav(_data->pName));
235 return pNtk;
236 }
237 Gia_Man_t *pGia = toGia();
238 pNtk = Gia_ManRewirePut(pGia);
239 Gia_ManStop(pGia);
240 return pNtk;
241}
#define ABC_FREE(obj)
Definition abc_global.h:267
Abc_Ntk_t * Abc_ManRewireNtkFromMiniMapping(int *vMapping)
Definition rewire_map.c:82
Abc_Ntk_t * Gia_ManRewirePut(Gia_Man_t *pGia)
Definition rewire_map.c:38
char * pName
Definition abc.h:158
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: