Commit fd877c3f by Alan Mishchenko

Several improvements to CBA data-structure.

parent 0f9001c9
......@@ -202,7 +202,10 @@ Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fBuffers, int fVerbose )
Vec_IntClear( &p->vBuf2RootObj );
Cba_ManForEachNtk( p, pNtk, i )
Cba_NtkStartCopies(pNtk);
{
Cba_NtkDeriveIndex( pNtk );
Cba_NtkStartCopies( pNtk );
}
// start the manager
pNew = Gia_ManStart( Cba_ManNodeNum(p) );
......@@ -297,15 +300,15 @@ void Cba_NtkCreateAndConnectBuffer( Gia_Man_t * pGia, Gia_Obj_t * pObj, Cba_Ntk_
if ( pGia && Gia_ObjFaninId0p(pGia, pObj) > 0 )
{
assert( Cba_ObjName(p, Gia_ObjFanin0(pObj)->Value) != Cba_ObjName(p, iTerm) ); // not a feedthrough
iObj = Cba_ObjAlloc( p, CBA_OBJ_BI, 0, Gia_ObjFanin0(pObj)->Value );
iObj = Cba_ObjAlloc( p, CBA_OBJ_BI, Gia_ObjFanin0(pObj)->Value );
Cba_ObjSetName( p, iObj, Cba_ObjName(p, Gia_ObjFanin0(pObj)->Value) );
Cba_ObjAlloc( p, Gia_ObjFaninC0(pObj) ? CBA_BOX_INV : CBA_BOX_BUF, -1, -1 );
Cba_ObjAlloc( p, Gia_ObjFaninC0(pObj) ? CBA_BOX_INV : CBA_BOX_BUF, -1 );
}
else
{
Cba_ObjAlloc( p, pGia && Gia_ObjFaninC0(pObj) ? CBA_BOX_C1 : CBA_BOX_C0, -1, -1 );
Cba_ObjAlloc( p, pGia && Gia_ObjFaninC0(pObj) ? CBA_BOX_C1 : CBA_BOX_C0, -1 );
}
iObj = Cba_ObjAlloc( p, CBA_OBJ_BO, 0, -1 );
iObj = Cba_ObjAlloc( p, CBA_OBJ_BO, -1 );
Cba_ObjSetName( p, iObj, Cba_ObjName(p, iTerm) );
Cba_ObjSetFanin( p, iTerm, iObj );
}
......@@ -348,12 +351,12 @@ void Cba_NtkInsertGia( Cba_Man_t * p, Gia_Man_t * pGia )
else
Type = CBA_BOX_AND;
// create box
iTerm = Cba_ObjAlloc( pNtk, CBA_OBJ_BI, 1, iLit1 );
iTerm = Cba_ObjAlloc( pNtk, CBA_OBJ_BI, iLit1 );
Cba_ObjSetName( pNtk, iTerm, Cba_ObjName(pNtk, iLit1) );
iTerm = Cba_ObjAlloc( pNtk, CBA_OBJ_BI, 0, iLit0 );
iTerm = Cba_ObjAlloc( pNtk, CBA_OBJ_BI, iLit0 );
Cba_ObjSetName( pNtk, iTerm, Cba_ObjName(pNtk, iLit0) );
Cba_ObjAlloc( pNtk, Type, -1, -1 );
pObj->Value = Cba_ObjAlloc( pNtk, CBA_OBJ_BO, 0, -1 );
Cba_ObjAlloc( pNtk, Type, -1 );
pObj->Value = Cba_ObjAlloc( pNtk, CBA_OBJ_BO, -1 );
}
}
assert( Count == Gia_ManBufNum(pGia) );
......@@ -453,16 +456,16 @@ void Cba_NtkCreateOrConnectFanin( Abc_Obj_t * pFanin, Cba_Ntk_t * p, int iTerm )
else if ( pFanin && (Abc_ObjIsPi(pFanin) || Abc_ObjIsBarBuf(pFanin) || Abc_NodeIsSeriousGate(pFanin)) ) // PI/BO or gate with name
{
assert( Cba_ObjName(p, pFanin->iTemp) != Cba_ObjName(p, iTerm) ); // not a feedthrough
iObj = Cba_ObjAlloc( p, CBA_OBJ_BI, 0, pFanin->iTemp );
iObj = Cba_ObjAlloc( p, CBA_OBJ_BI, pFanin->iTemp );
Cba_ObjSetName( p, iObj, Cba_ObjName(p, pFanin->iTemp) );
Cba_ObjAlloc( p, CBA_BOX_GATE, p->pDesign->ElemGates[2], -1 ); // buffer
iObj = Cba_ObjAlloc( p, CBA_OBJ_BO, 0, -1 );
Cba_ObjAlloc( p, CBA_BOX_GATE, p->pDesign->ElemGates[2] ); // buffer
iObj = Cba_ObjAlloc( p, CBA_OBJ_BO, -1 );
}
else
{
assert( !pFanin || Abc_NodeIsConst0(pFanin) || Abc_NodeIsConst1(pFanin) );
Cba_ObjAlloc( p, CBA_BOX_GATE, p->pDesign->ElemGates[(pFanin && Abc_NodeIsConst1(pFanin))], -1 ); // const 0/1
iObj = Cba_ObjAlloc( p, CBA_OBJ_BO, 0, -1 );
Cba_ObjAlloc( p, CBA_BOX_GATE, p->pDesign->ElemGates[(pFanin && Abc_NodeIsConst1(pFanin))] ); // const 0/1
iObj = Cba_ObjAlloc( p, CBA_OBJ_BO, -1 );
}
Cba_ObjSetName( p, iObj, Cba_ObjName(p, iTerm) );
Cba_ObjSetFanin( p, iTerm, iObj );
......@@ -514,11 +517,11 @@ void Cba_NtkInsertNtk( Cba_Man_t * p, Abc_Ntk_t * pNtk )
pCbaNtk = Cba_ManNtk( p, pObj->iTemp );
for ( k = Abc_ObjFaninNum(pObj)-1; k >= 0; k-- )
{
iTerm = Cba_ObjAlloc( pCbaNtk, CBA_OBJ_BI, k, Abc_ObjFanin(pObj, k)->iTemp );
iTerm = Cba_ObjAlloc( pCbaNtk, CBA_OBJ_BI, Abc_ObjFanin(pObj, k)->iTemp );
Cba_ObjSetName( pCbaNtk, iTerm, Cba_ObjName(pCbaNtk, Abc_ObjFanin(pObj, k)->iTemp) );
}
Cba_ObjAlloc( pCbaNtk, CBA_BOX_GATE, Abc_NamStrFind(p->pMods, Mio_GateReadName((Mio_Gate_t *)pObj->pData)), -1 );
pObj->iTemp = Cba_ObjAlloc( pCbaNtk, CBA_OBJ_BO, 0, -1 );
Cba_ObjAlloc( pCbaNtk, CBA_BOX_GATE, Abc_NamStrFind(p->pMods, Mio_GateReadName((Mio_Gate_t *)pObj->pData)) );
pObj->iTemp = Cba_ObjAlloc( pCbaNtk, CBA_OBJ_BO, -1 );
}
}
assert( Count == pNtk->nBarBufs2 );
......
......@@ -44,7 +44,7 @@ ABC_NAMESPACE_IMPL_START
***********************************************************************/
int CbaManReadCbaLine( Vec_Str_t * vOut, int * pPos, char * pBuffer, char * pLimit )
{
char c;
char c;
while ( (c = Vec_StrEntry(vOut, (*pPos)++)) != '\n' && pBuffer < pLimit )
*pBuffer++ = c;
*pBuffer = 0;
......@@ -94,11 +94,19 @@ void Cba_ManReadCbaVecInt( Vec_Str_t * vOut, int * pPos, Vec_Int_t * p, int nSiz
}
void Cba_ManReadCbaNtk( Vec_Str_t * vOut, int * pPos, Cba_Ntk_t * pNtk )
{
Cba_ManReadCbaVecInt( vOut, pPos, &pNtk->vInputs, 4 * Cba_NtkPiNumAlloc(pNtk) );
Cba_ManReadCbaVecInt( vOut, pPos, &pNtk->vOutputs, 4 * Cba_NtkPoNumAlloc(pNtk) );
Cba_ManReadCbaVecStr( vOut, pPos, &pNtk->vType, Cba_NtkObjNumAlloc(pNtk) );
Cba_ManReadCbaVecInt( vOut, pPos, &pNtk->vIndex, 4 * Cba_NtkObjNumAlloc(pNtk) );
Cba_ManReadCbaVecInt( vOut, pPos, &pNtk->vFanin, 4 * Cba_NtkObjNumAlloc(pNtk) );
int i, Type;
Cba_ManReadCbaVecStr( vOut, pPos, &pNtk->vType, Cba_NtkObjNumAlloc(pNtk) );
Cba_ManReadCbaVecInt( vOut, pPos, &pNtk->vFanin, 4 * Cba_NtkObjNumAlloc(pNtk) );
Cba_NtkForEachObjType( pNtk, Type, i )
{
if ( Type == CBA_OBJ_PI )
Vec_IntPush( &pNtk->vInputs, i );
if ( Type == CBA_OBJ_PO )
Vec_IntPush( &pNtk->vOutputs, i );
}
assert( Cba_NtkPiNum(pNtk) == Cba_NtkPiNumAlloc(pNtk) );
assert( Cba_NtkPoNum(pNtk) == Cba_NtkPoNumAlloc(pNtk) );
assert( Cba_NtkObjNum(pNtk) == Cba_NtkObjNumAlloc(pNtk) );
}
Cba_Man_t * Cba_ManReadCbaInt( Vec_Str_t * vOut )
{
......@@ -186,11 +194,8 @@ Cba_Man_t * Cba_ManReadCba( char * pFileName )
***********************************************************************/
void Cba_ManWriteCbaNtk( Vec_Str_t * vOut, Cba_Ntk_t * pNtk )
{
Vec_StrPushBuffer( vOut, (char *)Vec_IntArray(&pNtk->vInputs), 4 * Cba_NtkPiNum(pNtk) );
Vec_StrPushBuffer( vOut, (char *)Vec_IntArray(&pNtk->vOutputs), 4 * Cba_NtkPoNum(pNtk) );
Vec_StrPushBuffer( vOut, (char *)Vec_StrArray(&pNtk->vType), Cba_NtkObjNum(pNtk) );
Vec_StrPushBuffer( vOut, (char *)Vec_IntArray(&pNtk->vIndex), 4 * Cba_NtkObjNum(pNtk) );
Vec_StrPushBuffer( vOut, (char *)Vec_IntArray(&pNtk->vFanin), 4 * Cba_NtkObjNum(pNtk) );
Vec_StrPushBuffer( vOut, (char *)Vec_StrArray(&pNtk->vType), Cba_NtkObjNum(pNtk) );
Vec_StrPushBuffer( vOut, (char *)Vec_IntArray(&pNtk->vFanin), 4 * Cba_NtkObjNum(pNtk) );
}
void Cba_ManWriteCbaInt( Vec_Str_t * vOut, Cba_Man_t * p )
{
......
......@@ -507,7 +507,7 @@ int Cba_CommandClp( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( 1, "Cba_CommandGet(): There is no current design.\n" );
return 0;
}
pNew = Cba_ManDup( p );
pNew = Cba_ManCollapse( p );
Cba_AbcUpdateMan( pAbc, pNew );
return 0;
usage:
......
......@@ -115,7 +115,7 @@ int Cba_ManClpObjNum_rec( Cba_Ntk_t * p )
if ( p->Count >= 0 )
return p->Count;
Cba_NtkForEachBox( p, i )
Counter += Cba_ObjIsBoxUser(p, i) ? Cba_ManClpObjNum_rec( Cba_BoxNtk(p, i) ) : Cba_BoxSize(p, i);
Counter += Cba_ObjIsBoxUser(p, i) ? Cba_ManClpObjNum_rec( Cba_BoxNtk(p, i) ) + 3*Cba_BoxBoNum(p, i) : Cba_BoxSize(p, i);
return (p->Count = Counter);
}
int Cba_ManClpObjNum( Cba_Man_t * p )
......@@ -220,37 +220,49 @@ int Cba_NtkDfsUserBoxes( Cba_Ntk_t * p )
***********************************************************************/
void Cba_NtkCollapse_rec( Cba_Ntk_t * pNew, Cba_Ntk_t * p, Vec_Int_t * vSigs )
{
int i, k, iObj, iTerm;
int i, iObj, iObjNew, iTerm;
Cba_NtkStartCopies( p );
// set PI copies
assert( Vec_IntSize(vSigs) == Cba_NtkPiNum(p) );
Cba_NtkForEachPi( p, iObj, i )
Cba_ObjSetCopy( p, iObj, Vec_IntEntry(vSigs, i) );
// duplicate internal objects
// duplicate internal objects and create buffers for hierarchy instances
Cba_NtkForEachBox( p, iObj )
if ( Cba_ObjIsBoxPrim(p, iObj) )
if ( Cba_ObjIsBoxPrim( p, iObj ) )
Cba_BoxDup( pNew, p, iObj );
// duplicate user moduled in DFS order
Vec_IntForEachEntry( &p->vArray, iObj, i )
{
assert( Cba_ObjIsBoxUser(p, iObj) );
Vec_IntClear( vSigs );
Cba_BoxForEachBi( p, iObj, iTerm, k )
Vec_IntPush( vSigs, Cba_ObjCopy(p, Cba_ObjFanin(p, iTerm)) );
Cba_NtkCollapse_rec( pNew, Cba_BoxNtk(p, iObj), vSigs );
assert( Vec_IntSize(vSigs) == Cba_BoxBoNum(p, iObj) );
Cba_BoxForEachBo( p, iObj, iTerm, k )
Cba_ObjSetCopy( p, iTerm, Vec_IntEntry(vSigs, k) );
}
// connect objects
Cba_NtkForEachBi( p, iObj )
Cba_ObjSetFanin( pNew, Cba_ObjCopy(p, iObj), Cba_ObjCopy(p, Cba_ObjFanin(p, iObj)) );
else
{
Cba_BoxForEachBo( p, iObj, iTerm, i )
{
iObjNew = Cba_ObjAlloc( pNew, CBA_OBJ_BI, -1 );
iObjNew = Cba_ObjAlloc( pNew, CBA_BOX_BUF, -1 ); // buffer
iObjNew = Cba_ObjAlloc( pNew, CBA_OBJ_BO, -1 );
Cba_ObjSetCopy( p, iTerm, iObjNew );
}
}
// duplicate user modules and connect objects
Cba_NtkForEachBox( p, iObj )
if ( Cba_ObjIsBoxPrim( p, iObj ) )
{
Cba_BoxForEachBi( p, iObj, iTerm, i )
Cba_ObjSetFanin( pNew, Cba_ObjCopy(p, iTerm), Cba_ObjCopy(p, Cba_ObjFanin(p, iTerm)) );
}
else
{
Vec_IntClear( vSigs );
Cba_BoxForEachBi( p, iObj, iTerm, i )
Vec_IntPush( vSigs, Cba_ObjCopy(p, Cba_ObjFanin(p, iTerm)) );
Cba_NtkCollapse_rec( pNew, Cba_BoxNtk(p, iObj), vSigs );
assert( Vec_IntSize(vSigs) == Cba_BoxBoNum(p, iObj) );
Cba_BoxForEachBo( p, iObj, iTerm, i )
Cba_ObjSetFanin( pNew, Cba_ObjCopy(p, iTerm)-2, Vec_IntEntry(vSigs, i) );
}
// collect POs
Vec_IntClear( vSigs );
Cba_NtkForEachPo( p, iObj, i )
Vec_IntPush( vSigs, Cba_ObjCopy(p, Cba_ObjFanin(p, iObj)) );
}
Cba_Man_t * Cba_ManCollapseInt( Cba_Man_t * p )
Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p )
{
int i, iObj;
Vec_Int_t * vSigs = Vec_IntAlloc( 1000 );
......@@ -259,29 +271,26 @@ Cba_Man_t * Cba_ManCollapseInt( Cba_Man_t * p )
Cba_Ntk_t * pRootNew = Cba_ManRoot( pNew );
Cba_NtkAlloc( pRootNew, Cba_NtkNameId(pRoot), Cba_NtkPiNum(pRoot), Cba_NtkPoNum(pRoot), Cba_ManClpObjNum(p) );
Cba_NtkForEachPi( pRoot, iObj, i )
Vec_IntPush( vSigs, Cba_ObjAlloc(pRootNew, CBA_OBJ_PI, i, -1) );
Vec_IntPush( vSigs, Cba_ObjAlloc(pRootNew, CBA_OBJ_PI, -1) );
Cba_NtkCollapse_rec( pRootNew, pRoot, vSigs );
assert( Vec_IntSize(vSigs) == Cba_NtkPoNum(pRoot) );
Cba_NtkForEachPo( pRoot, iObj, i )
Cba_ObjAlloc( pRootNew, CBA_OBJ_PO, i, Vec_IntEntry(vSigs, i) );
Cba_ObjAlloc( pRootNew, CBA_OBJ_PO, Vec_IntEntry(vSigs, i) );
assert( Cba_NtkObjNum(pRootNew) == Cba_NtkObjNumAlloc(pRootNew) );
Vec_IntFree( vSigs );
/*
// transfer PI/PO names
Cba_NtkStartNames( pRootNew );
Cba_NtkForEachPo( pRoot, iObj, i )
Cba_ObjSetName( pRootNew, Cba_NtkPo(pRootNew, i), Cba_ObjName(pRoot, iObj) );
Cba_NtkForEachPo( pRoot, iObj, i )
Cba_ObjSetName( pRootNew, Cba_NtkPo(pRootNew, i), Cba_ObjName(pRoot, iObj) );
if ( Cba_NtkHasNames(pRoot) )
{
Cba_NtkStartNames( pRootNew );
Cba_NtkForEachPo( pRoot, iObj, i )
Cba_ObjSetName( pRootNew, Cba_NtkPo(pRootNew, i), Cba_ObjName(pRoot, iObj) );
Cba_NtkForEachPo( pRoot, iObj, i )
Cba_ObjSetName( pRootNew, Cba_NtkPo(pRootNew, i), Cba_ObjName(pRoot, iObj) );
}
*/
return pNew;
}
Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p )
{
Cba_Ntk_t * pNtk; int i;
Cba_ManForEachNtk( p, pNtk, i )
if ( !Cba_NtkDfsUserBoxes(pNtk) )
return NULL;
return Cba_ManCollapseInt( p );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
......
......@@ -147,7 +147,7 @@ void Prs_ManBuildNtk( Cba_Ntk_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_
{
if ( Vec_IntEntry(vMap, NameId) != -1 )
printf( "Primary inputs %d and %d have the same name.\n", Vec_IntEntry(vMap, NameId), i );
iObj = Cba_ObjAlloc( pNew, CBA_OBJ_PI, -1, -1 );
iObj = Cba_ObjAlloc( pNew, CBA_OBJ_PI, -1 );
Cba_ObjSetName( pNew, iObj, NameId );
Vec_IntWriteEntry( vMap, NameId, iObj );
}
......@@ -250,7 +250,7 @@ void Prs_ManBuildNtk( Cba_Ntk_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_
}
Prs_NtkForEachPo( pNtk, NameId, i )
{
iObj = Cba_ObjAlloc( pNew, CBA_OBJ_PO, -1, Vec_IntEntry(vMap, NameId) );
iObj = Cba_ObjAlloc( pNew, CBA_OBJ_PO, Vec_IntEntry(vMap, NameId) );
Cba_ObjSetName( pNew, iObj, NameId );
}
if ( nNonDriven )
......
......@@ -289,7 +289,7 @@ int Cba_NtkDeriveFromPtr( Cba_Ntk_t * pNtk, Vec_Ptr_t * vNtk, Vec_Int_t * vMap,
NameId = Abc_NamStrFindOrAdd( pNtk->pDesign->pStrs, pName, NULL );
if ( Vec_IntGetEntryFull(vMap, NameId) != -1 )
{ printf( "PI with name \"%s\" is not unique module \"%s\".\n", pName, pModuleName ); return 0; }
iObj = Cba_ObjAlloc( pNtk, CBA_OBJ_PI, -1, -1 );
iObj = Cba_ObjAlloc( pNtk, CBA_OBJ_PI, -1 );
Cba_ObjSetName( pNtk, iObj, NameId );
Vec_IntSetEntryFull( vMap, NameId, iObj );
}
......@@ -340,7 +340,7 @@ int Cba_NtkDeriveFromPtr( Cba_Ntk_t * pNtk, Vec_Ptr_t * vNtk, Vec_Int_t * vMap,
NameId = Abc_NamStrFindOrAdd( pNtk->pDesign->pStrs, pName, NULL );
if ( Vec_IntGetEntryFull(vMap, NameId) == -1 )
printf( "PO with name \"%s\" in not driven in module \"%s\".\n", pName, pModuleName );
iObj = Cba_ObjAlloc( pNtk, CBA_OBJ_PO, -1, Vec_IntGetEntryFull(vMap, NameId) );
iObj = Cba_ObjAlloc( pNtk, CBA_OBJ_PO, Vec_IntGetEntryFull(vMap, NameId) );
Cba_ObjSetName( pNtk, iObj, NameId );
}
// update map
......
......@@ -322,7 +322,7 @@ void Abc_SclDnsizePerformInt( SC_Lib * pLib, Abc_Ntk_t * pNtk, SC_SizePars * pPa
Vec_IntFree( vEvals );
Vec_IntFree( vTryLater );
if ( !pPars->fVerbose )
printf( " \r" );
printf( " \r" );
// report runtime
p->timeTotal = Abc_Clock() - p->timeTotal;
......
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