abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
reo.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [reo.h]
4 
5  PackageName [REO: A specialized DD reordering engine.]
6 
7  Synopsis [External and internal declarations.]
8 
9  Author [Alan Mishchenko]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - October 15, 2002.]
14 
15  Revision [$Id: reo.h,v 1.0 2002/15/10 03:00:00 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #ifndef ABC__bdd__reo__reo_h
20 #define ABC__bdd__reo__reo_h
21 
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include "misc/extra/extraBdd.h"
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// MACRO DEFINITIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 
32 
34 
35 
36 // reordering parameters
37 #define REO_REORDER_LIMIT 1.15 // determines the quality/runtime trade-off
38 #define REO_QUAL_PAR 3 // the quality [1 = simple lower bound, 2 = strict, larger = heuristic]
39 // internal parameters
40 #define REO_CONST_LEVEL 30000 // the number of the constant level
41 #define REO_TOPREF_UNDEF 30000 // the undefined top reference
42 #define REO_CHUNK_SIZE 5000 // the number of units allocated at one time
43 #define REO_COST_EPSILON 0.0000001 // difference in cost large enough so that it counted as an error
44 #define REO_HIGH_VALUE 10000000 // a large value used to initialize some variables
45 // interface parameters
46 #define REO_ENABLE 1 // the value of the enable flag
47 #define REO_DISABLE 0 // the value of the disable flag
48 
49 // the types of minimization currently supported
50 typedef enum {
52  REO_MINIMIZE_WIDTH, // may not work for BDDs with complemented edges
54 } reo_min_type;
55 
56 ////////////////////////////////////////////////////////////////////////
57 /// DATA STRUCTURES ///
58 ////////////////////////////////////////////////////////////////////////
59 
60 typedef struct _reo_unit reo_unit; // the unit representing one DD node during reordering
61 typedef struct _reo_plane reo_plane; // the set of nodes on one level
62 typedef struct _reo_hash reo_hash; // the entry in the hash table
63 typedef struct _reo_man reo_man; // the reordering manager
64 typedef struct _reo_test reo_test; //
65 
66 struct _reo_unit
67 {
68  short lev; // the level of this node at the beginning
69  short TopRef; // the top level from which this node is refed (used to update BDD width)
70  short TopRefNew; // the new top level from which this node is refed (used to update BDD width)
71  short n; // the number of incoming edges (similar to ref count in the BDD)
72  int Sign; // the signature
73 
74  reo_unit * pE; // the pointer to the "else" branch
75  reo_unit * pT; // the pointer to the "then" branch
76  reo_unit * Next; // the link to the next one in the list
77  double Weight; // the probability of traversing this node
78 };
79 
80 struct _reo_plane
81 {
82  int fSifted; // to mark the sifted variables
83  int statsNodes; // the number of nodes in the current level
84  int statsWidth; // the width on the current level
85  double statsApl; // the sum of node probabilities on this level
86  double statsCost; // the current cost is stored here
87  double statsCostAbove; // the current cost is stored here
88  double statsCostBelow; // the current cost is stored here
89 
90  reo_unit * pHead; // the pointer to the beginning of the unit list
91 };
92 
93 struct _reo_hash
94 {
95  int Sign; // signature of the current cache operation
96  reo_unit * Arg1; // the first argument
97  reo_unit * Arg2; // the second argument
98  reo_unit * Arg3; // the third argument
99 };
100 
101 struct _reo_man
102 {
103  // these paramaters can be set by the API functions
104  int fMinWidth; // the flag to enable reordering for minimum width
105  int fMinApl; // the flag to enable reordering for minimum APL
106  int fVerbose; // the verbosity level
107  int fVerify; // the flag toggling verification
108  int fRemapUp; // the flag to enable remapping
109  int nIters; // the number of interations of sifting to perform
110 
111  // parameters given by the user when reordering is called
112  DdManager * dd; // the CUDD BDD manager
113  int * pOrder; // the resulting variable order will be returned here
114 
115  // derived parameters
116  int fThisIsAdd; // this flag is one if the function is the ADD
117  int * pSupp; // the support of the given function
118  int nSuppAlloc; // the max allowed number of support variables
119  int nSupp; // the number of support variables
120  int * pOrderInt; // the array storing the internal variable permutation
121  double * pVarCosts; // other arrays
122  int * pLevelOrder; // other arrays
123  reo_unit ** pWidthCofs; // temporary storage for cofactors used during reordering for width
124 
125  // parameters related to cost
132  double nAplCur;
133  double nAplBeg;
134  double nAplEnd;
135 
136  // mapping of the function into planes and back
137  int * pMapToPlanes; // the mapping of var indexes into plane levels
138  int * pMapToDdVarsOrig;// the mapping of plane levels into the original indexes
139  int * pMapToDdVarsFinal;// the mapping of plane levels into the final indexes
140 
141  // the planes table
143  int nPlanes;
145  int nTops;
147 
148  // the hash table
149  reo_hash * HTable; // the table itself
150  int nTableSize; // the size of the hash table
151  int Signature; // the signature counter
152 
153  // the referenced node list
154  int nNodesMaxAlloc; // this parameters determins how much memory is allocated
158 
159  // unit memory management
165 
166  // statistic variables
169  int nSwaps; // the number of swaps
170  int nNISwaps; // the number of swaps without interaction
171 };
172 
173 // used to manipulate units
174 #define Unit_Regular(u) ((reo_unit *)((ABC_PTRUINT_T)(u) & ~01))
175 #define Unit_Not(u) ((reo_unit *)((ABC_PTRUINT_T)(u) ^ 01))
176 #define Unit_NotCond(u,c) ((reo_unit *)((ABC_PTRUINT_T)(u) ^ (c)))
177 #define Unit_IsConstant(u) ((int)((u)->lev == REO_CONST_LEVEL))
178 
179 ////////////////////////////////////////////////////////////////////////
180 /// FUNCTION DECLARATIONS ///
181 ////////////////////////////////////////////////////////////////////////
182 
183 // ======================= reoApi.c ========================================
184 extern reo_man * Extra_ReorderInit( int nDdVarsMax, int nNodesMax );
185 extern void Extra_ReorderQuit( reo_man * p );
186 extern void Extra_ReorderSetMinimizationType( reo_man * p, reo_min_type fMinType );
187 extern void Extra_ReorderSetRemapping( reo_man * p, int fRemapUp );
188 extern void Extra_ReorderSetIterations( reo_man * p, int nIters );
189 extern void Extra_ReorderSetVerbosity( reo_man * p, int fVerbose );
190 extern void Extra_ReorderSetVerification( reo_man * p, int fVerify );
191 extern DdNode * Extra_Reorder( reo_man * p, DdManager * dd, DdNode * Func, int * pOrder );
192 extern void Extra_ReorderArray( reo_man * p, DdManager * dd, DdNode * Funcs[], DdNode * FuncsRes[], int nFuncs, int * pOrder );
193 // ======================= reoCore.c =======================================
194 extern void reoReorderArray( reo_man * p, DdManager * dd, DdNode * Funcs[], DdNode * FuncsRes[], int nFuncs, int * pOrder );
195 extern void reoResizeStructures( reo_man * p, int nDdVarsMax, int nNodesMax, int nFuncs );
196 // ======================= reoProfile.c ======================================
197 extern void reoProfileNodesStart( reo_man * p );
198 extern void reoProfileAplStart( reo_man * p );
199 extern void reoProfileWidthStart( reo_man * p );
200 extern void reoProfileWidthStart2( reo_man * p );
201 extern void reoProfileAplPrint( reo_man * p );
202 extern void reoProfileNodesPrint( reo_man * p );
203 extern void reoProfileWidthPrint( reo_man * p );
204 extern void reoProfileWidthVerifyLevel( reo_plane * pPlane, int Level );
205 // ======================= reoSift.c =======================================
206 extern void reoReorderSift( reo_man * p );
207 // ======================= reoSwap.c =======================================
208 extern double reoReorderSwapAdjacentVars( reo_man * p, int Level, int fMovingUp );
209 // ======================= reoTransfer.c ===================================
211 extern DdNode * reoTransferUnitsToNodes_rec( reo_man * p, reo_unit * pUnit );
212 // ======================= reoUnits.c ======================================
214 extern void reoUnitsRecycleUnit( reo_man * p, reo_unit * pUnit );
215 extern void reoUnitsRecycleUnitList( reo_man * p, reo_plane * pPlane );
216 extern void reoUnitsAddUnitToPlane( reo_plane * pPlane, reo_unit * pUnit );
217 extern void reoUnitsStopDispenser( reo_man * p );
218 // ======================= reoTest.c =======================================
219 extern void Extra_ReorderTest( DdManager * dd, DdNode * Func );
220 extern DdNode * Extra_ReorderCudd( DdManager * dd, DdNode * aFunc, int pPermuteReo[] );
221 extern int Extra_bddReorderTest( DdManager * dd, DdNode * bF );
222 extern int Extra_addReorderTest( DdManager * dd, DdNode * aF );
223 
224 
225 
227 
228 
229 
230 #endif
231 
232 ////////////////////////////////////////////////////////////////////////
233 /// END OF FILE ///
234 ////////////////////////////////////////////////////////////////////////
int nPlanes
Definition: reo.h:143
int fMinApl
Definition: reo.h:105
void Extra_ReorderTest(DdManager *dd, DdNode *Func)
DECLARATIONS ///.
Definition: reoTest.c:43
int fVerbose
Definition: reo.h:106
int nWidthBeg
Definition: reo.h:130
short lev
Definition: reo.h:68
int Sign
Definition: reo.h:95
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
double Weight
Definition: reo.h:77
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void reoProfileAplStart(reo_man *p)
Definition: reoProfile.c:78
void Extra_ReorderSetVerbosity(reo_man *p, int fVerbose)
Definition: reoApi.c:229
reo_unit ** pWidthCofs
Definition: reo.h:123
double * pVarCosts
Definition: reo.h:121
double nAplCur
Definition: reo.h:132
void reoProfileWidthStart(reo_man *p)
Definition: reoProfile.c:130
int nTops
Definition: reo.h:145
void Extra_ReorderSetVerification(reo_man *p, int fVerify)
Definition: reoApi.c:212
DdNode * Extra_Reorder(reo_man *p, DdManager *dd, DdNode *Func, int *pOrder)
Definition: reoApi.c:262
DdNode * Extra_ReorderCudd(DdManager *dd, DdNode *aFunc, int pPermuteReo[])
Definition: reoTest.c:109
void reoProfileWidthPrint(reo_man *p)
Definition: reoProfile.c:321
DdManager * dd
Definition: reo.h:112
int nTopsAlloc
Definition: reo.h:146
reo_unit * reoTransferNodesToUnits_rec(reo_man *p, DdNode *F)
DECLARATIONS ///.
Definition: reoTransfer.c:43
reo_unit * reoUnitsGetNextUnit(reo_man *p)
FUNCTION DEFINITIONS ///.
Definition: reoUnits.c:45
int * pMapToPlanes
Definition: reo.h:137
int Signature
Definition: reo.h:151
int nNodesCur
Definition: reo.h:127
double statsCostBelow
Definition: reo.h:88
int nUnitsUsed
Definition: reo.h:164
int fThisIsAdd
Definition: reo.h:116
int nNodesMaxAlloc
Definition: reo.h:154
int nSupp
Definition: reo.h:119
reo_unit * Arg2
Definition: reo.h:97
DdNode * reoTransferUnitsToNodes_rec(reo_man *p, reo_unit *pUnit)
Definition: reoTransfer.c:120
int statsWidth
Definition: reo.h:84
void Extra_ReorderSetMinimizationType(reo_man *p, reo_min_type fMinType)
Definition: reoApi.c:122
int nMemChunks
Definition: reo.h:162
void reoUnitsRecycleUnitList(reo_man *p, reo_plane *pPlane)
Definition: reoUnits.c:87
double statsCostAbove
Definition: reo.h:87
int nRefNodes
Definition: reo.h:156
double nAplBeg
Definition: reo.h:133
int nNISwaps
Definition: reo.h:170
int * pOrder
Definition: reo.h:113
reo_unit * pUnitFreeList
Definition: reo.h:160
int Extra_bddReorderTest(DdManager *dd, DdNode *bF)
Definition: reoTest.c:180
int * pMapToDdVarsFinal
Definition: reo.h:139
void reoUnitsAddUnitToPlane(reo_plane *pPlane, reo_unit *pUnit)
Definition: reoUnits.c:135
int fRemapUp
Definition: reo.h:108
void reoUnitsStopDispenser(reo_man *p)
Definition: reoUnits.c:115
int nSuppAlloc
Definition: reo.h:118
int HashFailure
Definition: reo.h:168
void reoProfileWidthVerifyLevel(reo_plane *pPlane, int Level)
Definition: reoProfile.c:354
int * pLevelOrder
Definition: reo.h:122
reo_unit * pT
Definition: reo.h:75
int fMinWidth
Definition: reo.h:104
void reoProfileNodesStart(reo_man *p)
DECLARATIONS ///.
Definition: reoProfile.c:46
int Extra_addReorderTest(DdManager *dd, DdNode *aF)
Definition: reoTest.c:217
void reoResizeStructures(reo_man *p, int nDdVarsMax, int nNodesMax, int nFuncs)
Definition: reoCore.c:269
DdNode ** pRefNodes
Definition: reo.h:155
reo_unit * Next
Definition: reo.h:76
short TopRef
Definition: reo.h:69
short n
Definition: reo.h:71
int nNodesBeg
Definition: reo.h:126
int nIters
Definition: reo.h:109
reo_unit * pE
Definition: reo.h:74
void Extra_ReorderArray(reo_man *p, DdManager *dd, DdNode *Funcs[], DdNode *FuncsRes[], int nFuncs, int *pOrder)
Definition: reoApi.c:283
reo_hash * HTable
Definition: reo.h:149
int nTableSize
Definition: reo.h:150
short TopRefNew
Definition: reo.h:70
double statsCost
Definition: reo.h:86
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
int nRefNodesAlloc
Definition: reo.h:157
Definition: reo.h:80
reo_unit ** pTops
Definition: reo.h:144
void reoProfileAplPrint(reo_man *p)
Definition: reoProfile.c:305
double statsApl
Definition: reo.h:85
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
void reoReorderSift(reo_man *p)
DECLARATIONS ///.
Definition: reoSift.c:44
double reoReorderSwapAdjacentVars(reo_man *p, int Level, int fMovingUp)
FUNCTION DEFINITIONS ///.
Definition: reoSwap.c:46
int * pSupp
Definition: reo.h:117
int * pMapToDdVarsOrig
Definition: reo.h:138
int Sign
Definition: reo.h:72
reo_plane * pPlanes
Definition: reo.h:142
int nMemChunksAlloc
Definition: reo.h:163
int nSwaps
Definition: reo.h:169
reo_unit * Arg3
Definition: reo.h:98
int nWidthEnd
Definition: reo.h:131
void reoUnitsRecycleUnit(reo_man *p, reo_unit *pUnit)
Definition: reoUnits.c:69
reo_unit * Arg1
Definition: reo.h:96
Definition: reo.h:66
void reoProfileNodesPrint(reo_man *p)
Definition: reoProfile.c:289
void Extra_ReorderSetIterations(reo_man *p, int nIters)
Definition: reoApi.c:192
reo_unit ** pMemChunks
Definition: reo.h:161
reo_man * Extra_ReorderInit(int nDdVarsMax, int nNodesMax)
FUNCTION DECLARATIONS ///.
Definition: reoApi.c:50
void Extra_ReorderQuit(reo_man *p)
Definition: reoApi.c:79
int fVerify
Definition: reo.h:107
int nNodesEnd
Definition: reo.h:128
int HashSuccess
Definition: reo.h:167
void reoProfileWidthStart2(reo_man *p)
Definition: reoProfile.c:222
reo_min_type
Definition: reo.h:50
int statsNodes
Definition: reo.h:83
reo_unit * pHead
Definition: reo.h:90
void Extra_ReorderSetRemapping(reo_man *p, int fRemapUp)
Definition: reoApi.c:172
double nAplEnd
Definition: reo.h:134
int * pOrderInt
Definition: reo.h:120
int fSifted
Definition: reo.h:82
struct _reo_test reo_test
Definition: reo.h:64
int nWidthCur
Definition: reo.h:129
Definition: reo.h:101
Definition: reo.h:93