ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcRefactor.c File Reference
#include "base/abc/abc.h"
#include "bool/dec/dec.h"
#include "bool/kit/kit.h"
Include dependency graph for abcRefactor.c:

Go to the source code of this file.

Classes

struct  Abc_ManRef_t_
 

Typedefs

typedef typedefABC_NAMESPACE_IMPL_START struct Abc_ManRef_t_ Abc_ManRef_t
 DECLARATIONS ///.
 

Functions

wordAbc_NodeConeTruth (Vec_Ptr_t *vVars, Vec_Ptr_t *vFuncs, int nWordsMax, Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVisited)
 FUNCTION DEFINITIONS ///.
 
int Abc_NodeConeIsConst0 (word *pTruth, int nVars)
 
int Abc_NodeConeIsConst1 (word *pTruth, int nVars)
 
Dec_Graph_tAbc_NodeRefactor (Abc_ManRef_t *p, Abc_Obj_t *pNode, Vec_Ptr_t *vFanins, int nMinSaved, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose)
 
Abc_ManRef_tAbc_NtkManRefStart (int nNodeSizeMax, int nConeSizeMax, int fUseDcs, int fVerbose)
 
void Abc_NtkManRefStop (Abc_ManRef_t *p)
 
void Abc_NtkManRefPrintStats (Abc_ManRef_t *p)
 
int Abc_NtkRefactor (Abc_Ntk_t *pNtk, int nNodeSizeMax, int nMinSaved, int nConeSizeMax, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose)
 DECLARATIONS ///.
 

Typedef Documentation

◆ Abc_ManRef_t

typedef typedefABC_NAMESPACE_IMPL_START struct Abc_ManRef_t_ Abc_ManRef_t

DECLARATIONS ///.

CFile****************************************************************

FileName [abcRefactor.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Resynthesis based on collapsing and refactoring.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
abcRefactor.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 32 of file abcRefactor.c.

Function Documentation

◆ Abc_NodeConeIsConst0()

int Abc_NodeConeIsConst0 ( word * pTruth,
int nVars )

Definition at line 123 of file abcRefactor.c.

124{
125 int k, nWords = Abc_Truth6WordNum( nVars );
126 for ( k = 0; k < nWords; k++ )
127 if ( pTruth[k] )
128 return 0;
129 return 1;
130}
int nWords
Definition abcNpn.c:127
Here is the caller graph for this function:

◆ Abc_NodeConeIsConst1()

int Abc_NodeConeIsConst1 ( word * pTruth,
int nVars )

Definition at line 131 of file abcRefactor.c.

132{
133 int k, nWords = Abc_Truth6WordNum( nVars );
134 for ( k = 0; k < nWords; k++ )
135 if ( ~pTruth[k] )
136 return 0;
137 return 1;
138}
Here is the caller graph for this function:

◆ Abc_NodeConeTruth()

word * Abc_NodeConeTruth ( Vec_Ptr_t * vVars,
Vec_Ptr_t * vFuncs,
int nWordsMax,
Abc_Obj_t * pRoot,
Vec_Ptr_t * vLeaves,
Vec_Ptr_t * vVisited )

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Returns function of the cone.]

Description []

SideEffects []

SeeAlso []

Definition at line 81 of file abcRefactor.c.

82{
83 Abc_Obj_t * pNode;
84 word * pTruth0, * pTruth1, * pTruth = NULL;
85 int i, k, nWords = Abc_Truth6WordNum( Vec_PtrSize(vLeaves) );
86 // get nodes in the cut without fanins in the DFS order
87 Abc_NodeConeCollect( &pRoot, 1, vLeaves, vVisited, 0 );
88 // set elementary functions
89 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pNode, i )
90 pNode->pCopy = (Abc_Obj_t *)Vec_PtrEntry( vVars, i );
91 // prepare functions
92 for ( i = Vec_PtrSize(vFuncs); i < Vec_PtrSize(vVisited); i++ )
93 Vec_PtrPush( vFuncs, ABC_ALLOC(word, nWordsMax) );
94 // compute functions for the collected nodes
95 Vec_PtrForEachEntry( Abc_Obj_t *, vVisited, pNode, i )
96 {
97 assert( !Abc_ObjIsPi(pNode) );
98 pTruth0 = (word *)Abc_ObjFanin0(pNode)->pCopy;
99 pTruth1 = (word *)Abc_ObjFanin1(pNode)->pCopy;
100 pTruth = (word *)Vec_PtrEntry( vFuncs, i );
101 if ( Abc_ObjFaninC0(pNode) )
102 {
103 if ( Abc_ObjFaninC1(pNode) )
104 for ( k = 0; k < nWords; k++ )
105 pTruth[k] = ~pTruth0[k] & ~pTruth1[k];
106 else
107 for ( k = 0; k < nWords; k++ )
108 pTruth[k] = ~pTruth0[k] & pTruth1[k];
109 }
110 else
111 {
112 if ( Abc_ObjFaninC1(pNode) )
113 for ( k = 0; k < nWords; k++ )
114 pTruth[k] = pTruth0[k] & ~pTruth1[k];
115 else
116 for ( k = 0; k < nWords; k++ )
117 pTruth[k] = pTruth0[k] & pTruth1[k];
118 }
119 pNode->pCopy = (Abc_Obj_t *)pTruth;
120 }
121 return pTruth;
122}
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL void Abc_NodeConeCollect(Abc_Obj_t **ppRoots, int nRoots, Vec_Ptr_t *vFanins, Vec_Ptr_t *vVisited, int fIncludeFanins)
Definition abcReconv.c:444
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
Abc_Obj_t * pCopy
Definition abc.h:148
#define assert(ex)
Definition util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NodeRefactor()

Dec_Graph_t * Abc_NodeRefactor ( Abc_ManRef_t * p,
Abc_Obj_t * pNode,
Vec_Ptr_t * vFanins,
int nMinSaved,
int fUpdateLevel,
int fUseZeros,
int fUseDcs,
int fVerbose )

Function*************************************************************

Synopsis [Resynthesizes the node using refactoring.]

Description []

SideEffects []

SeeAlso []

Definition at line 152 of file abcRefactor.c.

153{
154 extern int Dec_GraphToNetworkCount( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMax, int LevelMax );
155 int fVeryVerbose = 0;
156 int nVars = Vec_PtrSize(vFanins);
157 int nWordsMax = Abc_Truth6WordNum(p->nNodeSizeMax);
158 Dec_Graph_t * pFForm;
159 Abc_Obj_t * pFanin;
160 word * pTruth;
161 abctime clk;
162 int i, nNodesSaved, nNodesAdded, Required;
163 if ( fUseZeros )
164 nMinSaved = 0;
165
166 p->nNodesConsidered++;
167
168 Required = fUpdateLevel? Abc_ObjRequiredLevel(pNode) : ABC_INFINITY;
169
170 // get the function of the cut
171clk = Abc_Clock();
172 pTruth = Abc_NodeConeTruth( p->vVars, p->vFuncs, nWordsMax, pNode, vFanins, p->vVisited );
173p->timeTru += Abc_Clock() - clk;
174 if ( pTruth == NULL )
175 return NULL;
176
177 // always accept the case of constant node
178 if ( Abc_NodeConeIsConst0(pTruth, nVars) || Abc_NodeConeIsConst1(pTruth, nVars) )
179 {
180 p->nLastGain = Abc_NodeMffcSize( pNode );
181 p->nNodesGained += p->nLastGain;
182 p->nNodesRefactored++;
183 return Abc_NodeConeIsConst0(pTruth, nVars) ? Dec_GraphCreateConst0() : Dec_GraphCreateConst1();
184 }
185
186 // get the factored form
187clk = Abc_Clock();
188 pFForm = (Dec_Graph_t *)Kit_TruthToGraph( (unsigned *)pTruth, nVars, p->vMemory );
189p->timeFact += Abc_Clock() - clk;
190
191 // mark the fanin boundary
192 // (can mark only essential fanins, belonging to bNodeFunc!)
193 Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pFanin, i )
194 pFanin->vFanouts.nSize++;
195 // label MFFC with current traversal ID
196 Abc_NtkIncrementTravId( pNode->pNtk );
197 nNodesSaved = Abc_NodeMffcLabelAig( pNode );
198 // unmark the fanin boundary and set the fanins as leaves in the form
199 Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pFanin, i )
200 {
201 pFanin->vFanouts.nSize--;
202 Dec_GraphNode(pFForm, i)->pFunc = pFanin;
203 }
204
205 // detect how many new nodes will be added (while taking into account reused nodes)
206clk = Abc_Clock();
207 nNodesAdded = Dec_GraphToNetworkCount( pNode, pFForm, nNodesSaved, Required );
208p->timeEval += Abc_Clock() - clk;
209 // quit if there is no improvement
210 //if ( nNodesAdded == -1 || (nNodesAdded == nNodesSaved && !fUseZeros) )
211 if ( nNodesAdded == -1 || nNodesSaved - nNodesAdded < nMinSaved )
212 {
213 Dec_GraphFree( pFForm );
214 return NULL;
215 }
216
217 // compute the total gain in the number of nodes
218 p->nLastGain = nNodesSaved - nNodesAdded;
219 p->nNodesGained += p->nLastGain;
220 p->nNodesRefactored++;
221
222 // report the progress
223 if ( fVeryVerbose )
224 {
225 printf( "Node %6s : ", Abc_ObjName(pNode) );
226 printf( "Cone = %2d. ", vFanins->nSize );
227 printf( "FF = %2d. ", 1 + Dec_GraphNodeNum(pFForm) );
228 printf( "MFFC = %2d. ", nNodesSaved );
229 printf( "Add = %2d. ", nNodesAdded );
230 printf( "GAIN = %2d. ", p->nLastGain );
231 printf( "\n" );
232 }
233 return pFForm;
234}
int Abc_NodeConeIsConst0(word *pTruth, int nVars)
word * Abc_NodeConeTruth(Vec_Ptr_t *vVars, Vec_Ptr_t *vFuncs, int nWordsMax, Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVisited)
FUNCTION DEFINITIONS ///.
Definition abcRefactor.c:81
int Abc_NodeConeIsConst1(word *pTruth, int nVars)
ABC_DLL int Abc_NodeMffcSize(Abc_Obj_t *pNode)
FUNCTION DEFINITIONS ///.
Definition abcRefs.c:48
ABC_DLL int Abc_ObjRequiredLevel(Abc_Obj_t *pObj)
Definition abcTiming.c:1214
ABC_DLL int Abc_NodeMffcLabelAig(Abc_Obj_t *pNode)
Definition abcRefs.c:100
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
int Dec_GraphToNetworkCount(Abc_Obj_t *pRoot, Dec_Graph_t *pGraph, int NodeMax, int LevelMax)
Definition decAbc.c:167
struct Dec_Graph_t_ Dec_Graph_t
Definition dec.h:68
Cube * p
Definition exorList.c:222
Kit_Graph_t * Kit_TruthToGraph(unsigned *pTruth, int nVars, Vec_Int_t *vMemory)
Definition kitGraph.c:356
Abc_Ntk_t * pNtk
Definition abc.h:130
Vec_Int_t vFanouts
Definition abc.h:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkManRefPrintStats()

void Abc_NtkManRefPrintStats ( Abc_ManRef_t * p)

Function*************************************************************

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 296 of file abcRefactor.c.

297{
298 printf( "Refactoring statistics:\n" );
299 printf( "Nodes considered = %8d.\n", p->nNodesConsidered );
300 printf( "Nodes refactored = %8d.\n", p->nNodesRefactored );
301 printf( "Gain = %8d. (%6.2f %%).\n", p->nNodesBeg-p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/p->nNodesBeg );
302 ABC_PRT( "Cuts ", p->timeCut );
303 ABC_PRT( "Resynthesis", p->timeRes );
304 ABC_PRT( " BDD ", p->timeTru );
305 ABC_PRT( " DCs ", p->timeDcs );
306 ABC_PRT( " SOP ", p->timeSop );
307 ABC_PRT( " FF ", p->timeFact );
308 ABC_PRT( " Eval ", p->timeEval );
309 ABC_PRT( "AIG update ", p->timeNtk );
310 ABC_PRT( "TOTAL ", p->timeTotal );
311}
#define ABC_PRT(a, t)
Definition abc_global.h:255
Here is the caller graph for this function:

◆ Abc_NtkManRefStart()

Abc_ManRef_t * Abc_NtkManRefStart ( int nNodeSizeMax,
int nConeSizeMax,
int fUseDcs,
int fVerbose )

Function*************************************************************

Synopsis [Starts the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 248 of file abcRefactor.c.

249{
250 Abc_ManRef_t * p;
251 p = ABC_ALLOC( Abc_ManRef_t, 1 );
252 memset( p, 0, sizeof(Abc_ManRef_t) );
253 p->vCube = Vec_StrAlloc( 100 );
254 p->vVisited = Vec_PtrAlloc( 100 );
255 p->nNodeSizeMax = nNodeSizeMax;
256 p->nConeSizeMax = nConeSizeMax;
257 p->fVerbose = fVerbose;
258 p->vVars = Vec_PtrAllocTruthTables( Abc_MaxInt(nNodeSizeMax, 6) );
259 p->vFuncs = Vec_PtrAlloc( 100 );
260 p->vMemory = Vec_IntAlloc( 1 << 16 );
261 return p;
262}
struct Abc_ManRef_t_ Abc_ManRef_t
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkManRefStop()

void Abc_NtkManRefStop ( Abc_ManRef_t * p)

Function*************************************************************

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 275 of file abcRefactor.c.

276{
277 Vec_PtrFreeFree( p->vFuncs );
278 Vec_PtrFree( p->vVars );
279 Vec_IntFree( p->vMemory );
280 Vec_PtrFree( p->vVisited );
281 Vec_StrFree( p->vCube );
282 ABC_FREE( p );
283}
#define ABC_FREE(obj)
Definition abc_global.h:267
Here is the caller graph for this function:

◆ Abc_NtkRefactor()

int Abc_NtkRefactor ( Abc_Ntk_t * pNtk,
int nNodeSizeMax,
int nMinSaved,
int nConeSizeMax,
int fUpdateLevel,
int fUseZeros,
int fUseDcs,
int fVerbose )

DECLARATIONS ///.

Function*************************************************************

Synopsis [Performs incremental resynthesis of the AIG.]

Description [Starting from each node, computes a reconvergence-driven cut, derives BDD of the cut function, constructs ISOP, factors the ISOP, and replaces the current implementation of the MFFC of the node by the new factored form, if the number of AIG nodes is reduced and the total number of levels of the AIG network is not increated. Returns the number of AIG nodes saved.]

SideEffects []

SeeAlso []

Definition at line 329 of file abcRefactor.c.

330{
331 extern int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
332 ProgressBar * pProgress;
333 Abc_ManRef_t * pManRef;
334 Abc_ManCut_t * pManCut;
335 Dec_Graph_t * pFForm;
336 Vec_Ptr_t * vFanins;
337 Abc_Obj_t * pNode;
338 abctime clk, clkStart = Abc_Clock();
339 int i, nNodes, RetValue = 1;
340
341 assert( Abc_NtkIsStrash(pNtk) );
342 // cleanup the AIG
344 // start the managers
345 pManCut = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, 1000 );
346 pManRef = Abc_NtkManRefStart( nNodeSizeMax, nConeSizeMax, fUseDcs, fVerbose );
347 pManRef->vLeaves = Abc_NtkManCutReadCutLarge( pManCut );
348 // compute the reverse levels if level update is requested
349 if ( fUpdateLevel )
350 Abc_NtkStartReverseLevels( pNtk, 0 );
351
352 // resynthesize each node once
353 pManRef->nNodesBeg = Abc_NtkNodeNum(pNtk);
354 nNodes = Abc_NtkObjNumMax(pNtk);
355 pProgress = Extra_ProgressBarStart( stdout, nNodes );
356 Abc_NtkForEachNode( pNtk, pNode, i )
357 {
358 Extra_ProgressBarUpdate( pProgress, i, NULL );
359 // skip the constant node
360// if ( Abc_NodeIsConst(pNode) )
361// continue;
362 // skip persistant nodes
363 if ( Abc_NodeIsPersistant(pNode) )
364 continue;
365 // skip the nodes with many fanouts
366 if ( Abc_ObjFanoutNum(pNode) > 1000 )
367 continue;
368 // stop if all nodes have been tried once
369 if ( i >= nNodes )
370 break;
371 // compute a reconvergence-driven cut
372clk = Abc_Clock();
373 vFanins = Abc_NodeFindCut( pManCut, pNode, fUseDcs );
374pManRef->timeCut += Abc_Clock() - clk;
375 // evaluate this cut
376clk = Abc_Clock();
377 pFForm = Abc_NodeRefactor( pManRef, pNode, vFanins, nMinSaved, fUpdateLevel, fUseZeros, fUseDcs, fVerbose );
378pManRef->timeRes += Abc_Clock() - clk;
379 if ( pFForm == NULL )
380 continue;
381 // acceptable replacement found, update the graph
382clk = Abc_Clock();
383 if ( !Dec_GraphUpdateNetwork( pNode, pFForm, fUpdateLevel, pManRef->nLastGain ) )
384 {
385 Dec_GraphFree( pFForm );
386 RetValue = -1;
387 break;
388 }
389pManRef->timeNtk += Abc_Clock() - clk;
390 Dec_GraphFree( pFForm );
391 }
392 Extra_ProgressBarStop( pProgress );
393pManRef->timeTotal = Abc_Clock() - clkStart;
394 pManRef->nNodesEnd = Abc_NtkNodeNum(pNtk);
395
396 // print statistics of the manager
397 if ( fVerbose )
398 Abc_NtkManRefPrintStats( pManRef );
399 // delete the managers
400 Abc_NtkManCutStop( pManCut );
401 Abc_NtkManRefStop( pManRef );
402 // put the nodes into the DFS order and reassign their IDs
403 Abc_NtkReassignIds( pNtk );
404// Abc_AigCheckFaninOrder( pNtk->pManFunc );
405 if ( RetValue != -1 )
406 {
407 // fix the levels
408 if ( fUpdateLevel )
410 else
411 Abc_NtkLevel( pNtk );
412 // check
413 if ( !Abc_NtkCheck( pNtk ) )
414 {
415 printf( "Abc_NtkRefactor: The network check has failed.\n" );
416 return 0;
417 }
418 }
419 return RetValue;
420}
int Dec_GraphUpdateNetwork(Abc_Obj_t *pRoot, Dec_Graph_t *pGraph, int fUpdateLevel, int nGain)
Definition decAbc.c:240
Dec_Graph_t * Abc_NodeRefactor(Abc_ManRef_t *p, Abc_Obj_t *pNode, Vec_Ptr_t *vFanins, int nMinSaved, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose)
void Abc_NtkManRefStop(Abc_ManRef_t *p)
Abc_ManRef_t * Abc_NtkManRefStart(int nNodeSizeMax, int nConeSizeMax, int fUseDcs, int fVerbose)
void Abc_NtkManRefPrintStats(Abc_ManRef_t *p)
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
struct Abc_ManCut_t_ Abc_ManCut_t
Definition abc.h:119
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
ABC_DLL void Abc_NtkManCutStop(Abc_ManCut_t *p)
Definition abcReconv.c:623
ABC_DLL void Abc_NtkStopReverseLevels(Abc_Ntk_t *pNtk)
Definition abcTiming.c:1302
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition abcDfs.c:1449
ABC_DLL Vec_Ptr_t * Abc_NodeFindCut(Abc_ManCut_t *p, Abc_Obj_t *pRoot, int fContain)
Definition abcReconv.c:256
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
Definition abcAig.c:194
ABC_DLL void Abc_NtkStartReverseLevels(Abc_Ntk_t *pNtk, int nMaxLevelIncrease)
Definition abcTiming.c:1274
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadCutLarge(Abc_ManCut_t *p)
Definition abcReconv.c:644
ABC_DLL void Abc_NtkReassignIds(Abc_Ntk_t *pNtk)
Definition abcUtil.c:1809
ABC_DLL Abc_ManCut_t * Abc_NtkManCutStart(int nNodeSizeMax, int nConeSizeMax, int nNodeFanStop, int nConeFanStop)
Definition abcReconv.c:595
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
void Extra_ProgressBarStop(ProgressBar *p)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
Vec_Ptr_t * vLeaves
void * pManFunc
Definition abc.h:191
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
Here is the call graph for this function:
Here is the caller graph for this function: