absRefSelect.c 10.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/**CFile****************************************************************

  FileName    [absRefSelect.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Abstraction package.]

  Synopsis    [Post-processes the set of selected refinement objects.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: absRefSelect.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/
 
#include "abs.h"
#include "absRef.h"

ABC_NAMESPACE_IMPL_START 

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

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Rnm_ManPrintSelected( Rnm_Man_t * p, Vec_Int_t * vNewPPis )
{
    Gia_Obj_t * pObj;
    int i, Counter = 0;
    Gia_ManForEachObjVec( p->vMap, p->pGia, pObj, i )
        if ( Gia_ObjIsPi(p->pGia, pObj) ) 
            printf( "-" );
        else if ( Vec_IntFind(vNewPPis, Gia_ObjId(p->pGia, pObj)) >= 0 )// this is PPI
            printf( "1" ), Counter++;
        else
            printf( "0" );
    printf( " %3d\n", Counter );
}

/**Function*************************************************************

  Synopsis    [Perform structural analysis.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ga2_StructAnalize( Gia_Man_t * p, Vec_Int_t * vFront, Vec_Int_t * vInter, Vec_Int_t * vNewPPis )
{
72
    Vec_Int_t * vFanins;
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    Gia_Obj_t * pObj, * pFanin;
    int i, k;
    // clean labels
    Gia_ManForEachObj( p, pObj, i )
        pObj->fMark0 = pObj->fMark1 = 0;
    // label frontier
    Gia_ManForEachObjVec( vFront, p, pObj, i )
        pObj->fMark0 = 1, pObj->fMark1 = 0;
    // label objects
    Gia_ManForEachObjVec( vInter, p, pObj, i )
        pObj->fMark1 = 0, pObj->fMark1 = 1;
    // label selected
    Gia_ManForEachObjVec( vNewPPis, p, pObj, i )
        pObj->fMark1 = 1, pObj->fMark1 = 1;
    // explore selected
    Gia_ManForEachObjVec( vNewPPis, p, pObj, i )
    {
        printf( "Selected PPI %3d : ", i+1 );
        printf( "%6d ",  Gia_ObjId(p, pObj) );
        printf( "\n" );
93 94
        vFanins = Ga2_ObjLeaves( p, pObj );
        Gia_ManForEachObjVec( vFanins, p, pFanin, k )
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
        {
            printf( "    " );
            printf( "%6d ", Gia_ObjId(p, pFanin) );
            if ( pFanin->fMark0 && pFanin->fMark1 )
                printf( "selected PPI" );
            else if ( pFanin->fMark0 && !pFanin->fMark1 )
                printf( "frontier (original PI or PPI)" );
            else if ( !pFanin->fMark0 &&  pFanin->fMark1 )
                printf( "abstracted node" );
            else if ( !pFanin->fMark0 && !pFanin->fMark1 )
                printf( "free variable" );
            printf( "\n" );
        }
    }
}

/**Function*************************************************************

  Synopsis    [Postprocessing the set of PPIs using structural analysis.]

  Description [The following sets are used:
  The set of all PI+PPI is in p->vMap.
  The set of all abstracted objects is in p->vObjs;
  The set of important PPIs is in vOldPPis.
  The new set of selected PPIs is in vNewPPis.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Int_t * Rnm_ManFilterSelected( Rnm_Man_t * p, Vec_Int_t * vOldPPis )
{
128 129
    int fVerbose = 0;
    Vec_Int_t * vNewPPis, * vFanins;
130 131 132 133 134 135 136 137 138 139 140
    Gia_Obj_t * pObj, * pFanin;
    int i, k, RetValue, Counters[3] = {0};

    // (0) make sure fanin counters are 0 at the beginning
//    Gia_ManForEachObj( p->pGia, pObj, i )
//        assert( Rnm_ObjCount(p, pObj) == 0 );

    // (1) increment PPI fanin counters
    Vec_IntClear( p->vFanins );
    Gia_ManForEachObjVec( vOldPPis, p->pGia, pObj, i )
    {
141 142
        vFanins = Ga2_ObjLeaves( p->pGia, pObj );
        Gia_ManForEachObjVec( vFanins, p->pGia, pFanin, k )
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
            if ( Rnm_ObjAddToCount(p, pFanin) == 0 ) // fanin counter is 0 -- save it
                Vec_IntPush( p->vFanins, Gia_ObjId(p->pGia, pFanin) );
    }

    // (3) select objects with reconvergence, which create potential constraints
    // - flop objects
    // - objects whose fanin belongs to the justified area
    // - objects whose fanins overlap
    // (these do not guantee reconvergence, but may potentially have it)
    // (other objects cannot have reconvergence, even if they are added)
    vNewPPis = Vec_IntAlloc( 100 );
    Gia_ManForEachObjVec( vOldPPis, p->pGia, pObj, i )
    {
        if ( Gia_ObjIsRo(p->pGia, pObj) )
        {
            if ( fVerbose )
                Counters[0]++;
            Vec_IntPush( vNewPPis, Gia_ObjId(p->pGia, pObj) );
            continue;
        }
163 164
        vFanins = Ga2_ObjLeaves( p->pGia, pObj );
        Gia_ManForEachObjVec( vFanins, p->pGia, pFanin, k )
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
        {
            if ( Rnm_ObjIsJust(p, pFanin) || Rnm_ObjCount(p, pFanin) > 1 )
            {
                if ( fVerbose )
                    Counters[1] += Rnm_ObjIsJust(p, pFanin);
                if ( fVerbose )
                    Counters[2] += (Rnm_ObjCount(p, pFanin) > 1);
                Vec_IntPush( vNewPPis, Gia_ObjId(p->pGia, pObj) );
                break;
            }
        }
    }
    RetValue = Vec_IntUniqify( vNewPPis );
    assert( RetValue == 0 );

    // (4) clear fanin counters
    // this is important for counters to be correctly set in the future iterations -- see step (0)
    Gia_ManForEachObjVec( p->vFanins, p->pGia, pObj, i )
        Rnm_ObjSetCount( p, pObj, 0 );

    // visualize
    if ( fVerbose )
        printf( "*** Refinement %3d : PI+PPI =%4d. Old =%4d. New =%4d.   FF =%4d. Just =%4d. Shared =%4d.\n", 
            p->nRefId, Vec_IntSize(p->vMap), Vec_IntSize(vOldPPis), Vec_IntSize(vNewPPis), Counters[0], Counters[1], Counters[2] );

//    Rnm_ManPrintSelected( p, vNewPPis );
//    Ga2_StructAnalize( p->pGia, p->vMap, p->vObjs, vNewPPis );
    return vNewPPis;
}


/**Function*************************************************************

  Synopsis    [Improved postprocessing the set of PPIs.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Int_t * Rnm_ManFilterSelectedNew( Rnm_Man_t * p, Vec_Int_t * vOldPPis )
{
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
    static int Counter = 0;
    int fVerbose = 0;
    Vec_Int_t * vNewPPis, * vFanins, * vFanins2;
    Gia_Obj_t * pObj, * pFanin, * pFanin2;
    int i, k, k2, RetValue, Counters[3] = {0};

    // return full set of PPIs once in a while
    if ( ++Counter % 9 == 0 )
        return Vec_IntDup( vOldPPis );
    return Rnm_ManFilterSelected( p, vOldPPis );

    // (0) make sure fanin counters are 0 at the beginning
//    Gia_ManForEachObj( p->pGia, pObj, i )
//        assert( Rnm_ObjCount(p, pObj) == 0 );

    // (1) increment two levels of PPI fanin counters
    Vec_IntClear( p->vFanins );
    Gia_ManForEachObjVec( vOldPPis, p->pGia, pObj, i )
    {
        // go through the fanins
        vFanins = Ga2_ObjLeaves( p->pGia, pObj );
        Gia_ManForEachObjVec( vFanins, p->pGia, pFanin, k )
        {
            Rnm_ObjAddToCount(p, pFanin);
            if ( Rnm_ObjIsJust(p, pFanin) )   // included in the abstraction
                Rnm_ObjAddToCount(p, pFanin); // count it second time!
            Vec_IntPush( p->vFanins, Gia_ObjId(p->pGia, pFanin) );

            // go through the fanins of the fanins
            vFanins2 = Ga2_ObjLeaves( p->pGia, pFanin );
            Gia_ManForEachObjVec( vFanins2, p->pGia, pFanin2, k2 )
            {
                Rnm_ObjAddToCount(p, pFanin2);
                if ( Rnm_ObjIsJust(p, pFanin2) )   // included in the abstraction
                    Rnm_ObjAddToCount(p, pFanin2); // count it second time!
                Vec_IntPush( p->vFanins, Gia_ObjId(p->pGia, pFanin2) );
            }
        }
    }

    // (3) select objects with reconvergence, which create potential constraints
    // - flop objects - yes
    // - objects whose fanin (or fanins' fanin) belongs to the justified area - yes
    // - objects whose fanins (or fanins' fanin) overlap - yes
    // (these do not guantee reconvergence, but may potentially have it)
    // (other objects cannot have reconvergence, even if they are added)
    vNewPPis = Vec_IntAlloc( 100 );
    Gia_ManForEachObjVec( vOldPPis, p->pGia, pObj, i )
    {
        if ( Gia_ObjIsRo(p->pGia, pObj) )
        {
            if ( fVerbose )
                Counters[0]++;
            Vec_IntPush( vNewPPis, Gia_ObjId(p->pGia, pObj) );
            continue;
        } 
        // go through the first fanins
        vFanins = Ga2_ObjLeaves( p->pGia, pObj );
        Gia_ManForEachObjVec( vFanins, p->pGia, pFanin, k )
        {
            if ( Rnm_ObjCount(p, pFanin) > 1 )
                Vec_IntPush( vNewPPis, Gia_ObjId(p->pGia, pObj) );
            continue;

            // go through the fanins of the fanins
            vFanins2 = Ga2_ObjLeaves( p->pGia, pFanin );
            Gia_ManForEachObjVec( vFanins2, p->pGia, pFanin2, k2 )
            {
                if ( Rnm_ObjCount(p, pFanin2) > 1 )
                {
//                    Vec_IntPush( vNewPPis, Gia_ObjId(p->pGia, pFanin) );
                    Vec_IntPush( vNewPPis, Gia_ObjId(p->pGia, pObj) );
                }
            }
        }
    }
    RetValue = Vec_IntUniqify( vNewPPis );
//    assert( RetValue == 0 ); // we will have duplicated entries here!

    // (4) clear fanin counters
    // this is important for counters to be correctly set in the future iterations -- see step (0)
    Gia_ManForEachObjVec( p->vFanins, p->pGia, pObj, i )
        Rnm_ObjSetCount( p, pObj, 0 );

    // visualize
    if ( fVerbose )
        printf( "*** Refinement %3d : PI+PPI =%4d. Old =%4d. New =%4d.   FF =%4d. Just =%4d. Shared =%4d.\n", 
            p->nRefId, Vec_IntSize(p->vMap), Vec_IntSize(vOldPPis), Vec_IntSize(vNewPPis), Counters[0], Counters[1], Counters[2] );

//    Rnm_ManPrintSelected( p, vNewPPis );
//    Ga2_StructAnalize( p->pGia, p->vMap, p->vObjs, vNewPPis );
300 301 302 303 304 305 306 307 308 309
    return vNewPPis;
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


ABC_NAMESPACE_IMPL_END