Commit 8f74276e by Alan Mishchenko

Initial changes to enable gate-level abstraction.

parent 81b040e6
...@@ -133,6 +133,7 @@ struct Gia_Man_t_ ...@@ -133,6 +133,7 @@ struct Gia_Man_t_
int * pCopies; // intermediate copies int * pCopies; // intermediate copies
Vec_Int_t * vTruths; // used for truth table computation Vec_Int_t * vTruths; // used for truth table computation
Vec_Int_t * vFlopClasses; // classes of flops for retiming/merging/etc Vec_Int_t * vFlopClasses; // classes of flops for retiming/merging/etc
Vec_Int_t * vGateClasses; // classes of gates for abstraction
unsigned char* pSwitching; // switching activity for each object unsigned char* pSwitching; // switching activity for each object
Gia_Plc_t * pPlacement; // placement of the objects Gia_Plc_t * pPlacement; // placement of the objects
int * pTravIds; // separate traversal ID representation int * pTravIds; // separate traversal ID representation
...@@ -656,7 +657,8 @@ extern Gia_Man_t * Gia_ManMiter( Gia_Man_t * pAig0, Gia_Man_t * pAig1, i ...@@ -656,7 +657,8 @@ extern Gia_Man_t * Gia_ManMiter( Gia_Man_t * pAig0, Gia_Man_t * pAig1, i
extern Gia_Man_t * Gia_ManTransformMiter( Gia_Man_t * p ); extern Gia_Man_t * Gia_ManTransformMiter( Gia_Man_t * p );
extern Gia_Man_t * Gia_ManChoiceMiter( Vec_Ptr_t * vGias ); extern Gia_Man_t * Gia_ManChoiceMiter( Vec_Ptr_t * vGias );
extern Gia_Man_t * Gia_ManDupWithConstraints( Gia_Man_t * p, Vec_Int_t * vPoTypes ); extern Gia_Man_t * Gia_ManDupWithConstraints( Gia_Man_t * p, Vec_Int_t * vPoTypes );
extern Gia_Man_t * Gia_ManDupAbstraction( Gia_Man_t * p, Vec_Int_t * vFlopClasses ); extern Gia_Man_t * Gia_ManDupAbsFlops( Gia_Man_t * p, Vec_Int_t * vFlopClasses );
extern Gia_Man_t * Gia_ManDupAbsGates( Gia_Man_t * p, Vec_Int_t * vGateClasses );
/*=== giaEnable.c ==========================================================*/ /*=== giaEnable.c ==========================================================*/
extern void Gia_ManDetectSeqSignals( Gia_Man_t * p, int fSetReset, int fVerbose ); extern void Gia_ManDetectSeqSignals( Gia_Man_t * p, int fSetReset, int fVerbose );
extern Gia_Man_t * Gia_ManUnrollAndCofactor( Gia_Man_t * p, int nFrames, int nFanMax, int fVerbose ); extern Gia_Man_t * Gia_ManUnrollAndCofactor( Gia_Man_t * p, int nFrames, int nFanMax, int fVerbose );
...@@ -750,7 +752,7 @@ extern int Gia_MmStepReadMemUsage( Gia_MmStep_t * p ); ...@@ -750,7 +752,7 @@ extern int Gia_MmStepReadMemUsage( Gia_MmStep_t * p );
/*=== giaPat.c ===========================================================*/ /*=== giaPat.c ===========================================================*/
extern void Gia_SatVerifyPattern( Gia_Man_t * p, Gia_Obj_t * pRoot, Vec_Int_t * vCex, Vec_Int_t * vVisit ); extern void Gia_SatVerifyPattern( Gia_Man_t * p, Gia_Obj_t * pRoot, Vec_Int_t * vCex, Vec_Int_t * vVisit );
/*=== giaReparam.c ===========================================================*/ /*=== giaReparam.c ===========================================================*/
extern Gia_Man_t * Gia_ManReparm( Gia_Man_t * p, int fVerbose ); extern Gia_Man_t * Gia_ManReparam( Gia_Man_t * p, int fVerbose );
/*=== giaRetime.c ===========================================================*/ /*=== giaRetime.c ===========================================================*/
extern Gia_Man_t * Gia_ManRetimeForward( Gia_Man_t * p, int nMaxIters, int fVerbose ); extern Gia_Man_t * Gia_ManRetimeForward( Gia_Man_t * p, int nMaxIters, int fVerbose );
/*=== giaSat.c ============================================================*/ /*=== giaSat.c ============================================================*/
......
...@@ -111,32 +111,6 @@ Vec_Int_t * Gia_ManClasses2Flops( Vec_Int_t * vFlopClasses ) ...@@ -111,32 +111,6 @@ Vec_Int_t * Gia_ManClasses2Flops( Vec_Int_t * vFlopClasses )
/**Function************************************************************* /**Function*************************************************************
Synopsis [Performs abstraction on the AIG manager.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManDupAbstractionAig( Gia_Man_t * p, Vec_Int_t * vFlops )
{
Gia_Man_t * pGia;
Aig_Man_t * pNew, * pTemp;
pNew = Gia_ManToAig( p, 0 );
pNew = Saig_ManDupAbstraction( pTemp = pNew, vFlops );
Aig_ManStop( pTemp );
pGia = Gia_ManFromAig( pNew );
// pGia->vCiNumsOrig = pNew->vCiNumsOrig;
// pNew->vCiNumsOrig = NULL;
Aig_ManStop( pNew );
return pGia;
}
/**Function*************************************************************
Synopsis [Starts abstraction by computing latch map.] Synopsis [Starts abstraction by computing latch map.]
Description [] Description []
...@@ -281,7 +255,7 @@ int Gia_ManCbaPerform( Gia_Man_t * pGia, void * pPars ) ...@@ -281,7 +255,7 @@ int Gia_ManCbaPerform( Gia_Man_t * pGia, void * pPars )
pGia->vFlopClasses = Vec_IntStart( Gia_ManRegNum(pGia) ); pGia->vFlopClasses = Vec_IntStart( Gia_ManRegNum(pGia) );
} }
// derive abstraction // derive abstraction
pAbs = Gia_ManDupAbstraction( pGia, pGia->vFlopClasses ); pAbs = Gia_ManDupAbsFlops( pGia, pGia->vFlopClasses );
pAig = Gia_ManToAigSimple( pAbs ); pAig = Gia_ManToAigSimple( pAbs );
Gia_ManStop( pAbs ); Gia_ManStop( pAbs );
// refine abstraction using CBA // refine abstraction using CBA
...@@ -343,7 +317,7 @@ int Gia_ManPbaPerform( Gia_Man_t * pGia, int nStart, int nFrames, int nConfLimit ...@@ -343,7 +317,7 @@ int Gia_ManPbaPerform( Gia_Man_t * pGia, int nStart, int nFrames, int nConfLimit
return 0; return 0;
} }
// derive abstraction // derive abstraction
pAbs = Gia_ManDupAbstraction( pGia, pGia->vFlopClasses ); pAbs = Gia_ManDupAbsFlops( pGia, pGia->vFlopClasses );
// refine abstraction using PBA // refine abstraction using PBA
pAig = Gia_ManToAigSimple( pAbs ); pAig = Gia_ManToAigSimple( pAbs );
Gia_ManStop( pAbs ); Gia_ManStop( pAbs );
......
...@@ -507,6 +507,13 @@ Gia_Man_t * Gia_ReadAiger2( char * pFileName, int fCheck ) ...@@ -507,6 +507,13 @@ Gia_Man_t * Gia_ReadAiger2( char * pFileName, int fCheck )
pNew->vFlopClasses = Vec_IntStart( Gia_ManRegNum(pNew) ); pNew->vFlopClasses = Vec_IntStart( Gia_ManRegNum(pNew) );
Gia_ReadFlopClasses( &pCur, pNew->vFlopClasses, Gia_ManRegNum(pNew) ); Gia_ReadFlopClasses( &pCur, pNew->vFlopClasses, Gia_ManRegNum(pNew) );
} }
if ( *pCur == 'g' )
{
pCur++;
// read gate classes
pNew->vGateClasses = Vec_IntStart( Gia_ManObjNum(pNew) );
Gia_ReadFlopClasses( &pCur, pNew->vGateClasses, Gia_ManObjNum(pNew) );
}
if ( *pCur == 'm' ) if ( *pCur == 'm' )
{ {
pCur++; pCur++;
...@@ -712,6 +719,13 @@ Gia_Man_t * Gia_ReadAigerFromMemory( char * pContents, int nFileSize, int fCheck ...@@ -712,6 +719,13 @@ Gia_Man_t * Gia_ReadAigerFromMemory( char * pContents, int nFileSize, int fCheck
pNew->vFlopClasses = Vec_IntStart( Gia_ManRegNum(pNew) ); pNew->vFlopClasses = Vec_IntStart( Gia_ManRegNum(pNew) );
Gia_ReadFlopClasses( &pCur, pNew->vFlopClasses, Gia_ManRegNum(pNew) ); Gia_ReadFlopClasses( &pCur, pNew->vFlopClasses, Gia_ManRegNum(pNew) );
} }
if ( *pCur == 'g' )
{
pCur++;
// read gate classes
pNew->vGateClasses = Vec_IntStart( Gia_ManObjNum(pNew) );
Gia_ReadFlopClasses( &pCur, pNew->vGateClasses, Gia_ManObjNum(pNew) );
}
if ( *pCur == 'm' ) if ( *pCur == 'm' )
{ {
pCur++; pCur++;
...@@ -898,11 +912,13 @@ Gia_Man_t * Gia_ReadAigerFromMemory( char * pContents, int nFileSize, int fCheck ...@@ -898,11 +912,13 @@ Gia_Man_t * Gia_ReadAigerFromMemory( char * pContents, int nFileSize, int fCheck
} }
{ {
Vec_Int_t * vFlopMap; Vec_Int_t * vFlopMap, * vGateMap;
vFlopMap = pNew->vFlopClasses; pNew->vFlopClasses = NULL; vFlopMap = pNew->vFlopClasses; pNew->vFlopClasses = NULL;
vGateMap = pNew->vGateClasses; pNew->vGateClasses = NULL;
pNew = Gia_ManCleanup( pTemp = pNew ); pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp ); Gia_ManStop( pTemp );
pNew->vFlopClasses = vFlopMap; pNew->vFlopClasses = vFlopMap;
pNew->vGateClasses = vGateMap;
} }
return pNew; return pNew;
} }
...@@ -1317,6 +1333,16 @@ void Gia_WriteAiger( Gia_Man_t * pInit, char * pFileName, int fWriteSymbols, int ...@@ -1317,6 +1333,16 @@ void Gia_WriteAiger( Gia_Man_t * pInit, char * pFileName, int fWriteSymbols, int
fwrite( Buffer, 1, 4, pFile ); fwrite( Buffer, 1, 4, pFile );
fwrite( Vec_IntArray(p->vFlopClasses), 1, nSize, pFile ); fwrite( Vec_IntArray(p->vFlopClasses), 1, nSize, pFile );
} }
// write gate classes
if ( p->vGateClasses )
{
unsigned char Buffer[10];
int nSize = 4*Gia_ManObjNum(p);
Gia_WriteInt( Buffer, nSize );
fprintf( pFile, "g" );
fwrite( Buffer, 1, 4, pFile );
fwrite( Vec_IntArray(p->vGateClasses), 1, nSize, pFile );
}
// write mapping // write mapping
if ( p->pMapping ) if ( p->pMapping )
{ {
......
...@@ -1517,12 +1517,13 @@ Gia_Man_t * Gia_ManDupWithConstraints( Gia_Man_t * p, Vec_Int_t * vPoTypes ) ...@@ -1517,12 +1517,13 @@ Gia_Man_t * Gia_ManDupWithConstraints( Gia_Man_t * p, Vec_Int_t * vPoTypes )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Gia_ManDupAbstraction_rec( Gia_Man_t * pNew, Gia_Obj_t * pObj ) void Gia_ManDupAbsFlops_rec( Gia_Man_t * pNew, Gia_Obj_t * pObj )
{ {
if ( ~pObj->Value ) if ( ~pObj->Value )
return; return;
Gia_ManDupAbstraction_rec( pNew, Gia_ObjFanin0(pObj) ); assert( Gia_ObjIsAnd(pObj) );
Gia_ManDupAbstraction_rec( pNew, Gia_ObjFanin1(pObj) ); Gia_ManDupAbsFlops_rec( pNew, Gia_ObjFanin0(pObj) );
Gia_ManDupAbsFlops_rec( pNew, Gia_ObjFanin1(pObj) );
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
} }
...@@ -1537,7 +1538,7 @@ void Gia_ManDupAbstraction_rec( Gia_Man_t * pNew, Gia_Obj_t * pObj ) ...@@ -1537,7 +1538,7 @@ void Gia_ManDupAbstraction_rec( Gia_Man_t * pNew, Gia_Obj_t * pObj )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Gia_Man_t * Gia_ManDupAbstraction( Gia_Man_t * p, Vec_Int_t * vFlopClasses ) Gia_Man_t * Gia_ManDupAbsFlops( Gia_Man_t * p, Vec_Int_t * vFlopClasses )
{ {
Gia_Man_t * pNew, * pTemp; Gia_Man_t * pNew, * pTemp;
Gia_Obj_t * pObj; Gia_Obj_t * pObj;
...@@ -1562,14 +1563,73 @@ Gia_Man_t * Gia_ManDupAbstraction( Gia_Man_t * p, Vec_Int_t * vFlopClasses ) ...@@ -1562,14 +1563,73 @@ Gia_Man_t * Gia_ManDupAbstraction( Gia_Man_t * p, Vec_Int_t * vFlopClasses )
Gia_ManHashAlloc( pNew ); Gia_ManHashAlloc( pNew );
Gia_ManForEachPo( p, pObj, i ) Gia_ManForEachPo( p, pObj, i )
{ {
Gia_ManDupAbstraction_rec( pNew, Gia_ObjFanin0(pObj) ); Gia_ManDupAbsFlops_rec( pNew, Gia_ObjFanin0(pObj) );
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
} }
// create RIs // create RIs
Gia_ManForEachRi( p, pObj, i ) Gia_ManForEachRi( p, pObj, i )
if ( Vec_IntEntry(vFlopClasses, i) ) if ( Vec_IntEntry(vFlopClasses, i) )
{ {
Gia_ManDupAbstraction_rec( pNew, Gia_ObjFanin0(pObj) ); Gia_ManDupAbsFlops_rec( pNew, Gia_ObjFanin0(pObj) );
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
nFlops++;
}
Gia_ManHashStop( pNew );
Gia_ManSetRegNum( pNew, nFlops );
// clean up
pNew = Gia_ManSeqCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
return pNew;
}
/**Function*************************************************************
Synopsis [Performs abstraction of the AIG to preserve the included gates.]
Description [The array contains PIs, LOs, and internal nodes included.
0=unsed, 1=PI, 2=PPI, 3=FF, 4=AND.]
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManDupAbsGates( Gia_Man_t * p, Vec_Int_t * vGateClasses )
{
Gia_Man_t * pNew, * pTemp;
Gia_Obj_t * pObj;
int i, nFlops = 0;
assert( Gia_ManPoNum(p) == 1 );
Gia_ManFillValue( p );
// start the new manager
pNew = Gia_ManStart( 5000 );
pNew->pName = Gia_UtilStrsav( p->pName );
// create PIs
Gia_ManConst0(p)->Value = 0;
Gia_ManForEachPi( p, pObj, i )
if ( Vec_IntEntry(vGateClasses, Gia_ObjId(p, pObj)) == 1 )
pObj->Value = Gia_ManAppendCi(pNew);
// create additional PIs
Gia_ManForEachPi( p, pObj, i )
if ( Vec_IntEntry(vGateClasses, Gia_ObjId(p, pObj)) == 2 )
pObj->Value = Gia_ManAppendCi(pNew);
// create ROs
Gia_ManForEachRo( p, pObj, i )
if ( Vec_IntEntry(vGateClasses, Gia_ObjId(p, pObj)) == 3 )
pObj->Value = Gia_ManAppendCi(pNew);
// create POs
Gia_ManHashAlloc( pNew );
Gia_ManForEachPo( p, pObj, i )
{
Gia_ManDupAbsFlops_rec( pNew, Gia_ObjFanin0(pObj) );
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
}
// create RIs
Gia_ManForEachRo( p, pObj, i )
if ( Vec_IntEntry(vGateClasses, Gia_ObjId(p, pObj)) == 3 )
{
pObj = Gia_ObjRoToRi(p, pObj);
Gia_ManDupAbsFlops_rec( pNew, Gia_ObjFanin0(pObj) );
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
nFlops++; nFlops++;
} }
......
...@@ -81,6 +81,7 @@ void Gia_ManStop( Gia_Man_t * p ) ...@@ -81,6 +81,7 @@ void Gia_ManStop( Gia_Man_t * p )
Vec_IntFreeP( &p->vUserPoIds ); Vec_IntFreeP( &p->vUserPoIds );
Vec_IntFreeP( &p->vUserFfIds ); Vec_IntFreeP( &p->vUserFfIds );
Vec_IntFreeP( &p->vFlopClasses ); Vec_IntFreeP( &p->vFlopClasses );
Vec_IntFreeP( &p->vGateClasses );
Vec_IntFreeP( &p->vLevels ); Vec_IntFreeP( &p->vLevels );
Vec_IntFreeP( &p->vTruths ); Vec_IntFreeP( &p->vTruths );
Vec_IntFree( p->vCis ); Vec_IntFree( p->vCis );
...@@ -166,30 +167,21 @@ void Gia_ManPrintClasses_old( Gia_Man_t * p ) ...@@ -166,30 +167,21 @@ void Gia_ManPrintClasses_old( Gia_Man_t * p )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Gia_ManPrintClasses( Gia_Man_t * p ) void Gia_ManPrintFlopClasses( Gia_Man_t * p )
{ {
int i, Class, Counter0, Counter1; int Counter0, Counter1;
if ( p->vFlopClasses == NULL ) if ( p->vFlopClasses == NULL )
return; return;
if ( Vec_IntSize(p->vFlopClasses) != Gia_ManRegNum(p) ) if ( Vec_IntSize(p->vFlopClasses) != Gia_ManRegNum(p) )
{ {
printf( "Gia_ManPrintClasses(): The number of flop map entries differs from the number of flops.\n" ); printf( "Gia_ManPrintFlopClasses(): The number of flop map entries differs from the number of flops.\n" );
return; return;
} }
printf( "Register classes: " ); Counter0 = Vec_IntCountEntry( p->vFlopClasses, 0 );
// count zero entries Counter1 = Vec_IntCountEntry( p->vFlopClasses, 1 );
Counter0 = 0; printf( "Flop-level abstraction: Excluded FFs = %d Included FFs = %d ", Counter0, Counter1 );
Vec_IntForEachEntry( p->vFlopClasses, Class, i )
Counter0 += (Class == 0);
printf( "0=%d ", Counter0 );
// count one entries
Counter1 = 0;
Vec_IntForEachEntry( p->vFlopClasses, Class, i )
Counter1 += (Class == 1);
printf( "1=%d ", Counter1 );
// add comment
if ( Counter0 + Counter1 < Gia_ManRegNum(p) ) if ( Counter0 + Counter1 < Gia_ManRegNum(p) )
printf( "there are other classes..." ); printf( "and there are other FF classes..." );
printf( "\n" ); printf( "\n" );
} }
...@@ -204,6 +196,35 @@ void Gia_ManPrintClasses( Gia_Man_t * p ) ...@@ -204,6 +196,35 @@ void Gia_ManPrintClasses( Gia_Man_t * p )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Gia_ManPrintGateClasses( Gia_Man_t * p )
{
int i, Counter[5];
if ( p->vGateClasses == NULL )
return;
if ( Vec_IntSize(p->vGateClasses) != Gia_ManObjNum(p) )
{
printf( "Gia_ManPrintGateClasses(): The number of flop map entries differs from the number of flops.\n" );
return;
}
for ( i = 0; i < 5; i++ )
Counter[i] = Vec_IntCountEntry( p->vGateClasses, i );
printf( "Gate-level abstraction: PI = %d PPI = %d FF = %d AND = %d Unused = %d\n",
Counter[1], Counter[2], Counter[3], Counter[4], Counter[0] );
if ( Counter[0] + Counter[1] + Counter[2] + Counter[3] + Counter[4] != Gia_ManObjNum(p) )
printf( "Gia_ManPrintGateClasses(): Mismatch in the object count.\n" );
}
/**Function*************************************************************
Synopsis [Prints stats for the AIG.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManPrintPlacement( Gia_Man_t * p ) void Gia_ManPrintPlacement( Gia_Man_t * p )
{ {
int i, nFixed = 0, nUndef = 0; int i, nFixed = 0, nUndef = 0;
...@@ -261,7 +282,8 @@ void Gia_ManPrintStats( Gia_Man_t * p, int fSwitch ) ...@@ -261,7 +282,8 @@ void Gia_ManPrintStats( Gia_Man_t * p, int fSwitch )
if ( p->pPlacement ) if ( p->pPlacement )
Gia_ManPrintPlacement( p ); Gia_ManPrintPlacement( p );
// print register classes // print register classes
Gia_ManPrintClasses( p ); Gia_ManPrintFlopClasses( p );
Gia_ManPrintGateClasses( p );
} }
/**Function************************************************************* /**Function*************************************************************
......
...@@ -138,7 +138,7 @@ Gia_Man_t * Gia_ManDupFf2In( Gia_Man_t * p, int nFlopsOld ) ...@@ -138,7 +138,7 @@ Gia_Man_t * Gia_ManDupFf2In( Gia_Man_t * p, int nFlopsOld )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Gia_Man_t * Gia_ManReparm( Gia_Man_t * p, int fVerbose ) Gia_Man_t * Gia_ManReparam( Gia_Man_t * p, int fVerbose )
{ {
// extern Aig_Man_t * Saig_ManRetimeMinArea( Aig_Man_t * p, int nMaxIters, int fForwardOnly, int fBackwardOnly, int fInitial, int fVerbose ); // extern Aig_Man_t * Saig_ManRetimeMinArea( Aig_Man_t * p, int nMaxIters, int fForwardOnly, int fBackwardOnly, int fInitial, int fVerbose );
Aig_Man_t * pMan, * pTemp; Aig_Man_t * pMan, * pTemp;
......
...@@ -917,11 +917,11 @@ static inline int Vec_IntSum( Vec_Int_t * p ) ...@@ -917,11 +917,11 @@ static inline int Vec_IntSum( Vec_Int_t * p )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
static inline int Vec_IntCountZero( Vec_Int_t * p ) static inline int Vec_IntCountEntry( Vec_Int_t * p, int Entry )
{ {
int i, Counter = 0; int i, Counter = 0;
for ( i = 0; i < p->nSize; i++ ) for ( i = 0; i < p->nSize; i++ )
Counter += (p->pArray[i] == 0); Counter += (p->pArray[i] == Entry);
return Counter; return Counter;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment