mapperCore.c 8.53 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
/**CFile****************************************************************

  FileName    [mapperCore.c]

  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]

  Synopsis    [Generic technology mapping engine.]

  Author      [MVSIS Group]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 2.0. Started - June 1, 2004.]

  Revision    [$Id: mapperCore.c,v 1.7 2004/10/01 23:41:04 satrajit Exp $]

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

#include "mapperInt.h"
//#include "resm.h"

22 23 24
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
25 26 27 28 29
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
30
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [Performs technology mapping for the given object graph.]

  Description [The object graph is stored in the mapping manager.
  First, the AND nodes that fanout into POs are collected in the DFS order.
  Two preprocessing steps are performed: the k-feasible cuts are computed 
  for each node and the truth tables are computed for each cut. Next, the 
  delay-optimal matches are assigned for each node, followed by several 
  iterations of area recoveryd: using area flow (global optimization) 
  and using exact area at a node (local optimization).]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Map_Mapping( Map_Man_t * p )
{
Alan Mishchenko committed
52
    int fShowSwitching         = 1;
Alan Mishchenko committed
53
    int fUseAreaFlow           = 1;
Alan Mishchenko committed
54 55
    int fUseExactArea          = !p->fSwitching;
    int fUseExactAreaWithPhase = !p->fSwitching;
Alan Mishchenko committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    int clk;

    //////////////////////////////////////////////////////////////////////
    // perform pre-mapping computations
    // collect the nodes reachable from POs in the DFS order (including the choices)
    p->vAnds = Map_MappingDfs( p, 1 );
    if ( p->fVerbose )
        Map_MappingReportChoices( p ); 
    Map_MappingSetChoiceLevels( p ); // should always be called before mapping!
//    return 1;

    // compute the cuts of nodes in the DFS order
    clk = clock();
    Map_MappingCuts( p );
    p->timeCuts = clock() - clk;
    // derive the truth tables 
    clk = clock();
    Map_MappingTruths( p );
    p->timeTruth = clock() - clk;
    //////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
76
//ABC_PRT( "Truths", clock() - clk );
Alan Mishchenko committed
77 78 79 80 81 82 83 84 85 86 87 88 89

    //////////////////////////////////////////////////////////////////////
    // compute the minimum-delay mapping
    clk = clock();
    p->fMappingMode = 0;
    if ( !Map_MappingMatches( p ) )
        return 0;
    p->timeMatch = clock() - clk;
    // compute the references and collect the nodes used in the mapping
    Map_MappingSetRefs( p );
    p->AreaBase = Map_MappingGetArea( p, p->vMapping );
if ( p->fVerbose )
{
Alan Mishchenko committed
90 91 92 93
printf( "Delay    : %s = %8.2f  Flow = %11.1f  Area = %11.1f  %4.1f %%   ", 
                    fShowSwitching? "Switch" : "Delay", 
                    fShowSwitching? Map_MappingGetSwitching(p,p->vMapping) : p->fRequiredGlo, 
                    Map_MappingGetAreaFlow(p), p->AreaBase, 0.0 );
Alan Mishchenko committed
94
ABC_PRT( "Time", p->timeMatch );
Alan Mishchenko committed
95 96 97
}
    //////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
98
    if ( !p->fAreaRecovery )
Alan Mishchenko committed
99 100 101
    {
        if ( p->fVerbose )
            Map_MappingPrintOutputArrivals( p );
Alan Mishchenko committed
102
        return 1;
Alan Mishchenko committed
103
    }
Alan Mishchenko committed
104

Alan Mishchenko committed
105 106 107 108 109
    //////////////////////////////////////////////////////////////////////
    // perform area recovery using area flow
    clk = clock();
    if ( fUseAreaFlow )
    {
Alan Mishchenko committed
110
        // compute the required times
Alan Mishchenko committed
111 112 113 114 115 116 117 118 119
        Map_TimeComputeRequiredGlobal( p );
        // recover area flow
        p->fMappingMode = 1;
        Map_MappingMatches( p );
        // compute the references and collect the nodes used in the mapping
        Map_MappingSetRefs( p );
        p->AreaFinal = Map_MappingGetArea( p, p->vMapping );
if ( p->fVerbose )
{
Alan Mishchenko committed
120 121 122 123
printf( "AreaFlow : %s = %8.2f  Flow = %11.1f  Area = %11.1f  %4.1f %%   ", 
                    fShowSwitching? "Switch" : "Delay", 
                    fShowSwitching? Map_MappingGetSwitching(p,p->vMapping) : p->fRequiredGlo, 
                    Map_MappingGetAreaFlow(p), p->AreaFinal, 
Alan Mishchenko committed
124
                    100.0*(p->AreaBase-p->AreaFinal)/p->AreaBase );
Alan Mishchenko committed
125
ABC_PRT( "Time", clock() - clk );
Alan Mishchenko committed
126 127 128 129 130 131 132 133 134 135
}
    }
    p->timeArea += clock() - clk;
    //////////////////////////////////////////////////////////////////////

    //////////////////////////////////////////////////////////////////////
    // perform area recovery using exact area
    clk = clock();
    if ( fUseExactArea )
    {
Alan Mishchenko committed
136
        // compute the required times
Alan Mishchenko committed
137
        Map_TimeComputeRequiredGlobal( p );
Alan Mishchenko committed
138
        // recover area
Alan Mishchenko committed
139 140 141 142 143 144 145
        p->fMappingMode = 2;
        Map_MappingMatches( p );
        // compute the references and collect the nodes used in the mapping
        Map_MappingSetRefs( p );
        p->AreaFinal = Map_MappingGetArea( p, p->vMapping );
if ( p->fVerbose )
{
Alan Mishchenko committed
146 147 148 149
printf( "Area     : %s = %8.2f  Flow = %11.1f  Area = %11.1f  %4.1f %%   ", 
                    fShowSwitching? "Switch" : "Delay", 
                    fShowSwitching? Map_MappingGetSwitching(p,p->vMapping) : p->fRequiredGlo, 
                    0.0, p->AreaFinal, 
Alan Mishchenko committed
150
                    100.0*(p->AreaBase-p->AreaFinal)/p->AreaBase );
Alan Mishchenko committed
151
ABC_PRT( "Time", clock() - clk );
Alan Mishchenko committed
152 153 154 155 156 157 158 159 160 161
}
    }
    p->timeArea += clock() - clk;
    //////////////////////////////////////////////////////////////////////

    //////////////////////////////////////////////////////////////////////
    // perform area recovery using exact area
    clk = clock();
    if ( fUseExactAreaWithPhase )
    {
Alan Mishchenko committed
162
        // compute the required times
Alan Mishchenko committed
163
        Map_TimeComputeRequiredGlobal( p );
Alan Mishchenko committed
164
        // recover area
Alan Mishchenko committed
165 166 167 168 169 170 171
        p->fMappingMode = 3;
        Map_MappingMatches( p );
        // compute the references and collect the nodes used in the mapping
        Map_MappingSetRefs( p );
        p->AreaFinal = Map_MappingGetArea( p, p->vMapping );
if ( p->fVerbose )
{
Alan Mishchenko committed
172 173 174 175 176
printf( "Area     : %s = %8.2f  Flow = %11.1f  Area = %11.1f  %4.1f %%   ", 
                    fShowSwitching? "Switch" : "Delay", 
                    fShowSwitching? Map_MappingGetSwitching(p,p->vMapping) : p->fRequiredGlo, 
                    0.0, p->AreaFinal, 
                    100.0*(p->AreaBase-p->AreaFinal)/p->AreaBase );
Alan Mishchenko committed
177
ABC_PRT( "Time", clock() - clk );
Alan Mishchenko committed
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
}
    }
    p->timeArea += clock() - clk;
    //////////////////////////////////////////////////////////////////////

    //////////////////////////////////////////////////////////////////////
    // perform area recovery using exact area
    clk = clock();
    if ( p->fSwitching )
    {
        // compute the required times
        Map_TimeComputeRequiredGlobal( p );
        // recover switching activity
        p->fMappingMode = 4;
        Map_MappingMatches( p );
        // compute the references and collect the nodes used in the mapping
        Map_MappingSetRefs( p );
        p->AreaFinal = Map_MappingGetArea( p, p->vMapping );
if ( p->fVerbose )
{
printf( "Switching: %s = %8.2f  Flow = %11.1f  Area = %11.1f  %4.1f %%   ", 
                    fShowSwitching? "Switch" : "Delay", 
                    fShowSwitching? Map_MappingGetSwitching(p,p->vMapping) : p->fRequiredGlo, 
                    0.0, p->AreaFinal, 
                    100.0*(p->AreaBase-p->AreaFinal)/p->AreaBase );
Alan Mishchenko committed
203
ABC_PRT( "Time", clock() - clk );
Alan Mishchenko committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
}

        // compute the required times
        Map_TimeComputeRequiredGlobal( p );
        // recover switching activity
        p->fMappingMode = 4;
        Map_MappingMatches( p );
        // compute the references and collect the nodes used in the mapping
        Map_MappingSetRefs( p );
        p->AreaFinal = Map_MappingGetArea( p, p->vMapping );
if ( p->fVerbose )
{
printf( "Switching: %s = %8.2f  Flow = %11.1f  Area = %11.1f  %4.1f %%   ", 
                    fShowSwitching? "Switch" : "Delay", 
                    fShowSwitching? Map_MappingGetSwitching(p,p->vMapping) : p->fRequiredGlo, 
                    0.0, p->AreaFinal, 
Alan Mishchenko committed
220
                    100.0*(p->AreaBase-p->AreaFinal)/p->AreaBase );
Alan Mishchenko committed
221
ABC_PRT( "Time", clock() - clk );
Alan Mishchenko committed
222 223 224 225 226 227 228 229 230 231
}
    }
    p->timeArea += clock() - clk;
    //////////////////////////////////////////////////////////////////////

    // print the arrival times of the latest outputs
    if ( p->fVerbose )
        Map_MappingPrintOutputArrivals( p );
    return 1;
}
232 233
ABC_NAMESPACE_IMPL_END