ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ivyRwrAlg.c File Reference
#include "ivy.h"
Include dependency graph for ivyRwrAlg.c:

Go to the source code of this file.

Functions

int Ivy_ManRewriteAlg (Ivy_Man_t *p, int fUpdateLevel, int fUseZeroCost)
 FUNCTION DEFINITIONS ///.
 
int Ivy_NodeCountMffc_rec (Ivy_Obj_t *pNode)
 
int Ivy_ManFindAlgCutCompare (Ivy_Obj_t **pp1, Ivy_Obj_t **pp2)
 
int Ivy_ManFindAlgCut_rec (Ivy_Obj_t *pObj, Ivy_Type_t Type, Vec_Ptr_t *vFront, Vec_Ptr_t *vCone)
 

Function Documentation

◆ Ivy_ManFindAlgCut_rec()

int Ivy_ManFindAlgCut_rec ( Ivy_Obj_t * pObj,
Ivy_Type_t Type,
Vec_Ptr_t * vFront,
Vec_Ptr_t * vCone )

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

Synopsis [Computing one algebraic cut.]

Description [Returns 1 if the tree-leaves of this node where traversed and found to have no external references (and have not been collected). Returns 0 if the tree-leaves have external references and are collected.]

SideEffects []

SeeAlso []

Definition at line 279 of file ivyRwrAlg.c.

280{
281 int RetValue0, RetValue1;
282 Ivy_Obj_t * pObjR = Ivy_Regular(pObj);
283 assert( !Ivy_ObjIsBuf(pObjR) );
284 assert( Type != IVY_EXOR || !Ivy_IsComplement(pObj) );
285
286 // make sure the node is not visited twice in different polarities
287 if ( Ivy_IsComplement(pObj) )
288 { // if complemented, mark B
289 if ( pObjR->fMarkA )
290 return -1;
291 pObjR->fMarkB = 1;
292 }
293 else
294 { // if non-complicated, mark A
295 if ( pObjR->fMarkB )
296 return -1;
297 pObjR->fMarkA = 1;
298 }
299 Vec_PtrPush( vCone, pObjR );
300
301 // if the node is the end of the tree, return
302 if ( Ivy_IsComplement(pObj) || Ivy_ObjType(pObj) != Type )
303 {
304 if ( Ivy_ObjRefs(pObjR) == 1 )
305 return 1;
306 assert( Ivy_ObjRefs(pObjR) > 1 );
307 Vec_PtrPush( vFront, pObj );
308 return 0;
309 }
310
311 // branch on the node
312 assert( !Ivy_IsComplement(pObj) );
313 assert( Ivy_ObjIsNode(pObj) );
314 // what if buffer has more than one fanout???
315 RetValue0 = Ivy_ManFindAlgCut_rec( Ivy_ObjReal( Ivy_ObjChild0(pObj) ), Type, vFront, vCone );
316 RetValue1 = Ivy_ManFindAlgCut_rec( Ivy_ObjReal( Ivy_ObjChild1(pObj) ), Type, vFront, vCone );
317 if ( RetValue0 == -1 || RetValue1 == -1 )
318 return -1;
319
320 // the case when both have no external references
321 if ( RetValue0 && RetValue1 )
322 {
323 if ( Ivy_ObjRefs(pObj) == 1 )
324 return 1;
325 assert( Ivy_ObjRefs(pObj) > 1 );
326 Vec_PtrPush( vFront, pObj );
327 return 0;
328 }
329 // the case when one of them has external references
330 if ( RetValue0 )
331 Vec_PtrPush( vFront, Ivy_ObjReal( Ivy_ObjChild0(pObj) ) );
332 if ( RetValue1 )
333 Vec_PtrPush( vFront, Ivy_ObjReal( Ivy_ObjChild1(pObj) ) );
334 return 0;
335}
int Ivy_ManFindAlgCut_rec(Ivy_Obj_t *pObj, Ivy_Type_t Type, Vec_Ptr_t *vFront, Vec_Ptr_t *vCone)
Definition ivyRwrAlg.c:279
Ivy_Obj_t * Ivy_ObjReal(Ivy_Obj_t *pObj)
Definition ivyUtil.c:609
struct Ivy_Obj_t_ Ivy_Obj_t
Definition ivy.h:47
@ IVY_EXOR
Definition ivy.h:59
unsigned fMarkB
Definition ivy.h:79
unsigned fMarkA
Definition ivy.h:78
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ivy_ManFindAlgCutCompare()

int Ivy_ManFindAlgCutCompare ( Ivy_Obj_t ** pp1,
Ivy_Obj_t ** pp2 )

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

Synopsis [Comparison for node pointers.]

Description []

SideEffects []

SeeAlso []

Definition at line 257 of file ivyRwrAlg.c.

258{
259 if ( *pp1 < *pp2 )
260 return -1;
261 if ( *pp1 > *pp2 )
262 return 1;
263 return 0;
264}

◆ Ivy_ManRewriteAlg()

int Ivy_ManRewriteAlg ( Ivy_Man_t * p,
int fUpdateLevel,
int fUseZeroCost )

FUNCTION DEFINITIONS ///.

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

Synopsis [Algebraic AIG rewriting.]

Description []

SideEffects []

SeeAlso []

Definition at line 49 of file ivyRwrAlg.c.

