mapperCore.c 8.34 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 )
{
52
    int fShowSwitching         = 0;
Alan Mishchenko committed
53
    int fUseAreaFlow           = 1;
Alan Mishchenko committed
54 55
    int fUseExactArea          = !p->fSwitching;
    int fUseExactAreaWithPhase = !p->fSwitching;
56
    abctime clk;
Alan Mishchenko committed
57 58 59 60 61 62 63 64 65

    //////////////////////////////////////////////////////////////////////
    // perform pre-mapping computations
    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
66
    clk = Abc_Clock();
Alan Mishchenko committed
67
    Map_MappingCuts( p );
68
    p->timeCuts = Abc_Clock() - clk;
Alan Mishchenko committed
69
    // derive the truth tables 
70
    clk = Abc_Clock();
Alan Mishchenko committed
71
    Map_MappingTruths( p );
72
    p->timeTruth = Abc_Clock() - clk;
Alan Mishchenko committed
73
    //////////////////////////////////////////////////////////////////////
74
//ABC_PRT( "Truths", Abc_Clock() - clk );
Alan Mishchenko committed
75 76 77

    //////////////////////////////////////////////////////////////////////
    // compute the minimum-delay mapping
78
    clk = Abc_Clock();
Alan Mishchenko committed
79 80 81
    p->fMappingMode = 0;
    if ( !Map_MappingMatches( p ) )
        return 0;
82
    p->timeMatch = Abc_Clock() - clk;
Alan Mishchenko committed
83 84
    // compute the references and collect the nodes used in the mapping
    Map_MappingSetRefs( p );
85
    p->AreaBase = Map_MappingGetArea( p );
Alan Mishchenko committed
86 87
if ( p->fVerbose )
{
Alan Mishchenko committed
88 89
printf( "Delay    : %s = %8.2f  Flow = %11.1f  Area = %11.1f  %4.1f %%   ", 
                    fShowSwitching? "Switch" : "Delay", 
90
                    fShowSwitching? Map_MappingGetSwitching(p) : p->fRequiredGlo, 
Alan Mishchenko committed
91
                    Map_MappingGetAreaFlow(p), p->AreaBase, 0.0 );
Alan Mishchenko committed
92
ABC_PRT( "Time", p->timeMatch );
Alan Mishchenko committed
93 94 95
}
    //////////////////////////////////////////////////////////////////////

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

Alan Mishchenko committed
103 104
    //////////////////////////////////////////////////////////////////////
    // perform area recovery using area flow
105
    clk = Abc_Clock();
Alan Mishchenko committed
106 107
    if ( fUseAreaFlow )
    {
Alan Mishchenko committed
108
        // compute the required times
Alan Mishchenko committed
109 110 111 112 113 114
        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 );
115
        p->AreaFinal = Map_MappingGetArea( p );
Alan Mishchenko committed
116 117
if ( p->fVerbose )
{
Alan Mishchenko committed
118 119
printf( "AreaFlow : %s = %8.2f  Flow = %11.1f  Area = %11.1f  %4.1f %%   ", 
                    fShowSwitching? "Switch" : "Delay", 
120
                    fShowSwitching? Map_MappingGetSwitching(p) : p->fRequiredGlo, 
Alan Mishchenko committed
121
                    Map_MappingGetAreaFlow(p), p->AreaFinal, 
Alan Mishchenko committed
122
                    100.0*(p->AreaBase-p->AreaFinal)/p->AreaBase );
123
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
124 125
}
    }
126
    p->timeArea += Abc_Clock() - clk;
Alan Mishchenko committed
127 128 129 130
    //////////////////////////////////////////////////////////////////////

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

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

    //////////////////////////////////////////////////////////////////////
    // perform area recovery using exact area
183
    clk = Abc_Clock();
Alan Mishchenko committed
184 185 186 187 188 189 190 191 192
    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 );
193
        p->AreaFinal = Map_MappingGetArea( p );
Alan Mishchenko committed
194 195 196 197
if ( p->fVerbose )
{
printf( "Switching: %s = %8.2f  Flow = %11.1f  Area = %11.1f  %4.1f %%   ", 
                    fShowSwitching? "Switch" : "Delay", 
198
                    fShowSwitching? Map_MappingGetSwitching(p) : p->fRequiredGlo, 
Alan Mishchenko committed
199 200
                    0.0, p->AreaFinal, 
                    100.0*(p->AreaBase-p->AreaFinal)/p->AreaBase );
201
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
202 203 204 205 206 207 208 209 210
}

        // 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 );
211
        p->AreaFinal = Map_MappingGetArea( p );
Alan Mishchenko committed
212 213 214 215
if ( p->fVerbose )
{
printf( "Switching: %s = %8.2f  Flow = %11.1f  Area = %11.1f  %4.1f %%   ", 
                    fShowSwitching? "Switch" : "Delay", 
216
                    fShowSwitching? Map_MappingGetSwitching(p) : p->fRequiredGlo, 
Alan Mishchenko committed
217
                    0.0, p->AreaFinal, 
Alan Mishchenko committed
218
                    100.0*(p->AreaBase-p->AreaFinal)/p->AreaBase );
219
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
220 221
}
    }
222
    p->timeArea += Abc_Clock() - clk;
Alan Mishchenko committed
223 224 225 226 227 228 229
    //////////////////////////////////////////////////////////////////////

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