#include "reo.h"
Go to the source code of this file.
Functions | |
reo_unit * | reoTransferNodesToUnits_rec (reo_man *p, DdNode *F) |
DdNode * | reoTransferUnitsToNodes_rec (reo_man *p, reo_unit *pUnit) |
CFile****************************************************************
FileName [reoTransfer.c]
PackageName [REO: A specialized DD reordering engine.]
Synopsis [Transfering a DD from the CUDD manager into REOs internal data structures and back.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - October 15, 2002.]
Revision [
] DECLARATIONS /// FUNCTION DEFINITIONS ///Function*************************************************************
Synopsis [Transfers the DD into the internal reordering data structure.]
Description [It is important that the hash table is lossless.]
SideEffects []
SeeAlso []
Definition at line 40 of file reoTransfer.c.
00041 { 00042 DdManager * dd = p->dd; 00043 reo_unit * pUnit; 00044 int HKey, fComp; 00045 00046 fComp = Cudd_IsComplement(F); 00047 F = Cudd_Regular(F); 00048 00049 // check the hash-table 00050 if ( F->ref != 1 ) 00051 { 00052 // search cache - use linear probing 00053 for ( HKey = hashKey2(p->Signature,F,p->nTableSize); p->HTable[HKey].Sign == p->Signature; HKey = (HKey+1) % p->nTableSize ) 00054 if ( p->HTable[HKey].Arg1 == (reo_unit *)F ) 00055 { 00056 pUnit = p->HTable[HKey].Arg2; 00057 assert( pUnit ); 00058 // increment the edge counter 00059 pUnit->n++; 00060 return Unit_NotCond( pUnit, fComp ); 00061 } 00062 } 00063 // the entry in not found in the cache 00064 00065 // create a new entry 00066 pUnit = reoUnitsGetNextUnit( p ); 00067 pUnit->n = 1; 00068 if ( cuddIsConstant(F) ) 00069 { 00070 pUnit->lev = REO_CONST_LEVEL; 00071 pUnit->pE = (reo_unit*)((int)(cuddV(F))); 00072 pUnit->pT = NULL; 00073 // check if the diagram that is being reordering has complement edges 00074 if ( F != dd->one ) 00075 p->fThisIsAdd = 1; 00076 // insert the unit into the corresponding plane 00077 reoUnitsAddUnitToPlane( &(p->pPlanes[p->nSupp]), pUnit ); // increments the unit counter 00078 } 00079 else 00080 { 00081 pUnit->lev = p->pMapToPlanes[F->index]; 00082 pUnit->pE = reoTransferNodesToUnits_rec( p, cuddE(F) ); 00083 pUnit->pT = reoTransferNodesToUnits_rec( p, cuddT(F) ); 00084 // insert the unit into the corresponding plane 00085 reoUnitsAddUnitToPlane( &(p->pPlanes[pUnit->lev]), pUnit ); // increments the unit counter 00086 } 00087 00088 // add to the hash table 00089 if ( F->ref != 1 ) 00090 { 00091 // the next free entry is already found - it is pointed to by HKey 00092 // while we traversed the diagram, the hash entry to which HKey points, 00093 // might have been used. Make sure that its signature is different. 00094 for ( ; p->HTable[HKey].Sign == p->Signature; HKey = (HKey+1) % p->nTableSize ); 00095 p->HTable[HKey].Sign = p->Signature; 00096 p->HTable[HKey].Arg1 = (reo_unit *)F; 00097 p->HTable[HKey].Arg2 = pUnit; 00098 } 00099 00100 // increment the counter of nodes 00101 p->nNodesCur++; 00102 return Unit_NotCond( pUnit, fComp ); 00103 }
Function*************************************************************
Synopsis [Creates the DD from the internal reordering data structure.]
Description [It is important that the hash table is lossless.]
SideEffects []
SeeAlso []
Definition at line 116 of file reoTransfer.c.
00117 { 00118 DdManager * dd = p->dd; 00119 DdNode * bRes, * E, * T; 00120 int HKey, fComp; 00121 00122 fComp = Cudd_IsComplement(pUnit); 00123 pUnit = Unit_Regular(pUnit); 00124 00125 // check the hash-table 00126 if ( pUnit->n != 1 ) 00127 { 00128 for ( HKey = hashKey2(p->Signature,pUnit,p->nTableSize); p->HTable[HKey].Sign == p->Signature; HKey = (HKey+1) % p->nTableSize ) 00129 if ( p->HTable[HKey].Arg1 == pUnit ) 00130 { 00131 bRes = (DdNode*) p->HTable[HKey].Arg2; 00132 assert( bRes ); 00133 return Cudd_NotCond( bRes, fComp ); 00134 } 00135 } 00136 00137 // treat the case of constants 00138 if ( Unit_IsConstant(pUnit) ) 00139 { 00140 bRes = cuddUniqueConst( dd, ((double)((int)(pUnit->pE))) ); 00141 cuddRef( bRes ); 00142 } 00143 else 00144 { 00145 // split and recur on children of this node 00146 E = reoTransferUnitsToNodes_rec( p, pUnit->pE ); 00147 if ( E == NULL ) 00148 return NULL; 00149 cuddRef(E); 00150 00151 T = reoTransferUnitsToNodes_rec( p, pUnit->pT ); 00152 if ( T == NULL ) 00153 { 00154 Cudd_RecursiveDeref(dd, E); 00155 return NULL; 00156 } 00157 cuddRef(T); 00158 00159 // consider the case when Res0 and Res1 are the same node 00160 assert( E != T ); 00161 assert( !Cudd_IsComplement(T) ); 00162 00163 bRes = cuddUniqueInter( dd, p->pMapToDdVarsFinal[pUnit->lev], T, E ); 00164 if ( bRes == NULL ) 00165 { 00166 Cudd_RecursiveDeref(dd,E); 00167 Cudd_RecursiveDeref(dd,T); 00168 return NULL; 00169 } 00170 cuddRef( bRes ); 00171 cuddDeref( E ); 00172 cuddDeref( T ); 00173 } 00174 00175 // do not keep the result if the ref count is only 1, since it will not be visited again 00176 if ( pUnit->n != 1 ) 00177 { 00178 // while we traversed the diagram, the hash entry to which HKey points, 00179 // might have been used. Make sure that its signature is different. 00180 for ( ; p->HTable[HKey].Sign == p->Signature; HKey = (HKey+1) % p->nTableSize ); 00181 p->HTable[HKey].Sign = p->Signature; 00182 p->HTable[HKey].Arg1 = pUnit; 00183 p->HTable[HKey].Arg2 = (reo_unit *)bRes; 00184 00185 // add the DD to the referenced DD list in order to be able to store it in cache 00186 p->pRefNodes[p->nRefNodes++] = bRes; Cudd_Ref( bRes ); 00187 // no need to do this, because the garbage collection will not take bRes away 00188 // it is held by the diagram in the making 00189 } 00190 // increment the counter of nodes 00191 p->nNodesCur++; 00192 cuddDeref( bRes ); 00193 return Cudd_NotCond( bRes, fComp ); 00194 }