ntlUtil.c 20.2 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
/**CFile****************************************************************

  FileName    [ntlUtil.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Netlist representation.]

  Synopsis    [Various utilities.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "ntl.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

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
  Synopsis    [Returns one if the file has a given extension.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_FileIsType( char * pFileName, char * pS1, char * pS2, char * pS3 )
{
    int lenS, lenF = strlen(pFileName);
    lenS = pS1 ? strlen(pS1) : 0;
    if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS1, lenS ) )
        return 1;
    lenS = pS2 ? strlen(pS2) : 0;
    if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS2, lenS ) )
        return 1;
    lenS = pS3 ? strlen(pS3) : 0;
    if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS3, lenS ) )
        return 1;
    return 0;
}

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

Alan Mishchenko committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  Synopsis    [Reads the maximum number of fanins.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_ModelGetFaninMax( Ntl_Mod_t * pRoot )
{
    Ntl_Obj_t * pNode;
    int i, nFaninsMax = 0;
    Ntl_ModelForEachNode( pRoot, pNode, i )
    {
        if ( nFaninsMax < Ntl_ObjFaninNum(pNode) )
            nFaninsMax = Ntl_ObjFaninNum(pNode);
    }
    return nFaninsMax;
}

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

  Synopsis    [If the net is driven by an inv/buf, returns its fanin.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Ntl_Net_t * Ntl_ModelFindSimpleNet( Ntl_Net_t * pNetCo )
{
    // skip the case when the net is not driven by a node
    if ( !Ntl_ObjIsNode(pNetCo->pDriver) )
        return NULL;
    // skip the case when the node is not an inv/buf
    if ( Ntl_ObjFaninNum(pNetCo->pDriver) != 1 )
        return NULL;
    return Ntl_ObjFanin0(pNetCo->pDriver);
}

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

Alan Mishchenko committed
107
  Synopsis    [Connects COs to the internal nodes other than inv/bufs.]
Alan Mishchenko committed
108 109 110 111 112 113 114 115

  Description [Should be called immediately after reading from file.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
int Ntl_ManCountSimpleCoDriversOne( Ntl_Net_t * pNetCo )
{
    Ntl_Net_t * pNetFanin;
    // skip the case when the net is not driven by a node
    if ( !Ntl_ObjIsNode(pNetCo->pDriver) )
        return 0;
    // skip the case when the node is not an inv/buf
    if ( Ntl_ObjFaninNum(pNetCo->pDriver) != 1 )
        return 0;
    // skip the case when the second-generation driver is not a node
    pNetFanin = Ntl_ObjFanin0(pNetCo->pDriver);
    if ( !Ntl_ObjIsNode(pNetFanin->pDriver) )
        return 0;
    return 1;
}

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

  Synopsis    [Counts COs that are connected to the internal nodes through invs/bufs.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_ManCountSimpleCoDrivers( Ntl_Man_t * p )
{
    Ntl_Net_t * pNetCo;
    Ntl_Obj_t * pObj;
    Ntl_Mod_t * pRoot;
    int i, k, Counter;
    Counter = 0;
    pRoot = Ntl_ManRootModel( p );
    Ntl_ModelForEachPo( pRoot, pObj, i )
        Counter += Ntl_ManCountSimpleCoDriversOne( Ntl_ObjFanin0(pObj) );
    Ntl_ModelForEachLatch( pRoot, pObj, i )
        Counter += Ntl_ManCountSimpleCoDriversOne( Ntl_ObjFanin0(pObj) );
    Ntl_ModelForEachBox( pRoot, pObj, i )
        Ntl_ObjForEachFanin( pObj, pNetCo, k )
            Counter += Ntl_ManCountSimpleCoDriversOne( pNetCo );
    return Counter;
}

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

Alan Mishchenko committed
163 164 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
  Synopsis    [Derives the array of CI names.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Ptr_t * Ntl_ManCollectCiNames( Ntl_Man_t * p )
{
    Vec_Ptr_t * vNames;
    Ntl_Net_t * pNet;
    int i;
    vNames = Vec_PtrAlloc( 1000 );
    Ntl_ManForEachCiNet( p, pNet, i )
        Vec_PtrPush( vNames, pNet->pName );
    return vNames;
}

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

  Synopsis    [Derives the array of CI names.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Ptr_t * Ntl_ManCollectCoNames( Ntl_Man_t * p )
{
    Vec_Ptr_t * vNames;
    Ntl_Net_t * pNet;
    int i;
    vNames = Vec_PtrAlloc( 1000 );
    Ntl_ManForEachCoNet( p, pNet, i )
        Vec_PtrPush( vNames, pNet->pName );
    return vNames;
}

Alan Mishchenko committed
205 206 207 208 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
/**Function*************************************************************

  Synopsis    [Marks the CI/CO nets.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ntl_ManMarkCiCoNets( Ntl_Man_t * p )
{
    Ntl_Net_t * pNet;
    int i;
    Ntl_ManForEachCiNet( p, pNet, i )
        pNet->fMark = 1;
    Ntl_ManForEachCoNet( p, pNet, i )
        pNet->fMark = 1;
}

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

  Synopsis    [Unmarks the CI/CO nets.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ntl_ManUnmarkCiCoNets( Ntl_Man_t * p )
{
    Ntl_Net_t * pNet;
    int i;
    Ntl_ManForEachCiNet( p, pNet, i )
        pNet->fMark = 0;
    Ntl_ManForEachCoNet( p, pNet, i )
        pNet->fMark = 0;
}

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

Alan Mishchenko committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
  Synopsis    [Convert initial values of registers to be zero.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ntl_ManSetZeroInitValues( Ntl_Man_t * p )
{
    Ntl_Mod_t * pRoot;
    Ntl_Obj_t * pObj;
    int i;
    pRoot = Ntl_ManRootModel(p);
    Ntl_ModelForEachLatch( pRoot, pObj, i )
Alan Mishchenko committed
265
        pObj->LatchId.regInit = 0;
Alan Mishchenko committed
266 267 268 269 270 271 272 273 274 275 276 277 278
}

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

  Synopsis    [Transforms the netlist to have latches with const-0 init-values.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
279
void Ntl_ManAddInverters( Ntl_Mod_t * pRoot, Ntl_Obj_t * pObj )
Alan Mishchenko committed
280 281
{
    char * pStore;
Alan Mishchenko committed
282
//    Ntl_Mod_t * pRoot = pObj->pModel;
Alan Mishchenko committed
283 284 285 286
    Ntl_Man_t * pMan = pRoot->pMan;
    Ntl_Net_t * pNetLo, * pNetLi, * pNetLoInv, * pNetLiInv;
    Ntl_Obj_t * pNode;
    int nLength, RetValue;
Alan Mishchenko committed
287
    assert( Ntl_ObjIsInit1( pObj ) );
Alan Mishchenko committed
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
    // get the nets
    pNetLi = Ntl_ObjFanin0(pObj);
    pNetLo = Ntl_ObjFanout0(pObj);
    // get storage for net names
    nLength = strlen(pNetLi->pName) + strlen(pNetLo->pName) + 10; 
    pStore = Aig_MmFlexEntryFetch( pMan->pMemSops, nLength );
    // create input interter
    pNode = Ntl_ModelCreateNode( pRoot, 1 );
    pNode->pSop = Ntl_ManStoreSop( pMan->pMemSops, "0 1\n" );
    Ntl_ObjSetFanin( pNode, pNetLi, 0 );
    // create input net
    strcpy( pStore, pNetLi->pName );
    strcat( pStore, "_inv" );
    if ( Ntl_ModelFindNet( pRoot, pStore ) )
    {
        printf( "Ntl_ManTransformInitValues(): Internal error! Cannot create net with LI-name + _inv\n" );
        return;
    }
    pNetLiInv = Ntl_ModelFindOrCreateNet( pRoot, pStore );
    RetValue = Ntl_ModelSetNetDriver( pNode, pNetLiInv );
    assert( RetValue );
    // connect latch to the input net
    Ntl_ObjSetFanin( pObj, pNetLiInv, 0 );
    // disconnect latch from the output net
    RetValue = Ntl_ModelClearNetDriver( pObj, pNetLo );
    assert( RetValue );
    // create the output net
    strcpy( pStore, pNetLo->pName );
    strcat( pStore, "_inv" );
    if ( Ntl_ModelFindNet( pRoot, pStore ) )
    {
        printf( "Ntl_ManTransformInitValues(): Internal error! Cannot create net with LO-name + _inv\n" );
        return;
    }
    pNetLoInv = Ntl_ModelFindOrCreateNet( pRoot, pStore );
    RetValue = Ntl_ModelSetNetDriver( pObj, pNetLoInv );
    assert( RetValue );
    // create output interter
    pNode = Ntl_ModelCreateNode( pRoot, 1 );
    pNode->pSop = Ntl_ManStoreSop( pMan->pMemSops, "0 1\n" );
    Ntl_ObjSetFanin( pNode, pNetLoInv, 0 );
    // redirect the old output net
    RetValue = Ntl_ModelSetNetDriver( pNode, pNetLo );
    assert( RetValue );
}

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

  Synopsis    [Transforms the netlist to have latches with const-0 init-values.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ntl_ManTransformInitValues( Ntl_Man_t * p )
{
    Ntl_Mod_t * pRoot;
    Ntl_Obj_t * pObj;
    int i;
    pRoot = Ntl_ManRootModel(p);
    Ntl_ModelForEachLatch( pRoot, pObj, i )
    {
Alan Mishchenko committed
353
        if ( Ntl_ObjIsInit1( pObj ) )
Alan Mishchenko committed
354
            Ntl_ManAddInverters( pRoot, pObj );
Alan Mishchenko committed
355
        pObj->LatchId.regInit = 0;
Alan Mishchenko committed
356
    }
Alan Mishchenko committed
357 358 359 360
}

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

Alan Mishchenko committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
  Synopsis    [Transforms register classes.]

  Description [Returns the vector of vectors containing the numbers
  of registers belonging to the same class. Skips classes containing
  less than the given number of registers.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Vec_t * Ntl_ManTransformRegClasses( Ntl_Man_t * pMan, int nSizeMax, int fVerbose )
{
    Vec_Ptr_t * vParts;
    Vec_Int_t * vPart;
    int * pClassNums, nClasses;
    int Class, ClassMax, i, k;
    if ( Vec_IntSize(pMan->vRegClasses) == 0 )
    {
        printf( "Ntl_ManReportRegClasses(): Register classes are not defined.\n" );
Alan Mishchenko committed
381
//        return (Vec_Vec_t *)Vec_PtrAlloc(0);
Alan Mishchenko committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
        return NULL;
    }
    // find the largest class
    ClassMax = -1;
    Vec_IntForEachEntry( pMan->vRegClasses, Class, k )
    {
        if ( Class < 0 )
        {
            printf( "Ntl_ManReportRegClasses(): Register class (%d) is negative.\n", Class );
            return NULL;
        }
        if ( ClassMax < Class )
            ClassMax = Class;
    }
    if ( ClassMax > 1000000 )
    {
        printf( "Ntl_ManReportRegClasses(): The largest number of a register class (%d) is too large (> 1000000).\n", ClassMax );
        return NULL;
    }
    // count the number of classes
Alan Mishchenko committed
402
    pClassNums = ABC_CALLOC( int, ClassMax + 1 );
Alan Mishchenko committed
403 404 405 406 407 408 409 410 411 412 413
    Vec_IntForEachEntry( pMan->vRegClasses, Class, k )
        pClassNums[Class]++;
    // count the number of classes
    nClasses = 0;
    for ( i = 0; i <= ClassMax; i++ )
        nClasses += (int)(pClassNums[i] > 0);
    // report the classes
    if ( fVerbose && nClasses > 1 )
    {
        printf( "The number of register clases = %d.\n", nClasses );
        for ( i = 0; i <= ClassMax; i++ )
Alan Mishchenko committed
414
            if ( pClassNums[i] )
Alan Mishchenko committed
415
                printf( "(%d, %d)  ", i, pClassNums[i] );
Alan Mishchenko committed
416 417 418 419 420
        printf( "\n" );
    }
    // skip if there is only one class
    if ( nClasses == 1 )
    {
Alan Mishchenko committed
421 422 423 424 425 426 427
        vParts = NULL;
        if ( Vec_IntSize(pMan->vRegClasses) >= nSizeMax )
        {
            vParts = Vec_PtrAlloc( 100 );
            vPart = Vec_IntStartNatural( Vec_IntSize(pMan->vRegClasses) );
            Vec_PtrPush( vParts, vPart );
        }
Alan Mishchenko committed
428
        printf( "There is only one class with %d registers.\n", Vec_IntSize(pMan->vRegClasses) );
Alan Mishchenko committed
429
        ABC_FREE( pClassNums );
Alan Mishchenko committed
430
        return (Vec_Vec_t *)vParts;
Alan Mishchenko committed
431 432 433 434 435
    }
    // create classes
    vParts = Vec_PtrAlloc( 100 );
    for ( i = 0; i <= ClassMax; i++ )
    {
Alan Mishchenko committed
436
        if ( pClassNums[i] == 0 || pClassNums[i] < nSizeMax )
Alan Mishchenko committed
437 438 439 440 441 442 443 444
            continue;
        vPart = Vec_IntAlloc( pClassNums[i] );
        Vec_IntForEachEntry( pMan->vRegClasses, Class, k )
            if ( Class == i )
                Vec_IntPush( vPart, k );
        assert( Vec_IntSize(vPart) == pClassNums[i] );
        Vec_PtrPush( vParts, vPart );
    }
Alan Mishchenko committed
445
    ABC_FREE( pClassNums );
Alan Mishchenko committed
446
    Vec_VecSort( (Vec_Vec_t *)vParts, 1 );
Alan Mishchenko committed
447 448 449 450
    // report the selected classes
    if ( fVerbose )
    {
        printf( "The number of selected register clases = %d.\n", Vec_PtrSize(vParts) );
451
        Vec_PtrForEachEntry( Vec_Int_t *, vParts, vPart, i )
Alan Mishchenko committed
452
            printf( "(%d, %d)  ", i, Vec_IntSize(vPart) );
Alan Mishchenko committed
453 454 455 456 457 458 459
        printf( "\n" );
    }
    return (Vec_Vec_t *)vParts;
}

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

Alan Mishchenko committed
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
  Synopsis    [Filter register clases using clock-domain information.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ntl_ManFilterRegisterClasses( Aig_Man_t * pAig, Vec_Int_t * vRegClasses, int fVerbose )
{
    Aig_Obj_t * pObj, * pRepr;
    int i, k, nOmitted, nTotal;
    if ( pAig->pReprs == NULL )
        return;
    assert( pAig->nRegs > 0 );
    Aig_ManForEachPi( pAig, pObj, i )
        pObj->PioNum = -1;
    k = 0;
    Aig_ManForEachLoSeq( pAig, pObj, i )
        pObj->PioNum = k++;
    // consider equivalences
    nOmitted = nTotal = 0;
    Aig_ManForEachObj( pAig, pObj, i )
    {
        pRepr = pAig->pReprs[pObj->Id];
        if ( pRepr == NULL )
            continue;
        nTotal++;
        assert( Aig_ObjIsPi(pObj) );
        assert( Aig_ObjIsPi(pRepr) || Aig_ObjIsConst1(pRepr) );
        if ( Aig_ObjIsConst1(pRepr) )
            continue;
        assert( pObj->PioNum >= 0 && pRepr->PioNum >= 0 );
        // remove equivalence if they belong to different classes
        if ( Vec_IntEntry( vRegClasses, pObj->PioNum ) == 
             Vec_IntEntry( vRegClasses, pRepr->PioNum ) )
             continue;
         pAig->pReprs[pObj->Id] = NULL;
         nOmitted++;
    }
    Aig_ManForEachPi( pAig, pObj, i )
        pObj->PioNum = -1;
    if ( fVerbose )
        printf( "Omitted %d (out of %d) equivs due to register class mismatch.\n", 
            nOmitted, nTotal );
}


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

Alan Mishchenko committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
  Synopsis    [Counts the number of CIs in the model.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_ManLatchNum( Ntl_Man_t * p )
{
    Ntl_Mod_t * pRoot;
    Ntl_Obj_t * pObj;
    int i, Counter = 0;
    pRoot = Ntl_ManRootModel(p);
    Ntl_ModelForEachBox( pRoot, pObj, i )
        Counter += Ntl_ModelLatchNum( pObj->pImplem );
    return Counter;
}

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

  Synopsis    [Returns 1 if the design is combinational.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_ManIsComb( Ntl_Man_t * p )          
{ 
    return Ntl_ManLatchNum(p) == 0; 
} 

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

Alan Mishchenko committed
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
  Synopsis    [Counts the number of CIs in the model.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_ModelCombLeafNum( Ntl_Mod_t * p )
{
    Ntl_Obj_t * pObj;
    int i, Counter = 0;
    Ntl_ModelForEachCombLeaf( p, pObj, i )
        Counter += Ntl_ObjFanoutNum( pObj );
    return Counter;
}

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

  Synopsis    [Counts the number of COs in the model.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_ModelCombRootNum( Ntl_Mod_t * p )
{
    Ntl_Obj_t * pObj;
    int i, Counter = 0;
    Ntl_ModelForEachCombRoot( p, pObj, i )
        Counter += Ntl_ObjFaninNum( pObj );
    return Counter;
}

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

  Synopsis    [Counts the number of CIs in the model.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_ModelSeqLeafNum( Ntl_Mod_t * p )
{
    Ntl_Obj_t * pObj;
    int i, Counter = 0;
    Ntl_ModelForEachSeqLeaf( p, pObj, i )
        Counter += Ntl_ObjFanoutNum( pObj );
    return Counter;
}

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

  Synopsis    [Counts the number of COs in the model.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_ModelSeqRootNum( Ntl_Mod_t * p )
{
    Ntl_Obj_t * pObj;
    int i, Counter = 0;
    Ntl_ModelForEachSeqRoot( p, pObj, i )
        Counter += Ntl_ObjFaninNum( pObj );
    return Counter;
}

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

  Synopsis    [Unmarks the CI/CO nets.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ntl_ModelCheckNetsAreNotMarked( Ntl_Mod_t * pModel )
{
    Ntl_Net_t * pNet;
    int i;
    Ntl_ModelForEachNet( pModel, pNet, i )
        assert( pNet->fMark == 0 );
    return 1;
}

/**Function*************************************************************
Alan Mishchenko committed
648

Alan Mishchenko committed
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
  Synopsis    [Unmarks the CI/CO nets.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ntl_ModelClearNets( Ntl_Mod_t * pModel )
{
    Ntl_Net_t * pNet;
    int i;
    Ntl_ModelForEachNet( pModel, pNet, i )
    {
Alan Mishchenko committed
664 665
        pNet->nVisits = pNet->fMark = 0;
        pNet->pCopy = pNet->pCopy2 = NULL;
Alan Mishchenko committed
666
    }
Alan Mishchenko committed
667 668
}

Alan Mishchenko committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
/**Function*************************************************************

  Synopsis    [Removes nets without fanins and fanouts.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ntl_ManRemoveUselessNets( Ntl_Man_t * p )
{
    Ntl_Mod_t * pRoot;
    Ntl_Obj_t * pNode;
    Ntl_Net_t * pNet;
    int i, k, Counter;
    pRoot = Ntl_ManRootModel( p );
    Ntl_ModelForEachNet( pRoot, pNet, i )
        pNet->fMark = 0;
    Ntl_ModelForEachPi( pRoot, pNode, i )
    {
        pNet = Ntl_ObjFanout0(pNode);
        pNet->fMark = 1;
    }
    Ntl_ModelForEachPo( pRoot, pNode, i )
    {
        pNet = Ntl_ObjFanin0(pNode);
        pNet->fMark = 1;
    }
    Ntl_ModelForEachNode( pRoot, pNode, i )
    {
        Ntl_ObjForEachFanin( pNode, pNet, k )
            pNet->fMark = 1;
        Ntl_ObjForEachFanout( pNode, pNet, k )
            pNet->fMark = 1;
    }
    Ntl_ModelForEachBox( pRoot, pNode, i )
    {
        Ntl_ObjForEachFanin( pNode, pNet, k )
            pNet->fMark = 1;
        Ntl_ObjForEachFanout( pNode, pNet, k )
            pNet->fMark = 1;
    }
    Counter = 0;
    Ntl_ModelForEachNet( pRoot, pNet, i )
    {
        if ( pNet->fMark )
        {
            pNet->fMark = 0;
            continue;
        }
        if ( pNet->fFixed )
            continue;
        Ntl_ModelDeleteNet( pRoot, pNet );
        Vec_PtrWriteEntry( pRoot->vNets, pNet->NetId, NULL );
        Counter++;
    }
    if ( Counter )
        printf( "Deleted %d nets without fanins/fanouts.\n", Counter );
}

Alan Mishchenko committed
731 732 733 734 735
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


736 737
ABC_NAMESPACE_IMPL_END