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

Go to the source code of this file.

Functions

void Abc_PlaceBegin (Abc_Ntk_t *pNtk)
 
void Abc_PlaceEnd (Abc_Ntk_t *pNtk)
 
void Abc_PlaceUpdate (Vec_Ptr_t *vAddedCells, Vec_Ptr_t *vUpdatedNets)
 
int Abc_NtkRewrite (Abc_Ntk_t *pNtk, int fUpdateLevel, int fUseZeros, int fVerbose, int fVeryVerbose, int fPlaceEnable)
 FUNCTION DEFINITIONS ///.
 
void Abc_ManRewritePrintDivs (Vec_Ptr_t *vDivs, int nLeaves)
 
void Abc_ManShowCutCone_rec (Abc_Obj_t *pNode, Vec_Ptr_t *vDivs)
 
void Abc_RwrExpWithCut_rec (Abc_Obj_t *pNode, Vec_Ptr_t *vLeaves, int fUseA)
 
void Abc_RwrExpWithCut (Abc_Obj_t *pNode, Vec_Ptr_t *vLeaves)
 

Function Documentation

◆ Abc_ManRewritePrintDivs()

void Abc_ManRewritePrintDivs ( Vec_Ptr_t * vDivs,
int nLeaves )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 276 of file abcRewrite.c.

277{
278 Abc_Obj_t * pFanin, * pNode, * pRoot;
279 int i, k;
280 pRoot = (Abc_Obj_t *)Vec_PtrEntryLast(vDivs);
281 // print the nodes
282 Vec_PtrForEachEntry( Abc_Obj_t *, vDivs, pNode, i )
283 {
284 if ( i < nLeaves )
285 {
286 printf( "%6d : %c\n", pNode->Id, 'a'+i );
287 continue;
288 }
289 printf( "%6d : %2d = ", pNode->Id, i );
290 // find the first fanin
291 Vec_PtrForEachEntry( Abc_Obj_t *, vDivs, pFanin, k )
292 if ( Abc_ObjFanin0(pNode) == pFanin )
293 break;
294 if ( k < nLeaves )
295 printf( "%c", 'a' + k );
296 else
297 printf( "%d", k );
298 printf( "%s ", Abc_ObjFaninC0(pNode)? "\'" : "" );
299 // find the second fanin
300 Vec_PtrForEachEntry( Abc_Obj_t *, vDivs, pFanin, k )
301 if ( Abc_ObjFanin1(pNode) == pFanin )
302 break;
303 if ( k < nLeaves )
304 printf( "%c", 'a' + k );
305 else
306 printf( "%d", k );
307 printf( "%s ", Abc_ObjFaninC1(pNode)? "\'" : "" );
308 if ( pNode == pRoot )
309 printf( " root" );
310 printf( "\n" );
311 }
312 printf( "\n" );
313}
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
int Id
Definition abc.h:132
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
Here is the caller graph for this function:

◆ Abc_ManShowCutCone_rec()

void Abc_ManShowCutCone_rec ( Abc_Obj_t * pNode,
Vec_Ptr_t * vDivs )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 326 of file abcRewrite.c.

327{
328 if ( Abc_NodeIsTravIdCurrent(pNode) )
329 return;
330 Abc_NodeSetTravIdCurrent(pNode);
331 Abc_ManShowCutCone_rec( Abc_ObjFanin0(pNode), vDivs );
332 Abc_ManShowCutCone_rec( Abc_ObjFanin1(pNode), vDivs );
333 Vec_PtrPush( vDivs, pNode );
334}
void Abc_ManShowCutCone_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vDivs)
Definition abcRewrite.c:326
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkRewrite()

int Abc_NtkRewrite ( Abc_Ntk_t * pNtk,
int fUpdateLevel,
int fUseZeros,
int fVerbose,
int fVeryVerbose,
int fPlaceEnable )

FUNCTION DEFINITIONS ///.

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

Synopsis [Performs incremental rewriting of the AIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 61 of file abcRewrite.c.

62{
63 extern int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
64 ProgressBar * pProgress;
65 Cut_Man_t * pManCut;
66 Rwr_Man_t * pManRwr;
67 Abc_Obj_t * pNode;
68// Vec_Ptr_t * vAddedCells = NULL, * vUpdatedNets = NULL;
69 Dec_Graph_t * pGraph;
70 int i, nNodes, nGain, fCompl, RetValue = 1;
71 abctime clk, clkStart = Abc_Clock();
72
73 assert( Abc_NtkIsStrash(pNtk) );
74 // cleanup the AIG
76/*
77 {
78 Vec_Vec_t * vParts;
79 vParts = Abc_NtkPartitionSmart( pNtk, 50, 1 );
80 Vec_VecFree( vParts );
81 }
82*/
83
84 // start placement package
85// if ( fPlaceEnable )
86// {
87// Abc_PlaceBegin( pNtk );
88// vAddedCells = Abc_AigUpdateStart( pNtk->pManFunc, &vUpdatedNets );
89// }
90
91 // start the rewriting manager
92 pManRwr = Rwr_ManStart( 0 );
93 if ( pManRwr == NULL )
94 return 0;
95 // compute the reverse levels if level update is requested
96 if ( fUpdateLevel )
98 // start the cut manager
99clk = Abc_Clock();
100 pManCut = Abc_NtkStartCutManForRewrite( pNtk );
101Rwr_ManAddTimeCuts( pManRwr, Abc_Clock() - clk );
102 pNtk->pManCut = pManCut;
103
104 if ( fVeryVerbose )
105 Rwr_ScoresClean( pManRwr );
106
107 // resynthesize each node once
108 pManRwr->nNodesBeg = Abc_NtkNodeNum(pNtk);
109 nNodes = Abc_NtkObjNumMax(pNtk);
110 pProgress = Extra_ProgressBarStart( stdout, nNodes );
111 Abc_NtkForEachNode( pNtk, pNode, i )
112 {
113 Extra_ProgressBarUpdate( pProgress, i, NULL );
114 // stop if all nodes have been tried once
115 if ( i >= nNodes )
116 break;
117 // skip persistant nodes
118 if ( Abc_NodeIsPersistant(pNode) )
119 continue;
120 // skip the nodes with many fanouts
121 if ( Abc_ObjFanoutNum(pNode) > 1000 )
122 continue;
123
124 // for each cut, try to resynthesize it
125 nGain = Rwr_NodeRewrite( pManRwr, pManCut, pNode, fUpdateLevel, fUseZeros, fPlaceEnable );
126 if ( !(nGain > 0 || (nGain == 0 && fUseZeros)) )
127 continue;
128 // if we end up here, a rewriting step is accepted
129
130 // get hold of the new subgraph to be added to the AIG
131 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
132 fCompl = Rwr_ManReadCompl(pManRwr);
133
134 // reset the array of the changed nodes
135 if ( fPlaceEnable )
137
138 // complement the FF if needed
139 if ( fCompl ) Dec_GraphComplement( pGraph );
140clk = Abc_Clock();
141 if ( !Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain ) )
142 {
143 RetValue = -1;
144 break;
145 }
146Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
147 if ( fCompl ) Dec_GraphComplement( pGraph );
148
149 // use the array of changed nodes to update placement
150// if ( fPlaceEnable )
151// Abc_PlaceUpdate( vAddedCells, vUpdatedNets );
152 }
153 Extra_ProgressBarStop( pProgress );
154Rwr_ManAddTimeTotal( pManRwr, Abc_Clock() - clkStart );
155 // print stats
156 pManRwr->nNodesEnd = Abc_NtkNodeNum(pNtk);
157 if ( fVerbose )
158 Rwr_ManPrintStats( pManRwr );
159// Rwr_ManPrintStatsFile( pManRwr );
160 if ( fVeryVerbose )
161 Rwr_ScoresReport( pManRwr );
162 // delete the managers
163 Rwr_ManStop( pManRwr );
164 Cut_ManStop( pManCut );
165 pNtk->pManCut = NULL;
166
167 // start placement package
168// if ( fPlaceEnable )
169// {
170// Abc_PlaceEnd( pNtk );
171// Abc_AigUpdateStop( pNtk->pManFunc );
172// }
173
174 // put the nodes into the DFS order and reassign their IDs
175 {
176// abctime clk = Abc_Clock();
177 Abc_NtkReassignIds( pNtk );
178// ABC_PRT( "time", Abc_Clock() - clk );
179 }
180// Abc_AigCheckFaninOrder( pNtk->pManFunc );
181 // fix the levels
182 if ( RetValue >= 0 )
183 {
184 if ( fUpdateLevel )
186 else
187 Abc_NtkLevel( pNtk );
188 // check
189 if ( !Abc_NtkCheck( pNtk ) )
190 {
191 printf( "Abc_NtkRewrite: The network check has failed.\n" );
192 return 0;
193 }
194 }
195 return RetValue;
196}
int Dec_GraphUpdateNetwork(Abc_Obj_t *pRoot, Dec_Graph_t *pGraph, int fUpdateLevel, int nGain)
Definition decAbc.c:240
ABC_DLL void Abc_AigUpdateReset(Abc_Aig_t *pMan)
Definition abcAig.c:1477
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
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 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 void Abc_NtkReassignIds(Abc_Ntk_t *pNtk)
Definition abcUtil.c:1809
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
ABC_INT64_T abctime
Definition abc_global.h:332
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
struct Cut_ManStruct_t_ Cut_Man_t
BASIC TYPES ///.
Definition cut.h:48
void Cut_ManStop(Cut_Man_t *p)
Definition cutMan.c:124
struct Dec_Graph_t_ Dec_Graph_t
Definition dec.h:68
void Extra_ProgressBarStop(ProgressBar *p)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
void Rwr_ManAddTimeUpdate(Rwr_Man_t *p, abctime Time)
Definition rwrMan.c:277
Rwr_Man_t * Rwr_ManStart(int fPrecompute)
DECLARATIONS ///.
Definition rwrMan.c:47
void Rwr_ScoresClean(Rwr_Man_t *p)
Definition rwrEva.c:504
void Rwr_ManAddTimeCuts(Rwr_Man_t *p, abctime Time)
Definition rwrMan.c:261
void Rwr_ManAddTimeTotal(Rwr_Man_t *p, abctime Time)
Definition rwrMan.c:293
void Rwr_ScoresReport(Rwr_Man_t *p)
Definition rwrEva.c:550
int Rwr_ManReadCompl(Rwr_Man_t *p)
Definition rwrMan.c:245
void Rwr_ManPrintStats(Rwr_Man_t *p)
Definition rwrMan.c:143
struct Rwr_Man_t_ Rwr_Man_t
Definition rwr.h:47
void Rwr_ManStop(Rwr_Man_t *p)
Definition rwrMan.c:109
int Rwr_NodeRewrite(Rwr_Man_t *p, Cut_Man_t *pManCut, Abc_Obj_t *pNode, int fUpdateLevel, int fUseZeros, int fPlaceEnable)
FUNCTION DEFINITIONS ///.
Definition rwrEva.c:59
void * Rwr_ManReadDecs(Rwr_Man_t *p)
Definition rwrMan.c:213
void * pManFunc
Definition abc.h:191
void * pManCut
Definition abc.h:193
int nNodesBeg
Definition rwr.h:82
int nNodesEnd
Definition rwr.h:83
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_PlaceBegin()

void Abc_PlaceBegin ( Abc_Ntk_t * pNtk)
extern

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

Synopsis [This procedure is called before the writing start.]

Description []

SideEffects []

SeeAlso []

Definition at line 178 of file abcPlace.c.

179{
180 Abc_Obj_t * pObj;
181 int i;
182
183 // allocate and clean internal storage
184 nAllocSize = 5 * Abc_NtkObjNumMax(pNtk);
187 memset( cells, 0, sizeof(ConcreteCell) * nAllocSize );
188 memset( nets, 0, sizeof(ConcreteNet) * nAllocSize );
189
190 // create AbstractCells
191 // 1: pad
192 // 2: and
193 if (!abstractCells)
195
196 abstractCells[0].m_height = 1.0;
197 abstractCells[0].m_width = 1.0;
198 abstractCells[0].m_label = "pio";
199 abstractCells[0].m_pad = 1;
200
201 abstractCells[1].m_height = 1.0;
202 abstractCells[1].m_width = 1.0;
203 abstractCells[1].m_label = "and";
204 abstractCells[1].m_pad = 0;
205
206 // input pads
207 Abc_NtkForEachCi( pNtk, pObj, i )
208 Abc_PlaceCreateCell( pObj, 0 );
209
210 // ouput pads
211 Abc_NtkForEachCo( pNtk, pObj, i )
212 Abc_PlaceCreateCell( pObj, 0 );
213
214 // AND nodes
215 Abc_AigForEachAnd( pNtk, pObj, i )
216 Abc_PlaceCreateCell( pObj, 1 );
217
218 // all nets
219 Abc_NtkForEachObj( pNtk, pObj, i )
220 {
221 if ( !Abc_ObjIsCi(pObj) && !Abc_ObjIsNode(pObj) )
222 continue;
223 Abc_PlaceUpdateNet( pObj );
224 }
225
226 globalPreplace((float)0.8);
227 globalPlace();
228}
ABC_NAMESPACE_IMPL_START AbstractCell * abstractCells
DECLARATIONS ///.
Definition abcPlace.c:33
int nAllocSize
Definition abcPlace.c:36
ConcreteNet * nets
Definition abcPlace.c:35
ConcreteCell * cells
Definition abcPlace.c:34
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
#define Abc_AigForEachAnd(pNtk, pNode, i)
Definition abc.h:488
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
#define ALLOC(type, num)
Definition avl.h:27
#define REALLOC(type, obj, num)
Definition avl.h:29
void globalPreplace(float utilization)
Place pad ring, leaving a core area to meet a desired utilization.
Definition place_pads.c:31
void globalPlace()
Performs analytic placement using a GORDIAN-like algorithm.
char * memset()

◆ Abc_PlaceEnd()

void Abc_PlaceEnd ( Abc_Ntk_t * pNtk)
extern

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

Synopsis [This procedure is called after the writing completes.]

Description []

SideEffects []

SeeAlso []

Definition at line 241 of file abcPlace.c.

242{
243 int i;
244
245
246 // clean up
247 for ( i = 0; i < nAllocSize; i++ )
248 FREE( nets[i].m_terms );
250 FREE( cells );
251 FREE( nets );
252}
#define FREE(obj)
Definition avl.h:31

◆ Abc_PlaceUpdate()

void Abc_PlaceUpdate ( Vec_Ptr_t * vAddedCells,
Vec_Ptr_t * vUpdatedNets )
extern

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

Synopsis [Updates placement after one step of rewriting.]

Description []

SideEffects []

SeeAlso []

Definition at line 126 of file abcPlace.c.

127{
128 Abc_Obj_t * pObj, * pFanin;
129 int i, k;
130 Vec_Ptr_t * vCells, * vNets;
131
132 // start the arrays of new cells and nets
133 vCells = Vec_PtrAlloc( 16 );
134 vNets = Vec_PtrAlloc( 32 );
135
136 // go through the new nodes
137 Vec_PtrForEachEntry( Abc_Obj_t *, vAddedCells, pObj, i )
138 {
139 assert( !Abc_ObjIsComplement(pObj) );
140 Abc_PlaceCreateCell( pObj, 1 );
141 Abc_PlaceUpdateNet( pObj );
142
143 // add the new cell and its fanin nets to temporary storage
144 Vec_PtrPush( vCells, &(cells[pObj->Id]) );
145 Abc_ObjForEachFanin( pObj, pFanin, k )
146 Vec_PtrPushUnique( vNets, &(nets[pFanin->Id]) );
147 }
148
149 // go through the modified nets
150 Vec_PtrForEachEntry( Abc_Obj_t *, vUpdatedNets, pObj, i )
151 {
152 assert( !Abc_ObjIsComplement(pObj) );
153 if ( Abc_ObjType(pObj) == ABC_OBJ_NONE ) // dead node
154 continue;
155 Abc_PlaceUpdateNet( pObj );
156 }
157
158 // update the placement
159// fastPlace( Vec_PtrSize(vCells), (ConcreteCell **)Vec_PtrArray(vCells),
160// Vec_PtrSize(vNets), (ConcreteNet **)Vec_PtrArray(vNets) );
161
162 // clean up
163 Vec_PtrFree( vCells );
164 Vec_PtrFree( vNets );
165}
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
@ ABC_OBJ_NONE
Definition abc.h:87
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42

◆ Abc_RwrExpWithCut()

void Abc_RwrExpWithCut ( Abc_Obj_t * pNode,
Vec_Ptr_t * vLeaves )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 403 of file abcRewrite.c.

404{
405 Abc_Obj_t * pObj;
406 int i, CountA, CountB;
407 Abc_RwrExpWithCut_rec( Abc_ObjFanin0(pNode), vLeaves, 1 );
408 Abc_RwrExpWithCut_rec( Abc_ObjFanin1(pNode), vLeaves, 0 );
409 CountA = CountB = 0;
410 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
411 {
412 CountA += Abc_ObjRegular(pObj)->fMarkA;
413 CountB += Abc_ObjRegular(pObj)->fMarkB;
414 Abc_ObjRegular(pObj)->fMarkA = 0;
415 Abc_ObjRegular(pObj)->fMarkB = 0;
416 }
417 printf( "(%d,%d:%d) ", CountA, CountB, CountA+CountB-Vec_PtrSize(vLeaves) );
418}
void Abc_RwrExpWithCut_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vLeaves, int fUseA)
Definition abcRewrite.c:377
Here is the call graph for this function:

◆ Abc_RwrExpWithCut_rec()

void Abc_RwrExpWithCut_rec ( Abc_Obj_t * pNode,
Vec_Ptr_t * vLeaves,
int fUseA )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 377 of file abcRewrite.c.

378{
379 if ( Vec_PtrFind(vLeaves, pNode) >= 0 || Vec_PtrFind(vLeaves, Abc_ObjNot(pNode)) >= 0 )
380 {
381 if ( fUseA )
382 Abc_ObjRegular(pNode)->fMarkA = 1;
383 else
384 Abc_ObjRegular(pNode)->fMarkB = 1;
385 return;
386 }
387 assert( Abc_ObjIsNode(pNode) );
388 Abc_RwrExpWithCut_rec( Abc_ObjFanin0(pNode), vLeaves, fUseA );
389 Abc_RwrExpWithCut_rec( Abc_ObjFanin1(pNode), vLeaves, fUseA );
390}
Here is the call graph for this function:
Here is the caller graph for this function: