hopObj.c 7.65 KB
Newer Older
Alan Mishchenko committed
1 2
/**CFile****************************************************************

Alan Mishchenko committed
3
  FileName    [hopObj.c]
Alan Mishchenko committed
4 5 6 7 8 9 10 11 12 13 14 15 16

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Minimalistic And-Inverter Graph package.]

  Synopsis    [Adding/removing objects.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - May 11, 2006.]

Alan Mishchenko committed
17
  Revision    [$Id: hopObj.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
Alan Mishchenko committed
18 19 20

***********************************************************************/

Alan Mishchenko committed
21
#include "hop.h"
Alan Mishchenko committed
22

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    [Creates primary input.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
45
Hop_Obj_t * Hop_ObjCreatePi( Hop_Man_t * p )
Alan Mishchenko committed
46
{
Alan Mishchenko committed
47 48
    Hop_Obj_t * pObj;
    pObj = Hop_ManFetchMemory( p );
Alan Mishchenko committed
49
    pObj->Type = AIG_PI;
Alan Mishchenko committed
50
    pObj->PioNum = Vec_PtrSize( p->vPis );
Alan Mishchenko committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    Vec_PtrPush( p->vPis, pObj );
    p->nObjs[AIG_PI]++;
    return pObj;
}

/**Function*************************************************************

  Synopsis    [Creates primary output with the given driver.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
67
Hop_Obj_t * Hop_ObjCreatePo( Hop_Man_t * p, Hop_Obj_t * pDriver )
Alan Mishchenko committed
68
{
Alan Mishchenko committed
69 70
    Hop_Obj_t * pObj;
    pObj = Hop_ManFetchMemory( p );
Alan Mishchenko committed
71 72 73 74 75
    pObj->Type = AIG_PO;
    Vec_PtrPush( p->vPos, pObj );
    // add connections
    pObj->pFanin0 = pDriver;
    if ( p->fRefCount )
Alan Mishchenko committed
76
        Hop_ObjRef( Hop_Regular(pDriver) );
Alan Mishchenko committed
77
    else
Alan Mishchenko committed
78
        pObj->nRefs = Hop_ObjLevel( Hop_Regular(pDriver) );
Alan Mishchenko committed
79
    // set the phase
Alan Mishchenko committed
80
    pObj->fPhase = Hop_ObjPhaseCompl(pDriver);
Alan Mishchenko committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    // update node counters of the manager
    p->nObjs[AIG_PO]++;
    return pObj;
}

/**Function*************************************************************

  Synopsis    [Create the new node assuming it does not exist.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
97
Hop_Obj_t * Hop_ObjCreate( Hop_Man_t * p, Hop_Obj_t * pGhost )
Alan Mishchenko committed
98
{
Alan Mishchenko committed
99 100 101
    Hop_Obj_t * pObj;
    assert( !Hop_IsComplement(pGhost) );
    assert( Hop_ObjIsNode(pGhost) );
Alan Mishchenko committed
102 103
    assert( pGhost == &p->Ghost );
    // get memory for the new object
Alan Mishchenko committed
104
    pObj = Hop_ManFetchMemory( p );
Alan Mishchenko committed
105 106
    pObj->Type = pGhost->Type;
    // add connections
Alan Mishchenko committed
107
    Hop_ObjConnect( p, pObj, pGhost->pFanin0, pGhost->pFanin1 );
Alan Mishchenko committed
108
    // update node counters of the manager
Alan Mishchenko committed
109
    p->nObjs[Hop_ObjType(pObj)]++;
Alan Mishchenko committed
110
    assert( pObj->pData == NULL );
Alan Mishchenko committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124
    return pObj;
}

/**Function*************************************************************

  Synopsis    [Connect the object to the fanin.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
125
void Hop_ObjConnect( Hop_Man_t * p, Hop_Obj_t * pObj, Hop_Obj_t * pFan0, Hop_Obj_t * pFan1 )
Alan Mishchenko committed
126
{
Alan Mishchenko committed
127 128
    assert( !Hop_IsComplement(pObj) );
    assert( Hop_ObjIsNode(pObj) );
Alan Mishchenko committed
129 130 131 132 133 134 135
    // add the first fanin
    pObj->pFanin0 = pFan0;
    pObj->pFanin1 = pFan1;
    // increment references of the fanins and add their fanouts
    if ( p->fRefCount )
    {
        if ( pFan0 != NULL )
Alan Mishchenko committed
136
            Hop_ObjRef( Hop_ObjFanin0(pObj) );
Alan Mishchenko committed
137
        if ( pFan1 != NULL )
Alan Mishchenko committed
138
            Hop_ObjRef( Hop_ObjFanin1(pObj) );
Alan Mishchenko committed
139 140
    }
    else
Alan Mishchenko committed
141
        pObj->nRefs = Hop_ObjLevelNew( pObj );
Alan Mishchenko committed
142
    // set the phase
Alan Mishchenko committed
143
    pObj->fPhase = Hop_ObjPhaseCompl(pFan0) & Hop_ObjPhaseCompl(pFan1);
Alan Mishchenko committed
144
    // add the node to the structural hash table
Alan Mishchenko committed
145
    Hop_TableInsert( p, pObj );
Alan Mishchenko committed
146 147 148 149 150 151 152 153 154 155 156 157 158
}

/**Function*************************************************************

  Synopsis    [Connect the object to the fanin.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
159
void Hop_ObjDisconnect( Hop_Man_t * p, Hop_Obj_t * pObj )
Alan Mishchenko committed
160
{
Alan Mishchenko committed
161 162
    assert( !Hop_IsComplement(pObj) );
    assert( Hop_ObjIsNode(pObj) );
Alan Mishchenko committed
163 164
    // remove connections
    if ( pObj->pFanin0 != NULL )
Alan Mishchenko committed
165
        Hop_ObjDeref(Hop_ObjFanin0(pObj));
Alan Mishchenko committed
166
    if ( pObj->pFanin1 != NULL )
Alan Mishchenko committed
167
        Hop_ObjDeref(Hop_ObjFanin1(pObj));
Alan Mishchenko committed
168
    // remove the node from the structural hash table
Alan Mishchenko committed
169
    Hop_TableDelete( p, pObj );
Alan Mishchenko committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    // add the first fanin
    pObj->pFanin0 = NULL;
    pObj->pFanin1 = NULL;
}

/**Function*************************************************************

  Synopsis    [Deletes the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
186
void Hop_ObjDelete( Hop_Man_t * p, Hop_Obj_t * pObj )
Alan Mishchenko committed
187
{
Alan Mishchenko committed
188 189 190
    assert( !Hop_IsComplement(pObj) );
    assert( !Hop_ObjIsTerm(pObj) );
    assert( Hop_ObjRefs(pObj) == 0 );
Alan Mishchenko committed
191 192 193 194
    // update node counters of the manager
    p->nObjs[pObj->Type]--;
    p->nDeleted++;
    // remove connections
Alan Mishchenko committed
195
    Hop_ObjDisconnect( p, pObj );
Alan Mishchenko committed
196
    // remove PIs/POs from the arrays
Alan Mishchenko committed
197
    if ( Hop_ObjIsPi(pObj) )
Alan Mishchenko committed
198
        Vec_PtrRemove( p->vPis, pObj );
Alan Mishchenko committed
199
    // free the node
Alan Mishchenko committed
200
    Hop_ManRecycleMemory( p, pObj );
Alan Mishchenko committed
201 202 203 204 205 206 207 208 209 210 211 212 213
}

/**Function*************************************************************

  Synopsis    [Deletes the MFFC of the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
214
void Hop_ObjDelete_rec( Hop_Man_t * p, Hop_Obj_t * pObj )
Alan Mishchenko committed
215
{
Alan Mishchenko committed
216 217 218
    Hop_Obj_t * pFanin0, * pFanin1;
    assert( !Hop_IsComplement(pObj) );
    if ( Hop_ObjIsConst1(pObj) || Hop_ObjIsPi(pObj) )
Alan Mishchenko committed
219
        return;
Alan Mishchenko committed
220 221 222 223 224 225 226 227
    assert( Hop_ObjIsNode(pObj) );
    pFanin0 = Hop_ObjFanin0(pObj);
    pFanin1 = Hop_ObjFanin1(pObj);
    Hop_ObjDelete( p, pObj );
    if ( pFanin0 && !Hop_ObjIsNone(pFanin0) && Hop_ObjRefs(pFanin0) == 0 )
        Hop_ObjDelete_rec( p, pFanin0 );
    if ( pFanin1 && !Hop_ObjIsNone(pFanin1) && Hop_ObjRefs(pFanin1) == 0 )
        Hop_ObjDelete_rec( p, pFanin1 );
Alan Mishchenko committed
228 229
}

Alan Mishchenko committed
230 231 232 233 234 235 236 237 238 239 240 241 242
/**Function*************************************************************

  Synopsis    [Returns the representative of the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Hop_Obj_t * Hop_ObjRepr( Hop_Obj_t * pObj )
{
Alan Mishchenko committed
243 244 245
    assert( !Hop_IsComplement(pObj) );
    if ( pObj->pData == NULL || pObj->pData == pObj )
        return pObj;
246
    return Hop_ObjRepr( (Hop_Obj_t *)pObj->pData );
Alan Mishchenko committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
}

/**Function*************************************************************

  Synopsis    [Sets an equivalence relation between the nodes.]

  Description [Makes the representative of pNew point to the representaive of pOld.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Hop_ObjCreateChoice( Hop_Obj_t * pOld, Hop_Obj_t * pNew )
{
    Hop_Obj_t * pOldRepr;
    Hop_Obj_t * pNewRepr;
    assert( pOld != NULL && pNew != NULL );
    pOldRepr = Hop_ObjRepr(pOld);
    pNewRepr = Hop_ObjRepr(pNew);
    if ( pNewRepr != pOldRepr )
        pNewRepr->pData = pOldRepr;
}

Alan Mishchenko committed
271 272 273 274 275
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


276 277
ABC_NAMESPACE_IMPL_END