Extending &trim to trim structurally equivalent primary outputs.

This commit is contained in:
Alan Mishchenko 2021-08-19 09:48:46 -07:00
parent 4da6cc8904
commit 77760dd8ac
3 changed files with 141 additions and 3 deletions

View File

@ -2320,6 +2320,31 @@ Gia_Man_t * Gia_ManDupTrimmed2( Gia_Man_t * p )
assert( !Gia_ManHasDangling( pNew ) );
return pNew;
}
Gia_Man_t * Gia_ManDupTrimmed3( Gia_Man_t * p )
{
Vec_Int_t * vMap = Vec_IntStartFull( Gia_ManObjNum(p) );
Gia_Man_t * pNew;
Gia_Obj_t * pObj;
int i;
pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManFillValue( p );
Gia_ManConst0(p)->Value = 0;
Gia_ManForEachCi( p, pObj, i )
pObj->Value = Gia_ManAppendCi(pNew);
Gia_ManForEachAnd( p, pObj, i )
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
// mark duplicated POs
Gia_ManForEachPo( p, pObj, i )
Vec_IntWriteEntry( vMap, Gia_ObjFaninId0p(p, pObj), i );
Gia_ManForEachPo( p, pObj, i )
if ( Vec_IntEntry(vMap, Gia_ObjFaninId0p(p, pObj)) == i )
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
Vec_IntFree( vMap );
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
return pNew;
}
/**Function*************************************************************

View File

@ -2819,6 +2819,108 @@ void Gia_ManDumpSuppFileTest( Gia_Man_t * p, char * pFileName )
Vec_StrFree( vRes );
}
/**Function*************************************************************
Synopsis [Compute support diffs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManConvertSupp_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj )
{
if ( !Gia_ObjIsAnd(pObj) )
return;
if ( Gia_ObjIsTravIdCurrent(p, pObj) )
return;
Gia_ObjSetTravIdCurrent(p, pObj);
Gia_ManConvertSupp_rec( pNew, p, Gia_ObjFanin0(pObj) );
Gia_ManConvertSupp_rec( pNew, p, Gia_ObjFanin1(pObj) );
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
}
Gia_Man_t * Gia_ManConvertSupp( Gia_Man_t * p )
{
int fOnly1 = 0;
int fVerbose = 1;
abctime clk = Abc_Clock();
Gia_Man_t * pNew, * pTemp;
Gia_Obj_t * pObjPi, * pObjRi, * pObjRo;
Vec_Int_t * vSupp = Vec_IntAlloc( 100 );
Vec_Int_t * vAnds = Vec_IntAlloc( 100 );
int i, n, iLits[2];
assert( Gia_ManRegNum(p) && Gia_ManRegNum(p) % 8 == 0 );
pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManFillValue(p);
Gia_ManConst0(p)->Value = 0;
Gia_ManForEachPi( p, pObjPi, i )
pObjPi->Value = Gia_ManAppendCi( pNew );
Gia_ManHashAlloc( pNew );
Gia_ManForEachRi( p, pObjRi, i )
{
pObjRo = Gia_ObjRiToRo(p, pObjRi);
if ( (i - Gia_ManPoNum(p)) % 8 != 0 )
continue;
if ( fOnly1 )
{
assert( pObjRo->Value == ~0 );
for ( n = 0; n < 2; n++ )
{
pObjRo->Value = n;
Gia_ManIncrementTravId( p );
Gia_ManConvertSupp_rec( pNew, p, Gia_ObjFanin0(pObjRi) );
iLits[n] = Gia_ObjFanin0Copy(pObjRi);
}
pObjRo->Value = ~0;
Gia_ManAppendCo( pNew, Abc_LitNot(Gia_ManHashAnd( pNew, iLits[1], Abc_LitNot(iLits[0]) )) );
}
else
{
int Fanin = Gia_ObjFaninId0p( p, pObjRi );
Vec_Int_t * vNodes = Gia_ManCollectNodesCis( p, &Fanin, 1 );
Gia_Obj_t * pObj; int i, m;
Vec_IntClear( vSupp );
Vec_IntClear( vAnds );
Gia_ManForEachObjVec( vNodes, p, pObj, i )
Vec_IntPush( Gia_ObjIsAnd(pObj) ? vAnds : vSupp, Gia_ObjId(p, pObj) );
Vec_IntFree( vNodes );
Vec_IntSort( vSupp, 0 );
for ( m = 0; m < 4; m++ )
{
Gia_ManForEachObjVec( vSupp, p, pObj, i )
if ( i >= Vec_IntSize(vSupp)-5 )
pObj->Value = (i == Vec_IntSize(vSupp)-5+m) ? 1 : 0;
Gia_ManForEachObjVec( vAnds, p, pObj, i )
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
//if ( m == 4 )
// Gia_ManAppendCo( pNew, 0 );
//else
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObjRi) );
//Gia_ManAppendCo( pNew, Abc_Var2Lit( Vec_IntEntry(vSupp, Vec_IntSize(vSupp)-5+m), 0 ) );
Gia_ManForEachObjVec( vSupp, p, pObj, i )
if ( i >= Vec_IntSize(vSupp)-5 )
pObj->Value = Abc_Var2Lit( 1 + Gia_ObjCioId(pObj), 0 );
}
}
}
Vec_IntFree( vSupp );
Vec_IntFree( vAnds );
Gia_ManHashStop( pNew );
//Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
if ( fVerbose )
printf( "Transformed %d outputs, ", Gia_ManPoNum(pNew) );
if ( fVerbose )
Abc_PrintTime( 0, "Time", Abc_Clock() - clk );
return pNew;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -32628,8 +32628,9 @@ int Abc_CommandAbc9Trim( Abc_Frame_t * pAbc, int argc, char ** argv )
int fTrimCos = 1;
int fDualOut = 0;
int fPoFedByPi = 0;
int fPoFedByPo = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "Viocdh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "Viocpdh" ) ) != EOF )
{
switch ( c )
{
@ -32653,6 +32654,9 @@ int Abc_CommandAbc9Trim( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'c':
fPoFedByPi ^= 1;
break;
case 'p':
fPoFedByPo ^= 1;
break;
case 'd':
fDualOut ^= 1;
break;
@ -32674,16 +32678,23 @@ int Abc_CommandAbc9Trim( Abc_Frame_t * pAbc, int argc, char ** argv )
pTemp = Gia_ManDupTrimmed2( pTemp2 = pTemp );
Gia_ManStop( pTemp2 );
}
if ( fPoFedByPo )
{
extern Gia_Man_t * Gia_ManDupTrimmed3( Gia_Man_t * p );
pTemp = Gia_ManDupTrimmed3( pTemp2 = pTemp );
Gia_ManStop( pTemp2 );
}
Abc_FrameUpdateGia( pAbc, pTemp );
return 0;
usage:
Abc_Print( -2, "usage: &trim [-V num] [-iocdh]\n" );
Abc_Print( -2, "usage: &trim [-V num] [-iocpdh]\n" );
Abc_Print( -2, "\t removes PIs without fanout and PO driven by constants\n" );
Abc_Print( -2, "\t-V num : the value (0 or 1) of POs to remove [default = both]\n" );
Abc_Print( -2, "\t-i : toggle removing PIs [default = %s]\n", fTrimCis? "yes": "no" );
Abc_Print( -2, "\t-o : toggle removing POs [default = %s]\n", fTrimCos? "yes": "no" );
Abc_Print( -2, "\t-c : toggle additionally removing POs fed by PIs [default = %s]\n", fPoFedByPi? "yes": "no" );
Abc_Print( -2, "\t-p : toggle additionally removing duplicated POs [default = %s]\n", fPoFedByPo? "yes": "no" );
Abc_Print( -2, "\t-d : toggle using dual-output miter [default = %s]\n", fDualOut? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
@ -49291,7 +49302,7 @@ int Abc_CommandAbc9Test( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "Abc_CommandAbc9Test(): There is no AIG.\n" );
return 1;
}
Abc_FrameUpdateGia( pAbc, Gia_ManPerformNewResub(pAbc->pGia, 100, 8, 1, 1) );
Abc_FrameUpdateGia( pAbc, Gia_ManPerformNewResub(pAbc->pGia, 100, 6, 1, 1) );
// printf( "AIG in \"%s\" has the sum of output support sizes equal to %d.\n", pAbc->pGia->pSpec, Gia_ManSumTotalOfSupportSizes(pAbc->pGia) );
return 0;
usage: