abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcFanio.c File Reference
#include "abc.h"

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START void 
Vec_IntPushMem (Mem_Step_t *pMemMan, Vec_Int_t *p, int Entry)
 DECLARATIONS ///. More...
 
void Abc_ObjAddFanin (Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
 
void Abc_ObjDeleteFanin (Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
 
void Abc_ObjRemoveFanins (Abc_Obj_t *pObj)
 
void Abc_ObjPatchFanin (Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
 
Abc_Obj_tAbc_ObjInsertBetween (Abc_Obj_t *pNodeIn, Abc_Obj_t *pNodeOut, Abc_ObjType_t Type)
 
void Abc_ObjTransferFanout (Abc_Obj_t *pNodeFrom, Abc_Obj_t *pNodeTo)
 
void Abc_ObjReplace (Abc_Obj_t *pNodeOld, Abc_Obj_t *pNodeNew)
 
int Abc_ObjFanoutFaninNum (Abc_Obj_t *pFanout, Abc_Obj_t *pFanin)
 

Function Documentation

void Abc_ObjAddFanin ( Abc_Obj_t pObj,
Abc_Obj_t pFanin 
)

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

Synopsis [Creates fanout/fanin relationship between the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 84 of file abcFanio.c.

85 {
86  Abc_Obj_t * pFaninR = Abc_ObjRegular(pFanin);
87  assert( !Abc_ObjIsComplement(pObj) );
88  assert( pObj->pNtk == pFaninR->pNtk );
89  assert( pObj->Id >= 0 && pFaninR->Id >= 0 );
90  assert( !Abc_ObjIsPi(pObj) && !Abc_ObjIsPo(pFaninR) ); // fanin of PI or fanout of PO
91  assert( !Abc_ObjIsCo(pObj) || !Abc_ObjFaninNum(pObj) ); // CO with two fanins
92  assert( !Abc_ObjIsNet(pObj) || !Abc_ObjFaninNum(pObj) ); // net with two fanins
93  Vec_IntPushMem( pObj->pNtk->pMmStep, &pObj->vFanins, pFaninR->Id );
94  Vec_IntPushMem( pObj->pNtk->pMmStep, &pFaninR->vFanouts, pObj->Id );
95  if ( Abc_ObjIsComplement(pFanin) )
96  Abc_ObjSetFaninC( pObj, Abc_ObjFaninNum(pObj)-1 );
97 }
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static int Abc_ObjIsPi(Abc_Obj_t *pObj)
Definition: abc.h:347
Vec_Int_t vFanins
Definition: abc.h:143
static int Abc_ObjIsCo(Abc_Obj_t *pObj)
Definition: abc.h:352
static void Abc_ObjSetFaninC(Abc_Obj_t *pObj, int i)
Definition: abc.h:380
Vec_Int_t vFanouts
Definition: abc.h:144
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
Abc_Ntk_t * pNtk
Definition: abc.h:130
int Id
Definition: abc.h:132
static int Abc_ObjIsNet(Abc_Obj_t *pObj)
Definition: abc.h:354
Mem_Step_t * pMmStep
Definition: abc.h:190
static int Abc_ObjIsPo(Abc_Obj_t *pObj)
Definition: abc.h:348
#define assert(ex)
Definition: util_old.h:213
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
static ABC_NAMESPACE_IMPL_START void Vec_IntPushMem(Mem_Step_t *pMemMan, Vec_Int_t *p, int Entry)
DECLARATIONS ///.
Definition: abcFanio.c:45
void Abc_ObjDeleteFanin ( Abc_Obj_t pObj,
Abc_Obj_t pFanin 
)

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

Synopsis [Destroys fanout/fanin relationship between the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 111 of file abcFanio.c.

112 {
113  assert( !Abc_ObjIsComplement(pObj) );
114  assert( !Abc_ObjIsComplement(pFanin) );
115  assert( pObj->pNtk == pFanin->pNtk );
116  assert( pObj->Id >= 0 && pFanin->Id >= 0 );
117  if ( !Vec_IntRemove( &pObj->vFanins, pFanin->Id ) )
118  {
119  printf( "The obj %d is not found among the fanins of obj %d ...\n", pFanin->Id, pObj->Id );
120  return;
121  }
122  if ( !Vec_IntRemove( &pFanin->vFanouts, pObj->Id ) )
123  {
124  printf( "The obj %d is not found among the fanouts of obj %d ...\n", pObj->Id, pFanin->Id );
125  return;
126  }
127 }
Vec_Int_t vFanins
Definition: abc.h:143
static int Vec_IntRemove(Vec_Int_t *p, int Entry)
Definition: vecInt.h:915
Vec_Int_t vFanouts
Definition: abc.h:144
Abc_Ntk_t * pNtk
Definition: abc.h:130
int Id
Definition: abc.h:132
#define assert(ex)
Definition: util_old.h:213
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
int Abc_ObjFanoutFaninNum ( Abc_Obj_t pFanout,
Abc_Obj_t pFanin 
)

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

Synopsis [Returns the index of the fanin in the fanin list of the fanout.]

Description []

SideEffects []

SeeAlso []

Definition at line 321 of file abcFanio.c.

322 {
323  Abc_Obj_t * pObj;
324  int i;
325  Abc_ObjForEachFanin( pFanout, pObj, i )
326  if ( pObj == pFanin )
327  return i;
328  return -1;
329 }
if(last==0)
Definition: sparse_int.h:34
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
Abc_Obj_t* Abc_ObjInsertBetween ( Abc_Obj_t pNodeIn,
Abc_Obj_t pNodeOut,
Abc_ObjType_t  Type 
)

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

Synopsis [Inserts one-input node of the type specified between the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 223 of file abcFanio.c.

224 {
225  Abc_Obj_t * pNodeNew;
226  int iFanoutIndex, iFaninIndex;
227  // find pNodeOut among the fanouts of pNodeIn
228  if ( (iFanoutIndex = Vec_IntFind( &pNodeIn->vFanouts, pNodeOut->Id )) == -1 )
229  {
230  printf( "Node %s is not among", Abc_ObjName(pNodeOut) );
231  printf( " the fanouts of node %s...\n", Abc_ObjName(pNodeIn) );
232  return NULL;
233  }
234  // find pNodeIn among the fanins of pNodeOut
235  if ( (iFaninIndex = Vec_IntFind( &pNodeOut->vFanins, pNodeIn->Id )) == -1 )
236  {
237  printf( "Node %s is not among", Abc_ObjName(pNodeIn) );
238  printf( " the fanins of node %s...\n", Abc_ObjName(pNodeOut) );
239  return NULL;
240  }
241  // create the new node
242  pNodeNew = Abc_NtkCreateObj( pNodeIn->pNtk, Type );
243  // add pNodeIn as fanin and pNodeOut as fanout
244  Vec_IntPushMem( pNodeNew->pNtk->pMmStep, &pNodeNew->vFanins, pNodeIn->Id );
245  Vec_IntPushMem( pNodeNew->pNtk->pMmStep, &pNodeNew->vFanouts, pNodeOut->Id );
246  // update the fanout of pNodeIn
247  Vec_IntWriteEntry( &pNodeIn->vFanouts, iFanoutIndex, pNodeNew->Id );
248  // update the fanin of pNodeOut
249  Vec_IntWriteEntry( &pNodeOut->vFanins, iFaninIndex, pNodeNew->Id );
250  return pNodeNew;
251 }
static int Vec_IntFind(Vec_Int_t *p, int Entry)
Definition: vecInt.h:895
Vec_Int_t vFanins
Definition: abc.h:143
ABC_DLL Abc_Obj_t * Abc_NtkCreateObj(Abc_Ntk_t *pNtk, Abc_ObjType_t Type)
Definition: abcObj.c:106
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
Vec_Int_t vFanouts
Definition: abc.h:144
Abc_Ntk_t * pNtk
Definition: abc.h:130
int Id
Definition: abc.h:132
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
Mem_Step_t * pMmStep
Definition: abc.h:190
static ABC_NAMESPACE_IMPL_START void Vec_IntPushMem(Mem_Step_t *pMemMan, Vec_Int_t *p, int Entry)
DECLARATIONS ///.
Definition: abcFanio.c:45
void Abc_ObjPatchFanin ( Abc_Obj_t pObj,
Abc_Obj_t pFaninOld,
Abc_Obj_t pFaninNew 
)

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

Synopsis [Replaces a fanin of the node.]

Description [The node is pObj. An old fanin of this node (pFaninOld) has to be replaced by a new fanin (pFaninNew). Assumes that the node and the old fanin are not complemented. The new fanin can be complemented. In this case, the polarity of the new fanin will change, compared to the polarity of the old fanin.]

SideEffects []

SeeAlso []

Definition at line 172 of file abcFanio.c.

173 {
174  Abc_Obj_t * pFaninNewR = Abc_ObjRegular(pFaninNew);
175  int iFanin;//, nLats;//, fCompl;
176  assert( !Abc_ObjIsComplement(pObj) );
177  assert( !Abc_ObjIsComplement(pFaninOld) );
178  assert( pFaninOld != pFaninNewR );
179 // assert( pObj != pFaninOld );
180 // assert( pObj != pFaninNewR );
181  assert( pObj->pNtk == pFaninOld->pNtk );
182  assert( pObj->pNtk == pFaninNewR->pNtk );
183  if ( (iFanin = Vec_IntFind( &pObj->vFanins, pFaninOld->Id )) == -1 )
184  {
185  printf( "Node %s is not among", Abc_ObjName(pFaninOld) );
186  printf( " the fanins of node %s...\n", Abc_ObjName(pObj) );
187  return;
188  }
189 
190  // remember the attributes of the old fanin
191 // fCompl = Abc_ObjFaninC(pObj, iFanin);
192  // replace the old fanin entry by the new fanin entry (removes attributes)
193  Vec_IntWriteEntry( &pObj->vFanins, iFanin, pFaninNewR->Id );
194  // set the attributes of the new fanin
195 // if ( fCompl ^ Abc_ObjIsComplement(pFaninNew) )
196 // Abc_ObjSetFaninC( pObj, iFanin );
197  if ( Abc_ObjIsComplement(pFaninNew) )
198  Abc_ObjXorFaninC( pObj, iFanin );
199 
200 // if ( Abc_NtkIsSeq(pObj->pNtk) && (nLats = Seq_ObjFaninL(pObj, iFanin)) )
201 // Seq_ObjSetFaninL( pObj, iFanin, nLats );
202  // update the fanout of the fanin
203  if ( !Vec_IntRemove( &pFaninOld->vFanouts, pObj->Id ) )
204  {
205  printf( "Node %s is not among", Abc_ObjName(pObj) );
206  printf( " the fanouts of its old fanin %s...\n", Abc_ObjName(pFaninOld) );
207 // return;
208  }
209  Vec_IntPushMem( pObj->pNtk->pMmStep, &pFaninNewR->vFanouts, pObj->Id );
210 }
static int Vec_IntFind(Vec_Int_t *p, int Entry)
Definition: vecInt.h:895
Vec_Int_t vFanins
Definition: abc.h:143
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Vec_IntRemove(Vec_Int_t *p, int Entry)
Definition: vecInt.h:915
Vec_Int_t vFanouts
Definition: abc.h:144
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
Abc_Ntk_t * pNtk
Definition: abc.h:130
int Id
Definition: abc.h:132
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
static void Abc_ObjXorFaninC(Abc_Obj_t *pObj, int i)
Definition: abc.h:381
Mem_Step_t * pMmStep
Definition: abc.h:190
#define assert(ex)
Definition: util_old.h:213
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
static ABC_NAMESPACE_IMPL_START void Vec_IntPushMem(Mem_Step_t *pMemMan, Vec_Int_t *p, int Entry)
DECLARATIONS ///.
Definition: abcFanio.c:45
void Abc_ObjRemoveFanins ( Abc_Obj_t pObj)

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

Synopsis [Destroys fanout/fanin relationship between the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 141 of file abcFanio.c.

142 {
143  Vec_Int_t * vFaninsOld;
144  Abc_Obj_t * pFanin;
145  int k;
146  // remove old fanins
147  vFaninsOld = &pObj->vFanins;
148  for ( k = vFaninsOld->nSize - 1; k >= 0; k-- )
149  {
150  pFanin = Abc_NtkObj( pObj->pNtk, vFaninsOld->pArray[k] );
151  Abc_ObjDeleteFanin( pObj, pFanin );
152  }
153  pObj->fCompl0 = 0;
154  pObj->fCompl1 = 0;
155  assert( vFaninsOld->nSize == 0 );
156 }
unsigned fCompl0
Definition: abc.h:140
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Abc_ObjDeleteFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:111
Vec_Int_t vFanins
Definition: abc.h:143
static Abc_Obj_t * Abc_NtkObj(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:314
unsigned fCompl1
Definition: abc.h:141
Abc_Ntk_t * pNtk
Definition: abc.h:130
#define assert(ex)
Definition: util_old.h:213
void Abc_ObjReplace ( Abc_Obj_t pNodeOld,
Abc_Obj_t pNodeNew 
)

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

Synopsis [Replaces the node by a new node.]

Description []

SideEffects []

SeeAlso []

Definition at line 297 of file abcFanio.c.

298 {
299  assert( !Abc_ObjIsComplement(pNodeOld) );
300  assert( !Abc_ObjIsComplement(pNodeNew) );
301  assert( pNodeOld->pNtk == pNodeNew->pNtk );
302  assert( pNodeOld != pNodeNew );
303  assert( Abc_ObjFanoutNum(pNodeOld) > 0 );
304  // transfer the fanouts to the old node
305  Abc_ObjTransferFanout( pNodeOld, pNodeNew );
306  // remove the old node
307  Abc_NtkDeleteObj_rec( pNodeOld, 1 );
308 }
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
Definition: abcObj.c:273
Abc_Ntk_t * pNtk
Definition: abc.h:130
void Abc_ObjTransferFanout(Abc_Obj_t *pNodeFrom, Abc_Obj_t *pNodeTo)
Definition: abcFanio.c:264
#define assert(ex)
Definition: util_old.h:213
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
void Abc_ObjTransferFanout ( Abc_Obj_t pNodeFrom,
Abc_Obj_t pNodeTo 
)

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

Synopsis [Transfers fanout from the old node to the new node.]

Description []

SideEffects []

SeeAlso []

Definition at line 264 of file abcFanio.c.

265 {
266  Vec_Ptr_t * vFanouts;
267  int nFanoutsOld, i;
268  assert( !Abc_ObjIsComplement(pNodeFrom) );
269  assert( !Abc_ObjIsComplement(pNodeTo) );
270  assert( !Abc_ObjIsPo(pNodeFrom) && !Abc_ObjIsPo(pNodeTo) );
271  assert( pNodeFrom->pNtk == pNodeTo->pNtk );
272  assert( pNodeFrom != pNodeTo );
273  assert( !Abc_ObjIsNode(pNodeFrom) || Abc_ObjFanoutNum(pNodeFrom) > 0 );
274  // get the fanouts of the old node
275  nFanoutsOld = Abc_ObjFanoutNum(pNodeTo);
276  vFanouts = Vec_PtrAlloc( nFanoutsOld );
277  Abc_NodeCollectFanouts( pNodeFrom, vFanouts );
278  // patch the fanin of each of them
279  for ( i = 0; i < vFanouts->nSize; i++ )
280  Abc_ObjPatchFanin( (Abc_Obj_t *)vFanouts->pArray[i], pNodeFrom, pNodeTo );
281  assert( Abc_ObjFanoutNum(pNodeFrom) == 0 );
282  assert( Abc_ObjFanoutNum(pNodeTo) == nFanoutsOld + vFanouts->nSize );
283  Vec_PtrFree( vFanouts );
284 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
Definition: abcFanio.c:172
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
Abc_Ntk_t * pNtk
Definition: abc.h:130
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
static int Abc_ObjIsPo(Abc_Obj_t *pObj)
Definition: abc.h:348
#define assert(ex)
Definition: util_old.h:213
ABC_DLL void Abc_NodeCollectFanouts(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition: abcUtil.c:1607
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
static ABC_NAMESPACE_IMPL_START void Vec_IntPushMem ( Mem_Step_t pMemMan,
Vec_Int_t p,
int  Entry 
)
inlinestatic

DECLARATIONS ///.

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

FileName [abcFanio.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Various procedures to connect fanins/fanouts.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file abcFanio.c.

46 {
47  if ( p->nSize == p->nCap )
48  {
49  int * pArray;
50  int i;
51 
52  if ( p->nSize == 0 )
53  p->nCap = 1;
54  if ( pMemMan )
55  pArray = (int *)Mem_StepEntryFetch( pMemMan, p->nCap * 8 );
56  else
57  pArray = ABC_ALLOC( int, p->nCap * 2 );
58  if ( p->pArray )
59  {
60  for ( i = 0; i < p->nSize; i++ )
61  pArray[i] = p->pArray[i];
62  if ( pMemMan )
63  Mem_StepEntryRecycle( pMemMan, (char *)p->pArray, p->nCap * 4 );
64  else
65  ABC_FREE( p->pArray );
66  }
67  p->nCap *= 2;
68  p->pArray = pArray;
69  }
70  p->pArray[p->nSize++] = Entry;
71 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Mem_StepEntryRecycle(Mem_Step_t *p, char *pEntry, int nBytes)
Definition: mem.c:570
if(last==0)
Definition: sparse_int.h:34
char * Mem_StepEntryFetch(Mem_Step_t *p, int nBytes)
Definition: mem.c:537
#define ABC_FREE(obj)
Definition: abc_global.h:232