abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hopObj.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [hopObj.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Minimalistic And-Inverter Graph package.]
8 
9  Synopsis [Adding/removing objects.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - May 11, 2006.]
16 
17  Revision [$Id: hopObj.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "hop.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Creates primary input.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
46 {
47  Hop_Obj_t * pObj;
48  pObj = Hop_ManFetchMemory( p );
49  pObj->Type = AIG_PI;
50  pObj->PioNum = Vec_PtrSize( p->vPis );
51  Vec_PtrPush( p->vPis, pObj );
52  p->nObjs[AIG_PI]++;
53  return pObj;
54 }
55 
56 /**Function*************************************************************
57 
58  Synopsis [Creates primary output with the given driver.]
59 
60  Description []
61 
62  SideEffects []
63 
64  SeeAlso []
65 
66 ***********************************************************************/
68 {
69  Hop_Obj_t * pObj;
70  pObj = Hop_ManFetchMemory( p );
71  pObj->Type = AIG_PO;
72  Vec_PtrPush( p->vPos, pObj );
73  // add connections
74  pObj->pFanin0 = pDriver;
75  if ( p->fRefCount )
76  Hop_ObjRef( Hop_Regular(pDriver) );
77  else
78  pObj->nRefs = Hop_ObjLevel( Hop_Regular(pDriver) );
79  // set the phase
80  pObj->fPhase = Hop_ObjPhaseCompl(pDriver);
81  // update node counters of the manager
82  p->nObjs[AIG_PO]++;
83  return pObj;
84 }
85 
86 /**Function*************************************************************
87 
88  Synopsis [Create the new node assuming it does not exist.]
89 
90  Description []
91 
92  SideEffects []
93 
94  SeeAlso []
95 
96 ***********************************************************************/
98 {
99  Hop_Obj_t * pObj;
100  assert( !Hop_IsComplement(pGhost) );
101  assert( Hop_ObjIsNode(pGhost) );
102  assert( pGhost == &p->Ghost );
103  // get memory for the new object
104  pObj = Hop_ManFetchMemory( p );
105  pObj->Type = pGhost->Type;
106  // add connections
107  Hop_ObjConnect( p, pObj, pGhost->pFanin0, pGhost->pFanin1 );
108  // update node counters of the manager
109  p->nObjs[Hop_ObjType(pObj)]++;
110  assert( pObj->pData == NULL );
111  return pObj;
112 }
113 
114 /**Function*************************************************************
115 
116  Synopsis [Connect the object to the fanin.]
117 
118  Description []
119 
120  SideEffects []
121 
122  SeeAlso []
123 
124 ***********************************************************************/
125 void Hop_ObjConnect( Hop_Man_t * p, Hop_Obj_t * pObj, Hop_Obj_t * pFan0, Hop_Obj_t * pFan1 )
126 {
127  assert( !Hop_IsComplement(pObj) );
128  assert( Hop_ObjIsNode(pObj) );
129  // add the first fanin
130  pObj->pFanin0 = pFan0;
131  pObj->pFanin1 = pFan1;
132  // increment references of the fanins and add their fanouts
133  if ( p->fRefCount )
134  {
135  if ( pFan0 != NULL )
136  Hop_ObjRef( Hop_ObjFanin0(pObj) );
137  if ( pFan1 != NULL )
138  Hop_ObjRef( Hop_ObjFanin1(pObj) );
139  }
140  else
141  pObj->nRefs = Hop_ObjLevelNew( pObj );
142  // set the phase
143  pObj->fPhase = Hop_ObjPhaseCompl(pFan0) & Hop_ObjPhaseCompl(pFan1);
144  // add the node to the structural hash table
145  Hop_TableInsert( p, pObj );
146 }
147 
148 /**Function*************************************************************
149 
150  Synopsis [Connect the object to the fanin.]
151 
152  Description []
153 
154  SideEffects []
155 
156  SeeAlso []
157 
158 ***********************************************************************/
160 {
161  assert( !Hop_IsComplement(pObj) );
162  assert( Hop_ObjIsNode(pObj) );
163  // remove connections
164  if ( pObj->pFanin0 != NULL )
166  if ( pObj->pFanin1 != NULL )
168  // remove the node from the structural hash table
169  Hop_TableDelete( p, pObj );
170  // add the first fanin
171  pObj->pFanin0 = NULL;
172  pObj->pFanin1 = NULL;
173 }
174 
175 /**Function*************************************************************
176 
177  Synopsis [Deletes the node.]
178 
179  Description []
180 
181  SideEffects []
182 
183  SeeAlso []
184 
185 ***********************************************************************/
187 {
188  assert( !Hop_IsComplement(pObj) );
189  assert( !Hop_ObjIsTerm(pObj) );
190  assert( Hop_ObjRefs(pObj) == 0 );
191  // update node counters of the manager
192  p->nObjs[pObj->Type]--;
193  p->nDeleted++;
194  // remove connections
195  Hop_ObjDisconnect( p, pObj );
196  // remove PIs/POs from the arrays
197  if ( Hop_ObjIsPi(pObj) )
198  Vec_PtrRemove( p->vPis, pObj );
199  // free the node
200  Hop_ManRecycleMemory( p, pObj );
201 }
202 
203 /**Function*************************************************************
204 
205  Synopsis [Deletes the MFFC of the node.]
206 
207  Description []
208 
209  SideEffects []
210 
211  SeeAlso []
212 
213 ***********************************************************************/
215 {
216  Hop_Obj_t * pFanin0, * pFanin1;
217  assert( !Hop_IsComplement(pObj) );
218  if ( Hop_ObjIsConst1(pObj) || Hop_ObjIsPi(pObj) )
219  return;
220  assert( Hop_ObjIsNode(pObj) );
221  pFanin0 = Hop_ObjFanin0(pObj);
222  pFanin1 = Hop_ObjFanin1(pObj);
223  Hop_ObjDelete( p, pObj );
224  if ( pFanin0 && !Hop_ObjIsNone(pFanin0) && Hop_ObjRefs(pFanin0) == 0 )
225  Hop_ObjDelete_rec( p, pFanin0 );
226  if ( pFanin1 && !Hop_ObjIsNone(pFanin1) && Hop_ObjRefs(pFanin1) == 0 )
227  Hop_ObjDelete_rec( p, pFanin1 );
228 }
229 
230 /**Function*************************************************************
231 
232  Synopsis [Returns the representative of the node.]
233 
234  Description []
235 
236  SideEffects []
237 
238  SeeAlso []
239 
240 ***********************************************************************/
242 {
243  assert( !Hop_IsComplement(pObj) );
244  if ( pObj->pData == NULL || pObj->pData == pObj )
245  return pObj;
246  return Hop_ObjRepr( (Hop_Obj_t *)pObj->pData );
247 }
248 
249 /**Function*************************************************************
250 
251  Synopsis [Sets an equivalence relation between the nodes.]
252 
253  Description [Makes the representative of pNew point to the representaive of pOld.]
254 
255  SideEffects []
256 
257  SeeAlso []
258 
259 ***********************************************************************/
261 {
262  Hop_Obj_t * pOldRepr;
263  Hop_Obj_t * pNewRepr;
264  assert( pOld != NULL && pNew != NULL );
265  pOldRepr = Hop_ObjRepr(pOld);
266  pNewRepr = Hop_ObjRepr(pNew);
267  if ( pNewRepr != pOldRepr )
268  pNewRepr->pData = pOldRepr;
269 }
270 
271 ////////////////////////////////////////////////////////////////////////
272 /// END OF FILE ///
273 ////////////////////////////////////////////////////////////////////////
274 
275 
277 
static Hop_Obj_t * Hop_ObjFanin1(Hop_Obj_t *pObj)
Definition: hop.h:183
static int Hop_ObjRefs(Hop_Obj_t *pObj)
Definition: hop.h:176
Hop_Obj_t * Hop_ObjCreatePo(Hop_Man_t *p, Hop_Obj_t *pDriver)
Definition: hopObj.c:67
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Hop_TableInsert(Hop_Man_t *p, Hop_Obj_t *pObj)
Definition: hopTable.c:100
static int Hop_ObjIsPi(Hop_Obj_t *pObj)
Definition: hop.h:156
static int Hop_ObjIsNode(Hop_Obj_t *pObj)
Definition: hop.h:160
static Hop_Type_t Hop_ObjType(Hop_Obj_t *pObj)
Definition: hop.h:153
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
Hop_Obj_t * pFanin1
Definition: hop.h:74
unsigned int Type
Definition: hop.h:75
ABC_NAMESPACE_IMPL_START Hop_Obj_t * Hop_ObjCreatePi(Hop_Man_t *p)
DECLARATIONS ///.
Definition: hopObj.c:45
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
unsigned int nRefs
Definition: hop.h:79
Definition: hop.h:65
static void Vec_PtrRemove(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:714
static void Hop_ManRecycleMemory(Hop_Man_t *p, Hop_Obj_t *pEntry)
Definition: hop.h:246
void Hop_ObjConnect(Hop_Man_t *p, Hop_Obj_t *pObj, Hop_Obj_t *pFan0, Hop_Obj_t *pFan1)
Definition: hopObj.c:125
unsigned int fPhase
Definition: hop.h:76
Definition: hop.h:57
Hop_Obj_t * Hop_ObjRepr(Hop_Obj_t *pObj)
Definition: hopObj.c:241
static int Hop_ObjPhaseCompl(Hop_Obj_t *pObj)
Definition: hop.h:192
int PioNum
Definition: hop.h:72
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Hop_ObjIsNone(Hop_Obj_t *pObj)
Definition: hop.h:154
Hop_Obj_t * pFanin0
Definition: hop.h:73
static Hop_Obj_t * Hop_ManFetchMemory(Hop_Man_t *p)
Definition: hop.h:230
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
void Hop_ObjDelete(Hop_Man_t *p, Hop_Obj_t *pObj)
Definition: hopObj.c:186
void * pData
Definition: hop.h:68
Definition: hop.h:58
static Hop_Obj_t * Hop_ObjFanin0(Hop_Obj_t *pObj)
Definition: hop.h:182
static int Hop_ObjIsConst1(Hop_Obj_t *pObj)
Definition: hop.h:155
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Hop_ObjLevel(Hop_Obj_t *pObj)
Definition: hop.h:190
static int Hop_ObjIsTerm(Hop_Obj_t *pObj)
Definition: hop.h:161
static void Hop_ObjRef(Hop_Obj_t *pObj)
Definition: hop.h:177
static void Hop_ObjDeref(Hop_Obj_t *pObj)
Definition: hop.h:178
void Hop_ObjDisconnect(Hop_Man_t *p, Hop_Obj_t *pObj)
Definition: hopObj.c:159
void Hop_TableDelete(Hop_Man_t *p, Hop_Obj_t *pObj)
Definition: hopTable.c:123
#define assert(ex)
Definition: util_old.h:213
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
static int Hop_ObjLevelNew(Hop_Obj_t *pObj)
Definition: hop.h:191
Hop_Obj_t * Hop_ObjCreate(Hop_Man_t *p, Hop_Obj_t *pGhost)
Definition: hopObj.c:97
void Hop_ObjCreateChoice(Hop_Obj_t *pOld, Hop_Obj_t *pNew)
Definition: hopObj.c:260
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
void Hop_ObjDelete_rec(Hop_Man_t *p, Hop_Obj_t *pObj)
Definition: hopObj.c:214