fretime.h 5.65 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/**CFile****************************************************************

  FileName    [fretime.h]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Flow-based retiming package.]

  Synopsis    [Header file for retiming package.]

  Author      [Aaron Hurst]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - January 1, 2008.]

  Revision    [$Id: fretime.h,v 1.00 2008/01/01 00:00:00 ahurst Exp $]

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

#if !defined(RETIME_H_)
#define RETIME_H_

24

Alan Mishchenko committed
25 26
#include "abc.h"

27 28 29
ABC_NAMESPACE_HEADER_START


Alan Mishchenko committed
30 31 32 33
// #define IGNORE_TIMING
// #define DEBUG_PRINT_FLOWS
// #define DEBUG_VISITED
// #define DEBUG_PREORDER
Alan Mishchenko committed
34 35
#define DEBUG_CHECK
// #define DEBUG_PRINT_LEVELS
Alan Mishchenko committed
36 37 38 39 40 41 42 43

////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

#define MAX_DIST 30000

// flags in Flow_Data structure...
Alan Mishchenko committed
44 45
#define VISITED_E       0x001
#define VISITED_R       0x002
Alan Mishchenko committed
46
#define VISITED  (VISITED_E | VISITED_R)
Alan Mishchenko committed
47 48 49 50 51
#define FLOW            0x004
#define CROSS_BOUNDARY  0x008
#define BLOCK           0x010
#define INIT_0          0x020
#define INIT_1          0x040
Alan Mishchenko committed
52
#define INIT_CARE (INIT_0 | INIT_1)
Alan Mishchenko committed
53
#define CONSERVATIVE    0x080
Alan Mishchenko committed
54
#define BLOCK_OR_CONS (BLOCK | CONSERVATIVE)
Alan Mishchenko committed
55
#define BIAS_NODE       0x100
Alan Mishchenko committed
56 57 58 59 60 61 62 63

typedef struct Flow_Data_t_ {
  unsigned int mark : 16;

  union {
    Abc_Obj_t   *pred;
    /* unsigned int var; */
    Abc_Obj_t   *pInitObj;
Alan Mishchenko committed
64
    Abc_Obj_t   *pCopy;
Alan Mishchenko committed
65 66 67 68 69 70 71 72
    Vec_Ptr_t   *vNodes;
  };

  unsigned int e_dist : 16;
  unsigned int r_dist : 16;
} Flow_Data_t;

// useful macros for manipulating Flow_Data structure...
Alan Mishchenko committed
73 74 75 76
#define FDATA( x )     (pManMR->pDataArray+Abc_ObjId(x))
#define FSET( x, y )   FDATA(x)->mark |= y
#define FUNSET( x, y ) FDATA(x)->mark &= ~y
#define FTEST( x, y )  (FDATA(x)->mark & y)
Alan Mishchenko committed
77 78
#define FTIMEEDGES( x )  &(pManMR->vTimeEdges[Abc_ObjId( x )])

Alan Mishchenko committed
79 80 81 82
typedef struct NodeLag_T_ {
  int id;
  int lag;
} NodeLag_t;
Alan Mishchenko committed
83

Alan Mishchenko committed
84 85 86 87 88 89 90
typedef struct InitConstraint_t_ {
  Abc_Obj_t *pBiasNode;

  Vec_Int_t  vNodes;
  Vec_Int_t  vLags;

} InitConstraint_t;
Alan Mishchenko committed
91 92 93 94 95

typedef struct MinRegMan_t_ {
 
  // problem description:
  int         maxDelay;
96
  int        fComputeInitState, fGuaranteeInitState, fBlockConst;
Alan Mishchenko committed
97
  int         nNodes, nLatches;
98 99
  int        fForwardOnly, fBackwardOnly;
  int        fConservTimingOnly;
Alan Mishchenko committed
100
  int         nMaxIters;
101
  int        fVerbose;
Alan Mishchenko committed
102 103 104 105 106
  Abc_Ntk_t  *pNtk;

  int         nPreRefine;

  // problem state
107 108
  int        fIsForward;
  int        fSinkDistTerminate;
Alan Mishchenko committed
109 110 111 112
  int         nExactConstraints, nConservConstraints;
  int         fSolutionIsDc;
  int         constraintMask;
  int         iteration, subIteration;
Alan Mishchenko committed
113
  Vec_Int_t  *vLags;
Alan Mishchenko committed
114 115 116 117 118 119
  
  // problem data
  Vec_Int_t   *vSinkDistHist;
  Flow_Data_t *pDataArray;
  Vec_Ptr_t   *vTimeEdges;
  Vec_Ptr_t   *vExactNodes;
Alan Mishchenko committed
120
  Vec_Ptr_t   *vInitConstraints;
Alan Mishchenko committed
121 122
  Abc_Ntk_t   *pInitNtk;
  Vec_Ptr_t   *vNodes; // re-useable struct
Alan Mishchenko committed
123 124 125 126
  
  NodeLag_t   *pInitToOrig;
  int          sizeInitToOrig;
  
Alan Mishchenko committed
127 128
} MinRegMan_t ;

Alan Mishchenko committed
129 130
extern MinRegMan_t *pManMR;

Alan Mishchenko committed
131 132
#define vprintf if (pManMR->fVerbose) printf 

Alan Mishchenko committed
133 134 135 136 137 138 139 140
static inline void FSETPRED(Abc_Obj_t *pObj, Abc_Obj_t *pPred) {
  assert(!Abc_ObjIsLatch(pObj)); // must preserve field to maintain init state linkage
  FDATA(pObj)->pred = pPred;
}
static inline Abc_Obj_t * FGETPRED(Abc_Obj_t *pObj) {
  return FDATA(pObj)->pred;
}

Alan Mishchenko committed
141 142
/*=== fretMain.c ==========================================================*/

Alan Mishchenko committed
143 144
Abc_Ntk_t *    Abc_FlowRetime_MinReg( Abc_Ntk_t * pNtk, int fVerbose,
                                      int fComputeInitState, int fGuaranteeInitState, int fBlockConst,
Alan Mishchenko committed
145 146 147 148 149 150 151
                                      int fForward, int fBackward, int nMaxIters,
                                      int maxDelay, int fFastButConservative);

void print_node(Abc_Obj_t *pObj);

void Abc_ObjBetterTransferFanout( Abc_Obj_t * pFrom, Abc_Obj_t * pTo, int compl );

152 153 154
int  Abc_FlowRetime_PushFlows( Abc_Ntk_t * pNtk, int fVerbose );
int Abc_FlowRetime_IsAcrossCut( Abc_Obj_t *pCur, Abc_Obj_t *pNext );
void Abc_FlowRetime_ClearFlows( int fClearAll );
Alan Mishchenko committed
155

Alan Mishchenko committed
156 157 158 159 160 161 162
int  Abc_FlowRetime_GetLag( Abc_Obj_t *pObj );
void Abc_FlowRetime_SetLag( Abc_Obj_t *pObj, int lag );

void Abc_FlowRetime_UpdateLags( );

void Abc_ObjPrintNeighborhood( Abc_Obj_t *pObj, int depth );

163
Abc_Ntk_t * Abc_FlowRetime_NtkSilentRestrash( Abc_Ntk_t * pNtk, int fCleanup );
Alan Mishchenko committed
164

Alan Mishchenko committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
/*=== fretFlow.c ==========================================================*/

int  dfsplain_e( Abc_Obj_t *pObj, Abc_Obj_t *pPred );
int  dfsplain_r( Abc_Obj_t *pObj, Abc_Obj_t *pPred );

void dfsfast_preorder( Abc_Ntk_t *pNtk );
int  dfsfast_e( Abc_Obj_t *pObj, Abc_Obj_t *pPred );
int  dfsfast_r( Abc_Obj_t *pObj, Abc_Obj_t *pPred );

/*=== fretInit.c ==========================================================*/

void Abc_FlowRetime_PrintInitStateInfo( Abc_Ntk_t * pNtk );

void Abc_FlowRetime_InitState( Abc_Ntk_t * pNtk );

void Abc_FlowRetime_UpdateForwardInit( Abc_Ntk_t * pNtk );
void Abc_FlowRetime_UpdateBackwardInit( Abc_Ntk_t * pNtk );

void Abc_FlowRetime_SetupBackwardInit( Abc_Ntk_t * pNtk );
int  Abc_FlowRetime_SolveBackwardInit( Abc_Ntk_t * pNtk );

void Abc_FlowRetime_ConstrainInit(  );
Alan Mishchenko committed
187 188
void Abc_FlowRetime_AddInitBias(  );
void Abc_FlowRetime_RemoveInitBias(  );
Alan Mishchenko committed
189 190 191 192 193 194

/*=== fretTime.c ==========================================================*/

void Abc_FlowRetime_InitTiming( Abc_Ntk_t *pNtk );
void Abc_FlowRetime_FreeTiming( Abc_Ntk_t *pNtk );

195
int Abc_FlowRetime_RefineConstraints( );
Alan Mishchenko committed
196 197 198 199 200

void Abc_FlowRetime_ConstrainConserv( Abc_Ntk_t * pNtk );
void Abc_FlowRetime_ConstrainExact( Abc_Obj_t * pObj );
void Abc_FlowRetime_ConstrainExactAll( Abc_Ntk_t * pNtk );

201 202 203 204


ABC_NAMESPACE_HEADER_END

Alan Mishchenko committed
205
#endif