abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
reoApi.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [reoApi.c]
4 
5  PackageName [REO: A specialized DD reordering engine.]
6 
7  Synopsis [Implementation of API functions.]
8 
9  Author [Alan Mishchenko]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - October 15, 2002.]
14 
15  Revision [$Id: reoApi.c,v 1.0 2002/15/10 03:00:00 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "reo.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// FUNCTION DEFINITIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 /**Function*************************************************************
33 
34  Synopsis [Initializes the reordering engine.]
35 
36  Description [The first argument is the max number of variables in the
37  CUDD DD manager which will be used with the reordering engine
38  (this number of should be the maximum of BDD and ZDD parts).
39  The second argument is the maximum number of BDD nodes in the BDDs
40  to be reordered. These limits are soft. Setting lower limits will later
41  cause the reordering manager to resize internal data structures.
42  However, setting the exact values will make reordering more efficient
43  because resizing will be not necessary.]
44 
45  SideEffects []
46 
47  SeeAlso []
48 
49 ***********************************************************************/
50 reo_man * Extra_ReorderInit( int nDdVarsMax, int nNodesMax )
51 {
52  reo_man * p;
53  // allocate and clean the data structure
54  p = ABC_ALLOC( reo_man, 1 );
55  memset( p, 0, sizeof(reo_man) );
56  // resize the manager to meet user's needs
57  reoResizeStructures( p, nDdVarsMax, nNodesMax, 100 );
58  // set the defaults
59  p->fMinApl = 0;
60  p->fMinWidth = 0;
61  p->fRemapUp = 0;
62  p->fVerbose = 0;
63  p->fVerify = 0;
64  p->nIters = 1;
65  return p;
66 }
67 
68 /**Function*************************************************************
69 
70  Synopsis [Disposes of the reordering engine.]
71 
72  Description [Removes all memory associated with the reordering engine.]
73 
74  SideEffects []
75 
76  SeeAlso []
77 
78 ***********************************************************************/
80 {
81  ABC_FREE( p->pTops );
82  ABC_FREE( p->pSupp );
83  ABC_FREE( p->pOrderInt );
84  ABC_FREE( p->pWidthCofs );
85  ABC_FREE( p->pMapToPlanes );
88  ABC_FREE( p->pPlanes );
89  ABC_FREE( p->pVarCosts );
90  ABC_FREE( p->pLevelOrder );
91  ABC_FREE( p->HTable );
92  ABC_FREE( p->pRefNodes );
94  ABC_FREE( p->pMemChunks );
95  ABC_FREE( p );
96 }
97 
98 /**Function*************************************************************
99 
100  Synopsis [Sets the type of DD minimizationl that will be performed.]
101 
102  Description [Currently, three different types of minimization are supported.
103  It is possible to minimize the number of BDD nodes. This is a classical type
104  of minimization, which is attempting to reduce the total number of nodes in
105  the (shared) BDD of the given Boolean functions. It is also possible to
106  minimize the BDD width, defined as the sum total of the number of cofactors
107  on each level in the (shared) BDD (note that the number of cofactors on the
108  given level may be larger than the number of nodes appearing on the given level).
109  It is also possible to minimize the average path length in the (shared) BDD
110  defined as the sum of products, for all BDD paths from the top node to any
111  terminal node, of the number of minterms on the path by the number of nodes
112  on the path. The default reordering type is minimization for the number of
113  BDD nodes. Calling this function with REO_MINIMIZE_WIDTH or REO_MINIMIZE_APL
114  as the second argument, changes the default minimization option for all the
115  reorder calls performed afterwards.]
116 
117  SideEffects []
118 
119  SeeAlso []
120 
121 ***********************************************************************/
123 {
124  if ( fMinType == REO_MINIMIZE_NODES )
125  {
126  p->fMinWidth = 0;
127  p->fMinApl = 0;
128  }
129  else if ( fMinType == REO_MINIMIZE_WIDTH )
130  {
131  p->fMinWidth = 1;
132  p->fMinApl = 0;
133  }
134  else if ( fMinType == REO_MINIMIZE_APL )
135  {
136  p->fMinWidth = 0;
137  p->fMinApl = 1;
138  }
139  else
140  {
141  assert( 0 );
142  }
143 }
144 
145 /**Function*************************************************************
146 
147  Synopsis [Sets the type of remapping performed by the engine.]
148 
149  Description [The remapping refers to the way the resulting BDD
150  is expressed using the elementary variables of the CUDD BDD manager.
151  Currently, two types possibilities are supported: remapping and no
152  remapping. Remapping means that the function(s) after reordering
153  depend on the topmost variables in the manager. No remapping means
154  that the function(s) after reordering depend on the same variables
155  as before. Consider the following example. Suppose the initial four
156  variable function depends on variables 2,4,5, and 9 on the CUDD BDD
157  manager, which may be found anywhere in the current variable order.
158  If remapping is set, the function after ordering depends on the
159  topmost variables in the manager, which may or may not be the same
160  as the variables 2,4,5, and 9. If no remapping is set, then the
161  reordered function depend on the same variables 2,4,5, and 9, but
162  the meaning of each variale has changed according to the new ordering.
163  The resulting ordering is returned in the array "pOrder" filled out
164  by the reordering engine in the call to Extra_Reorder(). The default
165  is no remapping.]
166 
167  SideEffects []
168 
169  SeeAlso []
170 
171 ***********************************************************************/
172 void Extra_ReorderSetRemapping( reo_man * p, int fRemapUp )
173 {
174  p->fRemapUp = fRemapUp;
175 }
176 
177 /**Function*************************************************************
178 
179  Synopsis [Sets the number of iterations of sifting performed.]
180 
181  Description [The default is one iteration. But a higher minimization
182  quality is desired, it is possible to set the number of iterations
183  to any number larger than 1. Convergence is often reached after
184  several iterations, so typically it make no sense to set the number
185  of iterations higher than 3.]
186 
187  SideEffects []
188 
189  SeeAlso []
190 
191 ***********************************************************************/
192 void Extra_ReorderSetIterations( reo_man * p, int nIters )
193 {
194  p->nIters = nIters;
195 }
196 
197 /**Function*************************************************************
198 
199  Synopsis [Sets the verification mode.]
200 
201  Description [Setting the level to 1 results in verifying the results
202  of variable reordering. Verification is performed by remapping the
203  resulting functions into the original variable order and comparing
204  them with the original functions given by the user. Enabling verification
205  typically leads to 20-30% increase in the total runtime of REO.]
206 
207  SideEffects []
208 
209  SeeAlso []
210 
211 ***********************************************************************/
212 void Extra_ReorderSetVerification( reo_man * p, int fVerify )
213 {
214  p->fVerify = fVerify;
215 }
216 
217 /**Function*************************************************************
218 
219  Synopsis [Sets the verbosity level.]
220 
221  Description [Setting the level to 1 results in printing statistics
222  before and after the reordering.]
223 
224  SideEffects []
225 
226  SeeAlso []
227 
228 ***********************************************************************/
229 void Extra_ReorderSetVerbosity( reo_man * p, int fVerbose )
230 {
231  p->fVerbose = fVerbose;
232 }
233 
234 /**Function*************************************************************
235 
236  Synopsis [Performs reordering of the function.]
237 
238  Description [Returns the DD minimized by variable reordering in the REO
239  engine. Takes the CUDD decision diagram manager (dd) and the function (Func)
240  represented as a BDD or ADD (MTBDD). If the variable array (pOrder) is not NULL,
241  returns the resulting variable permutation. The permutation is such that if the resulting
242  function is permuted by Cudd_(add,bdd)Permute() using pOrder as the permutation
243  array, the initial function (Func) results.
244  Several flag set by other interface functions specify reordering options:
245  - Remappig can be set by Extra_ReorderSetRemapping(). Then the resulting DD after
246  reordering is remapped into the topmost levels of the DD manager. Otherwise,
247  the resulting DD after reordering is mapped using the same variables, on which it
248  originally depended, only (possibly) permuted as a result of reordering.
249  - Minimization type can be set by Extra_ReorderSetMinimizationType(). Note
250  that when the BDD is minimized for the total width of the total APL, the number
251  BDD nodes can increase. The total width is defines as sum total of widths on each
252  level. The width on one level is defined as the number of distinct BDD nodes
253  pointed by the nodes situated above the given level.
254  - The number of iterations of sifting can be set by Extra_ReorderSetIterations().
255  The decision diagram returned by this procedure is not referenced.]
256 
257  SideEffects []
258 
259  SeeAlso []
260 
261 ***********************************************************************/
262 DdNode * Extra_Reorder( reo_man * p, DdManager * dd, DdNode * Func, int * pOrder )
263 {
264  DdNode * FuncRes;
265  Extra_ReorderArray( p, dd, &Func, &FuncRes, 1, pOrder );
266  Cudd_Deref( FuncRes );
267  return FuncRes;
268 }
269 
270 /**Function*************************************************************
271 
272  Synopsis [Performs reordering of the array of functions.]
273 
274  Description [The options are similar to the procedure Extra_Reorder(), except that
275  the user should also provide storage for the resulting DDs, which are returned
276  referenced.]
277 
278  SideEffects []
279 
280  SeeAlso []
281 
282 ***********************************************************************/
283 void Extra_ReorderArray( reo_man * p, DdManager * dd, DdNode * Funcs[], DdNode * FuncsRes[], int nFuncs, int * pOrder )
284 {
285  reoReorderArray( p, dd, Funcs, FuncsRes, nFuncs, pOrder );
286 }
287 
288 
289 ////////////////////////////////////////////////////////////////////////
290 /// END OF FILE ///
291 ////////////////////////////////////////////////////////////////////////
292 
294 
void Extra_ReorderSetVerbosity(reo_man *p, int fVerbose)
Definition: reoApi.c:229
char * memset()
int fMinApl
Definition: reo.h:105
int fVerbose
Definition: reo.h:106
void reoReorderArray(reo_man *p, DdManager *dd, DdNode *Funcs[], DdNode *FuncsRes[], int nFuncs, int *pOrder)
FUNCTION DEFINITIONS ///.
Definition: reoCore.c:50
Definition: cudd.h:278
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Extra_ReorderQuit(reo_man *p)
Definition: reoApi.c:79
void Cudd_Deref(DdNode *node)
Definition: cuddRef.c:438
reo_unit ** pWidthCofs
Definition: reo.h:123
double * pVarCosts
Definition: reo.h:121
int * pMapToPlanes
Definition: reo.h:137
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
ABC_NAMESPACE_IMPL_START reo_man * Extra_ReorderInit(int nDdVarsMax, int nNodesMax)
DECLARATIONS ///.
Definition: reoApi.c:50
int * pMapToDdVarsFinal
Definition: reo.h:139
int fRemapUp
Definition: reo.h:108
void reoUnitsStopDispenser(reo_man *p)
Definition: reoUnits.c:115
int * pLevelOrder
Definition: reo.h:122
void Extra_ReorderSetRemapping(reo_man *p, int fRemapUp)
Definition: reoApi.c:172
int fMinWidth
Definition: reo.h:104
void reoResizeStructures(reo_man *p, int nDdVarsMax, int nNodesMax, int nFuncs)
Definition: reoCore.c:269
DdNode * Extra_Reorder(reo_man *p, DdManager *dd, DdNode *Func, int *pOrder)
Definition: reoApi.c:262
DdNode ** pRefNodes
Definition: reo.h:155
int nIters
Definition: reo.h:109
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void Extra_ReorderSetMinimizationType(reo_man *p, reo_min_type fMinType)
Definition: reoApi.c:122
reo_hash * HTable
Definition: reo.h:149
void Extra_ReorderArray(reo_man *p, DdManager *dd, DdNode *Funcs[], DdNode *FuncsRes[], int nFuncs, int *pOrder)
Definition: reoApi.c:283
reo_unit ** pTops
Definition: reo.h:144
void Extra_ReorderSetVerification(reo_man *p, int fVerify)
Definition: reoApi.c:212
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int * pSupp
Definition: reo.h:117
int * pMapToDdVarsOrig
Definition: reo.h:138
reo_plane * pPlanes
Definition: reo.h:142
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Extra_ReorderSetIterations(reo_man *p, int nIters)
Definition: reoApi.c:192
reo_unit ** pMemChunks
Definition: reo.h:161
#define assert(ex)
Definition: util_old.h:213
int fVerify
Definition: reo.h:107
reo_min_type
Definition: reo.h:50
int * pOrderInt
Definition: reo.h:120
Definition: reo.h:101