50{
51 Vec_Int_t * vRequired;
52 Vec_Ptr_t * vFront, * vLeaves, * vCone, * vSol;
53 Ivy_Obj_t * pObj, * pResult;
54 int i, RetValue, LevelR, nNodesOld;
55 int CountUsed, CountUndo;
56 vRequired = fUpdateLevel? Ivy_ManRequiredLevels( p ) : NULL;
57 vFront = Vec_PtrAlloc( 100 );
58 vLeaves = Vec_PtrAlloc( 100 );
59 vCone = Vec_PtrAlloc( 100 );
60 vSol = Vec_PtrAlloc( 100 );
61 // go through the nodes in the topological order
62 CountUsed = CountUndo = 0;
63 nNodesOld = Ivy_ManObjIdNext(p);
64 Ivy_ManForEachObj( p, pObj, i )
65 {
66 assert( !Ivy_ObjIsBuf(pObj) );
67 if ( i >= nNodesOld )
68 break;
69 // skip no-nodes and MUX roots
70 if ( !Ivy_ObjIsNode(pObj) || Ivy_ObjIsExor(pObj) || Ivy_ObjIsMuxType(pObj) )
71 continue;
72// if ( pObj->Id > 297 ) // 296 --- 297
73// break;
74 if ( pObj->Id == 297 )
75 {
76 int x = 0;
77 }
78 // get the largest algebraic cut
79 RetValue = Ivy_ManFindAlgCut( pObj, vFront, vLeaves, vCone );
80 // the case of a trivial tree cut
81 if ( RetValue == 1 )
82 continue;
83 // the case of constant 0 cone
84 if ( RetValue == -1 )
85 {
86 Ivy_ObjReplace( pObj, Ivy_ManConst0(p), 1, 0, 1 );
87 continue;
88 }
89 assert( Vec_PtrSize(vLeaves) > 2 );
90 // get the required level for this node
91 LevelR = vRequired? Vec_IntEntry(vRequired, pObj->Id) : 1000000;
92 // create a new cone
93 pResult = Ivy_NodeRewriteAlg( pObj, vFront, vLeaves, vCone, vSol, LevelR, fUseZeroCost );
94 if ( pResult == NULL || pResult == pObj )
95 continue;
96 assert( Vec_PtrSize(vSol) == 1 || !Ivy_IsComplement(pResult) );
97 if ( Ivy_ObjLevel(Ivy_Regular(pResult)) > LevelR && Ivy_ObjRefs(Ivy_Regular(pResult)) == 0 )
98 Ivy_ObjDelete_rec(Ivy_Regular(pResult), 1), CountUndo++;
99 else
100 Ivy_ObjReplace( pObj, pResult, 1, 0, 1 ), CountUsed++;
101 }
102 printf( "Used = %d. Undo = %d.\n", CountUsed, CountUndo );
103 Vec_PtrFree( vFront );
104 Vec_PtrFree( vCone );
105 Vec_PtrFree( vSol );
106 if ( vRequired ) Vec_IntFree( vRequired );
107 if ( i = Ivy_ManCleanup(p) )
108 printf( "Cleanup after rewriting removed %d dangling nodes.\n", i );
109 if ( !Ivy_ManCheck(p) )
110 printf( "Ivy_ManRewriteAlg(): The check has failed.\n" );
111 return 1;
112}
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
int Ivy_ManCheck(Ivy_Man_t *p)
DECLARATIONS ///.
Definition ivyCheck.c:45
Vec_Int_t * Ivy_ManRequiredLevels(Ivy_Man_t *p)
Definition ivyDfs.c:250
int Ivy_ManCleanup(Ivy_Man_t *p)
Definition ivyMan.c:265
#define Ivy_ManForEachObj(p, pObj, i)
Definition ivy.h:393
void Ivy_ObjReplace(Ivy_Man_t *p, Ivy_Obj_t *pObjOld, Ivy_Obj_t *pObjNew, int fDeleteOld, int fFreeTop, int fUpdateLevel)
Definition ivyObj.c:328
int Ivy_ObjIsMuxType(Ivy_Obj_t *pObj)
Definition ivyUtil.c:479
void Ivy_ObjDelete_rec(Ivy_Man_t *p, Ivy_Obj_t *pObj, int fFreeTop)
Definition ivyObj.c:299
int Id
Definition ivy.h:75
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
Here is the call graph for this function:

◆ Ivy_NodeCountMffc_rec()

int Ivy_NodeCountMffc_rec ( Ivy_Obj_t * pNode)

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

Synopsis [Comparison for node pointers.]

Description []

SideEffects []

SeeAlso []

Definition at line 217 of file ivyRwrAlg.c.

218{
219 if ( Ivy_ObjRefs(pNode) > 0 || Ivy_ObjIsCi(pNode) || pNode->fMarkA )
220 return 0;
221 assert( pNode->fMarkB );
222 pNode->fMarkA = 1;
223// printf( "%d ", pNode->Id );
224 if ( Ivy_ObjIsBuf(pNode) )
225 return Ivy_NodeCountMffc_rec( Ivy_ObjFanin0(pNode) );
226 return 1 + Ivy_NodeCountMffc_rec( Ivy_ObjFanin0(pNode) ) + Ivy_NodeCountMffc_rec( Ivy_ObjFanin1(pNode) );
227}
int Ivy_NodeCountMffc_rec(Ivy_Obj_t *pNode)
Definition ivyRwrAlg.c:217
Here is the call graph for this function:
Here is the caller graph for this function: